-
Notifications
You must be signed in to change notification settings - Fork 70
Adds gray code ordering method #86
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
Conversation
By the way, don't pay attention to the Cognitive Complexity requirement in the codeclimate at the moment, I'll raise that bar in a separate PR. edit: This is done. |
@BoxiLi Haven't pushed the tests yet. But all the functions do output what they are supposed to (except for the plot). |
@BoxiLi Here's an example output for decomposing a random 3 qubit unitary into two-level arrays. Earlier when I was referring to finding the non-trivial indices, I was talking about the output arrays from Right now, I am comparing these to an identity matrix to find the indices that make them two-level unitaries. Going back to what you said during the meeting, I do think there needs to be a better method of finding the non-trivial indices instead of comparing each and every array value to an identity. I am thinking of defining a function to iterate over the output from this function to make list of smaller 1 qubit arrays and their respective two-level indices. np.set_printoptions(precision=3)
np.set_printoptions(suppress=True)
two_qubit = rand_unitary(8,dims=[[2] * 3] * 2)
array_decompose = _decompose_to_two_level_arrays(two_qubit, 3)
print(*array_decompose, sep='\n\n') Edit : Removed large output for above. |
My suggestion is that if we can represent all the information in a compact form, like It is like entropy in physics, it is easy to go from low entropy to high entropy (Gate->full matrix) but "very hard" to go the other way around :) Of course, when you want to test the result you will like them to be in the matrix or |
I think I am going to keep the array output as is for the decomposition to two level arrays because I tend to check their output product quite often for larger number of qubits. I will try to define a function to generate a compact form output I will need to look over how a |
Surely you can go whichever way you find easier before we finalize things. My experience is that, during the calculation, you will very likely first get the compact information. Like in the following code. You first get the single-qubit-unitary consisting of compact_info = (
np.array([[a_star/norm_constant, b/norm_constant],[b_star/norm_constant, -a/norm_constant]]),
index_1,
index_2
) And let the function return it if only the compact form is needed. For your convenience, you can add a parameter |
For your purpose, defining a class is equivalent to saving the compact info. If you want to focus on the decomposition algorithm, the compact info representation is sufficient. The most basic use case of class is to save a bunch of information together under the same name. You can understand it same as a list. Just instead of access each element by the index. you can access them by an attribute name, like We don't need to support two-level gates in |
Yep, I am aware of this. My issue is not knowing which attributes would be helpful and then going back and changing them too many times. For the array output, I will create a But for the |
That also makes sense. Do you need to show them in the circuit plotting? If that is the case, then indeed you have to define a class object. I have to admit that currently define a gate subclass is not very straightforward as Gate is still a bit entangled with QubitCircuit. Let me know if you have any trouble. Basically, you can always define a method in the subclass that overwrite the method in the parent class. So you have plenty of flexibility there. That is the magic of class. You don't need to have a very clean solution to this gate subclass. We can remove redundancy later and focus on the core functionality you need at the moment. |
Co-Authored-By: Boxi Li <[email protected]>
def _decompose_multi_cnot_further(): | ||
""" Decomposes output of lemma 7.3 even further by using only 1 particular | ||
cnot with different controls. | ||
# based on lemma 7.2 of https://arxiv.org/abs/quant-ph/9503016 | ||
""" |
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.
Some of these functions have incomplete code because locally their output is incorrect. Want to correct the error before committing.
assert expected_gray_code == calc_gray_code | ||
|
||
|
||
@pytest.mark.xfail |
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.
This test fails. See comment for more info --> kept it for later today while working on the general fucntions.
closing this for now. Will add a new general decomposition method PR later this week. |
Examples
Suppose the non-trivial state indices of a two-level unitary are 10 and 31. The gray code sequence of this mapping can be obtained via