Header menu logo Encodings

Hamiltonian Module

Hamiltonian construction from one-body and two-body integrals.

Assembles the second-quantized electronic Hamiltonian: H = Σ_{pq} h_{pq} a†_p a_q + ½ Σ_{pqrs} ⟨pq|rs⟩ a†_p a†_q a_s a_r and encodes it as a sum of Pauli strings using any provided encoding function. The function handles one-body terms, two-body terms, coefficient combination, and zero-term dropping.

Types

Type Description

EncoderFn

A function type that encodes a ladder operator into qubit Pauli strings.

ExchangeTerm

A two-body exchange term with indices i, j, k, l, representing ⟨ij|kl⟩ a†_i a†_j a_l a_k.

HamiltonianSkeleton

A precomputed encoding skeleton separating Pauli structure from integral coefficients.

HamiltonianTerm

Discriminated union representing a term in the Hamiltonian.

OverlapTerm

A one-body overlap term with indices i and j, representing h_{ij} a†_i a_j.

SkeletonEntry

A single entry in a precomputed Hamiltonian skeleton.

SkeletonTerm

A pre-computed Pauli term with its signature cached.

Functions and values

Function or value Description

applyCoefficients skeleton coefficientFactory

Full Usage: applyCoefficients skeleton coefficientFactory

Parameters:
Returns: PauliRegisterSequence A PauliRegisterSequence representing the encoded Hamiltonian.

Apply integral coefficients to a precomputed skeleton.

Accumulates coefficients directly into a dictionary keyed by pre-computed Pauli signatures. No Pauli algebra, no intermediate PauliRegister construction, and no re-computation of signature strings. Final PauliRegister objects are created only for the combined result (~tens of terms, not thousands).

Typical runtime is under 10 ms for systems up to ~20 qubits, making PES scans over hundreds of geometries essentially free after the one-time skeleton build.

skeleton : HamiltonianSkeleton

The precomputed skeleton from computeHamiltonianSkeleton.

coefficientFactory : string -> Complex option

A function returning Some(coefficient) for a given comma-separated index key, or None to skip.

Returns: PauliRegisterSequence

A PauliRegisterSequence representing the encoded Hamiltonian.

computeHamiltonian coefficientFactory n

Full Usage: computeHamiltonian coefficientFactory n

Parameters:
    coefficientFactory : string -> Complex option - A function that returns Some(coefficient) for a given comma-separated index key (e.g., "0,1" for one-body, "0,1,2,3" for two-body), or None if the term should be skipped.
    n : uint32 - The number of qubits/modes in the system.

Returns: PauliRegisterSequence A PauliRegisterSequence representing the encoded Hamiltonian.

Compute a qubit Hamiltonian from integral coefficients using Jordan-Wigner encoding.

Iterates over all one-body (i,j) and two-body (i,j,k,l) index combinations, retrieves coefficients from the factory function, and encodes non-zero terms using the Jordan-Wigner transformation. Keys are formatted as comma-separated indices: "i,j" for one-body and "i,j,k,l" for two-body terms.

coefficientFactory : string -> Complex option

A function that returns Some(coefficient) for a given comma-separated index key (e.g., "0,1" for one-body, "0,1,2,3" for two-body), or None if the term should be skipped.

n : uint32

The number of qubits/modes in the system.

Returns: PauliRegisterSequence

A PauliRegisterSequence representing the encoded Hamiltonian.

computeHamiltonianParallel coefficientFactory n

Full Usage: computeHamiltonianParallel coefficientFactory n

Parameters:
    coefficientFactory : string -> Complex option
    n : uint32

Returns: PauliRegisterSequence

Parallel version of computeHamiltonian (Jordan-Wigner).

coefficientFactory : string -> Complex option
n : uint32
Returns: PauliRegisterSequence

computeHamiltonianSkeleton encode n

Full Usage: computeHamiltonianSkeleton encode n

Parameters:
    encode : EncoderFn - The encoding function.
    n : uint32 - The number of qubits/modes.

Returns: HamiltonianSkeleton A HamiltonianSkeleton containing precomputed Pauli structures for all one-body and two-body operator products.

Precompute the Pauli skeleton for a given encoding and system size.

Uses Array.Parallel.map on the n⁴ two-body index space. Signatures and operator arrays are cached in SkeletonTerm records so that applyCoefficients can accumulate coefficients without any Pauli algebra or string computation.

encode : EncoderFn

The encoding function.

n : uint32

The number of qubits/modes.

Returns: HamiltonianSkeleton

A HamiltonianSkeleton containing precomputed Pauli structures for all one-body and two-body operator products.

computeHamiltonianSkeletonFor encode coefficientFactory n

Full Usage: computeHamiltonianSkeletonFor encode coefficientFactory n

Parameters:
    encode : EncoderFn - The encoding function.
    coefficientFactory : string -> Complex option - A function that returns Some for keys to include. Only the presence/absence matters; coefficient values are ignored.
    n : uint32 - The number of qubits/modes.

Returns: HamiltonianSkeleton A HamiltonianSkeleton containing precomputed Pauli structures only for index combinations where the factory returns Some.

Precompute a sparse Pauli skeleton using a coefficient factory to discover active keys.

For molecules, typically only 5–10% of possible index combinations have non-zero integrals. This variant precomputes only those entries, giving a proportional speedup over the full computeHamiltonianSkeleton.

Use when all geometries in a scan share the same sparsity pattern (same basis set → same non-zero integral indices).

encode : EncoderFn

The encoding function.

coefficientFactory : string -> Complex option

A function that returns Some for keys to include. Only the presence/absence matters; coefficient values are ignored.

n : uint32

The number of qubits/modes.

Returns: HamiltonianSkeleton

A HamiltonianSkeleton containing precomputed Pauli structures only for index combinations where the factory returns Some.

computeHamiltonianWith encode coefficientFactory n

Full Usage: computeHamiltonianWith encode coefficientFactory n

Parameters:
    encode : EncoderFn - The encoding function to transform ladder operators to Pauli strings.
    coefficientFactory : string -> Complex option - A function that returns Some(coefficient) for a given comma-separated index key (e.g., "0,1" for one-body, "0,1,2,3" for two-body), or None if the term should be skipped.
    n : uint32 - The number of qubits/modes in the system.

Returns: PauliRegisterSequence A PauliRegisterSequence representing the encoded Hamiltonian.

Compute a qubit Hamiltonian from integral coefficients using any encoding.

Generic version that accepts any fermion-to-qubit encoding function. Useful for comparing different encodings (Jordan-Wigner, Bravyi-Kitaev, etc.) on the same Hamiltonian. Keys are formatted as comma-separated indices: "i,j" for one-body and "i,j,k,l" for two-body terms.

encode : EncoderFn

The encoding function to transform ladder operators to Pauli strings.

coefficientFactory : string -> Complex option

A function that returns Some(coefficient) for a given comma-separated index key (e.g., "0,1" for one-body, "0,1,2,3" for two-body), or None if the term should be skipped.

n : uint32

The number of qubits/modes in the system.

Returns: PauliRegisterSequence

A PauliRegisterSequence representing the encoded Hamiltonian.

computeHamiltonianWithParallel encode coefficientFactory n

Full Usage: computeHamiltonianWithParallel encode coefficientFactory n

Parameters:
    encode : EncoderFn - The encoding function to transform ladder operators to Pauli strings.
    coefficientFactory : string -> Complex option - A function that returns Some(coefficient) for a given comma-separated index key.
    n : uint32 - The number of qubits/modes in the system.

Returns: PauliRegisterSequence A PauliRegisterSequence representing the encoded Hamiltonian.

Parallel version of computeHamiltonianWith. Distributes encoding work across available CPU cores using Array.Parallel.

The n² one-body and n⁴ two-body index loops are parallelised. Coefficient lookups remain sequential (cheap), while the expensive encode-and-multiply steps run across all cores. Produces results identical to the sequential computeHamiltonianWith.

encode : EncoderFn

The encoding function to transform ladder operators to Pauli strings.

coefficientFactory : string -> Complex option

A function that returns Some(coefficient) for a given comma-separated index key.

n : uint32

The number of qubits/modes in the system.

Returns: PauliRegisterSequence

A PauliRegisterSequence representing the encoded Hamiltonian.

Type something to start searching.