GithubHelp home page GithubHelp logo

braketsimulator.jl's People

Contributors

amazon-auto avatar krneta avatar kshyatt-aws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

braketsimulator.jl's Issues

Support for the `AdjointGradient` result type

Describe the feature you'd like
Native Julia implementation of the adjoint gradient differentiation method for the StateVectorSimulator. Amazon Braket's on-demand state vector simulator SV1 currently supports this differentiation method, but the Python local state vector simulator does not.

How would this feature be used? Please describe.
This differentiation method would allow efficient computation of gradients of parameterized circuits locally and in parallel for exact state vector simulations.

Describe alternatives you've considered
N/A

Additional context
See the Amazon Braket/Pennylane Adjoint Gradient blog for an example of how this might be used. Since the simulator doesn't currently support arbitrary functions for elements of quantum gates, a fallback to finite differences (for applying the chain rule to functions which aren't continuously differentiable) isn't needed.

For smaller circuits, using Julia's dynamic/nested threading capabilities (being careful to avoid running out of memory) would be useful.

Support for `Sum` observable type in `Expectation`, `Variance`, `AdjointGradient` result types for `shots=0`

Describe the feature you'd like
Currently, Amazon Braket's on-demand state vector simulator only supports the Sum observable type for AdjointGradient results. However, this is a natural construct for Expectation and Variance when shots=0 (for exact, non-sampled workloads).

How would this feature be used? Please describe.
Users would be able to construct Sum observables and measure them in Expectation and Variance when shots=0.

Describe alternatives you've considered
Right now, users have to explicitly create Expectation/Variances for each term in the sum and combine them by hand.

Additional context
This is another opportunity to carefully use dynamic threading for smaller circuits for a performance improvement.

Expanded support for quantum chemistry operations

Describe the feature you'd like
Currently we support DoubleExcitation and SingleExcitation, which are spin-preserving (cannot move between different spin sectors). PennyLane's qchem supports a wider variety of gates relevant to quantum chemistry. Adding support for these natively in the local simulator would improve performance for various quantum chemistry workflows, like VQE.

How would this feature be used? Please describe.
This would allow a PennyLane device wrapping this simulator to indicate it supports these gates natively, bypassing the PennyLane decomposition process and improving performance when PennyLane users supply quantum chemistry circuits to this simulator.

Describe alternatives you've considered
Currently we can use the PennyLane-defined decompositions, but this may turn one gate into 8+ which is less efficient.

Additional context
See src/custom_gates.jl for DoubleExcitation and SingleExcitation implementations, which can serve as templates. Implementations of inv and ^ for these gates as well as correctness tests would be needed.

Monte Carlo based noise simulation

Describe the feature you'd like
A new simulator which implements Monte Carlo sampling to perform trajectory-based noise simulation. This would be shots>0 only but would allow qubit counts up to the maximum the state vector simulator supports.

How would this feature be used? Please describe.
Allows simulation of noisy circuits with >= 16 qubits.

Describe alternatives you've considered
We have already implemented the "exact" form of noise simulation, density matrix based noise simulation. This allows users to trade accuracy for higher qubit counts.

Additional context
There is another opportunity here to use threaded parallelism but this will require care when interacting with the random number generator for the Monte Carlo moves.

Multi-node/hybrid support with Dagger.jl

Describe the feature you'd like
Use Dagger.jl to provide multi-node and/or hybrid (multi-thread on multiple nodes) parallelism for large batches of tasks.

How would this feature be used? Please describe.
Users would add Dagger workers (using their local HPC cluster or some cloud resource) and use the Dagger scheduler to handle partitioning batch items among them.

Describe alternatives you've considered
For multi-node support, Julia's builtin Distributed stdlib would be an option. Dagger.jl provides a graph-based scheduler and the ability to tag resources needed (for example, GPUs) which are a bit more sophisticated.

Additional context
A Julia package extension would be a natural way to add support for this.

bug: Doctest for docs/src/index.md errors locally

Doctest for docs/src/index.md Errors Locally
Doctests for all the other tests passes locally but when testing the entire package via doctest(BraketSimulator), doctest for docs/src/index.md fails. This prevents all the doctests from running locally.

To make sure that error was independent of my local branch, I made a new branch Doctest solely to run doctests on that branch locally and got the same error!

To reproduce

[ Info: Disabling history file for this session
julia> using BraketSimulator

julia> using Documenter

julia> doctest(BraketSimulator)
┌ Warning: Unable to determine HTML(edit_link = ...) from remote HEAD branch, defaulting to "master".
│ Calling `git remote` failed with an exception. Set JULIA_DEBUG=Documenter to see the error.
│ Unless this is due to a configuration error, the relevant variable should be set explicitly.
└ @ Documenter ~/.julia/packages/Documenter/CJeWX/src/utilities/utilities.jl:640
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
┌ Error: doctest failure in ~/Desktop/New/qchem/BraketSimulator.jl/docs/src/index.md:38-58
│ 
│ ```jldoctest
│ julia> using Braket, BraketSimulator
│ 
│ julia> n_qubits = 10;
│ 
│ julia> c = Circuit();
│ 
│ julia> H(c, 0);
│ 
│ julia> foreach(q->CNot(c, 0, q), 1:n_qubits-1);
│ 
│ julia> Amplitude(c, [repeat("0", n_qubits), repeat("1", n_qubits)]);
│ 
│ julia> sim = LocalSimulator("braket_sv_v2"); # use the state vector simulator (without noise)
│ 
│ julia> res = result(simulate(sim, ir(c, Val(:JAQCD)), shots=0));
│ 
│ julia> res.values
│ 1-element Vector{Any}:
│  Dict{String, ComplexF64}("0000000000" => 0.7071067811865475 + 0.0im, "1111111111" => 0.7071067811865475 + 0.0im)
│ ```
│ 
│ Subexpression:
│ 
│ res = result(simulate(sim, ir(c, Val(:JAQCD)), shots=0));
│ 
│ Evaluated output:
│ 
│ ERROR: MethodError: no method matching simulate(::StateVectorSimulator{ComplexF64, Vector{ComplexF64}}, ::Braket.IR.Program, ::Int64, ::Int64; inputs::Dict{String, Float64})
│ 
│ Closest candidates are:
│   simulate(::BraketSimulator.AbstractSimulator, ::Braket.IR.Program, ::Int64; shots, kwargs...)
│    @ BraketSimulator ~/Desktop/New/qchem/BraketSimulator.jl/src/BraketSimulator.jl:236
│   simulate(!Matched::LocalSimulator, ::Union{Braket.AbstractProgram, AnalogHamiltonianSimulation, Circuit}, ::Any...; shots, inputs, kwargs...)
│    @ Braket ~/Desktop/New/braket/2/Braket.jl/src/local_simulator.jl:62
│   simulate(!Matched::LocalSimulator, !Matched::Vector{T}, ::Any...; shots, max_parallel, inputs, kwargs...) where T
│    @ Braket ~/Desktop/New/braket/2/Braket.jl/src/local_simulator.jl:93
│   ...
│ 
│ Stacktrace:
│  [1] _run_internal(::StateVectorSimulator{ComplexF64, Vector{ComplexF64}}, ::Braket.IR.Program; shots::Int64, inputs::Dict{String, Float64}, kwargs::@Kwargs{})
│    @ Braket ~/Desktop/New/braket/2/Braket.jl/src/local_simulator.jl:175
│  [2] simulate(::LocalSimulator, ::Braket.IR.Program; shots::Int64, inputs::Dict{String, Float64}, kwargs::@Kwargs{})
│    @ Braket ~/Desktop/New/braket/2/Braket.jl/src/local_simulator.jl:64
│  [3] top-level scope
│    @ none:1
│ 
│ Expected output:
│ 
│ 
│ 
│   diff =
│    ERROR: MethodError: no method matching simulate(::StateVectorSimulator{ComplexF64, Vector{ComplexF64}}, ::Braket.IR.Program, ::Int64, ::Int64; inputs::Dict{String, Float64})                                                                                                                                            
│    
│    Closest candidates are:
│      simulate(::BraketSimulator.AbstractSimulator, ::Braket.IR.Program, ::Int64; shots, kwargs...)
│       @ BraketSimulator ~/Desktop/New/qchem/BraketSimulator.jl/src/BraketSimulator.jl:236
│      simulate(!Matched::LocalSimulator, ::Union{Braket.AbstractProgram, AnalogHamiltonianSimulation, Circuit}, ::Any...; shots, inputs, kwargs...)
│       @ Braket ~/Desktop/New/braket/2/Braket.jl/src/local_simulator.jl:62
│      simulate(!Matched::LocalSimulator, !Matched::Vector{T}, ::Any...; shots, max_parallel, inputs, kwargs...) where T
│       @ Braket ~/Desktop/New/braket/2/Braket.jl/src/local_simulator.jl:93
│      ...
│    
│    Stacktrace:
│     [1] _run_internal(::StateVectorSimulator{ComplexF64, Vector{ComplexF64}}, ::Braket.IR.Program; shots::Int64, inputs::Dict{String, Float64}, kwargs::@Kwargs{})                                                                                                                                                          
│       @ Braket ~/Desktop/New/braket/2/Braket.jl/src/local_simulator.jl:175
│     [2] simulate(::LocalSimulator, ::Braket.IR.Program; shots::Int64, inputs::Dict{String, Float64}, kwargs::@Kwargs{})
│       @ Braket ~/Desktop/New/braket/2/Braket.jl/src/local_simulator.jl:64
│     [3] top-level scope
│       @ none:1
└ @ Documenter ~/Desktop/New/qchem/BraketSimulator.jl/docs/src/index.md:38
┌ Error: doctest failure in ~/Desktop/New/qchem/BraketSimulator.jl/docs/src/index.md:38-58
│ 
│ ```jldoctest
│ julia> using Braket, BraketSimulator
│ 
│ julia> n_qubits = 10;
│ 
│ julia> c = Circuit();
│ 
│ julia> H(c, 0);
│ 
│ julia> foreach(q->CNot(c, 0, q), 1:n_qubits-1);
│ 
│ julia> Amplitude(c, [repeat("0", n_qubits), repeat("1", n_qubits)]);
│ 
│ julia> sim = LocalSimulator("braket_sv_v2"); # use the state vector simulator (without noise)
│ 
│ julia> res = result(simulate(sim, ir(c, Val(:JAQCD)), shots=0));
│ 
│ julia> res.values
│ 1-element Vector{Any}:
│  Dict{String, ComplexF64}("0000000000" => 0.7071067811865475 + 0.0im, "1111111111" => 0.7071067811865475 + 0.0im)
│ ```
│ 
│ Subexpression:
│ 
│ res.values
│ 
│ Evaluated output:
│ 
│ ERROR: UndefVarError: `res` not defined
│ Stacktrace:
│  [1] top-level scope
│    @ none:1
│ 
│ Expected output:
│ 
│ 1-element Vector{Any}:
│  Dict{String, ComplexF64}("0000000000" => 0.7071067811865475 + 0.0im, "1111111111" => 0.7071067811865475 + 0.0im)
│ 
│   diff =
│    1-element Vector{Any}:
│     Dict{String, ComplexF64}("0000000000" => 0.7071067811865475 + 0.0im, "1111111111" => 0.7071067811865475 + 0.0im)ERROR: UndefVarError: `res` not defined
│    Stacktrace:
│     [1] top-level scope
│       @ none:1
└ @ Documenter ~/Desktop/New/qchem/BraketSimulator.jl/docs/src/index.md:38
┌ Error: Doctesting failed
│   exception =
│    `makedocs` encountered a doctest error. Terminating build
│    Stacktrace:
│      [1] error(s::String)
│        @ Base ./error.jl:35
│      [2] runner(::Type{Documenter.Builder.Doctest}, doc::Documenter.Document)
│        @ Documenter ~/.julia/packages/Documenter/CJeWX/src/builder_pipeline.jl:212
│      [3] dispatch(::Type{Documenter.Builder.DocumentPipeline}, x::Documenter.Document)
│        @ Documenter.Selectors ~/.julia/packages/Documenter/CJeWX/src/utilities/Selectors.jl:170
│      [4] #86
│        @ ~/.julia/packages/Documenter/CJeWX/src/makedocs.jl:248 [inlined]
│      [5] withenv(::Documenter.var"#86#88"{Documenter.Document}, ::Pair{String, Nothing}, ::Vararg{Pair{String, Nothing}})
│        @ Base ./env.jl:257
│      [6] #85
│        @ ~/.julia/packages/Documenter/CJeWX/src/makedocs.jl:247 [inlined]
│      [7] cd(f::Documenter.var"#85#87"{Documenter.Document}, dir::String)
│        @ Base.Filesystem ./file.jl:112
│      [8] makedocs(; debug::Bool, format::Documenter.HTMLWriter.HTML, kwargs::@Kwargs{root::String, source::String, sitename::String, doctest::Symbol, modules::Vector{Module}, doctestfilters::Vector{Regex}, remotes::Nothing, plugins::Vector{Documenter.Plugin}})                                                        
│        @ Documenter ~/.julia/packages/Documenter/CJeWX/src/makedocs.jl:247
│      [9] (::Documenter.var"#all_doctests#131"{Bool, Vector{Regex}, Vector{Documenter.Plugin}, Vector{Module}})()
│        @ Documenter ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:82
│     [10] macro expansion
│        @ ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:107 [inlined]
│     [11] macro expansion
│        @ ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Test/src/Test.jl:669 [inlined]
│     [12] macro expansion
│        @ ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:107 [inlined]
│     [13] macro expansion
│        @ ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
│     [14] doctest(source::String, modules::Vector{Module}; fix::Bool, testset::String, doctestfilters::Vector{Regex}, plugins::Vector{Documenter.Plugin})
│        @ Documenter ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:107
│     [15] doctest
│        @ ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:66 [inlined]
│     [16] doctest(package::Module; manual::Bool, testset::Nothing, kwargs::@Kwargs{})
│        @ Documenter ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:34
│     [17] doctest(package::Module)
│        @ Documenter ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:20
│     [18] top-level scope
│        @ REPL[26379]:1
│     [19] eval
│        @ ./boot.jl:385 [inlined]
│     [20] eval_user_input(ast::Any, backend::REPL.REPLBackend, mod::Module)
│        @ REPL ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:150
│     [21] repl_backend_loop(backend::REPL.REPLBackend, get_module::Function)
│        @ REPL ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:246
│     [22] start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function)
│        @ REPL ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:231
│     [23] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool, backend::Any)
│        @ REPL ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:389
│     [24] run_repl(repl::REPL.AbstractREPL, consumer::Any)
│        @ REPL ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:375
│     [25] (::Base.var"#1013#1015"{Bool, Bool, Bool})(REPL::Module)
│        @ Base ./client.jl:432
│     [26] #invokelatest#2
│        @ ./essentials.jl:892 [inlined]
│     [27] invokelatest
│        @ ./essentials.jl:889 [inlined]
│     [28] run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool)
│        @ Base ./client.jl:416
│     [29] exec_options(opts::Base.JLOptions)
│        @ Base ./client.jl:333
│     [30] _start()
│        @ Base ./client.jl:552
└ @ Documenter ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:96
Doctests: BraketSimulator: Test Failed at /home/.julia/packages/Documenter/CJeWX/src/doctest.jl:107
  Expression: all_doctests()

Stacktrace:
 [1] macro expansion
   @ ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Test/src/Test.jl:672 [inlined]
 [2] macro expansion
   @ ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:107 [inlined]
 [3] macro expansion
   @ ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
 [4] doctest(source::String, modules::Vector{Module}; fix::Bool, testset::String, doctestfilters::Vector{Regex}, plugins::Vector{Documenter.Plugin})
   @ Documenter ~/.julia/packages/Documenter/CJeWX/src/doctest.jl:107
Test Summary:             | Fail  Total  Time
Doctests: BraketSimulator |    1      1  9.8s
ERROR: Some tests did not pass: 0 passed, 1 failed, 0 errored, 0 broken.

Also, locally, I was getting this error as well which I fixed locally by setting StaticArrays to "=1.9.5"


ERROR: Unsatisfiable requirements detected for package StaticArrays [90137ffa]:
 StaticArrays [90137ffa] log:
 ├─possible versions are: 0.8.0-1.9.5 or uninstalled
 ├─restricted to versions 1.9.5 by Braket [19504a0f], leaving only versions: 1.9.5
 │ └─Braket [19504a0f] log:
 │   ├─possible versions are: 0.9.0 or uninstalled
 │   └─Braket [19504a0f] is fixed to version 0.9.0
 └─restricted to versions 1.9.3 by BraketSimulator [76d27892] — no versions left
   └─BraketSimulator [76d27892] log:
     ├─possible versions are: 0.0.1 or uninstalled
     └─BraketSimulator [76d27892] is fixed to version 0.0.1

Expected behavior
Doctest should pass for docs/src/index.md Errors Locally

System Information
Linux-based Distribution

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.