fulqrum.gpu.TileGPUResidentHamiltonian¶
- class TileGPUResidentHamiltonian(hsub, alpha_strs, beta_strs, *, gpu_ids=(0,), comm=None, process_grid=None, threads_per_block=256, comm_backend='auto', intra_node_size=None, build_threads=0, config=None)[source]¶
GPU-backed real type-2 Hamiltonian for distributed matrix-free matvecs.
Use this operator with
distributed_primme_eigshfor MPI eigenvalue solves.The subspace must be a half-string/tensor product with alpha in the low qubits and beta in the high qubits. Each sector must have 1–128 orbitals (bits), a fixed electron count and operator groups supported by the GPU kernels. Use at least two occupied orbitals per half string; lower occupations are outside verified GPU support and may give incorrect results. GPU execution requires CuPy and the compiled CUDA components.
- Parameters:
hsub – Real type-2
SubspaceHamiltonianon the tensor product subspace.alpha_strs – Spin-sector string collections matching
hsub. Each sector supports 1–128 orbitals. Use binary-string sequences or integer NumPy arrays: one-dimensionaluint64for sectors of at most 64 orbitals, shape(N, 2)uint64(lowest orbitals in column 0) for wider sectors.beta_strs – Spin-sector string collections matching
hsub. Each sector supports 1–128 orbitals. Use binary-string sequences or integer NumPy arrays: one-dimensionaluint64for sectors of at most 64 orbitals, shape(N, 2)uint64(lowest orbitals in column 0) for wider sectors.gpu_ids – Exactly one CUDA device ID for this rank, as a one-element sequence. Defaults to
(0,); choose each rank’s device explicitly.comm – MPI communicator; defaults to
MPI.COMM_WORLD.LocalCommsupports in-process workers, as used byGPUHamiltonian.process_grid –
(p_alpha, p_beta), with product equal to communicator size (num ranks).Nonechooses a grid automatically.threads_per_block – CUDA threads per kernel block; defaults to 256.
comm_backend –
"auto","nccl","host_mpi","cuda_mpi"or"inproc". Automatic selection respects GPU configuration; it triesncclfirst and falls back tohost_mpiwhen conditions are not met. Preferncclwhen available orhost_mpiotherwise.cuda_mpimay work, but is not fully validated yet.LocalCommuses the in-process backend.intra_node_size – Optional positive size of contiguous rank groups for communication.
Noneuses detected node membership.build_threads – CPU construction threads. Zero derives the count from
OMP_NUM_THREADS; positiveFQ_BUILD_THREADStakes precedence.config – Checked
GpuConfigsnapshot.NoneusesGpuConfig.from_environ()during construction.
- Raises:
NotImplementedError – Complex operators or multiple GPU IDs per rank are requested.
ValueError – Device selection, process grid, layout, electron counts, operator groups or shared settings are invalid.
ImportError – The default MPI communicator cannot be obtained because mpi4py is unavailable.
RuntimeError – Collective construction or device-memory checks fail.
Methods
compute_rdms(evec_local, *[, rank, spin_summed])Collectively compute reduced density matrices from local state-vector tiles.
Return local connection counts and estimates for comparing partition work.
Split
predicted_hbm_bytesinto allocated and not-yet-allocated bytes.rdm_scratch()Clear this rank's cached GPU connection data for rebuilding on the next matvec.
Compatibility no-op; all ranks participate directly in collective calls.
Compatibility no-op; there are no persistent workers to stop.
Collectively check predicted allocations against available GPU memory.
Attributes
HHermitian adjoint.
TTranspose.
Same source-rank tuple as
source_ranks.nccl,host_mpi,cuda_mpiorinproc.MPI or
LocalCommcommunicator used by this rank.Return a copy of this rank's construction measurements and resolved settings.
This rank's zero-based alpha coordinate in
process_grid.This rank's zero-based beta coordinate in
process_grid.Return this rank's Hamiltonian diagonal as a host NumPy
float64vector.Return a copy of this rank's latest successful matvec timing dictionary.
Lowest sampled free memory on this rank's GPU, in bytes, or None.
Number of alpha half strings in this rank's vector tile.
Number of beta half strings in this rank's vector tile.
Local vector length, equal to
n_a_local * n_b_local.Return this rank's predicted GPU memory by allocation category, in bytes.
Process grid
(p_alpha, p_beta); product equals communicator size.Return this rank's JSON-serializable settings and construction choices.
Sorted communicator ranks whose vector tiles contribute to this rank's result.
Whether this instance enables CuPy input and
outfor local matvecs.ndim- property assigned_source_ranks: tuple[int, ...]¶
Same source-rank tuple as
source_ranks.
- property backend_name: str¶
nccl,host_mpi,cuda_mpiorinproc.- Type:
Resolved backend
- property comm¶
MPI or
LocalCommcommunicator used by this rank.
- compute_rdms(evec_local, *, rank: int = 1, spin_summed: bool = False)[source]¶
Collectively compute reduced density matrices from local state-vector tiles.
Every rank supplies its part of the same real state and uses the same
rankandspin_summedoptions. All ranks receive the full result as host NumPy arrays after GPU work and communication complete. Alpha and beta must have equal orbital counts.Amplitudes are used without normalization. Scaling the full state by a real factor scales every RDM by its square. Normalize the full state before distributing it if you need RDMs for a normalized state. Spin and tensor-index conventions follow PySCF
make_rdm12s(reorder=True).- Parameters:
evec_local – NumPy-compatible or CuPy array of
n_localreal amplitudes, or shape(n_b_local, n_a_local). Uses the same beta-outer, alpha-inner tile order as the local matvec.rank – RDM order, 1 or 2; defaults to 1. This is not an MPI rank.
spin_summed – Combine alpha and beta spin blocks; defaults to False.
- Returns:
For
rank=1,(gamma_a, gamma_b)or spin-summedgamma. Forrank=2,((gamma_a, gamma_b), (G_aa, G_ab, G_bb))or spin-summed(gamma, G). Each one-particle array has shape(m, m)and each two-particle array(m, m, m, m), wheremis the common number of orbitals per sector.- Raises:
FulqrumError – A sector has more than 128 orbitals.
ValueError – The RDM order, local vector size or sector counts are invalid, or alpha and beta have different orbital counts.
- property construction_timing: dict¶
Return a copy of this rank’s construction measurements and resolved settings.
Phase times are in seconds and allocation sizes in bytes. The dictionary also includes counts, grid dimensions and execution choices. Reading it does not repeat construction or launch GPU work.
- property coord_alpha: int¶
This rank’s zero-based alpha coordinate in
process_grid.
- property coord_beta: int¶
This rank’s zero-based beta coordinate in
process_grid.
- property diag_local: ndarray¶
Return this rank’s Hamiltonian diagonal as a host NumPy
float64vector.Includes constant energy, has length
n_localand uses beta-outer, alpha-inner tile order. Suitable for the distributed solver’s local diagonal preconditioner. The array may be cached; treat it as read-only. Access may compute the diagonal or copy it from the GPU. Without CuPy, this property returns a zero array.
- property last_timing: dict¶
Return a copy of this rank’s latest successful matvec timing dictionary.
Empty before the first successful product.
wall,computeandexchangeare in seconds;comm_ms_totalis in milliseconds, and*_bytesfields are byte counts. The compute interval includes exchange, so these durations are not additive. Reading uses existing measurements only.
- property min_free_hbm_bytes¶
Lowest sampled free memory on this rank’s GPU, in bytes, or None.
Samples are recorded after construction and matvecs. This is a local sampled minimum, not a continuously measured peak or a cross-rank minimum.
- property n_a_local: int¶
Number of alpha half strings in this rank’s vector tile.
- property n_b_local: int¶
Number of beta half strings in this rank’s vector tile.
- property n_local: int¶
Local vector length, equal to
n_a_local * n_b_local.
- partition_diagnostic() dict[source]¶
Return local connection counts and estimates for comparing partition work.
- property predicted_hbm_bytes: dict¶
Return this rank’s predicted GPU memory by allocation category, in bytes.
Covers Hamiltonian buffers, tables and caches. Solver-owned storage is separate. These are the estimates used by
verify_hbm_fits, not a measurement of total device usage. Reading does not allocate GPU memory.
- predicted_hbm_split() tuple[dict, dict][source]¶
Split
predicted_hbm_bytesinto allocated and not-yet-allocated bytes.Returns
(resident, pending). Resident categories are allocated by the end of construction; pending ones are allocated lazily, mostly by the first matvec.verify_hbm_fitscompares only the pending bytes with free memory, and the sum of both with total memory.
- property process_grid: tuple[int, int]¶
Process grid
(p_alpha, p_beta); product equals communicator size.
- reset_cache() None[source]¶
Clear this rank’s cached GPU connection data for rebuilding on the next matvec.
Host-resident caches are retained. For a distributed operator, invoke this on all ranks before their next collective product.
- property run_record: dict¶
Return this rank’s JSON-serializable settings and construction choices.
Includes the resolved backend, exchange mode, process grid, tuning decisions and configuration digests. Uses existing state without GPU work or communicator collectives.
- run_workers() None[source]¶
Compatibility no-op; all ranks participate directly in collective calls.
- property source_ranks: tuple[int, ...]¶
Sorted communicator ranks whose vector tiles contribute to this rank’s result.
Includes this rank. The tuple describes source communication, not a separate set of eigensolver participants.
- property supports_device_matvec: bool¶
Whether this instance enables CuPy input and
outfor local matvecs.This reports the selected device-vector code path; it is not a separate CUDA hardware or kernel validation test.
- verify_hbm_fits()[source]¶
Collectively check predicted allocations against available GPU memory.
Call on every communicator rank. Tries to release unused CuPy device and pinned memory-pool blocks before querying free memory, then checks estimates with reserved headroom. Existing allocated buffers remain in use. Without CuPy, the memory test is skipped; ranks still participate in the collective error check.
- Returns:
None when no rank reports an overrun.
- Raises:
RuntimeError – At least one rank’s predicted allocations do not fit; the error is raised on every rank.