Symbols#

Qibo provides a basic set of symbols which inherit the sympy.Symbol object and can be used to construct qibo.hamiltonians.SymbolicHamiltonian objects as described in the Hamiltonians section.

class qibo.symbols.Symbol(q, matrix, name='Symbol', commutative=False, **assumptions)[source]#

Qibo specialization for sympy symbols.

These symbols can be used to create qibo.hamiltonians.hamiltonians.SymbolicHamiltonian. See How to define custom Hamiltonians using symbols? for more details.

Example

from qibo.hamiltonians import SymbolicHamiltonian
from qibo.symbols import X, Y, Z

# construct a XYZ Hamiltonian on two qubits using Qibo symbols
form = X(0) * X(1) + Y(0) * Y(1) + Z(0) * Z(1)
ham = SymbolicHamiltonian(form)
Parameters:
  • q (int) – Target qubit id.

  • matrix (np.ndarray) – 2x2 matrix represented by this symbol.

  • name (str) – Name of the symbol which defines how it is represented in symbolic expressions.

  • commutative (bool) – If True the constructed symbols commute with each other. Default is False. This argument should be used with caution because quantum operators are not commutative objects and therefore switching this to True may lead to wrong results. It is useful for improving performance in symbolic calculations in cases where the user is sure that the operators participating in the Hamiltonian form are commuting (for example when the Hamiltonian consists of Z terms only).

property gate#

Qibo gate that implements the action of the symbol on states.

full_matrix(nqubits)[source]#

Calculates the full dense matrix corresponding to the symbol as part of a bigger system.

Parameters:
  • nqubits (int) – Total number of qubits in the system.

  • backend (Backend) – Optional backend to represent the matrix with. By default the global backend is used.

Returns:

Matrix of dimension (2^nqubits, 2^nqubits) composed of the Kronecker product between identities and the symbol’s single-qubit matrix.

class qibo.symbols.I(q, commutative=False, **assumptions)[source]#

Qibo symbol for the identity operator.

Parameters:

q (int) – Target qubit id.

class qibo.symbols.X(q, commutative=False, **assumptions)[source]#

Qibo symbol for the Pauli-X operator.

Parameters:

q (int) – Target qubit id.

class qibo.symbols.Y(q, commutative=False, **assumptions)[source]#

Qibo symbol for the Pauli-X operator.

Parameters:

q (int) – Target qubit id.

class qibo.symbols.Z(q, commutative=False, **assumptions)[source]#

Qibo symbol for the Pauli-X operator.

Parameters:

q (int) – Target qubit id.