qandle.operators module
- class qandle.operators.CNOT(control: int, target: int)[source]
Bases:
UnbuiltOperator
CNOT gate.
- build(num_qubits, **kwargs) BuiltCNOT [source]
Builds the operator, i.e. converts it to a torch.nn.Module.
- to_qasm() QasmRepresentation [source]
Returns the OpenQASM2 representation of the operator.
- class qandle.operators.CZ(control: int, target: int)[source]
Bases:
UnbuiltOperator
CZ gate.
- build(num_qubits, **kwargs) BuiltCZ [source]
Builds the operator, i.e. converts it to a torch.nn.Module.
- to_qasm() QasmRepresentation [source]
Returns the OpenQASM2 representation of the operator.
- qandle.operators.CustomGate
Define a custom single qubit gate. This module is always built, and therefore might have a big memory footprint.
- Attributes:
- qubitint
The index of the qubit this gate operates on.
- matrixtorch.Tensor
The matrix representation of the gate. Must be a 2x2 unitary matrix.
- num_qubitsint
The number of qubits in the circuit.
- self_descriptionstr
The description of the gate. Default is “U”. This name will be used in the string representation of the gate and in the OpenQASM2 representation.
- class qandle.operators.Operator[source]
Bases:
ABC
Everything that can be applied to a state.
- named = False
- abstract to_qasm() QasmRepresentation [source]
Returns the OpenQASM2 representation of the operator.
- class qandle.operators.RX(qubit: int, theta: float | Tensor | None = None, name: str | None = None, **kwargs)[source]
Bases:
UnbuiltParametrizedOperator
Parametrized RX gate, i.e. a rotation around the x-axis of the Bloch sphere.
This class represents a parametrized RX gate in a quantum circuit.
Used by
qandle.qcircuit.QCircuit
to build the circuit.- Attributes:
- qubitint
The index of the qubit this gate operates on.
- thetafloat, torch.Tensor, optional
The parameter of the RX gate, by default None. If None, a random parameter \([0, 1]\) is chosen.
- namestr, optional
The name of the operator, by default None. If None, the operator is not named and does not accept named inputs.
- remappingCallable, optional
A function that remaps the parameter theta, by default config.DEFAULT_MAPPING. To disable remapping, pass
qw_map.none
orlambda x: x
.
- class qandle.operators.RY(qubit: int, theta: float | Tensor | None = None, name: str | None = None, **kwargs)[source]
Bases:
UnbuiltParametrizedOperator
Parametrized RY gate, i.e. a rotation around the y-axis of the Bloch sphere.
This class represents a parametrized RY gate in a quantum circuit.
Used by
qandle.qcircuit.QCircuit
to build the circuit.- Attributes
- qubitint
The index of the qubit this gate operates on.
- thetafloat, torch.Tensor, optional
The parameter of the RY gate, by default None. If None, a random parameter \([0, 1]\) is chosen.
- namestr, optional
The name of the operator, by default None. If None, the operator is not named and does not accept named inputs.
- remappingCallable, optional
A function that remaps the parameter theta, by default config.DEFAULT_MAPPING. To disable remapping, pass
qw_map.none
orlambda x: x
.
- class qandle.operators.RZ(qubit: int, theta: float | Tensor | None = None, name: str | None = None, **kwargs)[source]
Bases:
UnbuiltParametrizedOperator
Parametrized RZ gate, i.e. a rotation around the z-axis of the Bloch sphere.
This class represents a parametrized RZ gate in a quantum circuit.
Used by
qandle.qcircuit.QCircuit
to build the circuit.- Attributes
- qubitint
The index of the qubit this gate operates on.
- thetafloat, torch.Tensor, optional
The parameter of the RZ gate, by default None. If None, a random parameter \([0, 1]\) is chosen.
- namestr, optional
The name of the operator, by default None. If None, the operator is not named and does not accept named inputs.
- remappingCallable, optional
A function that remaps the parameter theta, by default config.DEFAULT_MAPPING. To disable remapping, pass
qw_map.none
orlambda x: x
.
- class qandle.operators.Reset(qubit: int)[source]
Bases:
UnbuiltOperator
- build(num_qubits, **kwargs) BuiltReset [source]
Builds the operator, i.e. converts it to a torch.nn.Module.
- to_qasm() QasmRepresentation [source]
Returns the OpenQASM2 representation of the operator.