Skip to content

hamiltonian Module

The pyqpanda3.hamiltonian module provides classes for constructing, manipulating, and analyzing Pauli operators and Hamiltonians. These are the fundamental building blocks for defining quantum observables, problem Hamiltonians in variational algorithms (VQE, QAOA), and quantum simulation tasks.

Overview

A Hamiltonian in quantum mechanics is an operator that describes the total energy of a quantum system. In the context of quantum computing, Hamiltonians are commonly expressed as linear combinations of Pauli operators acting on qubits:

H=iciPi

where each Pi is a tensor product of Pauli matrices (I, X, Y, Z) and ci is a (possibly complex) coefficient.

The module exposes four main classes:

  • PauliOperator -- A multi-term sum of Pauli strings with coefficients. Supports full arithmetic algebra (+, -, *, @), tensor product via .tensor(), string serialization, matrix conversion, and commuting-term grouping.
  • PauliTerm -- A single term in a Pauli operator, consisting of a Pauli string and a coefficient. Provides access to the individual Pauli-with-qubit pairs and quantum circuit conversion.
  • PauliWithQbit -- A Pauli matrix (I, X, Y, Z) associated with a specific qubit index. The smallest unit of a Pauli term.
  • Hamiltonian -- A higher-level wrapper around PauliOperator with the same algebraic interface and additional convenience methods.

Class Hierarchy

Sub-topics

TopicDescription
PauliOperatorMulti-term Pauli operator with full arithmetic algebra
PauliTermSingle Pauli term with coefficient
PauliWithQbitPauli matrix bound to a qubit index
HamiltonianHigh-level Hamiltonian wrapper

Released under the MIT License.