Operator#

class torchquantum.operator.Operator(has_params: bool = False, trainable: bool = False, init_params=None, n_wires=None, wires=None, inverse=False)[source]#

Bases: QuantumModule

The class for quantum operators.

__init__(has_params: bool = False, trainable: bool = False, init_params=None, n_wires=None, wires=None, inverse=False)[source]#

__init__ function for Operator.

Parameters:
  • has_params (bool, optional) – Whether the operations has parameters. Defaults to False.

  • trainable (bool, optional) – Whether the parameters are trainable (if contains parameters). Defaults to False.

  • init_params (torch.Tensor, optional) – Initial parameters. Defaults to None.

  • n_wires (int, optional) – Number of qubits. Defaults to None.

  • wires (Union[int, List[int]], optional) – Which qubit the operation is applied to. Defaults to None.

Methods

forward(q_device: QuantumDevice, wires=None, params=None, inverse=None)[source]#

Apply the operator to the quantum device states.

Parameters:
  • q_device (torchquantum.QuantumDevice) – Quantum Device that the operator is applied to.

  • wires (Union[int, List[int]]) – Qubits that the operator is applied to.

  • params (torch.Tensor) – Parameters of the operator

  • inverse (bool) – Whether inverse the unitary matrix of the operator.

Returns:

set_wires(wires)[source]#

Set which qubits the operator is applied to.

Parameters:

wires (Union[int, List[int]]) – Qubits the operator is applied to.

Returns: None.

Attributes

eigvals#

The eigenvalues of the unitary matrix of the operator.

Returns: Eigenvalues.

matrix#

The unitary matrix of the operator.

name#

String for the name of the operator.

training: bool#