-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…10254) * adding reverse collection direction and test * propagating options to CollectAndCollapse, CollectLinearFunctions and CollectCliffords passes * reno * test for clifford collection pass * adding option split_layers * propagating options and adding tests * imrpoving tests and release notes * temporarily removing release notes * reinstating release notes * reno fix * change suggestion in review comments * correct fix this time * using condition_resources instead of condition_bits * Update qiskit/dagcircuit/collect_blocks.py This is nice! Co-authored-by: Matthew Treinish <mtreinish@kortar.org> --------- Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
- Loading branch information
1 parent
e595066
commit 94cb65e
Showing
8 changed files
with
555 additions
and
21 deletions.
There are no files selected for viewing
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
67 changes: 67 additions & 0 deletions
67
releasenotes/notes/add-block-collection-options-359d5e496313acdb.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,67 @@ | ||
--- | ||
features: | ||
- | | ||
Added two new options to :class:`~BlockCollector`. | ||
The first new options ``split_layers`` allows to split the collected block into sub-blocks | ||
over disjoint qubit subsets, i.e. into depth-1 sub-blocks. | ||
The second new option ``collect_from_back`` allows to greedily collect blocks starting | ||
from the outputs of the circuit. This is important in combination with ALAP-scheduling passes | ||
where we may prefer to put gates in the later rather than earlier blocks. | ||
- | | ||
Added new options ``split_layers`` and ``collect_from_back`` to | ||
:class:`~CollectLinearFunctions` and :class:`~CollectCliffords` transpiler passes. | ||
When ``split_layers`` is `True`, the collected blocks are split into | ||
into sub-blocks over disjoint qubit subsets, i.e. into depth-1 sub-blocks. | ||
Consider the following example:: | ||
from qiskit.circuit import QuantumCircuit | ||
from qiskit.transpiler.passes import CollectLinearFunctions | ||
circuit = QuantumCircuit(5) | ||
circuit.cx(0, 2) | ||
circuit.cx(1, 4) | ||
circuit.cx(2, 0) | ||
circuit.cx(0, 3) | ||
circuit.swap(3, 2) | ||
circuit.swap(4, 1) | ||
# Collect all linear gates, without splitting into layers | ||
qct = CollectLinearFunctions(split_blocks=False, min_block_size=1, split_layers=False)(circuit) | ||
assert qct.count_ops()["linear_function"] == 1 | ||
# Collect all linear gates, with splitting into layers | ||
qct = CollectLinearFunctions(split_blocks=False, min_block_size=1, split_layers=True)(circuit) | ||
assert qct.count_ops()["linear_function"] == 4 | ||
The original circuit is linear. When collecting linear gates without splitting into layers, | ||
we should end up with a single linear function. However, when collecting linear gates and | ||
splitting into layers, we should end up with 4 linear functions. | ||
When ``collect_from_back`` is `True`, the blocks are greedily collected from the outputs towards | ||
the inputs of the circuit. Consider the following example:: | ||
from qiskit.circuit import QuantumCircuit | ||
from qiskit.transpiler.passes import CollectLinearFunctions | ||
circuit = QuantumCircuit(3) | ||
circuit.cx(1, 2) | ||
circuit.cx(1, 0) | ||
circuit.h(2) | ||
circuit.swap(1, 2) | ||
# This combines the CX(1, 2) and CX(1, 0) gates into a single linear function | ||
qct = CollectLinearFunctions(collect_from_back=False)(circuit) | ||
# This combines the CX(1, 0) and SWAP(1, 2) gates into a single linear function | ||
qct = CollectLinearFunctions(collect_from_back=True)(circuit) | ||
The original circuit contains a Hadamard gate, so that the `CX(1, 0)` gate can be | ||
combined either with `CX(1, 2)` or with `SWAP(1, 2)`, but not with both. When | ||
``collect_from_back`` is `False`, the linear blocks are greedily collected from the start | ||
of the circuit, and thus `CX(1, 0)` is combined with `CX(1, 2)`. When | ||
``collect_from_back`` is `True`, the linear blocks are greedily collected from the end | ||
of the circuit, and thus `CX(1, 0)` is combined with `SWAP(1, 2)`. |
Oops, something went wrong.