From ef42417f471d603209ca32747ff64477bc3b35d8 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 5 Apr 2024 13:11:46 +0200 Subject: [PATCH 01/18] Provider abstraction is not very useful --- qiskit/providers/provider.py | 14 ++++++++++++++ test/utils/base.py | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/qiskit/providers/provider.py b/qiskit/providers/provider.py index 9bea69c1ea85..e317bcbd0cc7 100644 --- a/qiskit/providers/provider.py +++ b/qiskit/providers/provider.py @@ -15,6 +15,7 @@ from abc import ABC, abstractmethod from qiskit.providers.exceptions import QiskitBackendNotFoundError +from qiskit.utils import deprecate_func class Provider: @@ -28,12 +29,25 @@ class Provider: version = 0 + @deprecate_func( + since=1.1, + additional_msg="The full ABC Provider and ProviderV1 is deprecated and it is going to" + " be removed in 2.0. Just remove it as a super class.", + ) + def __init__(self): + pass + class ProviderV1(Provider, ABC): """Base class for a Backend Provider.""" version = 1 + @deprecate_func( + since=1.1, + additional_msg="The full ABC Provider and ProviderV1 is deprecated and it is going to" + " be removed in 2.0. Just remove it as a super class.", + ) def get_backend(self, name=None, **kwargs): """Return a single backend matching the specified filtering. diff --git a/test/utils/base.py b/test/utils/base.py index 1b8be97641a8..747be7f66b51 100644 --- a/test/utils/base.py +++ b/test/utils/base.py @@ -174,7 +174,8 @@ def tearDown(self): # due to importing the instances from the top-level qiskit namespace. from qiskit.providers.basic_provider import BasicProvider - BasicProvider()._backends = BasicProvider()._verify_backends() + with self.assertWarns(DeprecationWarning): + BasicProvider()._backends = BasicProvider()._verify_backends() @classmethod def setUpClass(cls): From a30b8ec5bb69a294ab517a76f57dcffa987dedda Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 5 Apr 2024 13:30:56 +0200 Subject: [PATCH 02/18] udpate docs --- qiskit/providers/__init__.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/qiskit/providers/__init__.py b/qiskit/providers/__init__.py index 029d335695d5..19d300c9bbf6 100644 --- a/qiskit/providers/__init__.py +++ b/qiskit/providers/__init__.py @@ -17,13 +17,13 @@ .. currentmodule:: qiskit.providers -This module contains the classes used to build external providers for Terra. A -provider is anything that provides an external service to Terra. The typical +This module contains the classes used to build external providers for Qiskit. A +provider is anything that provides an external service to Qiskit. The typical example of this is a Backend provider which provides :class:`~qiskit.providers.Backend` objects which can be used for executing :class:`~qiskit.circuit.QuantumCircuit` and/or :class:`~qiskit.pulse.Schedule` objects. This module contains the abstract classes which are used to define the -interface between a provider and terra. +interface between a provider and Qiskit. Version Support =============== @@ -36,17 +36,17 @@ Version Changes ---------------- -Each minor version release of qiskit-terra **may** increment the version of any -providers interface a single version number. It will be an aggregate of all +Each minor version release of ``qiskit`` **may** increment the version of any +backend interface a single version number. It will be an aggregate of all the interface changes for that release on that interface. Version Support Policy ---------------------- To enable providers to have time to adjust to changes in this interface -Terra will support multiple versions of each class at once. Given the +Qiskit will support multiple versions of each class at once. Given the nature of one version per release the version deprecation policy is a bit -more conservative than the standard deprecation policy. Terra will support a +more conservative than the standard deprecation policy. Qiskit will support a provider interface version for a minimum of 3 minor releases or the first release after 6 months from the release that introduced a version, whichever is longer, prior to a potential deprecation. After that the standard deprecation @@ -57,17 +57,17 @@ 0.19.0 we release 0.23.0. In 0.23.0 we can deprecate BackendV2, and it needs to still be supported and can't be removed until the deprecation policy completes. -It's worth pointing out that Terra's version support policy doesn't mean +It's worth pointing out that Qiskit's version support policy doesn't mean providers themselves will have the same support story, they can (and arguably should) update to newer versions as soon as they can, the support window is -just for Terra's supported versions. Part of this lengthy window prior to +just for Qiskit's supported versions. Part of this lengthy window prior to deprecation is to give providers enough time to do their own deprecation of a potential end user impacting change in a user facing part of the interface prior to bumping their version. For example, let's say we changed the signature to ``Backend.run()`` in ``BackendV34`` in a backwards incompatible way. Before Aer could update its :class:`~qiskit_aer.AerSimulator` class to be based on version 34 they'd need to deprecate the old signature prior to switching -over. The changeover for Aer is not guaranteed to be lockstep with Terra so we +over. The changeover for Aer is not guaranteed to be lockstep with Qiskit, so we need to ensure there is a sufficient amount of time for Aer to complete its deprecation cycle prior to removing version 33 (ie making version 34 mandatory/the minimum version). @@ -131,12 +131,13 @@ .. autoexception:: JobTimeoutError .. autoexception:: BackendConfigurationError -====================== -Writing a New Provider -====================== +===================== +Writing a New Backend +===================== If you have a quantum device or simulator that you would like to integrate with -Qiskit you will need to write a provider. A provider will provide Terra with a +Qiskit you will need to write a backend. A provider is a collection of backends +and will provide Qiskit with a method to get available :class:`~qiskit.providers.BackendV2` objects. The :class:`~qiskit.providers.BackendV2` object provides both information describing a backend and its operation for the :mod:`~qiskit.transpiler` so that circuits @@ -149,8 +150,7 @@ fashion regardless of how the backend is implemented. At a high level the basic steps for writing a provider are: - * Implement a :class:`~qiskit.providers.ProviderV1` subclass that handles - access to the backend(s). + * Implement a ``Provider`` class that handles access to the backend(s). * Implement a :class:`~qiskit.providers.BackendV2` subclass and its :meth:`~qiskit.providers.BackendV2.run` method. @@ -173,12 +173,11 @@ and methods to filter and acquire backends (using the provided credentials if required). An example provider class looks like:: - from qiskit.providers import ProviderV1 as Provider from qiskit.providers.providerutils import filter_backends from .backend import MyBackend - class MyProvider(Provider): + class MyProvider: def __init__(self, token=None): super().__init__() From 2822a7deca9f3da523c8260d6fae7abbe2e9b32f Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 5 Apr 2024 14:01:29 +0200 Subject: [PATCH 03/18] ignore deprecations --- test/python/primitives/test_backend_sampler.py | 3 ++- .../basic_provider/test_basic_provider_backends.py | 9 ++++++--- .../test_multi_registers_convention.py | 3 ++- test/python/transpiler/test_sabre_swap.py | 12 +++++++----- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/test/python/primitives/test_backend_sampler.py b/test/python/primitives/test_backend_sampler.py index b455e6b5dc17..8d1a3e2aab2b 100644 --- a/test/python/primitives/test_backend_sampler.py +++ b/test/python/primitives/test_backend_sampler.py @@ -352,7 +352,8 @@ def test_circuit_with_dynamic_circuit(self): qc.measure(0, 0) qc.break_loop().c_if(0, True) - backend = Aer.get_backend("aer_simulator") + with self.assertWarns(DeprecationWarning): + backend = Aer.get_backend("aer_simulator") sampler = BackendSampler(backend, skip_transpilation=True) sampler.set_options(seed_simulator=15) sampler.set_transpile_options(seed_transpiler=15) diff --git a/test/python/providers/basic_provider/test_basic_provider_backends.py b/test/python/providers/basic_provider/test_basic_provider_backends.py index d761015d04e1..5c00ec87671a 100644 --- a/test/python/providers/basic_provider/test_basic_provider_backends.py +++ b/test/python/providers/basic_provider/test_basic_provider_backends.py @@ -22,7 +22,8 @@ class TestBasicProviderBackends(QiskitTestCase): def setUp(self): super().setUp() - self.provider = BasicProvider() + with self.assertWarns(DeprecationWarning): + self.provider = BasicProvider() self.backend_name = "basic_simulator" def test_backends(self): @@ -32,9 +33,11 @@ def test_backends(self): def test_get_backend(self): """Test getting a backend from the provider.""" - backend = self.provider.get_backend(name=self.backend_name) + with self.assertWarns(DeprecationWarning): + backend = self.provider.get_backend(name=self.backend_name) self.assertEqual(backend.name, self.backend_name) def test_aliases_fail(self): """Test a failing backend lookup.""" - self.assertRaises(QiskitBackendNotFoundError, BasicProvider().get_backend, "bad_name") + with self.assertWarns(DeprecationWarning): + self.assertRaises(QiskitBackendNotFoundError, BasicProvider().get_backend, "bad_name") diff --git a/test/python/providers/basic_provider/test_multi_registers_convention.py b/test/python/providers/basic_provider/test_multi_registers_convention.py index a6d114f6b5b7..8ebf559f938c 100644 --- a/test/python/providers/basic_provider/test_multi_registers_convention.py +++ b/test/python/providers/basic_provider/test_multi_registers_convention.py @@ -36,7 +36,8 @@ def test_circuit_multi(self): qc = circ.compose(meas) - backend_sim = BasicProvider().get_backend("basic_simulator") + with self.assertWarns(DeprecationWarning): + backend_sim = BasicProvider().get_backend("basic_simulator") result = backend_sim.run(qc).result() counts = result.get_counts(qc) diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index e63565c14b05..8414568f7a5f 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -271,14 +271,16 @@ def test_no_infinite_loop(self, method): # `couplings <= coupling_map`. self.assertEqual(couplings - set(coupling_map.get_edges()), set()) - # Assert that the same keys are produced by a simulation - this is a test that the inserted - # swaps route the qubits correctly. - if not optionals.HAS_AER: - return + with self.assertWarns(DeprecationWarning): + # Assert that the same keys are produced by a simulation - this is a test that the inserted + # swaps route the qubits correctly. + if not optionals.HAS_AER: + return from qiskit_aer import Aer - sim = Aer.get_backend("aer_simulator") + with self.assertWarns(DeprecationWarning): + sim = Aer.get_backend("aer_simulator") in_results = sim.run(qc, shots=4096).result().get_counts() out_results = sim.run(routed, shots=4096).result().get_counts() self.assertEqual(set(in_results), set(out_results)) From 26be87ed19cabeeec0e44a00b962ea0da9d3f88b Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 5 Apr 2024 14:29:52 +0200 Subject: [PATCH 04/18] not triggered on CI --- test/python/transpiler/test_sabre_swap.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/python/transpiler/test_sabre_swap.py b/test/python/transpiler/test_sabre_swap.py index 8414568f7a5f..a9fec85be665 100644 --- a/test/python/transpiler/test_sabre_swap.py +++ b/test/python/transpiler/test_sabre_swap.py @@ -271,11 +271,10 @@ def test_no_infinite_loop(self, method): # `couplings <= coupling_map`. self.assertEqual(couplings - set(coupling_map.get_edges()), set()) - with self.assertWarns(DeprecationWarning): - # Assert that the same keys are produced by a simulation - this is a test that the inserted - # swaps route the qubits correctly. - if not optionals.HAS_AER: - return + # Assert that the same keys are produced by a simulation - this is a test that the inserted + # swaps route the qubits correctly. + if not optionals.HAS_AER: + return from qiskit_aer import Aer From 2462c08dca5cf17041da59a29cf17a80e4bbc0a7 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 8 Apr 2024 09:15:29 +0200 Subject: [PATCH 05/18] deprecation warnings in visual tests --- .../circuit/test_circuit_matplotlib_drawer.py | 15 +++++--- .../mpl/graph/test_graph_matplotlib_drawer.py | 36 ++++++++++++------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py index e99cb3f628d8..202cb454bf20 100644 --- a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py +++ b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py @@ -836,9 +836,13 @@ def test_partial_layout(self): See: https://github.com/Qiskit/qiskit-terra/issues/4757""" circuit = QuantumCircuit(3) circuit.h(1) + + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(5, coupling_map=TENERIFE_CMAP) + transpiled = transpile( circuit, - backend=GenericBackendV2(5, coupling_map=TENERIFE_CMAP), + backend=backend, basis_gates=["id", "cx", "rz", "sx", "x"], optimization_level=0, initial_layout=[1, 2, 0], @@ -2178,7 +2182,8 @@ def test_control_flow_layout(self): qc.cx(0, 1) with case(case.DEFAULT): qc.h(0) - backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=16) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=16) backend.target.add_instruction(SwitchCaseOp, name="switch_case") tqc = transpile(qc, backend, optimization_level=2, seed_transpiler=671_42) fname = "layout_control_flow.png" @@ -2211,7 +2216,8 @@ def test_control_flow_nested_layout(self): with case(case.DEFAULT): with qc.if_test((creg[1], 0)): qc.h(0) - backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=0) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=0) backend.target.add_instruction(SwitchCaseOp, name="switch_case") backend.target.add_instruction(IfElseOp, name="if_else") tqc = transpile(qc, backend, optimization_level=2, seed_transpiler=671_42) @@ -2278,7 +2284,8 @@ def test_annotated_operation(self): def test_no_qreg_names_after_layout(self): """Test that full register names are not shown after transpilation. See https://github.com/Qiskit/qiskit-terra/issues/11038""" - backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=42) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=42) qc = QuantumCircuit(3) qc.cx(0, 1) diff --git a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py index ae69f212f89c..41cb216c72a7 100644 --- a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py +++ b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py @@ -389,7 +389,8 @@ def test_plot_1_qubit_gate_map(self): """Test plot_gate_map using 1 qubit backend""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=1) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=1) fname = "1_qubit_gate_map.png" self.graph_plot_gate_map(backend=backend, filename=fname) @@ -407,7 +408,8 @@ def test_plot_5_qubit_gate_map(self): """Test plot_gate_map using 5 qubit backend""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) fname = "5_qubit_gate_map.png" self.graph_plot_gate_map(backend=backend, filename=fname) @@ -425,7 +427,8 @@ def test_plot_7_qubit_gate_map(self): """Test plot_gate_map using 7 qubit backend""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) fname = "7_qubit_gate_map.png" self.graph_plot_gate_map(backend=backend, filename=fname) @@ -443,7 +446,8 @@ def test_plot_16_qubit_gate_map(self): """Test plot_gate_map using 16 qubit backend""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP) fname = "16_qubit_gate_map.png" self.graph_plot_gate_map(backend=backend, filename=fname) @@ -461,7 +465,8 @@ def test_plot_27_qubit_gate_map(self): """Test plot_gate_map using 27 qubit backend""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) fname = "27_qubit_gate_map.png" self.graph_plot_gate_map(backend=backend, filename=fname) @@ -479,7 +484,8 @@ def test_plot_65_qubit_gate_map(self): """test for plot_gate_map using 65 qubit backend""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) fname = "65_qubit_gate_map.png" self.graph_plot_gate_map(backend=backend, filename=fname) @@ -497,7 +503,8 @@ def test_figsize(self): """Test figsize parameter of plot_gate_map""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) fname = "figsize.png" self.graph_plot_gate_map(backend=backend, figsize=(10, 10), filename=fname) @@ -515,7 +522,8 @@ def test_qubit_size(self): """Test qubit_size parameter of plot_gate_map""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) fname = "qubit_size.png" self.graph_plot_gate_map(backend=backend, qubit_size=38, filename=fname) @@ -533,7 +541,8 @@ def test_qubit_color(self): """Test qubit_color parameter of plot_gate_map""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) fname = "qubit_color.png" self.graph_plot_gate_map(backend=backend, qubit_color=["#ff0000"] * 7, filename=fname) @@ -551,7 +560,8 @@ def test_qubit_labels(self): """Test qubit_labels parameter of plot_gate_map""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) fname = "qubit_labels.png" self.graph_plot_gate_map( @@ -571,7 +581,8 @@ def test_line_color(self): """Test line_color parameter of plot_gate_map""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) fname = "line_color.png" self.graph_plot_gate_map(backend=backend, line_color=["#00ff00"] * 144, filename=fname) @@ -589,7 +600,8 @@ def test_font_color(self): """Test font_color parameter of plot_gate_map""" # getting the mock backend from FakeProvider - backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + with self.assertWarns(DeprecationWarning): + backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) fname = "font_color.png" self.graph_plot_gate_map(backend=backend, font_color="#ff00ff", filename=fname) From 13dd0cd30aa4ee41dddc0365bdbe94f5f57a26ea Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 8 Apr 2024 11:47:43 +0200 Subject: [PATCH 06/18] set up --- .../mpl/graph/test_graph_matplotlib_drawer.py | 70 +++++++------------ 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py index 41cb216c72a7..4e2559893b01 100644 --- a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py +++ b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py @@ -75,6 +75,15 @@ def setUp(self): plot_coupling_map, str(self), RESULT_DIR ) + with self.assertWarns(DeprecationWarning): + self.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) + self.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) + self.backend_16_rueschlikon = GenericBackendV2( + num_qubits=16, coupling_map=RUESCHLIKON_CMAP + ) + self.backend_27_mumbai = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) + self.backend_65_manhattan = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + if not os.path.exists(FAILURE_DIFF_DIR): os.makedirs(FAILURE_DIFF_DIR) @@ -408,11 +417,8 @@ def test_plot_5_qubit_gate_map(self): """Test plot_gate_map using 5 qubit backend""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) - fname = "5_qubit_gate_map.png" - self.graph_plot_gate_map(backend=backend, filename=fname) + self.graph_plot_gate_map(backend=self.backend_5_yorktown, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -427,11 +433,8 @@ def test_plot_7_qubit_gate_map(self): """Test plot_gate_map using 7 qubit backend""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) - fname = "7_qubit_gate_map.png" - self.graph_plot_gate_map(backend=backend, filename=fname) + self.graph_plot_gate_map(backend=self.backend_7_lagos, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -446,11 +449,8 @@ def test_plot_16_qubit_gate_map(self): """Test plot_gate_map using 16 qubit backend""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP) - fname = "16_qubit_gate_map.png" - self.graph_plot_gate_map(backend=backend, filename=fname) + self.graph_plot_gate_map(backend=self.backend_16_rueschlikon, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -465,11 +465,8 @@ def test_plot_27_qubit_gate_map(self): """Test plot_gate_map using 27 qubit backend""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) - fname = "27_qubit_gate_map.png" - self.graph_plot_gate_map(backend=backend, filename=fname) + self.graph_plot_gate_map(backend=self.backend_27_mumbai, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -484,11 +481,8 @@ def test_plot_65_qubit_gate_map(self): """test for plot_gate_map using 65 qubit backend""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) - fname = "65_qubit_gate_map.png" - self.graph_plot_gate_map(backend=backend, filename=fname) + self.graph_plot_gate_map(backend=self.backend_65_manhattan, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -503,11 +497,8 @@ def test_figsize(self): """Test figsize parameter of plot_gate_map""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) - fname = "figsize.png" - self.graph_plot_gate_map(backend=backend, figsize=(10, 10), filename=fname) + self.graph_plot_gate_map(backend=self.backend_5_yorktown, figsize=(10, 10), filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -522,11 +513,8 @@ def test_qubit_size(self): """Test qubit_size parameter of plot_gate_map""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) - fname = "qubit_size.png" - self.graph_plot_gate_map(backend=backend, qubit_size=38, filename=fname) + self.graph_plot_gate_map(backend=self.backend_5_yorktown, qubit_size=38, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -541,11 +529,10 @@ def test_qubit_color(self): """Test qubit_color parameter of plot_gate_map""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) - fname = "qubit_color.png" - self.graph_plot_gate_map(backend=backend, qubit_color=["#ff0000"] * 7, filename=fname) + self.graph_plot_gate_map( + backend=self.backend_7_lagos, qubit_color=["#ff0000"] * 7, filename=fname + ) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -560,12 +547,9 @@ def test_qubit_labels(self): """Test qubit_labels parameter of plot_gate_map""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) - fname = "qubit_labels.png" self.graph_plot_gate_map( - backend=backend, qubit_labels=list(range(10, 17, 1)), filename=fname + backend=self.backend_7_lagos, qubit_labels=list(range(10, 17, 1)), filename=fname ) ratio = VisualTestUtilities._save_diff( @@ -581,11 +565,10 @@ def test_line_color(self): """Test line_color parameter of plot_gate_map""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) - fname = "line_color.png" - self.graph_plot_gate_map(backend=backend, line_color=["#00ff00"] * 144, filename=fname) + self.graph_plot_gate_map( + backend=self.backend_65_manhattan, line_color=["#00ff00"] * 144, filename=fname + ) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -600,11 +583,10 @@ def test_font_color(self): """Test font_color parameter of plot_gate_map""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) - fname = "font_color.png" - self.graph_plot_gate_map(backend=backend, font_color="#ff00ff", filename=fname) + self.graph_plot_gate_map( + backend=self.backend_65_manhattan, font_color="#ff00ff", filename=fname + ) ratio = VisualTestUtilities._save_diff( self._image_path(fname), From 6c26b1f6a951d7d3f9396019089b1443b0e9dae5 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 8 Apr 2024 13:10:26 +0200 Subject: [PATCH 07/18] set up without warning? --- .../mpl/graph/test_graph_matplotlib_drawer.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py index 4e2559893b01..bf2d2815bc1d 100644 --- a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py +++ b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py @@ -75,14 +75,11 @@ def setUp(self): plot_coupling_map, str(self), RESULT_DIR ) - with self.assertWarns(DeprecationWarning): - self.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) - self.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) - self.backend_16_rueschlikon = GenericBackendV2( - num_qubits=16, coupling_map=RUESCHLIKON_CMAP - ) - self.backend_27_mumbai = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) - self.backend_65_manhattan = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + self.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) + self.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) + self.backend_16_rueschlikon = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP) + self.backend_27_mumbai = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) + self.backend_65_manhattan = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) if not os.path.exists(FAILURE_DIFF_DIR): os.makedirs(FAILURE_DIFF_DIR) From df178a3fd8732bbc7cbe993589997a73855c0486 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 9 Apr 2024 09:25:23 +0200 Subject: [PATCH 08/18] setUpClass --- .../mpl/graph/test_graph_matplotlib_drawer.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py index bf2d2815bc1d..e325d4f8d699 100644 --- a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py +++ b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py @@ -60,6 +60,15 @@ def cwd(path): class TestGraphMatplotlibDrawer(QiskitTestCase): """Graph MPL visualization""" + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) + cls.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) + cls.backend_16_rueschlikon = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP) + cls.backend_27_mumbai = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) + cls.backend_65_manhattan = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + def setUp(self): super().setUp() self.graph_state_drawer = VisualTestUtilities.save_data_wrap( @@ -75,12 +84,6 @@ def setUp(self): plot_coupling_map, str(self), RESULT_DIR ) - self.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) - self.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) - self.backend_16_rueschlikon = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP) - self.backend_27_mumbai = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) - self.backend_65_manhattan = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) - if not os.path.exists(FAILURE_DIFF_DIR): os.makedirs(FAILURE_DIFF_DIR) From a2e1f44315871b8dc2e9b814a2e0bfc12e67a088 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 9 Apr 2024 16:08:51 +0200 Subject: [PATCH 09/18] more test adjust --- qiskit/providers/backend.py | 4 +-- .../circuit/test_circuit_matplotlib_drawer.py | 32 ++++++++++++------- .../mpl/graph/test_graph_matplotlib_drawer.py | 20 ++++++------ 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/qiskit/providers/backend.py b/qiskit/providers/backend.py index 5ff10b5f7f74..8ffc7765109c 100644 --- a/qiskit/providers/backend.py +++ b/qiskit/providers/backend.py @@ -40,8 +40,8 @@ class Backend: class BackendV1(Backend, ABC): """Abstract class for Backends - This abstract class is to be used for all Backend objects created by a - provider. There are several classes of information contained in a Backend. + This abstract class is to be used for Backend objects. + There are several classes of information contained in a Backend. The first are the attributes of the class itself. These should be used to defined the immutable characteristics of the backend. The ``options`` attribute of the backend is used to contain the dynamic user configurable diff --git a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py index 202cb454bf20..6437fed2b4f8 100644 --- a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py +++ b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py @@ -73,6 +73,17 @@ class TestCircuitMatplotlibDrawer(QiskitTestCase): """Circuit MPL visualization""" + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42) + cls.backend_5_tenerife = GenericBackendV2(num_qubits=5, coupling_map=TENERIFE_CMAP, seed=42) + cls.backend_yorktown_with_switch_if = GenericBackendV2( + num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42 + ) + cls.backend_yorktown_with_switch_if.target.add_instruction(SwitchCaseOp, name="switch_case") + cls.backend_yorktown_with_switch_if.target.add_instruction(IfElseOp, name="if_else") + def setUp(self): super().setUp() self.threshold = 0.9999 @@ -837,12 +848,9 @@ def test_partial_layout(self): circuit = QuantumCircuit(3) circuit.h(1) - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(5, coupling_map=TENERIFE_CMAP) - transpiled = transpile( circuit, - backend=backend, + backend=self.backend_5_tenerife, basis_gates=["id", "cx", "rz", "sx", "x"], optimization_level=0, initial_layout=[1, 2, 0], @@ -2216,11 +2224,9 @@ def test_control_flow_nested_layout(self): with case(case.DEFAULT): with qc.if_test((creg[1], 0)): qc.h(0) - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=0) - backend.target.add_instruction(SwitchCaseOp, name="switch_case") - backend.target.add_instruction(IfElseOp, name="if_else") - tqc = transpile(qc, backend, optimization_level=2, seed_transpiler=671_42) + tqc = transpile( + qc, self.backend_yorktown_with_switch_if, optimization_level=2, seed_transpiler=671_42 + ) fname = "nested_layout_control_flow.png" self.circuit_drawer(tqc, output="mpl", filename=fname) @@ -2284,15 +2290,17 @@ def test_annotated_operation(self): def test_no_qreg_names_after_layout(self): """Test that full register names are not shown after transpilation. See https://github.com/Qiskit/qiskit-terra/issues/11038""" - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=42) qc = QuantumCircuit(3) qc.cx(0, 1) qc.cx(1, 2) qc.cx(2, 0) circuit = transpile( - qc, backend, basis_gates=["rz", "sx", "cx"], layout_method="sabre", seed_transpiler=42 + qc, + self.backend_5_yorktown, + basis_gates=["rz", "sx", "cx"], + layout_method="sabre", + seed_transpiler=42, ) fname = "qreg_names_after_layout.png" diff --git a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py index e325d4f8d699..34d2a33c5afa 100644 --- a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py +++ b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py @@ -63,11 +63,16 @@ class TestGraphMatplotlibDrawer(QiskitTestCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) - cls.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) - cls.backend_16_rueschlikon = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP) - cls.backend_27_mumbai = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) - cls.backend_65_manhattan = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + cls.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42) + cls.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP, seed=42) + cls.backend_16_rueschlikon = GenericBackendV2( + num_qubits=16, coupling_map=RUESCHLIKON_CMAP, seed=42 + ) + cls.backend_27_mumbai = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP, seed=42) + cls.backend_65_manhattan = GenericBackendV2( + num_qubits=65, coupling_map=MANHATTAN_CMAP, seed=42 + ) + cls.backend1Q = GenericBackendV2(num_qubits=1, seed=42) def setUp(self): super().setUp() @@ -398,11 +403,8 @@ def test_plot_1_qubit_gate_map(self): """Test plot_gate_map using 1 qubit backend""" # getting the mock backend from FakeProvider - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(num_qubits=1) - fname = "1_qubit_gate_map.png" - self.graph_plot_gate_map(backend=backend, filename=fname) + self.graph_plot_gate_map(backend=self.backend1Q, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), From 5c3a9fd99ab31392b4a8a784ebd2c1fb31657ff5 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 11 Apr 2024 10:30:39 +0200 Subject: [PATCH 10/18] raise at setUpClass --- .../mpl/graph/test_graph_matplotlib_drawer.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py index 34d2a33c5afa..a8c00ebe8b10 100644 --- a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py +++ b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py @@ -63,16 +63,21 @@ class TestGraphMatplotlibDrawer(QiskitTestCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42) - cls.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP, seed=42) - cls.backend_16_rueschlikon = GenericBackendV2( - num_qubits=16, coupling_map=RUESCHLIKON_CMAP, seed=42 - ) - cls.backend_27_mumbai = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP, seed=42) - cls.backend_65_manhattan = GenericBackendV2( - num_qubits=65, coupling_map=MANHATTAN_CMAP, seed=42 - ) - cls.backend1Q = GenericBackendV2(num_qubits=1, seed=42) + with cls.assertRaises(DeprecationWarning): + cls.backend_5_yorktown = GenericBackendV2( + num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42 + ) + cls.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP, seed=42) + cls.backend_16_rueschlikon = GenericBackendV2( + num_qubits=16, coupling_map=RUESCHLIKON_CMAP, seed=42 + ) + cls.backend_27_mumbai = GenericBackendV2( + num_qubits=27, coupling_map=MUMBAI_CMAP, seed=42 + ) + cls.backend_65_manhattan = GenericBackendV2( + num_qubits=65, coupling_map=MANHATTAN_CMAP, seed=42 + ) + cls.backend1Q = GenericBackendV2(num_qubits=1, seed=42) def setUp(self): super().setUp() From d125803a3f2ed183f6e64c89e52b82b1397141be Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 11 Apr 2024 11:28:42 +0200 Subject: [PATCH 11/18] warms --- test/visual/mpl/graph/test_graph_matplotlib_drawer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py index a8c00ebe8b10..507803998a05 100644 --- a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py +++ b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py @@ -63,7 +63,7 @@ class TestGraphMatplotlibDrawer(QiskitTestCase): @classmethod def setUpClass(cls): super().setUpClass() - with cls.assertRaises(DeprecationWarning): + with cls.assertWarns(DeprecationWarning): cls.backend_5_yorktown = GenericBackendV2( num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42 ) From 2af7adba13616a1c3031c0be6413e097cf710d04 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 12 Apr 2024 13:38:35 +0200 Subject: [PATCH 12/18] test_circuit_matplotlib_drawer.py --- .../circuit/test_circuit_matplotlib_drawer.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py index 6437fed2b4f8..db2da3824813 100644 --- a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py +++ b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py @@ -76,13 +76,20 @@ class TestCircuitMatplotlibDrawer(QiskitTestCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.backend_5_yorktown = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42) - cls.backend_5_tenerife = GenericBackendV2(num_qubits=5, coupling_map=TENERIFE_CMAP, seed=42) - cls.backend_yorktown_with_switch_if = GenericBackendV2( - num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42 - ) - cls.backend_yorktown_with_switch_if.target.add_instruction(SwitchCaseOp, name="switch_case") - cls.backend_yorktown_with_switch_if.target.add_instruction(IfElseOp, name="if_else") + with cls.assertWarns(DeprecationWarning): + cls.backend_5_yorktown = GenericBackendV2( + num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42 + ) + cls.backend_5_tenerife = GenericBackendV2( + num_qubits=5, coupling_map=TENERIFE_CMAP, seed=42 + ) + cls.backend_yorktown_with_switch_if = GenericBackendV2( + num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42 + ) + cls.backend_yorktown_with_switch_if.target.add_instruction( + SwitchCaseOp, name="switch_case" + ) + cls.backend_yorktown_with_switch_if.target.add_instruction(IfElseOp, name="if_else") def setUp(self): super().setUp() From b03af736366b3d7eab0540440d59f0297d7bc18f Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 12 Apr 2024 14:39:32 +0200 Subject: [PATCH 13/18] skip Aer warning --- .../fake_provider/generic_backend_v2.py | 14 ++-- .../circuit/test_circuit_matplotlib_drawer.py | 38 ++-------- .../mpl/graph/test_graph_matplotlib_drawer.py | 73 +++++++++---------- 3 files changed, 53 insertions(+), 72 deletions(-) diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 3776211cc08c..6b4970349fb0 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -526,12 +526,16 @@ def _setup_sim(self) -> None: @classmethod def _default_options(cls) -> Options: - if _optionals.HAS_AER: - from qiskit_aer import AerSimulator + with warnings.catch_warnings(): # TODO remove catch once aer release without Provider ABC + warnings.filterwarnings( + "ignore", category=DeprecationWarning, message=".+ABC Provider and ProviderV1.+" + ) + if _optionals.HAS_AER: + from qiskit_aer import AerSimulator - return AerSimulator._default_options() - else: - return BasicSimulator._default_options() + return AerSimulator._default_options() + else: + return BasicSimulator._default_options() def drive_channel(self, qubit: int): drive_channels_map = getattr(self, "channels_map", {}).get("drive", {}) diff --git a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py index db2da3824813..e99cb3f628d8 100644 --- a/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py +++ b/test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py @@ -73,24 +73,6 @@ class TestCircuitMatplotlibDrawer(QiskitTestCase): """Circuit MPL visualization""" - @classmethod - def setUpClass(cls): - super().setUpClass() - with cls.assertWarns(DeprecationWarning): - cls.backend_5_yorktown = GenericBackendV2( - num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42 - ) - cls.backend_5_tenerife = GenericBackendV2( - num_qubits=5, coupling_map=TENERIFE_CMAP, seed=42 - ) - cls.backend_yorktown_with_switch_if = GenericBackendV2( - num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42 - ) - cls.backend_yorktown_with_switch_if.target.add_instruction( - SwitchCaseOp, name="switch_case" - ) - cls.backend_yorktown_with_switch_if.target.add_instruction(IfElseOp, name="if_else") - def setUp(self): super().setUp() self.threshold = 0.9999 @@ -854,10 +836,9 @@ def test_partial_layout(self): See: https://github.com/Qiskit/qiskit-terra/issues/4757""" circuit = QuantumCircuit(3) circuit.h(1) - transpiled = transpile( circuit, - backend=self.backend_5_tenerife, + backend=GenericBackendV2(5, coupling_map=TENERIFE_CMAP), basis_gates=["id", "cx", "rz", "sx", "x"], optimization_level=0, initial_layout=[1, 2, 0], @@ -2197,8 +2178,7 @@ def test_control_flow_layout(self): qc.cx(0, 1) with case(case.DEFAULT): qc.h(0) - with self.assertWarns(DeprecationWarning): - backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=16) + backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=16) backend.target.add_instruction(SwitchCaseOp, name="switch_case") tqc = transpile(qc, backend, optimization_level=2, seed_transpiler=671_42) fname = "layout_control_flow.png" @@ -2231,9 +2211,10 @@ def test_control_flow_nested_layout(self): with case(case.DEFAULT): with qc.if_test((creg[1], 0)): qc.h(0) - tqc = transpile( - qc, self.backend_yorktown_with_switch_if, optimization_level=2, seed_transpiler=671_42 - ) + backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=0) + backend.target.add_instruction(SwitchCaseOp, name="switch_case") + backend.target.add_instruction(IfElseOp, name="if_else") + tqc = transpile(qc, backend, optimization_level=2, seed_transpiler=671_42) fname = "nested_layout_control_flow.png" self.circuit_drawer(tqc, output="mpl", filename=fname) @@ -2297,17 +2278,14 @@ def test_annotated_operation(self): def test_no_qreg_names_after_layout(self): """Test that full register names are not shown after transpilation. See https://github.com/Qiskit/qiskit-terra/issues/11038""" + backend = GenericBackendV2(5, coupling_map=YORKTOWN_CMAP, seed=42) qc = QuantumCircuit(3) qc.cx(0, 1) qc.cx(1, 2) qc.cx(2, 0) circuit = transpile( - qc, - self.backend_5_yorktown, - basis_gates=["rz", "sx", "cx"], - layout_method="sabre", - seed_transpiler=42, + qc, backend, basis_gates=["rz", "sx", "cx"], layout_method="sabre", seed_transpiler=42 ) fname = "qreg_names_after_layout.png" diff --git a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py index 507803998a05..ae69f212f89c 100644 --- a/test/visual/mpl/graph/test_graph_matplotlib_drawer.py +++ b/test/visual/mpl/graph/test_graph_matplotlib_drawer.py @@ -60,25 +60,6 @@ def cwd(path): class TestGraphMatplotlibDrawer(QiskitTestCase): """Graph MPL visualization""" - @classmethod - def setUpClass(cls): - super().setUpClass() - with cls.assertWarns(DeprecationWarning): - cls.backend_5_yorktown = GenericBackendV2( - num_qubits=5, coupling_map=YORKTOWN_CMAP, seed=42 - ) - cls.backend_7_lagos = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP, seed=42) - cls.backend_16_rueschlikon = GenericBackendV2( - num_qubits=16, coupling_map=RUESCHLIKON_CMAP, seed=42 - ) - cls.backend_27_mumbai = GenericBackendV2( - num_qubits=27, coupling_map=MUMBAI_CMAP, seed=42 - ) - cls.backend_65_manhattan = GenericBackendV2( - num_qubits=65, coupling_map=MANHATTAN_CMAP, seed=42 - ) - cls.backend1Q = GenericBackendV2(num_qubits=1, seed=42) - def setUp(self): super().setUp() self.graph_state_drawer = VisualTestUtilities.save_data_wrap( @@ -408,8 +389,10 @@ def test_plot_1_qubit_gate_map(self): """Test plot_gate_map using 1 qubit backend""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=1) + fname = "1_qubit_gate_map.png" - self.graph_plot_gate_map(backend=self.backend1Q, filename=fname) + self.graph_plot_gate_map(backend=backend, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -424,8 +407,10 @@ def test_plot_5_qubit_gate_map(self): """Test plot_gate_map using 5 qubit backend""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) + fname = "5_qubit_gate_map.png" - self.graph_plot_gate_map(backend=self.backend_5_yorktown, filename=fname) + self.graph_plot_gate_map(backend=backend, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -440,8 +425,10 @@ def test_plot_7_qubit_gate_map(self): """Test plot_gate_map using 7 qubit backend""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) + fname = "7_qubit_gate_map.png" - self.graph_plot_gate_map(backend=self.backend_7_lagos, filename=fname) + self.graph_plot_gate_map(backend=backend, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -456,8 +443,10 @@ def test_plot_16_qubit_gate_map(self): """Test plot_gate_map using 16 qubit backend""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP) + fname = "16_qubit_gate_map.png" - self.graph_plot_gate_map(backend=self.backend_16_rueschlikon, filename=fname) + self.graph_plot_gate_map(backend=backend, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -472,8 +461,10 @@ def test_plot_27_qubit_gate_map(self): """Test plot_gate_map using 27 qubit backend""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=27, coupling_map=MUMBAI_CMAP) + fname = "27_qubit_gate_map.png" - self.graph_plot_gate_map(backend=self.backend_27_mumbai, filename=fname) + self.graph_plot_gate_map(backend=backend, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -488,8 +479,10 @@ def test_plot_65_qubit_gate_map(self): """test for plot_gate_map using 65 qubit backend""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + fname = "65_qubit_gate_map.png" - self.graph_plot_gate_map(backend=self.backend_65_manhattan, filename=fname) + self.graph_plot_gate_map(backend=backend, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -504,8 +497,10 @@ def test_figsize(self): """Test figsize parameter of plot_gate_map""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) + fname = "figsize.png" - self.graph_plot_gate_map(backend=self.backend_5_yorktown, figsize=(10, 10), filename=fname) + self.graph_plot_gate_map(backend=backend, figsize=(10, 10), filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -520,8 +515,10 @@ def test_qubit_size(self): """Test qubit_size parameter of plot_gate_map""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=5, coupling_map=YORKTOWN_CMAP) + fname = "qubit_size.png" - self.graph_plot_gate_map(backend=self.backend_5_yorktown, qubit_size=38, filename=fname) + self.graph_plot_gate_map(backend=backend, qubit_size=38, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -536,10 +533,10 @@ def test_qubit_color(self): """Test qubit_color parameter of plot_gate_map""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) + fname = "qubit_color.png" - self.graph_plot_gate_map( - backend=self.backend_7_lagos, qubit_color=["#ff0000"] * 7, filename=fname - ) + self.graph_plot_gate_map(backend=backend, qubit_color=["#ff0000"] * 7, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -554,9 +551,11 @@ def test_qubit_labels(self): """Test qubit_labels parameter of plot_gate_map""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=7, coupling_map=LAGOS_CMAP) + fname = "qubit_labels.png" self.graph_plot_gate_map( - backend=self.backend_7_lagos, qubit_labels=list(range(10, 17, 1)), filename=fname + backend=backend, qubit_labels=list(range(10, 17, 1)), filename=fname ) ratio = VisualTestUtilities._save_diff( @@ -572,10 +571,10 @@ def test_line_color(self): """Test line_color parameter of plot_gate_map""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + fname = "line_color.png" - self.graph_plot_gate_map( - backend=self.backend_65_manhattan, line_color=["#00ff00"] * 144, filename=fname - ) + self.graph_plot_gate_map(backend=backend, line_color=["#00ff00"] * 144, filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), @@ -590,10 +589,10 @@ def test_font_color(self): """Test font_color parameter of plot_gate_map""" # getting the mock backend from FakeProvider + backend = GenericBackendV2(num_qubits=65, coupling_map=MANHATTAN_CMAP) + fname = "font_color.png" - self.graph_plot_gate_map( - backend=self.backend_65_manhattan, font_color="#ff00ff", filename=fname - ) + self.graph_plot_gate_map(backend=backend, font_color="#ff00ff", filename=fname) ratio = VisualTestUtilities._save_diff( self._image_path(fname), From afa1444e3004d5210c111c9a6da30e7278364646 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 19 Apr 2024 08:55:27 +0200 Subject: [PATCH 14/18] Apply suggestions from code review Co-authored-by: Matthew Treinish --- qiskit/providers/fake_provider/generic_backend_v2.py | 2 +- qiskit/providers/provider.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 6b4970349fb0..cf76e4508848 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -528,7 +528,7 @@ def _setup_sim(self) -> None: def _default_options(cls) -> Options: with warnings.catch_warnings(): # TODO remove catch once aer release without Provider ABC warnings.filterwarnings( - "ignore", category=DeprecationWarning, message=".+ABC Provider and ProviderV1.+" + "ignore", category=DeprecationWarning, message=".+abstract Provider and ProviderV1.+" ) if _optionals.HAS_AER: from qiskit_aer import AerSimulator diff --git a/qiskit/providers/provider.py b/qiskit/providers/provider.py index e317bcbd0cc7..2d780be6f211 100644 --- a/qiskit/providers/provider.py +++ b/qiskit/providers/provider.py @@ -31,8 +31,8 @@ class Provider: @deprecate_func( since=1.1, - additional_msg="The full ABC Provider and ProviderV1 is deprecated and it is going to" - " be removed in 2.0. Just remove it as a super class.", + additional_msg="The abstract Provider and ProviderV1 classes are deprecated and will" + " be removed in 2.0. You can just remove it as the parent class and a `get_backend` method that returns the backends from `self.backend`.", ) def __init__(self): pass @@ -45,8 +45,8 @@ class ProviderV1(Provider, ABC): @deprecate_func( since=1.1, - additional_msg="The full ABC Provider and ProviderV1 is deprecated and it is going to" - " be removed in 2.0. Just remove it as a super class.", + additional_msg="The abstract Provider and ProviderV1 classes are deprecated and will" + " be removed in 2.0. You can just remove it as the parent class and a `get_backend` method that returns the backends from `self.backend`.", ) def get_backend(self, name=None, **kwargs): """Return a single backend matching the specified filtering. From 0abdc2e13e1f1dc75e1ef60908f05fcc2cca2d71 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 19 Apr 2024 09:24:54 +0200 Subject: [PATCH 15/18] reno --- .../notes/deprecate_providerV1-ba17d7b4639d1cc5.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 releasenotes/notes/deprecate_providerV1-ba17d7b4639d1cc5.yaml diff --git a/releasenotes/notes/deprecate_providerV1-ba17d7b4639d1cc5.yaml b/releasenotes/notes/deprecate_providerV1-ba17d7b4639d1cc5.yaml new file mode 100644 index 000000000000..315fb24dbbdf --- /dev/null +++ b/releasenotes/notes/deprecate_providerV1-ba17d7b4639d1cc5.yaml @@ -0,0 +1,6 @@ +--- +deprecations_providers: + - | + The abstraction ``Provider`` (and ``ProviderV1``) is now deprecated and it is going to be removed in the next major release. + The abstraction was not giving implementator much: ``name``, ``backends``, and/or ``get_backend``. A _provider_, as a concept, will continue existing as a collection of backends. + To ajust to this deprecation, you can just remove the parent parent class from your provider. From d7360531d257a6d1a4c5aa3d0fc342c344a1bc44 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 22 Apr 2024 15:17:07 -0400 Subject: [PATCH 16/18] Run black --- qiskit/providers/fake_provider/generic_backend_v2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index cf76e4508848..7537efe01fcc 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -528,7 +528,9 @@ def _setup_sim(self) -> None: def _default_options(cls) -> Options: with warnings.catch_warnings(): # TODO remove catch once aer release without Provider ABC warnings.filterwarnings( - "ignore", category=DeprecationWarning, message=".+abstract Provider and ProviderV1.+" + "ignore", + category=DeprecationWarning, + message=".+abstract Provider and ProviderV1.+", ) if _optionals.HAS_AER: from qiskit_aer import AerSimulator From 038bc3c83b95dcf89f63fe6fe80ad1024bc43137 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 22 Apr 2024 15:25:32 -0400 Subject: [PATCH 17/18] Update release note --- .../deprecate_providerV1-ba17d7b4639d1cc5.yaml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/releasenotes/notes/deprecate_providerV1-ba17d7b4639d1cc5.yaml b/releasenotes/notes/deprecate_providerV1-ba17d7b4639d1cc5.yaml index 315fb24dbbdf..bfec8ef89041 100644 --- a/releasenotes/notes/deprecate_providerV1-ba17d7b4639d1cc5.yaml +++ b/releasenotes/notes/deprecate_providerV1-ba17d7b4639d1cc5.yaml @@ -1,6 +1,18 @@ --- deprecations_providers: - | - The abstraction ``Provider`` (and ``ProviderV1``) is now deprecated and it is going to be removed in the next major release. - The abstraction was not giving implementator much: ``name``, ``backends``, and/or ``get_backend``. A _provider_, as a concept, will continue existing as a collection of backends. - To ajust to this deprecation, you can just remove the parent parent class from your provider. + The abstract base classes ``Provider`` and ``ProviderV1`` are now deprecated and will be removed in Qiskit 2.0.0. + The abstraction provided by these interface definitions were not providing a huge value. solely just the attributes + ``name``, ``backends``, and a ``get_backend()``. A _provider_, as a concept, will continue existing as a collection + of backends. If you're implementing a provider currently you can adjust your + code by simply removing ``ProviderV1`` as the parent class of your + implementation. As part of this you probably would want to add an + implementation of ``get_backend`` for backwards compatibility. For example:: + + def get_backend(self, name=None, **kwargs): + backend = self.backends(name, **kwargs) + if len(backends) > 1: + raise QiskitBackendNotFoundError("More than one backend matches the criteria") + if not backends: + raise QiskitBackendNotFoundError("No backend matches the criteria") + return backends[0] From 0128ea6a0feb0684b3c2ed8c3c0467ae261d7e7a Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 23 Apr 2024 16:27:54 +0200 Subject: [PATCH 18/18] linter --- qiskit/providers/provider.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/qiskit/providers/provider.py b/qiskit/providers/provider.py index 2d780be6f211..dc836e7f25ee 100644 --- a/qiskit/providers/provider.py +++ b/qiskit/providers/provider.py @@ -31,8 +31,9 @@ class Provider: @deprecate_func( since=1.1, - additional_msg="The abstract Provider and ProviderV1 classes are deprecated and will" - " be removed in 2.0. You can just remove it as the parent class and a `get_backend` method that returns the backends from `self.backend`.", + additional_msg="The abstract Provider and ProviderV1 classes are deprecated and will be " + "removed in 2.0. You can just remove it as the parent class and a `get_backend` " + "method that returns the backends from `self.backend`.", ) def __init__(self): pass @@ -45,8 +46,9 @@ class ProviderV1(Provider, ABC): @deprecate_func( since=1.1, - additional_msg="The abstract Provider and ProviderV1 classes are deprecated and will" - " be removed in 2.0. You can just remove it as the parent class and a `get_backend` method that returns the backends from `self.backend`.", + additional_msg="The abstract Provider and ProviderV1 classes are deprecated and will be " + "removed in 2.0. You can just remove it as the parent class and a `get_backend` " + "method that returns the backends from `self.backend`.", ) def get_backend(self, name=None, **kwargs): """Return a single backend matching the specified filtering.