Hadamard#

class torchquantum.operator.Hadamard(has_params: bool = False, trainable: bool = False, init_params=None, n_wires=None, wires=None, inverse=False)[source]#

Bases: Observable

Class for Hadamard Gate.

__init__(has_params: bool = False, trainable: bool = False, init_params=None, n_wires=None, wires=None, inverse=False)#

Init function of the Observable class

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

diagonalizing_gates()[source]#

The diagonalizing gates when perform measurements.

Returns: None.

static func(q_device: None, wires: Union[List[int], int], params: Optional[Tensor] = None, n_wires: Optional[int] = None, static: bool = False, parent_graph=None, inverse: bool = False, comp_method: str = 'bmm')#

Perform the hadamard 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.

Attributes

eigvals = tensor([ 1.+0.j, -1.+0.j])#
matrix = tensor([[ 0.7071+0.j,  0.7071+0.j],         [ 0.7071+0.j, -0.7071+0.j]])#
num_params = 0#
num_wires = 1#
op_name = 'hadamard'#
training: bool#