Skip to content

Commit fa898c9

Browse files
committed
Add unit tests for CliffordGate.__repr__()
1 parent 292edbc commit fa898c9

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

cirq-core/cirq/ops/clifford_gate_test.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,27 @@ def test_all_single_qubit_clifford_unitaries():
923923
assert cirq.equal_up_to_global_phase(cs[23], (i - 1j * (-x - y - z)) / 2)
924924

925925

926+
def test_clifford_gate_repr():
927+
q0, q1, q2 = cirq.LineQubit.range(3)
928+
gates: list[cirq.ops.CliffordGate] = [
929+
# Common gates
930+
cirq.ops.CliffordGate.CNOT,
931+
cirq.ops.CliffordGate.CZ,
932+
cirq.ops.CliffordGate.SWAP,
933+
# Other gates
934+
cirq.ops.CliffordGate.from_op_list(
935+
[cirq.ops.PhasedXZGate(axis_phase_exponent=0.25, x_exponent=-1, z_exponent=0).on(q0)],
936+
[q0],
937+
),
938+
cirq.ops.CliffordGate.from_op_list([cirq.ops.X(q0), cirq.CZ(q1, q2)], [q0, q1, q2]),
939+
]
940+
for gate in gates:
941+
t = gate.clifford_tableau
942+
assert repr(gate) == f"Clifford Gate with Tableau:\n{t._str_full_()}"
943+
944+
926945
def test_single_qubit_clifford_gate_repr():
946+
# Common gates
927947
assert repr(cirq.ops.SingleQubitCliffordGate.X) == (
928948
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
929949
'rs=np.array([False, True]), xs=np.array([[True], [False]]), '
@@ -950,8 +970,22 @@ def test_single_qubit_clifford_gate_repr():
950970
'zs=np.array([[False], [True]])))'
951971
)
952972

953-
assert str(cirq.ops.SingleQubitCliffordGate.X) == (
973+
assert repr(cirq.ops.SingleQubitCliffordGate.X) == (
954974
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
955975
'rs=np.array([False, True]), xs=np.array([[True], [False]]), '
956976
'zs=np.array([[False], [True]])))'
957977
)
978+
979+
# Other gates
980+
qa = cirq.NamedQubit('a')
981+
gate = cirq.ops.SingleQubitCliffordGate.from_clifford_tableau(
982+
cirq.ops.CliffordGate.from_op_list(
983+
[cirq.ops.PhasedXZGate(axis_phase_exponent=0.25, x_exponent=-1, z_exponent=0).on(qa)],
984+
[qa],
985+
).clifford_tableau
986+
)
987+
assert repr(gate) == (
988+
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
989+
'rs=np.array([False, True]), xs=np.array([[True], [False]]), '
990+
'zs=np.array([[True], [True]])))'
991+
)

0 commit comments

Comments
 (0)