quairkit.operator.gate.custom¶
The source file of the oracle class and the control oracle class.
-
class quairkit.operator.gate.custom.Oracle(oracle, system_idx, acted_system_dim=
2, gate_info=None)¶ An oracle as a gate.
- Parameters:¶
- oracle : Tensor¶
Unitary oracle to be implemented.
- system_idx : List[int] | int¶
Indices of the systems on which the gates are applied.
- acted_system_dim : List[int] | int¶
dimension of systems that this gate acts on. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to be qubit case.
Note
The forward function of this class will not create a new instance of state.
- property info : OperatorInfoType¶
Information of this gate.
-
class quairkit.operator.gate.custom.ControlOracle(oracle, system_idx, index, acted_system_dim=
2, gate_info=None)¶ A controlled oracle as a gate.
- Parameters:¶
- oracle : Tensor¶
Unitary oracle to be implemented.
- system_idx : List[int | List[int]]¶
Indices of the systems on which the gates are applied. The first element in the list is the control system, represented by a int or a list of ints, and the remaining elements represent the oracle system.
- index : int¶
control index that activates the matrix.
- acted_system_dim : List[int] | int¶
dimension of systems that this gate acts on. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to be qubit case.
- gate_info : Dict | None¶
information of this gate that will be placed into the gate history or plotted by a Circuit. Defaults to
None.
Note
The forward function of this class will not create a new instance of state.
- property info : OperatorInfoType¶
Information of this gate.
-
class quairkit.operator.gate.custom.ParamOracle(generator, system_idx, param=
None, num_acted_param=1, acted_system_dim=2, gate_info=None, support_batch=True)¶ An parameterized oracle as a gate
- Parameters:¶
- generator : Callable[[Tensor], Tensor]¶
function that generates the oracle.
- system_idx : List[int] | int¶
indices of the system on which this gate acts on.
- param : Tensor | float | List[float]¶
input parameters of quantum parameterized gates. Defaults to
Nonei.e. randomized.- num_acted_param : int¶
the number of parameters required for a single operation.
- acted_system_dim : List[int] | int¶
dimension of systems that this gate acts on. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to be qubit case.
- gate_info : Dict¶
information of this gate that will be placed into the gate history or plotted by a Circuit. Defaults to
None.- support_batch : bool¶
whether the generator supports batched input. Defaults to
True.
Note
The forward function of this class will not create a new instance of state.
-
class quairkit.operator.gate.custom.ControlParamOracle(generator, system_idx, index, param=
None, num_acted_param=1, acted_system_dim=2, gate_info=None, support_batch=True)¶ An parameterized oracle as a gate
- Parameters:¶
- generator : Callable[[Tensor], Tensor]¶
function that generates the oracle.
- system_idx : List[int] | int¶
Indices of the systems on which the gates are applied. The first element in the list is the control system, represented by a int or a list of ints, and the remaining elements represent the oracle system.
- index : int¶
control index that activates the matrix.
- param : Tensor | float | List[float]¶
input parameters of quantum parameterized gates. Defaults to
Nonei.e. randomized.- num_acted_param : int¶
the number of parameters required for a single operation.
- acted_system_dim : List[int] | int¶
dimension of systems that this gate acts on. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to be qubit case.
- gate_info : Dict¶
information of this gate that will be placed into the gate history or plotted by a Circuit. Defaults to
None.- support_batch : bool¶
whether the generator supports batched input. Defaults to
True.
Note
The forward function of this class will not create a new instance of state.
-
class quairkit.operator.gate.custom.UniversalQudits(system_idx, acted_system_dim, param=
None, param_sharing=False, identity_init=False)¶ A collection of universal qudit gates. One of such a gate requires \(d^2 - 1\) parameters.
- Parameters:¶
- system_idx : Iterable[int] | str | None¶
Indices of the qubits on which the gates are applied. Defaults to the first qubit.
- param : Tensor | float | None¶
Parameters of the gates. Defaults to
None.- param_sharing : bool¶
Whether gates in the same layer share a parameter. Defaults to
False.- acted_system_dim : Iterable[int]¶
dimension of systems that this gate acts on. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to be qubit case.
- identity_init : bool¶
If
True, initialize to identity matrix (all-zero Gell-Mann coefficients). Cannot be used together withparam.
Note
The forward function of this class will not create a new instance of state.
-
class quairkit.operator.gate.custom.ManifoldUniversalQudits(system_idx, acted_system_dim, param=
None, param_sharing=False, identity_init=False)¶ A universal qudit gate optimized on the unitary manifold via Riemannian gradient descent.
Instead of parametrizing unitaries via Gell-Mann generators (exponential map), this gate stores the unitary matrix directly and uses SVD projection (retraction) plus tangent-space gradient projection to stay on the unitary manifold during optimization.
- Parameters:¶
- system_idx : Iterable[int] | str | None¶
Indices of the systems on which the gates are applied.
- acted_system_dim : Iterable[int]¶
Dimension of systems that this gate acts on. Must be a list of system dimensions (cannot be a single int).
- param : Tensor | None¶
Initial unitary matrix(ces). If
None, trainable with random (or identity ifidentity_init) init. Ifnn.Parameter, trainable with fixed init. If plainTensor, not trainable with fixed init. When provided, must be reshapable to[N, B, d, d]whered = prod(acted_system_dim).- param_sharing : bool¶
Whether gates in the same layer share a parameter. Defaults to
False.- identity_init : bool¶
If
True, initialize to identity matrix instead of random. Cannot be used together withparam.
Note
The forward function of this class will not create a new instance of state.
- property matrix : Tensor¶
Return the unitary matrix after SVD projection to U(d).
-
class quairkit.operator.gate.custom.QFT(system_idx, acted_system_dim=
2, is_dagger=False)¶ A collection of quantum Fourier transform (QFT) gates.
- Parameters:¶
- system_idx : List[int | List[int]] | int¶
Indices of the systems on which the gates are applied.
- acted_system_dim : List[int] | int¶
Dimension of systems that this gate acts on. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to qubit case.
- is_dagger : bool¶
Whether initialize this gate as inverse QFT. Defaults to
False.
Note
The forward function of this class will not create a new instance of state.
- property info : OperatorInfoType¶
Information of this gate.
-
class quairkit.operator.gate.custom.Permutation(perm, system_idx, acted_system_dim=
2)¶ permutation matrix as a gate.
- Parameters:¶
- perm : List[int]¶
A list representing the permutation of subsystems. For example, [1, 0, 2] swaps the first two subsystems.
- system_idx : List[int | List[int]]¶
Indices of the systems on which the gates are applied.
- acted_system_dim : List[int] | int¶
dimension of systems that this gate acts on. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to be qubit case.
- property info : OperatorInfoType¶
Information of this gate.