From 63a4224c7d6c2049e5d49657924eb6b365452f54 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Fri, 7 Jun 2024 00:32:18 +0500 Subject: [PATCH 01/10] [Feature]: Full support for local detuning --- src/ahs.jl | 169 +++++++++++++++++++++++++++++++++++++++++ test/local_detuning.jl | 49 ++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 test/local_detuning.jl diff --git a/src/ahs.jl b/src/ahs.jl index 9602a075..17f48afd 100644 --- a/src/ahs.jl +++ b/src/ahs.jl @@ -2,6 +2,7 @@ import StructTypes export AtomArrangementItem, AtomArrangement, TimeSeriesItem, TimeSeries, Field, DrivingField export ShiftingField, Hamiltonian, AnalogHamiltonianSimulation, Pattern, vacant, filled, SiteType, discretize +export LocalDetuning, stitch """ Hamiltonian @@ -271,3 +272,171 @@ function discretize(ahs::AnalogHamiltonianSimulation, device::Device) discretize(ahs.register, properties), map(h->discretize(h, properties), ahs.hamiltonian) ) end + +""" + LocalDetuning <: Hamiltonian + +Struct representing a Hamiltonian term `H_{shift}` representing the local detuning that changes the energy of the Rydberg level in an AnalogHamiltonianSimulation. + + +```math +H_{shift} (t) := -\\Delta(t) \\sum_k h_k | r_k \\rangle \\langle r_k | +``` + +where: + +- ``\\Delta(t)`` is the magnitude of the frequency shift in rad/s, +- ``h_k`` is the site coefficient of atom ``k``, a dimensionless real number between 0 and 1, +- ``|r_k \\rangle`` is the Rydberg state of atom ``k``. + +The sum ``\\sum_k`` is taken over all target atoms. + +Fields: +- `magnitude::Field`: Field containing the global magnitude time series Delta(t), + where time is measured in seconds (s) and values are measured in rad/s, and the + local pattern h_k of dimensionless real numbers between 0 and 1. + +```julia +julia> magnitude = Field(TimeSeries(OrderedDict([0 => TimeSeriesItem(0, 1), 1 => TimeSeriesItem(1, 2)]), true, -1)) +julia> local_detuning = LocalDetuning(magnitude) +``` +""" +struct LocalDetuning <: Hamiltonian + magnitude::Field +end + +""" + LocalDetuning(times::Vector{<:Number}, values::Vector{<:Number}, pattern::Vector{<:Number}) + +```julia +julia> times₁ = [0, 0.1, 0.2, 0.3]; +julia> glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0]; +julia> pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6]; +julia> s₁ = LocalDetuning(times₁, glob_amplitude₁, pattern₁) +LocalDetuning(Field(TimeSeries(OrderedCollections.OrderedDict{Number, TimeSeriesItem}(0.0 => TimeSeriesItem(0.0, 0.5), 0.1 => TimeSeriesItem(0.1, 0.8), 0.2 => TimeSeriesItem(0.2, 0.9), 0.3 => TimeSeriesItem(0.3, 1.0)), true, -1), Pattern(Number[0.3, 0.7, 0.6, -0.5, 0.0, 1.6]))) +``` +""" +function LocalDetuning(times::Vector{<:Number}, values::Vector{<:Number}, pattern::Vector{<:Number}) + if length(times) != length(values) + throw(ArgumentError("The length of the times and values lists must be equal.")) + end + + time_series = TimeSeries() + for (t, v) in zip(times, values) + time_series[t] = v + end + + field = Field(time_series, Pattern(pattern)) + LocalDetuning(field) +end + +""" + stitch(ld1::LocalDetuning, ld2::LocalDetuning; boundary::Symbol="mean") -> LocalDetuning + +Stitches two LocalDetuning terms based on the TimeSeries.stitch method. +The time points of the second LocalDetuning are shifted such that the first time point of +the second LocalDetuning coincides with the last time point of the first LocalDetuning. +The boundary point value is handled according to the boundary argument value. + +# Arguments: + ld1::LocalDetuning: The first LocalDetuning to be stitched. + ld2::LocalDetuning: The second LocalDetuning to be stitched. + boundary::Symbol="mean": The boundary point handler. Possible options are "mean", "left", "right". +""" +function stitch(ld1::LocalDetuning, ld2::LocalDetuning, boundary::Symbol=:mean) + if ld1.magnitude.pattern.series != ld2.magnitude.pattern.series + throw(ArgumentError("The LocalDetuning pattern for both fields must be equal.")) + end + + new_ts = stitch(ld1.magnitude.time_series, ld2.magnitude.time_series, boundary) + LocalDetuning(Field(new_ts, ld1.magnitude.pattern)) +end + +""" + stitch(ts1::TimeSeries, ts2::TimeSeries; boundary::Symbol="mean") + +Stitches two shifting fields based on the `TimeSeries.stitch` method. +The time points of the second `TimeSeries` are shifted such that the first time point of +the second `TimeSeries` coincides with the last time point of the first `TimeSeries`. +The boundary point value is handled according to the `boundary` argument value. + +# Arguments: +- `ts1::TimeSeries`: The first `TimeSeries` to be stitched. +- `ts2::TimeSeries`: The second `TimeSeries` to be stitched. +- `boundary::Symbol="mean"`: The boundary point handler. Possible options are "mean", "left", "right". + +# Examples: + +```julia +julia> times₁ = [0, 0.1, 0.2, 0.3]; +julia> glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0]; +julia> pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6]; + +julia> times₂ = [0, 0.1, 0.2, 0.3]; +julia> glob_amplitude₂ = [0.5, 0.8, 0.9, 1.0]; +julia> pattern₂ = pattern₁; + +julia> s₂ = LocalDetuning(times₂, glob_amplitude₂, pattern₂) +LocalDetuning(Field(TimeSeries(OrderedCollections.OrderedDict{Number, TimeSeriesItem}(0.0 => TimeSeriesItem(0.0, 0.5), 0.1 => TimeSeriesItem(0.1, 0.8), 0.2 => TimeSeriesItem(0.2, 0.9), 0.3 => TimeSeriesItem(0.3, 1.0)), true, -1), Pattern(Number[0.3, 0.7, 0.6, -0.5, 0.0, 1.6]))) + +julia> s₁ = LocalDetuning(times₁, glob_amplitude₁, pattern₁) +LocalDetuning(Field(TimeSeries(OrderedCollections.OrderedDict{Number, TimeSeriesItem}(0.0 => TimeSeriesItem(0.0, 0.5), 0.1 => TimeSeriesItem(0.1, 0.8), 0.2 => TimeSeriesItem(0.2, 0.9), 0.3 => TimeSeriesItem(0.3, 1.0)), true, -1), Pattern(Number[0.3, 0.7, 0.6, -0.5, 0.0, 1.6]))) + +julia> stitchedₗ = stitch(s₁, s₂, :mean) +LocalDetuning(Field(TimeSeries(OrderedCollections.OrderedDict{Number, TimeSeriesItem}(0.0 => TimeSeriesItem(0.0, 0.75), 0.1 => TimeSeriesItem(0.1, 0.8), 0.2 => TimeSeriesItem(0.2, 0.9), 0.3 => TimeSeriesItem(0.3, 1.0)), true, 1), Pattern(Number[0.3, 0.7, 0.6, -0.5, 0.0, 1.6]))) + +julia> stitchedₗ = stitch(s₁, s₂, :left) +LocalDetuning(Field(TimeSeries(OrderedCollections.OrderedDict{Number, TimeSeriesItem}(0.0 => TimeSeriesItem(0.3, 1.0), 0.1 => TimeSeriesItem(0.1, 0.8), 0.2 => TimeSeriesItem(0.2, 0.9), 0.3 => TimeSeriesItem(0.3, 1.0)), true, 1), Pattern(Number[0.3, 0.7, 0.6, -0.5, 0.0, 1.6]))) + +julia> stitchedₗ = stitch(s₁, s₂, :right) +LocalDetuning(Field(TimeSeries(OrderedCollections.OrderedDict{Number, TimeSeriesItem}(0.0 => TimeSeriesItem(0.0, 0.5), 0.1 => TimeSeriesItem(0.1, 0.8), 0.2 => TimeSeriesItem(0.2, 0.9), 0.3 => TimeSeriesItem(0.3, 1.0)), true, 1), Pattern(Number[0.3, 0.7, 0.6, -0.5, 0.0, 1.6]))) +``` +""" +function stitch(ts1::TimeSeries, ts2::TimeSeries, boundary::Symbol) + merged_series = deepcopy(ts1.series) + first_time_ts2 = first(collect(keys(ts2.series))) + last_time_ts1 = last(collect(keys(ts1.series))) + + if boundary == :mean + merged_value = (ts1.series[last_time_ts1].value + ts2.series[first_time_ts2].value) / 2 + merged_series[first_time_ts2] = TimeSeriesItem(first_time_ts2, merged_value) + elseif boundary == :left + merged_series[first_time_ts2] = ts1.series[last_time_ts1] + elseif boundary == :right + merged_series[first_time_ts2] = ts2.series[first_time_ts2] + else + throw(ArgumentError("Invalid boundary condition: $boundary")) + end + + for (t, v) in ts2.series + if t != first_time_ts2 + merged_series[t] = v + end + end + + largest_time = maximum(keys(merged_series)) + if largest_time isa Float64 + largest_time = Int(ceil(largest_time)) + end + + TimeSeries(merged_series, true, largest_time) +end +""" + discretize(ld::LocalDetuning, properties::DiscretizationProperties) -> LocalDetuning + +Creates a discretized version of the `LocalDetuning`. + +# Arguments: +- `ld::LocalDetuning`: The `LocalDetuning` to discretize. +- `properties::DiscretizationProperties`: Capabilities of a device that represent the + resolution with which the device can implement the parameters. +""" +function discretize(ld::LocalDetuning, properties::DiscretizationProperties) + local_detuning_parameters = properties.rydberg.rydbergLocal + time_resolution = local_detuning_parameters.timeResolution + value_resolution = local_detuning_parameters.commonDetuningResolution + pattern_resolution = local_detuning_parameters.localDetuningResolution + + discretized_magnitude = discretize(ld.magnitude, time_resolution, value_resolution, pattern_resolution) + LocalDetuning(discretized_magnitude) +end diff --git a/test/local_detuning.jl b/test/local_detuning.jl new file mode 100644 index 00000000..f31191ca --- /dev/null +++ b/test/local_detuning.jl @@ -0,0 +1,49 @@ +using Braket, Test, JSON3, StructTypes, Mocking, UUIDs, DecFP + +Mocking.activate() + +struct MockRydbergLocal + timeResolution::Dec128 + commonDetuningResolution::Dec128 + localDetuningResolution::Dec128 +end + +struct MockRydberg + c6coefficient::Dec128 + rydbergGlobal::Braket.RydbergGlobal + rydbergLocal::MockRydbergLocal +end + +struct MockAhsParadigmProperties + lattice::Braket.Lattice + rydberg::MockRydberg +end + +struct MockAhsDeviceCapabilities + action::Dict{Union{Braket.DeviceActionType, String}, Braket.DeviceActionProperties} + paradigm::MockAhsParadigmProperties +end + +@testset "AHS.LocalDetuning" begin + + @testset "LocalDetuning" begin + times₁ = [0, 0.1, 0.2, 0.3] + glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0] + pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6] + s₁ = LocalDetuning(times₁, glob_amplitude₁, pattern₁) + end + + @testset "LocalDetuning Stitch: Mean, Left, Right" begin + times₁ = [0, 0.1, 0.2, 0.3] + glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0] + pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6] + times₂ = [0, 0.1, 0.2, 0.3] + glob_amplitude₂ = [0.5, 0.8, 0.9, 1.0] + pattern₂ = pattern₁ + s₂ = LocalDetuning(times₂, glob_amplitude₂, pattern₂) + s₁ = LocalDetuning(times₁, glob_amplitude₁, pattern₁) + stitchedₗ = stitch(s₁, s₂, :mean) + stitchedₗ = stitch(s₁, s₂, :left) + stitchedₗ = stitch(s₁, s₂, :right) + end +end From 7a14d446a5be756dc7a16879da89213176c10019 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 8 Jun 2024 01:19:23 +0500 Subject: [PATCH 02/10] [Feature]: Full support for local detuning, Adding Mock Methods for Discretize for LocalDetuning --- src/ahs.jl | 14 ++++++++++++++ test/local_detuning.jl | 10 +++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ahs.jl b/src/ahs.jl index 17f48afd..13ff1437 100644 --- a/src/ahs.jl +++ b/src/ahs.jl @@ -330,6 +330,11 @@ function LocalDetuning(times::Vector{<:Number}, values::Vector{<:Number}, patter LocalDetuning(field) end + +function ir(ld::LocalDetuning) + return IR.LocalDetuning(ir(ld.magnitude)) +end + """ stitch(ld1::LocalDetuning, ld2::LocalDetuning; boundary::Symbol="mean") -> LocalDetuning @@ -440,3 +445,12 @@ function discretize(ld::LocalDetuning, properties::DiscretizationProperties) discretized_magnitude = discretize(ld.magnitude, time_resolution, value_resolution, pattern_resolution) LocalDetuning(discretized_magnitude) end + +function discretize(ld::LocalDetuning, properties::DiscretizationProperties) + local_detuning_parameters = properties.rydberg.rydbergLocal + time_resolution = Dec128(local_detuning_parameters.timeResolution) + value_resolution = Dec128(local_detuning_parameters.commonDetuningResolution) + pattern_resolution = Dec128(local_detuning_parameters.localDetuningResolution) + discretized_magnitude = discretize(ld.magnitude, time_resolution, value_resolution, pattern_resolution) + LocalDetuning(discretized_magnitude) +end diff --git a/test/local_detuning.jl b/test/local_detuning.jl index f31191ca..8759cb6c 100644 --- a/test/local_detuning.jl +++ b/test/local_detuning.jl @@ -14,16 +14,10 @@ struct MockRydberg rydbergLocal::MockRydbergLocal end -struct MockAhsParadigmProperties - lattice::Braket.Lattice +struct MockDiscretizationProperties rydberg::MockRydberg end -struct MockAhsDeviceCapabilities - action::Dict{Union{Braket.DeviceActionType, String}, Braket.DeviceActionProperties} - paradigm::MockAhsParadigmProperties -end - @testset "AHS.LocalDetuning" begin @testset "LocalDetuning" begin @@ -31,6 +25,7 @@ end glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0] pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6] s₁ = LocalDetuning(times₁, glob_amplitude₁, pattern₁) + #asserts to test this end @testset "LocalDetuning Stitch: Mean, Left, Right" begin @@ -45,5 +40,6 @@ end stitchedₗ = stitch(s₁, s₂, :mean) stitchedₗ = stitch(s₁, s₂, :left) stitchedₗ = stitch(s₁, s₂, :right) + #asserts to test this end end From 9092587c7bdddceee41c3fa5057fcb592cccd990 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 8 Jun 2024 23:16:43 +0500 Subject: [PATCH 03/10] [Feature]: Full support for local detuning - Adding basic tests --- test/local_detuning.jl | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/test/local_detuning.jl b/test/local_detuning.jl index 8759cb6c..69c18c6a 100644 --- a/test/local_detuning.jl +++ b/test/local_detuning.jl @@ -21,25 +21,27 @@ end @testset "AHS.LocalDetuning" begin @testset "LocalDetuning" begin - times₁ = [0, 0.1, 0.2, 0.3] - glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0] - pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6] - s₁ = LocalDetuning(times₁, glob_amplitude₁, pattern₁) - #asserts to test this + times₁ = [0, 0.1, 0.2, 0.3] + times₂ = [0.3, 0.1, 0.2, 0] + glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0] + pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6] + s₁ = LocalDetuning(times₁, glob_amplitude₁, pattern₁) + s₂ = LocalDetuning(times₂, glob_amplitude₁, pattern₁) + @test s₁.magnitude.pattern.series == [0.3, 0.7, 0.6, -0.5, 0, 1.6] + @test s₁.magnitude.time_series.sorted == true + @test s₂.magnitude.time_series.sorted == false end @testset "LocalDetuning Stitch: Mean, Left, Right" begin - times₁ = [0, 0.1, 0.2, 0.3] - glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0] - pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6] - times₂ = [0, 0.1, 0.2, 0.3] - glob_amplitude₂ = [0.5, 0.8, 0.9, 1.0] - pattern₂ = pattern₁ - s₂ = LocalDetuning(times₂, glob_amplitude₂, pattern₂) - s₁ = LocalDetuning(times₁, glob_amplitude₁, pattern₁) - stitchedₗ = stitch(s₁, s₂, :mean) - stitchedₗ = stitch(s₁, s₂, :left) - stitchedₗ = stitch(s₁, s₂, :right) - #asserts to test this + times₁ = [0, 0.1, 0.2, 0.3] + glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0] + pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6] + times₂ = [0, 0.1, 0.2, 0.3] + glob_amplitude₂ = [0.5, 0.8, 0.9, 1.0] + pattern₂ = pattern₁ + s₂ = LocalDetuning(times₂, glob_amplitude₂, pattern₂) + s₁ = LocalDetuning(times₁, glob_amplitude₁, pattern₁) + stitchedₗ = stitch(s₁, s₂, :left) + @test stitchedₗ.magnitude.pattern == s₁.magnitude.pattern end end From e47b78e34c5ea73661b06f2bb01dc5f5459b375d Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 8 Jun 2024 23:53:42 +0500 Subject: [PATCH 04/10] [Feature]: Adding full support for local detuning - Discretize Mock Tests --- test/local_detuning.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/local_detuning.jl b/test/local_detuning.jl index 69c18c6a..9a7fb027 100644 --- a/test/local_detuning.jl +++ b/test/local_detuning.jl @@ -44,4 +44,18 @@ end stitchedₗ = stitch(s₁, s₂, :left) @test stitchedₗ.magnitude.pattern == s₁.magnitude.pattern end + + @testset "LocalDetuning: Discretize" begin + times₅ = [0, 0.1, 0.2] + values₅ = [0.2, 0.5, 0.7] + pattern₅ = [0.1, 0.3, 0.5] + ld = LocalDetuning(times₅, values₅, pattern₅) + properties = Braket.DiscretizationProperties( + Braket.Lattice(Braket.Area(Dec128("1e-3"), Dec128("1e-3")), Braket.Geometry(Dec128("1e-7"), Dec128("1e-7"), Dec128("1e-7"), 200)), + MockRydberg(Dec128("1e-6"), Braket.RydbergGlobal((Dec128("1.0"), Dec128("1e6")), Dec128("400.0"), Dec128("0.2"), (Dec128("1.0"), Dec128("1e6")), Dec128("0.2"), Dec128("0.2"), (Dec128("1.0"), Dec128("1e6")), Dec128("5e-7"), Dec128("1e-9"), Dec128("1e-5"), Dec128("0.0"), Dec128("100.0")), + MockRydbergLocal(Dec128("1e-9"), Dec128("2000.0"), Dec128("0.01"))) + ) + discretizedₗ = discretize(ld, properties) + @test discretized_ld isa LocalDetuning + end end From c831f865a5afd9ea3a91d6138eeee36531111f2c Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Wed, 12 Jun 2024 23:35:23 +0500 Subject: [PATCH 05/10] [Feature]: Full support for local detuning - codereview suggestions --- docs/src/local_detuning.md | 7 +++++++ src/ahs.jl | 9 +++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 docs/src/local_detuning.md diff --git a/docs/src/local_detuning.md b/docs/src/local_detuning.md new file mode 100644 index 00000000..588971ad --- /dev/null +++ b/docs/src/local_detuning.md @@ -0,0 +1,7 @@ +# LocalDetuning + +```@docs +LocalDetuning +stitch +discretize +``` diff --git a/src/ahs.jl b/src/ahs.jl index 13ff1437..664237ff 100644 --- a/src/ahs.jl +++ b/src/ahs.jl @@ -276,7 +276,7 @@ end """ LocalDetuning <: Hamiltonian -Struct representing a Hamiltonian term `H_{shift}` representing the local detuning that changes the energy of the Rydberg level in an AnalogHamiltonianSimulation. +Struct representing a Hamiltonian term `H_{shift}` representing the [local detuning](https://aws.amazon.com/blogs/quantum-computing/local-detuning-now-available-on-queras-aquila-device-with-braket-direct/) that changes the energy of the Rydberg level in an AnalogHamiltonianSimulation. ```math @@ -331,10 +331,7 @@ function LocalDetuning(times::Vector{<:Number}, values::Vector{<:Number}, patter end -function ir(ld::LocalDetuning) - return IR.LocalDetuning(ir(ld.magnitude)) -end - +ir(ld::LocalDetuning) = IR.LocalDetuning(ir(ld.magnitude)) """ stitch(ld1::LocalDetuning, ld2::LocalDetuning; boundary::Symbol="mean") -> LocalDetuning @@ -360,7 +357,7 @@ end """ stitch(ts1::TimeSeries, ts2::TimeSeries; boundary::Symbol="mean") -Stitches two shifting fields based on the `TimeSeries.stitch` method. +[`Stitch`](@ref) two shifting fields based on the `TimeSeries.stitch` method. The time points of the second `TimeSeries` are shifted such that the first time point of the second `TimeSeries` coincides with the last time point of the first `TimeSeries`. The boundary point value is handled according to the `boundary` argument value. From 0871a7362e2afd26488ba6afba9c30ce570dce00 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 13 Jun 2024 21:48:23 +0500 Subject: [PATCH 06/10] [Feature] - Full support for local detuning - formatting --- docs/src/local_detuning.md | 7 ------- src/ahs.jl | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 docs/src/local_detuning.md diff --git a/docs/src/local_detuning.md b/docs/src/local_detuning.md deleted file mode 100644 index 588971ad..00000000 --- a/docs/src/local_detuning.md +++ /dev/null @@ -1,7 +0,0 @@ -# LocalDetuning - -```@docs -LocalDetuning -stitch -discretize -``` diff --git a/src/ahs.jl b/src/ahs.jl index 664237ff..3da0e18a 100644 --- a/src/ahs.jl +++ b/src/ahs.jl @@ -357,7 +357,7 @@ end """ stitch(ts1::TimeSeries, ts2::TimeSeries; boundary::Symbol="mean") -[`Stitch`](@ref) two shifting fields based on the `TimeSeries.stitch` method. +[`stitch`](@ref) two shifting fields based on the `TimeSeries.stitch` method. The time points of the second `TimeSeries` are shifted such that the first time point of the second `TimeSeries` coincides with the last time point of the first `TimeSeries`. The boundary point value is handled according to the `boundary` argument value. From 036c7dd7144d3eb2a6b8f9e4dfd29ff5233c4a3c Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 13 Jun 2024 21:52:54 +0500 Subject: [PATCH 07/10] [Feature] - Full support for local detuning - cleanup --- src/ahs.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ahs.jl b/src/ahs.jl index 3da0e18a..a6dba7ff 100644 --- a/src/ahs.jl +++ b/src/ahs.jl @@ -335,7 +335,7 @@ ir(ld::LocalDetuning) = IR.LocalDetuning(ir(ld.magnitude)) """ stitch(ld1::LocalDetuning, ld2::LocalDetuning; boundary::Symbol="mean") -> LocalDetuning -Stitches two LocalDetuning terms based on the TimeSeries.stitch method. +[`stitch`](@ref) two shifting fields based on the `TimeSeries.stitch` method. The time points of the second LocalDetuning are shifted such that the first time point of the second LocalDetuning coincides with the last time point of the first LocalDetuning. The boundary point value is handled according to the boundary argument value. From 1f0df7768638a30880fdda0ef3036eee8e8c6bc4 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Wed, 19 Jun 2024 09:04:21 +0500 Subject: [PATCH 08/10] adding codereview suggestions --- docs/src/ahs.md | 5 +++++ src/ahs.jl | 37 +++++++++++++++++-------------- test/local_detuning.jl | 50 ++++++++++++++++++++++++++++-------------- 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/docs/src/ahs.md b/docs/src/ahs.md index ab0a78f2..9859a4d6 100644 --- a/docs/src/ahs.md +++ b/docs/src/ahs.md @@ -7,10 +7,15 @@ discretize Hamiltonian AtomArrangementItem AtomArrangementItem(::Tuple{Number, Number}) +DiscretizationProperties TimeSeriesItem TimeSeries Field ShiftingField DrivingField ir(::AnalogHamiltonianSimulation) +ir(::LocalDetuning) +LocalDetuning +LocalDetuning(::Vector{<:Number}, ::Vector{<:Number}, ::Vector{<:Number}) +stitch ``` diff --git a/src/ahs.jl b/src/ahs.jl index a6dba7ff..b4f7cfef 100644 --- a/src/ahs.jl +++ b/src/ahs.jl @@ -276,7 +276,7 @@ end """ LocalDetuning <: Hamiltonian -Struct representing a Hamiltonian term `H_{shift}` representing the [local detuning](https://aws.amazon.com/blogs/quantum-computing/local-detuning-now-available-on-queras-aquila-device-with-braket-direct/) that changes the energy of the Rydberg level in an AnalogHamiltonianSimulation. +Struct representing a [`Hamiltonian`](@ref) term `H_{shift}` representing the [local detuning](https://aws.amazon.com/blogs/quantum-computing/local-detuning-now-available-on-queras-aquila-device-with-braket-direct/) that changes the energy of the Rydberg level in an [`AnalogHamiltonianSimulation`](@ref). ```math @@ -292,11 +292,13 @@ where: The sum ``\\sum_k`` is taken over all target atoms. Fields: -- `magnitude::Field`: Field containing the global magnitude time series Delta(t), +- `magnitude::Field`: [`Field](@ref) containing the global magnitude time series Delta(t), where time is measured in seconds (s) and values are measured in rad/s, and the local pattern h_k of dimensionless real numbers between 0 and 1. -```julia +# Examples + +```jldoctest julia> magnitude = Field(TimeSeries(OrderedDict([0 => TimeSeriesItem(0, 1), 1 => TimeSeriesItem(1, 2)]), true, -1)) julia> local_detuning = LocalDetuning(magnitude) ``` @@ -308,7 +310,9 @@ end """ LocalDetuning(times::Vector{<:Number}, values::Vector{<:Number}, pattern::Vector{<:Number}) -```julia +# Examples + +```jldoctest julia> times₁ = [0, 0.1, 0.2, 0.3]; julia> glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0]; julia> pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6]; @@ -332,12 +336,13 @@ end ir(ld::LocalDetuning) = IR.LocalDetuning(ir(ld.magnitude)) + """ stitch(ld1::LocalDetuning, ld2::LocalDetuning; boundary::Symbol="mean") -> LocalDetuning -[`stitch`](@ref) two shifting fields based on the `TimeSeries.stitch` method. -The time points of the second LocalDetuning are shifted such that the first time point of -the second LocalDetuning coincides with the last time point of the first LocalDetuning. +[`stitch`](@ref) two shifting fields based on the `stitch` method. +The time points of the second [`LocalDetuning`](@ref) are shifted such that the first time point of +the second [`LocalDetuning`](@ref) coincides with the last time point of the first [`LocalDetuning`](@ref). The boundary point value is handled according to the boundary argument value. # Arguments: @@ -357,19 +362,19 @@ end """ stitch(ts1::TimeSeries, ts2::TimeSeries; boundary::Symbol="mean") -[`stitch`](@ref) two shifting fields based on the `TimeSeries.stitch` method. -The time points of the second `TimeSeries` are shifted such that the first time point of -the second `TimeSeries` coincides with the last time point of the first `TimeSeries`. +[`stitch`](@ref) two shifting fields based on the `stitch` method. +The time points of the second [`TimeSeries`](@ref) are shifted such that the first time point of +the second [`TimeSeries`](@ref) coincides with the last time point of the first [`TimeSeries`](@ref). The boundary point value is handled according to the `boundary` argument value. # Arguments: -- `ts1::TimeSeries`: The first `TimeSeries` to be stitched. -- `ts2::TimeSeries`: The second `TimeSeries` to be stitched. +- `ts1::TimeSeries`: The first [`TimeSeries`](@ref) to be stitched. +- `ts2::TimeSeries`: The second [`TimeSeries`](@ref) to be stitched. - `boundary::Symbol="mean"`: The boundary point handler. Possible options are "mean", "left", "right". # Examples: -```julia +```jldoctest julia> times₁ = [0, 0.1, 0.2, 0.3]; julia> glob_amplitude₁ = [0.5, 0.8, 0.9, 1.0]; julia> pattern₁ = [0.3, 0.7, 0.6, -0.5, 0, 1.6]; @@ -426,11 +431,11 @@ end """ discretize(ld::LocalDetuning, properties::DiscretizationProperties) -> LocalDetuning -Creates a discretized version of the `LocalDetuning`. +Creates a discretized version of the [`LocalDetuning`](@ref). # Arguments: -- `ld::LocalDetuning`: The `LocalDetuning` to discretize. -- `properties::DiscretizationProperties`: Capabilities of a device that represent the +- `ld::LocalDetuning`: The [`LocalDetuning`](@ref) to discretize. +- `properties::[`DiscretizationProperties`](@ref): Capabilities of a device that represent the resolution with which the device can implement the parameters. """ function discretize(ld::LocalDetuning, properties::DiscretizationProperties) diff --git a/test/local_detuning.jl b/test/local_detuning.jl index 9a7fb027..a9129b1b 100644 --- a/test/local_detuning.jl +++ b/test/local_detuning.jl @@ -14,10 +14,6 @@ struct MockRydberg rydbergLocal::MockRydbergLocal end -struct MockDiscretizationProperties - rydberg::MockRydberg -end - @testset "AHS.LocalDetuning" begin @testset "LocalDetuning" begin @@ -44,18 +40,38 @@ end stitchedₗ = stitch(s₁, s₂, :left) @test stitchedₗ.magnitude.pattern == s₁.magnitude.pattern end + + @testset "LocalDetuning: Discretize" begin + times₅ = [0, 0.1, 0.2] + values₅ = [0.2, 0.5, 0.7] + pattern₅ = [0.1, 0.3, 0.5] + ld = LocalDetuning(times₅, values₅, pattern₅) + properties = Braket.DiscretizationProperties( + Braket.Lattice( + Braket.Area(Dec128("1e-3"), Dec128("1e-3")), + Braket.Geometry(Dec128("1e-7"), Dec128("1e-7"), Dec128("1e-7"), 200) + ), + MockRydberg( + Dec128("1e-6"), + Braket.RydbergGlobal( + (Dec128("1.0"), Dec128("1e6")), + Dec128("400.0"), + Dec128("0.2"), + (Dec128("1.0"), Dec128("1e6")), + Dec128("0.2"), + Dec128("0.2"), + (Dec128("1.0"), Dec128("1e6")), + Dec128("5e-7"), + Dec128("1e-9"), + Dec128("1e-5"), + Dec128("0.0"), + Dec128("100.0") + ), + MockRydbergLocal(Dec128("1e-9"), Dec128("2000.0"), Dec128("0.01")) + ) + ) + discretized_ld = discretize(ld, properties) + @test discretized_ld isa LocalDetuning + end - @testset "LocalDetuning: Discretize" begin - times₅ = [0, 0.1, 0.2] - values₅ = [0.2, 0.5, 0.7] - pattern₅ = [0.1, 0.3, 0.5] - ld = LocalDetuning(times₅, values₅, pattern₅) - properties = Braket.DiscretizationProperties( - Braket.Lattice(Braket.Area(Dec128("1e-3"), Dec128("1e-3")), Braket.Geometry(Dec128("1e-7"), Dec128("1e-7"), Dec128("1e-7"), 200)), - MockRydberg(Dec128("1e-6"), Braket.RydbergGlobal((Dec128("1.0"), Dec128("1e6")), Dec128("400.0"), Dec128("0.2"), (Dec128("1.0"), Dec128("1e6")), Dec128("0.2"), Dec128("0.2"), (Dec128("1.0"), Dec128("1e6")), Dec128("5e-7"), Dec128("1e-9"), Dec128("1e-5"), Dec128("0.0"), Dec128("100.0")), - MockRydbergLocal(Dec128("1e-9"), Dec128("2000.0"), Dec128("0.01"))) - ) - discretizedₗ = discretize(ld, properties) - @test discretized_ld isa LocalDetuning - end end From 834003859d692891ac606b20964547ac6fc99e84 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Wed, 19 Jun 2024 23:33:32 +0500 Subject: [PATCH 09/10] Minor Cleanup --- src/ahs.jl | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/ahs.jl b/src/ahs.jl index b4f7cfef..4bc01b79 100644 --- a/src/ahs.jl +++ b/src/ahs.jl @@ -438,16 +438,6 @@ Creates a discretized version of the [`LocalDetuning`](@ref). - `properties::[`DiscretizationProperties`](@ref): Capabilities of a device that represent the resolution with which the device can implement the parameters. """ -function discretize(ld::LocalDetuning, properties::DiscretizationProperties) - local_detuning_parameters = properties.rydberg.rydbergLocal - time_resolution = local_detuning_parameters.timeResolution - value_resolution = local_detuning_parameters.commonDetuningResolution - pattern_resolution = local_detuning_parameters.localDetuningResolution - - discretized_magnitude = discretize(ld.magnitude, time_resolution, value_resolution, pattern_resolution) - LocalDetuning(discretized_magnitude) -end - function discretize(ld::LocalDetuning, properties::DiscretizationProperties) local_detuning_parameters = properties.rydberg.rydbergLocal time_resolution = Dec128(local_detuning_parameters.timeResolution) From c215b53fe1421669af50488b2309917bf60b8c9a Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 20 Jun 2024 23:39:09 +0500 Subject: [PATCH 10/10] CI doc fix --- docs/src/ahs.md | 1 - src/ahs.jl | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/src/ahs.md b/docs/src/ahs.md index 9859a4d6..4d8d1b2c 100644 --- a/docs/src/ahs.md +++ b/docs/src/ahs.md @@ -7,7 +7,6 @@ discretize Hamiltonian AtomArrangementItem AtomArrangementItem(::Tuple{Number, Number}) -DiscretizationProperties TimeSeriesItem TimeSeries Field diff --git a/src/ahs.jl b/src/ahs.jl index 4bc01b79..79d4d952 100644 --- a/src/ahs.jl +++ b/src/ahs.jl @@ -334,7 +334,12 @@ function LocalDetuning(times::Vector{<:Number}, values::Vector{<:Number}, patter LocalDetuning(field) end +""" + ir(ld::LocalDetuning) +Generate IR from an [`LocalDetuning`](@ref) which can be run on +a neutral atom simulator or quantum device. +""" ir(ld::LocalDetuning) = IR.LocalDetuning(ir(ld.magnitude)) """ @@ -435,7 +440,7 @@ Creates a discretized version of the [`LocalDetuning`](@ref). # Arguments: - `ld::LocalDetuning`: The [`LocalDetuning`](@ref) to discretize. -- `properties::[`DiscretizationProperties`](@ref): Capabilities of a device that represent the +- `properties::DiscretizationProperties: Capabilities of a device that represent the resolution with which the device can implement the parameters. """ function discretize(ld::LocalDetuning, properties::DiscretizationProperties)