diff --git a/src/qiskit_qec/operators/pauli.py b/src/qiskit_qec/operators/pauli.py index e0a01889..610583f5 100644 --- a/src/qiskit_qec/operators/pauli.py +++ b/src/qiskit_qec/operators/pauli.py @@ -99,7 +99,8 @@ def __init__( ) elif isinstance(data, str): - matrix, phase_exp = pauli_rep.str2symplectic(data, qubit_order=input_qubit_order) + matrix, phase_exp = pauli_rep.str2symplectic( + data, qubit_order=input_qubit_order) elif isinstance(data, ScalarOp): matrix, phase_exp = pauli_rep.scalar_op2symplectic( data, output_encoding=pauli_rep.INTERNAL_PHASE_ENCODING @@ -110,10 +111,12 @@ def __init__( if z is None: # Using old Pauli initialization with positional args instead of kwargs z = data - matrix, phase_exp = self._from_split_array_deprecated(z, x, phase_exp) + matrix, phase_exp = self._from_split_array_deprecated( + z, x, phase_exp) elif label is not None: # DEPRECATED - matrix, phase_exp = self._from_label_deprecated(label, qubit_order=input_qubit_order) + matrix, phase_exp = self._from_label_deprecated( + label, qubit_order=input_qubit_order) else: raise QiskitError("Invalid input data for Pauli.") @@ -197,11 +200,11 @@ def x(self, val): @property def z(self): """The z vector for the Pauli.""" - return self.matrix[:, self.num_qubits :][0] + return self.matrix[:, self.num_qubits:][0] @z.setter def z(self, val): - self.matrix[:, self.num_qubits :][0] = val + self.matrix[:, self.num_qubits:][0] = val # --------------------------------------------------------------------- # Magic Methods @@ -218,7 +221,7 @@ def __str__(self): and self.num_qubits > self._truncate__ and BasePauli.EXTERNAL_SYNTAX == pauli_rep.PRODUCT_SYNTAX ): - front = self[-self._truncate__ :].to_label() + front = self[-self._truncate__:].to_label() return front + "..." return self.to_label() @@ -319,7 +322,7 @@ def _getitem(self, i): Returns: Pauli: Pauli acting on qubit i """ - return Pauli(self.matrix[0][i : self.matrix.shape[1] : self.num_qubits]) + return Pauli(self.matrix[0][i: self.matrix.shape[1]: self.num_qubits]) def _fast_getitem_str(self, i): """Get Pauli for qubit i @@ -518,14 +521,15 @@ def to_instruction(self): ) if len(pauli) == 1: - gate = {"I": IGate(), "X": XGate(), "Y": YGate(), "Z": ZGate()}[pauli] + gate = {"I": IGate(), "X": XGate(), "Y": YGate(), + "Z": ZGate()}[pauli] else: gate = PauliGate(pauli) - if not phase_exp[0]: + if not phase_exp: return gate # Add global phase circuit = QuantumCircuit(self.num_qubits, name=str(self)) - circuit.global_phase = -phase_exp[0] * pi / 2 + circuit.global_phase = -phase_exp * pi / 2 circuit.append(gate, range(self.num_qubits)) return circuit.to_instruction() @@ -696,7 +700,8 @@ def instrs2symplectic(instr: Union[Instruction, QuantumCircuit]): instr = instr.definition # Initialize identity Pauli - ret = Pauli(np.zeros((1, 2 * instr.num_qubits), dtype=bool), phase_exp=0) + ret = Pauli(np.zeros((1, 2 * instr.num_qubits), + dtype=bool), phase_exp=0) # Add circuit global phase if specified if instr.global_phase: ret._phase_exp = pauli_rep.cpx2exp( @@ -948,7 +953,8 @@ def insert_paulis(self, indices=None, paulis=None, pauli_labels=None): """ if pauli_labels is not None: if paulis is not None: - raise QiskitError("Please only provide either `paulis` or `pauli_labels`") + raise QiskitError( + "Please only provide either `paulis` or `pauli_labels`") if isinstance(pauli_labels, str): pauli_labels = list(pauli_labels) # since pauli label is in reversed order. @@ -1032,7 +1038,8 @@ def pauli_single(cls, num_qubits, index, pauli_label): Pauli: single qubit pauli """ tmp = Pauli(pauli_label) - ret = Pauli((np.zeros(num_qubits, dtype=bool), np.zeros(num_qubits, dtype=bool))) + ret = Pauli((np.zeros(num_qubits, dtype=bool), + np.zeros(num_qubits, dtype=bool))) ret.x[index] = tmp.x[0] ret.z[index] = tmp.z[0] ret.phase = tmp.phase @@ -1057,7 +1064,8 @@ def random(cls, num_qubits, seed=None): Pauli: the random pauli """ # pylint: disable=cyclic-import - from qiskit.quantum_info.operators.symplectic.random import random_pauli + from qiskit.quantum_info.operators.symplectic.random import \ + random_pauli return random_pauli(num_qubits, group_phase=False, seed=seed)