Multiple qumode code for function approximation

Hello,
I attempted to extend the Strawberry Field website’s 1-qumode function approximation (CV-QNN) code to multiple qumodes (more than one). I’m facing an issue with the classical input data encoding part. How to encode classical data for more than one qumode into quantum data.
Please let me know in case anyone has already solved the function approximation problem using multiple qumodes.

CV-QNN with just 1 qumode is not sufficient to approximate a fairly complicated function (in my case, a simple exponential function), no matter how many CV-QNN layers are employed. I obtained the best accuracy of 8E-2 (relative error). Has anyone else had similar problems?

Thanks in advance.

Hi @ameya,

What function are you referring to?

Maybe it will be easier for you to use PennyLane together with Strawberry Fields.

PennyLane’s CVNeuralNetLayers for example allows you to use several Modes. Make sure to read the documentation for this function and install the PennyLane-Strawberry Fields Plugin in order to use it.

Please let me know if this is what you were looking for!

Hello Catalina,
Thanks for your reply. The link which you provided has function fitting problem in the tutorial section. See the link here Function fitting with a photonic quantum neural network — PennyLane documentation .This approximates the function using single qumode (wire). In this case, the input data is encoded in the q-state using displacement gate. I wanted to write a code for multiple qumodes, I tried but I do not know how to encode the input data into quantum state using displacement gate. Can you please help me with multiple qumode function fitting problem?

thanks,
Ameya

Hi @ameya,

In the tutorial you shared we’re encoding the “X” data, point by point (“x”), into the circuit using a displacement gate. One function that will make your life easier if you’re using several qmodes is using the DisplacementEmbedding template. In the documentation for this template you will find an example with 3 wires, not specifically for function fitting, but it will help you understand how to use the template. Alternatively you could also do the embedding without using the template, by adding another displacement gate for every additional feature you want to add. If you look at the documentation for the Displacement gate you will notice that the first argument is the amplitude for the displacement and the second one is the phase. I recommend that you start by keeping the phase at 0.0 and making the amplitude depend on the value of your feature.

Eg:

qml.Displacement(x[0], 0.0, wires=0)
qml.Displacement(x[1], 0.0, wires=1)

If you’re interested in function fitting but don’t necessarily need to use Continuous Variable, please let me know and I can share some resources using the gate-based model.

Please let me know if this helps!

Thanks I will go through the documentation, and get back to you in case of any questions.

Also, I’m looking for CV based models for function fitting.