Skip to content

ump_workflow.state

module ump-workflow

Fitted state as JSON plus plain numeric arrays, and the save-time round trip (S7).

The analyst’s module returns to_state(model) -> (meta, arrays): meta is JSON-safe, arrays maps a name to anything numpy.asarray reads (a NumPy array, a list, a jax.Array, a torch tensor with __array__). Object dtype is refused (STATE_NOT_PLAIN) because saving it would need pickle. Arrays are written and read with allow_pickle=False. Before a bundle is written, round_trip rebuilds the model from its saved form and requires the same answers on the training data (WORKFLOW_STATE_LOSSY otherwise).

function

def to_arrays(arrays: Mapping[str, Any]) -> dict[str, np.ndarray]

Each value through numpy.asarray; refuses object or structured dtypes and names that are not plain.

Source: packages/ump-workflow/src/ump_workflow/state.py, line 26

function

def check_meta(meta: Any) -> dict[str, Any]

meta as plain JSON (a dict); refuses values JSON cannot hold exactly (objects, NaN, infinity).

Source: packages/ump-workflow/src/ump_workflow/state.py, line 45

function

def array_bytes(arr: np.ndarray) -> bytes

Source: packages/ump-workflow/src/ump_workflow/state.py, line 56

function

def load_array(data: bytes) -> np.ndarray

Source: packages/ump-workflow/src/ump_workflow/state.py, line 62

function

def draws_of(value: Any, question: str) -> np.ndarray

A question’s per-draw values as a 1-D float array. One number (a scalar, or fewer than two draws) is refused with QUESTION_NOT_DRAWS: an answer needs draws to carry an interval, never a bare point. So is an array of two or more dimensions (draws by channel, by week, even (n, 1)): flattening it would mix draws with another axis, so the question must reduce it to one value per draw itself.

Source: packages/ump-workflow/src/ump_workflow/state.py, line 67

function

def same_draws(a: np.ndarray, b: np.ndarray) -> bool

Source: packages/ump-workflow/src/ump_workflow/state.py, line 87

function

def round_trip(
to_state: Callable[[Any], Any],
from_state: Callable[[dict[str, Any], dict[str, np.ndarray]], Any],
model: Any,
answer: Callable[[Any], dict[str, np.ndarray]],
) -> tuple[dict[str, Any], dict[str, np.ndarray]]

Save model as it would be written, rebuild it with from_state and compare answer(model) with answer(rebuilt) (allclose, rtol 1e-9, atol 0). Returns the plain (meta, arrays) to write.

Source: packages/ump-workflow/src/ump_workflow/state.py, line 91

NameTypeValueDescription
NAMEre.compile('^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$')
RTOL1e-09