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() #8952

Merged
merged 6 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -635,7 +635,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.
19 changes: 19 additions & 0 deletions test/python/compiler/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,3 +1617,22 @@ 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."""

@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
with patch.dict("os.environ", {"QISKIT_PARALLEL": "FALSE"}):
mtreinish marked this conversation as resolved.
Show resolved Hide resolved
res = transpile([qc] * 3, target=target, optimization_level=opt_level)
self.assertIsInstance(res, list)
for circ in res:
self.assertIsInstance(circ, QuantumCircuit)