PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.25k stars 584 forks source link

Add batching support to the `BasisStatePreparation` template #2074

Open antalszava opened 2 years ago

antalszava commented 2 years ago

Feature details

Following up on the issue description from https://github.com/PennyLaneAI/pennylane/issues/1745 we would like to add batch support to the BasisStatePreparation template.

This follows the addition in https://github.com/PennyLaneAI/pennylane/pull/1710.

Implementation

We would like to support the following example:

import pennylane as qml
from pennylane import numpy as np

wires = 3
dev = qml.device("default.qubit", wires=wires)

@qml.batch_params
@qml.qnode(dev)
def circuit(data, weights):
    qml.templates.BasisStatePreparation(data, wires=[0, 1, 2])
    qml.templates.StronglyEntanglingLayers(weights, wires=[0, 1, 2])
    return qml.expval(qml.PauliX(0))

batch_size = 2

# create a batched input statevector
data = np.ones( (batch_size, wires))
circuit(data, weights)

This can be done by modifying the BasisStatePreparation source code as needed. In addition, a test should be added to tests/transforms/test_batch_params.py.

How important would you say this feature is?

2: Somewhat important. Needed this quarter.

Additional information

No response

eddddddy commented 2 years ago

Hello, I submitted a pull request for this issue. Let me know if there's anything I missed.