41
41
import numpy as np
42
42
import sympy
43
43
44
- import cirq
45
44
from cirq import value , protocols , linalg , qis , _compat
46
45
from cirq ._doc import document
47
46
from cirq ._import import LazyLoader
@@ -496,7 +495,7 @@ def matrix(self, qubits: Optional[Iterable[TKey]] = None) -> np.ndarray:
496
495
"""
497
496
qubits = self .qubits if qubits is None else qubits
498
497
factors = [self .get (q , default = identity .I ) for q in qubits ]
499
- if cirq .is_parameterized (self ):
498
+ if protocols .is_parameterized (self ):
500
499
raise NotImplementedError ('Cannot express as matrix when parameterized' )
501
500
assert isinstance (self .coefficient , complex )
502
501
return linalg .kron (self .coefficient , * [protocols .unitary (f ) for f in factors ])
@@ -980,7 +979,9 @@ def conjugated_by(self, clifford: 'cirq.OP_TREE') -> 'PauliString':
980
979
# Initialize the ps the same as self.
981
980
ps = PauliString (qubit_pauli_map = self ._qubit_pauli_map , coefficient = self .coefficient )
982
981
all_ops = list (op_tree .flatten_to_ops (clifford ))
983
- all_qubits = set .union (set (self .qubits ), [q for op in all_ops for q in op .qubits ])
982
+ all_qubits : set [TKey ] = set .union (
983
+ set (self .qubits ), [q for op in all_ops for q in op .qubits ]
984
+ )
984
985
985
986
# Iteratively calculate the conjugation in reverse order of ops.
986
987
for op in all_ops [::- 1 ]:
@@ -989,11 +990,9 @@ def conjugated_by(self, clifford: 'cirq.OP_TREE') -> 'PauliString':
989
990
# Then the conjugation = (C^{-1}⊗I·Pc⊗R·C⊗I) = (C^{-1}·Pc·C)⊗R.
990
991
991
992
# Isolate R
992
- remain : 'cirq.PauliString' = PauliString ()
993
- for q in all_qubits :
994
- pauli = ps .get (q )
995
- if pauli is not None and not q in op .qubits :
996
- remain *= pauli (q )
993
+ remain : 'cirq.PauliString' = PauliString (
994
+ * (pauli (q ) for q in all_qubits - set (op .qubits ) if (pauli := ps .get (q )) is not None )
995
+ )
997
996
998
997
# Initialize the conjugation of Pc.
999
998
conjugated : 'cirq.DensePauliString' = (
@@ -1005,7 +1004,7 @@ def conjugated_by(self, clifford: 'cirq.OP_TREE') -> 'PauliString':
1005
1004
# Note the clifford_tableau in CliffordGate represents C·P·C^-1 instead of C^-1·P·C.
1006
1005
# So we take the inverse of the tableau to match the definition of the conjugation here.
1007
1006
gate_in_clifford : 'cirq.CliffordGate'
1008
- if isinstance (op .gate , cirq .CliffordGate ):
1007
+ if isinstance (op .gate , clifford_gate .CliffordGate ):
1009
1008
gate_in_clifford = op .gate
1010
1009
else :
1011
1010
# Convert the clifford gate to CliffordGate type.
@@ -1020,7 +1019,7 @@ def conjugated_by(self, clifford: 'cirq.OP_TREE') -> 'PauliString':
1020
1019
# Puali X_k's conjugation is from the destabilzer table;
1021
1020
# Puali Z_k's conjugation is from the stabilzer table;
1022
1021
# Puali Y_k's conjugation is calcluated according to Y = iXZ. E.g., for the kth qubit,
1023
- # C^{-1}·Y_k⊗I·C = C^{-1}·(iX_k⊗I·Z_k⊗I)·C = i (C^{-1}·X_k⊗I·C)·(C^{-1}·Z_k⊗I·C)
1022
+ # C^{-1}·Y_k⊗I·C = C^{-1}·(iX_k⊗I·Z_k⊗I)·C = i (C^{-1}·X_k⊗I·C)·(C^{-1}·Z_k⊗I·C).
1024
1023
for qid , qubit in enumerate (op .qubits ):
1025
1024
pauli = ps .get (qubit )
1026
1025
match pauli :
@@ -1179,7 +1178,7 @@ def _try_interpret_as_pauli_string(op: Any):
1179
1178
if (pauli := gates .get (type (op .gate ), None )) is not None :
1180
1179
exponent = op .gate .exponent # type: ignore
1181
1180
if exponent % 2 == 0 :
1182
- return cirq . PauliString ()
1181
+ return PauliString ()
1183
1182
if exponent % 2 == 1 :
1184
1183
return pauli .on (op .qubits [0 ])
1185
1184
return None
0 commit comments