Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Full support for Local Detuning #86

Merged
merged 11 commits into from
Aug 28, 2024

Conversation

Fe-r-oz
Copy link

@Fe-r-oz Fe-r-oz commented Jun 6, 2024

Resolving Issue #79

Description of changes: QuEra's Aquila now supports local detuning with Braket Direct. The underlying structs are implemented in Braket.jl but many of the correctness tests and validations are not. Local detuning would be used with Braket Direct to access this advanced feature of Aquila.

Kindly please check out the implementation! I followed the Python LocalDetuning

The following functions and their docstrings are also added

1. LocalDetuning(times::Vector{<:Number}, values::Vector{<:Number}, pattern::Vector{<:Number})
2. stitch(ld1::LocalDetuning, ld2::LocalDetuning, boundary::Symbol=:mean)
3. function stitch(ts1::TimeSeries, ts2::TimeSeries, boundary::Symbol)
4. discretize(ld::LocalDetuning, properties::DiscretizationProperties)

I have tested thestitchand LocalDetuning(values, amplitude, pattern) locally using the values taken from the Python SDK.

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])))

julia> stitched_ld = stitch(s1, s2, :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_ld = stitch(s1, s2, :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_ld = stitch(s1, s2, :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])))

I am new to MockStructs tests , I am reading them in the ahs.test file to get more insight into it. I require guidance on how to properly use Mock structs to test discretize for LocalDetuning! Thanks!
Braket.jl/test/ahs.jl](

Braket.jl/test/ahs.jl

Lines 5 to 25 in 1d05da0

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
)

Testing done:
Testing in Progress.

Note: New to git_secrets, so please bear with me. Figuring out how to use it!

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate) [In Progress] (some tests are added)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kshyatt-aws
Copy link
Member

Thanks for the PR! I'll review this ASAP tomorrow.

@Fe-r-oz
Copy link
Author

Fe-r-oz commented Jun 8, 2024

Prepared discretize so it can be used by Mock test for LocalDetuning:

julia> 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")))
             )
Braket.DiscretizationProperties(Braket.Lattice(Braket.Area(0.001, 0.001), Braket.Geometry(1.0e-7, 1.0e-7, 1.0e-7, 200)), MockRydberg(1.0e-6, Braket.RydbergGlobal((1.0, 1.0e6), 400.0, 0.2, (1.0, 1.0e6), 0.2, 0.2, (1.0, 1.0e6), 5.0e-7, 1.0e-9, 1.0e-5, 0.0, 100.0), MockRydbergLocal(1.0e-9, 2000.0, 0.01)))

julia> discretized_ld = discretize(ld, properties)
LocalDetuning(Field(TimeSeries(OrderedCollections.OrderedDict{Number, TimeSeriesItem}(0.0 => TimeSeriesItem(0.0, 0.0), 0.1 => TimeSeriesItem(0.1, 0.0), 0.2 => TimeSeriesItem(0.2, 0.0)), true, -1), Pattern(Number[0.1, 0.3, 0.5])))

julia> @test discretized_ld isa LocalDetuning
Test Passed

@rmshaffer rmshaffer linked an issue Jun 10, 2024 that may be closed by this pull request
src/ahs.jl Outdated Show resolved Hide resolved
src/ahs.jl Outdated Show resolved Hide resolved
@kshyatt-aws
Copy link
Member

Other than some last comments this LGTM. I'll close the issue.

@Fe-r-oz
Copy link
Author

Fe-r-oz commented Jun 11, 2024

Thank you very much, @kshyatt-aws. I will surely address your comments!

@Fe-r-oz
Copy link
Author

Fe-r-oz commented Jun 13, 2024

Added suggested changed.

Local Testing Done. Results:

Test Summary: | Pass  Total   Time
AHS           | 1051   1051  48.7s
Test Summary: | Pass  Total  Time
utils         |   13     13  3.3s
Test Summary:      | Pass  Total  Time
QubitSet and Qubit |   14     14  0.3s
Test Summary:       | Pass  Total  Time
Dwave Device Schema |   15     15  2.3s
Test Summary:      | Pass  Total  Time
Ionq Device Schema |    4      4  0.9s
Test Summary:  | Pass  Total  Time
Rigetti device |    4      4  1.2s
Test Summary:               | Pass  Total  Time
Gate model simulator device |    3      3  0.2s
Test Summary:     | Pass  Total  Time
OQC device schema |    4      4  1.1s
Test Summary: | Pass  Total  Time
Quera device  |    2      2  0.5s
Test Summary: | Pass  Total  Time
Xanadu device |    3      3  0.7s
Test Summary:  | Pass  Total   Time
IR Translation |  132    132  22.3s
Test Summary: | Pass  Total     Time
Schemas       |  219    219  2m37.1s
Test Summary: | Pass  Total  Time
Devices       |   54     54  7.0s
Test Summary: | Pass  Total   Time
Circuit       |  284    284  41.9s
Test Summary:    | Pass  Total  Time
Measure operator |    7      7  0.0s
Test Summary:   | Pass  Total  Time
Free parameters |    6      6  1.2s
Test Summary: | Pass  Total   Time
Gates         |  349    349  12.0s
Test Summary: | Pass  Total  Time
Observables   |  250    250  6.1s
Test Summary: | Pass  Total  Time
Noises        |   62     62  2.1s
Test Summary: | Pass  Total  Time
Noise models  |   90     90  4.7s
Test Summary:              | Pass  Total  Time
Compiler directives basics |    8      8  0.1s
Test Summary:              | Pass  Total   Time
GateModelQuantumTaskResult |   11     11  17.7s
Test Summary:               | Pass  Total  Time
shots>0 results computation |   11     11  4.1s
Test Summary:             | Pass  Total  Time
PhotonicQuantumTaskResult |    5      5  6.1s
Test Summary:              | Pass  Broken  Total   Time
AnnealingQuantumTaskResult |   13       1     14  19.6s
Test Summary: | Pass  Total   Time
Tasks         |  128    128  10.7s
Test Summary: | Pass  Total  Time
Batched tasks |   42     42  4.4s
Test Summary: | Pass  Total  Time
Local Jobs    |  101    101  9.1s
Test Summary: | Pass  Total  Time
Job macro     |    4      4  5.4s
Test Summary: | Pass  Total     Time
Jobs          |   55     55  1m42.8s
     Testing Braket tests passed 

@Fe-r-oz Fe-r-oz requested a review from kshyatt-aws June 13, 2024 01:41
@Fe-r-oz Fe-r-oz changed the title [Feature]: Full support for local detuning feature: Full support for Local Detuning Jun 14, 2024
src/ahs.jl Outdated
"""
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can AnalogHamiltonianSimulation have a doc link?

- `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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should follow the proper doctest format like:

# Examples

[doctest here]

src/ahs.jl Outdated
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalDetuning can get a doc link here too

src/ahs.jl Outdated
"""
stitch(ts1::TimeSeries, ts2::TimeSeries; boundary::Symbol="mean")

[`stitch`](@ref) two shifting fields based on the `TimeSeries.stitch` method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeSeries.stitch isn't a valid Julia function reference? It should be just stitch

src/ahs.jl Outdated
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can TimeSeries have a doc link?

Copy link
Member

@kshyatt-aws kshyatt-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the new doc strings included in the relevant file in docs/src? Also, did you run the doctests to make sure they pass? (There's an example of how to do this in .github/workflows/CI.yml)

@Fe-r-oz Fe-r-oz requested a review from kshyatt-aws June 19, 2024 04:39
@Fe-r-oz
Copy link
Author

Fe-r-oz commented Jun 19, 2024

Local Tests for Local Detuning:

  ? Braket
     Testing Running tests...
WARNING: Method definition discretize(Braket.LocalDetuning, Braket.DiscretizationProperties) in module Braket at /home/Transcendence/Desktop/New/braket/3/Braket.jl/src/ahs.jl:441 overwritten at /home/Transcendence/Desktop/New/braket/3/Braket.jl/src/ahs.jl:451.
ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.
WARNING: Method definition discretize(Braket.LocalDetuning, Braket.DiscretizationProperties) in module Braket at /home/Transcendence/Desktop/New/braket/3/Braket.jl/src/ahs.jl:441 overwritten at /home/Transcendence/Desktop/New/braket/3/Braket.jl/src/ahs.jl:451.
Test Summary:    |Time
Method ambiguity | None  0.0s
Test Summary:           |Time
Unbound type parameters | None  0.0s
Test Summary:     | Pass  Total  Time
Undefined exports |    1      1  0.1s
Test Summary:                              | Pass  Total  Time
Compare Project.toml and test/Project.toml |    1      1  0.2s
WARNING: Method definition discretize(Braket.LocalDetuning, Braket.DiscretizationProperties) in module Braket at /home/Transcendence/Desktop/New/braket/3/Braket.jl/src/ahs.jl:441 overwritten at /home/Transcendence/Desktop/New/braket/3/Braket.jl/src/ahs.jl:451.
ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.
Test Summary:      | Pass  Total   Time
Stale dependencies |    1      1  31.2s
Test Summary: | Pass  Total  Time
Compat bounds |    4      4  0.6s
Test Summary: |Time
Piracy        | None  0.0s
Test Summary:    |Time
Persistent tasks | None  0.0s
Test Summary: | Pass  Total     Time
AHS           | 1051   1051  1m08.6s
Test Summary: | Pass  Total  Time
utils         |   13     13  4.3s
Test Summary:      | Pass  Total  Time
QubitSet and Qubit |   14     14  0.4s
Test Summary:       | Pass  Total  Time
Dwave Device Schema |   15     15  2.8s
Test Summary:      | Pass  Total  Time
Ionq Device Schema |    4      4  1.1s
Test Summary:  | Pass  Total  Time
Rigetti device |    4      4  1.4s
Test Summary:               | Pass  Total  Time
Gate model simulator device |    3      3  0.2s
Test Summary:     | Pass  Total  Time
OQC device schema |    4      4  1.4s
Test Summary: | Pass  Total  Time
Quera device  |    2      2  0.7s
Test Summary: | Pass  Total  Time
Xanadu device |    3      3  0.8s
Test Summary:  | Pass  Total   Time
IR Translation |  132    132  27.1s
Test Summary: | Pass  Total     Time
Schemas       |  219    219  4m10.8s
Test Summary: | Pass  Total  Time
Devices       |   54     54  6.7s
Test Summary: | Pass  Total   Time
Circuit       |  284    284  44.0s
Test Summary:    | Pass  Total  Time
Measure operator |    7      7  0.0s
Test Summary:   | Pass  Total  Time
Free parameters |    6      6  1.3s
Test Summary: | Pass  Total   Time
Gates         |  349    349  14.0s
Test Summary: | Pass  Total  Time
Observables   |  250    250  6.5s
Test Summary: | Pass  Total  Time
Noises        |   62     62  2.2s
Test Summary: | Pass  Total  Time
Noise models  |   90     90  4.5s
Test Summary:              | Pass  Total  Time
Compiler directives basics |    8      8  0.1s
Test Summary:              | Pass  Total   Time
GateModelQuantumTaskResult |   11     11  18.5s
Test Summary:               | Pass  Total  Time
shots>0 results computation |   11     11  4.1s
Test Summary:             | Pass  Total  Time
PhotonicQuantumTaskResult |    5      5  6.2s
Test Summary:              | Pass  Broken  Total   Time
AnnealingQuantumTaskResult |   13       1     14  20.9s
Test Summary: | Pass  Total  Time
Cost tracker  |   15     15  1.8s
Test Summary: | Pass  Total  Time
Batched tasks |   42     42  4.5s
[ Info: Using the long-lived AWS credentials found in session
Test Summary: | Pass  Total  Time
Local Jobs    |  101    101  9.7s
Test Summary: | Pass  Total  Time
Job macro     |    4      4  5.5s




Test Summary: | Pass  Total     Time
Jobs          |   55     55  1m44.3s
     Testing Braket tests passed 

@kshyatt-aws kshyatt-aws changed the base branch from main to ksh/feature_bump August 28, 2024 17:04
@kshyatt-aws kshyatt-aws merged commit dc641b6 into amazon-braket:ksh/feature_bump Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Full support for local detuning
2 participants