Skip to content

Commit

Permalink
fix: Pass through inputs for SerializableProgram simulation (#1033)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmshaffer authored Sep 23, 2024
1 parent 2ddb3d2 commit fd597d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/braket/devices/local_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ def _(self, program: OpenQASMProgram, inputs: Optional[dict[str, float]], _shots
return program

@_construct_payload.register
def _(self, program: SerializableProgram, _inputs, _shots):
return OpenQASMProgram(source=program.to_ir(ir_type=IRType.OPENQASM))
def _(self, program: SerializableProgram, inputs: Optional[dict[str, float]], _shots):
inputs_copy = inputs.copy() if inputs is not None else {}
return OpenQASMProgram(source=program.to_ir(ir_type=IRType.OPENQASM), inputs=inputs_copy)

@_construct_payload.register
def _(self, program: AnalogHamiltonianSimulation, _inputs, _shots):
Expand Down
21 changes: 19 additions & 2 deletions test/unit_tests/braket/devices/test_local_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,17 +588,34 @@ def test_run_serializable_program_model():
source="""
qubit[2] q;
bit[2] c;
h q[0];
cnot q[0], q[1];
c = measure q;
"""
)
)
assert task.result() == GateModelQuantumTaskResult.from_object(GATE_MODEL_RESULT)


def test_run_serializable_program_model_with_inputs():
dummy = DummySerializableProgramSimulator()
sim = LocalSimulator(dummy)
task = sim.run(
DummySerializableProgram(
source="""
input float a;
qubit[2] q;
bit[2] c;
h q[0];
cnot q[0], q[1];
c = measure q;
"""
),
inputs={"a": 0.1},
)
assert task.result() == GateModelQuantumTaskResult.from_object(GATE_MODEL_RESULT)


@pytest.mark.xfail(raises=ValueError)
def test_run_gate_model_value_error():
dummy = DummyCircuitSimulator()
Expand Down

0 comments on commit fd597d6

Please sign in to comment.