Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace committed Sep 14, 2023
1 parent f07b4c2 commit 2a1ce84
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
36 changes: 14 additions & 22 deletions src/qiskit_qec/operators/base_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def __init__(
self.matrix = matrix
self._num_paulis = self.matrix.shape[0]
if phase_exp is None:
self._phase_exp = np.zeros(
shape=(self.matrix.shape[0],), dtype=np.int8)
self._phase_exp = np.zeros(shape=(self.matrix.shape[0],), dtype=np.int8)
else:
self._phase_exp = np.atleast_1d(phase_exp)
if self._phase_exp.shape[0] != self.matrix.shape[0]:
Expand Down Expand Up @@ -190,22 +189,22 @@ def _x(self, val): # pylint: disable=invalid-name
@property
def z(self):
"""The z array for the symplectic representation."""
return self.matrix[:, self.num_qubits:]
return self.matrix[:, self.num_qubits :]

@z.setter
def z(self, val):
self.matrix[:, self.num_qubits:] = val
self.matrix[:, self.num_qubits :] = val

# @final Add when python >= 3.8
@property
def _z(self): # pylint: disable=invalid-name
"""The z array for the symplectic representation."""
return self.matrix[:, self.num_qubits:]
return self.matrix[:, self.num_qubits :]

# @final Add when python >= 3.8
@_z.setter
def _z(self, val): # pylint: disable=invalid-name
self.matrix[:, self.num_qubits:] = val
self.matrix[:, self.num_qubits :] = val

@property
def num_y(self):
Expand Down Expand Up @@ -299,8 +298,7 @@ def set_syntax(cls, syntax_code: Optional[int] = None, syntax_str: Optional[str]
BasePauli.EXTERNAL_SYNTAX = pauli_rep.INDEX_SYNTAX
else:
if syntax_code not in [0, 1, 2]:
raise QiskitError(
"Unknown syntax: {syntax_code}. See pauli_rep for options.")
raise QiskitError("Unknown syntax: {syntax_code}. See pauli_rep for options.")
BasePauli.EXTERNAL_SYNTAX = syntax_code

@property
Expand Down Expand Up @@ -427,8 +425,7 @@ def compose(

# Validation
if qargs is None and other.num_qubits != self.num_qubits:
raise QiskitError(
f"other {type(self).__name__} must be on the same number of qubits.")
raise QiskitError(f"other {type(self).__name__} must be on the same number of qubits.")

if qargs and other.num_qubits != len(qargs):
raise QiskitError(
Expand Down Expand Up @@ -477,11 +474,11 @@ def _compose(
phase_exp = a._phase_exp + b._phase_exp
if front:
phase_exp += 2 * np.sum(
np.logical_and(amat[:, : b.num_qubits], bmat[:, b.num_qubits:]), axis=1
np.logical_and(amat[:, : b.num_qubits], bmat[:, b.num_qubits :]), axis=1
)
else:
phase_exp += 2 * np.sum(
np.logical_and(bmat[:, : b.num_qubits], amat[:, b.num_qubits:]), axis=1
np.logical_and(bmat[:, : b.num_qubits], amat[:, b.num_qubits :]), axis=1
)
phase_exp = np.mod(phase_exp, 4)

Expand Down Expand Up @@ -631,8 +628,7 @@ def _commutes(self, other: "BasePauli", qargs: List = None) -> np.ndarray:
x1, z1 = self.matrix[:, inds], self.matrix[:, sinds]
else:
# x1, z1 = self.x, self.z
x1, z1 = self.matrix[:,
: self.num_qubits], self.matrix[:, self.num_qubits:]
x1, z1 = self.matrix[:, : self.num_qubits], self.matrix[:, self.num_qubits :]

return np.logical_not(np.sum((x1 & other.z) ^ (z1 & other.x), axis=1) % 2)

Expand Down Expand Up @@ -861,8 +857,7 @@ def _append_circuit(
"sdg": _evolve_sdg,
"sinv": _evolve_sdg,
}
basis_2q = {"cx": _evolve_cx, "cz": _evolve_cz,
"cy": _evolve_cy, "swap": _evolve_swap}
basis_2q = {"cx": _evolve_cx, "cz": _evolve_cz, "cy": _evolve_cy, "swap": _evolve_swap}

# Non-Clifford gates
non_clifford = ["t", "tdg", "ccx", "ccz"]
Expand All @@ -878,8 +873,7 @@ def _append_circuit(

# Apply gate if it is a Clifford basis gate
if name in non_clifford:
raise QiskitError(
f"Cannot update Pauli with non-Clifford gate {name}")
raise QiskitError(f"Cannot update Pauli with non-Clifford gate {name}")
if name in basis_1q:
if len(qargs) != 1:
raise QiskitError("Invalid qubits for 1-qubit gate.")
Expand Down Expand Up @@ -960,8 +954,7 @@ def _evolve_i(base_pauli: "BasePauli", qubit: int) -> "BasePauli":

def _evolve_x(base_pauli: "BasePauli", qubit: int) -> "BasePauli":
"""Update P -> X.P.X"""
base_pauli._phase_exp += 2 * \
base_pauli.matrix[:, qubit + base_pauli.num_qubits].T
base_pauli._phase_exp += 2 * base_pauli.matrix[:, qubit + base_pauli.num_qubits].T
return base_pauli


Expand Down Expand Up @@ -1008,8 +1001,7 @@ def _evolve_cy(base_pauli: "BasePauli", qctrl: int, qtrgt: int) -> "BasePauli":
z2 = base_pauli.matrix[:, qtrgt + base_pauli.num_qubits].copy()
base_pauli.matrix[:, qtrgt] ^= x1
base_pauli.matrix[:, qtrgt + base_pauli.num_qubits] ^= x1
base_pauli.matrix[:, qctrl +
base_pauli.num_qubits] ^= np.logical_xor(x2, z2)
base_pauli.matrix[:, qctrl + base_pauli.num_qubits] ^= np.logical_xor(x2, z2)
base_pauli._phase_exp += x1 + 2 * np.logical_and(x1, x2).T
return base_pauli

Expand Down
1 change: 0 additions & 1 deletion src/qiskit_qec/operators/pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ def evolve(self, other, qargs=None, frame="h"):
if qargs is None:
qargs = getattr(other, "qargs", None)


if not isinstance(other, (Pauli, Instruction, QuantumCircuit)):
# Convert to a Pauli
other = Pauli(other)
Expand Down
1 change: 0 additions & 1 deletion src/qiskit_qec/operators/pauli_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,6 @@ def evolve(self, other, qargs=None, frame="h"):
"""
from qiskit.circuit import Instruction, QuantumCircuit


if qargs is None:
qargs = getattr(other, "qargs", None)

Expand Down
2 changes: 0 additions & 2 deletions test/operators/test_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
from qiskit_qec.utils.pauli_rep import cpxstr2exp, split_pauli



@lru_cache(maxsize=8)
def pauli_group_labels(nq, full_group=True):
"""Generate list of the N-qubit pauli group string labels"""
Expand Down Expand Up @@ -402,7 +401,6 @@ def test_evolve_clifford2(self, gate, label):
self.assertEqual(value, value_h)
self.assertEqual(value_inv, value_s)


def test_barrier_delay_sim(self):
"""Test barrier and delay instructions can be simulated"""
target_circ = QuantumCircuit(2)
Expand Down

0 comments on commit 2a1ce84

Please sign in to comment.