Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace committed Sep 19, 2023
1 parent 49360ba commit 0782fcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
32 changes: 12 additions & 20 deletions src/qiskit_qec/operators/pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ 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
Expand All @@ -111,12 +110,10 @@ 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.")

Expand Down Expand Up @@ -200,11 +197,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
Expand All @@ -221,7 +218,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()

Expand Down Expand Up @@ -322,7 +319,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
Expand Down Expand Up @@ -521,8 +518,7 @@ 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:
Expand Down Expand Up @@ -700,8 +696,7 @@ 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(
Expand Down Expand Up @@ -953,8 +948,7 @@ 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.
Expand Down Expand Up @@ -1038,8 +1032,7 @@ 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
Expand All @@ -1064,8 +1057,7 @@ 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)

Expand Down
7 changes: 0 additions & 7 deletions test/utils/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,3 @@ def next_frame(_):
engine.screen.pixel[0, engine.size - 1].button.description == "hello",
"Pixel in game engine not displaying correct text",
)


if __name__ == "__main__":
# for testing locally. JUPYTER_PLATFORM_DIRS is set via tox when using tox
import os

os.environ["JUPYTER_PLATFORM_DIRS"] = 1

0 comments on commit 0782fcf

Please sign in to comment.