-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Adding is_zero_initialized
to transpile and extending HighLevelSynthesis with ancilla qubits
#12729
Conversation
…ot include equivalence library and HLS complains that it cannot synthesize the identity gate
Pull Request Test Coverage Report for Build 10027519940Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Heads up: the number of 2-qubit gates for the synthesized circuit on the benchpress
Here
Now, let's add an extra free qubit to the circuit (i.e. the circuit is now defined over
|
is_zero_initialized
to transpile and extending HighLevelSynthesis with ancilla qubits
One or more of the following people are relevant to this code:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tl;dr: I would suggest we only add is_zero_initialized
(and add RemoveResetInZeroState
in this case) and only add the HLS logic once we have plugins that can use it.
Overall this looks like a solid start for handling ancillas. But I have one question upfront: if our main goal is to introduce the new argument is_zero_initialized
for 1.2, wouldn't it make more sense to defer the HLS changes to when we actually add the new plugins that can use ancillas? That way we can also add tests and ensure the HLS logic works as expected, and we don't add "dead code" that is in the release but never used.
Another important point for is being consistent with the assumption that the initial state is RemoveResetInZeroState
pass if is_zero_initialized is True
-- otherwise it seems a bit unexpected that we state the qubits are already reset but don't remove initial resets.
I can open a PR with these changes to your branch, and if you agree, I'd be happy to move forward with the reduced changes for 1.2.
- add tests - add handling of no-ops and reset
Given that this PR is in ongoing discussion, I think it will likely not make it for 1.2, and be for 1.3. |
Superseded by #12911. |
This can be closed as the better PR #12911 has been merged! |
Updated Summary
This PR adds a new argument
is_zero_initialized
totranspile(...)
, as well as toPassManagerConfig
andgenerate_pass_manager
. If set toTrue
(the default) the qubits are assumed to be initially in state<0|
. For some additional context, see #10591, #5127 and other linked issues. After an offline discussion, we have concluded that having an explicit argument intranspile
achieves the best of both worlds.In addition, this PR passes this flag to
HighLevelSynthesis
transpiler pass. If set toTrue
, the pass can initially label all qubits as "clean auxiliary qubits". The pass then keeps track of clean and dirty auxiliary qubits throughout the run, and passes this information to plugins via kwargs_num_clean_ancillas
and_num_dirty_ancillas
. Additionally, the pass has been extended to handle the case that the circuit synthesizing a high-level-object is defined over these additional qubits.I have removed the MCX synthesis methods and MCX synthesis plugins from this PR. We will handle a more organized restructuring of the multi-controlled synthesis algorithms and plugins in a follow-up.
Original Summary (outdated)
For now this is a proof-of-concept PR based on internal Qiskit discussions. Everything is up to debate.
The idea is to extend the
HighLevelSynthesis
transpiler pass with the ability to use "auxiliary qubits" when synthesizing high-level operations using plugins. In this initial implementation, the allowed synthesis methods should support "dirty" auxiliary qubits, that is the synthesis methods are required to bring each auxiliary qubit into its original state. This allows to use any qubit that is not a part of the object's definition as an auxiliary qubit. It should be also possible to support "clean" auxiliary qubits (or a combination of clean and dirty auxiliary qubits).This is illustrated for two MCX synthesis functions: the default synthesis function (based on the reduction to MCPhase gate) that does not require any auxiliary qubits, and the "recursive synthesis" function (extracted from the definition of the
MCXRecursive
gate) that requires a single auxiliary qubit for MCX gates with more than 4 control qubits. The key difference between theMCXRecursiveGate
and the new functionality is that forMCXRecursiveGate
the number and the auxiliary qubits used are baked into the gate's definition, while with the new flow the gate is anMCXGate
only defined on its control and target qubits, and it's the actual synthesis that decides how many auxiliary qubits are available.This PR does not deprecate or remove
MCXRecursiveGate
(and other custom MCX variants). This can be done in some follow-up PR if we agree that this is the right strategy. Also note that since theMCXRecursiveGate
has a name "mcx_recursive" (or something like that) the two new "mcx" plugins do not apply, and the old synthesis behavior based on the gate's definition is used.More comments appear as notes within the code.
Details and comments
Here is a concrete example:
The output is:
Feedback is welcome!