pyflightstream.workspace.ledger (provisional)¶
Generated from the docstrings at build time: every one of the 28 names in the __all__ of pyflightstream.workspace.ledger has an entry below. The names a guide or an example uses come first; the others follow under Advanced.
The ledger: one read-only snapshot of a workspace's records.
Pipeline role: the reader under every query verb of pyfs-matrix (FR-379 to
FR-385) and their Python mirror (FR-388). :func:read_ledger reads the run
records (runs.json, or the manifest runs names), each matrix's plan
(post/<matrix>/plan.json) and each post's product index
(post/<matrix>/products.json) once, and answers from that snapshot:
- :meth:
Ledger.status, one row per polar (a simulation and its sweep); - :meth:
Ledger.points, one row per datapoint; - :meth:
Ledger.freshness, per matrix, whether the plan and the post are current; - :meth:
Ledger.card, the effective record of one datapoint by its run id; - :meth:
Ledger.sim_folders, where a simulation's folder is, a batch's included.
Every answer is plain dictionaries and strings, so a script reads the same rows the command prints, with no data frame.
A datapoint is counted once, by its effective record, chosen by the rules of
:mod:pyflightstream.workspace._effective (FR-381), the one home the run layer
reads too. A point a plan names and no record carries is counted with the
derived status :data:PLANNED, written in lower case so that no recorded word
can be mistaken for it (FR-382, FR-384); recorded words are printed as recorded.
READ ONLY (FR-383). Nothing here writes, creates a folder, takes or waits on the
manifest lock, expands a compacted simulation or asks a scheduler: the files are
read whole, each in one call, so a writer that replaces runs.json at that
moment is neither slowed nor refused. A row of the manifest that cannot be read
is named by its position and run id and the other rows are read
(:attr:Ledger.unreadable); only a manifest that is not JSON at all is refused.
Used in the guides¶
pyflightstream.workspace.ledger.history
¶
history(
root: str | Path | Ledger,
target: str,
*,
runs: str | None = None,
) -> list[dict[str, Any]]
Return every recorded attempt with its source, archive stamp and continuation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
(str, Path or Ledger)
|
Workspace root or snapshot. |
required |
target
|
str
|
Simulation id, point name, sim_ |
required |
runs
|
str
|
Manifest name; its archived copies are read as well. |
None
|
Returns:
| Type | Description |
|---|---|
list of dict
|
History rows and explicitly identified unreadable archive rows. |
Examples:
>>> history("campaign", "2006")
pyflightstream.workspace.ledger.matrix_stem
¶
matrix_stem(value: str) -> str
Return the stem a matrix argument names: l1_g6, l1_g6.fs or a path to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
A matrix stem, file name or path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The file name without its |
Examples:
>>> matrix_stem("inputs/matrices/l1_g6.fs")
'l1_g6'
pyflightstream.workspace.ledger.status_rows
¶
status_rows(
root: str | Path | Ledger,
*,
runs: str | None = None,
sims: Iterable[str] | None = None,
matrix: str | None = None,
statuses: Sequence[str] = (),
failed: bool = False,
) -> list[dict[str, object]]
Return the polar rows printed by status --json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
(str, Path or Ledger)
|
Workspace root or an already read snapshot. |
required |
runs
|
str
|
Manifest name when reading a root. |
None
|
sims
|
iterable of str
|
Simulation ids to select. |
None
|
matrix
|
str
|
Matrix stem or file name. |
None
|
statuses
|
sequence of str
|
Recorded words, with an optional trailing wildcard. |
()
|
failed
|
bool
|
Select polars containing a failed point. |
False
|
Returns:
| Type | Description |
|---|---|
list of dict
|
JSON-serializable polar rows. |
Examples:
>>> status_rows("campaign", sims=["2006"])
Advanced¶
pyflightstream.workspace.ledger.Ledger
dataclass
¶
Ledger(
root: Path,
manifest: Path,
read_at: str,
sources: dict[str, str],
unreadable: tuple[dict[str, object], ...],
notes: tuple[dict[str, object], ...],
_entries: tuple[_Entry, ...],
_plans: dict[str, _Plan],
_records: tuple[RunRecord, ...],
_products: dict[str, dict[str, Any]],
)
One read-only snapshot of a workspace's records (FR-388).
Built by :func:read_ledger; every method answers from the snapshot and
reads no file again, except :meth:freshness (the matrices on disk) and
:meth:sim_folders (the folders), which only read.
Attributes:
| Name | Type | Description |
|---|---|---|
root |
Path
|
The workspace root. |
manifest |
Path
|
The run-record file read. |
read_at |
str
|
When the snapshot was read, ISO 8601 in UTC. |
sources |
dict of str to str
|
Each file read, relative to the root, to its modification time. |
unreadable |
tuple of dict
|
Each manifest row that could not be read: |
notes |
tuple of dict
|
The rows that are notes rather than records: |
records
¶
records() -> list[dict[str, Any]]
Return every valid present record, before effective-point selection.
Returns:
| Type | Description |
|---|---|
list of dict
|
Independent JSON-serializable copies in manifest order. |
Examples:
>>> read_ledger("campaign").records()
status
¶
status(
*,
sims: Iterable[str] | None = None,
matrix: str | None = None,
statuses: Sequence[str] = (),
failed: bool = False,
) -> list[dict[str, object]]
Return one row per polar, ordered by matrix then simulation id as a number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sims
|
iterable of str
|
Only these simulations. |
None
|
matrix
|
str
|
Only the polars of this matrix stem. |
None
|
statuses
|
sequence of str
|
Only the polars with a datapoint in one of these words; a word
ending in |
()
|
failed
|
bool
|
Only the polars with at least one failed datapoint. |
False
|
Returns:
| Type | Description |
|---|---|
list of dict
|
The keys of :data: |
points
¶
points(
*,
sims: Iterable[str] | None = None,
matrix: str | None = None,
statuses: Sequence[str] = (),
failed: bool = False,
) -> list[dict[str, object]]
Return one row per datapoint, by its effective record (status --points).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sims
|
iterable of str
|
Only these simulations. |
None
|
matrix
|
str
|
Only this matrix stem. |
None
|
statuses
|
sequence of str
|
Only the datapoints in one of these words ( |
()
|
failed
|
bool
|
Only the failed datapoints. |
False
|
Returns:
| Type | Description |
|---|---|
list of dict
|
The keys of :data: |
card
¶
card(run_id: str) -> dict[str, object] | None
Return the effective record of the datapoint whose run id is run_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
The run id of an effective point record (a job's point carries its job's prefix and its own point name). |
required |
Returns:
| Type | Description |
|---|---|
dict or None
|
The record as the manifest writes it, or None when no effective record has that run id. |
unmatched
¶
unmatched(sims: Iterable[str]) -> list[str]
Return the ids of sims that name no record and no planned point (FR-738).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sims
|
iterable of str
|
Simulation ids. |
required |
Returns:
| Type | Description |
|---|---|
list of str
|
The ids no datapoint of the snapshot carries, in the order given. |
sim_folders
¶
sim_folders(sim_id: str) -> list[str]
Return where a simulation's files are, relative to the root, without opening any.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim_id
|
str
|
The simulation id. |
required |
Returns:
| Type | Description |
|---|---|
list of str
|
|
freshness
¶
freshness(
*, matrix: str | None = None
) -> list[dict[str, object]]
Return, per matrix, whether its plan and its post are current (FR-748).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
str
|
Only this matrix stem. |
None
|
Returns:
| Type | Description |
|---|---|
list of dict
|
|
document
¶
document(
rows: Sequence[Mapping[str, object]],
) -> dict[str, object]
Return the --json document of these rows (FR-759).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
sequence of dict
|
Rows from :meth: |
required |
Returns:
| Type | Description |
|---|---|
dict
|
|
pyflightstream.workspace.ledger.POINT_COLUMNS
module-attribute
¶
POINT_COLUMNS = (
"sim",
"point",
"matrix",
"status",
"was",
"iterations",
"residual",
"wall_s",
"build",
"where",
)
pyflightstream.workspace.ledger.SIMS_IDS_HELP
module-attribute
¶
SIMS_IDS_HELP = "simulation ids: --sims 2006 2007; comma forms 2006,2007 and [2006,2007] remain accepted, including mixtures of words and bracketed lists"
pyflightstream.workspace.ledger.STATUS_COLUMNS
module-attribute
¶
STATUS_COLUMNS = (
"sim",
"polar",
"sweep",
"points",
"matrix",
"status",
)
pyflightstream.workspace.ledger.activity_rows
¶
activity_rows(
root: str | Path | Ledger,
*,
sims: Iterable[str] | None = None,
run: str | None = None,
stage: str | None = None,
since: str | None = None,
problems: bool = False,
open_only: bool = False,
) -> list[dict[str, Any]]
Return recorded activity rows oldest first, optionally selected by identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
(str, Path or Ledger)
|
Workspace root or snapshot. |
required |
sims
|
iterable of str
|
Simulation ids. |
None
|
run
|
str
|
Run id. |
None
|
stage
|
str
|
Recorded stage name. |
None
|
since
|
str
|
ISO time or duration. |
None
|
problems
|
bool
|
Only events carrying problems or failure. |
False
|
open_only
|
bool
|
Only started stages without a finish. |
False
|
Returns:
| Type | Description |
|---|---|
list of dict
|
JSON-serializable activity records. |
Raises:
| Type | Description |
|---|---|
WorkspaceError
|
If |
Warns:
| Type | Description |
|---|---|
PyflightstreamWarning
|
Naming each activity line left out: a torn or malformed line, one that is not a JSON object, or one whose timestamp is no ISO time. |
Examples:
>>> activity_rows("campaign", stage="run")
pyflightstream.workspace.ledger.additional_rows
¶
additional_rows(
root: str | Path | Ledger,
) -> list[dict[str, Any]]
Return the additional register's fields exactly as recorded (FR-393).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
(str, Path or Ledger)
|
Workspace root or snapshot. |
required |
Returns:
| Type | Description |
|---|---|
list of dict
|
Recorded entries without model defaults or derived fields. |
Raises:
| Type | Description |
|---|---|
WorkspaceError
|
If the additional register does not hold a list of records. |
Examples:
>>> additional_rows("campaign")
pyflightstream.workspace.ledger.check_status_words
¶
check_status_words(
statuses: Sequence[str], *, context: str = "statuses"
) -> None
Refuse a status word that no recorded or derived status takes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statuses
|
sequence of str
|
The words of a |
required |
context
|
str
|
Selection name to include in a refusal; defaults to |
'statuses'
|
Raises:
| Type | Description |
|---|---|
WorkspaceError
|
If a word is neither a :class: |
pyflightstream.workspace.ledger.diff
¶
diff(
root: str | Path | Ledger,
run_a: str,
run_b: str,
*,
runs: str | None = None,
) -> list[dict[str, Any]]
Return changed record fields and attributed script differences between two runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
(str, Path or Ledger)
|
Workspace root or snapshot. |
required |
run_a
|
str
|
Run ids, optionally suffixed with @ |
required |
run_b
|
str
|
Run ids, optionally suffixed with @ |
required |
runs
|
str
|
Present manifest name. |
None
|
Returns:
| Type | Description |
|---|---|
list of dict
|
Changed fields with a and b values, and script comparison availability. |
Raises:
| Type | Description |
|---|---|
WorkspaceError
|
When a selector is absent or ambiguous. |
Examples:
>>> diff("campaign", "camp/sim_2006/A0@20261001-120000",
... "camp/sim_2006/A0")
pyflightstream.workspace.ledger.latest_record_of_point
¶
latest_record_of_point(
records: Iterable[RunRecord], sim_id: str, name: str
) -> RunRecord | None
Return the most recent record of one point, in file order, whatever its status.
A continuation's run id is <campaign>/sim_<id>/r<stamp>/<name>, so the
point name still ENDS every run id of the point, which is what this reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
iterable of RunRecord
|
The records, in file order. |
required |
sim_id
|
str
|
The simulation of the point. |
required |
name
|
str
|
The point name. |
required |
Returns:
| Type | Description |
|---|---|
RunRecord or None
|
The last record of that point that is not a refused continuation. |
pyflightstream.workspace.ledger.listed_sims
¶
listed_sims(text: str | Sequence[str]) -> list[str]
Read simulation ids as delete-sims spells them: 4001,2009 or [4001,2009].
"4001 2009" selects two simulation ids. Selection separates whitespace-delimited ids
before matching records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str or sequence of str
|
The ids, comma or blank separated, with or without square brackets. |
required |
Returns:
| Type | Description |
|---|---|
list of str
|
The ids, in the order given, blanks dropped. |
Examples:
>>> listed_sims("[2006, 2007]")
['2006', '2007']
>>> listed_sims("2006 2007")
['2006', '2007']
pyflightstream.workspace.ledger.point_card
¶
point_card(
root: str | Path | Ledger,
run_id: str,
*,
runs: str | None = None,
) -> dict[str, object] | None
Return the effective record of one point, without reading archives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
(str, Path or Ledger)
|
Workspace root or snapshot. |
required |
run_id
|
str
|
Effective datapoint run id. |
required |
runs
|
str
|
Manifest name. |
None
|
Returns:
| Type | Description |
|---|---|
dict or None
|
JSON-serializable outcome-first card, or None when absent. |
Examples:
>>> point_card("campaign", "camp/sim_2006/A0")
pyflightstream.workspace.ledger.point_rows
¶
point_rows(
root: str | Path | Ledger,
*,
runs: str | None = None,
sims: Iterable[str] | None = None,
matrix: str | None = None,
statuses: Sequence[str] = (),
failed: bool = False,
) -> list[dict[str, object]]
Return the datapoint rows printed by status --points --json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
(str, Path or Ledger)
|
Workspace root or snapshot. |
required |
runs
|
str
|
Manifest name. |
None
|
sims
|
iterable of str
|
Simulation ids. |
None
|
matrix
|
str
|
Matrix stem. |
None
|
statuses
|
sequence of str
|
Recorded status filters. |
()
|
failed
|
bool
|
Select failed points only. |
False
|
Returns:
| Type | Description |
|---|---|
list of dict
|
JSON-serializable datapoint rows. |
Examples:
>>> point_rows("campaign", failed=True)
pyflightstream.workspace.ledger.post_log_groups
¶
post_log_groups(
root: str | Path | Ledger,
matrix: str,
*,
sims: Iterable[str] | None = None,
) -> list[dict[str, Any]]
Return recorded post diagnostics grouped by category, family and message shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
(str, Path or Ledger)
|
Workspace root or snapshot. |
required |
matrix
|
str
|
Matrix stem. |
required |
sims
|
iterable of str
|
Simulation ids to select. |
None
|
Returns:
| Type | Description |
|---|---|
list of dict
|
Each category, family and shape with a count and one example. |
Raises:
| Type | Description |
|---|---|
WorkspaceError
|
If the matrix's post log is not an object holding a list of records. |
Examples:
>>> post_log_groups("campaign", "sample")
pyflightstream.workspace.ledger.post_warning_category
module-attribute
¶
post_warning_category = _category
pyflightstream.workspace.ledger.post_warning_groups
module-attribute
¶
post_warning_groups = _groups
pyflightstream.workspace.ledger.read_ledger
¶
read_ledger(
root: str | Path, *, runs: str | None = None
) -> Ledger
Read one snapshot of a workspace's records, writing nothing (FR-383, FR-388).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str or Path
|
The workspace root. |
required |
runs
|
str
|
Another manifest in the root to read in place of |
None
|
Returns:
| Type | Description |
|---|---|
Ledger
|
The snapshot; its methods return plain dictionaries. |
Raises:
| Type | Description |
|---|---|
WorkspaceError
|
When the manifest is not JSON at all, or |
Examples:
>>> ledger = read_ledger("campaign")
>>> ledger.status(sims=["2006"])
pyflightstream.workspace.ledger.running_batches
¶
running_batches(
root: str | Path, rows: Iterable[Any]
) -> dict[str, set[str]]
Map every batch whose job has not ended to the simulations it holds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str or Path
|
The campaign workspace root. |
required |
rows
|
iterable
|
The run records, as mappings or as |
required |
Returns:
| Type | Description |
|---|---|
dict of str to set of str
|
Batch label ( |
pyflightstream.workspace.ledger.status_text
¶
status_text(counts: Mapping[str, int]) -> str
Return a polar's status: the one word, or the count of each word.
One word when every datapoint shares it. Otherwise each word with its count,
in the order of FR-733: the concluded words (CONVERGED,
COMPLETED_MAX_ITER, MAX_ITER_REACHED, WALLTIME_REACHED, RAN_MISSING_LOG), then the failed ones
(FAILED_*),
then SUBMITTED, then :data:PLANNED; a word no group names comes last.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
counts
|
mapping of str to int
|
Status word to the number of datapoints in it. |
required |
Returns:
| Type | Description |
|---|---|
str
|
For example |
Examples:
>>> status_text({"SUBMITTED": 2, "FAILED_DIVERGED": 1, "CONVERGED": 6})
'CONVERGED 6, FAILED_DIVERGED 1, SUBMITTED 2'
pyflightstream.workspace.ledger.trace_product
¶
trace_product(
root: str | Path | Ledger, product: str
) -> list[dict[str, Any]]
Return a product index entry and its recorded producer identities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
(str, Path or Ledger)
|
Workspace root or snapshot. |
required |
product
|
str
|
Product path relative to the workspace, or absolute. |
required |
Returns:
| Type | Description |
|---|---|
list of dict
|
Index entries with records and provenance paths; empty for an unknown path. |
Examples:
>>> trace_product("campaign", "post/sample/polar.csv")