I am trying to develop a CV neural network for function fitting, so I am basing my code on this tutorial
However, I am interested in using more than one qumode. I am using qml.CVNeuralNetLayers to create the layers. When I define the circuit, to give an initial value for the parameters, I am doing something like this
shapes = qml.CVNeuralNetLayers.shape(n_layers=num_layers, n_wires=num_wires) var_init = [np.random.random(shape, requires_grad=True) for shape in shapes] def circuit(var, x): for i,j in enumerate(x): qml.Displacement(j, 0.0, wires=i) qml.CVNeuralNetLayers(*var, wires=range(num_wires)) return qml.expval(qml.X(0)),qml.expval(qml.X(1)),qml.expval(qml.X(2)) var_init_array = np.array(var_init)
I have noted that the last part in which I define var_init_array is neccesary to make the circuit trainable (otherwise it just keeps using the same parameters for each iteration). The problem is that qml.CVNeuralNetLayers requires several tensors with different shapes as inputs, so I get an error when trying to define the aforementioned array (except when num_wires=3, because all of those tensors have the same shape and then everything works):
could not broadcast input array from shape (4,6) into shape (4,)
I don’t get why I can’t train the circuit with a list of tensors instead of having to convert it to an array, but anyway the arguments in qml.CVNeuralNetLayers are not generally equal in shape so I can’t define that array and train my network. I don’t know which is the best solution to this, so any help is welcome. Thank you in advance!