paddle_quantum.gate.base

The source file of the basic class for the quantum gates.

class paddle_quantum.gate.base.Gate(matrix=None, qubits_idx=None, depth=1, gate_info=None, num_qubits=None, check_legality=True, num_acted_qubits=None, backend=None, dtype=None, name_scope=None)

Bases: Channel

Base class for quantum gates.

Parameters:
  • matrix (Tensor) – the matrix of this gate. Defaults to None i.e. not specified.

  • qubits_idx (Iterable[Iterable[int]] | Iterable[int] | int) – indices of the qubits on which this gate acts on. Defaults to None. i.e. list(range(num_acted_qubits)).

  • depth (int) – Number of layers. Defaults to 1.

  • gate_info (dict) – information of this gate that will be placed into the gate history or plotted by a Circuit.

  • None. (prefix name will be snake cased class name. Defaults to) –

  • num_qubits (int) – total number of qubits. Defaults to None.

  • check_legality (bool) – whether check the completeness of the matrix if provided. Defaults to True.

  • num_acted_qubits (int) – the number of qubits that this gate acts on. Defaults to None.

  • backend (Backend) – Backend on which the gates are executed. Defaults to None.

  • dtype (str) – Type of data. Defaults to None.

  • name_scope (str) – Prefix name used by the layer to name parameters. If prefix is “my_layer”, parameter name in

  • "my_layer_0.w_n" (MyLayer can be) –

  • suffix (where "w" is the parameter base name and "n" is an unique) –

  • None (auto-generated. If) –

  • None.

property matrix: Tensor

Unitary matrix of this gate

Raises:

ValueError – Need to specify the matrix form in this Gate instance.

gate_history_generation()

determine self.gate_history

set_gate_info(**kwargs)

the interface to set self.gate_info

Parameters:

kwargs (Any) – parameters to set self.gate_info

display_in_circuit(ax, x)

The display function called by circuit instance when plotting.

Parameters:
  • ax (Axes) – the matplotlib.axes.Axes instance

  • x (float) – the start horizontal position

Returns:

the total width occupied

Return type:

float

Note

Users could overload this function for custom display.

class paddle_quantum.gate.base.ParamGate(generator, param=None, depth=1, num_acted_param=1, param_sharing=False, qubits_idx=None, gate_info=None, num_qubits=None, check_legality=True, num_acted_qubits=None, backend=None, dtype=None, name_scope=None)

Bases: Gate

Base class for quantum parameterized gates.

Parameters:
  • generator (Callable[[Tensor], Tensor]) – function that generates the unitary matrix of this gate.

  • param (Tensor | float | List[float]) – input parameters of quantum parameterized gates. Defaults to None i.e. randomized.

  • qubits_idx (Iterable[Iterable[int]] | Iterable[int] | int) – indices of the qubits on which this gate acts on. Defaults to None. i.e. list(range(num_acted_qubits)).

  • depth (int) – number of layers. Defaults to 1.

  • num_acted_param (int) – the number of parameters required for a single operation.

  • param_sharing (bool) – whether all operations are shared by the same parameter set.

  • gate_info (dict) – information of this gate that will be placed into the gate history or plotted by a Circuit. Defaults to None.

  • num_qubits (int) – total number of qubits. Defaults to None.

  • check_legality (bool) – whether check the completeness of the matrix if provided. Defaults to True.

  • num_acted_qubits (int) – the number of qubits that this gate acts on. Defaults to None.

  • backend (Backend) – Backend on which the gates are executed. Defaults to None.

  • dtype (str) – Type of data. Defaults to None.

  • name_scope (str) – Prefix name used by the layer to name parameters. If prefix is “my_layer”, parameter name in

  • "my_layer_0.w_n" (MyLayer can be) –

  • suffix (where "w" is the parameter base name and "n" is an unique) –

  • None (auto-generated. If) –

  • None. (prefix name will be snake cased class name. Defaults to) –

theta_generation(param, param_shape)

determine self.theta, and create parameter if necessary

Parameters:
  • param (Tensor | float | List[float]) – input theta

  • param_shape (List[int]) – shape for theta

Note

In the following cases param will be transformed to a parameter:
  • param is None

In the following cases param will be added to the parameter list:
  • param is a ParamBase

In the following cases param will keep unchanged:
  • param is a Tensor but not a ParamBase

  • param is a float or a list of floats

gate_history_generation()

determine self.gate_history when gate is parameterized

display_in_circuit(ax, x)

The display function called by circuit instance when plotting.

Parameters:
  • ax (Axes) – the matplotlib.axes.Axes instance

  • x (float) – the start horizontal position

Returns:

the total width occupied

Return type:

float

Note

Users could overload this function for custom display.