What is the difference between qubitstatevector, amplitudeembedding and MottonenStatePreparation coding? If 2 ^ n data are encoded into n qubits, are there any other methods besides these three methods?
Hi @zj-lucky, very good question!
MottonenStatePreparation are not really encodings but state preparations. This means that what they do is that they put your qubits into the specific quantum state that you want.
For example, let’s say you have one qubit and you want to put it in state [0,1]. Then you can use either
MottonenStatePreparation to put your qubit into that state.
Note that not all devices support
QubitStateVector. Remember that PennyLane allows you to use the devices from many different providers and not all of them support all operations. In the case where you use
QubitStateVector on a device that doesn’t support it, then under the hood PennyLane will use the Mottonen state preparation.
On the other hand you have encodings/embeddings. These are algorithms used to embed classical data into a quantum computer. Your data can be a set of real numbers for example, and you will want to somehow encode those numbers into quantum states.
In this page you will find several kinds of embeddings. The reason to use one or the other will depend on the kind of data and your problem. For instance,
BasisEmbedding is useful when you have discrete data and
AmplitudeEmbedding is useful when you have continuous and normalized data.
Here are some examples of how these embeddings can be used.
Basis State: you can see it in the first example of the variational classifier demo. In the second example you can see a different (custom) embedding. https://pennylane.ai/qml/demos/tutorial_variational_classifier.html
Amplitude embedding: in the docs for this embedding there are a couple of examples that can help you learn how to use it in your code.
Please let me know if this helped!
Thank you very much for your reply, which helped me a lot. BasisEmbedding and AmplitudeEmbedding are quantum encodings of classical data. We know the difference between them, but for quantum state preparation: What is the essential difference between QubitStateVector and MottonenStatePreparation? Is there any explanation of their principle?
Good question @zj-lucky.
In fact QubitStateVector is an operation that is available in some devices but not others. Some hardware providers may have this operation and then it’s up to them to decide how to make it work under the hood.
The MottonenStatePreparation uses a sequence of uniformly controlled rotations to prepare the given state. This can be implemented in all devices. This is why, if you use QubitStateVector in your code but this operation is not available in the device, then PennyLane will use the MottonenStatePreparation instead.
Please let me know if this is clear!
In my understanding,
QubitStateVector is an abstract gate.
It doesn’t tell us how we can construct it by using elementary gate set (e.g. RX,RY,RZ,CNOT…).
Therefore, it only works in simulators.
# pennylane-qiskit plugin and pylatexenc is required. n_qubits = 2 dev_qiskit = qml.device("qiskit.aer", wires=n_qubits) state = [1/2,-1/2,1/2,-1/2] @qml.qnode(dev_qiskit) def circ(): qml.QubitStateVector(state,wires=range(n_qubits)) return qml.probs(wires=range(n_qubits)) circ() dev_qiskit._circuit.draw(output='mpl')
On the other hand,
MottonenStatePreparation is an example of an actual implementation of
QubitStateVector with using elementary gate set.
n_qubits = 2 dev_qiskit = qml.device("qiskit.aer", wires=n_qubits) state = [1/2,-1/2,1/2,-1/2] @qml.qnode(dev_qiskit) def circ(): qml.templates.MottonenStatePreparation(state, wires=range(n_qubits)) return qml.probs(wires=range(n_qubits)) circ() dev_qiskit._circuit.draw(output='mpl')
However, I don’t know whether this implementation (namely, decomposition of state preparation into elementary gate chain) is computationally effecient or not.
Sorry, if my understanding is not correct.
Hi @Kuma-quant, thank you for this explanation! It sounds accurate to me and the drawing of the circuits is very helpful.
As far as I know
QubitStateVector is not limited to only working on simulators. It depends more on what is supported by the hardware provider. Qiskit supports
QubitStateVector for simulators but it could also support it for actual quantum computers, and perform any decomposition of their choice under the hood.
The benefit of having the option of using either
MottonenStatePreparation is that you can decide whether to go with whatever the provider is doing in
QubitStateVector, or having more control on how the state is prepared by using
I hope this helped to complement the answer .
Thanks @CatalinaAlbornoz .
Oh, I didn’t know it.
Indeed, Qiskit now supports decomposition of state vector preparation into elementary gate set!
Oh that’s great @Kuma-quant! Thanks for sharing!