QubitUnitaryFast#
- class torchquantum.operator.QubitUnitaryFast(has_params: bool = False, trainable: bool = False, init_params=None, n_wires=None, wires=None)[source]#
Bases:
Operation
Class for fast implementation of controlled Qubit Unitary gate.
- __init__(has_params: bool = False, trainable: bool = False, init_params=None, n_wires=None, wires=None)[source]#
_summary_
- 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
- build_params(trainable)[source]#
Build parameters.
- Parameters:
trainable (bool) – Whether the parameters are trainable.
- Returns:
Built parameters.
- Return type:
torch.Tensor
- classmethod from_controlled_operation(op, c_wires, t_wires, trainable)[source]#
- Parameters:
op – the operation
c_wires – controlled wires, will only be a set such as 1, [2,3]
t_wires – can be a list of list of wires, multiple sets
[[1 –
2] –
[3 –
4]] –
trainable –
- static func(q_device, wires, params=None, n_wires=None, static=False, parent_graph=None, inverse=False, comp_method='bmm')#
Perform the qubitunitaryfast gate.
- Parameters:
q_device (tq.QuantumDevice) – The QuantumDevice.
wires (Union[List[int], int]) – Which qubit(s) to apply the gate.
params (torch.Tensor, optional) – Parameters (if any) of the gate. Default to None.
n_wires (int, optional) – Number of qubits the gate is applied to. Default to None.
static (bool, optional) – Whether use static mode computation. Default to False.
parent_graph (tq.QuantumGraph, optional) – Parent QuantumGraph of current operation. Default to None.
inverse (bool, optional) – Whether inverse the gate. Default to False.
comp_method (bool, optional) – Use ‘bmm’ or ‘einsum’ method to perform
'bmm'. (matrix vector multiplication. Default to) –
- Returns:
None.
- reset_params(init_params=None)[source]#
Reset parameters.
- Parameters:
init_params (torch.Tensor, optional) – Input the initialization parameters. Defaults to None.
Attributes
- num_params = -1#
- num_wires = -1#
- op_name = 'qubitunitaryfast'#