@@ -529,18 +529,26 @@ def test_text_diagram_info(gate, sym, exp):
529
529
)
530
530
531
531
532
- def test_from_unitary ():
533
- def _test (clifford_gate ):
534
- u = cirq .unitary (clifford_gate )
535
- result_gate = cirq .SingleQubitCliffordGate .from_unitary (u )
536
- assert result_gate == clifford_gate
537
-
538
- _test (cirq .SingleQubitCliffordGate .I )
539
- _test (cirq .SingleQubitCliffordGate .H )
540
- _test (cirq .SingleQubitCliffordGate .X )
541
- _test (cirq .SingleQubitCliffordGate .Y )
542
- _test (cirq .SingleQubitCliffordGate .Z )
543
- _test (cirq .SingleQubitCliffordGate .X_nsqrt )
532
+ @pytest .mark .parametrize (
533
+ "clifford_gate" ,
534
+ (
535
+ cirq .SingleQubitCliffordGate .I ,
536
+ cirq .SingleQubitCliffordGate .H ,
537
+ cirq .SingleQubitCliffordGate .X ,
538
+ cirq .SingleQubitCliffordGate .Y ,
539
+ cirq .SingleQubitCliffordGate .Z ,
540
+ cirq .SingleQubitCliffordGate .X_sqrt ,
541
+ cirq .SingleQubitCliffordGate .Y_sqrt ,
542
+ cirq .SingleQubitCliffordGate .Z_sqrt ,
543
+ cirq .SingleQubitCliffordGate .X_nsqrt ,
544
+ cirq .SingleQubitCliffordGate .Y_nsqrt ,
545
+ cirq .SingleQubitCliffordGate .Z_nsqrt ,
546
+ ),
547
+ )
548
+ def test_from_unitary (clifford_gate ):
549
+ u = cirq .unitary (clifford_gate )
550
+ result_gate = cirq .SingleQubitCliffordGate .from_unitary (u )
551
+ assert result_gate == clifford_gate
544
552
545
553
546
554
def test_from_unitary_with_phase_shift ():
@@ -612,6 +620,15 @@ def test_common_clifford_gate(clifford_gate, standard_gate):
612
620
cirq .testing .assert_allclose_up_to_global_phase (u_c , u_s , atol = 1e-8 )
613
621
614
622
623
+ @pytest .mark .parametrize ('clifford_gate_name' , ("I" , "X" , "Y" , "Z" , "H" , "S" , "CNOT" , "CZ" , "SWAP" ))
624
+ def test_common_clifford_gate_caching (clifford_gate_name ):
625
+ cache_name = f"_{ clifford_gate_name } "
626
+ delattr (cirq .CliffordGate , cache_name )
627
+ assert not hasattr (cirq .CliffordGate , cache_name )
628
+ _ = getattr (cirq .CliffordGate , clifford_gate_name )
629
+ assert hasattr (cirq .CliffordGate , cache_name )
630
+
631
+
615
632
def test_multi_qubit_clifford_pow ():
616
633
assert cirq .CliffordGate .X ** - 1 == cirq .CliffordGate .X
617
634
assert cirq .CliffordGate .H ** - 1 == cirq .CliffordGate .H
0 commit comments