kups.core.neighborlist.adaptive
¶
Adaptive cutoff neighbor list with per-call, cost-based dispatch.
:class:AdaptiveNeighborList is itself a NeighborList[Literal[2]]. It holds
a tuple of (implementation, cost) pairs where each cost is a
:class:NeighborListCost -- a numerical estimate of that implementation's
runtime for a given call. On every __call__ it evaluates each cost from the
call's particle and system counts and dispatches to the cheapest implementation,
so a single object routes differently across calls.
The :meth:AdaptiveNeighborList.new / :meth:AdaptiveNeighborList.from_state
classmethods seed the tuple with the library implementations
(:class:DenseNearestNeighborList, :class:CellListNeighborList,
:class:AllDenseNearestNeighborList) and their default cost guesses. Augmenting
the set is just appending another (implementation, cost) pair to
implementations; all implementations are built from one lens, so they share
the UniversalNeighborlistParameters capacities.
Costs use coarse counts rather than cutoff or box geometry: counts are static at trace time, so the dispatch is a plain Python branch that compiles only the selected implementation.
AdaptiveNeighborList
¶
Bases: NeighborList[Literal[2]]
Neighbor list that dispatches to the cheapest backing implementation.
Holds (implementation, cost) pairs and, on each call, picks the
implementation whose :class:NeighborListCost is smallest for that call's
counts. Augment by appending pairs to :attr:implementations; the seeded
implementations share the UniversalNeighborlistParameters capacities, so
growing one grows the shared state.
Attributes:
| Name | Type | Description |
|---|---|---|
implementations |
tuple[NeighborListCandidate, ...]
|
Candidate :class: |
Source code in src/kups/core/neighborlist/adaptive.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
from_state(state, cutoffs)
classmethod
¶
Seed from a state exposing neighborlist_params.
Source code in src/kups/core/neighborlist/adaptive.py
new(state, lens, cutoffs)
classmethod
¶
Seed the library implementations with their default cost guesses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
S
|
Object exposing |
required |
lens
|
Lens[S, IsUniversalNeighborlistParams]
|
Lens focusing the shared |
required |
cutoffs
|
Table[SystemId, Array]
|
Per-system cutoffs bound onto each implementation. |
required |
Returns:
| Type | Description |
|---|---|
AdaptiveNeighborList
|
An |
Source code in src/kups/core/neighborlist/adaptive.py
NeighborListCandidate
¶
A backing neighbor list paired with its cost estimator.
Attributes:
| Name | Type | Description |
|---|---|---|
neighborlist |
NeighborList[Literal[2]]
|
The candidate implementation. |
cost |
NeighborListCost
|
Estimates the implementation's cost for a call's counts. |
Source code in src/kups/core/neighborlist/adaptive.py
NeighborListCost
¶
Bases: Protocol
Estimates the relative runtime cost of a neighbor list for one call.
Lower is cheaper; :class:AdaptiveNeighborList dispatches to the minimum.
Return math.inf to mark an implementation invalid for the given shape.
Source code in src/kups/core/neighborlist/adaptive.py
all_dense_cost(num_particles, num_systems)
¶
Default cost for :class:AllDenseNearestNeighborList.
O(N^2) across all particles, so it ties dense for a single system and is
invalid (inf) for multiple systems, which it would incorrectly merge.
Source code in src/kups/core/neighborlist/adaptive.py
cell_list_cost(num_particles, num_systems)
¶
Default cost for :class:CellListNeighborList (O(N) with a large
constant, crossing dense at _CELL_LIST_CROSSOVER particles per system).
Source code in src/kups/core/neighborlist/adaptive.py
dense_cost(num_particles, num_systems)
¶
Default cost for :class:DenseNearestNeighborList (O(N^2/K)).