Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Update dependencies, address pylint issues (#250)
Browse files Browse the repository at this point in the history
* enable code coverage reports, rework CI workflow

based on latest updates in https://github.com/qiskit/qiskit-ibm-runtime

* update dependencies, address linting issues

Co-authored-by: Rathish Cholarajan <rathishc24@gmail.com>
  • Loading branch information
daka1510 and rathishcholarajan authored Mar 4, 2022
1 parent ee2121e commit 0cb1c16
Show file tree
Hide file tree
Showing 30 changed files with 546 additions and 415 deletions.
661 changes: 394 additions & 267 deletions .pylintrc

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
astroid==2.3.3
pylint==2.4.4
traitlets!=5.0.5
5 changes: 1 addition & 4 deletions qiskit_ibm_provider/api/clients/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ def stream(

self._current_retry += 1
if self._current_retry > retries:
error_message = (
"Max retries exceeded: Failed to establish a "
f"websocket connection."
)
error_message = "Max retries exceeded: Failed to establish a websocket connection."
if self._error:
error_message += f" Error: {self._error}"

Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_provider/credentials/configrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _section_name(credentials_: Credentials) -> str:
unrolled_credentials[_PREFERENCES_SECTION_NAME] = unrolled_pref

# Write the configuration file.
with open(filename, "w") as config_file:
with open(filename, "w", encoding="utf-8") as config_file:
config_parser = ConfigParser()
config_parser.optionxform = str # type: ignore
config_parser.read_dict(unrolled_credentials)
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_provider/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def run( # type: ignore[override]
<qiskit_ibm_provider.ibm_backend_service.IBMBackendService.jobs>` method.
backend_options: DEPRECATED dictionary of backend options for the execution.
noise_model: Noise model.
kwargs: Additional runtime configuration options. They take
**kwargs: Additional runtime configuration options. They take
precedence over options of the same names specified in `backend_options`.
Returns:
Expand Down
4 changes: 2 additions & 2 deletions qiskit_ibm_provider/ibm_backend_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def backends(
hub: Name of the hub.
group: Name of the group.
project: Name of the project.
kwargs: Simple filters that specify a ``True``/``False`` criteria in the
**kwargs: Simple filters that specify a ``True``/``False`` criteria in the
backend configuration, backends status, or provider credentials.
An example to get the operational backends with 5 qubits::
Expand All @@ -141,7 +141,7 @@ def backends(
IBMBackendValueError: If only one or two parameters from `hub`, `group`,
`project` are specified.
"""
backends: List[IBMBackend] = list()
backends: List[IBMBackend] = []
if all([hub, group, project]):
hgp = self._provider._get_hgp(hub, group, project)
backends = list(hgp.backends.values())
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_provider/ibm_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def backends(
hub: Name of the hub.
group: Name of the group.
project: Name of the project.
kwargs: Simple filters that specify a ``True``/``False`` criteria in the
**kwargs: Simple filters that specify a ``True``/``False`` criteria in the
backend configuration, backends status, or provider credentials.
An example to get the operational backends with 5 qubits::
Expand Down
4 changes: 2 additions & 2 deletions qiskit_ibm_provider/jupyter/dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, children: Optional[List] = None, **kwargs: Any):
**kwargs: Additional keywords to be passed to ``ipywidgets.Accordion``.
"""
children = children or []
super(AccordionWithThread, self).__init__(children=children, **kwargs)
super().__init__(children=children, **kwargs)
self._thread = None
# Devices VBox.
self._device_list = None # type: Optional[wid.VBox]
Expand Down Expand Up @@ -109,7 +109,7 @@ def _get_backends(self) -> None:
)
for backend in hgp.backends.values():
if not backend.configuration().simulator:
if backend.name() not in ibm_backends.keys():
if backend.name() not in ibm_backends:
ibm_backends[backend.name()] = BackendWithProviders(
backend=backend, providers=[hgp_name]
)
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_provider/jupyter/jobs_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _job_summary(
_id = job.job_id()
_name = job.name()
_status = job.status().name
if _year not in jobs_dates.keys():
if _year not in jobs_dates:
jobs_dates[_year] = {}

_month = _date.month
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_provider/jupyter/qubits_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def qubits_tab(backend: Union[IBMBackend, FakeBackend]) -> wid.VBox:
for nduv in qubit_data:
if nduv.name == "readout_error":
cali_data[nduv.name] = str(round(nduv.value * 100, 3))
elif nduv.name in cali_data.keys():
elif nduv.name in cali_data:
cali_data[nduv.name] = str(round(nduv.value, 3)) + " " + nduv.unit

gate_names = []
Expand Down
8 changes: 4 additions & 4 deletions qiskit_ibm_provider/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def _minimal_ext_cmd(cmd: List[str]) -> bytes:
# construct minimal environment
env = {}
for k in ["SYSTEMROOT", "PATH"]:
v = os.environ.get(k)
if v is not None:
env[k] = v
version = os.environ.get(k)
if version is not None:
env[k] = version
# LANGUAGE is used on win32
env["LANGUAGE"] = "C"
env["LANG"] = "C"
Expand Down Expand Up @@ -60,7 +60,7 @@ def git_version() -> str:
return git_revision


with open(os.path.join(ROOT_DIR, "VERSION.txt"), "r") as version_file:
with open(os.path.join(ROOT_DIR, "VERSION.txt"), "r", encoding="utf-8") as version_file:
VERSION = version_file.read().strip()


Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_provider/visualization/interactive/error_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def iplot_error_map(
n_qubits = config.n_qubits
cmap = config.coupling_map

if n_qubits in DEVICE_LAYOUTS.keys():
if n_qubits in DEVICE_LAYOUTS:
grid_data = DEVICE_LAYOUTS[n_qubits]
else:
fig = go.Figure()
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_provider/visualization/interactive/gate_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def iplot_gate_map(
if isinstance(line_color, str):
line_color = [line_color] * len(cmap) if cmap else []

if n_qubits in DEVICE_LAYOUTS.keys():
if n_qubits in DEVICE_LAYOUTS:
grid_data = DEVICE_LAYOUTS[n_qubits]
else:
fig = go.Figure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def show(self, *args, **kwargs) -> None:
import plotly.io as pio

config = {}
if "config" not in kwargs.keys():
if "config" not in kwargs:
config = {"displayModeBar": False, "editable": False}

pio.show(self._fig, *args, config=config, **kwargs)
Expand Down Expand Up @@ -101,7 +101,7 @@ def show(self, *args: Any, **kwargs: Any) -> None:
import plotly.io as pio

config = {}
if "config" not in kwargs.keys():
if "config" not in kwargs:
config = {"scrollZoom": False, "displayModeBar": False, "editable": False}

pio.show(self, *args, config=config, **kwargs)
Expand Down
9 changes: 3 additions & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
mypy==0.812
pycodestyle
pylint==2.4.4
mypy==0.931
pylint==2.12.2
vcrpy
pproxy==2.1.8
pproxy==2.7.8
Sphinx>=1.8.3
sphinx-rtd-theme>=0.4.0
sphinx-tabs>=1.1.11
Expand All @@ -21,9 +20,7 @@ reno>=2.11.0
scipy>=1.0
nbformat>=4.4.0
nbconvert>=5.3.1
qiskit_rng
qiskit-aer
websockets>=8
scikit-quant;platform_system != 'Windows'
black==22.1.0
coverage>=6.3
3 changes: 1 addition & 2 deletions test/contextmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def _mock_initialize_hgps(
self, credentials: Credentials, preferences: Optional[Dict] = None
) -> None:
"""Mock ``_initialize_hgps()``, just storing the credentials."""
hgp = dict()
hgp["credentials"] = credentials
hgp = {"credentials": credentials}
self._hgp = hgp
self._hgps = {}
if preferences:
Expand Down
2 changes: 1 addition & 1 deletion test/fake_account_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def data(self):

time_per_step = {}
timestamp = self._creation_date
for api_stat in API_STATUS_TO_INT:
for api_stat in API_STATUS_TO_INT: # pylint: disable=consider-using-dict-items
if API_STATUS_TO_INT[status] > API_STATUS_TO_INT[api_stat]:
time_per_step[api_stat.value] = timestamp.isoformat()
timestamp += timedelta(seconds=30)
Expand Down
28 changes: 14 additions & 14 deletions test/ibm/test_account_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ def setUpClass(cls, provider, hub, group, project):
def setUp(self):
"""Initial test setup."""
super().setUp()
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
self.qc1 = QuantumCircuit(qr, cr, name="qc1")
self.qc2 = QuantumCircuit(qr, cr, name="qc2")
self.qc1.h(qr)
self.qc2.h(qr[0])
self.qc2.cx(qr[0], qr[1])
self.qc1.measure(qr[0], cr[0])
self.qc1.measure(qr[1], cr[1])
self.qc2.measure(qr[0], cr[0])
self.qc2.measure(qr[1], cr[1])
quantum_register = QuantumRegister(2)
classical_register = ClassicalRegister(2)
self.qc1 = QuantumCircuit(quantum_register, classical_register, name="qc1")
self.qc2 = QuantumCircuit(quantum_register, classical_register, name="qc2")
self.qc1.h(quantum_register)
self.qc2.h(quantum_register[0])
self.qc2.cx(quantum_register[0], quantum_register[1])
self.qc1.measure(quantum_register[0], classical_register[0])
self.qc1.measure(quantum_register[1], classical_register[1])
self.qc2.measure(quantum_register[0], classical_register[0])
self.qc2.measure(quantum_register[1], classical_register[1])
self.seed = 73846087

self.fake_server = None
Expand Down Expand Up @@ -214,9 +214,9 @@ def setUpClass(cls, provider, hub, group, project):
def _get_qobj(backend):
"""Return a Qobj."""
# Create a circuit.
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
qc1 = QuantumCircuit(qr, cr, name="qc1")
quantum_register = QuantumRegister(2)
classical_register = ClassicalRegister(2)
qc1 = QuantumCircuit(quantum_register, classical_register, name="qc1")
seed = 73846087

# Assemble the Qobj.
Expand Down
2 changes: 1 addition & 1 deletion test/ibm/test_basic_server_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ def _submit_job_with_retry(self, circs, backend, max_retry=5):
limit_error = err
time.sleep(1)

self.fail(
return self.fail(
"Unable to submit job after {} retries: {}".format(max_retry, limit_error)
)
2 changes: 1 addition & 1 deletion test/ibm/test_composite_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ def test_job_missing_subjobs(self):
)
with self.assertRaises(IBMJobInvalidStateError) as err_cm:
self.provider.backend.job(job_set.job_id())
self.assertIn(f"tags", str(err_cm.exception))
self.assertIn("tags", str(err_cm.exception))
finally:
job._api_client.job_update_attribute(
job_id=job.job_id(), attr_name="tags", attr_value=saved_tags
Expand Down
56 changes: 30 additions & 26 deletions test/ibm/test_ibm_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ def setUpClass(cls, provider, hub, group, project):

def setUp(self):
super().setUp()
qr = QuantumRegister(1)
cr = ClassicalRegister(1)
self._qc1 = QuantumCircuit(qr, cr, name="qc1")
self._qc2 = QuantumCircuit(qr, cr, name="qc2")
self._qc1.measure(qr[0], cr[0])
self._qc2.x(qr[0])
self._qc2.measure(qr[0], cr[0])
quantum_register = QuantumRegister(1)
classical_register = ClassicalRegister(1)
self._qc1 = QuantumCircuit(quantum_register, classical_register, name="qc1")
self._qc2 = QuantumCircuit(quantum_register, classical_register, name="qc2")
self._qc1.measure(quantum_register[0], classical_register[0])
self._qc2.x(quantum_register[0])
self._qc2.measure(quantum_register[0], classical_register[0])

def test_ibm_result_fields(self):
"""Test components of a result from a remote simulator."""
Expand All @@ -67,61 +67,65 @@ def test_compile_remote(self, backend):
"""Test transpile with a remote backend."""
qubit_reg = QuantumRegister(2, name="q")
clbit_reg = ClassicalRegister(2, name="c")
qc = QuantumCircuit(qubit_reg, clbit_reg, name="bell")
qc.h(qubit_reg[0])
qc.cx(qubit_reg[0], qubit_reg[1])
qc.measure(qubit_reg, clbit_reg)
quantum_circuit = QuantumCircuit(qubit_reg, clbit_reg, name="bell")
quantum_circuit.h(qubit_reg[0])
quantum_circuit.cx(qubit_reg[0], qubit_reg[1])
quantum_circuit.measure(qubit_reg, clbit_reg)

circuits = transpile(qc, backend=backend)
circuits = transpile(quantum_circuit, backend=backend)
self.assertIsInstance(circuits, QuantumCircuit)

@requires_device
def test_compile_two_remote(self, backend):
"""Test transpile with a remote backend on two circuits."""
qubit_reg = QuantumRegister(2, name="q")
clbit_reg = ClassicalRegister(2, name="c")
qc = QuantumCircuit(qubit_reg, clbit_reg, name="bell")
qc.h(qubit_reg[0])
qc.cx(qubit_reg[0], qubit_reg[1])
qc.measure(qubit_reg, clbit_reg)
quantum_circuit = QuantumCircuit(qubit_reg, clbit_reg, name="bell")
quantum_circuit.h(qubit_reg[0])
quantum_circuit.cx(qubit_reg[0], qubit_reg[1])
quantum_circuit.measure(qubit_reg, clbit_reg)
qc_extra = QuantumCircuit(qubit_reg, clbit_reg, name="extra")
qc_extra.measure(qubit_reg, clbit_reg)
circuits = transpile([qc, qc_extra], backend)
circuits = transpile([quantum_circuit, qc_extra], backend)
self.assertIsInstance(circuits[0], QuantumCircuit)
self.assertIsInstance(circuits[1], QuantumCircuit)

def test_compile_two_run_remote(self):
"""Test transpile and run two circuits."""
qubit_reg = QuantumRegister(2, name="q")
clbit_reg = ClassicalRegister(2, name="c")
qc = QuantumCircuit(qubit_reg, clbit_reg, name="bell")
qc.h(qubit_reg[0])
qc.cx(qubit_reg[0], qubit_reg[1])
qc.measure(qubit_reg, clbit_reg)
quantum_circuit = QuantumCircuit(qubit_reg, clbit_reg, name="bell")
quantum_circuit.h(qubit_reg[0])
quantum_circuit.cx(qubit_reg[0], qubit_reg[1])
quantum_circuit.measure(qubit_reg, clbit_reg)
qc_extra = QuantumCircuit(qubit_reg, clbit_reg, name="extra")
qc_extra.measure(qubit_reg, clbit_reg)
circs = transpile(
[qc, qc_extra], backend=self.sim_backend, seed_transpiler=self.seed
[quantum_circuit, qc_extra],
backend=self.sim_backend,
seed_transpiler=self.seed,
)
job = self.sim_backend.run(circs)
result = job.result()
self.assertIsInstance(result, Result)

def test_execute_two_remote(self):
"""Test executing two circuits on a remote backend."""
qc = ReferenceCircuits.bell()
quantum_circuit = ReferenceCircuits.bell()
qc_extra = QuantumCircuit(2, 2)
qc_extra.measure_all()
job = execute([qc, qc_extra], self.sim_backend, seed_transpiler=self.seed)
job = execute(
[quantum_circuit, qc_extra], self.sim_backend, seed_transpiler=self.seed
)
results = job.result()
self.assertIsInstance(results, Result)

@requires_private_provider
def test_private_job(self, provider, hub, group, project):
"""Test a private job."""
backend = provider.get_backend("ibmq_qasm_simulator", hub, group, project)
qc = ReferenceCircuits.bell()
job = execute(qc, backend=backend)
quantum_circuit = ReferenceCircuits.bell()
job = execute(quantum_circuit, backend=backend)
self.assertIsNotNone(job.circuits())
self.assertIsNotNone(job.result())

Expand Down
Loading

0 comments on commit 0cb1c16

Please sign in to comment.