mindquantum.core.gates.BasicGate

View Source On Gitee
class mindquantum.core.gates.BasicGate(name, n_qubits, obj_qubits=None, ctrl_qubits=None)[source]

BasicGate is the base class of all gates.

Parameters
  • name (str) – the name of this gate.

  • n_qubits (int) – how many qubits is this gate.

  • obj_qubits (int, list[int]) – Specific which qubits the gate act on.

  • ctrl_qubits (int, list[int]) – Specific the control qubits. Default, None.

property acted

Check whether this gate is acted on qubits.

define_projectq_gate()[source]

Define the corresponded projectq gate.

abstract get_cpp_obj()[source]

Get the underlying C++ object.

hermitian()[source]

Return the hermitian gate of this gate.

matrix(*args)[source]

Matrix of the gate.

no_grad()[source]

Set this gate to not calculate gradient.

on(obj_qubits, ctrl_qubits=None)[source]

Define which qubit the gate act on and the control qubit.

Note

In this framework, the qubit that the gate act on is specified first, even for control gate, e.g. CNOT, the second arg is control qubits.

Parameters
  • obj_qubits (int, list[int]) – Specific which qubits the gate act on.

  • ctrl_qubits (int, list[int]) – Specific the control qubits. Default, None.

Returns

Gate, Return a new gate.

Examples

>>> from mindquantum.core.gates import X
>>> x = X.on(1)
>>> x.obj_qubits
[1]
>>> x.ctrl_qubits
[]
>>> x = X.on(2, [0, 1])
>>> x.ctrl_qubits
[0, 1]
property parameterized

Check whether this gate is a parameterized gate.

requires_grad()[source]

Set this gate to calculate gradient.

In default, a parameterized gate will requires grad when you init it.