RandomLayer#
- class torchquantum.layer.RandomLayer(wires, n_ops=None, n_params=None, op_ratios=None, op_types=(<class 'torchquantum.operator.standard_gates.rx.RX'>, <class 'torchquantum.operator.standard_gates.ry.RY'>, <class 'torchquantum.operator.standard_gates.rz.RZ'>, <class 'torchquantum.operator.standard_gates.paulix.CNOT'>), seed=None, qiskit_compatible=False)[source]#
Bases:
QuantumModule
Quantum module that represents a random layer of quantum operations applied to specified wires.
- Parameters:
wires (int or Iterable[int]) – Indices of the wires the operations are applied to.
n_ops (int) – Number of random operations in the layer.
n_params (int) – Number of parameters for each random operation.
op_ratios (list or float) – Ratios determining the relative frequencies of different operation types.
op_types (tuple or tq.Operator) – Types of random operations to be included in the layer.
seed (int) – Seed for random number generation.
qiskit_compatible (bool) – Flag indicating whether the layer should be compatible with Qiskit.
- op_ratios#
Ratios determining the relative frequencies of different operation types.
- Type:
numpy.array
- op_list#
List of random operations in the layer.
- Type:
tq.QuantumModuleList
- __init__(wires, n_ops=None, n_params=None, op_ratios=None, op_types=(<class 'torchquantum.operator.standard_gates.rx.RX'>, <class 'torchquantum.operator.standard_gates.ry.RY'>, <class 'torchquantum.operator.standard_gates.rz.RZ'>, <class 'torchquantum.operator.standard_gates.paulix.CNOT'>), seed=None, qiskit_compatible=False)[source]#
Initialize the QuantumModule.
- Returns:
None.
Examples
>>> qmodule = QuantumModule()
Methods
- forward(q_device: QuantumDevice)[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.
- rebuild_random_layer_from_op_list(n_ops_in, wires_in, op_list_in)[source]#
Rebuilds a random layer from the given operation list. This method is used for loading a random layer from a checkpoint.
Attributes