qarp.operators.pyscf

Adapters from a converged pyscf mean-field object onto qarp’s tensor/ONV surface.

pyscf is optional and imported lazily inside each function (conventions §15); this module imports without it. Inputs are the user’s own mf — nothing here runs SCF. Spin orbitals are abab (2i = orbital i alpha, 2i+1 = beta, §1) throughout; the unrestricted helper returns per-spin spatial blocks and leaves the interleave to spin_blocks_to_spin_orbital downstream.

qarp.operators.pyscf.active_space_from_mf(mf: Any, active_electrons: int, active_orbitals: int) tuple[tuple[float, NDArray, NDArray], list[int]][source]

Frozen-core active-space integrals and the matching reference ONV (restricted).

The two calls every active-space example makes together: active_space_integrals(*integrals_from_mf(mf), n_electrons, e, o) and active_space(onv_from_mf(mf), e, o).

qarp.operators.pyscf.fermion_operator_from_mf(mf: Any, threshold: float = 1e-12) FermionOperator[source]

Molecular FermionOperator straight from a restricted mean-field.

qarp.operators.pyscf.integrals_from_mf(mf: Any) tuple[float, NDArray, NDArray][source]

(constant, one-electron, two-electron) in the MO spatial basis, chemists’ notation.

qarp.operators.pyscf.onv_coefficients_from_civec(civec: NDArray, n_orbitals: int, nelec: tuple[int, int] | int, *, threshold: float = 1e-12, n_core: int = 0) dict[tuple[int, ...], complex][source]

Convert a pyscf FCI/CASCI vector to abab ONV coefficients for MultiONVStateBlock.

civec is the (n_alpha_strings, n_beta_strings) array pyscf’s fci.FCI(mf).kernel() / mcscf.CASCI(...).ci return over n_orbitals spatial orbitals with nelec = (n_alpha, n_beta) (an int is split like pyscf: β gets nelec // 2). Each row/column address is decoded with pyscf.fci.cistring (bit i set ⇔ spatial orbital i occupied) and placed on the abab register — active orbital i → spin-orbitals 2(n_core + i) (α) and 2(n_core + i) + 1 (β) — after n_core doubly occupied core orbitals, so the ONV has length 2 (n_core + n_orbitals).

Sign convention: pyscf’s determinant is string)(β string)|vac⟩, all α creation operators to the left of the β ones; qarp’s (MultiONVStateBlock, FermionOperator) is ascending spin-orbital index, which interleaves the two. Moving each β operator on spatial p left past the α operators on q > p gives the per-determinant sign (−1)^{#{(p occ_β, q occ_α) : q > p}} applied here (within-string conventions only contribute a global sign). Confirmed by the CASCI energy oracle in tests/test_operators/test_pyscf_helpers.py.

pyscf is imported lazily; entries with |c| < threshold are dropped.

qarp.operators.pyscf.onv_from_mf(mf: Any) list[int][source]

Reference determinant as an abab ONV, from mf.mol.nelec; RHF, ROHF and UHF alike.

qarp.operators.pyscf.unrestricted_integrals_from_mf(mf: Any) tuple[float, tuple[NDArray, NDArray], tuple[NDArray, NDArray, NDArray]][source]

(constant, (h_a, h_b), (g_aa, g_ab, g_bb)) in the UHF MO bases, chemists’ notation.

Per-spin spatial blocks — no spin-orbital index exists here. The abab interleave happens once, in spin_blocks_to_spin_orbital (via unrestricted_integrals_to_fermion_operator); never an aabb layout.