Skip to content

Commit d9c9d1f

Browse files
committed
Small fixes.
1 parent f98f4c7 commit d9c9d1f

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

cirq-core/cirq/ops/pauli_string.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import numpy as np
4242
import sympy
4343

44-
import cirq
4544
from cirq import value, protocols, linalg, qis, _compat
4645
from cirq._doc import document
4746
from cirq._import import LazyLoader
@@ -496,7 +495,7 @@ def matrix(self, qubits: Optional[Iterable[TKey]] = None) -> np.ndarray:
496495
"""
497496
qubits = self.qubits if qubits is None else qubits
498497
factors = [self.get(q, default=identity.I) for q in qubits]
499-
if cirq.is_parameterized(self):
498+
if protocols.is_parameterized(self):
500499
raise NotImplementedError('Cannot express as matrix when parameterized')
501500
assert isinstance(self.coefficient, complex)
502501
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':
980979
# Initialize the ps the same as self.
981980
ps = PauliString(qubit_pauli_map=self._qubit_pauli_map, coefficient=self.coefficient)
982981
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+
)
984985

985986
# Iteratively calculate the conjugation in reverse order of ops.
986987
for op in all_ops[::-1]:
@@ -989,11 +990,9 @@ def conjugated_by(self, clifford: 'cirq.OP_TREE') -> 'PauliString':
989990
# Then the conjugation = (C^{-1}⊗I·Pc⊗R·C⊗I) = (C^{-1}·Pc·C)⊗R.
990991

991992
# 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+
)
997996

998997
# Initialize the conjugation of Pc.
999998
conjugated: 'cirq.DensePauliString' = (
@@ -1005,7 +1004,7 @@ def conjugated_by(self, clifford: 'cirq.OP_TREE') -> 'PauliString':
10051004
# Note the clifford_tableau in CliffordGate represents C·P·C^-1 instead of C^-1·P·C.
10061005
# So we take the inverse of the tableau to match the definition of the conjugation here.
10071006
gate_in_clifford: 'cirq.CliffordGate'
1008-
if isinstance(op.gate, cirq.CliffordGate):
1007+
if isinstance(op.gate, clifford_gate.CliffordGate):
10091008
gate_in_clifford = op.gate
10101009
else:
10111010
# Convert the clifford gate to CliffordGate type.
@@ -1020,7 +1019,7 @@ def conjugated_by(self, clifford: 'cirq.OP_TREE') -> 'PauliString':
10201019
# Puali X_k's conjugation is from the destabilzer table;
10211020
# Puali Z_k's conjugation is from the stabilzer table;
10221021
# 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).
10241023
for qid, qubit in enumerate(op.qubits):
10251024
pauli = ps.get(qubit)
10261025
match pauli:
@@ -1179,7 +1178,7 @@ def _try_interpret_as_pauli_string(op: Any):
11791178
if (pauli := gates.get(type(op.gate), None)) is not None:
11801179
exponent = op.gate.exponent # type: ignore
11811180
if exponent % 2 == 0:
1182-
return cirq.PauliString()
1181+
return PauliString()
11831182
if exponent % 2 == 1:
11841183
return pauli.on(op.qubits[0])
11851184
return None

0 commit comments

Comments
 (0)