-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fixed issue 4526 by adding InitializeGate #5179
Conversation
State preparation should really not be a unitary operation. Which part of the paper you link to above has this? The reset could be removed by the transpiler if it occurs in the beginning of the circuit, but the reset is required to reliably prepare a state. cc'ing @Cryoris too as he opened the initial issue. |
@ajavadia thank you for your feedback I've implemented the circuit performing controlled-initialize and twice-controlled-initialize in order to extend the circuit presented in the linked paper. In particular, when the author initializes its single-qubit data with the controlled version of RY (sometimes controlled X when the data is |
After discussing with @ajavadia I think it would make sense to move the state-preparation logic into a |
@Cryoris Thank you for your comment. There is anything I can do to improve the code? |
Yes, could you put all the logic inside class InitializeGate(Gate):
def _define(self):
# all the logic of `Initialize` in here
class Initialize(Instruction):
def _define(self):
# resets and then InitializeGate Once that is done, we can think of a better name than |
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.
I think the approach looks good. @ajavadia do you have an idea on the naming?
"""Calculate a subcircuit that implements this initialization | ||
|
||
Implements a recursive initialization algorithm, including optimizations, | ||
from "Synthesis of Quantum Logic Circuits" Shende, Bullock, Markov | ||
https://arxiv.org/abs/quant-ph/0406176v5 | ||
|
||
Additionally implements some extra optimizations: remove zero rotations and | ||
double cnots. | ||
""" |
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.
I think this comment can be removed, it applies to InitializeGate
since the decomposition is computed there.
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.
The comment is now removed
Co-authored-by: Julien Gacon <gaconju@gmail.com>
@Cryoris Thank you for your comment. I've merged the fix |
Following #7666, now that we have a |
Yeah, this is obsolete as of #7666, thanks. For the future: the motivating example for including the unitary component of initialisation as a separate instruction was so users could define their own mappings |
Summary
Fixes #4526
Details and comments
Initialize
is implemented as anInstruction
object instead ofGate
because it uses reset instruction which is not unitary. This fix modifiesInitialize
passing an additional named parameterreset
to its constructor whose default value isTrue
. You can expect the behavior ofInitialize
to be the same if you don't specify thereset
parameter.However, instantiating
Initialize
withreset=False
lets us define theInitializeGate
gate. We can now create the controlled version ofInitialize
usingInitializeGate(desired_vector).control(how_many_controlled_qubits)
.Here an example usage:
The introduction of
InitializeGate
and its controlled version may help with the implementation of quantum distance-based classifier like the one you find in [Schuld, Fingerhuth, Petruccione, 2018].