kicad2ems.core.runs¶
A kicad2ems run started by another program (kicad2ems-gui, the KiCad plugin):
its settings as a TOML file, the command line (run as a separate process), its
event stream (--events, JSON lines), stopping it and the files it wrote. No Qt
here.
run = Run(settings_dict, out_dir, preview=False)
run.argv() # [python, -m, kicad2ems, <out>/gui_run.toml,
# --events, ...]
tail = EventTail(path); tail.read() -> [event dicts]
read_summary(path) # a <name>_run.json, its format checked (formats.py)
stop_runs(out_dir) # STOP for the run (stop.py), ABORT into every FDTD
# run folder
find_results(out_dir) # [(label, path)] of the newest finished run's files
run_dir(base, board), preview_dir(base, board),
tool_dir(base, board, analysis, what), tool_preview_dir(...)
# where a front end's runs go: a folder each under
# the output folder
write_toml(path, settings); toml_value(v); load_toml(path)
update_toml(path, keys, tables) # a config edited, its comments kept
A run folder is known by its mark, which whoever starts the run leaves in it
(`kicad2ems study`, the GUI) and completes with how it ended:
mark(folder, engine, asked, preview, config, settings)
ended(folder, outcome) # 'done', 'stopped', 'crashed', 'failed, code 1'
marked(folder) # dict(engine, questions, preview, ...), or None
info(folder) # RunInfo: what the folder is, read from its mark
index(base, board=None, running=())
# [RunInfo] of the runs under base, the newest
# first, the board's preview last
latest_results(base, board, config=None)
# {analysis: its newest finished run's folder}
- class kicad2ems.core.runs.EventTail(path)[source]¶
Reads the new complete lines of an events file on each call. The stream's first line names its format (formats.py): it is not passed on, and a format this kicad2ems cannot read comes out as a log line saying so.
- class kicad2ems.core.runs.Run(values, out_dir, preview=False)[source]¶
One kicad2ems run: its settings file, event file and command line.
- class kicad2ems.core.runs.RunInfo(folder: str, kind: str, board: str, when: datetime, what: str = '', questions: tuple = (), engines: tuple = (), outcome: str = 'done', took: float = None, size: int = 0, settings: dict = None, config: str = None, preview: bool = False)[source]¶
A run folder as its mark says.
- kicad2ems.core.runs.board_name(board)[source]¶
The name a board's run folders take: its file name without the extension (and a resolved board's _board).
- kicad2ems.core.runs.descendants(pid, proc='/proc')[source]¶
Every process below pid, by parent pid whatever its session or group (fem's Palace and Elmer ranks run in sessions of their own), nearest first; [] where it cannot be told, and for no process (pid 0 or 1: the whole system is below them).
- kicad2ems.core.runs.ended(folder, how)[source]¶
A marked run's end into its mark: how (outcome's words) and when.
- kicad2ems.core.runs.find_results(out_dir)[source]¶
(label, path) of the files of the newest finished run in out_dir (from its <name>_run.json).
- kicad2ems.core.runs.index(base, board=None, running=())[source]¶
The runs under base: of the board (None: of every board), the newest first and the board's preview last; running: the folders of runs going now (only the front end that started them knows).
- kicad2ems.core.runs.info(folder)[source]¶
The RunInfo of one run folder, wherever it is (None: not a run's).
- kicad2ems.core.runs.kill_tree(pid, also=())[source]¶
A run's process and everything below it ended now (SIGKILL; Windows: taskkill /T /F): its workers, its openEMS, an analysis's MPI ranks in sessions of their own, which killing the process alone had left running (their guard's atexit and SIGTERM handler never run under SIGKILL). also: tree_of's [(pid, start)] from before (each only while it is that same process). Only pid's own descendants, never processes found by name. Returns the pids signalled.
- kicad2ems.core.runs.latest_results(base, board, config=None, runs=None)[source]¶
{analysis: the folder of its newest finished run on this board under base}, a run of `config` (None: of none) before the others, and the newest solvers' run as 'sparams': what an analysis that starts from another's result is given (Analysis.command's results). runs: the index, when read already.
- kicad2ems.core.runs.load_toml(path)[source]¶
A TOML file's tables; OSError, or tomllib.TOMLDecodeError (a ValueError).
- kicad2ems.core.runs.mark(folder, engine, asked=(), preview=False, config=None, settings=None)[source]¶
Leave the mark of a run in its folder (made if it is not there): the engine that makes it, the questions asked of it, whether it is a preview; config: the config file it was started from, settings: the settings it ran with (a front end's form: JSON, anything else as its text), each kept when given. Returns the mark's path.
- kicad2ems.core.runs.marked(folder)[source]¶
The mark of a run's folder: dict(engine, questions, preview), with config, settings, outcome and ended when it has them; None (no mark, or not readable).
- kicad2ems.core.runs.outcome(code, stopped=False, crashed=False)[source]¶
How a run ended, as its mark keeps it: 'done', 'stopped', 'crashed', 'failed, code 1'.
- kicad2ems.core.runs.preview_dir(base, board)[source]¶
The folder a board's previews share (each refreshes it): <base>/<board>_preview.
- kicad2ems.core.runs.process_children(proc='/proc')[source]¶
{parent pid: [child pids]} of every process: Linux's /proc, else ps (macOS, the BSDs); {} where neither tells.
- kicad2ems.core.runs.read_summary(path)[source]¶
A run summary (<name>_run.json), checked: ValueError when this kicad2ems cannot read its format.
- kicad2ems.core.runs.run_dir(base, board, now=None)[source]¶
The folder of an S-parameter run started now: <base>/<board>_20261013_141502.
- kicad2ems.core.runs.run_log(folder)[source]¶
A run's log as text: the events' log lines, else its process's whole output (stdout.log); '' if neither.
- kicad2ems.core.runs.same_config(a, b)[source]¶
Whether two runs' configs are the same file (None: none, the form as it was not saved, or a run from before the mark kept one).
- kicad2ems.core.runs.stop_runs(out_dir)[source]¶
Ask the run writing to out_dir to stop: its STOP file (every solver checks it, stop.py), and ABORT into every FDTD run folder under out_dir (<out>/<engine>/exc_<port>: the engine stops and finishes normally); returns those folders.
- kicad2ems.core.runs.toml_value(v)[source]¶
A value as TOML text: booleans, numbers and lists of them as they are, anything else a quoted string.
- kicad2ems.core.runs.tool_dir(base, board, kind, name, now=None)[source]¶
The folder of an analysis's run started now: <base>/<board>_<analysis>_<what>_20261013_141502 (what: the rail, the converter: Analysis.tag).
- kicad2ems.core.runs.tool_preview_dir(base, board, kind)[source]¶
The folder an analysis's previews of a board share: <base>/<board>_<analysis>_preview.
- kicad2ems.core.runs.tree_of(pid, proc='/proc')[source]¶
[(pid, its start)] of every process below pid now (descendants), for a kill_tree later: a tool asked to stop may end and leave its children to init before it is killed (Linux: each with its start, so that a pid used again by another process is not touched; elsewhere []).
- kicad2ems.core.runs.update_toml(path, keys=None, tables=None, source=None, head=())[source]¶
Write the TOML file at `path` from the text of `source` (default: the file itself; neither there: the comment lines `head`), keeping its comments, order and every line not named here: keys {(table, key): value}: the key's value set in place, its trailing comment kept; None: its line removed. A new key goes after the last one of its table ('': the top level, above the first table), or into a new table at the end. tables {name: {key: value | {table} | [{table}, ...]}}: [name] and every [name.*] and [[name.*]] replaced by these, where the first of them was (else at the end); {}: taken out. Not written when nothing changes.