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).
Functions
Section titled “Functions”to_arrays
Section titled “to_arrays”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
check_meta
Section titled “check_meta”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
array_bytes
Section titled “array_bytes”function
def array_bytes(arr: np.ndarray) -> bytesSource: packages/ump-workflow/src/ump_workflow/state.py, line 56
load_array
Section titled “load_array”function
def load_array(data: bytes) -> np.ndarraySource: packages/ump-workflow/src/ump_workflow/state.py, line 62
draws_of
Section titled “draws_of”function
def draws_of(value: Any, question: str) -> np.ndarrayA 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
same_draws
Section titled “same_draws”function
def same_draws(a: np.ndarray, b: np.ndarray) -> boolSource: packages/ump-workflow/src/ump_workflow/state.py, line 87
round_trip
Section titled “round_trip”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
Constants
Section titled “Constants”| Name | Type | Value | Description |
|---|---|---|---|
NAME | re.compile('^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$') | ||
RTOL | 1e-09 |