Skip to content

Commit

Permalink
Add new simulator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laurencap committed Nov 10, 2023
1 parent 9472840 commit 8f4d277
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion test/unit_tests/braket/experimental/autoqasm/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

def _test_parametric_on_local_sim(program: aq.Program, inputs: dict[str, float]) -> None:
device = LocalSimulator(backend=StateVectorSimulator())
task = device.run(program, shots=10, inputs=inputs)
task = device.run(program, shots=100, inputs=inputs)
assert isinstance(task, LocalQuantumTask)
assert isinstance(task.result().measurements, dict)
return task.result().measurements
Expand Down Expand Up @@ -610,6 +610,34 @@ def parametric(basis: int):
assert parametric(FreeParameter("basis")).to_ir() == expected


def test_sim_conditional_stmts():
@aq.main
def main(basis: int):
if basis == 1:
h(0)
else:
x(0)
c = measure(0) # noqa: F841

measurements = _test_parametric_on_local_sim(main(FreeParameter("basis")), {"basis": 0})
assert all(val == 1 for val in measurements["c"])
measurements = _test_parametric_on_local_sim(main(FreeParameter("basis")), {"basis": 1})
assert 1 in measurements["c"] and 0 in measurements["c"]


def test_sim_comparison_stmts():
@aq.main
def main(basis: int):
if basis > 0.5:
x(0)
c = measure(0) # noqa: F841

measurements = _test_parametric_on_local_sim(main(FreeParameter("basis")), {"basis": 0.5})
assert all(val == 0 for val in measurements["c"])
measurements = _test_parametric_on_local_sim(main(FreeParameter("basis")), {"basis": 0.55})
assert all(val == 1 for val in measurements["c"])


def test_param_neq():
"""Test parameters used in conditional not equals statements."""

Expand Down

0 comments on commit 8f4d277

Please sign in to comment.