qat.core.Observable

Check this notebook for an example of use and manipulation of observables.

class qat.core.Observable(nqbits, matrix=None, pauli_terms=None, ising=None, constant_coeff=0.0)

Class describing an observable (i.e some Hermitian operator) over the Hilbert space spanned by a list of qbits.

The observable is stored as a sum of Terms, each composed of a Pauli operator and a real coefficient. It is also possible to store it with an Ising object which represents an Ising Hamiltonian.

The purpose of this class is mainly to efficiently automatize the sampling of this observable on the final state obtained after a computation.

Construction:

An Observable object can be constructed in various ways:

using a matrix representation:

using a list of Term:

or using an Ising object from the Ising:

Parameters
  • nqbits (int) – number of qubits

  • matrix (np.array, optional) – the matrix representing the observable. Defaults to None.

  • pauli_terms (list<Term>, optional) – the list of products of Pauli operators representing the observable. Defaults to None.

  • ising (Ising, optional) – an object representing an Ising encoded problem

  • constant_coeff (float) – a constant additive term

terms

the list of products of Pauli operators representing the observable.

Type

list<Term>

ising

represents an Ising encoded problem (present if terms is None)

Type

Ising, optional

nbqbits

the number of qbits on which the observable acts

Type

int

constant_coeff

a constant additive term

Type

float

to_matrix(sparse: bool = True)

Returns the matrix representation of the Observable.

Parameters

sparse (bool, optional) – If a sparse matrix should be returned. Default to True.

Returns

numpy.ndarray or scipy.sparse.spmatrix

Note

Not implemented for other representation than using Pauli chains.