This repository provides a framework for constructing quantum Hamiltonians using Qiskit. The implementation allows for easy definition of time-dependent Hamiltonians, including Ising, Heisenberg, and general spin chain models. The Hamiltonian
class serves as the base, while specialized classes extend it to represent specific models. Additionally, the framework enables conversion of these Hamiltonians into quantum circuits for execution on quantum simulators or real quantum hardware.
The Hamiltonian
class is the core structure for defining a quantum Hamiltonian. It allows users to specify:
- The number of qubits (
nqubits
) - A list of terms in the Hamiltonian, where each term consists of:
- A Pauli operator (e.g.,
X
,Y
,Z
,XX
,YY
,ZZ
) - The qubits on which the operator acts
- A time-dependent function defining the coefficient of the term
- A Pauli operator (e.g.,
get_term(t)
: Returns the terms of the Hamiltonian evaluated at timet
.coefs(t)
: Extracts the coefficients of the Hamiltonian terms at timet
.l1_norm(T)
: Computes the integral of the L1 norm of the coefficients over time.get_matrix()
: Constructs the Hamiltonian matrix representation.gen_quantum_circuit(t, init_state)
: Generates a Qiskit quantum circuit that implements the Hamiltonian evolution at timet
.
The Ising model describes a system of interacting spins with nearest-neighbor interactions. The Hamiltonian is given by:
where:
-
$J$ controls the interaction strength between neighboring spins. -
$d$ represents the strength of an external field. -
$P$ is either$X$ (for a transverse field) or$Z$ (for a longitudinal field).
The Heisenberg model includes interactions in all three Pauli bases:
where
A more general spin chain model allows different types of interactions and external fields:
where:
-
$J_{ij}$ defines interaction strengths. -
$h_i$ represents local field strengths. -
$P$ can be any Pauli operator ($X$ ,$Y$ , or$Z$ ).
- Install the necessary dependencies:
pip install qiskit scipy numpy
- Create an instance of a Hamiltonian:
from ising_hamiltonian import Ising_Hamil H = Ising_Hamil(n=4, J=1.0, d=0.5, transverse=True)
- Generate the Hamiltonian matrix:
matrix = H.get_matrix()
- Create a quantum circuit representation:
qc = H.gen_quantum_circuit(t=1.0) print(qc)
This project is released under the MIT License.