Skip to main content

fockit - Quantum many-body operators and solvers

Copyright (C) 2026 H. L. Nourse

What is fockit?

Build many-body models, write your own operator algebras, and test algorithms on them. Quick and simple.

Comes with fermions, bosons and Pauli operators, and you can add your own. Simple exact solvers check your ideas on small systems.

Where to start?

The example below builds a model and solves it; the section after it adds your own algebra. More examples are in examples/ and in the tests:

  • tests/algebra/ for the operator algebra.
  • tests/hilbert/ for Hilbert spaces and matrices; test_symmetries.py there for symmetry sectors (momentum, reflection, spin flip, spin inversion, particle-hole, point groups).
  • tests/solve/ for the solvers.

Example

An electron hopping between two sites. Each site has a phonon and a spin.

from fockit.algebra import b, bdag, c, cdag, n, sigma_x, sigma_z
from fockit.hilbert import (
    BosonSpace, FermionSpace, PauliSpace, enumerate_basis, to_matrix,
)
from fockit.solve import groundstate

# The operator
H = -(cdag(0) * c(1) + cdag(1) * c(0)) + 0.2 * sigma_z(0) * sigma_z(1)
for i in (0, 1):
    H += bdag(i) * b(i) + 0.5 * n(i) * (b(i) + bdag(i)) + 0.3 * n(i) * sigma_x(i)

# A symmetry reduced basis H acts on
basis = enumerate_basis(
    {FermionSpace(): [0, 1], BosonSpace(n_max=6): [0, 1], PauliSpace(): [0, 1]},
    diagonal_symmetries={n(0) + n(1): 1},                 # one electron
    permutation_symmetries=[({0: 1, 1: 0}, 1)],           # even under swapping the sites
    onsite_symmetries=[([sigma_x(0), sigma_x(1)], 1)],    # even under flipping both spins
)

# The matrix representation of H in the above basis
mat = to_matrix(H, basis)

# The ground state
energy, state = groundstate(mat)

Your own algebra

Give the rules for swapping two neighbouring operators, which order is normal, and the adjoint. For example Majorana fermions:

from dataclasses import dataclass

from fockit.algebra import Monomial, Op, OpSum, SwapResult, mode_sort_key, normal_order


@dataclass(frozen=True)
class MajoranaRules:
    """γ_i γ_j + γ_j γ_i = 2 δ_ij."""

    def swap(self, left, right):
        if left == right:
            return SwapResult(terms=((1, ()),))  # γ γ = 1
        return SwapResult(terms=((-1, (right, left)),))  # anticommute

    def is_normal_ordered_pair(self, left, right):
        return mode_sort_key(left.mode) < mode_sort_key(right.mode)

    def dagger(self, op):
        return op


def gamma(mode):
    return OpSum({Monomial((Op(mode, "γ", MajoranaRules()),)): 1})


normal_order(gamma(1) * gamma(0) * gamma(1))  # -γ(0)
normal_order((gamma(0) + gamma(1)) ** 2)  # 2

examples/majorana.py solves a Majorana model with it, and examples/anyons.py also gives anyons their own Hilbert space.

Dependencies

Installation

Clone source

git clone https://github.com/thenoursehorse/fockit
cd fockit

Install with uv

uv sync --extra solve

Add --extra sympy for symbolic coefficients.

Tests

uv sync --extra sympy --extra solve
uv run pytest

Development

After installing as for the tests, set up the pre-commit hooks:

uv run pre-commit install

AI use

This code was written with AI coding assistants (Claude Code and Codex). All of it is reviewed and tested.

Metadata

Release files for fockit 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fockit 0.3.0
File Size Uploaded
fockit-0.3.0.tar.gz 49.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fockit 0.3.0
File Interpreter ABI Platform
fockit-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 86.7 kB

Release files / fockit-0.3.0.tar.gz

Download URL fockit-0.3.0.tar.gz
Size 49.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2207967f3505ca3f5fce88ace4a8e2b1ef60909070faef7905a8b82f48aa22ff
BLAKE2b-256 checksum
How to use checksums
f448f7b7021a357b3c18a6544d1713fd48f60da4bf0452c2c4c7e0b28e08ca56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / fockit-0.3.0-py3-none-any.whl

Download URL fockit-0.3.0-py3-none-any.whl
Size 37.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef1b97bf4b62bda37cc2c99b7a1c5ff02df19b9a95c5c96750dcc0f7003d33b8
BLAKE2b-256 checksum
How to use checksums
58b9fc7c214386236c3eba19eceb725efcd461c1787a3e4844235dbef48e1014
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.1

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page