layer#
Quantum layers
Classes
|
A layer of CNOT gates. |
|
A layer of CNOT gates in a cyclic way. |
|
A base class for layers of two-qubit gates. |
|
A layer of Hadamard gates. |
|
A |
|
A base class for layers of single-qubit gates with parameters. |
|
A layer of Rx gates. |
|
A layer of Ry gates. |
|
A layer of Rz gates. |
|
A base class for layers of single-qubit gates. |
|
A layer of U3 gates. |
|
A layer of Pauli-X gates. |
|
A layer of Pauli-Y gates. |
|
A layer of Pauli-Z gates. |
- class CnotLayer(nqubit: int = 2, wires: list[list[int]] | None = None, name: str = 'CnotLayer', den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
DoubleLayerA layer of CNOT gates.
- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[list[int]] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonename (str) – The name of the layer. Default:
'CnotLayer'den_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 CnotRing(nqubit: int = 2, minmax: list[int] | None = None, step: int = 1, reverse: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
CnotLayerA layer of CNOT gates in a cyclic way.
- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
minmax (list[int] | None) – The minimum and maximum indices of qubits that the quantum operation acts on. Default:
Nonestep (int) – The distance between the control and target qubits of each CNOT gate. Default: 1
reverse (bool) – Whether the CNOT gates are applied from the maximum to the minimum index or vice versa. 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
- class DoubleLayer(name: str | None = None, nqubit: int = 2, wires: list[list[int]] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
LayerA base class for layers of two-qubit gates.
- Parameters:
name (str | None) – The name of the layer. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (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
- class HLayer(nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleLayerA layer of Hadamard gates.
- Parameters:
nqubit (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
- class Observable(nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, basis: str = 'z', den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleLayerA
Layerthat represents an observable which can be expressed by Pauli string.- Parameters:
nqubit (int) – The number of qubits in the circuit. Default: 1
wires (int | list[int] | list[list[int]] | None) – The wires to measure. Default:
None(which means all wires are measured)basis (str) – The measurement basis for each wire. It can be
'x','y', or'z'. If only one character is given, it is repeated for all wires. Default:'z'den_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 ParametricSingleLayer(name: str | None = None, nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = True)[source]#
Bases:
SingleLayerA base class for layers of single-qubit gates with parameters.
- 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:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:True(which meansnn.Parameter)
- inverse() ParametricSingleLayer[source]#
Get the inversed layer.
- class RxLayer(nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, inputs: Any = None, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = True)[source]#
Bases:
ParametricSingleLayerA layer of Rx gates.
- Parameters:
nqubit (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:
Noneinputs (Any) – The parameters of the layer. 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:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:True(which meansnn.Parameter)
- class RyLayer(nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, inputs: Any = None, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = True)[source]#
Bases:
ParametricSingleLayerA layer of Ry gates.
- Parameters:
nqubit (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:
Noneinputs (Any) – The parameters of the layer. 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:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:True(which meansnn.Parameter)
- class RzLayer(nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, inputs: Any = None, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = True)[source]#
Bases:
ParametricSingleLayerA layer of Rz gates.
- Parameters:
nqubit (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:
Noneinputs (Any) – The parameters of the layer. 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:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:True(which meansnn.Parameter)
- class SingleLayer(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:
LayerA base class for layers of single-qubit gates.
- 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
- class U3Layer(nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, inputs: Any = None, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = True)[source]#
Bases:
ParametricSingleLayerA layer of U3 gates.
- Parameters:
nqubit (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:
Noneinputs (Any) – The parameters of the layer. 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:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:True(which meansnn.Parameter)
- class XLayer(nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleLayerA layer of Pauli-X gates.
- Parameters:
nqubit (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
- class YLayer(nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleLayerA layer of Pauli-Y gates.
- Parameters:
nqubit (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
- class ZLayer(nqubit: int = 1, wires: int | list[int] | list[list[int]] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleLayerA layer of Pauli-Z gates.
- Parameters:
nqubit (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