From 10c6548576e53725705d1b2a70b26fde35c38e32 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt <67932820+kshyatt-aws@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:51:43 -0400 Subject: [PATCH] change: Update to new BraketSimulator interface (#90) --- .github/workflows/CI.yml | 4 ++-- PyBraket/CondaPkg.toml | 6 ++++-- src/local_simulator.jl | 35 +++++++++-------------------------- test/task_batch.jl | 2 +- 4 files changed, 16 insertions(+), 31 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 55a09cea..8b9b8855 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -20,7 +20,7 @@ jobs: # don't run on draft PRs if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }} # allow windows to fail - continue-on-error: ${{ matrix.os == 'windows-latest' }} + continue-on-error: ${{ matrix.os == 'windows-latest' || matrix.group == 'PyBraket-unit' }} strategy: fail-fast: true max-parallel: 2 @@ -61,7 +61,7 @@ jobs: # don't run on draft PRs if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }} # allow failures on nightly or beta Julia - continue-on-error: ${{ matrix.version == 'nightly'}} + continue-on-error: ${{ matrix.version == 'nightly' || matrix.group == 'PyBraket-unit' }} strategy: fail-fast: true max-parallel: 2 diff --git a/PyBraket/CondaPkg.toml b/PyBraket/CondaPkg.toml index 48fd26b0..5671c946 100644 --- a/PyBraket/CondaPkg.toml +++ b/PyBraket/CondaPkg.toml @@ -1,9 +1,11 @@ [deps] -python = ">=3" +python = ">=3.9,<=3.11" pydantic = "" scipy = "" numpy = "" [pip.deps] -amazon-braket-sdk = ">=1.70.0" +amazon-braket-sdk = ">=1.81.0" amazon-braket-default-simulator = ">=1.10.0" +urllib3 = "<2" +botocore = ">=1.34" diff --git a/src/local_simulator.jl b/src/local_simulator.jl index 95d0eeaf..ca1ca880 100644 --- a/src/local_simulator.jl +++ b/src/local_simulator.jl @@ -61,10 +61,7 @@ simulator. Returns a [`LocalQuantumTask`](@ref Braket.LocalQuantumTask). """ function simulate(d::LocalSimulator, task_spec::Union{Circuit, AnalogHamiltonianSimulation, AbstractProgram}, args...; shots::Int=0, inputs::Dict{String, Float64} = Dict{String, Float64}(), kwargs...) sim = d._delegate - @debug "Single task. Starting run..." - stats = @timed _run_internal(sim, task_spec, args...; inputs=inputs, shots=shots, kwargs...) - @debug "Single task. Time to run internally: $(stats.time). GC time: $(stats.gctime)." - local_result = stats.value + local_result = _run_internal(sim, task_spec, args...; inputs=inputs, shots=shots, kwargs...) return LocalQuantumTask(local_result.task_metadata.id, local_result) end @@ -152,13 +149,13 @@ function _run_internal(simulator, circuit::Circuit, args...; shots::Int=0, input program = ir(circuit, Val(:OpenQASM)) full_inputs = isnothing(program.inputs) ? inputs : merge(program.inputs, inputs) full_program = OpenQasmProgram(program.braketSchemaHeader, program.source, full_inputs) - r = simulate(simulator, full_program, args...; shots=shots, kwargs...) + r = simulate(simulator, full_program, shots; kwargs...) return format_result(r) elseif haskey(properties(simulator).action, "braket.ir.jaqcd.program") - validate_circuit_and_shots(circuit, shots) + validate_circuit_and_shots(circuit, shots) program = ir(circuit, Val(:JAQCD)) qubits = qubit_count(circuit) - r = simulate(simulator, program, qubits, args...; shots=shots, inputs=inputs, kwargs...) + r = simulate(simulator, program, qubits, shots; inputs=inputs, kwargs...) return format_result(r) else throw(ErrorException("$(typeof(simulator)) does not support qubit gate-based programs.")) @@ -166,31 +163,17 @@ function _run_internal(simulator, circuit::Circuit, args...; shots::Int=0, input end function _run_internal(simulator, program::OpenQasmProgram, args...; shots::Int=0, inputs::Dict{String, Float64}=Dict{String, Float64}(), kwargs...) if haskey(properties(simulator).action, "braket.ir.openqasm.program") - stats = @timed begin - simulate(simulator, program; shots=shots, inputs=inputs, kwargs...) - end - @debug "Time to invoke simulator: $(stats.time)" - r = stats.value - stats = @timed format_result(r) - @debug "Time to format results: $(stats.time)" - return stats.value + r = simulate(simulator, program, shots; inputs=inputs, kwargs...) + return format_result(r) else throw(ErrorException("$(typeof(simulator)) does not support qubit gate-based programs.")) end end function _run_internal(simulator, program::Program, args...; shots::Int=0, inputs::Dict{String, Float64}=Dict{String, Float64}(), kwargs...) if haskey(properties(simulator).action, "braket.ir.jaqcd.program") - stats = @timed qubit_count(program) - @debug "Time to get qubit count: $(stats.time)" - qubits = stats.value - stats = @timed begin - simulate(simulator, program, qubits, args...; shots=shots, inputs=inputs, kwargs...) - end - @debug "Time to invoke simulator: $(stats.time)" - r = stats.value - stats = @timed format_result(r) - @debug "Time to format results: $(stats.time)" - return stats.value + qubits = qubit_count(program) + r = simulate(simulator, program, qubits, shots; inputs=inputs, kwargs...) + return format_result(r) else throw(ErrorException("$(typeof(simulator)) does not support qubit gate-based programs.")) end diff --git a/test/task_batch.jl b/test/task_batch.jl index bb395741..057fb080 100644 --- a/test/task_batch.jl +++ b/test/task_batch.jl @@ -89,7 +89,7 @@ XANADU_ARN = "arn:aws:braket:us-east-1::device/qpu/xanadu/Borealis" n_tasks = 10 raw_tasks = [Braket.AwsQuantumTask("arn:fake:$i") for i in 1:n_tasks] specs = [c for ix in 1:n_tasks] - t = Braket.AwsQuantumTaskBatch(deepcopy(raw_tasks), nothing, Set{String}(), "fake_device", specs, ("fake_bucket", "fake_prefix"), 100, 1, 10) + t = Braket.AwsQuantumTaskBatch(copy(raw_tasks), nothing, Set{String}(), "fake_device", specs, ("fake_bucket", "fake_prefix"), 100, 1, 10) t._results = fill("fake_result", n_tasks) @test isnothing(Braket.retry_unsuccessful_tasks(t)) t._results = convert(Vector{Any}, fill(nothing, n_tasks))