Encoding complex data

Hi everybody.

Let’s consider that i have complex data. how can i encode them with MÖttÖnen preparation method? How can i define angles for complex data? is it possible to do it or not?

Many thanks for your useful answers in advance.

Hi @sassan_moradi!

The input to MottonenStatePreparation applied to N wires should be a complex, normalized vector of length 2 ** N. For example, if you have two qubits then you can encode a 4-dimensional complex datapoint.

Here is an example:

import pennylane as qml
from pennylane import numpy as np

dev = qml.device("default.qubit", wires=2)

dat = np.random.random(4) + 1j * np.random.random(4)
dat /= np.sqrt(np.sum(np.abs(dat) ** 2))

def f(dat):
    qml.templates.MottonenStatePreparation(dat, wires=range(2))
    return qml.state()

dat_out = f(dat)

abs(np.vdot(dat, dat_out)) ** 2

Note that the prepared state dat_out is the same as dat up to a global phase.

many many thanks for your useful answer.

No problem, let us know if you have any difficulties! Thanks

i run your example. I encountered this error message:
AttributeError: module ‘pennylane’ has no attribute ‘state’.

This may be a case of upgrading PennyLane, try running
pip install pennylane --upgrade

many thanks again, Tom. It works “pip install pennylane --upgrade”.

1 Like