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.
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
How-to: Quantum Arithmetic #1229
base: dev
Are you sure you want to change the base?
How-to: Quantum Arithmetic #1229
Changes from 9 commits
d29d6d7
6e89bb1
eabb5e8
d7c6117
464cb64
56fc617
b8997a1
5893c0b
ca722ae
c3fdbbc
513a1a5
c8725b9
0ca2526
ddb8b06
ddc8a90
937f8a7
8aad2e2
a5b4540
d16d951
9b8f24f
0a176f8
006891c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 like the intro 👍
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.
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.
Too negative and not really true! Quantum hardware currently has a hard time with arithmetic, but in principle a quantum computer can do this with ease. I suggest instead motivating quantum arithmetic by saying that we don't plan to use quantum computers as calculators, but arithmetic is an important building block
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.
Add link
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.
Add link
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.
an image showing a sketch of an inplace and outplace operator could look good here :)
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 is repetitive compared to the previous sentences
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.
Nice!
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.
Just say we first write a circuit to prepare |x>|y>|0>, which we should have referenced before as the starting point, e.g., we should say that Adder is |x>|y>|0> --> |x>|y>|x+y>
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.
So basically I suggest that you first define what addition looks like in quantum and show both versions. Then describe the circuit to implement it
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 don't like the name "prepare initial state". Actually preparing a target quantum state is very difficult. This is just initializing registers to a basis state. Consider a better name.
product_basis_state
comes to mindThere 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.
Why are we sampling? maybe good to explain in a comment
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.
Can't we just return the state?
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 idea is that if we sample we are showing that these results can also be obtained in hardware, where access to the state is not possible. I added an explanation in case it was not clear 👍
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 suggest that in order to do not make the reader think that this whole cell is for initialization, you could break the cell here and say:
“Next, for understandability, we will use an auxiliary function that will take 1 sample from the circuit and return the associated decimal number."
or similar
You may also move the sampling note of the next paragraph here
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.
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 haven't really explained why this is needed. It may also not be super clear to all readers that the uncomputation is done using the adjoint. For example, it may be a good opportunity to mention that we can use adders and multipliers to effectively subtract and divide.
In fact I'm curious, would the multiplier work if we multiply by 1/3? Multiply by sqrt{2}? It's not clear what are the allowed values for such scalars. Seems like only integers make sense
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.
As suggested, I added an explanation about how the subtraction and division can be achieved by using the adjoint. Regarding the possibility of multiplying by non-integer numbers, the documentation of each operator specifies that the constant used for addition/multiplication is an integer: https://docs.pennylane.ai/en/stable/code/api/pennylane.Adder.html , https://docs.pennylane.ai/en/stable/code/api/pennylane.Multiplier.html
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.
No, showing incorrect results is not good in a demo! Much better to clarify from the beginning that all arithmetic is done modulo the largest number that can be supported given the number of qubits. Then you have an example that works, and THEN you can quickly change inputs to showcase overflow, tying back to the how this was mentioned before.
In fact getting 1 instead of 33 is not wrong, it's what we want and expect. We just have to remember that this is all modular arithmetic (hence why it's good to clarify from the beginning)
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.
Good point! I clarified from the beginning that all arithmetic is modular. Then, changed the order to show first the "expected" result (33) and then reduce the number of wires to showcase the overflow and remember that quantum arithmetic is modular.
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.
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.
By the way, I'm thinking it may be nice to code up a simple function to convert binary into integers so we can print out the numerical value directly alongside the bitstring description. If I remember correctly, numpy or scipy have these already
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.
Also, is there a way to visualize the circuits that doesn't just show
OutPoly
or something? It would be great to see how they are decomposed into basic operationsThere 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.
Unfortunately, there's no such built-in function that automatically converts a list representing a binary number into its decimal form. However, I've coded a custom function to print out the numerical value alongside the bitstring.
Regarding visualization, I included a printout of the Adder circuit, showing that the addition uses a QFT to switch the basis and then applies rotations to perform the addition in the Fourier basis. I think, this operator is the most pedagogical to showcase, since it serves as a building block to build the others. I also referred the reader to this demo, where the decomposition is further explained: https://pennylane.ai/qml/demos/tutorial_qft_arithmetics/
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.
Remove the second sentence