Skip to content

Commit

Permalink
change: Update to new BraketSimulator interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt-aws committed Jun 20, 2024
1 parent 1d05da0 commit 2329f6a
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions src/local_simulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ simulator. Returns a [`LocalQuantumTask`](@ref Braket.LocalQuantumTask).
"""
function simulate(d::LocalSimulator, task_spec::Union{Circuit, 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...)

Check warning on line 64 in src/local_simulator.jl

View check run for this annotation

Codecov / codecov/patch

src/local_simulator.jl#L64

Added line #L64 was not covered by tests
return LocalQuantumTask(local_result.task_metadata.id, local_result)
end

Expand Down Expand Up @@ -152,45 +149,31 @@ 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...)

Check warning on line 152 in src/local_simulator.jl

View check run for this annotation

Codecov / codecov/patch

src/local_simulator.jl#L152

Added line #L152 was not covered by tests
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)

Check warning on line 155 in src/local_simulator.jl

View check run for this annotation

Codecov / codecov/patch

src/local_simulator.jl#L155

Added line #L155 was not covered by tests
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...)

Check warning on line 158 in src/local_simulator.jl

View check run for this annotation

Codecov / codecov/patch

src/local_simulator.jl#L158

Added line #L158 was not covered by tests
return format_result(r)
else
throw(ErrorException("$(typeof(simulator)) does not support qubit gate-based programs."))
end
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)

Check warning on line 167 in src/local_simulator.jl

View check run for this annotation

Codecov / codecov/patch

src/local_simulator.jl#L166-L167

Added lines #L166 - L167 were not covered by tests
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)

Check warning on line 176 in src/local_simulator.jl

View check run for this annotation

Codecov / codecov/patch

src/local_simulator.jl#L174-L176

Added lines #L174 - L176 were not covered by tests
else
throw(ErrorException("$(typeof(simulator)) does not support qubit gate-based programs."))
end
Expand Down

0 comments on commit 2329f6a

Please sign in to comment.