When using pytorch and pennylane, multiple amplitude encoding is not work
def encode(inputs, n_qubits, embed_type="amplitude"):
start, end = n_qubits
# setting embedding
if "amplitude" == embed_type:
qml.templates.AmplitudeEmbedding(inputs, wires=range(start, end))
if "angle" == embed_type:
qml.templates.AngleEmbedding(inputs, wires=range(start, end))
def qnn(n_qubits, layer):
dev = qml.device("default.qubit", wires=n_qubits)
def _qcnn(weights,inputs):
x1 = inputs[:, :128]
x2 = inputs[:, -128:]
inputs1 = F.normalize(x1, p=2, dim=1)
encode(inputs1, (0,7), embed_type="amplitude")
inputs2 = F.normalize(x2, p=2, dim=1)
encode(inputs2, (7,14), embed_type="amplitude")
ansatz(weights,layer)
return qml.probs(wires=[0,1,2,3,4,5,6,7,8,9,10,11,12,13])
qlayer = qml.QNode(_qcnn, dev, interface="torch")
weight_shapes = {"weights": 49*layer}
return qml.qnn.TorchLayer(qlayer, weight_shapes)
error message below:
compute_decomposition
raise ValueError(
ValueError: Broadcasting with MottonenStatePreparation is not supported. Please use the qml.transforms.broadcast_expand transform to use broadcasting with MottonenStatePreparation.
Using an amplitude encoding works fine.