forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove list argument broadcasting and simplify transpile()
This commit updates the transpile() function to no longer support broadcast of lists of arguments. This functionality was deprecated in the 0.23.0 release. As part of this removal the internals of the transpile() function are simplified so we don't need to handle broadcasting, building preset pass managers, parallel dispatch, etc anymore as this functionality (without broadcasting) already exists through the transpiler API. Besides greatly simplifying the transpile() code and using more aspects of the public APIs that exist in the qiskit.transpiler module, this commit also should fix the overhead we have around parallel execution due to the complexity of supporting broadcasting. This overhead was partially addressed before in Qiskit#7789 which leveraged shared memory to minimize the serialization time necessary for IPC but by using `PassManager.run()` internally now all of that overhead is removed as the initial fork will have all the necessary context in each process from the start. Three seemingly unrelated changes made here were necessary to support our current transpile() API without building custom pass manager construction. The first is the handling of layout from intlist. The current Layout class is dependent on a circuit because it maps Qubit objects to a physical qubit index. Ideally the layout structure would just map virtual indices to physical indices (see Qiskit#8060 for a similar issue, also it's worth noting this is how the internal NLayout and QPY represent layout), but because of the existing API the construction of a Layout is dependent on a circuit. For the initial_layout argument when running with multiple circuits to avoid the need to broadcasting the layout construction for supported input types that need the circuit to lookup the Qubit objects the SetLayout pass now supports taking in an int list and will construct a Layout object at run time. This effectively defers the Layout object creation for initial_layout to run time so it can be built as a function of the circuit as the API demands. The second is the FakeBackend class used in some tests was constructing invalid backends in some cases. This wasn't caught in the previous structure because the backends were not actually being parsed by transpile() previously which masked this issue. This commit fixes that issue because PassManagerConfig.from_backend() was failing because of the invalid backend construction. The third issue is a new _skip_target private argument to generate_preset_pass_manager() and PassManagerConfig. This was necessary to recreate the behavior of transpile() when a user provides a BackendV2 and either `basis_gates` or `coupling_map` arguments. In general the internals of the transpiler treat a target as higher priority because it has more complete and restrictive constraints than the basis_gates/coupling map objects. However, for transpile() if a backendv2 is passed in for backend paired with coupling_map and/or basis_gates the expected workflow is that the basis_gates and coupling_map arguments take priority and override the equivalent attributes from the backend. To facilitate this we need to block pulling the target from the backend This should only be needed for a short period of time as when Qiskit#9256 is implemented we'll just build a single target from the arguments as needed. Fixes Qiskit#7741
- Loading branch information
Showing
9 changed files
with
214 additions
and
481 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
releasenotes/notes/remove-transpile-broadcast-1dfde28d508efa0d.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
upgrade: | ||
- | | ||
Support for passing in lists of argument values to the :func:`~.transpile` | ||
function is removed. This functionality was deprecated as part of the | ||
0.23.0 release and is now being removed. Removing this functionality was | ||
necessary to greatly reduce the overhead for parallel execution for | ||
transpiling multiple circuits at once. If you’re using this functionality | ||
currently you can call :func:`~.transpile` multiple times instead. For | ||
example if you were previously doing something like:: | ||
from qiskit.transpiler import CouplingMap | ||
from qiskit import QuantumCircuit | ||
from qiskit import transpile | ||
qc = QuantumCircuit(2) | ||
qc.h(0) | ||
qc.cx(0, 1) | ||
qc.measure_all() | ||
cmaps = [CouplingMap.from_heavy_hex(d) for d in range(3, 15, 2)] | ||
results = transpile([qc] * 6, coupling_map=cmaps) | ||
instead you should now run something like:: | ||
from itertools import cycle | ||
from qiskit.transpiler import CouplingMap | ||
from qiskit import QuantumCircuit | ||
from qiskit import transpile | ||
qc = QuantumCircuit(2) | ||
qc.h(0) | ||
qc.cx(0, 1) | ||
qc.measure_all() | ||
cmaps = [CouplingMap.from_heavy_hex(d) for d in range(3, 15, 2)] | ||
results = [] | ||
for qc, cmap in zip(cycle([qc]), cmaps): | ||
results.append(transpile(qc, coupling_map=cmap)) | ||
You can also leverage :func:`~.parallel_map` or ``multiprocessing`` from | ||
the Python standard library if you want to run this in parallel. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters