qilisdk.digital.gates

Attributes

TBasicGate

Classes

Gate

Represents a quantum gate that can be used in quantum circuits.

BasicGate

Represents a quantum gate that can be used in quantum circuits.

Modified

Represents a quantum gate that can be used in quantum circuits.

Controlled

Represents a quantum gate that can be used in quantum circuits.

Adjoint

Represents the adjoint (conjugate transpose) of a unitary gate.

Exponential

Represents the exponential of a unitary gate.

M

Measurement operation on a qubit. The measurement is performed in the computational basis and the

I

The Identity gate.

X

The Pauli-X gate.

Y

The Pauli-Y gate.

Z

The Pauli-Z gate.

H

The Hadamard gate.

S

Represents the S gate, which induces a pi/2 phase.

T

Represents the T gate, which induces a pi/4 phase.

RX

Represents a theta angle rotation around the X-axis (polar) in the Bloch sphere.

RY

Represents a theta angle rotation around the Y-axis (polar) in the Bloch sphere.

RZ

Represents a phi angle rotation around the Z-axis (azimuthal) in the Bloch sphere.

U1

Represents the U1 gate defined by an azimuthal angle phi.

U2

Represents the U2 gate defined by the angles phi and gamma.

U3

Represents the U3 gate defined by the angles theta, phi and gamma.

CNOT

Represents the CNOT gate.

CZ

Represents the CZ gate.

SWAP

The SWAP gate.

Module Contents

TBasicGate[source]
class Gate[source]

Bases: qilisdk.core.parameterizable.Parameterizable, abc.ABC

Represents a quantum gate that can be used in quantum circuits.

PARAMETER_NAMES: ClassVar[list[str]] = [][source]
property name: str[source]
Abstractmethod:

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

property matrix: numpy.ndarray[source]
Abstractmethod:

Retrieve the matrix of the gate.

Raises:

GateHasNoMatrixError – If gate has no matrix.

Returns:

The matrix of the gate.

Return type:

np.ndarray

property control_qubits: tuple[int, Ellipsis][source]

Retrieve the indices of the control qubits.

Returns:

A tuple containing the indices of the control qubits.

Return type:

tuple[int, …]

property target_qubits: tuple[int, Ellipsis][source]

Retrieve the indices of the target qubits.

Returns:

A tuple containing the indices of the target qubits.

Return type:

tuple[int, …]

property qubits: tuple[int, Ellipsis][source]

Retrieve all qubits associated with the gate, including both control and target qubits.

Returns:

A tuple of all qubit indices on which the gate operates.

Return type:

tuple[int, …]

property nqubits: int[source]

Retrieve the number of qubits the gate acts upon.

Returns:

The number of qubits for this gate.

Return type:

int

property nparameters: int[source]

Retrieve the number of parameters for the gate.

Returns:

The count of parameters needed by the gate.

Return type:

int

property is_parameterized: bool[source]

Determine whether the gate requires parameters.

Returns:

True if the gate is parameterized; otherwise, False.

Return type:

bool

get_parameters(where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) dict[str, float][source]

Retrieve a mapping of parameter names to their corresponding values.

Parameters:

where (Callable[[Parameter], bool] | None) – Optional predicate used to filter parameters.

Returns:

A dictionary mapping each parameter name to its numeric value.

Return type:

dict[str, float]

get_parameter_names(where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) list[str][source]

Retrieve the symbolic names of the gate’s parameters.

Parameters:

where (Callable[[Parameter], bool] | None) – Optional predicate used to filter parameters.

Returns:

A list containing the names of the parameters.

Return type:

list[str]

get_parameter_values(where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) list[float][source]

Retrieve the numerical values assigned to the gate’s parameters.

Parameters:

where (Callable[[Parameter], bool] | None) – Optional predicate used to filter parameters.

Returns:

A list containing the parameter values.

Return type:

list[float]

set_parameters(parameters: dict[str, float]) None[source]

Set the parameters for the gate using a dictionary mapping names to values.

Parameters:

parameters (dict[str, float]) – A dictionary where keys are parameter names and values are the new parameter values.

Raises:
set_parameter_values(values: list[float], where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) None[source]

Set the numerical values for the gate’s parameters.

Parameters:
  • values (list[float]) – A list containing new parameter values.

  • where (Callable[[Parameter], bool] | None) – Optional predicate selecting parameters to update.

Raises:
get_parameter_bounds(where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) dict[str, tuple[float, float]][source]

Return parameter bounds, optionally filtered by predicate.

set_parameter_bounds(ranges: dict[str, tuple[float, float]]) None[source]

Update the allowable ranges for the specified parameters.

Parameters:

ranges (dict[str, tuple[float, float]]) – Mapping from parameter label to (lower, upper) bounds.

Raises:

ValueError – If an unknown parameter label is provided.

class BasicGate(target_qubits: tuple[int, Ellipsis], parameters: dict[str, qilisdk.core.variables.Parameter] | None = None, parameter_transforms: dict[str, qilisdk.core.variables.Term] | None = None)[source]

Bases: Gate

Represents a quantum gate that can be used in quantum circuits.

Build a basic gate.

Parameters:
  • target_qubits (tuple[int, ]) – Qubit indices the gate acts on. Duplicate indices are rejected.

  • parameters (dict[str, Parameter] | None) – Optional parameter objects keyed by label for parameterized gates.

  • parameter_transforms (dict[str, Term] | None) – Optional symbolic transforms keyed by parameter name.

Raises:
  • ValueError – if duplicate target qubits are found.

  • ValueError – if any parameter transform is not a parameterized term.

  • InvalidParameterNameError – if any parameter mentioned in parameter_transforms is not in parameters.

property matrix: numpy.ndarray[source]

Retrieve the matrix of the gate.

Raises:

GateHasNoMatrixError – If gate has no matrix.

Returns:

The matrix of the gate.

Return type:

np.ndarray

property target_qubits: tuple[int, Ellipsis][source]

Retrieve the indices of the target qubits.

Returns:

A tuple containing the indices of the target qubits.

Return type:

tuple[int, …]

set_parameters(parameters: dict[str, float]) None[source]

Set the parameters for the gate using a dictionary mapping names to values.

Parameters:

parameters (dict[str, float]) – A dictionary where keys are parameter names and values are the new parameter values.

Raises:
set_parameter_values(values: list[float], where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) None[source]

Set the numerical values for the gate’s parameters.

Parameters:
  • values (list[float]) – A list containing new parameter values.

  • where (Callable[[Parameter], bool] | None) – Optional predicate selecting parameters to update.

Raises:
set_parameter_bounds(ranges: dict[str, tuple[float, float]]) None[source]

Update the allowable ranges for the specified parameters.

Parameters:

ranges (dict[str, tuple[float, float]]) – Mapping from parameter label to (lower, upper) bounds.

Raises:

ValueError – If an unknown parameter label is provided.

controlled(*control_qubits: int) Controlled[Self][source]

Creates a controlled version of this unitary gate.

This method returns a new instance of a Controlled gate where the provided qubits serve as the control qubits and the current unitary gate is used as the target. The resulting gate operates on both the control and target qubits.

Parameters:

*control_qubits (int) – One or more integer indices specifying the control qubits.

Returns:

A new Controlled gate instance that wraps this unitary gate with the specified control qubits.

Return type:

Controlled

adjoint() Adjoint[Self][source]

Returns the adjoint (conjugate transpose) of this unitary gate.

This method constructs and returns a new gate whose matrix is the conjugate transpose of the current gate’s matrix. The adjoint (or Hermitian conjugate) is commonly used to reverse the effect of a unitary operation.

Returns:

A new Adjoint gate instance representing the adjoint of this gate.

Return type:

Adjoint

exponential() Exponential[Self][source]

Returns the exponential of this unitary gate.

This method computes the matrix exponential of the current gate’s matrix, resulting in a new gate. The matrix exponential is useful for representing continuous time evolution in quantum systems and appears in various quantum mechanics and quantum computing applications.

Returns:

A new Exponential gate instance whose matrix is the matrix exponential of the current gate’s matrix.

Return type:

Exponential

class Modified(basic_gate: TBasicGate)[source]

Bases: Gate, Generic[TBasicGate]

Represents a quantum gate that can be used in quantum circuits.

property basic_gate: TBasicGate[source]
property matrix: numpy.ndarray[source]

Retrieve the matrix of the gate.

Raises:

GateHasNoMatrixError – If gate has no matrix.

Returns:

The matrix of the gate.

Return type:

np.ndarray

property target_qubits: tuple[int, Ellipsis][source]

Retrieve the indices of the target qubits.

Returns:

A tuple containing the indices of the target qubits.

Return type:

tuple[int, …]

property nparameters: int[source]

Retrieve the number of parameters for the gate.

Returns:

The count of parameters needed by the gate.

Return type:

int

property is_parameterized: bool[source]

Determine whether the gate requires parameters.

Returns:

True if the gate is parameterized; otherwise, False.

Return type:

bool

get_parameters(where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) dict[str, float][source]

Retrieve a mapping of parameter names to their corresponding values.

Parameters:

where (Callable[[Parameter], bool] | None) – Optional predicate used to filter parameters.

Returns:

A dictionary mapping each parameter name to its numeric value.

Return type:

dict[str, float]

get_parameter_names(where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) list[str][source]

Retrieve the symbolic names of the gate’s parameters.

Parameters:

where (Callable[[Parameter], bool] | None) – Optional predicate used to filter parameters.

Returns:

A list containing the names of the parameters.

Return type:

list[str]

get_parameter_values(where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) list[float][source]

Retrieve the numerical values assigned to the gate’s parameters.

Parameters:

where (Callable[[Parameter], bool] | None) – Optional predicate used to filter parameters.

Returns:

A list containing the parameter values.

Return type:

list[float]

set_parameters(parameters: dict[str, float]) None[source]

Set the parameters for the gate using a dictionary mapping names to values.

Parameters:

parameters (dict[str, float]) – A dictionary where keys are parameter names and values are the new parameter values.

Raises:
set_parameter_values(values: list[float], where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) None[source]

Set the numerical values for the gate’s parameters.

Parameters:
  • values (list[float]) – A list containing new parameter values.

  • where (Callable[[Parameter], bool] | None) – Optional predicate selecting parameters to update.

Raises:
get_parameter_bounds(where: collections.abc.Callable[[qilisdk.core.variables.Parameter], bool] | None = None) dict[str, tuple[float, float]][source]

Return parameter bounds, optionally filtered by predicate.

set_parameter_bounds(ranges: dict[str, tuple[float, float]]) None[source]

Update the allowable ranges for the specified parameters.

Parameters:

ranges (dict[str, tuple[float, float]]) – Mapping from parameter label to (lower, upper) bounds.

Raises:

ValueError – If an unknown parameter label is provided.

is_modified_from(gate_type: type[TBasicGate]) bool[source]
class Controlled(*control_qubits: int, basic_gate: TBasicGate | Controlled[TBasicGate])[source]

Bases: Modified[TBasicGate]

Represents a quantum gate that can be used in quantum circuits.

property control_qubits: tuple[int, Ellipsis][source]

Retrieve the indices of the control qubits.

Returns:

A tuple containing the indices of the control qubits.

Return type:

tuple[int, …]

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

class Adjoint(basic_gate: TBasicGate)[source]

Bases: Modified[TBasicGate]

Represents the adjoint (conjugate transpose) of a unitary gate.

property name: str[source]

Get the name of the adjoint gate.

The name is constructed by appending an adjoint symbol (†) to the name of the underlying gate. For example, if the underlying gate’s name is “X”, this property returns “X†”.

Returns:

The name of the adjoint gate.

Return type:

str

class Exponential(basic_gate: TBasicGate)[source]

Bases: Modified[TBasicGate]

Represents the exponential of a unitary gate. The matrix of this gate is computed as the matrix exponential (e^(gate.matrix)) of the underlying gate’s matrix.

property name: str[source]

Get the name of the exponential gate.

The name is constructed by prepending the underlying gate’s name within “e^”. For example, if the underlying gate’s name is “X”, the exponential gate’s name is “e^X”.

Returns:

The generated name of the exponential gate.

Return type:

str

class M(*qubits: int)[source]

Bases: Gate

Measurement operation on a qubit. The measurement is performed in the computational basis and the result is stored in a classical bit with the same label as the measured qubit.

Initialize a measurement operation.

Parameters:

qubits (int) – One or more qubit indices to measure.

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

property matrix: numpy.ndarray[source]

Retrieve the matrix of the gate.

Raises:

GateHasNoMatrixError – If gate has no matrix.

Returns:

The matrix of the gate.

Return type:

np.ndarray

property target_qubits: tuple[int, Ellipsis][source]

Retrieve the indices of the target qubits.

Returns:

A tuple containing the indices of the target qubits.

Return type:

tuple[int, …]

class I(qubit: int)[source]

Bases: BasicGate

The Identity gate.

The associated matrix is:

[[1, 0],
[0, 1]]

Initialize an identity gate.

Parameters:

qubit (int) – The target qubit index for the identity gate.

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

class X(qubit: int)[source]

Bases: BasicGate

The Pauli-X gate.

The associated matrix is:

[[0, 1],
[1, 0]]

This is a pi radians rotation around the X-axis in the Bloch sphere.

Initialize a Pauli-X gate.

Parameters:

qubit (int) – The target qubit index for the X gate.

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

class Y(qubit: int)[source]

Bases: BasicGate

The Pauli-Y gate.

The associated matrix is:

[[ 0, -i ],
 [ i,  0 ]]

This is a pi radians rotation around the Y-axis in the Bloch sphere.

Initialize a Pauli-Y gate.

Parameters:

qubit (int) – The target qubit index for the Y gate.

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

class Z(qubit: int)[source]

Bases: BasicGate

The Pauli-Z gate.

The associated matrix is:

[[1, 0],
[0, -1]]

This is a pi radians rotation around the Z-axis in the Bloch sphere.

Initialize a Pauli-Z gate.

Parameters:

qubit (int) – The target qubit index for the Z gate.

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

class H(qubit: int)[source]

Bases: BasicGate

The Hadamard gate.

The associated matrix is:

[[1/sqrt(2),  1/sqrt(2)],
 [1/sqrt(2), -1/sqrt(2)]]

This is a pi radians rotation around the (X+Z)-axis in the Bloch sphere.

Initialize a Hadamard gate.

Parameters:

qubit (int) – The target qubit index for the Hadamard gate.

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

class S(qubit: int)[source]

Bases: BasicGate

Represents the S gate, which induces a pi/2 phase.

The associated matrix is:

[[1, 0],
 [0, i]]

This gate is also known as the square root of Z gate: S**2=Z, or equivalently it is a pi/2 radians rotation around the Z-axis in the Bloch sphere.

Initialize an S gate.

Parameters:

qubit (int) – The target qubit index for the S gate.

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

class T(qubit: int)[source]

Bases: BasicGate

Represents the T gate, which induces a pi/4 phase.

The associated matrix is:

[[1,           0],
 [0, exp(i*pi/4)]]

This gate is also known as the fourth-root of Z gate: T**4=Z, or equivalently it is a pi/4 radians rotation around the Z-axis in the Bloch sphere.

Initialize a T gate.

Parameters:

qubit (int) – The target qubit index for the T gate.

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

class RX(qubit: int, *, theta: float | qilisdk.core.variables.Parameter | qilisdk.core.variables.Term)[source]

Bases: BasicGate

Represents a theta angle rotation around the X-axis (polar) in the Bloch sphere.

The associated matrix is:

[[cos(theta/2),     -i*sin(theta/2)],
 [-i*sin(theta/2),     cos(theta/2)]]
This is an exponential of the Pauli-X operator:

RX(theta) = exp(-i*theta*X/2)

Initialize an RX gate.

Parameters:
PARAMETER_NAMES: ClassVar[list[str]] = ['theta'][source]
property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

property theta: float[source]
class RY(qubit: int, *, theta: float | qilisdk.core.variables.Parameter | qilisdk.core.variables.Term)[source]

Bases: BasicGate

Represents a theta angle rotation around the Y-axis (polar) in the Bloch sphere.

The associated matrix is:

[[cos(theta/2), -sin(theta/2)],
 [sin(theta/2),  cos(theta/2)]]
This is an exponential of the Pauli-Y operator:

RY(theta) = exp(-i*theta*Y/2)

Initialize an RY gate.

Parameters:
PARAMETER_NAMES: ClassVar[list[str]] = ['theta'][source]
property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

property theta: float[source]
class RZ(qubit: int, *, phi: float | qilisdk.core.variables.Parameter | qilisdk.core.variables.Term)[source]

Bases: BasicGate

Represents a phi angle rotation around the Z-axis (azimuthal) in the Bloch sphere.

The associated matrix is:

[[exp(-i*phi/2),              0],
 [0,               exp(i*phi/2)]]
This is an exponential of the Pauli-Z operator:

RZ(phi) = exp(-i*phi*Z/2)

Which is equivalent to the U1 gate plus a global phase:

RZ(phi) = exp(-i*phi/2)U1(phi)

Other unitaries you can get from this one are:
  • RZ(phi=pi) = exp(-i*pi/2) Z = -i Z

  • RZ(phi=pi/2) = exp(-i*pi/4) S

  • RZ(phi=pi/4) = exp(-i*pi/8) T

Initialize an RZ gate.

Parameters:
  • qubit (int) – The target qubit index for the rotation.

  • phi (float | Parameter | Term) – The rotation angle (azimuthal) in radians.

PARAMETER_NAMES: ClassVar[list[str]] = ['phi'][source]
property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

property phi: float[source]
class U1(qubit: int, *, phi: float | qilisdk.core.variables.Parameter | qilisdk.core.variables.Term)[source]

Bases: BasicGate

Represents the U1 gate defined by an azimuthal angle phi.

The associated matrix is:

[[1,            0],
 [0, exp(i*phi)]]
Which is equivalent to the RZ gate plus a global phase:

U1(phi) = exp(i*phi/2)RZ(phi)

Other unitaries you can get from this one are:
  • U1(phi=np.pi) = Z

  • U1(phi=np.pi/2) = S

  • U1(phi=np.pi/4) = T

Initialize a U1 gate.

Parameters:
  • qubit (int) – The target qubit index for the U1 gate.

  • phi (float | Parameter | Term) – The phase to add, or equivalently the rotation angle (azimuthal) in radians.

PARAMETER_NAMES: ClassVar[list[str]] = ['phi'][source]
property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

property phi: float[source]
class U2(qubit: int, *, phi: float | qilisdk.core.variables.Parameter | qilisdk.core.variables.Term, gamma: float | qilisdk.core.variables.Parameter | qilisdk.core.variables.Term)[source]

Bases: BasicGate

Represents the U2 gate defined by the angles phi and gamma.

The associated matrix is:

1/sqrt(2)*[[1,                   -exp(i*gamma)],
           [exp(i*phi),    exp(i*(phi+gamma))]]
Which is equivalent to two azimuthal rotations of phi and gamma, with a pi/2 polar rotation in between:

U2(phi, gamma) = exp(i*(phi+gamma)/2) RZ(phi) RY(pi/2) RZ(gamma)

This is the same matrix of qiskit and pennylane, differing from qibo implementation on a global phase:

U2(phi, gamma) = U2_qiskit/pennylane(phi, gamma) = exp(i*(phi+gamma)/2) U2_qibo(phi, gamma)

Other unitaries you can get from this one are:
  • U2(phi=0, gamma=pi) = H

  • U2(phi=0, gamma=0) = RY(theta=pi/2)

  • U2(phi=-pi/2, gamma=pi/2) = RX(theta=pi/2)

Initialize a U2 gate.

Parameters:
  • qubit (int) – The target qubit index for the U2 gate.

  • phi (float | Parameter | Term) – The first phase parameter, or equivalently the first rotation angle (azimuthal) in radians.

  • gamma (float | Parameter | Term) – The second phase parameter, or equivalently the second rotation angle (azimuthal) in radians.

PARAMETER_NAMES: ClassVar[list[str]] = ['phi', 'gamma'][source]
property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

property phi: float[source]
property gamma: float[source]
class U3(qubit: int, *, theta: float | qilisdk.core.variables.Parameter | qilisdk.core.variables.Term, phi: float | qilisdk.core.variables.Parameter | qilisdk.core.variables.Term, gamma: float | qilisdk.core.variables.Parameter | qilisdk.core.variables.Term)[source]

Bases: BasicGate

Represents the U3 gate defined by the angles theta, phi and gamma.

The associated matrix is:

[[cos(theta/2), -exp(i*gamma/2*sin(theta/2))],
 [exp(i*phi/2)*sin(theta/2),    exp(i*(phi+gamma))*cos(theta/2)]]
Which is equivalent to two azimuthal rotations of phi and gamma, with a ‘theta’ polar rotation in between:

U3(theta, phi, gamma) = exp(i*(phi+gamma)/2) RZ(phi) RY(theta) RZ(gamma)

This is the same matrix of qiskit and pennylane, differing from QASM and qibo implementation on a global phase:

U3(theta, phi, gamma) = U3_qiskit/pennylane(theta, phi, gamma) = exp(-i*(phi+gamma)/2) U3_QASM/qibo(theta, phi, gamma)

Other unitaries you can get from this one are:
  • U3(theta=pi/2, phi, gamma) = U2(phi, gamma)

  • U3(theta=0, phi=0, gamma) = U1(gamma) and U3(theta=0, phi, gamma=0) = U1(phi)

  • U3(theta, phi=0, gamma=0) = RY(theta)

  • U3(theta, phi=-pi/2, gamma=pi/2) = RX(theta)

Initialize a U3 gate.

Parameters:
  • qubit (int) – The target qubit index for the U3 gate.

  • theta (float | Parameter | Term) – The rotation angle (polar), in between both phase rotations (azimuthal).

  • phi (float | Parameter | Term) – The first phase parameter, or equivalently the first rotation angle (azimuthal) in radians.

  • gamma (float | Parameter | Term) – The second phase parameter, or equivalently the second rotation angle (azimuthal) in radians.

PARAMETER_NAMES: ClassVar[list[str]] = ['theta', 'phi', 'gamma'][source]
property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

property theta: float[source]
property phi: float[source]
property gamma: float[source]
class CNOT(control: int, target: int)[source]

Bases: Controlled[X]

Represents the CNOT gate.

The associated matrix is:

[[1, 0, 0, 0],
 [0, 1, 0, 0],
 [0, 0, 0, 1],
 [0, 0, 1, 0]]
Which is equivalent to the CZ gate surrounded by two H’s gates on the target qubit:

CNOT(control, target) = H(target) CZ(control, target) H(target)

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str

class CZ(control: int, target: int)[source]

Bases: Controlled[Z]

Represents the CZ gate.

The associated matrix is:

[[1, 0, 0, 0],
 [0, 1, 0, 0],
 [0, 0, 1, 0],
 [0, 0, 0, -1]]
This gate is totally symmetric respect control and target, meaning that both are control and target in reality:

CZ(control, target) = CZ(target, control)

It is also equivalent to the CNOT gate surrounded by two H’s gates on the target qubit:

CZ(control, target) = H(target) CNOT(control, target) H(target)

class SWAP(qubit_a: int, qubit_b: int)[source]

Bases: BasicGate

The SWAP gate.

The associated matrix is:

[[1, 0, 0, 0],
 [0, 0, 1, 0],
 [0, 1, 0, 0],
 [0, 0, 0, 1]]
Parameters:
  • qubit_a (int) – First qubit to swap with.

  • qubit_b (int) – Second qubit to swap with.

property name: str[source]

Retrieve the name of the gate.

Returns:

The name of the gate.

Return type:

str