operation#
Base classes for quantum operations
Classes
|
A base class for quantum channels. |
|
A base class for quantum gates. |
|
A base class for quasiprobability-decomposition gates. |
|
A base class for quantum layers. |
|
A operation for denoting a QPD measurement location. |
|
A base class for quantum operations. |
- class Channel(inputs: Any = None, name: str | None = None, nqubit: int = 1, wires: int | list[int] | None = None, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
OperationA base class for quantum channels.
- Parameters:
inputs (Any) – The parameter of the channel. Default:
Nonename (str | None) – The name of the channel. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonetsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- property prob#
The error probability.
- class Gate(name: str | None = None, nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
OperationA base class for quantum gates.
- Parameters:
name (str | None) – The name of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- forward(x: Tensor | MatrixProductState | DistributedQubitState) Tensor | MatrixProductState | DistributedQubitState[source]#
Perform a forward pass.
- get_mpo() tuple[list[Tensor], int][source]#
Convert gate to MPO form with identities at empty sites.
Note
If sites are not adjacent, insert identities in the middle, i.e.,
>>> | | | | | >>> --A---x---B-- -> --A---I---B-- >>> | | | | |
where
>>> a >>> | >>> --i--I--j-- >>> | >>> b
means \(\delta_{i,j} \delta_{a,b}\)
- op_den_mat_base(x: Tensor, matrix: Tensor) Tensor[source]#
Perform a forward pass of a gate for density matrices.
- op_den_mat_control(x: Tensor, matrix: Tensor) Tensor[source]#
Perform a forward pass of a controlled gate for density matrices.
- op_dist_state(x: DistributedQubitState) DistributedQubitState[source]#
Perform a forward pass of a gate for a distributed state vector.
- op_mps(mps: MatrixProductState) MatrixProductState[source]#
Perform a forward pass for the
MatrixProductState.
- op_state_base(x: Tensor, matrix: Tensor) Tensor[source]#
Perform a forward pass of a gate for state vectors.
- class GateQPD(bases: nn.ModuleList[nn.ModuleList[nn.Sequential]], coeffs: list[float], label: int | None = None, name: str | None = None, nqubit: int = 1, wires: int | list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
GateA base class for quasiprobability-decomposition gates.
- Parameters:
bases (nn.ModuleList[nn.ModuleList[nn.Sequential]]) – The probabilistic basis operations for the decomposition. A nested structure where: - bases[i] is the i-th term of the QPD (corresponding to coeffs[i]). - bases[i][j] is the nn.Sequential operations applied to the j-th qubit.
coeffs (list[float]) – The coefficients for quasiprobability representation.
label (int | None) – The label of the gate. Default:
Nonename (str | None) – The name of the quantum operation. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class Layer(name: str | None = None, nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
OperationA base class for quantum layers.
- Parameters:
name (str | None) – The name of the layer. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | list[list[int]] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- forward(x: Tensor | MatrixProductState | DistributedQubitState) Tensor | MatrixProductState | DistributedQubitState[source]#
Perform a forward pass.
- class MeasureQPD(nqubit: int = 1, wires: int | list[int] | None = None)[source]#
Bases:
OperationA operation for denoting a QPD measurement location.
- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
None
- class Operation(name: str | None = None, nqubit: int = 1, wires: int | list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
ModuleA base class for quantum operations.
- Parameters:
name (str | None) – The name of the quantum operation. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False