upxo.meshing.gbconformant.pipeline package

Submodules

Module contents

Run the grain-conformal tetrahedral meshing pipeline, and save and restore its stage results.

from upxo.meshing.gbconformant.pipeline import run result = run(RAW_FOLDER=”path/to/raw_export”, HIERARCHY_LEVEL=”blk”, through=”export_abaqus”)

run applies the stages in order (see STAGES), saving each stage’s results in the run folder in portable files; a second run of the same settings restores them and runs only what changed. python -m upxo.meshing.gbconformant.pipeline --help lists the commands.

class upxo.meshing.gbconformant.pipeline.CheckpointStore(run_folder, keep_history=True)[source]

Bases: object

Stage results in <run_folder>/checkpoints.

With keep_history (the default) every stage keeps the results it wrote, so a stage can be run again from the results of the stage before it. Without it a newer stage’s result replaces the older copy of the same artefact, which takes less disk; a restore then returns only a prefix of stages whose results are all still complete.

stage_dir(stage_id)[source]
meta(stage_id)[source]
stages()[source]
save_stage(state, stage_id, signature, status='OK', report=None, config_changes=None)[source]

Write the results stage_id produced; return its meta dictionary.

config_changes are the settings the stage itself changed while running (the hierarchy level it found, the spacing after an upscale); a restore applies them again.

save_marker(stage_id, signature, status, report=None, config_changes=None)[source]

A stage with no results of its own (for instance a skipped one).

history_bytes(order)[source]

Disk the older copies of artefacts take: every artefact kept by more than one stage, less its newest copy.

drop_history(order)[source]

Keep each artefact only in the last stage of order that wrote it; returns the bytes freed.

A run that finished still restores as a whole afterwards (its results are the newest copies); what is lost is running a stage again from the results of the stage before it.

discard(stage_ids)[source]
restore(state, stage_ids, signatures, set_status, set_config=None)[source]

Load every stage that is still valid, in order; later stages follow earlier ones.

set_status(stage_id, text) receives 'OK', 'Skipped' or 'Stale'; set_config(stage_id, changes) receives the settings a restored stage changed. Returns {'restored': [...], 'stale': [...], 'bytes': n, 'problems': [...]}.

load_keys(stage_id, keys)[source]

Read only the artefacts keys that stage_id saved (those it did not save are left out).

class upxo.meshing.gbconformant.pipeline.PipelineState(config: dict, stage_ids: list[str])[source]

Bases: object

Holds settings, artefacts, and per-stage status.

property busy: bool
try_begin_operation() → bool[source]
end_operation() → None[source]
request_cancel() → None[source]

Ask the current stage to stop at the next progress checkpoint.

check_cancel() → None[source]

Raise PipelineCancelled if a cancel was requested.

set_progress_handler(handler) → None[source]

handler(message, current=None, total=None) receives the progress of the running stage.

report_progress(message: str, current=None, total=None) → None[source]
append_log(message: str) → None[source]
set_status(stage_id: str, status: StageStatus) → None[source]
pop_history(stage_id: str, data: dict) → dict[source]

Move data['history'] into the stage’s history artefact; returns data without it.

The per-pass list stays out of the compact stage report (and the JSON written for it) the same way it was dropped before this existed; it is kept instead at "<stage_id>.history" for later per-pass inspection, and is invalidated together with the stage that wrote it.

store_artefact(key: str, value: object) → None[source]
get_artefact(key: str, default=None)[source]
invalidate_from(stage_id: str, reason: str = '') → list[str][source]

Mark stage_id and every later stage stale; drop their artefacts.

reason says why (it is kept for each stage that held results). Returns the list of invalidated stage ids.

invalidate_after(stage_id: str, reason: str = '') → list[str][source]

Invalidate every stage that comes after stage_id; returns their ids.

invalidation_preview(stage_id: str) → dict[source]

What invalidating from stage_id would throw away: the finished stages and the time they took.

stale_reason_text(stage_id: str) → str[source]

"<reason> (<time>)" for a stale stage, else an empty string.

class upxo.meshing.gbconformant.pipeline.RunResult(state: PipelineState, run_folder: Path, through: str, restored: list[str] = <factory>, ran: list[str] = <factory>, skipped: list[str] = <factory>, failed_stage: str | None = None, error: str | None = None, manifest: Path | None = None)[source]

Bases: object

What a run did.

state: PipelineState
run_folder: Path
through: str
restored: list[str]
ran: list[str]
skipped: list[str]
failed_stage: str | None = None
error: str | None = None
manifest: Path | None = None
property ok: bool
property reports: dict
export_folder() → Path | None[source]

Folder of the Abaqus export, when the run reached it.

property suggestions: list

Settings worth changing after the failure (empty when the run did not fail or nothing is known).

raise_for_failure() → None[source]
exception upxo.meshing.gbconformant.pipeline.SerializeError[source]

Bases: TypeError

A value cannot be written in the portable form.

class upxo.meshing.gbconformant.pipeline.Setting(key: str, default: Any, kind: str = '', minimum: float | None = None, maximum: float | None = None, choices: tuple = (), auto: bool = False, size: int = 0, container: str = 'tuple', integral: bool = False, stages: tuple = (), unit: str = '', signed_when_changed: bool = False)[source]

Bases: object

One setting: its default, type, limits and the stages whose results it decides.

key: str
default: Any
kind: str = ''

bool | int | float | text | choice | int_choice | sequence | ids | any (derived from the default when empty).

minimum: float | None = None
maximum: float | None = None
choices: tuple = ()
auto: bool = False

None is a valid value and means “decide automatically”.

size: int = 0

Length of a sequence.

container: str = 'tuple'

what a sequence is stored as.

Type:

tuple or list

integral: bool = False

A sequence keeps whole numbers as int.

stages: tuple = ()

Stages whose results depend on this setting.

unit: str = ''

length (voxel edge lengths), factor (a multiple of the voxel edge length), voxels (a count of voxels) or thickness (a number of voxels across).

Type:

What the number measures, so a physical size can be shown beside it

signed_when_changed: bool = False

Left out of the stages’ saved-results signature while it holds its default, so that adding the setting does not make results saved before it existed stale; changing it from the default still does.

exception upxo.meshing.gbconformant.pipeline.SettingsError[source]

Bases: ValueError

A setting name or value that cannot be used.

class upxo.meshing.gbconformant.pipeline.StageDef(id: str, title: str, group: str, kind: str = 'compute', optional_flag: str | None = None, backend: str = 'd3v2p0')[source]

Bases: object

One stage that computes or writes something.

id: str
title: str
group: str
kind: str = 'compute'
optional_flag: str | None = None

Setting that switches the stage off when False; the stage is then skipped.

backend: str = 'd3v2p0'

d3v2p0 or d3v2p1 (the algorithm generation); none when no backend choice applies.

class upxo.meshing.gbconformant.pipeline.StageStatus(*values)[source]

Bases: str, Enum

NOT_RUN = 'Not run'
RUNNING = 'Running'
OK = 'OK'
FAILED = 'Failed'
STALE = 'Stale'
SKIPPED = 'Skipped'
upxo.meshing.gbconformant.pipeline.build_config(overrides: Mapping | None = None, *, extra: Iterable[Setting] = (), **named) → dict[source]

Defaults changed by overrides and named values, each checked.

Unknown names and unusable values raise SettingsError.

upxo.meshing.gbconformant.pipeline.canonical_signature(parts)[source]

Short hash of parts (numbers, text, lists and dictionaries in any order).

upxo.meshing.gbconformant.pipeline.chain_signatures(stage_ids, own)[source]

Signature per stage that also depends on every earlier stage’s own part.

upxo.meshing.gbconformant.pipeline.default_config(extra: Iterable[Setting] = ()) → dict[source]

A fresh, mutable settings dict holding every default (plus those of extra).

upxo.meshing.gbconformant.pipeline.load_versioned(loaded: Mapping, version: int, extra: Iterable[Setting] = ()) → tuple[dict, list[str]][source]

Migrate settings saved at version and coerce them; returns (config, problems).

upxo.meshing.gbconformant.pipeline.parse_assignment(text: str, extra: Iterable[Setting] = ()) → tuple[str, Any][source]

"KEY=VALUE" -> (KEY, checked value).

upxo.meshing.gbconformant.pipeline.read_value(stem)[source]

Read what write_value() wrote; refuses an unknown format or version.

upxo.meshing.gbconformant.pipeline.run(config: dict | None = None, *, through: str = 'export_abaqus', resume: bool = True, on_event: Callable[[dict], None] | None = None, write_manifest: bool = True, **settings) → RunResult[source]

Run the pipeline up to and including through.

config and keyword settings are settings by name (see upxo.meshing.gbconformant.pipeline.settings); unknown names and unusable values raise SettingsError. With resume the results a previous run of the same run folder saved are restored first (each stage only while its settings and everything before it are unchanged) and only the remaining stages run. A failing stage does not raise: the result names it in failed_stage and error.

upxo.meshing.gbconformant.pipeline.stage_def(stage_id: str) → StageDef[source]
upxo.meshing.gbconformant.pipeline.stage_ids() → list[str][source]
upxo.meshing.gbconformant.pipeline.write_value(stem, value, where='value')[source]

Write value as <stem>.json (+ <stem>.npz when it holds arrays).

Returns {'json': name, 'npz': name or None}; raises SerializeError.