RandomLayer¶
Module: pennylane.templates.layers
-
RandomLayer
(weights, wires, ratio_imprim=0.3, imprimitive=<class 'pennylane.ops.qubit.CNOT'>, rotations=None, seed=42)[source]¶ A layer of randomly chosen single qubit rotations and 2-qubit entangling gates, acting on randomly chosen qubits.
The number \(k\) of single qubit rotations is inferred from the first dimension of
weights
.This is an example of two 4-qubit random layers with four Pauli-y/Pauli-z rotations \(R_y, R_z\), controlled-Z gates as imprimitives, as well as
ratio_imprim=0.3
:Note
Using the default seed (or any other fixed integer seed) generates one and the same circuit in every quantum node. To generate different circuit architectures, either use a different random seed, or use
seed=None
together with thecache=False
option when creating a quantum node.Warning
If you use a random number generator anywhere inside the quantum function without the
cache=False
option, a new random circuit architecture will be created every time the quantum node is evaluated.Parameters: - weights (array[float]) – array of weights of shape
(k,)
- wires (Sequence[int]) – sequence of qubit indices that the template acts on
Keyword Arguments: - ratio_imprim (float) – value between 0 and 1 that determines the ratio of imprimitive to rotation gates
- imprimitive (pennylane.ops.Operation) – two-qubit gate to use, defaults to
CNOT
- rotations (list[pennylane.ops.Operation]) – List of Pauli-X, Pauli-Y and/or Pauli-Z gates. The frequency determines how often a particular rotation type is used. Defaults to the use of all three rotations with equal frequency.
- seed (int) – seed to generate random architecture
- weights (array[float]) – array of weights of shape