← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe
Google Quantum AI
OpenFermion: getting started with quantum chemistry
Official source: quantumlib/OpenFermion
Download ZIP (free)OpenFermion, for bringing electronic structure problems to quantum computers, with an example that maps the Fermi-Hubbard model to qubits with Jordan-Wigner and checks the result against the analytic solution.
What is OpenFermion?
OpenFermion is a library that turns the behaviour of electrons (fermions) in molecules and materials into a form that can be simulated on a quantum computer. It maps fermionic operators to qubit (Pauli) operators with the Jordan-Wigner or Bravyi-Kitaev transformations.
When to use it
- When preparing a molecule's Hamiltonian as input to algorithms such as VQE.
- When studying condensed-matter models such as Fermi-Hubbard.
- When connecting to PySCF for real molecular integrals with the
openfermionpyscfplugin.
The example in this package
hubbard_jordan_wigner.py builds the two-site Fermi-Hubbard model, maps it to
a qubit Hamiltonian and computes the ground-state energy. The result in the
half-filled sector matches the known analytic formula (U − √(U² + 16t²)) / 2
to machine precision.
Next steps
- Generate the Hamiltonian of the H₂ or LiH molecule with
pip install openfermionpyscf. - Pass the resulting Pauli operator to a Cirq- or Qiskit-based VQE.
Installation and running
pip install openfermion
python hubbard_jordan_wigner.py
Tested with: openfermion 1.8.1, Python 3.12.
Official source
- Repository: quantumlib/OpenFermion
- Latest release: v1.8.1 — 17 July 2026
- Licence: Apache-2.0
- Stars: 1,743
- Default branch commit when the catalogue was built:
90074a3093f8(12 October 2026)
Links
Package contents
hubbard_jordan_wigner.pyREADME.en.md— this fileREADME.md— the same guide in TurkishLICENSE— the licence of the files in this packageKAYNAK.json— a machine-readable summary of the official sourceUPSTREAM-LICENSE.txt— the licence text of the official projectCITATION.cff— citation information of the official project
Licence
The example code and the guide in this package were written by the Quantum Store editors and are MIT licensed. The project it uses is subject to its own licence (Apache-2.0).
Quantum Store — https://hakanerdogan.com/en
Example code
The example shipped in the package, run and checked. Comments and printed messages are in Turkish; the code is the same in any language. Everything is in the ZIP.
hubbard_jordan_wigner.py
"""OpenFermion: 2 siteli Fermi-Hubbard modelini kübit Hamiltonyenine çevir.
Fermiyonik operatör Jordan-Wigner dönüşümüyle Pauli operatörlerine çevrilir,
ardından taban durum enerjisi tam köşegenleştirme ile hesaplanır.
Çalıştırma:
pip install openfermion
python hubbard_jordan_wigner.py
"""
import numpy as np
import openfermion as of
hamiltonian = of.fermi_hubbard(
x_dimension=2,
y_dimension=1,
tunneling=1.0,
coulomb=4.0,
periodic=False,
)
qubit_hamiltonian = of.jordan_wigner(hamiltonian)
print("Kübit Hamiltonyeni (Jordan-Wigner):")
print(qubit_hamiltonian)
sparse = of.get_sparse_operator(qubit_hamiltonian)
energy, _ = of.get_ground_state(sparse)
print(f"\nTaban durum enerjisi: {energy:.6f}")
# Yarı dolu sektör (2 elektron) için analitik sonuç: (U - sqrt(U^2 + 16 t^2)) / 2
t, u = 1.0, 4.0
half_filling = of.jw_number_restrict_operator(sparse, 2, n_qubits=4)
e_half = np.linalg.eigvalsh(half_filling.toarray())[0]
analytic = (u - np.sqrt(u**2 + 16 * t**2)) / 2
print(f"Yarı dolu sektör: {e_half:.6f} (analitik: {analytic:.6f})")
assert abs(e_half - analytic) < 1e-9
print("Tamam: sayısal sonuç analitik değerle eşleşiyor.")
Related concepts
- VQE (variational quantum eigensolver) · VQE is a hybrid quantum algorithm that approximates the ground-state energy of a molecule by tuning a parameterised quantum circuit in a classical optimisation loop.