From 0b0142801d56c435efc1e6d5984ba5940081c357 Mon Sep 17 00:00:00 2001 From: Drew Vandeth Date: Thu, 29 Aug 2024 15:29:40 +1000 Subject: [PATCH] linting --- src/qiskit_qec/operators/pauli.py | 19 +++++++++++-------- src/qiskit_qec/operators/pauli_list.py | 12 +++++++----- test/operators/test_pauli.py | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/qiskit_qec/operators/pauli.py b/src/qiskit_qec/operators/pauli.py index 4b2418a5..ece06a55 100644 --- a/src/qiskit_qec/operators/pauli.py +++ b/src/qiskit_qec/operators/pauli.py @@ -11,7 +11,7 @@ # that they have been altered from the originals. # Part of the QEC framework """Module for Pauli""" -from typing import Any, Dict, List, Optional, Union +from typing import Dict, List, Optional, Union import numpy as np from qiskit.circuit import Instruction, QuantumCircuit @@ -47,7 +47,6 @@ def __init__( z: Union[List, np.ndarray, None] = None, phase_exp: Union[int, str, np.ndarray, None] = None, input_pauli_encoding: Optional[str] = BasePauli.EXTERNAL_PAULI_ENCODING, - label: Optional[str] = None, input_qubit_order: Optional[str] = "right-to-left", order: Optional[str] = "xz", tuple_order: Optional[str] = "zx", @@ -61,12 +60,14 @@ def __init__( data (str | tuple | List | np.ndarray | BasePauli | None): Input data x (Union[List, np.ndarray, None], optional): X Part. Defaults to None. z (Union[List, np.ndarray, None], optional): Z Part. Defaults to None. - phase_exp (Union[str, np.ndarray, None], optional): Phase expression of Pauli. Defaults to None. - input_pauli_encoding (str, optional): What encoding is used for the input data. Default = BasePauli.EXTERNAL_PAULI_ENCODING - label ([str], optional): Deprecated. Defaults to None. + phase_exp (Union[str, np.ndarray, None], optional): Phase expression of + Pauli. Defaults to None. + input_pauli_encoding (str, optional): What encoding is used for the input + data. Default = BasePauli.EXTERNAL_PAULI_ENCODING input_qubit_order (str, optional): Qubit read order. Defaults to "right-to-left". order (str, optional): Order in which data lists X and Z. Defaults to 'xz' - tuple_order (str, optional): Order in data for X and Z parts of tuples. Defaults to 'zx' + tuple_order (str, optional): Order in data for X and Z parts of tuples. + Defaults to 'zx' num_qubits (int, optional): Number of qubits to use in Pauli. Defaults to None. @@ -94,7 +95,9 @@ def __init__( >>>Pauli(None, x=[0,1],z=[1,1],phase_exp = '-i') Pauli('-iYZ') - >>>Pauli(np.array([[0,1,1,1]]),phase_exp="(-i,1)(-1,0)", num_qubits=10, order="zx", input_pauli_encoding='-isXZ') + >>>Pauli(np.array([[0,1,1,1]]), + phase_exp="(-i,1)(-1,0)", + num_qubits=10, order="zx", input_pauli_encoding='-isXZ') Pauli('-iIIIIIIIIYX') >>>Pauli(([0,1],[1,1],'-i'), tuple_order='xz') @@ -399,7 +402,7 @@ def _fast_getitem_str(self, i): i (int): index of qubit Returns: - str: Streing representing the Pauli acting on qubit i, + str: String representing the Pauli acting on qubit i, (0,0):"I", (1,0):"X", (0,1):"Z", (1,1):"Y" """ return Pauli.pltb_str[(self.matrix[0][i], self.matrix[0][i + self.num_qubits])] diff --git a/src/qiskit_qec/operators/pauli_list.py b/src/qiskit_qec/operators/pauli_list.py index 0198ad1a..e3315716 100644 --- a/src/qiskit_qec/operators/pauli_list.py +++ b/src/qiskit_qec/operators/pauli_list.py @@ -53,9 +53,10 @@ def __init__( input_qubit_order (str, optional): Order to read pdata. Defaults to "right-to-left". order (str, optional): Order in which data input lists X and Z. Defaults to 'xz' num_qubits (int, optional): Number of qubits to use in Pauli. Defaults to None. - fast_load (bool, optional): If True class stores individual Pauls for fast element selection. - The fast_load options is much faster when loading elements from the list, say 100ns versus 2.3 us - but does so at the cost of initializing speed and memory. Defaults to True + fast_load (bool, optional): If True class stores individual Pauls for fast element + selection. The fast_load options is much faster when loading elements from the list, + say 100ns versus 2.3 us but does so at the cost of initializing speed and memory. + Defaults to True Raises: @@ -291,7 +292,7 @@ def __getitem__(self, index): # Single Pauli try: return self.paulis[index] - except TypeError as load_error: + except TypeError: return BasePauli(self.matrix[index], self._phase_exp[index]) elif isinstance(index, (slice, list, np.ndarray)): # Sub-Table view @@ -308,7 +309,7 @@ def getaslist(self, slc: Union[numbers.Integral, slice]) -> List["Pauli"]: """ try: return self.paulis[slc] - except TypeError as load_error: + except TypeError: return [ BasePauli(self.matrix[index], self._phase_exp[index]) for index in self.num_paulis ] @@ -388,6 +389,7 @@ def __len__(self): return self._num_paulis def set_fast_load(self, fast_load: bool): + """Set if class uses the fast_store method. Storing Pauli variables""" self.fast_load = fast_load if self.fast_load is True: self.paulis = [ diff --git a/test/operators/test_pauli.py b/test/operators/test_pauli.py index b203022f..171dbc85 100644 --- a/test/operators/test_pauli.py +++ b/test/operators/test_pauli.py @@ -215,7 +215,7 @@ def test_delete(self): pauli = pauli.delete([0, 2]) self.assertEqual(str(pauli), "IY") - def test_delete(self): + def test_delete2(self): """Test delete method""" pauli = Pauli("IXYZ") pauli = pauli.delete([1])