Skip to content

Commit

Permalink
Remove qiskit-toqm tests and requirements-dev.txt entry (backport #9057
Browse files Browse the repository at this point in the history
…) (#9061)

* Remove qiskit-toqm tests and requirements-dev.txt entry (#9057)

* Remove qiskit-toqm tests and requirements-dev.txt entry

Im #9042 we removed the special case code to enable using toqm as an
optional routing method. This was needed prior to qiskit-terra 0.22.0 as
we didn't have the transpiler stage plugin interface. However, now that
we've added a dedicated interface for external transpiler passes to
integrate into transpile() the toqm passes are using that interface.
However, in #9042 the tests for verifying the previously hard-coded toqm
routing method path worked as before were left intact. In general this
would be a good approach to ensure we're maintaining backwards
compatibilty with the new modular interface with earlier releases.
However, in this specific case this is causing an issue with how tests
are run. Since qiskit-toqm has a necessary dependency on qiskit-terra
this means when we install our development requirements before running
tests toqm is pulling in the latest stable release of qiskit-terra from
pypi. Then we later upgrade that with the source build before running
tests. This however this bi-directional test dependency introduces a
tension in a number of places. For the most recent example, when we're
trying to add support for new platforms (see #9028 for an example)
where the stable version of qiskit-terra does not support the platform.
We're unable to run CI with qiskit-toqm being installed first since
installing stable qiskit-terra won't work/

This commit removes qiskit-toqm from the requirements-dev.txt list and
also removes the test cases using it to fix this conflict. In general
the testing for qiskit-toqm can now be self contained since it's
exercising a stable interface in terra that's tested independently. When
weighing the backwards compatibility coverage vs the CI and build
complexities having the bidirectional test dependency has just removing
the toqm tests and development requirement is the simplest path forward.

* Remove unused imports

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 8999047)

# Conflicts:
#	requirements-dev.txt

* Remove qiskit-toqm from requirements-dev.txt

This fixes a merge conflict and removes the qiskit-toqm entry from the requirements-dev.txt file

* Fix lint failure

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] and mtreinish committed Nov 3, 2022
1 parent e61b93f commit 0a731ca
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 53 deletions.
7 changes: 6 additions & 1 deletion qiskit/transpiler/preset_passmanagers/level0.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ def _choose_layout_condition(property_set):
# TODO: Remove when qiskit-toqm has it's own plugin and we can rely on just the plugin interface
if routing_method == "toqm" and "toqm" not in list_stage_plugins("routing"):
HAS_TOQM.require_now("TOQM-based routing")
from qiskit_toqm import ToqmSwap, ToqmStrategyO0, latencies_from_target
# pylint: disable=import-error
from qiskit_toqm import (
ToqmSwap,
ToqmStrategyO0,
latencies_from_target,
)

if initial_layout:
raise TranspilerError("Initial layouts are not supported with TOQM-based routing.")
Expand Down
7 changes: 6 additions & 1 deletion qiskit/transpiler/preset_passmanagers/level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ def _vf2_match_not_found(property_set):
# TODO: Remove when qiskit-toqm has it's own plugin and we can rely on just the plugin interface
if routing_method == "toqm" and "toqm" not in list_stage_plugins("routing"):
HAS_TOQM.require_now("TOQM-based routing")
from qiskit_toqm import ToqmSwap, ToqmStrategyO1, latencies_from_target
# pylint: disable=import-error
from qiskit_toqm import (
ToqmSwap,
ToqmStrategyO1,
latencies_from_target,
)

if initial_layout:
raise TranspilerError("Initial layouts are not supported with TOQM-based routing.")
Expand Down
7 changes: 6 additions & 1 deletion qiskit/transpiler/preset_passmanagers/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ def _vf2_match_not_found(property_set):
# TODO: Remove when qiskit-toqm has it's own plugin and we can rely on just the plugin interface
if routing_method == "toqm" and "toqm" not in list_stage_plugins("routing"):
HAS_TOQM.require_now("TOQM-based routing")
from qiskit_toqm import ToqmSwap, ToqmStrategyO2, latencies_from_target
# pylint: disable=import-error
from qiskit_toqm import (
ToqmSwap,
ToqmStrategyO2,
latencies_from_target,
)

if initial_layout:
raise TranspilerError("Initial layouts are not supported with TOQM-based routing.")
Expand Down
7 changes: 6 additions & 1 deletion qiskit/transpiler/preset_passmanagers/level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ def _vf2_match_not_found(property_set):
# TODO: Remove when qiskit-toqm has it's own plugin and we can rely on just the plugin interface
if routing_method == "toqm" and "toqm" not in list_stage_plugins("routing"):
HAS_TOQM.require_now("TOQM-based routing")
from qiskit_toqm import ToqmSwap, ToqmStrategyO3, latencies_from_target
# pylint: disable=import-error
from qiskit_toqm import (
ToqmSwap,
ToqmStrategyO3,
latencies_from_target,
)

if initial_layout:
raise TranspilerError("Initial layouts are not supported with TOQM-based routing.")
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ seaborn>=0.9.0
reno>=3.4.0
Sphinx>=3.0.0
qiskit-sphinx-theme>=1.6
qiskit-toqm>=0.0.4;platform_machine != 'aarch64' or platform_system != 'Linux'
sphinx-autodoc-typehints~=1.18,!=1.19.3
jupyter-sphinx
sphinx-design>=0.2.0
Expand Down
48 changes: 0 additions & 48 deletions test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@
FakeTokyo,
FakePoughkeepsie,
FakeLagosV2,
FakeLima,
FakeWashington,
)
from qiskit.converters import circuit_to_dag
from qiskit.circuit.library import GraphState
from qiskit.quantum_info import random_unitary
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.transpiler.preset_passmanagers import level0, level1, level2, level3
from qiskit.utils.optionals import HAS_TOQM
from qiskit.transpiler.passes import Collect2qBlocks, GatesInBasis


Expand Down Expand Up @@ -267,51 +264,6 @@ def counting_callback_func(pass_, dag, time, property_set, count):
self.assertEqual(gates_in_basis_true_count + 1, collect_2q_blocks_count)


@ddt
@unittest.skipUnless(HAS_TOQM, "qiskit-toqm needs to be installed")
class TestToqmIntegration(QiskitTestCase):
"""Test transpiler with TOQM-based routing"""

@combine(
level=[0, 1, 2, 3],
layout_method=[None, "trivial", "dense", "noise_adaptive", "sabre"],
backend_vbits_pair=[(FakeWashington(), 10), (FakeLima(), 5)],
dsc="TOQM-based routing with '{layout_method}' layout"
+ "method on '{backend_vbits_pair[0]}' backend at level '{level}'",
name="TOQM_{layout_method}_{backend_vbits_pair[0]}_level{level}",
)
def test_basic_circuit(self, level, layout_method, backend_vbits_pair):
"""
Basic circuits transpile across all opt levels and layout
methods when using TOQM-based routing.
"""
backend, circuit_size = backend_vbits_pair
qr = QuantumRegister(circuit_size, "q")
qc = QuantumCircuit(qr)

# Generate a circuit that should need swaps.
for i in range(1, qr.size):
qc.cx(0, i)

result = transpile(
qc,
layout_method=layout_method,
routing_method="toqm",
backend=backend,
optimization_level=level,
seed_transpiler=4222022,
)

self.assertIsInstance(result, QuantumCircuit)

def test_initial_layout_is_rejected(self):
"""Initial layout is rejected when using TOQM-based routing"""
with self.assertRaisesRegex(
TranspilerError, "Initial layouts are not supported with TOQM-based routing."
):
transpile(QuantumCircuit(2), initial_layout=[1, 0], routing_method="toqm")


@ddt
class TestTranspileLevels(QiskitTestCase):
"""Test transpiler on fake backend"""
Expand Down

0 comments on commit 0a731ca

Please sign in to comment.