Skip to content

pyflightstream.workspace.costs (provisional)

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

The per-machine cost file of a workspace: inputs/costs/c<NNN>.toml (FR-398).

Run cost depends on the machine and the mesh, so the measured values of a machine belong to its user and never to the package. A workspace may carry one file per machine under costs/; :func:read_cost_file reads one into a :class:CostFile, refusing an unknown or misplaced key by name, and :func:resolve_cost_file finds the one a plan names. :func:estimate_seconds turns a file and a point's figures into an expected wall time::

seconds = reference.wall_time_s
          x (faces / reference.mesh_faces) ** mesh.exponent_b
          x (steps / reference.steps) ** steps.exponent
          x speedup(reference.ncpus) / speedup(ncpus)
          x product of the multipliers of the flags the point sets

The efficiency curve [parallel] is a table of ncpus against speedup, interpolated linearly between its stated points. A processor count outside the stated range is NEVER extrapolated: the estimate is withheld and the basis says why. The package ships only a synthetic example (examples/costs/c000.toml); :func:unmarked_cost_files is the guard that every cost file a tree tracks says so.

Advanced

pyflightstream.workspace.costs.COSTS_DIR module-attribute

COSTS_DIR = 'costs'

pyflightstream.workspace.costs.CostEstimate dataclass

CostEstimate(seconds: float | None, basis: str)

The expected wall time of one point under a cost file.

Attributes:

Name Type Description
seconds float or None

The estimate, None when the file cannot answer for this point.

basis str

One sentence naming what the figure rests on, or why there is none.

pyflightstream.workspace.costs.CostFile dataclass

CostFile(
    path: Path,
    machine: dict,
    reference: dict,
    ncpus: tuple[float, ...],
    speedup: tuple[float, ...],
    fit: tuple[float, float] | None = None,
    mesh_exponent: float = 1.0,
    steps_exponent: float = 1.0,
    flags: dict[str, float] = dict(),
)

One machine's cost model (FR-398).

Attributes:

Name Type Description
path Path

Where it was read from, for a refusal that has to name it.

machine dict

name and fs_build of the machine.

reference dict

The anchor run: wall_time_s, mesh_faces, ncpus and optionally steps, pol and run_type.

ncpus tuple of float

The processor counts of the efficiency curve, ascending.

speedup tuple of float

The speedup stated at each of ncpus.

fit tuple of float or None

(a, c) of speedup = a N^c when the file states it; recorded, never used to extrapolate.

mesh_exponent float

The exponent b of the face count.

steps_exponent float

The exponent of the step count.

flags dict of str to float

The multiplier of each solver flag.

speedup_at

speedup_at(ncpus: float) -> float | None

Interpolate the efficiency curve at ncpus, or None outside its range.

Parameters:

Name Type Description Default
ncpus float

Processor count.

required

Returns:

Type Description
float or None

The speedup, linear between the two stated points around ncpus; None when ncpus lies outside the stated range.

pyflightstream.workspace.costs.SYNTHETIC_WORD module-attribute

SYNTHETIC_WORD = 'synthetic'

pyflightstream.workspace.costs.cost_files

cost_files(inputs_dir: str | Path) -> list[Path]

Every cost file a workspace carries, sorted.

Parameters:

Name Type Description Default
inputs_dir str or Path

The workspace inputs/ directory.

required

Returns:

Type Description
list of Path

The c<digits>.toml files of its costs/ folder; empty when none.

Raises:

Type Description
InputArtifactError

If the folder holds a c*.toml file whose name is not c and digits, which names the file and the expected pattern.

pyflightstream.workspace.costs.estimate_seconds

estimate_seconds(
    cost: CostFile,
    *,
    faces: int | None,
    steps: int | None,
    ncpus: int | None,
    flags: Collection[str] = (),
) -> CostEstimate

Estimate the wall time of one point under cost (FR-398).

A figure the point does not state (faces, steps, ncpus) leaves its factor at one and the basis says so; a processor count outside the stated range of the efficiency curve withholds the estimate rather than extrapolating.

Parameters:

Name Type Description Default
cost CostFile

The machine's model.

required
faces int or None

The mesh face count of the point.

required
steps int or None

The time steps of the point; None for a steady row.

required
ncpus int or None

The processors the point sets.

required
flags collection of str

The solver flags the point sets; each one the file states multiplies.

()

Returns:

Type Description
CostEstimate

The seconds, or None with the reason in basis.

pyflightstream.workspace.costs.priced_rows

priced_rows(
    rows: Sequence,
    cases_by_run_id: Mapping[str, object],
    inputs_dir: str | Path | None,
)

Replace the fitted time of each cost row by the cost file's, when the workspace has one.

FR-398. Without a cost file the rows come back as they are, which is what preserves the plan --cost output format. A point the file cannot answer for (a processor count outside its stated range) keeps no number and a warning names it.

Parameters:

Name Type Description Default
rows sequence of PlannedPointCost

The rows the recorded-run fit produced.

required
cases_by_run_id mapping

The case of each run id, specialised to its point.

required
inputs_dir str or Path or None

The workspace inputs/ directory; None (a stand-in without one) prices nothing.

required

Returns:

Type Description
list

The rows, with seconds, samples and basis of the cost file's estimate where the workspace carries one.

pyflightstream.workspace.costs.read_cost_file

read_cost_file(path: str | Path) -> CostFile

Read one cost file, refusing an unknown or malformed key by name.

Parameters:

Name Type Description Default
path str or Path

The c<NNN>.toml file.

required

Returns:

Type Description
CostFile

The model.

Raises:

Type Description
InputArtifactError

If a table or key is not one this package reads, a required number is missing, or the efficiency curve is malformed.

pyflightstream.workspace.costs.resolve_cost_file

resolve_cost_file(
    inputs_dir: str | Path,
) -> CostFile | None

Return the cost file this plan uses, or None when the workspace has none.

Parameters:

Name Type Description Default
inputs_dir str or Path

The workspace inputs/ directory.

required

Returns:

Type Description
CostFile or None

The selected file, else the only one; None without any.

Raises:

Type Description
InputArtifactError

If the selection names no file, if several files exist and none is selected, or the file is refused by :func:read_cost_file.

pyflightstream.workspace.costs.select_cost_file

select_cost_file(name: str | None) -> None

Select which cost file :func:resolve_cost_file returns (CLI --cost-file NAME).

Parameters:

Name Type Description Default
name str or None

The file stem, c002 for inputs/costs/c002.toml; None clears it.

required

Returns:

Type Description
None

Held in a context variable, so it belongs to the invocation: a console command restores it when it ends (PFS-2094.045), and a Python caller sets it plainly.

pyflightstream.workspace.costs.unmarked_cost_files

unmarked_cost_files(
    root: str | Path, *, skip: Collection[str] = ("tests",)
) -> list[Path]

Every tracked-style c*.toml under root that does not say it is synthetic.

The guard of FR-807: the package ships no measured machine value, so a cost file anywhere in the tree (outside the skip folders) must carry the word :data:SYNTHETIC_WORD.

Parameters:

Name Type Description Default
root str or Path

The tree to walk (a repository root).

required
skip collection of str

Top-level folders left out, the tests' own fixtures by default.

('tests',)

Returns:

Type Description
list of Path

The cost files lacking the word, sorted; empty when the tree is clean.