Skip to content

pyflightstream.run.records (provisional)

Generated from the docstrings at build time: every one of the 4 names in the public definitions (the module declares no __all__) of pyflightstream.run.records has an entry below. The names a guide or an example uses come first; the others follow under Advanced.

The run records of a workspace: which manifest, its restore and its rebuild.

Pipeline role: the run row, beside the manifest the run stage writes. It is the home of three operations on the records of a campaign workspace (work package B1; the packages that call it, B2 with the sync and B3 with the post and collect reading --runs, code against the same signatures):

  • :func:resolve_manifest names the manifest file a command reads: the default runs.json, or another file directly in the workspace root (pyfs-matrix post --runs NAME and its siblings). it is defined in :mod:pyflightstream.workspace.naming and re-exported here (AD-09), so the storage layer below this one reads it without reaching up.
  • :func:restore brings a file of the records family back from the workspace's archive, EXACTLY: the manifest, the storage record, a matrix's products record, the plan receipt or the additional-post record (the kinds of :data:RESTORE_KINDS). It previews unless asked to apply, and archives the current file before it replaces it, so a restore can itself be undone.
  • :func:rebuild makes run records AGAIN from the simulation folders under sims/ when no archive holds them. It is not a restore and every record it makes says so in its warnings.

The two operations carry two names on purpose (GEO-066, R2): a reader must never trust a rebuilt record as the one written when the point ran.

How a record is rebuilt, and what proves it. The matrix row is run again through this package's own campaign loop in a throwaway SHADOW workspace (a copy of inputs/ and of the matrix in a temporary folder), with a submitting executor that submits nothing, which mints the SUBMITTED record the cluster path writes. The proof of identity is the executed script: the script on disk under sims/sim_<id>/scripts/ must be the script THIS package version renders for that row, once the workspace root and the interpreter path are set aside on both sides; otherwise the simulation is refused, naming the version and, line by line, which input the difference comes from. The record is then completed by the package's own collect stage run READ-ONLY over the files already on disk (:func:collect_without_writing): a collection that would move, copy, translate or expand a file is not done, and the record stays SUBMITTED for pyfs-matrix collect. The whole workspace tree is compared before and after, and nothing is written when it changed.

Deliberately NOT rebuilt: a simulation stored compressed, one whose record a known run of another package version wrote, one whose row no matrix holds (it waits for the revision that ran, matrix), one whose executed script differs, and one with no declared output. A SUBMITTED record is pointed to pyfs-matrix collect unless every simulation is rebuilt (all_sims), which judges each from its outputs instead.

The post and the collect of other records (work package B3): :func:manifest_workspace is the workspace post --runs NAME and collect --runs NAME read, :func:assemble_records assembles the records of post --from-sims in memory from the simulation folders, and :func:from_sims_workspace is the workspace that post reads. Both kinds are a :class:ManifestWorkspace, whose products go to post/<matrix>@<label>/ beside the default ones and never over them.

FIVE MODULES (AD-11). This one holds :func:restore and :func:mark_failed and keeps every public name of the records family at its public path. The record files, their archives, the lease and :class:RecordsError are :mod:pyflightstream.run._record_files; what a rebuild reads and compares is :mod:pyflightstream.run._rebuild_evidence; the rebuild itself is :mod:pyflightstream.run._rebuild; the assembly of other records for the post is :mod:pyflightstream.run._assemble. Each imports only ones before it and none imports this module, so there is no import cycle among them. The machinery the rebuild drives and the collect's assessor are imported inside the functions that call them. The collect stage is made read-only by replacing its three writes with refusals for the length of one call, under a lock (:func:collect_without_writing); nothing else of the stage is changed.

Advanced

pyflightstream.run.records.mark_converged

mark_converged(
    root: str | Path,
    sims: Sequence[str],
    *,
    reason: str,
    points: Sequence[str] | None = None,
    apply: bool = False,
) -> dict[str, Any]

Record a person's verdict of CONVERGED on the named points (FR-414).

Parameters:

Name Type Description Default
root str or Path

The workspace root.

required
sims sequence of str

Simulation ids; each may hold several, comma separated.

required
reason str

Why the person judges them converged, recorded as given; required.

required
points sequence of str

Point names; only the records of these points of the named simulations are marked. Without it every point of them is.

None
apply bool

Write. Without it nothing changes and the result says what would.

False

Returns:

Type Description
dict

applied, marked (per point: sim_id, run_id, from), already (the run ids already CONVERGED, left as they are), refused (by run id or sim_<id>, the reason and remedy), reason and, when applied, runs_archived_as.

Raises:

Type Description
RunsManifestError

No reason, no simulation named, no runs.json, a simulation or a point no record names, an unresolved run id alias (2006_3); applying while any point is refused, naming each, with nothing written.

AliasError

An alias the records and the plan read differently, or that names no point, as mark-failed refuses it.

pyflightstream.run.records.mark_failed

mark_failed(
    root: str | Path,
    sims: Sequence[str],
    *,
    reason: str | None = None,
    apply: bool = False,
    points: Mapping[str, Sequence[str]] | None = None,
) -> dict[str, Any]

Mark every record of the named simulations FAILED_MARKED (FR-309).

A run can end CONVERGED and still be wrong, which the person finds only later, reading its products. The record is not deleted: its status becomes FAILED_MARKED, and marked keeps the status it had, when it was marked and the reason given, so the post, the cost estimate and delete-sims treat it as any failure and the history stays. A steady job is marked per point: each points_ran entry marked takes the status and its own marked, and the job takes its worst point's status; a job marked whole keeps marked at its top as well.

Parameters:

Name Type Description Default
root str or Path

The workspace root.

required
sims sequence of str

Simulation ids. An id with no record in runs.json is refused by name before anything is written.

required
reason str

Why the runs are marked, recorded as it is given.

None
apply bool

Write. Without it nothing changes and the result says what would.

False
points mapping of str to sequence of str

Per simulation, the point names whose records alone are marked (a run id alias, FR-395); a simulation also in sims is marked whole.

None

Returns:

Type Description
dict

applied, marked (per point: sim_id, run_id, from; a point of a steady job by its own run id), already (the run ids already FAILED_MARKED, left as they are) and, when applied, runs_archived_as.

Raises:

Type Description
RunsManifestError

No runs.json, no simulation named, an id with no record, or a point of points that no record holds.

pyflightstream.run.records.rebuild

rebuild(
    root: str | Path,
    *,
    out: str | None = None,
    all_sims: bool = False,
    sims: Sequence[str] | None = None,
    build_alias: Mapping[str, str] | None = None,
    matrix: str | Path | None = None,
    apply: bool = False,
    inputs_from: str | Path | None = None,
) -> dict[str, Any]

Rebuild run records from the simulation folders under sims/.

Each record is minted again by this package from the matrix row, proved by the executed script being the one this version renders for that row, and completed by the collect stage over the files on disk, read-only (the module docstring says how). A record the rebuild makes carries a warning starting with REBUILT that says what was reconstructed and with which version.

Parameters:

Name Type Description Default
root str or Path

The workspace root.

required
out str

The manifest file the rebuilt records go to, a name :func:resolve_manifest accepts, never runs.json and never a file that exists: both refused before any work. With it runs.json is never touched: the file holds the rows of runs.json with each rebuilt record in the place of the row of its run id, and the other rebuilt records after them (with all_sims, the rebuilt records only). Without it, applying appends the rebuilt records whose run ids runs.json does not hold, after archiving runs.json to archive/runs-<stamp>.json, or writes runs.json when there is none.

None
all_sims bool

Rebuild EVERY simulation folder on disk, recorded or not, so the result can be compared with runs.json; requires out. A SUBMITTED status in runs.json is then ignored and each simulation takes the status its outputs support, except a folder written within :data:QUIET_WINDOW_S, which stays SUBMITTED. Without it only the simulations no record names are rebuilt, and each SUBMITTED record is pointed to pyfs-matrix collect rather than given an end.

False
sims sequence of str

The simulation ids to rebuild, recorded or not.

None
build_alias mapping of str to str

The scheduler name a solver build had when it ran, keyed by the build, for a build the submission profile no longer maps; the default is the build itself. It enters only the job descriptor of the shadow run, never the solver script, and the record says which alias was assumed.

None
matrix str or Path

The matrix revision the simulations ran from, for a POL no current matrix holds (a row deleted or renumbered after it ran). Name the file as the matrix was named when it ran. Without it every matrix at the root and in inputs/matrices/ is read.

None
apply bool

Write the manifest; without it the call previews and writes nothing.

False
inputs_from str or Path

Another origin's inputs/ folder (another workspace's, a copy from the cluster) whose files are laid over this workspace's in the shadow, for inputs that changed after the run. Each record names the inputs it took from there whose bytes differ from the workspace's; the workspace's own files are never changed.

None

Returns:

Type Description
dict

target (the manifest applying writes), applied, written, archived_as, package_version, rebuilt (sim, run id and status per record), records (the rebuilt records), refused (by sim, the reason), submitted (the SUBMITTED run ids pointed to collect), waiting_for_matrix (the sims no matrix row names), never_ran, build_aliases and notes.

Raises:

Type Description
RunsManifestError

out is not a file name directly in the root.

RecordsError

all_sims without out, or with sims; out naming runs.json or a file that exists; a matrix or inputs_from that is not there; no sims/; a run holding runs.json.lock; applying when nothing was rebuilt, when the workspace tree changed during the rebuild, or when runs.json changed meanwhile.

pyflightstream.run.records.restore

restore(
    root: str | Path,
    kind: str,
    *,
    stamp: str | None = None,
    apply: bool = False,
    matrix: str | None = None,
) -> dict[str, Any]

Restore one file of the records family from the workspace's archive.

Exact and cheap: the archived bytes become the file again, unchanged. The archive forms read are archive/runs-<stamp>.json, where sync, --force-rerun, delete-sims, rename, mark-failed and mark-converged copy the manifest before rewriting it; in the same form archive/storage_management-<stamp>.json and archive/additional-<stamp>.json; and, beside a matrix's products, post/<matrix>/archive/<stamp>/products.json and .../plan.json. Every restore that applies archives the file it replaces in these forms. The writers of the storage record, the products record, the plan receipt and the additional-post record archive their file before rewriting it (workspace.naming.archive_previous, the one home of these names), so every kind has copies to bring back; products.json is archived rather than removed when a post rebuilds. A copy numbered within one stamp (runs-<stamp>.2.json) or labelled after it (runs-<stamp>-before-doctor.json) is found too.

Parameters:

Name Type Description Default
root str or Path

The workspace root.

required
kind str

One of :data:RESTORE_KINDS: runs (runs.json), storage (storage_management.json), additional (additional.json), products (post/<matrix>/products.json) or plan (post/<matrix>/plan.json).

required
stamp str

The archive stamp to restore from, YYYYMMDD-HHMMSS as the archive spells it, or the whole numbered or labelled stamp. The copy of exactly that name is taken; a bare stamp that no plain copy carries takes the newest numbered or labelled copy of it. None takes the newest copy.

None
apply bool

Change files; without it the call previews and changes nothing. With it the current file, when there is one, is archived first under the same form, so the restore can be undone by restoring that copy.

False
matrix str

For products and plan, the matrix stem whose file to restore; needed only when archives exist for several matrices.

None

Returns:

Type Description
dict

kind, target and source (paths relative to the root), stamp, stamps_available, same (the current file already holds the archived bytes), applied, archived_as (where the current file went, or None) and, for runs, records (the rows the archived manifest holds).

Raises:

Type Description
RecordsError

An unknown kind; no archived copy (naming where it was looked for); a stamp no copy carries (naming the stamps that exist); archives for several matrices and none named; a matrix that is not a bare folder name under post/; an archived copy that is not readable JSON, or a manifest copy that is not a list of records; an applying restore of any kind while runs.json.lock is held (a run, a collect or a sync writing in the workspace), or while the restored file's own lease is held (storage_management.json.lock, additional.json.lock). The write itself holds those leases (RST-6).