-
Notifications
You must be signed in to change notification settings - Fork 186
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?
Conversation
👋 Hey, looks like you've updated some demos! 🐘 Don't forget to update the Please hide this comment once the field(s) are updated. Thanks! |
Thank you for opening this pull request. You can find the built site at this link. Deployment Info:
Note: It may take several minutes for updates to this pull request to be reflected on the deployed site. |
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.
Great job @gmlejarza 🚀
I made a push to try to simplify the code as much as possible as it could be “intimidating” at first. In general everything is fine and to improve it I would try to be much more direct trying to keep this how-to short
On the other hand, if you have a thumbnail suggestion, I will request it on Monday 🎨
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.
Left suggestions 😈
Classical computers handle arithmetic operations like addition, subtraction, multiplication, and exponentiation with ease. | ||
For instance, you can multiply two numbers on your phone in milliseconds! | ||
|
||
Quantum computers, however, aren't as efficient at basic arithmetic. So why do we need quantum arithmetic? | ||
While it's not "better" for basic operations, it's essential in more complex quantum algorithms. For example: |
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
Quantum computers, however, aren't as efficient at basic arithmetic. So why do we need quantum arithmetic? | ||
While it's not "better" for basic operations, it's essential in more complex quantum algorithms. For example: | ||
|
||
1. In Shor's algorithm quantum arithmetic is crucial for performing modular exponentiation. |
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
|
||
2. Grover's algorithm might need to use quantum arithmetic to construct oracles, as shown in [#demo_qft_arith]_. | ||
|
||
3. Loading functions into quantum computers, which often requires several quantum arithmetic operations. |
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
We can load the target function into the quantum computer using different quantum arithmetic operations. | ||
We will break down into pieces. We'll do a step by step load of the function :math:`f(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.
This is repetitive compared to the previous sentences
# |x> ---> |3x> | ||
qml.Multiplier(3, wires["x"], work_wires=wires["work_wires"]) | ||
|
||
# |3x>|y>|0> ---> |3x>|y>|3xy> |
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
print(circuit(x=1,y=4)) | ||
|
||
###################################################################### | ||
# The result doesn't seem right, as we expect to get :math:`f(x=1, y=4) = 33`. Can you guess why? |
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.
|
||
return qml.sample(wires = wires["output"]) | ||
|
||
print(circuit_with_Poly(x=1,y=4)) |
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 operations
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.
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/
# Conclusion | ||
# ------------------------------------------ | ||
# Understanding and implementing quantum arithmetic is a key step toward unlocking the full potential | ||
# of quantum computing. While it may not replace classical efficiency for simple tasks, its role in complex algorithms |
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
Co-authored-by: ixfoduap <[email protected]>
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 taking shape 💪
Here are some comments
Inplace operators, like the Adder and Multiplier, directly modify the original quantum state by updating a | ||
specific register's state. In contrast, Outplace operators, such as the OutAdder and OutMultiplier, | ||
combine multiple states and store the result in a new register, leaving the original states unchanged. | ||
|
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 :)
In quantum computing, all arithmetic operations are modular. This means the result of any operation is reduced | ||
modulo :math:`2^n`, where :math:`n` is the number of qubits in the register. This is because quantum states can only | ||
represent numbers up to :math:`2^n`, so it's important to keep this in mind when working with quantum arithmetic. |
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.
perhaps it would be better to say that it reduces to a module m. And for simplicity in this how-to we will take m = 2^n, the value that the template assumes by default
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.
Okay, I see that you comment on it later. I think it can be rephrased a bit for clarity
|
||
There are two addition operators in PennyLane: the :class:`~.pennylane.Adder` and the :class:`~.pennylane.OutAdder`. | ||
|
||
The :class:`~.pennylane.Adder` performs an **Inplace** operation, adding a constant value :math:`k` to the state of the wires :math:`|w \rangle`. It is defined as: |
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 would clarify
|
||
###################################################################### | ||
# Now, we write a circuit to prepare the state :math:`|x \rangle|y \rangle|0 \rangle`, since it will be needed for the Outplace | ||
# operation, where we initialize specific values to :math:`x` and :math:`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.
It may be convenient to say that we will use basic states in the example but you could introduce any quantum state
# Now we can implement an example for the :class:`~.pennylane.Adder`. We will add the constant term :math:`4` to the ``wires["x"]`` register: | ||
|
||
@qml.qnode(dev) | ||
def circuit(): | ||
|
||
# |0> ---> |0+4> | ||
qml.Adder(4, wires["x"]) | ||
|
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 example does not convince me because it gives the feeling that it must be linked to the above but it is something totally different
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 included a line explaining and added the initialization of prepare_initial_state
to link it with what it's above
# Nice! | ||
# | ||
# After going through these educational examples, you might be curious if it's possible to | ||
# use these operations for subtraction or division in a quantum computer. The answer is yes! |
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.
"modular division", to avoid confusion
# This is possible through the :func:`~.pennylane.adjoint` operation, which allows us to reverse a multiplication or addition operation, hence enabling | ||
# subtraction and division. We will see this in action in the following section. | ||
# | ||
# Loading a polynomial into a quantum computer |
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.
Let's not use the work "Load", maybe "apply?
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.
If you agree, take a look at the text that appears in more occasions
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.
Why you don't like "load"? I'm not particularly against "apply", but it looks to me that what we are doing is more "loading" a polynomial into a quantum state, more than applying the polynomial anywhere. Anyway, let me know your thoughts and I'm happy to discuss
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.
Definitely not loading! This is a circuit that applies a polynomial transformation to input registers. "Loading" has the connotation of loading data
# |3x>|y>|0> ---> |3x>|y>|3xy> | ||
qml.OutMultiplier(wires["x"], wires["y"], wires["output"]) | ||
|
||
# We return the x-register to its original value using the adjoint operation |
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've been told that it is not clear why we do this. I would emphasize in the text or here that by the definition of U, the inputs |x> and |y> are not modified.
# At this point, it's interesting to consider what would happen if we had chosen a smaller number of wires for the output. | ||
# For instance, if we had selected one less wire for the output, we would have obtained the result :math:`33 \mod 2^5 = 1`. | ||
|
||
wires = qml.registers({"x": 4, "y": 4, "output": 5, "work_wires": 4}) |
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.
We can remove work_wires 😎
wires = qml.registers({"x": 4, "y":4, "output":6,"work_wires": 4}) | ||
@qml.qnode(dev) | ||
def circuit_with_Poly(x,y): | ||
|
||
prepare_initial_state(x, y) | ||
qml.OutPoly(f, registers_wires=[wires["x"], wires["y"], wires["output"]]) |
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.
Based on new interface
wires = qml.registers({"x": 4, "y":4, "output":6,"work_wires": 4}) | |
@qml.qnode(dev) | |
def circuit_with_Poly(x,y): | |
prepare_initial_state(x, y) | |
qml.OutPoly(f, registers_wires=[wires["x"], wires["y"], wires["output"]]) | |
wires = qml.registers({"x": 4, "y":4, "output":6,"work_wires": 4}) | |
@qml.qnode(dev) | |
def circuit_with_Poly(x,y): | |
prepare_initial_state(x, y) | |
qml.OutPoly( | |
f, | |
x_wires = wires["x"], | |
y_wires = wires["y"], | |
output_wires = wires["output"]) |
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.
Easy and simple 💪 It's looking good
How-to use Quantum Arithmetic Operators | ||
======================================= | ||
|
||
Classical computers handle arithmetic operations like addition, subtraction, multiplication, and exponentiation with ease. |
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 👍
operation is reduced modulo :math:mod, where the default is :math:mod=2^n, with :math:n being the number of | ||
qubits in the register.Quantum states can represent numbers up to this limit, which is why PennyLane uses 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.
operation is reduced modulo :math:mod, where the default is :math:mod=2^n, with :math:n being the number of | |
qubits in the register.Quantum states can represent numbers up to this limit, which is why PennyLane uses it | |
operation is reduced modulo :math:`\text{mod}`, where the default is :math:`\text{mod}=2^n`, with :math:`n` being the number of | |
qubits in the register. Quantum states can represent numbers up to this limit, which is why PennyLane uses 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 think it would be better to write “where the Pennylane default is” and delete the phrase, “which is why Pennylane. [...]”
qubits in the register.Quantum states can represent numbers up to this limit, which is why PennyLane uses it | ||
as the default modulo for arithmetic operations. However, users can specify a custom value smaller than this | ||
default. It's important to keep this modular behavior in mind when working with quantum arithmetic, as using | ||
too few qubits in a quantum register could lead to overflow errors. We will come back to this point later. |
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.
it is probably not a good idea to speak of "error", as stated in another 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.
I changed "errors" for "issues"
Next, we will explore how to define and implement addition and multiplication operators in PennyLane. | ||
|
||
Let's start by defining the Inplace and Outplace arithmetic addition operations. |
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 found this section a bit long. I think these two sentences could be eliminated
Let's see how to implement these operators in Pennylane. | ||
|
||
The first thing to do is to define the `registers of wires <https://pennylane.ai/qml/demos/tutorial_how_to_use_registers/>`_ |
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.
we could merge them:
"In order to implement it in PL, the first thing to do [...]"
or similar
# This is possible through the :func:`~.pennylane.adjoint` operation, which allows us to reverse a multiplication or addition operation, hence enabling | ||
# modular division and subtraction. We will see this in action in the following section. |
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 jump from this paragraph to the next was a bit disjointed. We talk about subtraction and division saying we are going to look at it now and then suddenly we move on to polynomials and positive terms. I would simply say something like:
“note that even though we just saw addition and multiplication, modular subtraction and division come as for free thanks to the adjoint operator.”
I would not reference that we are going to see it later (even if we are)
# In this functions, we showed how to undo the multiplication by using the adjoint operation, which in this case is useful to clean | ||
# the input registers ``wires["x"]`` and ``wires["y"]`` after the operation. |
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 we can delete this sentence so as not to repeat ourselves
print(circuit(x=1,y=4), " which represents the number ", state_to_decimal(circuit(x=1,y=4))) | ||
|
||
###################################################################### | ||
# Cool, we get the correct result 33! |
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.
# Cool, we get the correct result 33! | |
# Cool, we get the correct result :math:`f(1,4)=33`! |
x_wires = wires["x"], | ||
y_wires = wires["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.
x_wires = wires["x"], | |
y_wires = wires["y"], | |
input_registers= [wires["x"], wires["y"]], |
new UI again 🙈
# adjoint function to undo certain multiplications and clean up the input registers after performing the operations. | ||
|
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.
# adjoint function to undo certain multiplications and clean up the input registers after performing the operations. | |
# adjoint function to undo certain multiplications and clean up the input registers after performing the operations since :math:`U` does not modify the input registers. | |
What do you think about clarifying this?
======================================= | ||
|
||
Classical computers handle arithmetic operations like addition, subtraction, multiplication, and exponentiation with ease. | ||
For instance, you can multiply two numbers on your phone in milliseconds! |
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.
For instance, you can multiply two numbers on your phone in milliseconds! | |
For instance, you can multiply large numbers on your phone in milliseconds! |
Quantum computers can handle these operations too, but their true value lies beyond basic calculations. While we don't plan to use | ||
quantum computers as calculators for everyday arithmetic, these operations play a crucial role in more advanced quantum algorithms, | ||
serving as fundamental building blocks in their design and execution. For example: |
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.
Quantum computers can handle these operations too, but their true value lies beyond basic calculations. While we don't plan to use | |
quantum computers as calculators for everyday arithmetic, these operations play a crucial role in more advanced quantum algorithms, | |
serving as fundamental building blocks in their design and execution. For example: | |
Quantum computers can handle these operations too, but their true value lies beyond basic calculations. Quantum arithmetic plays a crucial role in more advanced quantum algorithms, | |
serving as fundamental building blocks in their design and execution. For example: |
|
||
2. Grover's algorithm might need to use quantum arithmetic to construct oracles, as shown in [#demo_qft_arith]_. | ||
|
||
3. Loading functions into quantum computers often requires several quantum arithmetic operations [#sanders]_. |
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.
3. Loading functions into quantum computers often requires several quantum arithmetic operations [#sanders]_. | |
3. Loading data or preparing initial states on a quantum computer often requires several quantum arithmetic operations [#sanders]_. |
InPlace and OutPlace arithmetic operations | ||
------------------------------------------ | ||
Let's begin by defining the terms "Inplace" and "Outplace" in the context of arithmetic operators. | ||
Inplace operators, like the Adder and Multiplier, directly modify the original quantum state by updating a |
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.
Adder, Multiplier, OutAdder and OutMultiplier are now operations in PL, right? We should then add a link to them
:width: 90% | ||
|
||
In quantum computing, all arithmetic operations are inherently modular. This means that the result of any | ||
operation is reduced modulo :math:`\text{mod}`, where the Pennylane default is :math:`\text{mod}=2^n`, |
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.
"reduced module mod" is unclear. I suggest to :
- Say operations are modular, and add a link to wikipedia on modular arithmetic
- Give a simple example, like 32 +43 = 11 mod 64
- Mention that default in PL is 2^n
import pennylane as qml | ||
|
||
# we indicate the name of the registers and their number of qubits | ||
wires = qml.registers({"x": 4, "y":4, "output":6,"work_wires": 4}) |
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.
Not clear why we need work wires. Please clarify
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.
Tutorial is in much better shape now, but still needs improvements. I think my suggestions should be easy to address
|
||
###################################################################### | ||
# Now, we write a circuit to prepare the state :math:`|x \rangle|y \rangle|0 \rangle`, since it will be needed for the Outplace | ||
# operation, where we initialize specific values to :math:`x` and :math:`y`. Note that in this example we use basic states, but |
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.
# operation, where we initialize specific values to :math:`x` and :math:`y`. Note that in this example we use basic states, but | |
# operation, where we initialize specific values to :math:`x` and :math:`y`. Note that in this example we use computational basis states, but |
###################################################################### | ||
# Next, for understandability, we will use an auxiliary function that will | ||
# take 1 sample from the circuit and return the associated decimal number. | ||
# Note that we are sampling from the circuit instead of returning the quantum state to demonstrate |
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.
Sentence starting with "Note that we are sampling" should be first, then followed by "Next,..."
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 sentence about sampling is misleading. Of course the quantum circuit produce the target output in the output state, which means a measurement is deterministic. This has nothing to do with hardware applicability. What I understand is that sampling is a trick that helps to extract the state in the output register. So please explain this better
|
||
###################################################################### | ||
# Next, for understandability, we will use an auxiliary function that will | ||
# take 1 sample from the circuit and return the associated decimal number. |
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.
# take 1 sample from the circuit and return the associated decimal number. | |
# take one sample from the circuit and return the associated decimal number. |
return sum(bit * (2 ** idx) for idx, bit in enumerate(reversed(binary_array))) | ||
|
||
###################################################################### | ||
# In this example we are setting :math:`x=1` and :math:`y=4` and checking the results are as expected. |
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.
# In this example we are setting :math:`x=1` and :math:`y=4` and checking the results are as expected. | |
# In this example we are setting :math:`x=1` and :math:`y=4` and checking that the results are as expected. |
# In this example we are setting :math:`x=1` and :math:`y=4` and checking the results are as expected. | ||
|
||
output = circuit(x=1,y=4) | ||
print("x register: ", output[0]," which represents the number ", state_to_decimal(output[0])) |
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 long! I suggest [0001] --> 1, or something similarly compact
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.
And too long because code blocks that are to long horizontally show up in the build with a scroll bar which is ugly and annoying
# Cool, we get the correct result :math:`f(1,4)=33`! | ||
# | ||
# At this point, it's interesting to consider what would happen if we had chosen a smaller number of wires for the output. | ||
# For instance, if we had selected one less wire for the output, we would have obtained the result :math:`33 \mod 2^5 = 1`. |
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.
# For instance, if we had selected one less wire for the output, we would have obtained the result :math:`33 \mod 2^5 = 1`. | |
# For instance, if we had selected one less wire, we would have obtained the result :math:`33 \mod 2^5 = 1`. |
# In the last section, we showed how to use different arithmetic operations to load | ||
# a function onto a quantum computer. But what if I told you there's an easier way to do all this using just one | ||
# PennyLane function that handles the arithmetic for you? I'm talking about :class:`~.pennylane.OutPoly`. | ||
# This handy operator lets you load polynomials directly into quantum states, taking care of all the arithmetic in one go. | ||
# Let's check out how to load a function like :math:`f(x, y)` using :class:`~.pennylane.OutPoly`. |
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.
# In the last section, we showed how to use different arithmetic operations to load | |
# a function onto a quantum computer. But what if I told you there's an easier way to do all this using just one | |
# PennyLane function that handles the arithmetic for you? I'm talking about :class:`~.pennylane.OutPoly`. | |
# This handy operator lets you load polynomials directly into quantum states, taking care of all the arithmetic in one go. | |
# Let's check out how to load a function like :math:`f(x, y)` using :class:`~.pennylane.OutPoly`. | |
# There is a more direct method to apply polynomial transformations in PennyLane: | |
# using :class:`~.pennylane.OutPoly`. | |
# This operator automatically takes care of all the arithmetic under the hood. | |
# Let's check out how to load a function like :math:`f(x, y)` using :class:`~.pennylane.OutPoly`. |
return 4 + 3*x*y + 5*x + 3*y | ||
|
||
###################################################################### | ||
# Now, we load it into a quantum circuit. |
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.
# Now, we load it into a quantum circuit. | |
# Now, we create a quantum circuit using :class:`~.pennylane.OutPoly`. |
# Eureka! We've just seen how much easier it can be to implement arithmetic operations in one step. | ||
# Now, it's up to you to decide, depending on the problem you are tackling, whether to go for the versatility |
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.
# Eureka! We've just seen how much easier it can be to implement arithmetic operations in one step. | |
# Now, it's up to you to decide, depending on the problem you are tackling, whether to go for the versatility | |
# You can decide, depending on the problem you are tackling, whether to go for the versatility |
# of quantum computing. By leveraging tools like :class:`~.pennylane.OutPoly`, you can streamline the coding of your quantum algorithms. So, | ||
# whether you choose to customize your arithmetic operations or take advantage of the built-in convenience offered by PennyLane | ||
# operators, you are now equipped to tackle the exciting quantum challenges ahead. |
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.
# of quantum computing. By leveraging tools like :class:`~.pennylane.OutPoly`, you can streamline the coding of your quantum algorithms. So, | |
# whether you choose to customize your arithmetic operations or take advantage of the built-in convenience offered by PennyLane | |
# operators, you are now equipped to tackle the exciting quantum challenges ahead. | |
# of quantum computing. By leveraging quantum arithmetic operations in PennyLane, you can streamline | |
# the coding of your quantum algorithms. So, | |
# whether you choose to customize your arithmetic operations or take advantage of the built-in | |
# convenience offered by PennyLane | |
# operators, you are now equipped to tackle the exciting quantum challenges ahead. |
Title: How to use Quantum Arithmetic Operators [sc-74430]
Summary: We show how to load a function into a quantum computer using Pennylane arithmetic operators.
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
Promote and make people understand how to use quantum arithmetic operators in Pennylane.
Researchers working in quantum algorithms, beginners starting in quantum computing.
Quantum Arithmetic, Loading functions into quantum computers, Addition, Multiplication,
(more details here)