Skip to content

Commit

Permalink
fix: Use a placeholder action instead of trying to translate a circuit (
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt-aws authored May 1, 2024
1 parent 964ae80 commit 3b09ba0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ext/BraketSimulatorPythonExt/BraketSimulatorPythonExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ function simulate(
PythonCall.GC.disable()
if length(jl_specs) == 1
result = simulate(simulator, jl_specs[1], args[1:end-1]...; inputs = jl_inputs, shots=shots, kwargs...)
py_result = Py(result, task_specs[1])
py_result = Py(result)
else # this is a batch! use a Braket.jl LocalSimulator to take advantage of thread migration
local_sim = Braket.LocalSimulator(simulator)
task_batch = simulate(local_sim, jl_specs, args[1:end-1]...; inputs = jl_inputs, shots=shots, kwargs...)
raw_results = results(task_batch)
# now have to convert back to GateModelTaskResult from GateModelQuantumTaskResult
processed_results = map(zip(raw_results, task_specs)) do (result, task_spec)
header = Braket.braketSchemaHeader("braket.task_result.gate_model_task_result", "1")
return Py(Braket.GateModelTaskResult(header, result.measurements, result.measurement_probabilities, result.result_types, result.measured_qubits, result.task_metadata, result.additional_metadata), task_spec)
return Py(Braket.GateModelTaskResult(header, result.measurements, result.measurement_probabilities, result.result_types, result.measured_qubits, result.task_metadata, result.additional_metadata))
end
py_result = pylist(processed_results)
end
Expand Down
6 changes: 4 additions & 2 deletions ext/BraketSimulatorPythonExt/translation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,14 @@ function Py(ir::Program)
return braket[].ir.jaqcd.program_v1.Program(instructions=pylist(ir.instructions), results=res, basis_rotation_instructions=bris)
end

function Py(r::GateModelTaskResult, action)
function Py(r::GateModelTaskResult)
py_measurements = (isnothing(r.measurements) || isempty(r.measurements)) ? PythonCall.pybuiltins.None : pylist(pylist(meas) for meas in r.measurements)
py_probabilities = !isnothing(r.measurementProbabilities) ? pydict(Dict(pystr(k)=>v for (k,v) in r.measurementProbabilities)) : PythonCall.pybuiltins.None
py_qubits = !isnothing(r.measuredQubits) ? pylist(r.measuredQubits) : PythonCall.pybuiltins.None
py_results = pylist(Py(rtv) for rtv in r.resultTypes)
py_task_mtd = braket[].task_result.task_metadata_v1.TaskMetadata(id=pystr(r.taskMetadata.id), shots=Py(r.taskMetadata.shots), deviceId=pystr(r.taskMetadata.deviceId))
py_addl_mtd = braket[].task_result.additional_metadata.AdditionalMetadata(action=action)
# we create a placeholder OpenQASM3 Program here -- this is replaced by the "true" action in the Python wrapper
dummy_action = braket[].ir.openqasm.program_v1.Program(source=pystr(""))
py_addl_mtd = braket[].task_result.additional_metadata.AdditionalMetadata(action=dummy_action)
return braket[].task_result.GateModelTaskResult(measurements=py_measurements, measurementProbabilities=py_probabilities, resultTypes=py_results, measuredQubits=py_qubits, taskMetadata=py_task_mtd, additionalMetadata=py_addl_mtd)
end

0 comments on commit 3b09ba0

Please sign in to comment.