Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjaskula-aws committed Nov 20, 2023
1 parent f35cc38 commit fa4cb3a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/unit_tests/braket/circuits/test_angled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_is_operator(angled_gate):


def test_angle_is_none():
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="angle must not be None"):
AngledGate(qubit_count=1, ascii_symbols=["foo"], angle=None)


Expand Down
14 changes: 14 additions & 0 deletions test/unit_tests/braket/circuits/test_ascii_circuit_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ def test_one_gate_one_qubit_rotation_with_parameter():
_assert_correct_diagram(circ, expected)


def test_one_gate_with_global_phase():
circ = Circuit().x(target=0).gphase(0.15)
expected = (
"T : |0|",
" ",
"q0 : -X-",
"",
"T : |0|",
"",
"Global phase: 0.15",
)
_assert_correct_diagram(circ, expected)


def test_one_gate_one_qubit_rotation_with_unicode():
theta = FreeParameter("\u03B8")
circ = Circuit().rx(angle=theta, target=0)
Expand Down
36 changes: 36 additions & 0 deletions test/unit_tests/braket/circuits/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,22 @@ def foo(
inputs={},
),
),
(
Circuit().gphase(0.15).x(0),
OpenQasmProgram(
source="\n".join(
[
"OPENQASM 3.0;",
"bit[1] b;",
"qubit[1] q;",
"x q[0];",
"gphase(0.15);",
"b[0] = measure q[0];",
]
),
inputs={},
),
),
],
)
def test_from_ir(expected_circuit, ir):
Expand Down Expand Up @@ -3106,3 +3122,23 @@ def test_parametrized_pulse_circuit(user_defined_frame):

def test_free_param_float_mix():
Circuit().ms(0, 1, 0.1, FreeParameter("theta"))


def test_circuit_with_global_phase():
circuit = Circuit().gphase(0.15).x(0)
assert circuit.global_phase == 0.15

assert circuit.to_ir(
ir_type=IRType.OPENQASM,
serialization_properties=OpenQASMSerializationProperties(
qubit_reference_type=QubitReferenceType.PHYSICAL
),
).source == "\n".join(
[
"OPENQASM 3.0;",
"bit[1] b;",
"x $0;",
"gphase(0.15);",
"b[0] = measure $0;",
]
)
5 changes: 5 additions & 0 deletions test/unit_tests/braket/circuits/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,11 @@ def test_control_gphase_subroutine():
)


def test_angle_gphase_is_none():
with pytest.raises(ValueError, match="angle must not be None"):
Gate.GPhase(angle=None)


@pytest.mark.parametrize("testclass,subroutine_name,irclass,irsubclasses,kwargs", testdata)
def test_gate_adjoint_expansion_correct(testclass, subroutine_name, irclass, irsubclasses, kwargs):
gate = testclass(**create_valid_gate_class_input(irsubclasses, **kwargs))
Expand Down

0 comments on commit fa4cb3a

Please sign in to comment.