4

How does one perform amplitude encoding using only unitary gates ?

Could you show me a concrete example ?

glS
  • 27,670
  • 7
  • 39
  • 126
Duen
  • 466
  • 4
  • 12

2 Answers2

8

In amplitude encoding, we encode data into the amplitudes of a quantum state. So, dataset is represented as a normalized classical $2^n$-dimensional vector, which can be thought of as a quantum state of $n$ qubits. Then, we create the quantum circuit that prepares this state.

As an example, assume that your dataset contains two points:

$$D = \{(1, 3), (0, 2)\}$$ We write it as a vector $$V = [1, 3, 0, 2]$$ Then we normalize it $$V' = \frac{1}{\sqrt{14}}[1, 3, 0, 2]$$ This is a two-qubit quantum state which can be written as: $$|V\rangle = \frac{1}{\sqrt{14}}(|00\rangle + 3|01\rangle + 2|11\rangle)$$ So, we can embed it as follows:

from qiskit import QuantumCircuit
import numpy as np

state = (1 / np.sqrt(14)) * np.array([1, 3, 0, 2]) num_qubits = 2 circ = QuantumCircuit(num_qubits) circ.prepare_state(state, [0, 1])

And to draw the circuit:

circ.decompose(reps = 4).draw('mpl')

enter image description here

Egretta.Thula
  • 12,146
  • 1
  • 13
  • 35
3

The prepare_state method is not a standard method in Qiskit anymore, and it has been removed in recent versions.

To prepare an initial quantum state in Qiskit, you can use the initialize method, which takes a state vector as an input and prepares the qubits in the circuit according to that state vector.

Here is above example using the initialize method in Qiskit:

from qiskit import QuantumCircuit

import numpy as np

state = (1 / np.sqrt(14)) * np.array([1, 3, 0, 2])

num_qubits = 2

circ = QuantumCircuit(num_qubits)

circ.initialize(state, [0, 1])

Martin Vesely
  • 15,398
  • 4
  • 32
  • 75
Sassan
  • 41
  • 2