-
Notifications
You must be signed in to change notification settings - Fork 63
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
Adds single qubit decomposition functions #67
Conversation
_rotation_matrices_dictionary ={"ZYZ": _ZYZ_rotation, | ||
"ZXZ": _ZXZ_rotation, | ||
} |
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.
You can use the relation X=HZH
and Z=HXH
, where H
is the Hadamard transformation, to generalize to other cases. Because of Y=-HYH
, you can get "XYX"
and "XZX"
decomposition. I use here just Pauli matrices but the rotation is the same because RX(t)=exp(-iXt)
(maybe a 1/2 is missing). The transformation changes the rotation axes.
Now I think more about it, if we want, we can also find unitaries that generalize this to other cases. You can understand a Hadamard as roughly a rotation over the Y axis, so it changes RX
to RZ
. Therefore, one should be able to find a 90-degree rotation over X
or Z
that does a similar job, e.g. changes RY
to RZ
.
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 routine could be like this (just my thought, not that you have to):
- Regardless of the scheme, always use ZYZ decomposition, get the 3 angles and the global phase.
- For each scheme, there is a private function to decide what is the 3 rotation gates to use (RZ, RY or RZ) as well as the global phase correction. They always use the same rotation angles calculated for ZYZ (maybe add a minus sign here and there if needed). This can be manually derived as I sketched above.
In this way one only need one function to calculate the ZYZ angles, the rest is just tranformation.
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.
Yes, that's what I attempted to do by creating _angles_for_ZYZ
.
I had calculated the angles for the new combinations by using output of ZYZ and transforming Rz as product of RxRyRx and so on.. I made a mistake somewhere in these transformations and the outputs don't match.
Adding the combinations later down the line is just a matter of re-checking these calculations.
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 went through the code. And left a few comments. Generally looks good! Do you still plan to add schemes to this like ZXZ
etc? Or do you prefer to merge this first?
@hodgestar @BoxiLi @nathanshammah Going back to this Tuesday's discussion of renaming |
|
I think this seems like a good idea. Define a dictionary for all the methods specific to the number of qubits. This could also be where optimization methods are called. The possibilities right now - least number of gates, least number of CNOT gates. |
Changed decomposition functions being a subpackage to a submodule. All other functions in the subpackage have been made private with only The functions Here's an example screenshot : |
Maybe you two discussed this already, but what is the motivation behind this change? It doesn't (shouldn't) make a difference in the user interface I think because we only expose those public APIs in |
@BoxiLi We discussed some style changes as well as removing target and num_qubits as input to single qubit functions. The targets of these outputs will be changed from gray code ordering function.
I wanted to use an easier way to import the main decomposition functions if they were all in one file. Before yesterday's changes, if there was a need to import some function it would be like below : from qutip_qip.decompose.some_decomposition_functions_folder_name import decompose_n_qubit gate After creating from qutip_qip.decompose import decompose_n_qubit gate I could keep all of these in the same folder if you would prefer the import path be changed in |
Ok, I think this is the key point here:
If I understand correctly, you were saying that if we use a subpackage structure like this:
And there is a function
Is that correct? I don't think the above is true because if you import
That is what happening in e.g. Or did I miss understand you? |
I have pushed the new discussed changes. Looking back, I don't think we discussed |
The two functions are very general and can be promoted as class method, rather than being restricted in the decomposition module.
They are indeed useful functions, we can surely keep them in the code. However, we can make them a bit more general:
I made these two minor changes in a commit, feel free to criticize. |
@BoxiLi Looks good to me ! I could have also made the changes if you would have replied to an earlier comment ! Thanks ! 😸 |
Yeah, I definitely believe that you would have made the same changes. I missed that question so failed to reply on time. The PR is in good shape to me. I was considering that we could merge it on Monday if @hodgestar has no further suggestions. |
Co-authored-by: Boxi Li <etamin1201@gmail.com>
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.
Looking good to me!
Good job! You can now rebase your changes for two qubits gate decomposition on this. @purva-thakre |
Adds general single qubit decomposition functions.
decompose_to_rotation_matrices
because the calculations for others need to be re-calculated. The outputs were not agreeing with input gates. Will come back to these after a general method for n qubits has been added.ABC_decomposition
and others will be added towards the end.extract_global_phase
function is still giving an output off by a phase. In the example notebook, all the outputs are the same as input except forsigmay
. As I was able to useaverage_gate_fidelity
to compare the outputs even when they are off by a phase, I plan to come back to this towards the end. Too many days were spent trying to fix this.Initially, most of the outputs except for sigmay` were off by a phase_factor of -1. The problem was solved by changing the global phase angle.
Imports, style etc will be corrected after final approval.
Fixes #73