kups.application.utils.propagate
¶
Shared propagation utilities for simulation loops.
Provides warmup, sampling, and data-parallelism helpers used across MD, MCMC, and relaxation application modules.
make_cycle_function(propagator)
¶
JIT a propagator into a reusable per-cycle function with state donation.
Pass the result as cycle_fn to both :func:run_warmup_cycles and
:func:run_simulation_cycles so a single traced-and-compiled program is shared
across the warmup and sampling phases. For blocked stepping, compose the propagator
with :class:~kups.core.propagator.LoopPropagator before passing it in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
propagator
|
Propagator[State]
|
Step propagator to compile. |
required |
Returns:
| Type | Description |
|---|---|
CycleFunction[State]
|
A jitted |
Source code in src/kups/application/utils/propagate.py
propagate_and_fix(fn, key, state, *, max_tries=10)
¶
Execute a propagator repeatedly until all assertions pass or retries are exhausted.
On each attempt, failed assertions are repaired via their fix functions. Raises if a failed assertion has no fix function or retries run out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[Array, State], Result[State, State]]
|
Assertion-aware propagator produced by :func: |
required |
key
|
Array
|
JAX PRNG key. |
required |
state
|
State
|
Current simulation state. |
required |
max_tries
|
int
|
Maximum number of repair attempts. |
10
|
Returns:
| Type | Description |
|---|---|
State
|
Propagated state with all assertions satisfied. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If called inside a JAX transform. |
RuntimeError
|
If assertions still fail after |
Source code in src/kups/core/propagator.py
propagator_with_assertions(propagator)
¶
Wrap a propagator to capture assertion results alongside the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
propagator
|
Propagator[State]
|
Propagator to wrap. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Array, State], Result[State, State]]
|
Function returning a Result that pairs the new state with assertion metadata. |
Source code in src/kups/core/propagator.py
run_simulation_cycles(key, cycle_fn, state, num_cycles, logger, *, convergence_fn=None)
¶
Run simulation steps with logging and optional early stopping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
JAX PRNG key for stochastic propagators (e.g. MD thermostats). |
required |
cycle_fn
|
CycleFunction[State]
|
Compiled per-cycle function from :func: |
required |
state
|
State
|
Initial state. |
required |
num_cycles
|
int
|
Maximum number of steps. |
required |
logger
|
Logger[State]
|
Logger receiving state each step. |
required |
convergence_fn
|
Callable[[State], bool] | None
|
If provided, called after each step; stops early when it returns True. |
None
|
Returns:
| Type | Description |
|---|---|
State
|
State after all steps or early convergence. |
Source code in src/kups/application/utils/propagate.py
run_warmup_cycles(key, cycle_fn, state, num_cycles)
¶
Run warmup propagation cycles without logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
JAX PRNG key. |
required |
cycle_fn
|
CycleFunction[State]
|
Compiled per-cycle function from :func: |
required |
state
|
State
|
Initial simulation state. |
required |
num_cycles
|
int
|
Number of warmup steps. |
required |
Returns:
| Type | Description |
|---|---|
State
|
State after warmup. |