Op2QButterflyLayer#

class torchquantum.layer.Op2QButterflyLayer(op, n_wires: int, has_params=False, trainable=False, wire_reverse=False)[source]#

Bases: QuantumModule

Quantum layer applying the same two-qubit operation in a butterfly pattern.

This class represents a quantum layer that applies the same two-qubit operation in a butterfly pattern. The butterfly pattern connects the first and last wire, the second and second-to-last wire, and so on, until the center wire(s) in the case of an odd number of wires.

Parameters:
  • op (tq.Operator) – Two-qubit operation to be applied.

  • n_wires (int) – Number of wires in the quantum device.

  • has_params (bool, optional) – Flag indicating if the operation has parameters. Defaults to False.

  • trainable (bool, optional) – Flag indicating if the operation is trainable. Defaults to False.

  • wire_reverse (bool, optional) – Flag indicating if the order of wires in each pair should be reversed. Defaults to False.

__init__(op, n_wires: int, has_params=False, trainable=False, wire_reverse=False)[source]#

Initialize the QuantumModule.

Returns:

None.

Examples

>>> qmodule = QuantumModule()

Methods

forward(q_device)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Attributes

training: bool#