pyflightstream.cases.matrix (stable)¶
Generated from the docstrings at build time: every one of the 22 names in the __all__ of pyflightstream.cases.matrix has an entry below. The names a guide or an example uses come first; the others follow under Advanced.
Pipe-delimited run matrix: the reader and the converter.
Pipeline role: keeps the established run-matrix workflow working
unchanged, forever (BRF-08), and promotes the matrix to a first-class
interface of the file-managed modality : reading a
matrix and running it is one call,
:func:pyflightstream.run.matrix.run_matrix. Cases are represented
in memory by Campaign and SimCase; campaign files are refused. The layout is read as
is: POL, AIRCRAFT, DESCRIPTION, FLIGHT_CONDITION, SWEEP_VALUES, REF,
SET, PPROC, FS_BUILD, HIDDEN, RUN, WORKFLOW, VAR_NAMES_VALUES. Rows
with RUN = 1 are active. THE SWEPT VARIABLE IS A KEY OF
FLIGHT_CONDITION: whichever key carries the word sweep where its
value would be is the one that varies, exactly one may, and
SWEEP_VALUES carries its comma-separated values. Every other key of the
cell is a quantity the row holds at every point of the sweep.
VAR_NAMES_VALUES holds /-separated KEY:VALUE pairs; values may
contain spaces and escaped newlines (a literal backslash-n sequence),
which are preserved verbatim.
The historical 3-digit codes (REF, SET, ENTRY, FS_SCRIPT) were
resolved to files by number at run time; that import-by-number system
is replaced (PP-7, FR-12): :func:to_campaign maps the FS_SCRIPT
code to a registered recipe name through an explicit mapping and
preserves all four codes in the case variables, so the conversion is
lossless. The retired :func:convert_matrix refuses the native
campaign.toml equivalent; REmi is stated in millions in the
flight condition and converts to an absolute Reynolds number.
Binding REF, SET, ENTRY and FS_BUILD to workspace inputs belongs to
:class:pyflightstream.workspace.matrix.ResolvedMatrix and
:func:pyflightstream.workspace.matrix.resolve_matrix. Pre-flight and execution belong to
:func:pyflightstream.run.matrix.plan_matrix and
:func:pyflightstream.run.matrix.run_matrix.
THE LAYOUT HAS BROKEN TWICE, and both breaks are recognised rather than merely refused.
WORKFLOW selects the registered builder (PFS-2025.01, PFS-2025.12).
FLIGHT_CONDITION states the flow constraints (PFS-2027.01). The reader preserves the keys
for resolution against the reference geometry in the workspace layer.
:func:read_matrix refuses earlier layouts and names the current columns.
Migration instructions are in docs/upgrading.md.
What is left here imports nothing above the cases layer, at any level,
which is what :mod:tests.test_conventions now holds it to.
Used in the guides¶
Advanced¶
pyflightstream.cases.matrix.COLUMNS_NEW_AT_0_17_0
module-attribute
¶
COLUMNS_NEW_AT_0_17_0 = {
"CONFIGURATION": "nothing implies it; the upgrade writes the unstated cell",
"GEOMETRY": "the row's own GEOMETRY key, out of the free cell",
"SYMMETRY": "the row's own SYMMETRY key, out of the free cell",
"SYMMETRY_LOADS": "the unstated cell; a cited setup's symmetry_loads is refused by name, naming this column, so nothing is lost silently",
"NCPUS": "the unstated cell; the cited setup's max_parallel_threads is still read, so nothing is lost",
"WALLTIME": "no earlier row could state one, so it is written as the unstated cell",
}
pyflightstream.cases.matrix.COLUMNS_THAT_MAY_BE_UNSTATED
module-attribute
¶
COLUMNS_THAT_MAY_BE_UNSTATED = (
"CONFIGURATION",
"GEOMETRY",
"SYMMETRY",
"SYMMETRY_LOADS",
"NCPUS",
"WALLTIME",
)
pyflightstream.cases.matrix.COLUMN_MEANINGS
module-attribute
¶
COLUMN_MEANINGS: Mapping[str, InputKey] = {
"POL": InputKey(
"The row's identifier: the simulation id its points are recorded and named under.",
"an id, unique in the matrix",
),
"HIDDEN": InputKey(
"Whether the solver runs without its window.",
"1 is hidden",
),
"RUN": InputKey(
"Whether the row runs at all; only a row reading 1 is active.",
"an integer",
),
"AIRCRAFT": InputKey(
"The configuration's name.", "text"
),
"CONFIGURATION": InputKey(
"The user's own label for the configuration; it configures nothing.",
"text",
),
"DESCRIPTION": InputKey(
"Free text about the row.", "text"
),
"FLIGHT_CONDITION": InputKey(
"The flow condition and the attitude of every point: the keys given decide which quantity is solved for, and the swept key carries the word sweep.",
"KEY:value pairs, comma separated; see the table below",
),
"SWEEP_VALUES": InputKey(
"The values of the key the FLIGHT_CONDITION cell sweeps, one point each.",
"numbers, comma separated",
),
"GEOMETRY": InputKey(
"The geometry the row opens, a file of inputs/geometries/.",
"a file name with its extension",
"OPEN, IMPORT",
),
"REF": InputKey(
"The reference artifact the row's lengths, frames, rotors and discs come from.",
"an id of inputs/references/",
),
"SET": InputKey(
"The setup artifact the row's solver settings come from.",
"an id of inputs/setups/",
),
"PPROC": InputKey(
"The post-processing artifact the row's sections, plots, probes, exports and products come from.",
"an id of inputs/pproc/",
),
"SYMMETRY": InputKey(
"The symmetry the solver is initialized under, which states what was meshed.",
"NONE, MIRROR or PERIODIC",
"INITIALIZE_SOLVER",
),
"SYMMETRY_LOADS": InputKey(
"Whether the reported loads are the meshed sector's or the whole wheel's.",
"true or false",
"SET_ANALYSIS_SYMMETRY_LOADS",
),
"NCPUS": InputKey(
"The processor count: the solver's thread count and, on a cluster, the scheduler's ncpus.",
"a count",
"SET_MAX_PARALLEL_THREADS",
),
"WALLTIME": InputKey(
"The wall clock the row asks for: the scheduler's limit on a cluster, and what the watchdog counts down on an unsteady row.",
f"a number and its unit, {WALLTIME_UNITS_GLOSS}, as 240m or 4h",
unscripted=ROW_KEY_MEANINGS[
WALLTIME_VARIABLE
].unscripted,
),
"FS_BUILD": InputKey(
"The solver build the row runs on, as inputs/executables.toml names it.",
"a build identifier",
),
"WORKFLOW": InputKey(
"The run type that builds the row's script, or LEGACY for a row a recipe of the user builds.",
"steady, unsteady, unsteady_rotor, qsteady_rotor or LEGACY",
),
"VAR_NAMES_VALUES": InputKey(
"The row's own keys, the ones its run type reads; see the table of row keys.",
"KEY: value pairs separated by /",
),
}
pyflightstream.cases.matrix.DEFAULT_VERSION_OPTION
module-attribute
¶
DEFAULT_VERSION_OPTION = '--fs-version'
pyflightstream.cases.matrix.MatrixError
¶
Bases: PyflightstreamError, ValueError
A run-matrix file does not match the verified layout.
The reader supports exactly the verified format (FR-10); a deviation means the file is not a run matrix or was edited beyond what the matrix workflow produces.
pyflightstream.cases.matrix.MatrixRow
dataclass
¶
MatrixRow(
row_number: int,
pol: str,
aircraft: str,
description: str,
flight_condition: dict[str, float],
sweep: SweepAxis,
ref_code: str,
set_code: str,
pproc_code: str,
script_code: str,
fs_build: str,
hidden: bool,
run: int,
workflow: str,
variables: dict[str, str],
motions: list[dict[str, str]] = list(),
custom_motions: list[dict[str, str]] = list(),
rotations: list[dict[str, str]] = list(),
translations: list[dict[str, str]] = list(),
raw: list[dict[str, str]] = list(),
condition_order: list[str] = list(),
identifiers: dict[str, str] = dict(),
)
One parsed row of the run matrix.
Attributes:
| Name | Type | Description |
|---|---|---|
row_number |
int
|
Position of the row among the DATA rows of the file, 1-based. It counts CONTENT rows after blank lines and the dashed rule have been dropped, so it is not a physical line number, and it is assigned BEFORE the RUN filter: the number a refusal prints names the same row whether or not the row is active, which is what makes it usable for finding the cell to edit. |
pol |
str
|
Polar identifier (POL column); maps to the native |
aircraft, description |
str
|
Configuration name and free text. |
flight_condition |
dict
|
The FLIGHT_CONDITION cell, parsed to canonical key and float and kept in the units the KEYS name (PFS-2027.01). It replaced the RE and MACH columns: a run states its flow condition in one place, and which quantity gets solved for follows from which keys are present rather than from which columns are mandatory. An empty cell is an empty mapping, not a refusal; a row that states no condition is legal here and is answered one layer up. |
sweep |
SweepAxis
|
The sweep, already in native form. |
ref_code, set_code, pproc_code |
str
|
The library ids the REF, SET and PPROC cells carry. |
script_code |
str
|
A LEGACY row's recipe code, the |
fs_build |
str
|
FS_BUILD column, kept verbatim. |
hidden |
bool
|
HIDDEN column, the windowless-run flag. |
run |
int
|
Activity flag; rows with 1 are active. |
workflow |
str
|
WORKFLOW column, the workflow type the row asks for; one of
:data: |
variables |
dict
|
The KEY:VALUE variables, values kept as strings. |
pyflightstream.cases.matrix.RECOGNIZED_MATRIX_LAYOUTS
module-attribute
¶
RECOGNIZED_MATRIX_LAYOUTS = (
_COLUMNS,
_LAYOUT_0_9_0,
_LAYOUT_0_11_0,
_LAYOUT_0_15_0,
_LEGACY_COLUMNS_15,
_LEGACY_COLUMNS_16,
)
pyflightstream.cases.matrix.UNSTATED_CELLS
module-attribute
¶
UNSTATED_CELLS: tuple[str, ...] = ('', '-', NOT_APPLICABLE)
pyflightstream.cases.matrix.convert_matrix
¶
convert_matrix(
path: str | Path,
*,
name: str,
fs_version: str,
fs_exe: str,
recipes: Mapping[str, str],
) -> str
Refuse serialization to the retired campaign-file form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
The matrix to plan directly. |
required |
name
|
str
|
Former conversion arguments, retained only to give a didactic refusal. |
required |
fs_version
|
str
|
Former conversion arguments, retained only to give a didactic refusal. |
required |
fs_exe
|
str
|
Former conversion arguments, retained only to give a didactic refusal. |
required |
recipes
|
str
|
Former conversion arguments, retained only to give a didactic refusal. |
required |
Returns:
| Type | Description |
|---|---|
NoReturn
|
This retired entry point always raises; it produces no campaign file. |
Raises:
| Type | Description |
|---|---|
MatrixError
|
Campaign-file conversion is removed. Use the workspace matrix directly. |
pyflightstream.cases.matrix.matrix_pol_rows
¶
matrix_pol_rows(path: str | Path) -> list[tuple[int, str]]
Return (row_number, pol) of every data row, before any cell is parsed.
Same file-shape refusals as :func:read_matrix (header, UTF-8, cell count), none of
its cell checks, so a row whose content is malformed still states its POL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
The matrix file to read. |
required |
Returns:
| Type | Description |
|---|---|
list of tuple of (int, str)
|
One |
Raises:
| Type | Description |
|---|---|
MatrixError
|
The file is not UTF-8, holds no matrix content, its header is not the matrix header, or a row holds the wrong number of cells. |
pyflightstream.cases.matrix.read_matrix
¶
read_matrix(
path: str | Path, *, active_only: bool = True
) -> list[MatrixRow]
Read a pipe-delimited matrix.fs run matrix.
Decode strict UTF-8 with an optional BOM. Skip hash comments, blank lines and separator rules using the same classifier as Excel sync.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Matrix file location. |
required |
active_only
|
bool
|
Keep only rows with RUN = 1, the matrix activity filter; False returns every row. Keyword-only, so a bare boolean never hides in the call. |
True
|
Returns:
| Type | Description |
|---|---|
list of MatrixRow
|
Parsed rows in file order. |
Raises:
| Type | Description |
|---|---|
MatrixError
|
If the file carries the column layout of an earlier release, a column the layout does not know (named with the closest known column), or a LEGACY row states a raw command, a rotation or a translation. |
Warns:
| Type | Description |
|---|---|
NotApplicableWarning
|
A row whose |
PyflightstreamWarning
|
An |
Examples:
>>> import tempfile
>>> from pathlib import Path
>>> from pyflightstream.cases.matrix import MATRIX_COLUMNS
>>> cells = dict.fromkeys(MATRIX_COLUMNS, "NA")
>>> cells.update(
... POL="9001", HIDDEN="0", RUN="1", AIRCRAFT="Wing", DESCRIPTION="POLAR",
... FLIGHT_CONDITION="MACH:0.1, ALPHA:sweep", SWEEP_VALUES="0.0,2.0",
... FS_BUILD="MANUAL", WORKFLOW="LEGACY",
... VAR_NAMES_VALUES="OUTPUTS: loads_{point}.txt / RECIPE: 003",
... )
>>> path = Path(tempfile.mkdtemp()) / "matrix.fs"
>>> with path.open("w", encoding="utf-8") as stream:
... print(" | ".join(cells), file=stream)
... print(" | ".join(cells.values()), file=stream)
>>> [(row.pol, row.run) for row in read_matrix(path)]
[('9001', 1)]
pyflightstream.cases.matrix.refuse_silent_rows_without_default
¶
refuse_silent_rows_without_default(
rows: list[MatrixRow],
default: str | None,
path: str | Path,
) -> None
Refuse a matrix that names no build anywhere, naming the rows.
A row whose FS_BUILD cell strips to empty is SILENT: it asks for
no build at all and falls back to the campaign default. When that
default is empty too, nothing in the run names a FlightStream build,
and picking one, by any rule, would be the package deciding what the
study runs on. That is the one case that must not proceed on a guess
(FR-10, PFS-2009.08.03).
Called before anything is resolved, so a refusal costs no executable
lookup, no :class:~pyflightstream.cases.Campaign and no executor.
Placed here rather than at the build selection because the explicit
fs_exe override returns before the build set is ever built, so a
check there is skipped exactly when the override is passed, and the
acceptance is "with and without fs_exe".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list of MatrixRow
|
The rows to judge. Callers pass the ACTIVE rows: an inactive row runs nothing, so its empty cell asks nothing of anybody. |
required |
default
|
str or None
|
The campaign default version, as given. None and a string that strips to empty are the same absence here. |
required |
path
|
str or Path
|
Matrix location, for the message. |
required |
Raises:
| Type | Description |
|---|---|
MatrixError
|
When the default is absent and at least one active row names no build in its FS_BUILD cell; the message names every such row by row number and POL. When every active row names its build, nothing is raised and the function returns, because no default is then needed. |
pyflightstream.cases.matrix.renumber_pols
¶
renumber_pols(
path: str | Path,
changes: Mapping[int, str],
*,
in_place: bool = False,
) -> bytes
Rewrite the POL cell of the named data rows, byte for byte (PFS-2031.21).
BY ROW, NOT BY VALUE, which is the difference from :func:rewrite_codes:
a POL stated twice in one matrix is two rows with one value, and only the
second of them moves. Every other cell, the padding of the POL cell where
it can be kept, the dashed rule and every line ending survive unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
The matrix to rewrite, at the verified layout. |
required |
changes
|
mapping of int to str
|
Data row number, counted as :func: |
required |
in_place
|
bool
|
Write the rewritten bytes back over |
False
|
Returns:
| Type | Description |
|---|---|
bytes
|
The rewritten file. |
Raises:
| Type | Description |
|---|---|
MatrixError
|
The header does not name the verified layout, a data row holds the
wrong number of cells, or a row number in |
pyflightstream.cases.matrix.rewrite_codes
¶
rewrite_codes(
path: str | Path,
mapping: Mapping[str, Mapping[str, str]],
*,
in_place: bool = False,
) -> tuple[bytes, dict[str, int]]
Rewrite the REF, SET and PPROC cells of a matrix, byte for byte.
Every other cell, separator, comment rule and line ending survives unchanged, and EVERY data row is rewritten, active or not: a row whose RUN flag is 0 today is a row somebody flips to 1 tomorrow, and leaving its cell behind is exactly the half-resolving state the kind-letter rule exists to end (PFS-2009.03).
Works on BYTES rather than through :func:read_matrix, because the reader replaces undecodable
bytes, drops the dashed rule and strips every cell, so a converter
built on it hands back a file the user cannot diff against the one
they had.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
The matrix to rewrite. Read as bytes and not decoded. |
required |
mapping
|
mapping of str to mapping of str to str
|
Per column, old id to new id; the keys are
:data: |
required |
in_place
|
bool
|
Write the rewritten bytes back over |
False
|
Returns:
| Type | Description |
|---|---|
tuple of bytes and dict
|
The rewritten file, and how many cells changed per column. The count is what lets a caller refuse a migration that silently matched nothing. |
Raises:
| Type | Description |
|---|---|
MatrixError
|
The header does not name the verified layout, a data row holds the wrong number of cells, or no line carries a cell separator. |
Examples:
>>> from pyflightstream.cases.matrix import rewrite_codes
>>> text, counts = rewrite_codes(
... "matrix.fs", {"REF": {"003": "r003"}}, in_place=True
... )
pyflightstream.cases.matrix.to_campaign
¶
to_campaign(
path: str | Path,
*,
name: str,
fs_version: str,
fs_exe: str,
recipes: Mapping[str, str],
require_outputs: bool = True,
defer_raw_files: bool = False,
rows: list[MatrixRow] | None = None,
) -> Campaign
Convert a run matrix into a native :class:Campaign.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Matrix location; only RUN = 1 rows convert. |
required |
name
|
str
|
Campaign name; the matrix has none, so it is explicit input. |
required |
fs_version
|
str
|
FlightStream version, canonical identifier (26.120); a vendor release name works only where it names exactly one registered build. The FS_BUILD column does not identify one, so it is explicit input. |
required |
fs_exe
|
str
|
Explicit executable path (never guessed, SAD Section 5). |
required |
recipes
|
mapping of str to str
|
RECIPE code (a LEGACY row's) to recipe reference ( |
required |
require_outputs
|
bool
|
Refuse a row that declares no outputs (the default). False permits inspection of an incomplete in-memory campaign without executing it. |
True
|
defer_raw_files
|
bool
|
Leave out a raw-command record that names a file instead of refusing it; only the caller that resolves those files against a workspace passes True. |
False
|
rows
|
list of MatrixRow
|
Already selected active rows; when omitted, read all active rows from path. |
None
|
Returns:
| Type | Description |
|---|---|
Campaign
|
Native campaign; the matrix codes survive in each case's
variables ( |
Raises:
| Type | Description |
|---|---|
MatrixError
|
If a LEGACY row's RECIPE code is missing or not in |
pyflightstream.cases.matrix.workflow_types
¶
workflow_types() -> tuple[str, ...]
Every value a WORKFLOW cell may name.
:data:LEGACY_WORKFLOW first, then the registered workflow names in
the order :func:pyflightstream.cases.workflows.workflow_names
gives them. It is READ from the registry at call time rather than
frozen here, so a workflow registered tomorrow is accepted by this
reader the same day and no second list can disagree with the table.
Returns:
| Type | Description |
|---|---|
tuple of str
|
The accepted values, in the order the refusal lists them. |
Examples:
>>> from pyflightstream.cases.matrix import workflow_types
>>> workflow_types()[0]
'LEGACY'