A practical F# library for symbolic operator algebra on Fock space β fermionic and bosonic β with fermion-to-qubit encodings, qubit tapering, Trotterization, and circuit export.
The complete pipeline: molecular integrals β encoding β tapering β Trotter decomposition β OpenQASM / Q# / JSON circuit output.
π The Book: From Molecules to Quantum Circuits β 23-chapter guide with interactive labs, computed results (Hβ dissociation curve, HβO bond angle scan), and companion code.
π³ API Cookbook: 15 progressive chapters covering every type and function.
If you're exploring quantum chemistry on qubits, you usually hit this question quickly: how do I map fermions to Pauli operators? And increasingly: what about phonons and other bosonic modes?
FockMap gives you one small, consistent API for the complete quantum simulation pipeline:
- Encode fermionic or bosonic operators as Pauli strings (5 fermionic + 3 bosonic encodings)
- Taper qubits via Zβ symmetry detection and Clifford rotation (diagonal + general)
- Trotterize a Pauli Hamiltonian into gate sequences (first and second order)
- Export circuits as OpenQASM 3.0, Q#, or JSON for any quantum platform
- Define custom encodings with a few lines of F#
- Compare encodings side-by-side β same eigenvalues, different circuit costs
| Feature | OpenFermion | Qiskit Nature | PennyLane | FockMap |
|---|---|---|---|---|
| Define a new encoding | ~200 lines Python | Not supported | Not supported | 3β5 lines F# |
| Tree β encoding pipeline | β | β | β | β |
| Qubit tapering (Zβ + Clifford) | β | Partial | β | β |
| Trotter decomposition | β | β | β | β (1st + 2nd order) |
| Circuit export (QASM, Q#, JSON) | β | QASM only | β | β (all three) |
| Hamiltonian skeleton (PES scans) | β | β | β | β |
| Measurement grouping + shot estimates | β | β | β | β |
| QPE resource estimation | β | β | β | β |
| Bosonic operator algebra (CCR) | β | β | β | β |
| Bosonic-to-qubit encodings | β | β | β | β (Unary, Binary, Gray) |
| Mixed fermionβboson normal ordering | β | β | β | β |
| Type-safe operator algebra | β | β | β | β |
| Pure functional, zero mutation | β | β | β | β |
| Runtime dependencies | NumPy, SciPy | Many | NumPy, autograd, β¦ | None |
Internally, the library uses exact symbolic Pauli algebra (not floating-point matrix multiplication), so encoded operator manipulation stays fast and predictable.
| Encoding | Worst-Case Pauli Weight | Framework | Function |
|---|---|---|---|
| Jordan-Wigner | Index-set | jordanWignerTerms |
|
| Bravyi-Kitaev | Index-set | bravyiKitaevTerms |
|
| Parity | Index-set | parityTerms |
|
| Balanced Binary Tree | Path-based | balancedBinaryTreeTerms |
|
| Balanced Ternary Tree | Path-based | ternaryTreeTerms |
|
| Vlasov (Complete Ternary) | Path-based | vlasovTreeTerms |
| Encoding | Qubits / Mode | Max Weight | Function |
|---|---|---|---|
| Unary (one-hot) | 2 | unaryBosonTerms |
|
| Standard Binary | binaryBosonTerms |
||
| Gray Code | grayCodeBosonTerms |
Bosonic modes are truncated to BosonicEncoderFn signature and return PauliRegisterSequence, just like their fermionic counterparts.
All encodings return the same output type (PauliRegisterSequence), so you can swap schemes without rewriting downstream code.
dotnet add package FockMapgit clone https://github.com/johnazariah/encodings.git
cd encodings
dotnet build
dotnet testThis repository includes a full dev container configuration with .NET 10 (GA), F#, Python, LaTeX, and all required tooling pre-installed. To use it:
- Install Docker and VS Code with the Dev Containers extension
- Clone the repository and open it in VS Code
- When prompted, click "Reopen in Container" (or run
Dev Containers: Reopen in Containerfrom the command palette) - The container builds, restores packages, compiles the project, and runs tests automatically
Everything is pre-configured, so you can start coding immediately.
open System.Numerics
open Encodings
// 1. Define molecular integrals (Hβ in STO-3G)
let integrals = Map [
("0,0", Complex(-1.2563, 0.0)); ("1,1", Complex(-1.2563, 0.0))
("2,2", Complex(-0.4719, 0.0)); ("3,3", Complex(-0.4719, 0.0))
// ... (two-body integrals)
]
let factory key = integrals |> Map.tryFind key
// 2. Encode β 15-term Pauli Hamiltonian
let ham = computeHamiltonianWith jordanWignerTerms factory 4u
// 3. Taper β remove symmetry-redundant qubits
let tapered = taper defaultTaperingOptions ham
// 4 β 2 qubits
// 4. Trotterize β gate sequence
let step = firstOrderTrotter 0.1 tapered.Hamiltonian
let gates = decomposeTrotterStep step
// 5. Export β OpenQASM 3.0
let qasm = toOpenQasm defaultOpenQasmOptions tapered.TaperedQubitCount gates
// Ready to run on IBM Quantum, IonQ, Rigetti, Amazon Braket
// Also available: Q# and JSON export
let qs = toQSharp defaultQSharpOptions tapered.TaperedQubitCount gates
let json = toCircuitJson tapered.TaperedQubitCount Map.empty gates- The Book: From Molecules to Quantum Circuits β 23 chapters, from molecular integrals to quantum circuits
- Interactive Labs: 10 F# scripts β run with
dotnet fsi - API Cookbook: 15-chapter tutorial β every type and function
- Architecture: How the library works
- API Reference: All types and functions
- Site: johnazariah.github.io/encodings β API cookbook, architecture guide, cross-platform notes
- Book: johnazariah.github.io/encodings-book β full narrative with labs and companion code
FockMap implements the complete quantum simulation pipeline:
- Encoding β Map fermionic/bosonic ladder operators to Pauli strings via index-set schemes (JW, BK, Parity) or path-based tree encodings (binary, ternary, Vlasov, custom)
- Hamiltonian Assembly β Combine encoded operators with molecular integrals to build a qubit Hamiltonian (
PauliRegisterSequence) - Tapering β Detect Zβ symmetries (diagonal or general via Clifford rotation), fix sectors, and remove redundant qubits
- Trotterization β Decompose the Hamiltonian into Pauli rotations (first or second order), then into elementary gates (H, S, CNOT, Rz)
- Circuit Output β Export gate sequences as OpenQASM 3.0, Q#, or JSON
- Analysis β Measurement grouping, shot estimation, QPE resource estimation, cost comparison across encodings
Everything is symbolic and exact β no floating-point matrix multiplication, no approximation until the Trotter step.
For the full API walkthrough, see the Cookbook (18 chapters) or the Architecture guide.
dotnet test # all tests
dotnet test --logger "console;verbosity=detailed" # verbose
dotnet test --collect:"XPlat Code Coverage" # with coverageThe test suite covers encoding correctness, Pauli algebra laws, tapering, Trotterization, circuit output, and cross-encoding consistency. See the Test Register for a plain-English catalogue of all 700+ automated tests.
This library runs on Windows, macOS, and Linux via .NET 10, Microsoft's open-source, cross-platform runtime. It is written in F#, a functional-first language that is fully open-source under the F# Software Foundation and the .NET Foundation.
No platform-specific code and no native dependencies beyond the .NET SDK.
If you use this library in your research, please cite:
@software{fockmap2026,
author = {Azariah, John},
title = {FockMap: A Composable Framework for Quantum Operator Encodings},
year = {2026},
url = {https://github.com/johnazariah/encodings}
}A machine-readable citation file is available at CITATION.cff.
Contributions are welcome! See CONTRIBUTING.md for:
- How to report bugs and propose features
- Development setup instructions
- Coding conventions (pure functions, immutable data, XML docs)
- Pull request process
This library is dedicated to Dr. Guang Hao Low for his guidance and inspiration in the field of quantum algorithms.