Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel dispatch with target argument in transpile() (backport #8952) #8972

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def _parse_transpile_args(
if coupling_map is None:
coupling_map = target.build_coupling_map()
if basis_gates is None:
basis_gates = target.operation_names
basis_gates = list(target.operation_names)
if instruction_durations is None:
instruction_durations = target.durations()
if inst_map is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Fixed an issue with the :func:`~.transpile` where it would previously
fail with a ``TypeError`` if a custom :class:`~.Target` object was
passed in via the ``target`` argument and a list of multiple circuits
were specified for the ``circuits`` argument.
31 changes: 31 additions & 0 deletions test/python/compiler/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from qiskit.quantum_info import Operator, random_unitary
from qiskit.transpiler.passmanager_config import PassManagerConfig
from qiskit.transpiler.preset_passmanagers import level_0_pass_manager
from qiskit.tools import parallel


class CustomCX(Gate):
Expand Down Expand Up @@ -1789,3 +1790,33 @@ def test_custom_multiple_circuits(self):
self.assertEqual(len(transpiled), 2)
self.assertEqual(transpiled[0], expected)
self.assertEqual(transpiled[1], expected)


@ddt
class TestTranspileParallel(QiskitTestCase):
"""Test transpile() in parallel."""

def setUp(self):
super().setUp()

# Force parallel execution to True to test multiprocessing for this class
original_val = parallel.PARALLEL_DEFAULT

def restore_default():
parallel.PARALLEL_DEFAULT = original_val

self.addCleanup(restore_default)
parallel.PARALLEL_DEFAULT = True

@data(0, 1, 2, 3)
def test_parallel_with_target(self, opt_level):
"""Test that parallel dispatch works with a manual target."""
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
target = FakeMumbaiV2().target
res = transpile([qc] * 3, target=target, optimization_level=opt_level)
self.assertIsInstance(res, list)
for circ in res:
self.assertIsInstance(circ, QuantumCircuit)