Transform a circuit to support an initial batch dimension for gate inputs.
In a classical ML application one needs to batch the non-trainable inputs of the network. This function executes the same analogue for a quantum circuit: separate circuit executions are created for each input, which are then executed with the same trainable parameters.
The batch dimension is assumed to be the first rank of the non trainable tensor object. For a rank 1 feature space, the shape needs to be
xindicates the dimension of the features and
Ntbeing the number of examples within a batch. Based on arXiv:2202.10471.
The transformed circuit as described in
qml.transform. Executing this circuit will provide the batched results.
- Return type
dev = qml.device("default.qubit", wires=2, shots=None) @qml.batch_input(argnum=1) @qml.qnode(dev, diff_method="parameter-shift", interface="tf") def circuit(inputs, weights): qml.RY(weights, wires=0) qml.AngleEmbedding(inputs, wires=range(2), rotation="Y") qml.RY(weights, wires=1) return qml.expval(qml.PauliZ(1))
>>> x = tf.random.uniform((10, 2), 0, 1) >>> w = tf.random.uniform((2,), 0, 1) >>> circuit(x, w) <tf.Tensor: shape=(10,), dtype=float64, numpy= array([0.46230079, 0.73971315, 0.95666004, 0.5355225 , 0.66180948, 0.44519553, 0.93874261, 0.9483197 , 0.78737918, 0.90866411])>
- What is PennyLane?
- Quantum circuits
- Gradients and training
- Quantum operators
- Inspecting circuits
- Compiling circuits
- Quantum Chemistry
- Quantum Datasets
- QNode returns
- Custom transforms
- Transforms library
- Decorators and utility functions
- Transforms developer functions
- Old transforms framework