← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe

Google Quantum AI

OpenFermion: getting started with quantum chemistry

SoftwareChemistryLicence: Apache-2.0Version: 1.8.110.3 KB

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

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

  1. Generate the Hamiltonian of the H₂ or LiH molecule with pip install openfermionpyscf.
  2. 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

Links

Package contents

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

← All packages

Share: X · LinkedIn