qilisdk.analog.hamiltonian

Classes

PauliOperator

A generic abstract Pauli operator that acts on one qubit.

PauliZ

A generic abstract Pauli operator that acts on one qubit.

PauliX

A generic abstract Pauli operator that acts on one qubit.

PauliY

A generic abstract Pauli operator that acts on one qubit.

PauliI

A generic abstract Pauli operator that acts on one qubit.

Hamiltonian

Represent a Hamiltonian expressed as a linear combination of Pauli operators.

Functions

Z(→ Hamiltonian)

X(→ Hamiltonian)

Y(→ Hamiltonian)

I(→ Hamiltonian)

Module Contents

Z(qubit: int) Hamiltonian[fuente]
X(qubit: int) Hamiltonian[fuente]
Y(qubit: int) Hamiltonian[fuente]
I(qubit: int = 0) Hamiltonian[fuente]
class PauliOperator(qubit: int)[fuente]

Bases: abc.ABC

A generic abstract Pauli operator that acts on one qubit.

Ejemplo

from qilisdk.analog import PauliX

op = PauliX(0)

Flyweight usage: do NOT instantiate directly—use PauliX(q), PauliY(q), etc.

Note: You can also use the factory functions X(q), Y(q), Z(q), I(q) to get a Hamiltonian object.

property qubit: int[fuente]
property name: str[fuente]
classmethod matrix_for_dtype(dtype: numpy.dtype) numpy.ndarray[fuente]
property matrix: numpy.ndarray[fuente]
to_hamiltonian() Hamiltonian[fuente]

Convert this single operator to a Hamiltonian with one term.

Devuelve:

The converted Hamiltonian.

Tipo del valor devuelto:

Hamiltonian

class PauliZ(qubit: int)[fuente]

Bases: PauliOperator

A generic abstract Pauli operator that acts on one qubit.

Ejemplo

from qilisdk.analog import PauliX

op = PauliX(0)

Flyweight usage: do NOT instantiate directly—use PauliX(q), PauliY(q), etc.

Note: You can also use the factory functions X(q), Y(q), Z(q), I(q) to get a Hamiltonian object.

class PauliX(qubit: int)[fuente]

Bases: PauliOperator

A generic abstract Pauli operator that acts on one qubit.

Ejemplo

from qilisdk.analog import PauliX

op = PauliX(0)

Flyweight usage: do NOT instantiate directly—use PauliX(q), PauliY(q), etc.

Note: You can also use the factory functions X(q), Y(q), Z(q), I(q) to get a Hamiltonian object.

class PauliY(qubit: int)[fuente]

Bases: PauliOperator

A generic abstract Pauli operator that acts on one qubit.

Ejemplo

from qilisdk.analog import PauliX

op = PauliX(0)

Flyweight usage: do NOT instantiate directly—use PauliX(q), PauliY(q), etc.

Note: You can also use the factory functions X(q), Y(q), Z(q), I(q) to get a Hamiltonian object.

class PauliI(qubit: int)[fuente]

Bases: PauliOperator

A generic abstract Pauli operator that acts on one qubit.

Ejemplo

from qilisdk.analog import PauliX

op = PauliX(0)

Flyweight usage: do NOT instantiate directly—use PauliX(q), PauliY(q), etc.

Note: You can also use the factory functions X(q), Y(q), Z(q), I(q) to get a Hamiltonian object.

class Hamiltonian(elements: dict[tuple[PauliOperator, ...], complex | qilisdk.core.variables.Term | qilisdk.core.variables.Parameter] | None = None)[fuente]

Bases: qilisdk.core.parameterizable.Parameterizable

Represent a Hamiltonian expressed as a linear combination of Pauli operators.

Ejemplo

from qilisdk.analog.hamiltonian import Hamiltonian, X, Z

H = X(0) * X(1) + Z(1)

Build a Hamiltonian from a mapping of Pauli operator products to coefficients.

Parámetros:

elements (dict[tuple[PauliOperator, ], complex | Term | Parameter], optional) –

Mapping from operator tuples to numerical coefficients or symbolic parameters. For example:

{
    (Z(0), Y(1)): 1.0,
    (X(1),): 1j,
}

Defaults to None, which creates an empty Hamiltonian.

Muestra:

ValueError – If the provided coefficients include generic variables instead of parameters.

ZERO: int = 0[fuente]
property nqubits: int[fuente]

Number of qubits on which the Hamiltonian acts.

property elements: dict[tuple[PauliOperator, ...], complex][fuente]

Return the stored operator-coefficient mapping with symbolic terms evaluated.

simplify() Hamiltonian[fuente]

Simplify the Hamiltonian expression by removing near-zero terms and accumulating constant terms.

Devuelve:

Simplified Hamiltonian

Tipo del valor devuelto:

Hamiltonian

to_matrix() scipy.sparse.spmatrix[fuente]

Return the full matrix representation of the Hamiltonian by summing over all terms.

Devuelve:

The sparse matrix representation of the Hamiltonian.

Tipo del valor devuelto:

spmatrix

to_qtensor(total_nqubits: int | None = None) qilisdk.core.qtensor.QTensor[fuente]

Return the Hamiltonian as a QTensor built from the sparse matrix representation.

Parámetros:

total_nqubits (int, optional) – Specify the total number of qubits that this hamiltonian acts on. Defaults to None.

Devuelve:

The QTensor object representation of the Hamiltonian.

Tipo del valor devuelto:

QTensor

Muestra:

ValueError – If the total_nqubits provided is lower than the number of qubits effected by the hamiltonian.

get_static_hamiltonian() Hamiltonian[fuente]

Return a Hamiltonian containing only constant coefficients.

get_commuting_partitions() list[dict[tuple[PauliOperator, ...], complex | qilisdk.core.variables.Term | qilisdk.core.variables.Parameter]][fuente]

Split the Hamiltonian into a list of partitions, each containing commuting terms.

For now this is a greedy algorithm, but a smarter graph-coloring approach could be used later.

Devuelve:

A list of dictionaries, each representing a partition of the Hamiltonian containing commuting terms.

Tipo del valor devuelto:

list[dict[tuple[PauliOperator, …], complex | Term | Parameter]]

classmethod from_qtensor(tensor: qilisdk.core.qtensor.QTensor, tol: float | None = None, prune: float | None = None) Hamiltonian[fuente]

Expand a qtensor (dense operator) on n qubits into a sum of Pauli strings, returning a qilisdk.analog.Hamiltonian.

Parámetros:
  • tol (float) – Hermiticity check tolerance. Defaults to global zero tolerance setting.

  • prune (float) – Drop coefficients whose absolute value satisfies abs(c) < prune to reduce numerical noise. Defaults to global zero tolerance setting.

Devuelve:

Sum_{P in {I,X,Y,Z}^{⊗ n}} c_P * P with c_P = Tr(qt * P) / 2^n

Tipo del valor devuelto:

Hamiltonian

Raises

ValueError: If the input is not square, not a power-of-two dimension, or not Hermitian w.r.t. tol.

classmethod parse(hamiltonian_str: str) Hamiltonian[fuente]
commutator(h: Hamiltonian) Hamiltonian[fuente]

compute the commutator of the current hamiltonian with another hamiltonian (h)

Parámetros:

h (Hamiltonian) – the second hamiltonian.

Devuelve:

the commutator.

Tipo del valor devuelto:

Hamiltonian

anticommutator(h: Hamiltonian) Hamiltonian[fuente]

compute the anticommutator of the current hamiltonian with another hamiltonian (h)

Parámetros:

h (Hamiltonian) – the second hamiltonian.

Devuelve:

the anticommutator.

Tipo del valor devuelto:

Hamiltonian

commutes_with(h: Hamiltonian) bool[fuente]

Check whether this Hamiltonian commutes with another one ([self, h] == 0).

This is faster than materialising the full commutator self * h - h * self: every pair of Pauli strings either commutes or anticommutes, and which one holds can be decided with a cheap qubit-overlap parity check instead of a matrix/operator product. Commuting pairs contribute nothing to the commutator and are skipped entirely, so only the anticommuting pairs (for which [P, Q] = 2 P Q) are ever multiplied out and accumulated.

Parámetros:

h (Hamiltonian) – the Hamiltonian to test commutation against.

Devuelve:

True if the two Hamiltonians commute, False otherwise.

Tipo del valor devuelto:

bool

vector_norm() float[fuente]
Devuelve:

the vector norm of the hamiltonian.

Tipo del valor devuelto:

float

frobenius_norm() float[fuente]
Devuelve:

the forbenius norm of the hamiltonian.

Tipo del valor devuelto:

float

trace() qilisdk.core.types.Number[fuente]
Devuelve:

the trace of the hamiltonian.

Tipo del valor devuelto:

float