PennyLane for quantum machine learning

i am going to use Mottonenstate preparation method for data encoding. Based on Mottonen state preparation function in Pennylane, number of qubits is equal to log(num_feature). I used this ‘qml.templates.MottonenStatePreparation(x, wires=[1, 2, 3])’, but i got this error:
raise ValueError("‘state_vector’ has to be of length 1.0, got {}".format(norm))
ValueError: ‘state_vector’ has to be of length 1.0, got 35.146891102531455.
do i have to normalize data before using them as an input for MottonenStatePreparation function.

Many thanks

Hi @sassan_moradi,

Welcome, and thank you for your question!

Yes, the input vectors must be normalized. While this is indicated in the error message, I notice that it is not actually specified in the function documentation, so I’ll make an update to the docs to include this.

Feel free to let us know if you have any further questions!

Does it make sense to try the mottonen state preparation in 2D data? are there any limitations? also can we expand this to 3D or ND data? thanks

Hi @NikSchet,

As far as I know there are not generalizations to more dimensions, but depending on what you are doing one workaround would be to unroll (flatten) multi-dimensional data down into 1-dimensional data, and use that as the input to state prep.

If you’re interested to discuss further, I encourage you to open a new thread for this topic.

1 Like