I'm trying to learn how to use PennyLane's CVNeuralNetLayers. I wrote this code below but I am not able to use the resulting state of the circuit generated by this layer. I looked for examples in the documentation but found nothing.

I already tried to change the device to "default.qubit" but a similar error occurs. Is it possible to visualize the resulting state of this layer? Should i change the pennylane device?

from pennylane.templates.layers import CVNeuralNetLayers
from pennylane import numpy as np
import pennylane as qml

dev = qml.device('lightning.qubit', wires=4)

n_layers = 1
n_wires = 4

shapes = CVNeuralNetLayers.shape(n_layers, n_wires)
weights = [np.random.random(shape) for shape in shapes]

def circuit(weights):
  CVNeuralNetLayers(*weights, wires=[0, 1, 2, 3])
  return qml.state()

print("\n\n", qml.draw(circuit, expansion_strategy="lightning")(weights))

ket = circuit(weights)
print("\nResulting State: ", ket)

The output is:

DeviceError: Gate Beamsplitter not supported on device lightning.qubit

1 Answer 1


The CVNeuralNetLayers use a very particular set of quantum gates that are unique to photonics. The only device that is available in PennyLane which can simulate these gates is the Strawberry Fields plugin device. It should be able to handle circuits with CVNeuralNetLayers.

As a secondary note, this plugin is not as feature-rich as some other ones, so I'm not 100% whether or not it will support the functionality you are looking to use (qml.draw and qml.state). You'll have to check whether it suits your particular needs.

  • $\begingroup$ Yes! That's exactly my problem. I searched in the strawberry fields documentation and unfortunately I didn't find any device from this plugin that supports the qml.state or qml.draw functions $\endgroup$ Mar 29, 2023 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.