Add option max_block_width
to CollectLinearFunctions
and CollectClifford
passes
#13661
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new argument
max_block_width
to the classBlockCollector
and to the transpiler passesCollectLinearFunctions
andCollectCliffords
that are based on this class. This argument enforces block collection strategies to restrict the maximum number of qubits over which a block of nodes is defined.This option is similar to the option
max_block_size
in theCollectMultiQBlocks
transpiler pass (though naming-wise, I am calling this "width" instead of "size", which is how it should be using the terminology ofDAGCircuit
andQuantumCircuit
).The implementation is based on the adaptation of
BlockCollector
in AI resynthesis passes (including a small cleanup for updating the frontier nodes).Details and comments
Somewhat related to the PR, here is a more refined difference between
BlockCollector
andCollectMultiQBlocks
:BlockCollector
allows to only collect nodes that match a given "filter function" and treat other nodes as "should not be collected", whileCollectMultiQBlocks
collects all nodes (in particular,CollectMultiQBlocks
cannot be used to only collect say Clifford gates within in a larger circuit).BlockCollector
can collect nodes exploiting commutativity of nodes within the DAG;CollectMultiQBlocks
does not have this functionality.BlockCollector
has other options thatCollectMultiQBlocks
does not have.Both can now collect nodes "forward-wise" from the inputs towards the ouputs of a circuit, and
backward-wise
from the outputs towards the inputs.Both
BlockCollector
andCollectMultiQBlocks
are greedy, howeverCollectMultiQBlocks
is smarter, in the following way.BlockCollector
greedily collects one block at a time, greedily trying to add nodes into the block being collected. In particular it may create "disconnected" blocks . On the other hand,CollectMultiQBlocks
(with the implementation based on the disjoint set union data structure) produces connected blocks by construction.