diff --git a/ext/BraketSimulatorPythonExt/BraketSimulatorPythonExt.jl b/ext/BraketSimulatorPythonExt/BraketSimulatorPythonExt.jl index 802923e..2550a80 100644 --- a/ext/BraketSimulatorPythonExt/BraketSimulatorPythonExt.jl +++ b/ext/BraketSimulatorPythonExt/BraketSimulatorPythonExt.jl @@ -292,7 +292,7 @@ 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...) @@ -300,7 +300,7 @@ function simulate( # 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 diff --git a/ext/BraketSimulatorPythonExt/translation.jl b/ext/BraketSimulatorPythonExt/translation.jl index 7208c2b..125c65e 100644 --- a/ext/BraketSimulatorPythonExt/translation.jl +++ b/ext/BraketSimulatorPythonExt/translation.jl @@ -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