Hamiltonian#
Public names: edinpy.fermion.Hamiltonian and edinpy.boson.Hamiltonian.
- class edinpy.fermion.Hamiltonian(operator, sector)[source]#
Finite-sector Hamiltonian built from a symbolic operator expression.
- Parameters:
operator (Operator) – Symbolic second-quantized operator expression. All primitive operators in the expression must use the same mode specification as
sector.sector (NParticleSector) – Built fermionic or bosonic sector that defines the ordered many-body basis.
Notes
The sparse CSC matrix is constructed lazily when
matrix,calc_matrix(), or an explicit-matrix eigensolve requires it. Partial eigenproblems can instead useaslinearoperator()oreigsolve(matrix_free=True).- calc_matrix()[source]#
Construct and cache the Hamiltonian in CSC sparse format.
- Returns:
Square Hamiltonian matrix in the ordering of
sector.basis.- Return type:
scipy.sparse.csc_matrix
- property matrix#
Lazily constructed Hamiltonian matrix.
- Type:
scipy.sparse.csc_matrix
- aslinearoperator(*, execution='numpy')[source]#
Return the Hamiltonian as a matrix-free SciPy
LinearOperator.- Parameters:
execution ({"numpy", "numba-serial", "numba-parallel", "mixed"}, optional) – Hamiltonian-action implementation.
"numpy"uses the NumPy implementation."numba-serial"and"numba-parallel"are strict Numba requests and raise if the operator or basis is not supported."numba-parallel"uses Numba’s configured thread count."mixed"uses the statistics-specific conservative selection rule and does not enable parallel execution automatically.- Returns:
Matrix-free operator with forward and adjoint actions and shape
(sector.dimension, sector.dimension).- Return type:
scipy.sparse.linalg.LinearOperator
Notes
The explicit CSC matrix is not constructed. The adjoint action is obtained from the symbolic Hermitian adjoint of the operator.
- property solver_diagnostics#
Diagnostics from the most recent matrix-free eigensolve, or
None.The object is a frozen snapshot taken immediately when ARPACK returns. Subsequent uses of
aslinearoperator(), such as residual checks, do not alter the stored diagnostics. Explicit-matrix solves clear it.
- property compiler_stats#
Statistics for the lowered operator representation.
- Type:
dict[str, int]
- toarray()[source]#
Return the Hamiltonian as a dense NumPy array.
- Returns:
Dense matrix with shape
(sector.dimension, sector.dimension).- Return type:
numpy.ndarray
- is_hermitian(atol=1e-12)[source]#
Test Hermiticity of the explicit Hamiltonian matrix.
- Parameters:
atol (float, optional) – Absolute tolerance used when comparing the matrix with its Hermitian adjoint.
- Returns:
Truewhen the matrix is Hermitian withinatol.- Return type:
bool
- estimate_solver_memory(*, k=2, ncv=None)[source]#
Estimate dominant ARPACK workspace without materializing the matrix.
- Parameters:
k (int, optional) – Number of requested eigenpairs.
ncv (int or None, optional) – Krylov subspace size.
Noneuses SciPy’s default policy.
- Returns:
Implementation-informed estimate of the dominant SciPy/ARPACK arrays. It excludes the Hamiltonian, basis storage, and general process overhead.
- Return type:
ArpackMemoryEstimate
- ncv_for_arpack_budget(budget_bytes, *, k=2, ncv=None)[source]#
Choose the largest
ncvfitting an ARPACK workspace budget.- Parameters:
budget_bytes (int) – Maximum bytes assigned to the ARPACK arrays represented by
estimate_solver_memory().k (int, optional) – Number of requested eigenpairs.
ncv (int or None, optional) – Upper bound for the Krylov subspace size.
Nonecaps the search at SciPy’s normal default.
- Returns:
Largest admissible
ncvwithin the requested workspace budget.- Return type:
int
Notes
The budget excludes basis storage, Python and SciPy allocator overhead, linked libraries, and unrelated process memory.
- plan_solver_memory(total_memory_bytes, *, k=2, ncv=None, reserve_bytes=0, reserve_fraction=0.25, safety_factor=1.25)[source]#
Estimate memory for a matrix-free ARPACK eigensolve.
- Parameters:
total_memory_bytes (int) – Total memory envelope available to the process.
k (int, optional) – Number of requested eigenpairs.
ncv (int or None, optional) – Krylov subspace size.
Noneuses SciPy’s default policy.reserve_bytes (int, optional) – Fixed number of bytes withheld from the solver plan.
reserve_fraction (float, optional) – Fraction of
total_memory_byteswithheld in addition toreserve_bytes. Must satisfy0 <= value < 1.safety_factor (float, optional) – Multiplicative factor applied to the ARPACK array estimate. Must be at least one.
- Returns:
Estimated ARPACK storage, persistent basis storage, reserved memory, remaining headroom, and whether the plan fits.
- Return type:
SolverMemoryPlan
- ncv_for_memory_budget(total_memory_bytes, *, k=2, ncv=None, reserve_bytes=0, reserve_fraction=0.25, safety_factor=1.25)[source]#
Choose the largest
ncvfitting a total-memory envelope.- Parameters:
total_memory_bytes (int) – Total memory envelope available to the process.
k (int, optional) – Number of requested eigenpairs.
ncv (int or None, optional) – Upper bound for the Krylov subspace size.
Nonecaps the search at SciPy’s normal default.reserve_bytes (int, optional) – Fixed number of bytes withheld from the solver plan.
reserve_fraction (float, optional) – Fraction of total memory withheld in addition to
reserve_bytes.safety_factor (float, optional) – Multiplicative factor applied to the ARPACK array estimate.
- Returns:
Largest admissible
ncvsatisfying the memory plan.- Return type:
int
- eigsolve(*, sparse=True, k=2, which='SA', tol=1e-10, maxiter=None, ncv=None, v0=None, check_hermitian=True, matrix_free=False, execution='numpy')[source]#
Solve the Hermitian Hamiltonian eigenproblem.
- Parameters:
sparse (bool, optional) – Use ARPACK through
scipy.sparse.linalg.eigsh()whenTrueand fewer than all eigenpairs are requested. Otherwise use the dense Hermitian solverscipy.linalg.eigh(). Matrix-free solves requiresparse=True.k (int or None, optional) – Number of eigenpairs to return.
Nonerequests the complete spectrum and therefore requires an explicit matrix.which ({"SA", "LA", "SM", "LM"}, optional) – Spectral selection rule: smallest algebraic, largest algebraic, smallest magnitude, or largest magnitude, respectively.
tol (float, optional) – ARPACK convergence tolerance.
maxiter (int or None, optional) – Maximum number of ARPACK iterations.
Noneuses SciPy’s default.ncv (int or None, optional) – Number of Lanczos vectors used by ARPACK. It must satisfy
k < ncv <= dimension.Noneuses SciPy’s default policy.v0 (array_like or None, optional) – Initial vector for ARPACK.
Nonelets SciPy choose the starting vector.check_hermitian (bool, optional) – Check Hermiticity before an explicit-matrix solve. Matrix-free solves require
Falsebecause an exact check would construct the matrix.matrix_free (bool, optional) – Apply the Hamiltonian through a SciPy
LinearOperatorinstead of constructing the CSC matrix. Only partial sparse solves withk < sector.dimensionare supported.execution ({"numpy", "numba-serial", "numba-parallel", "mixed"}, optional) – Hamiltonian-action implementation used when
matrix_free=True. Explicit-matrix solves require"numpy". Strict Numba modes raise when the current operator or basis is unsupported.
- Returns:
eigenvalues (numpy.ndarray) – Requested eigenvalues ordered according to
which.eigenvectors (numpy.ndarray) – Corresponding normalized eigenvectors stored by column in the sector-basis ordering.
Notes
The returned eigenpairs are also stored in
eigvalsandeigvecs. Useeigenstate()oreigenstates()to recover basis-aware Fock vectors.
- eigenstate(index=0)[source]#
Return one computed eigenvector as a basis-aware Fock ket.
- Parameters:
index (int, optional) – Column index in the eigenvector array from the most recent
eigsolve(). Negative indices follow Python indexing.- Returns:
Eigenstate associated with
eigvals[index].- Return type:
- eigenstates()[source]#
Return all computed eigenvectors as basis-aware Fock kets.
- Returns:
Eigenstates in the same order as
eigvals.- Return type:
tuple[FockVector, …]
- property eigvals#
Eigenvalues from the most recent eigensolve.
- Type:
numpy.ndarray or None
- property eigvecs#
Eigenvectors from the most recent eigensolve.
- Type:
numpy.ndarray or None