Skip to content

Commit

Permalink
bug: Fixup numerical imprecision
Browse files Browse the repository at this point in the history
  • Loading branch information
laurencap committed Oct 30, 2023
1 parent 6a68b6c commit fb58273
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/unit_tests/braket/experimental/autoqasm/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

"""AutoQASM tests for parameter support."""

import numpy as np

import braket.experimental.autoqasm as aq
from braket.circuits import FreeParameter
from braket.default_simulator import StateVectorSimulator
Expand Down Expand Up @@ -51,7 +53,7 @@ def test_simple_parametric():
def test_sim_simple():
measurements = _test_parametric_on_local_sim(simple_parametric(), {"theta": 0})
assert 1 not in measurements["__bit_0__"]
measurements = _test_parametric_on_local_sim(simple_parametric(), {"theta": 3.14})
measurements = _test_parametric_on_local_sim(simple_parametric(), {"theta": np.pi})
assert 0 not in measurements["__bit_0__"]


Expand Down Expand Up @@ -80,9 +82,9 @@ def test_multiple_parameters():


def test_sim_multi_param():
measurements = _test_parametric_on_local_sim(multi_parametric(), {"alpha": 3.14, "theta": 0})
measurements = _test_parametric_on_local_sim(multi_parametric(), {"alpha": np.pi, "theta": 0})
assert all(val == "10" for val in measurements["c"])
measurements = _test_parametric_on_local_sim(multi_parametric(), {"alpha": 0, "theta": 3.14})
measurements = _test_parametric_on_local_sim(multi_parametric(), {"alpha": 0, "theta": np.pi})
assert all(val == "01" for val in measurements["c"])


Expand Down Expand Up @@ -171,7 +173,7 @@ def test_sim_multi_angle():
def parametric(phi: float, theta: float):
ms(0, 1, phi, phi, theta)

_test_parametric_on_local_sim(parametric(FreeParameter("phi"), 0.0), {"phi": 3.14})
_test_parametric_on_local_sim(parametric(FreeParameter("phi"), 0.0), {"phi": np.pi})


def test_parameters_passed_as_main_arg():
Expand Down Expand Up @@ -243,7 +245,7 @@ def parametric():
rx_theta(FreeParameter("theta"))
measure(0)

measurements = _test_parametric_on_local_sim(parametric(), {"theta": 3.14})
measurements = _test_parametric_on_local_sim(parametric(), {"theta": np.pi})
assert 0 not in measurements["__bit_0__"]


Expand Down

0 comments on commit fb58273

Please sign in to comment.