def StronglyEntanglingLayer(weights, wires, r=1, imprimitive=CNOT): r"""A layer applying rotations on each qubit followed by cascades of 2-qubit entangling gates. The 2-qubit or imprimitive gates act on each qubit :math:`i` chronologically. The second qubit for each gate is determined by :math:`(i+r)\mod n`, where :math:`n` is equal to `len(wires)` and :math:`range` a layer hyperparameter called the range. This is an example of two 4-qubit strongly entangling layers (ranges :math:`r=1` and :math:`r=2`, respectively) with rotations :math:`R` and CNOTs as imprimitives: .. figure:: ../../_static/layer_sec.png :align: center :width: 60% :target: javascript:void(0); Args: weights (array[float]): array of weights of shape ``(len(wires), 3)`` wires (Sequence[int]): sequence of qubit indices that the template acts on Keyword Args: r (int): range of the imprimitive gates of this layer, defaults to 1 imprimitive (pennylane.ops.Operation): two-qubit gate to use, defaults to :class:`~.CNOT` """ if len(wires) < 2: raise ValueError( "StronglyEntanglingLayer requires at least two wires or subsystems to apply " "the imprimitive gates.") for i, wire in enumerate(wires): Rot(weights[i, 0], weights[i, 1], weights[i, 2], wires=wire) num_wires = len(wires) for i in range(num_wires): imprimitive(wires=[wires[i], wires[(i + r) % num_wires]])
def StronglyEntanglingCircuitBlock(weights, periodic=True, r=1, imprimitive=CNOT, wires=None): """pennylane.template.StronglyEntanglingCircuitBlock(weights, periodic=True, r=1, imprimitive=qml.CNOT, wires) An individual block of a strongly entangling circuit. Args: weights (array[float]): shape ``(len(wires), 3)`` array of weights periodic (bool): whether to use periodic boundary conditions when applying imprimitive gates r (Sequence[int]): range of the imprimitive gates of this block imprimitive (pennylane.ops.Operation): Imprimitive gate to use, defaults to :class:`~.CNOT` Keyword Args: wires (Sequence[int]): Wires the block should act on """ for i, wire in enumerate(wires): Rot(weights[i, 0], weights[i, 1], weights[i, 2], wires=wire) num_wires = len(wires) for i in range(num_wires) if periodic else range(num_wires - 1): imprimitive(wires=[wires[i], wires[(i + r) % num_wires]])
def _strongly_entangling_layer(weights, wires, r, imprimitive): r"""A layer applying rotations on each qubit followed by cascades of 2-qubit entangling gates. Args: weights (array[float]): array of weights of shape ``(len(wires), 3)`` wires (Sequence[int]): sequence of qubit indices that the template acts on r (int): range of the imprimitive gates of this layer, defaults to 1 imprimitive (pennylane.ops.Operation): two-qubit gate to use, defaults to :class:`~pennylane.ops.CNOT` """ for i, wire in enumerate(wires): Rot(weights[i, 0], weights[i, 1], weights[i, 2], wires=wire) n_wires = len(wires) if n_wires > 1: for i in range(n_wires): imprimitive(wires=[wires[i], wires[(i + r) % n_wires]])