From 2f408493579ccd71ca50bca416b754451b15cfda Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 10 Oct 2022 10:56:35 -0400 Subject: [PATCH] Add retworkx to generated module list in the .pylintrc (#8867) * Add retworkx to generated module list in the .pylintrc With the recent release of retworkx 0.12.0 the package has been renamed to rustworkx. For compatibility the retworkx python namespace continues to work and instead it just redirects imports to the new name. However, pylint is unable to reason about this dynamic import redirecting which causes it to fail in CI. While in 0.23.0 we'll update the requirement to the rustworkx name in order to unblock CI for the pending 0.22.0 release this commit adds the retworkx namespace to the list of generated modules which tells pylint to try not to detect members of the module. * Expand config and add inline excludes where needed The earlier config update wasn't sufficient to get pylint to ignore all retworkx usage. This commit adds additional config entries for retworkx to try and get pylint to exclude it more thoroughly. Additionally, even with these global excludes on pylint there are a few places in the code where additional manual rule disabling was needed to get pylint to pass (further evidence for #1179). --- .pylintrc | 5 +++-- qiskit/circuit/equivalence.py | 2 +- qiskit/transpiler/coupling.py | 2 +- qiskit/transpiler/passes/basis/basis_translator.py | 6 ++++-- qiskit/visualization/dag_visualization.py | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.pylintrc b/.pylintrc index b2f744ba968f..e41f748ef897 100644 --- a/.pylintrc +++ b/.pylintrc @@ -33,8 +33,9 @@ unsafe-load-any-extension=no # A comma-separated list of package or module names from where C extensions may # be loaded. Extensions are loading into the active Python interpreter and may # run arbitrary code -extension-pkg-allow-list=retworkx, numpy, tweedledum, qiskit._accelerate - +extension-pkg-allow-list=retworkx, numpy, tweedledum, qiskit._accelerate, rustworkx +generated-modules=retworkx.visualization,retwork.visit +ignore-modules=retworkx,retworkx.visualization,retworkx.visit [MESSAGES CONTROL] diff --git a/qiskit/circuit/equivalence.py b/qiskit/circuit/equivalence.py index 5440efdb4d1c..381297e45819 100644 --- a/qiskit/circuit/equivalence.py +++ b/qiskit/circuit/equivalence.py @@ -14,7 +14,7 @@ from collections import namedtuple -from retworkx.visualization import graphviz_draw +from retworkx.visualization import graphviz_draw # pylint: disable=no-name-in-module,import-error import retworkx as rx from qiskit.exceptions import InvalidFileError diff --git a/qiskit/transpiler/coupling.py b/qiskit/transpiler/coupling.py index 0f4dc26d12bb..ddc93191f3e3 100644 --- a/qiskit/transpiler/coupling.py +++ b/qiskit/transpiler/coupling.py @@ -23,7 +23,7 @@ import numpy as np import retworkx as rx -from retworkx.visualization import graphviz_draw +from retworkx.visualization import graphviz_draw # pylint: disable=no-name-in-module,import-error from qiskit.transpiler.exceptions import CouplingError diff --git a/qiskit/transpiler/passes/basis/basis_translator.py b/qiskit/transpiler/passes/basis/basis_translator.py index 031f1471fd07..004371c126f1 100644 --- a/qiskit/transpiler/passes/basis/basis_translator.py +++ b/qiskit/transpiler/passes/basis/basis_translator.py @@ -10,6 +10,8 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. +# pylint: disable=missing-function-docstring + """Translates gates to a target basis using a given equivalence library.""" import time @@ -366,7 +368,7 @@ class StopIfBasisRewritable(Exception): """Custom exception that signals `retworkx.dijkstra_search` to stop.""" -class BasisSearchVisitor(retworkx.visit.DijkstraVisitor): +class BasisSearchVisitor(retworkx.visit.DijkstraVisitor): # pylint: disable=no-member """Handles events emitted during `retworkx.dijkstra_search`.""" def __init__(self, graph, source_basis, target_basis, num_gates_for_rule): @@ -412,7 +414,7 @@ def examine_edge(self, edge): # if there are gates in this `rule` that we have not yet generated, we can't apply # this `rule`. if `target` is already in basis, it's not beneficial to use this rule. if self._num_gates_remain_for_rule[index] > 0 or target in self.target_basis: - raise retworkx.visit.PruneSearch + raise retworkx.visit.PruneSearch # pylint: disable=no-member def edge_relaxed(self, edge): _, target, edata = edge diff --git a/qiskit/visualization/dag_visualization.py b/qiskit/visualization/dag_visualization.py index 3c513ba73dd9..a0d0ef7c228a 100644 --- a/qiskit/visualization/dag_visualization.py +++ b/qiskit/visualization/dag_visualization.py @@ -15,7 +15,7 @@ """ Visualization function for DAG circuit representation. """ -from retworkx.visualization import graphviz_draw +from retworkx.visualization import graphviz_draw # pylint: disable=no-name-in-module,import-error from qiskit.dagcircuit.dagnode import DAGOpNode, DAGInNode, DAGOutNode from qiskit.circuit import Qubit