Skip to content

pyflightstream.qa.cost (stable)

Generated from the docstrings at build time: every one of the 11 names in the __all__ of pyflightstream.qa.cost has an entry below. The names a guide or an example uses come first; the others follow under Advanced.

Wall-time cost of recorded runs, gathered so two builds can be compared.

Pipeline role: a READER over campaign manifests, at the qa end of the pipeline. It executes nothing, opens no report and needs no licensed seat: its whole input is the runs.json that FR-19 already requires every campaign to write, and its output is a table in which the same sweep points measured on two solver builds sit side by side.

The gap it closes. FR-19 has recorded wall_time_s per run , beside the requested version, the reported version, the vendor build string and the sha256 of the executable that actually ran. Nothing read those five fields together, so the question "did the new build get slower" had a complete answer sitting in every campaign root and no way to ask it.

Three decisions this module makes, each of which could reasonably have gone the other way and none of which is safe to leave implicit.

A column is a (build, executable) PAIR. fs_build is what the vendor prints and fs_exe_sha256 is what ran. A hotfix rebuilt from the same source tag prints the same build string and is a different program, so keying on the build string alone would average two executables into one column and hide the regression this view exists to show. Both fields are columns of :func:cost_rows, and the pivot's column label carries the build string plus the first twelve characters of the hash.

Absence is None, never 0.0 and never math.nan. A run whose record carries no wall time is not a run that took no time. results.tables maps the same missing field to math.nan and is right to, because its substrate is a numeric frame in which every cell must be a number; this module's substrate is plain Python, its output is evidence rather than arithmetic, and a caller who sums a column here must be stopped by a TypeError rather than quietly handed a total that is short by however many runs were never timed.

A comparison sums only the work both builds did. Points timed on one build alone are reported as unpaired and kept out of both totals: a total over two different sets of points is not a comparison, and the direction of the error is the dangerous one, since the build that ran MORE points looks slower for having done more.

Units and frames: every duration in this module is a wall-clock duration in SECONDS, measured around the solver process by the run layer (run/_executors.py) with time.perf_counter. It is not CPU time, it includes process start-up and file IO, and it is therefore only comparable between runs taken on the same machine under a comparable load. No reference frame applies; nothing here is a physical quantity.

Examples:

>>> from pyflightstream.qa.cost import cost_view
>>> from pyflightstream.workspace import RunRecord, RunStatus
>>> def timed(run_id, sim_id, alpha_deg, build, sha, seconds):
...     return RunRecord(
...         run_id=run_id,
...         sim_id=sim_id,
...         point={"alpha_deg": alpha_deg},
...         fs_version_requested="26.120",
...         fs_build=build,
...         fs_exe_sha256=sha,
...         package_version="0.8.0",
...         script_sha256="0" * 64,
...         raw_flag=False,
...         status=RunStatus.CONVERGED,
...         wall_time_s=seconds,
...     )
>>> view = cost_view(
...     [
...         timed("r1", "SIM-01", 2.0, "2122026", "a" * 64, 41.0),
...         timed("r2", "SIM-01", 2.0, "2900000", "b" * 64, 63.5),
...     ]
... )
>>> [build.label for build in view.builds]
['2122026@aaaaaaaaaaaa', '2900000@bbbbbbbbbbbb']
>>> comparison = view.compare(*view.builds)
>>> round(comparison.ratio, 3)
1.549

Used in the guides

pyflightstream.qa.cost.cost_view

cost_view(source: CostSource) -> CostView

Build the wall-time cost view of one campaign's manifest.

Parameters:

Name Type Description Default
source CampaignWorkspace, str, Path, or iterable of RunRecord

A managed workspace, a campaign root whose runs.json is read, or the records themselves. Nothing else is read: no report, no output file, no solver.

required

Returns:

Type Description
CostView

Points down, solver builds across. Empty (no builds, no points) for a campaign with no recorded runs, which a caller must decide about: an empty cost table is not a fast campaign.

See Also

cost_rows : the long form, one row per run. pyflightstream.results.tables.run_table : the results-layer view of the same manifest, which carries coefficients and maps a missing wall time to math.nan.

Examples:

A campaign with no recorded run is an empty view, not a fast one; this module's top docstring compares two builds.

>>> view = cost_view([])
>>> view.builds, view.points
((), ())

Advanced

pyflightstream.qa.cost.ABSENT module-attribute

ABSENT = 'absent'

pyflightstream.qa.cost.BuildComparison dataclass

BuildComparison(
    baseline: BuildKey,
    candidate: BuildKey,
    paired: tuple[PointCost, ...] = (),
    unpaired: tuple[PointKey, ...] = (),
)

Two builds over the points BOTH of them timed.

Attributes:

Name Type Description
baseline, candidate BuildKey

The two columns compared, in that order.

paired tuple of PointCost

Points timed on both builds, in the view's row order.

unpaired tuple of PointKey

Points recorded on at least one of the two builds and timed on fewer than both. They are named rather than silently dropped, because the totals below exclude them and a reader has to know how much of the campaign the comparison did not cover.

baseline_total_s property

baseline_total_s: float

Seconds the baseline spent on the paired points.

candidate_total_s property

candidate_total_s: float

Seconds the candidate spent on the same paired points.

ratio property

ratio: float | None

Total candidate time over total baseline time; None if unknown.

None when no point is paired, so the caller cannot read "nothing to compare" as "no change".

pyflightstream.qa.cost.BuildKey dataclass

BuildKey(fs_build: str | None, fs_exe_sha256: str | None)

One column of the cost view: the solver that produced the times.

Attributes:

Name Type Description
fs_build str or None

Vendor build string as the solver reported it, from :attr:pyflightstream.workspace.RunRecord.fs_build. None for a manifest written before the field existed.

fs_exe_sha256 str or None

Hex sha256 of the executable that ran, from :attr:pyflightstream.workspace.RunRecord.fs_exe_sha256. None for a manifest that did not record it.

label property

label: str

Reading name of the column, <build>@<first 12 of sha256>.

Both halves are present even when one field is missing, so a label is always shaped the same way and a reader can tell an unrecorded field from a recorded one.

pyflightstream.qa.cost.COST_ROW_COLUMNS module-attribute

COST_ROW_COLUMNS = (
    "run_id",
    "sim_id",
    "point",
    "fs_build",
    "fs_exe_sha256",
    "status",
    "wall_time_s",
    "step_wall_times_s",
    "step_wall_time_last20_mean_s",
)

pyflightstream.qa.cost.CostCell dataclass

CostCell(
    samples: tuple[float, ...] = (),
    run_count: int = 0,
    excluded_count: int = 0,
    excluded_samples: tuple[float, ...] = (),
)

Every run recorded for one (point, build), and what they cost.

Attributes:

Name Type Description
samples tuple of float

Wall-clock seconds of each run there that recorded one AND reached an answer, in manifest order. A re-run adds a sample rather than replacing one: a manifest is evidence and the second reading does not delete the first.

excluded_samples tuple of float

Wall-clock seconds of the runs counted in excluded_count that recorded one. Kept apart, never averaged into :attr:wall_time_s (PFS-2094.003): a build that fails fast must not read as a build that answers fast.

run_count int

Runs recorded for this (point, build), timed or not.

excluded_count int

How many of them did NOT REACH AN ANSWER, which is a wider set than failure: every FAILED status, a run the wall clock stopped, and a point still in a queue. Time to a failure is time, and it is not the time to an answer; the runs are kept and counted rather than dropped, because a silent drop is a quieter lie than a reported one.

wall_time_s property

wall_time_s: float | None

Mean of the recorded samples in seconds, or None.

Over the runs that reached an answer only. None when none of them was timed. It is deliberately not 0.0 and deliberately not math.nan: see this module's top docstring.

absent property

absent: bool

True when no run there carries a wall time to an answer.

recorded property

recorded: bool

True when at least one run is recorded there, timed or not.

pyflightstream.qa.cost.CostView dataclass

CostView(
    builds: tuple[BuildKey, ...] = (),
    points: tuple[PointKey, ...] = (),
    cells: Mapping[
        tuple[PointKey, BuildKey], CostCell
    ] = dict(),
)

The pivot: sweep points down, solver builds across.

Attributes:

Name Type Description
builds tuple of BuildKey

Columns, ordered by label so a rendering is reproducible.

points tuple of PointKey

Rows, ordered by simulation id then by axis values.

cells mapping

(point, build) to :class:CostCell, sparse: a pair with no run recorded is simply absent from it.

Raises:

Type Description
QaEvidenceError

If two builds render the same label, which two hashes sharing their first twelve characters would do. Refusing is the point: a duplicated label makes one column overwrite the other in :meth:rows, which is the silent merge this view exists to prevent. It keeps ValueError as its standard-library base.

cell

cell(point: PointKey, build: BuildKey) -> CostCell

Return the runs recorded for one point on one build.

Returns an empty cell (run_count == 0) when that point was never run on that build, which is a different fact from a run that was not timed; :attr:CostCell.recorded separates them.

wall_time_s

wall_time_s(
    point: PointKey, build: BuildKey
) -> float | None

Mean wall-clock seconds there, or None when absent.

build

build(label: str) -> BuildKey

Resolve one column by its label.

Parameters:

Name Type Description Default
label str

A label as :attr:BuildKey.label renders it.

required

Returns:

Type Description
BuildKey

The column that label names.

Raises:

Type Description
QaEvidenceError

If no column carries it. The message lists the labels that do exist, because the caller typed one and the useful answer is the real ones rather than the shape of a label.

rows

rows() -> list[dict[str, object]]

Return the pivot as plain rows: identity columns, then one per build.

Returns:

Type Description
list of dict

One dict per point. Keys are "sim_id", "point" and one :attr:BuildKey.label per build; each build value is the mean wall-clock time in seconds or None when that cell is absent. Plain dicts rather than a dataframe: this layer holds no opinion about a substrate, and pandas.DataFrame(view.rows()) is one call away.

compare

compare(
    baseline: BuildKey | str, candidate: BuildKey | str
) -> BuildComparison

Put two builds side by side over the points both of them timed.

Parameters:

Name Type Description Default
baseline BuildKey or str

The two columns, as keys or as labels. The baseline is the build the other is measured against, so a ratio above 1 means the candidate is slower.

required
candidate BuildKey or str

The two columns, as keys or as labels. The baseline is the build the other is measured against, so a ratio above 1 means the candidate is slower.

required

Returns:

Type Description
BuildComparison

Carrying the paired points, the points it could not pair, and the two totals over the paired set only.

pyflightstream.qa.cost.NOT_RUN module-attribute

NOT_RUN = 'not-run'

pyflightstream.qa.cost.PointCost dataclass

PointCost(
    point: PointKey, baseline_s: float, candidate_s: float
)

One point measured on both builds of a comparison.

Attributes:

Name Type Description
point PointKey

The simulation and sweep point.

baseline_s, candidate_s float

Mean wall-clock seconds on each build.

ratio property

ratio: float | None

candidate_s / baseline_s; above 1 means slower.

None when the baseline reading is zero, which no real solver run produces and a hand-built record can.

pyflightstream.qa.cost.PointKey dataclass

PointKey(
    sim_id: str,
    axes: tuple[tuple[str, float], ...],
    job: tuple[str, ...] | None = None,
)

One row of the cost view: a simulation and the point it ran.

The point is IDENTIFIED here, not analysed. Its axes stay a sorted tuple rather than becoming columns, which is why this table has no axis-collides-with-a-fixed-column failure mode; :func:pyflightstream.results.tables.sweep_table is where an axis becomes a column and where that collision is checked.

THE AXES ARE THE AERODYNAMIC ONES AND ONLY THOSE, because the point is what the run layer recorded and the run layer records :meth:pyflightstream.cases.SweepAxis.points. A geometry variant is therefore invisible in a row: two rotations of the same mesh run under one sim_id at one alpha land in ONE cell, and :attr:CostCell.wall_time_s averages them, so the variant that got slower cannot be seen. That is not a gap to close here. It is the evidence-side half of the reason a geometric sweep is not allowed to multiply with an aerodynamic one (PFS-2025.17): a study OF the geometry is one case per geometry, and a case is a sim_id, so each geometry is a row of its own in this table and the comparison the module exists for stays askable.

Attributes:

Name Type Description
sim_id str

Simulation identifier from the manifest record.

axes tuple of (str, float)

Sweep point as (axis name, value) pairs sorted by name. Values are compared exactly, which is what makes two runs of the same matrix line land in the same row; units are the axis's own, as the case matrix declared them. Empty for a job row.

job tuple of str, optional

None for a point row. For a JOB record (a steady matrix row run as one sweep, its run id ending in :data:~pyflightstream.workspace.JOB_TAG) the tags of the points it ran, in the order it ran them, possibly none. A job's wall time is the whole sweep's, so its row is the job and never its first point (PFS-2094.002).

label property

label: str

Reading name of the point, alpha_deg=2.0, beta_deg=0.0.

The value is rendered with repr, which round-trips a float exactly, rather than with a fixed precision. This label is an IDENTITY and two points a hair apart are two rows; :g would have printed six significant digits and given them one name. A job row reads sweep of 3 points: AL+000, AL+002, AL+004.

point property

point: dict[str, float]

The sweep point as the manifest carried it.

pyflightstream.qa.cost.cost_rows

cost_rows(source: CostSource) -> list[dict[str, object]]

Return the long form of the same evidence: one row per run.

Where :func:cost_view pivots so two builds can be read across, this keeps the manifest's own shape and spells fs_build and fs_exe_sha256 as ordinary columns, with the FULL hash rather than a label prefix.

Parameters:

Name Type Description Default
source CampaignWorkspace, str, Path, or iterable of RunRecord

As :func:cost_view.

required

Returns:

Type Description
list of dict

One dict per run, in manifest order, which is the order the campaign recorded them in and therefore the evidence order. Keys are :data:COST_ROW_COLUMNS; wall_time_s is the seconds the record holds or None where the run recorded none. A solver run records no zero; a hand-built record that holds one is passed through unchanged.