Skip to content

ump_workflow

package ump-workflow

UMP workflow bundles: save a fitted analyst workflow as a hashed folder of data and source, and rerun it on new data of the same necessary shape (score by default, a labelled refit or the Tier D summary otherwise).

Never pickles. Depends only on ump-spec, finprint, numpy and pandas.

Read the ump-workflow guide first for the main entry points.

ModuleWhat it holds
ump_workflow.answersAnswers from per-draw values: point, interval and the estimand, with horizons recomputed from the data.
ump_workflow.bundleThe bundle format (ump.workflow_bundle/0.1): a folder of data and source, never pickles.
ump_workflow.cliump-workflow: inspect, check, run and serve a bundle from the terminal.
ump_workflow.envThe environment pin: which versions a bundle was saved with, and how the running ones compare.
ump_workflow.errorsThe codes this runtime raises or notes. All are registered in ump_spec’s error_codes.yaml (source packages/ump-workflow); ump-spec’s tests/test_registry_additions.py scans this package for drift.
ump_workflow.loaderOpen a bundle in the load order S4 fixes, then run it on new data (S2: score by default).
ump_workflow.profileThe pandas side of ump_spec.rules.check_input: build the FrameProfile it reads, infer a contract from a training frame, and apply an InputReport to a frame (moved here from babelfin’s _contract.py so the runtime checks contracts without babelfin).
ump_workflow.savesave_workflow: fit the analyst’s module on training data and write a bundle.
ump_workflow.serveServe one workflow bundle as an app speaking UMP’s engine adapter contract (feature workflow-bundles, T7, S6).
ump_workflow.shareShare a bundle through ump-core (S6): pure helpers, no network code.
ump_workflow.stateFitted state as JSON plus plain numeric arrays, and the save-time round trip (S7).

Documented on the page of the module that defines them.

NameKindSummary
BUNDLE_FORMATconstant
CODESconstant
ApprovalTrustclassWhat an approval vouches for: hashes (code and prep-step sha256) or an empty set with a reason code (WORKFLOW_SHARE_NOT_APPROVED, WORKFLOW_SELF_APPROVED, WORKFLOW_SHARE_MISMATCH) and detail.
BundleDataclassA verified bundle, parsed. Nothing here has run the bundle’s code.
EnvReportclassdrift: one row per differing package (package, pinned, running, level); notes in the input-note shape; score_ok false on any major drift.
OpenBundleclassA verified bundle. .module exists only once the code is trusted.
RunResultclassroute: where the rerun went (score, refit, not_available); source: where the answers came from (score, refit or summary); answers: {name: {value, lo, hi, level, draws_summary, estimand, proposed}}; rows: rows used after the contract’s exclusions; history_end: the last period of the input that was run (the bundle’s training end when the answers are the summary’s).
WorkflowErrorclassA refusal with a registered code. str() is the code and the plain-words message.
build_summaryfunctionA Tier D model_manifest doc of the fit-time answers that have a summary_ref.
bundle_filesfunction{relpath: bytes} of every file in a verified bundle, workflow.json and SHA256SUMS included. Each file is read again and checked against the hashes the bundle was verified with (a file changed since the read is BUNDLE_TAMPERED).
bundle_manifest_refsfunctionThe payload_refs map of a shared bundle: workflow_bundle (sha256: of workflow.json, the bundle’s id) and file:<relpath> = sha256:<hex> for every file.
clean_framefunctionA new frame with the excluded rows removed (rows at a new category level, matched by level hash, and rows with no time or category value), drop_columns dropped and the coerce casts applied. The input is not changed. Missing values in variables are left for the caller’s stated policy.
compare_envfunctionCompare a bundle’s pin with the running versions (running overrides the lookup, for a known set).
contract_from_framefunctionInfer a contract from a training frame: every non-time, non-target, non-category column is a required variable with the frame’s dtype (missing: forbid unless it already has nulls). categories maps a column to its policy (a list means fixed); when None, string columns are fixed categories. Fixed categories get their level set (hash and count). freq is inferred from the time column when not given.
env_pinfunctionVersions to pin for a bundle whose code is source.
is_principal_idfunctionTrue for a principal id such as user:maya.chen (the rule save_workflow enforces on author); a bare name or an email is not one.
level_hashfunctionsha256 (hex) of one level’s canonical JSON string.
level_setfunctionsha256 (hex) of the canonical JSON of the sorted unique non-null values as strings, their count, and the sorted sha256 of each level. Never the values.
load_modulefunctionExecute source as a fresh module called name (registered in sys.modules while it runs, as dataclasses and pickle-free introspection need). No file is imported and no bytecode is written.
manifest_docfunctionThe draft Tier A model_manifest doc of a shared bundle: name, client, engine ump-workflow, family, estimands, summaries and dependence from summary.json, input_contract from contract.json, payload_refs from bundle_manifest_refs and the share note.
materializefunctionRebuild a bundle folder at dest (which must not exist) from {relpath: bytes} and verify it through read_bundle; with refs (a payload_refs map) the rebuilt bundle must also match them exactly. A wrong or missing blob refuses (BUNDLE_TAMPERED) and an unsafe path (absolute, .., a backslash) is BUNDLE_INVALID; on any refusal nothing is left behind.
module_importsfunctionSorted third-party top-level package names source imports anywhere (relative and stdlib excluded).
open_bundlefunctionVerify and parse a bundle (no code runs). trust_code=True trusts its module for this object only; trust_steps=True trusts its prep recipe’s named-step code (.step_code) for this object only. trusted_hashes (sha256 hex, as share.trusted_hashes_from_approval returns) trusts the module and each named step whose hash it names, for this object only: never written to the machine’s trust store.
profile_framefunctionWhat check_input reads about df: no row values, only dtypes, counts and hashes.
read_bundlefunctionVerify every file’s hash, then parse (data only: no code runs). Only SHA256SUMS and workflow.json are read before the file lists are compared, so an unlisted file is refused unread.
round_tripfunctionSave 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.
save_workflowfunctionFit, check and write a workflow bundle at path; returns the bundle folder.
summary_answersfunctionAnswers read from the Tier D summary, and the questions it holds no number for. Each answer carries its own question’s estimand (fit_estimand, else its template), never the summary’s per-metric one.
to_arraysfunctionEach value through numpy.asarray; refuses object or structured dtypes and names that are not plain.
training_statsfunctionworkflow.json’s training block: rows and time range of the raw input data, history_end (the last period, which a score must follow on from) and the min and max of every numeric contract variable on the prepped frame (channel_ranges, read by the out-of-support check).
trusted_hashes_from_approvalfunctionThe code and prep-step hashes a core envelope vouches for, checked against bundle. Trust is given only when the envelope is a model_manifest of engine ump-workflow in state validated (its head version is the validated one), approved_by is present and is none of the owner, the submitter and the bundle’s author, and the doc’s payload_refs and recorded code_sha256 / step_sha256 match the bundle exactly. Otherwise an empty set with a reason code.
write_bundlefunctionWrite a bundle folder at path (which must not exist). Everything is written to a temporary sibling and renamed into place, so a refusal leaves nothing behind. workflow holds name, version, seed, params, training and optionally author, created_at, tier, dependence, notes; the rest is filled here. code is the module’s bytes as the caller ran them (read once); without it code_path is read here. code_path always gives the file name.
NameTypeValueDescription
__version__'0.1.0'