From af714e3e23a50d84ff5106cac7047b086b32cefa Mon Sep 17 00:00:00 2001 From: Luciano Date: Sat, 12 Oct 2019 14:52:35 +0800 Subject: [PATCH] disable=invalid-name at line level instead of file level (#3242) * qiskit/qasm/node/customunitary.py * qiskit/qasm/node/opaque.py * qiskit/visualization/counts_visualization.py * qiskit/visualization/pass_manager_visualization.py * qiskit/visualization/gate_map.py * qiskit/extensions/ * qiskit/qasm/node/qreg.py * qiskit/quantum_info/states/measures.py * qiskit/qasm/node/indexedid.py * qiskit/qasm/node/creg.py * qiskit/tools/jupyter/copyright.py * qiskit/tools/jupyter/version_table.py * qiskit/quantum_info/random/utils.py * lint --- qiskit/extensions/quantum_initializer/diag.py | 1 - .../extensions/quantum_initializer/ucrot.py | 10 ++- qiskit/extensions/standard/ch.py | 4 +- qiskit/extensions/standard/cx.py | 4 +- qiskit/extensions/standard/cy.py | 4 +- qiskit/extensions/standard/cz.py | 4 +- qiskit/extensions/standard/h.py | 4 +- qiskit/extensions/standard/rx.py | 4 +- qiskit/extensions/standard/ry.py | 4 +- qiskit/extensions/standard/rz.py | 4 +- qiskit/extensions/standard/s.py | 8 +-- qiskit/extensions/standard/t.py | 4 +- qiskit/extensions/standard/u0.py | 4 +- qiskit/extensions/standard/u1.py | 4 +- qiskit/extensions/standard/u2.py | 3 +- qiskit/extensions/standard/u3.py | 4 +- qiskit/qasm/node/creg.py | 4 +- qiskit/qasm/node/customunitary.py | 4 +- qiskit/qasm/node/gate.py | 4 +- qiskit/qasm/node/indexedid.py | 4 +- qiskit/qasm/node/opaque.py | 4 +- qiskit/qasm/node/qreg.py | 4 +- qiskit/quantum_info/random/utils.py | 34 +++++---- qiskit/quantum_info/states/measures.py | 32 ++++----- qiskit/tools/jupyter/copyright.py | 2 +- qiskit/tools/jupyter/version_table.py | 2 +- qiskit/visualization/counts_visualization.py | 2 +- qiskit/visualization/gate_map.py | 72 +++++++++---------- .../pass_manager_visualization.py | 13 ++-- 29 files changed, 104 insertions(+), 147 deletions(-) diff --git a/qiskit/extensions/quantum_initializer/diag.py b/qiskit/extensions/quantum_initializer/diag.py index 81e085dbc041..1a1341247d7a 100644 --- a/qiskit/extensions/quantum_initializer/diag.py +++ b/qiskit/extensions/quantum_initializer/diag.py @@ -15,7 +15,6 @@ # The structure of the code is based on Emanuel Malvetti's semester thesis at ETH in 2018, # which was supervised by Raban Iten and Prof. Renato Renner. -# pylint: disable=invalid-name # pylint: disable=missing-param-doc # pylint: disable=missing-type-doc diff --git a/qiskit/extensions/quantum_initializer/ucrot.py b/qiskit/extensions/quantum_initializer/ucrot.py index 5efd13d5286d..f1d0fab723bf 100644 --- a/qiskit/extensions/quantum_initializer/ucrot.py +++ b/qiskit/extensions/quantum_initializer/ucrot.py @@ -15,8 +15,6 @@ # The structure of the code is based on Emanuel Malvetti's semester thesis at ETH in 2018, # which was supervised by Raban Iten and Prof. Renato Renner. -# pylint: disable=invalid-name - """ (Abstract) base class for uniformly controlled (also called multiplexed) single-qubit rotations R_t. This class provides a basis for the decomposition of uniformly controlled R_x,R_y and R_z gates @@ -55,9 +53,9 @@ def __init__(self, angle_list, rot_axis): if not isinstance(angle_list, list): raise QiskitError("The angles are not provided in a list.") # Check if the angles in angle_list are real numbers - for a in angle_list: + for angle in angle_list: try: - float(a) + float(angle) except TypeError: raise QiskitError( "An angle cannot be converted to type float (real angles are expected).") @@ -165,5 +163,5 @@ def _dec_uc_rotations(angles, start_index, end_index, reversedDec): # Calculate the new rotation angles according to Shende's decomposition -def _update_angles(a1, a2): - return (a1 + a2) / 2.0, (a1 - a2) / 2.0 +def _update_angles(angle1, angle2): + return (angle1 + angle2) / 2.0, (angle1 - angle2) / 2.0 diff --git a/qiskit/extensions/standard/ch.py b/qiskit/extensions/standard/ch.py index 19c255bc154d..83e453a6a6e7 100644 --- a/qiskit/extensions/standard/ch.py +++ b/qiskit/extensions/standard/ch.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ controlled-H gate. """ @@ -76,7 +74,7 @@ def to_matrix(self): [0, 1/np.sqrt(2), 0, -1/np.sqrt(2)]], dtype=complex) -def ch(self, ctl, tgt): +def ch(self, ctl, tgt): # pylint: disable=invalid-name """Apply CH from ctl to tgt.""" return self.append(CHGate(), [ctl, tgt], []) diff --git a/qiskit/extensions/standard/cx.py b/qiskit/extensions/standard/cx.py index cda467e7ecec..dd7451dc5994 100644 --- a/qiskit/extensions/standard/cx.py +++ b/qiskit/extensions/standard/cx.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ controlled-NOT gate. """ @@ -43,7 +41,7 @@ def to_matrix(self): [0, 1, 0, 0]], dtype=complex) -def cx(self, ctl, tgt): +def cx(self, ctl, tgt): # pylint: disable=invalid-name """Apply CX from ctl to tgt.""" return self.append(CnotGate(), [ctl, tgt], []) diff --git a/qiskit/extensions/standard/cy.py b/qiskit/extensions/standard/cy.py index 445e2688f4ee..95d2d1a12c80 100644 --- a/qiskit/extensions/standard/cy.py +++ b/qiskit/extensions/standard/cy.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ controlled-Y gate. """ @@ -52,7 +50,7 @@ def inverse(self): return CyGate() # self-inverse -def cy(self, ctl, tgt): +def cy(self, ctl, tgt): # pylint: disable=invalid-name """Apply CY to circuit.""" return self.append(CyGate(), [ctl, tgt], []) diff --git a/qiskit/extensions/standard/cz.py b/qiskit/extensions/standard/cz.py index 74e1259ce8d8..ea540c8e2d5e 100644 --- a/qiskit/extensions/standard/cz.py +++ b/qiskit/extensions/standard/cz.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ controlled-Phase gate. """ @@ -60,7 +58,7 @@ def to_matrix(self): [0, 0, 0, -1]], dtype=complex) -def cz(self, ctl, tgt): +def cz(self, ctl, tgt): # pylint: disable=invalid-name """Apply CZ to circuit.""" return self.append(CzGate(), [ctl, tgt], []) diff --git a/qiskit/extensions/standard/h.py b/qiskit/extensions/standard/h.py index c3e32fe41d38..d3a698ca2e91 100644 --- a/qiskit/extensions/standard/h.py +++ b/qiskit/extensions/standard/h.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ Hadamard gate. """ @@ -56,7 +54,7 @@ def to_matrix(self): [1, -1]], dtype=complex) / numpy.sqrt(2) -def h(self, q): +def h(self, q): # pylint: disable=invalid-name """Apply H to q.""" return self.append(HGate(), [q], []) diff --git a/qiskit/extensions/standard/rx.py b/qiskit/extensions/standard/rx.py index acd1b284add2..ba5773fdadde 100644 --- a/qiskit/extensions/standard/rx.py +++ b/qiskit/extensions/standard/rx.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ Rotation around the x-axis. """ @@ -61,7 +59,7 @@ def to_matrix(self): [-1j * sin, cos]], dtype=complex) -def rx(self, theta, q): +def rx(self, theta, q): # pylint: disable=invalid-name """Apply Rx to q.""" return self.append(RXGate(theta), [q], []) diff --git a/qiskit/extensions/standard/ry.py b/qiskit/extensions/standard/ry.py index 938bffac46c9..c0dd7f397f94 100644 --- a/qiskit/extensions/standard/ry.py +++ b/qiskit/extensions/standard/ry.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ Rotation around the y-axis. """ @@ -60,7 +58,7 @@ def to_matrix(self): [sin, cos]], dtype=complex) -def ry(self, theta, q): +def ry(self, theta, q): # pylint: disable=invalid-name """Apply Ry to q.""" return self.append(RYGate(theta), [q], []) diff --git a/qiskit/extensions/standard/rz.py b/qiskit/extensions/standard/rz.py index 245fa8a47730..7277de061408 100644 --- a/qiskit/extensions/standard/rz.py +++ b/qiskit/extensions/standard/rz.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ Rotation around the z-axis. """ @@ -51,7 +49,7 @@ def inverse(self): return RZGate(-self.params[0]) -def rz(self, phi, q): +def rz(self, phi, q): # pylint: disable=invalid-name """Apply Rz to q.""" return self.append(RZGate(phi), [q], []) diff --git a/qiskit/extensions/standard/s.py b/qiskit/extensions/standard/s.py index 95ff3043ce0c..6a8c3350d1b1 100644 --- a/qiskit/extensions/standard/s.py +++ b/qiskit/extensions/standard/s.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ S=diag(1,i) Clifford phase gate or its inverse. """ @@ -39,7 +37,7 @@ def _define(self): definition = [] q = QuantumRegister(1, "q") rule = [ - (U1Gate(pi/2), [q[0]], []) + (U1Gate(pi / 2), [q[0]], []) ] for inst in rule: definition.append(inst) @@ -69,7 +67,7 @@ def _define(self): definition = [] q = QuantumRegister(1, "q") rule = [ - (U1Gate(-pi/2), [q[0]], []) + (U1Gate(-pi / 2), [q[0]], []) ] for inst in rule: definition.append(inst) @@ -85,7 +83,7 @@ def to_matrix(self): [0, -1j]], dtype=complex) -def s(self, q): +def s(self, q): # pylint: disable=invalid-name """Apply S to q.""" return self.append(SGate(), [q], []) diff --git a/qiskit/extensions/standard/t.py b/qiskit/extensions/standard/t.py index 2cd66abf4145..35c9fdc1c4c4 100644 --- a/qiskit/extensions/standard/t.py +++ b/qiskit/extensions/standard/t.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ T=sqrt(S) phase gate or its inverse. """ @@ -85,7 +83,7 @@ def to_matrix(self): [0, (1-1j) / numpy.sqrt(2)]], dtype=complex) -def t(self, q): +def t(self, q): # pylint: disable=invalid-name """Apply T to q.""" return self.append(TGate(), [q], []) diff --git a/qiskit/extensions/standard/u0.py b/qiskit/extensions/standard/u0.py index ed4d9e079059..cab99c645046 100644 --- a/qiskit/extensions/standard/u0.py +++ b/qiskit/extensions/standard/u0.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ Single qubit gate cycle idle. """ @@ -54,7 +52,7 @@ def to_matrix(self): [0, 1]], dtype=complex) -def u0(self, m, q): +def u0(self, m, q): # pylint: disable=invalid-name """Apply u0 with length m to q.""" return self.append(U0Gate(m), [q], []) diff --git a/qiskit/extensions/standard/u1.py b/qiskit/extensions/standard/u1.py index b1f3568966a7..41a2d9358e47 100644 --- a/qiskit/extensions/standard/u1.py +++ b/qiskit/extensions/standard/u1.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ Diagonal single qubit gate. """ @@ -52,7 +50,7 @@ def to_matrix(self): return numpy.array([[1, 0], [0, numpy.exp(1j * lam)]], dtype=complex) -def u1(self, theta, q): +def u1(self, theta, q): # pylint: disable=invalid-name """Apply u1 with angle theta to q.""" return self.append(U1Gate(theta), [q], []) diff --git a/qiskit/extensions/standard/u2.py b/qiskit/extensions/standard/u2.py index 4494c3af7f7d..dad746af2f80 100644 --- a/qiskit/extensions/standard/u2.py +++ b/qiskit/extensions/standard/u2.py @@ -12,7 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name """ One-pulse single-qubit gate. """ @@ -59,7 +58,7 @@ def to_matrix(self): dtype=complex) -def u2(self, phi, lam, q): +def u2(self, phi, lam, q): # pylint: disable=invalid-name """Apply u2 to q.""" return self.append(U2Gate(phi, lam), [q], []) diff --git a/qiskit/extensions/standard/u3.py b/qiskit/extensions/standard/u3.py index 3f026016cf2d..d436cd9b3daa 100644 --- a/qiskit/extensions/standard/u3.py +++ b/qiskit/extensions/standard/u3.py @@ -12,10 +12,10 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name """ Two-pulse single-qubit gate. """ + import numpy from qiskit.circuit import Gate from qiskit.circuit import QuantumCircuit @@ -51,7 +51,7 @@ def to_matrix(self): dtype=complex) -def u3(self, theta, phi, lam, q): +def u3(self, theta, phi, lam, q): # pylint: disable=invalid-name """Apply u3 to q.""" return self.append(U3Gate(theta, phi, lam), [q], []) diff --git a/qiskit/qasm/node/creg.py b/qiskit/qasm/node/creg.py index b5f0ca866fc4..8c4a925b7c44 100644 --- a/qiskit/qasm/node/creg.py +++ b/qiskit/qasm/node/creg.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """Node for an OPENQASM creg statement.""" from .node import Node @@ -29,7 +27,7 @@ def __init__(self, children): """Create the creg node.""" super().__init__('creg', children, None) # This is the indexed id, the full "id[n]" object - self.id = children[0] + self.id = children[0] # pylint: disable=invalid-name # Name of the creg self.name = self.id.name # Source line number diff --git a/qiskit/qasm/node/customunitary.py b/qiskit/qasm/node/customunitary.py index 06c42fbab6d0..08bc784bb072 100644 --- a/qiskit/qasm/node/customunitary.py +++ b/qiskit/qasm/node/customunitary.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """Node for an OPENQASM custom gate statement.""" from .node import Node @@ -36,7 +34,7 @@ class CustomUnitary(Node): def __init__(self, children): """Create the custom gate node.""" super().__init__('custom_unitary', children, None) - self.id = children[0] + self.id = children[0] # pylint: disable=invalid-name self.name = self.id.name if len(children) == 3: self.arguments = children[1] diff --git a/qiskit/qasm/node/gate.py b/qiskit/qasm/node/gate.py index 76cc64fe6296..12f95bfae173 100644 --- a/qiskit/qasm/node/gate.py +++ b/qiskit/qasm/node/gate.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """Node for an OPENQASM gate definition.""" from .node import Node @@ -32,7 +30,7 @@ class Gate(Node): def __init__(self, children): """Create the gate node.""" super().__init__('gate', children, None) - self.id = children[0] + self.id = children[0] # pylint: disable=invalid-name # The next three fields are required by the symbtab self.name = self.id.name self.line = self.id.line diff --git a/qiskit/qasm/node/indexedid.py b/qiskit/qasm/node/indexedid.py index d991c2277c43..b48a56986dee 100644 --- a/qiskit/qasm/node/indexedid.py +++ b/qiskit/qasm/node/indexedid.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """Node for an OPENQASM indexed id.""" from .node import Node @@ -29,7 +27,7 @@ class IndexedId(Node): def __init__(self, children): """Create the indexed id node.""" super().__init__('indexed_id', children, None) - self.id = children[0] + self.id = children[0] # pylint: disable=invalid-name self.name = self.id.name self.line = self.id.line self.file = self.id.file diff --git a/qiskit/qasm/node/opaque.py b/qiskit/qasm/node/opaque.py index 4389588f2ccb..9138fe796ffe 100644 --- a/qiskit/qasm/node/opaque.py +++ b/qiskit/qasm/node/opaque.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """Node for an OPENQASM opaque gate declaration.""" from .node import Node @@ -31,7 +29,7 @@ class Opaque(Node): def __init__(self, children): """Create the opaque gate node.""" super().__init__('opaque', children, None) - self.id = children[0] + self.id = children[0] # pylint: disable=invalid-name # The next three fields are required by the symbtab self.name = self.id.name self.line = self.id.line diff --git a/qiskit/qasm/node/qreg.py b/qiskit/qasm/node/qreg.py index f853633fbda5..f6f0affd20f2 100644 --- a/qiskit/qasm/node/qreg.py +++ b/qiskit/qasm/node/qreg.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """Node for an OPENQASM qreg statement.""" from .node import Node @@ -29,7 +27,7 @@ def __init__(self, children): """Create the qreg node.""" super().__init__('qreg', children, None) # This is the indexed id, the full "id[n]" object - self.id = children[0] + self.id = children[0] # pylint: disable=invalid-name # Name of the qreg self.name = self.id.name # Source line number diff --git a/qiskit/quantum_info/random/utils.py b/qiskit/quantum_info/random/utils.py index 28304385d83a..c79287da9a5c 100644 --- a/qiskit/quantum_info/random/utils.py +++ b/qiskit/quantum_info/random/utils.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ Methods to create random unitaries, states, etc. """ @@ -47,8 +45,8 @@ def random_state(dim, seed=None): x += x == 0 x = -np.log(x) sumx = sum(x) - phases = rng.rand(dim)*2.0*np.pi - return np.sqrt(x/sumx)*np.exp(1j*phases) + phases = rng.rand(dim) * 2.0 * np.pi + return np.sqrt(x / sumx) * np.exp(1j * phases) def random_unitary(dim, seed=None): @@ -114,41 +112,41 @@ def __ginibre_matrix(nrow, ncol=None, seed=None): ncol = nrow if seed is not None: np.random.seed(seed) - G = np.random.normal(size=(nrow, ncol)) + \ - np.random.normal(size=(nrow, ncol)) * 1j - return G + + ginibre = np.random.normal(size=(nrow, ncol)) + np.random.normal(size=(nrow, ncol)) * 1j + return ginibre -def __random_density_hs(N, rank=None, seed=None): +def __random_density_hs(length, rank=None, seed=None): """ Generate a random density matrix from the Hilbert-Schmidt metric. Args: - N (int): the length of the density matrix. + length (int): the length of the density matrix. rank (int or None): the rank of the density matrix. The default value is full-rank. seed (int): Optional. To set a random seed. Returns: ndarray: rho (N,N a density matrix. """ - G = __ginibre_matrix(N, rank, seed) - G = G.dot(G.conj().T) - return G / np.trace(G) + ginibre = __ginibre_matrix(length, rank, seed) + ginibre = ginibre.dot(ginibre.conj().T) + return ginibre / np.trace(ginibre) -def __random_density_bures(N, rank=None, seed=None): +def __random_density_bures(length, rank=None, seed=None): """ Generate a random density matrix from the Bures metric. Args: - N (int): the length of the density matrix. + length (int): the length of the density matrix. rank (int or None): the rank of the density matrix. The default value is full-rank. seed (int): Optional. To set a random seed. Returns: ndarray: rho (N,N) a density matrix. """ - P = np.eye(N) + random_unitary(N).data - G = P.dot(__ginibre_matrix(N, rank, seed)) - G = G.dot(G.conj().T) - return G / np.trace(G) + density = np.eye(length) + random_unitary(length).data + ginibre = density.dot(__ginibre_matrix(length, rank, seed)) + ginibre = ginibre.dot(ginibre.conj().T) + return ginibre / np.trace(ginibre) diff --git a/qiskit/quantum_info/states/measures.py b/qiskit/quantum_info/states/measures.py index 04214770a887..8822c29a1504 100644 --- a/qiskit/quantum_info/states/measures.py +++ b/qiskit/quantum_info/states/measures.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ A collection of useful quantum information functions for states. @@ -48,36 +46,36 @@ def state_fidelity(state1, state2): array_like: The state fidelity F(state1, state2). """ # convert input to numpy arrays - s1 = np.array(state1) - s2 = np.array(state2) + state1 = np.array(state1) + state2 = np.array(state2) # fidelity of two state vectors - if s1.ndim == 1 and s2.ndim == 1: - return np.abs(s2.conj().dot(s1)) ** 2 + if state1.ndim == 1 and state2.ndim == 1: + return np.abs(state2.conj().dot(state1)) ** 2 # fidelity of vector and density matrix - elif s1.ndim == 1: + elif state1.ndim == 1: # psi = s1, rho = s2 - return np.abs(s1.conj().dot(s2).dot(s1)) - elif s2.ndim == 1: + return np.abs(state1.conj().dot(state2).dot(state1)) + elif state2.ndim == 1: # psi = s2, rho = s1 - return np.abs(s2.conj().dot(s1).dot(s2)) + return np.abs(state2.conj().dot(state1).dot(state2)) # fidelity of two density matrices - s1sq = _funm_svd(s1, np.sqrt) - s2sq = _funm_svd(s2, np.sqrt) + s1sq = _funm_svd(state1, np.sqrt) + s2sq = _funm_svd(state2, np.sqrt) return np.linalg.norm(s1sq.dot(s2sq), ord='nuc') ** 2 -def _funm_svd(a, func): +def _funm_svd(matrix, func): """Apply real scalar function to singular values of a matrix. Args: - a (array_like): (N, N) Matrix at which to evaluate the function. + matrix (array_like): (N, N) Matrix at which to evaluate the function. func (callable): Callable object that evaluates a scalar function f. Returns: ndarray: funm (N, N) Value of the matrix function specified by func evaluated at `A`. """ - U, s, Vh = la.svd(a, lapack_driver='gesvd') - S = np.diag(func(s)) - return U.dot(S).dot(Vh) + unitary1, singular_values, unitary2 = la.svd(matrix, lapack_driver='gesvd') + diag_func_singular = np.diag(func(singular_values)) + return unitary1.dot(diag_func_singular).dot(unitary2) diff --git a/qiskit/tools/jupyter/copyright.py b/qiskit/tools/jupyter/copyright.py index b8304f4c71ef..8485f69f1aef 100644 --- a/qiskit/tools/jupyter/copyright.py +++ b/qiskit/tools/jupyter/copyright.py @@ -11,7 +11,7 @@ # Any modifications or derivative works of this code must retain this # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name, unused-argument +# pylint: disable=unused-argument """A module for monitoring backends.""" diff --git a/qiskit/tools/jupyter/version_table.py b/qiskit/tools/jupyter/version_table.py index 83a4fb0fbf62..bfc278e62f4e 100644 --- a/qiskit/tools/jupyter/version_table.py +++ b/qiskit/tools/jupyter/version_table.py @@ -11,7 +11,7 @@ # Any modifications or derivative works of this code must retain this # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name, unused-argument +# pylint: disable=unused-argument """A module for monitoring backends.""" diff --git a/qiskit/visualization/counts_visualization.py b/qiskit/visualization/counts_visualization.py index fd3570342d3e..2f11d5da74b6 100644 --- a/qiskit/visualization/counts_visualization.py +++ b/qiskit/visualization/counts_visualization.py @@ -12,7 +12,7 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name,import-error +# pylint: disable=import-error """ Visualization functions for measurement counts. diff --git a/qiskit/visualization/gate_map.py b/qiskit/visualization/gate_map.py index cbb826ec2d22..67a497b31af1 100644 --- a/qiskit/visualization/gate_map.py +++ b/qiskit/visualization/gate_map.py @@ -11,7 +11,6 @@ # Any modifications or derivative works of this code must retain this # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name """A module for visualizing device coupling maps""" @@ -34,6 +33,7 @@ class _GraphDist(): """Transform the circles properly for non-square axes. """ + def __init__(self, size, ax, x=True): self.size = size self.ax = ax # pylint: disable=invalid-name @@ -168,7 +168,7 @@ def plot_gate_map(backend, figsize=None, max_dim = max(x_max, y_max) if figsize is None: - if x_max/max_dim > 0.33 and y_max/max_dim > 0.33: + if x_max / max_dim > 0.33 and y_max / max_dim > 0.33: figsize = (5, 5) else: figsize = (9, 3) @@ -179,9 +179,9 @@ def plot_gate_map(backend, figsize=None, # set coloring if qubit_color is None: - qubit_color = ['#648fff']*config.n_qubits + qubit_color = ['#648fff'] * config.n_qubits if line_color is None: - line_color = ['#648fff']*len(cmap) + line_color = ['#648fff'] * len(cmap) # Add lines for couplings for ind, edge in enumerate(cmap): @@ -195,31 +195,31 @@ def plot_gate_map(backend, figsize=None, if is_symmetric: if y_start == y_end: - x_end = (x_end - x_start)/2+x_start + x_end = (x_end - x_start) / 2 + x_start elif x_start == x_end: - y_end = (y_end - y_start)/2+y_start + y_end = (y_end - y_start) / 2 + y_start else: - x_end = (x_end - x_start)/2+x_start - y_end = (y_end - y_start)/2+y_start + x_end = (x_end - x_start) / 2 + x_start + y_end = (y_end - y_start) / 2 + y_start ax.add_artist(plt.Line2D([x_start, x_end], [-y_start, -y_end], color=line_color[ind], linewidth=line_width, zorder=0)) if plot_directed: - dx = x_end-x_start # pylint: disable=invalid-name - dy = y_end-y_start # pylint: disable=invalid-name + dx = x_end - x_start # pylint: disable=invalid-name + dy = y_end - y_start # pylint: disable=invalid-name if is_symmetric: - x_arrow = x_start+dx*0.95 - y_arrow = -y_start-dy*0.95 - dx_arrow = dx*0.01 - dy_arrow = -dy*0.01 + x_arrow = x_start + dx * 0.95 + y_arrow = -y_start - dy * 0.95 + dx_arrow = dx * 0.01 + dy_arrow = -dy * 0.01 head_width = 0.15 else: - x_arrow = x_start+dx*0.5 - y_arrow = -y_start-dy*0.5 - dx_arrow = dx*0.2 - dy_arrow = -dy*0.2 + x_arrow = x_start + dx * 0.5 + y_arrow = -y_start - dy * 0.5 + dx_arrow = dx * 0.2 + dy_arrow = -dy * 0.2 head_width = 0.2 ax.add_patch(mpatches.FancyArrow(x_arrow, y_arrow, @@ -244,8 +244,8 @@ def plot_gate_map(backend, figsize=None, horizontalalignment='center', verticalalignment='center', color=font_color, size=font_size, weight='bold') - ax.set_xlim([-1, x_max+1]) - ax.set_ylim([-(y_max+1), 1]) + ax.set_xlim([-1, x_max + 1]) + ax.set_ylim([-(y_max + 1), 1]) if not input_axes: if get_backend() in ['module://ipykernel.pylab.backend_inline', 'nbAgg']: @@ -277,7 +277,7 @@ def plot_circuit_layout(circuit, backend, view='virtual'): n_qubits = backend.configuration().n_qubits qubits = [] - qubit_labels = [None]*n_qubits + qubit_labels = [None] * n_qubits if view == 'virtual': idx = 0 @@ -296,13 +296,13 @@ def plot_circuit_layout(circuit, backend, view='virtual'): else: raise VisualizationError("Layout view must be 'virtual' or 'physical'.") - qcolors = ['#648fff']*n_qubits + qcolors = ['#648fff'] * n_qubits for k in qubits: qcolors[k] = 'k' cmap = backend.configuration().coupling_map - lcolors = ['#648fff']*len(cmap) + lcolors = ['#648fff'] * len(cmap) for idx, edge in enumerate(cmap): if edge[0] in qubits and edge[1] in qubits: @@ -338,10 +338,10 @@ def plot_error_map(backend, figsize=(12, 9), show_title=True): # U2 error rates single_gate_errors = [q['parameters'][0]['value'] - for q in props['gates'][1:3*n_qubits:3]] + for q in props['gates'][1:3 * n_qubits:3]] # Convert to percent - single_gate_errors = 100*np.asarray(single_gate_errors) + single_gate_errors = 100 * np.asarray(single_gate_errors) avg_1q_err = np.mean(single_gate_errors) single_norm = matplotlib.colors.Normalize( @@ -367,7 +367,7 @@ def plot_error_map(backend, figsize=(12, 9), show_title=True): continue # Convert to percent - cx_errors = 100*np.asarray(cx_errors) + cx_errors = 100 * np.asarray(cx_errors) avg_cx_err = np.mean(cx_errors) cx_norm = matplotlib.colors.Normalize( @@ -383,21 +383,21 @@ def plot_error_map(backend, figsize=(12, 9), show_title=True): if item['name'] == 'readout_error': read_err.append(item['value']) - read_err = 100*np.asarray(read_err) + read_err = 100 * np.asarray(read_err) avg_read_err = np.mean(read_err) max_read_err = np.max(read_err) fig = plt.figure(figsize=figsize) gridspec.GridSpec(nrows=2, ncols=3) - gs = gridspec.GridSpec(12, 12, height_ratios=[1]*11+[0.5], - width_ratios=[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) + grid_spec = gridspec.GridSpec(12, 12, height_ratios=[1] * 11 + [0.5], + width_ratios=[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) - left_ax = plt.subplot(gs[2:10, :1]) - main_ax = plt.subplot(gs[:11, 1:11]) - right_ax = plt.subplot(gs[2:10, 11:]) - bleft_ax = plt.subplot(gs[-1, :5]) - bright_ax = plt.subplot(gs[-1, 7:]) + left_ax = plt.subplot(grid_spec[2:10, :1]) + main_ax = plt.subplot(grid_spec[:11, 1:11]) + right_ax = plt.subplot(grid_spec[2:10, 11:]) + bleft_ax = plt.subplot(grid_spec[-1, :5]) + bright_ax = plt.subplot(grid_spec[-1, 7:]) plot_gate_map(backend, qubit_color=q_colors, line_color=line_colors, @@ -429,8 +429,8 @@ def plot_error_map(backend, figsize=(12, 9), show_title=True): num_left = n_qubits num_right = 0 else: - num_left = math.ceil(n_qubits/2) - num_right = n_qubits-num_left + num_left = math.ceil(n_qubits / 2) + num_right = n_qubits - num_left left_ax.barh(range(num_left), read_err[:num_left], align='center', color='#007d79') left_ax.axvline(avg_read_err, linestyle='--', color='#212121') diff --git a/qiskit/visualization/pass_manager_visualization.py b/qiskit/visualization/pass_manager_visualization.py index 9f15479f27b3..db29bc33e078 100644 --- a/qiskit/visualization/pass_manager_visualization.py +++ b/qiskit/visualization/pass_manager_visualization.py @@ -12,8 +12,6 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -# pylint: disable=invalid-name - """ Visualization function for a pass manager. Passes are grouped based on their flow controller, and coloured based on the type of pass. @@ -65,17 +63,20 @@ def pass_manager_drawer(pass_manager, filename, style=None, raw=False): try: import subprocess - _PROC = subprocess.Popen(['dot', '-V'], stdout=subprocess.PIPE, + _PROC = subprocess.Popen(['dot', '-V'], # pylint: disable=invalid-name + stdout=subprocess.PIPE, stderr=subprocess.PIPE) _PROC.communicate() if _PROC.returncode != 0: - HAS_GRAPHVIZ = False + has_graphviz = False else: - HAS_GRAPHVIZ = True + has_graphviz = True except Exception: # pylint: disable=broad-except # this is raised when the dot command cannot be found, which means GraphViz # isn't installed - HAS_GRAPHVIZ = False + has_graphviz = False + + HAS_GRAPHVIZ = has_graphviz # pylint: disable=invalid-name try: import pydot