Skip to content

Commit

Permalink
Add retworkx to generated module list in the .pylintrc (#8867)
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
mtreinish authored Oct 10, 2022
1 parent af82b4d commit 2f40849
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qiskit/transpiler/coupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions qiskit/transpiler/passes/basis/basis_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qiskit/visualization/dag_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f40849

Please sign in to comment.