# APIs
[← Architecture](architecture.md) · [Index](index.md) · [Next: KiCad import →](kicad-import.md)
Everything one part of kicad2ems uses of another is a module's public names,
its `__all__`: the tables on this page list them by module (a module named
`kicad2ems.core.x` as `core.x`), and the descriptions below say what the
interfaces between the parts are. The rest of each part is its own. The
[code reference](reference/index.md) (in the documentation site) lists every
module, class and function.
| Interface | Provided by | Used by |
|---|---|---|
| [For solvers](#for-solvers) | core | fdtd, mom25d, fem, pcbqs |
| [For analyses](#for-analyses) | core | pcbqs, fem |
| [For front ends](#for-front-ends) | core | gui, ipc, dfsynth |
| [The solvers](#solvers) | fdtd, mom25d, fem, pcbqs | core |
| [The analyses](#analyses) | pcbqs, fem | core, gui |
| [The command line and its files](#files) | core | gui, ipc, dfsynth |
| [gfdtd's engine](#gfdtd-engine) | gfdtd | fdtd |
| [The plan view](#planview) | gui | ipc |
| [`dfsynth --describe --json`](#dfsynth) | dfsynth | gui's Filter page |
(each a subpackage of kicad2ems: core is kicad2ems.core, and so on). The files a
run writes, and dfsynth's description, carry a format version: other programs
read them too.
Importing `core.solvers`, `core.analyses`, `core.study`, a solver's or an
analysis's module loads no PySide6, matplotlib or h5py: those are imported in
the functions that use them (tests/core/test_api.py checks it).
## For solvers
The solver interface and what a solver needs to write its results as the others
do.
| Module | Names |
|---|---|
| `kicad2ems.core.solvers` | `Solver`, `Result`, `Deviation`, `AUTO`, `FEATURES`, `LINES`, `registry()`, `get(name)` (a solver by name or alias), `resolve_lines(s)` |
| `kicad2ems.core.options` | `Option` (`kind`, `flag`, `pick`, `level`, `required`, `describe()`: its `--describe --json` row); its value parsers `floatlist`, `floats`, `strlist`, `items`, `lines`, `split`; a tool's options from a table (`table`) or an argparse parser (`from_parser`), into a parser (`add_arguments`), and the command line of values (`argv(options, values)`) |
| `kicad2ems.core.stop` | `check()` between steps raises `Stopped` when the GUI's Stop was pressed; `requested()` |
| `kicad2ems.core.sparams` | `mixed_mode`, `fill_reciprocal`, `figures(path)` (a Touchstone file's figures: each port's worst match and its dip, each transmission at the band's centre and its lowest), `compared({label: path})` (those side by side, with their spread) |
| `kicad2ems.core.plots` | `plot_antenna`, `plot_pattern`, `plot_convergence`, `preview` (the model and its mesh) |
| `kicad2ems.core.fields.antenna` | `describe` (an antenna's log lines), `match_summary`, `save`, `read`, `gain_table`, `add_polarisation`, `pattern_gain`, `read_sphere`, `sphere_cuts`, `sphere_gain` (far fields) |
| `kicad2ems.core.fields.dumps` | `Dump`, `write_info`, `write_npz`, `read_npz`, `G_DUMP` (the field-dump settings group), `parse_dump`, `add_dumps`, `estimate_size_mb`, `write_norm`, `plot_fd_dumps` |
| `kicad2ems.core.fields.frames` | `DumpSource`, `save_fd_outputs`, `save_animation`, `find_dumps`, `write_frames`; for a viewer's frames: `plane`, `default_axis`, `outlines`, `levels`, `render` |
| `kicad2ems.core.meshes` | `save` (the GUI's 3D mesh view), `find`, `segments`, `counts`, `LABELS` |
| `kicad2ems.core.phased` | drives, grids, tapers: `parse_drive`, `format_drive`, `parse_grid`, `format_grid`, `steer2d`, `aim`, `TAPERS`, `TAPER_SLL`, `parse_taper`, `taper`, `settings_drive`, `waves`, `radiated`, `combine`, `save`, `load` |
| `kicad2ems.core.geometry` | `split_holes` (a polygon with holes as simple polygons) |
| `kicad2ems.core.edges` | `describe`, `snap` (the board-edge walls: their log line, snapped onto a grid) |
| `kicad2ems.core.solvers.lines.fastsolve` | `solve`, `resolve_backend` (the line model's fast solve: a first look before a long run) |
| `kicad2ems.core.finish` | `resolve(s, m)` (a run's `Finish`: its metal layers, the outer layers it covers and each one's share of the loss; None without `--sigma` or a finish), `factor(f, finish)` (the finished face's impedance over bare copper's), `weighted(f, finish, share)`, `band_sigma(sigma, finish, share, fmin, fmax)` (the one conductivity of the same loss at the band centre), `face_z(f, sigma, t, finish)`, `layers` |
| `kicad2ems.core.roughness` | `hammerstad(f, rms_um, sigma)` (Hammerstad's loss factor), `rough_sigma(sigma, rms_um, f)` (the conductivity of the same loss at f), `band_sigma(s, fmin, fmax)` (a solver's one conductivity: `--sigma`, or with `--rough` that at the band centre) |
| `kicad2ems.core.constants` | `C0`, `EPS0`, `ETA0`, `MU0` |
| `kicad2ems.core.units` | `value` (a whole text as a value with an SI prefix: `'4k7'`, `'0R001'`), `parse_value` (a Value field's first word), `SI` |
| `kicad2ems.core.sitecfg` | `get` (where external programs are), `user_file`, `set_user` |
| `kicad2ems.core.pipeline` | `ram_gb` |
| `kicad2ems.emsdev.cpu` | `core_threads` (one per fast physical core) |
### Solvers
A solver is a subclass of `Solver`, listed by its module and class in
`kicad2ems.core.solvers.SOLVERS` (imported on the first `registry()` call):
```python
SOLVERS = ('kicad2ems.core.solvers.lines.solver:Qucs', ...,
'kicad2ems.mom25d.solvers.mom:MoM25D', ...)
```
It declares, as class attributes:
| Attribute | Meaning |
|---|---|
| `name`, `aliases`, `label` | `'mom25d'`, `('mom',)`, `'mom25d (MoM)'`; `name` is also its config table `[solver.mom25d]` |
| `consumes` | `'board'` (the geometry) or `'network'` (the line model) |
| `in_auto`, `in_all` | whether `--solvers auto` may pick it, and whether `all` includes it (default True; pcbqs, a solver for part of a band, neither; gfdtd not `all`) |
| `basic` | the keys of its options a run is set up with (its main cell size: `('mom_dmax',)`). A window shows those first and the rest under "More settings" (they get `Option.level = 'basic'`) |
| `previewed` | `--preview` prepares it without solving |
| `rank`, `order` | rough cost (cheap solvers run first); its place in lists |
| `capabilities` | `{feature: 'yes' \| 'no' \| 'ignored' \| 'approximated: how'}` over `FEATURES` |
| `options` | its settings, `[Option]`: the command line, config keys, GUI fields and settings are made from them |
and implements, in the order the pipeline calls them:
| Method | Returns |
|---|---|
| `check(s=None)` | `(usable, one line)`: its version and origin, or what is missing and how to get it |
| `validate(s)` | a message when its settings cannot be used together, or `None` |
| `assess(run)` | why it cannot model this board, a list (`[]`: it can) |
| `estimate(run)` | `dict(seconds, gb, what)`, its rough cost, for `--solvers auto`; or `None` |
| `prepare(run)` | its own form of the board (openEMS: the boundaries and mesh); a preview stops here |
| `solve(run, prep)` | a `Result`: S-parameters, port names, reference impedances, facts for the summary (`info`; its `modes`, the resonances it found, are shown as a table) |
| `deviations(run, prep)` | `[Deviation]`: what it models differently from the board |
| `readback(run, prep)` | what its own model holds, in the board's terms, for the parity checks; or `None` |
| `reusable(run)` | whether an earlier run's result may stand for its solve in this run (`kicad2ems.core.reuse`: the same board, frequencies, settings and code); its `outputs` is not called for one. Default: only a solver with no `outputs` of its own |
| `outputs(run, prep, result)` | its own extra outputs (optional) |
| `resources()` | the GPUs it would run on here and why there are none, or `None`: the CPU only |
`run` is the pipeline's `Job`: a solver may use `run.m` (the board), `run.s` (the settings, its options among
them), `run.freq` (Hz), `run.lm` (the line model), `run.name`, `run.log()`, `run.status(name, dict)` (progress
events), `run.path(suffix)`, `run.wrote(label, path)`, `run.figure(fig, suffix, key, label)` and `run.summary`.
[Architecture](architecture.md#solvers) has the rest: parity, and settings as
data.
## For analyses
Tools that work on the board a run is made of but give something other than
S-parameters (the crosstalk, pcbqs's power integrity, near field, circuit and
thermal analyses, the Elmer and Palace tools).
| Module | Names |
|---|---|
| `kicad2ems.core.analyses` | `Analysis`, `KINDS` (the kinds of an option), `RF` (the S-parameter run's key in a front end's lists: no analysis's), `registry()` (`{name: Analysis}`), `analysis_of(folder)` (`(name, preview)` of the analysis whose finished result a folder holds, as its mark says, or `None`), `read_config`, `read_sets` |
| `kicad2ems.core.study` | `Question` (name, label, group, about, shares, answer, order), `QUESTIONS` (kicad2ems's own: what an analysis may `provides`) |
| maps for a viewer | `Dump`, `write_info`, `write_npz` (`core.fields.dumps`): field dumps, as a solver's; `save` (`core.meshes`) |
### Analyses
An analysis is a subclass of `Analysis`, listed by its module and class in
`kicad2ems.core.analyses.ANALYSES` (imported on the first `registry()` call),
the [crosstalk between traces](si.md), [a board's coupling](si.md#coupling), [a channel in
time](timedomain.md), [the line parameters](rlgc.md) and [the radiated EMC questions](emc.md) among
them:
```python
ANALYSES = ('kicad2ems.core.si:Crosstalk',
'kicad2ems.core.coupling:Coupling',
'kicad2ems.core.timedomain:TimeDomain',
'kicad2ems.core.rlgc:LineParameters',
'kicad2ems.core.emission:Emission',
'kicad2ems.core.susceptibility:Susceptibility',
'kicad2ems.pcbqs.analyses:PowerIntegrity', ...)
```
It runs as a command of its own, so the tool behind it works without kicad2ems;
its `Analysis` class is the only part that imports
kicad2ems. It declares, as class attributes:
| Attribute | Meaning |
|---|---|
| `name`, `label`, `tool` | `'pdn'`, `'Power integrity'`, `'kicad2ems.pcbqs.pdn'` (what runs it, as lists show it); `name` is also its config table `[analysis.pdn]` and the tag of its run folders |
| `about` | one line: what it gives |
| `order` | its place in lists, and in a run of several |
| `previewed` | it has a preview (the model and its mesh, no solve) |
| `needs` | the analyses it cannot run without the results of |
| `result`, `preview_result` | the file a finished run (a preview) leaves in its folder (`'pdn.json'`): how a folder is known as its result |
| `paths` | the options whose values are paths: relative to the config file they are read from |
| `page` | `True`: the GUI has an editor of its own for it (the circuit's schematic) |
| `finds` | what the board can propose settings for (`'converters'`: the GUI's "Find converters"), with `discover` and `choices` below; `''`: nothing |
| `env` | environment variables its command runs with |
| `provides` | the [questions](#study-api) it answers, from one run: `('dc', 'pdn')`. None: one question of its own name |
| `engine` | the program's name as a list shows it beside a question: `'pcbqs'`, `'Elmer'` |
| `questions` | `Question` objects of its own, for what kicad2ems has no question for |
| `fields` | the bool option that makes it write field dumps too (`'fields'`), or `''` |
| `variants` | its engines when it is several to choose from beside a question: `((suffix, label, {option: value}), ...)`, each the engine `_` (suffix `''`: ``) that runs it with those settings, which are then not among its options (the crosstalk: `('gfdtd', 'line model + gfdtd', dict(check='gfdtd'))`); `check_with(sets)` is a variant's check. `()`: one engine, itself |
and implements:
| Method | Returns |
|---|---|
| `check()` | `(usable, one line)`: its version and origin, or what is missing and how to get it |
| `options()` | its settings, `[Option]` (`kicad2ems.core.options`), as the solvers' are; `o.kind` one of `KINDS`: `'str'`, `'int'`, `'float'`, `'bool'` (a switch), `'list'` (repeatable, its `conv` splitting a text into items). `o.level` `'basic'`: one of the few a run is set up with; `o.pick`: what the setting names on the board, for a front end to pick there (`'net'`, `'part'`, or `'nets'`, `'parts'` where it takes several); `o.required`: a run needs it set |
| `tag(values)` | a short name for a run of these settings (the rail, the converter): its folder's |
| `command(values, board, out, preview=False, results=None)` | the command line that runs it into folder `out`; `results`: `{analysis: the folder of its latest result on this board}`, for one that can start from another's. `ValueError` says what is missing |
| `status(line)` | the progress a line of its output states, or `None` |
| `discover(values, board)`, `choices(text)` | a command that proposes settings from the board, and its output as `[(label, values)]` to pick from; `None` when it has none |
| `report(folder)` | what a result holds, to read: `dict(title, summary, sections=[dict(title, text, table=dict(columns, rows, formats), notes)], notes, images, footer)`, or `None`. A cell is a number or a string. `show=dict(field, run)` and `mesh` say where a viewer starts: on the dump of that field with the largest values, on that mesh |
| `curves(folder)` | what a result holds, to plot: `[dict(title, xlabel, ylabel, logx, logy, info, curves=[dict(name, x, y, role, unit)])]`; `role` is `'data'`, `'reference'` or `'limit'` |
| `suggest(folder)` | settings a result proposes for other analyses: `[dict(to, label, values, note, need)]`; `need`: the options it has no value for, to set before a run. A front end shows each as a button on the result, puts the values into the other analysis's settings and asks its questions; an analysis with an editor of its own (`page`) is given them as its config table is, so a `model` it names is opened there |
| `examples()` | the examples it ships: `[dict(name, config, group, title, files)]` |
| `for_questions(values, asked)` | its settings for a run asked only some of its questions (a rail's drop without its impedance) |
| `answers(values)` | the questions a run of these settings answers, for one started with none asked (the window's own Run: its mark): by default all it provides; the rail's, the drop always, the impedance unless `no_pdn`, the decaps where `choose_decaps` |
| `owns(folder, preview=False)` | whether the folder holds its result: by default, that its result file is there. An engine whose file another also writes looks inside it |
| `figures(folder)` | the figures of its answer by name, `[dict(name, value, unit)]`, for a table of engines against figures ([below](#study-api)) |
| `missing(values, board, results=None)` | what a run of these settings still needs before it is started: `[dict(text, key)]`, `key` the option it is set by. By default what `command` raises; an analysis that can tell more from the board cheaply says it here (pcbqs's rail: a load with no pad on ground). `results` holds `None` for an analysis asked with it that has no result yet |
| `uses` | the analyses whose latest result it can start from when there is one (the temperature, from a circuit's losses): not required, as `needs` are. What one of them will give in the same run is not missing |
| `several` | what a study may hold several settings of it by, each a run of its own, as a front end names them (`'rail'`: a board's rails, a config's `[[analysis.]]` tables); `''`: one. `tag(values)` tells the runs apart: it names their folders and the study's lines |
| `several_keys` | the options that differ from one of those runs to the next (`('rail', 'volts', 'source', ...)`): a front end shows them as a table, a row a run, and the others once, shared |
Its maps need no method: an analysis writes them as field dumps under `//exc_/` with its board
as `/_board.json`, and a viewer of a run's dumps shows them. A dump's entry in `dump_info.json` may give
its `unit`, and `"range": "data"` for a quantity whose colours should span its own values (a temperature) instead
of starting at zero.
A config holds the analyses' settings under `[analysis.]` (or `[[analysis.]]`, several), which
kicad2ems itself leaves alone; its `[study]` says which run ([usage](usage.md#study)):
```toml
[analysis.circuit]
model = "buck.json" # an analysis's options by key; a path (its `paths`) relative to the file
```
### Questions and engines
A study asks questions of a board; engines answer them (`kicad2ems.core.study`). A question is something to find out
with a known kind of answer; an engine is a solver or an analysis. Several
engines may answer one question, and one engine several questions from one run.
| Group | Question | What it is | Answered by |
|---|---|---|---|
| RF | `sparams` | the ports' S-parameters | every solver |
| RF | `antenna` | a driven port's far field | the solvers whose `antenna` capability is yes or approximated |
| RF | `lines` | every trace's impedance and delay | the line model's solvers |
| Power | `dc` | a rail's DC drop, current density and loss | an analysis that `provides` it |
| Power | `pdn` | the impedance a rail's loads see (shares `dc`'s run) | |
| Power | `nearfield` | a converter's input loop and its magnetic field | |
| Power | `circuit` | a switching circuit on the board's copper | |
| Power | `capacitance` | the capacitance between nets | |
| Thermal | `thermal` | the board's steady temperature | |
| EMC | `conducted` | a switching circuit's conducted emission through a LISN in each supply line, against CISPR 32 or CISPR 25 | pcbqs's `conducted` |
| EMC | `emission` | the board's ports driven by a clock or data: the field at a test site's antenna against CISPR 32 | `emission` (mom25d) |
| EMC | `susceptibility` | the voltage a plane wave puts on each port, the worst over direction and polarisation | `susceptibility` (mom25d) |
`study_tree()` is what a front end lists: `[dict(group,
questions=[dict(question, engines, missing)])]`, every question with the engines
that answer it (`Engine`: `name`, `label`, `kind` `'solver'` or `'analysis'`,
`provides`, `impl` (the `Solver` or the `Analysis`), `fields`, `previewed`,
`check()`). `runs_for({question: [engine names]})` gives the runs that takes,
`{engine: the questions asked of it}`: one run for the questions an engine
answers together. A front end passes an analysis engine's settings through
`for_questions` before `command`, runs the solver engines as one kicad2ems run,
and leaves a mark in each run's folder (`runs.mark(folder, engine, asked,
preview)`, completed by `runs.ended(folder, outcome)` when it ends;
`runs.marked(folder)` reads it). The mark is what a folder is: `runs.info(folder)`
and `runs.index(base, board)` (the Runs page's list, a `RunInfo` per run: kind, when,
questions, engines, outcome, took, size, settings, config) read it, and
`analysis_of` knows a result's engine by it even where two engines write a file of
the same name. A folder made before marks were, or a mark of before they kept the
outcome, is read once more the old way: whose result file it holds (`Analysis.owns`).
`kicad2ems --check` lists the questions with their engines.
A config holds a study as its `[study]` tables ([usage](usage.md#study)). `study.read_config(config, strict=True)` gives
it as a `Study`: `asked` `{question: [engine names]}` in the order written (`[]`: the default engine; for
S-parameters, the solvers the settings name), `fields` `{question: True | False}` and `said` (`'study'`,
`'analysis'` for a config of the older `[analysis] run`, `''`); `strict=False` keeps a question or an engine it
does not know as written, for a front end to grey. `study.write_config(config, study)` writes the tables anew and keeps
the rest of the file. `study.plan(study)` is the runs it takes, in order, `[Step]`: `kind` (`'solvers'`: one
kicad2ems run, or `'analysis'`), `engines`, `questions`, `mode` (`'antenna'`, `'sparams'` or `''`: as the settings
say), `fields`, `name` (`'rf'` or the analysis). `kicad2ems study` runs them (`kicad2ems.core.study.run`), each as a
command of its own: the solvers' as `python -m kicad2ems /gui_run.toml --events ...` (`runs.Run`), an
analysis's as its `command`. The GUI makes the same plan and the same commands. A front end that starts each itself
puts it in `run_dir(base, board)` or `tool_dir(base, board, analysis, what)` (a preview in `preview_dir`,
`tool_preview_dir`), marks the folder, skips an analysis whose `needs` did not finish (`study.unmet(engine,
failed)`), and gives an analysis the results it may start from (`runs.latest_results(base, board, config)`:
`{analysis: its newest finished run's folder}`, the config's first).
**Two engines' answers side by side.** An engine's report is its own, and two
engines' headline numbers need not be the same quantity (a rail's drop with its
ground return, or the rail's own copper). So an analysis gives the figures of
its answer by name, `figures(folder)` → `[dict(name, value, unit)]`, and engines
that answer one question name the same quantity alike; the question says which
(`Question.figures`): `drop ` and `loss` for a rail's own copper,
`hottest` and `` for the temperature, `C ,` for capacitance. An
engine may add figures of its own (`drop with return `).
`study.compare({engine: folder})` lays them side by side: `dict(engines,
labels, rows=[dict(name, unit, values, spread)])`, a value `None` where an
engine does not give the figure. `default_fields(engine, fmin, fmax, layer,
sweep)` is what an engine is asked when its field dumps are wanted and none is
set: `{option: value}` (an FDTD solver's `dump`: E on the layer at the band's
centre; mom25d's `mom_dump`: that frequency; an analysis's `fields` switch).
**What a window shows first, and what a run still needs.** An option has a
`level`: `'basic'` for the few a run is set up with (the board, the extra ports,
the frequency range and points; a solver names its own in `basic`), nothing for
the rest. kicad2ems-gui shows the basic ones in view and the others under "More
settings". `rf_needs(values)` is what an S-parameter run of a form's values
still needs, `[dict(text, key)]`: no board, a board that is not there, a KiCad
board without a port (its footprints are read, no model is made), a band the
wrong way round. An analysis says its own with `missing`. A front end lists them
where the settings are and does not start the run; kicad2ems's own commands say
the same when they are run.
## For front ends
For programs that drive kicad2ems: read a board, show its line model, start runs and read their results.
| Module | Names |
|---|---|
| `kicad2ems.core.importers.kicad` | `KiCadBoard` (a `.kicad_pcb`, or KiCad's board text), `read_pos`, `pos_port_refs`, `resolve_nets`, `DiffLegs`, `board_outline` |
| `kicad2ems.core.board` | `Board` (the canonical model), `Port` |
| `kicad2ems.core.parts` | `kind_value` (a footprint's lumped part), `not_fitted` (DNP, excluded from simulation, or 'NF' in its value) |
| `kicad2ems.core.region` | `extra_port_fps` (the footprints a region adds as ports) |
| `kicad2ems.core.layout` | `board_layout(path)`: a `.kicad_pcb` as the model board's dict (`Board.to_dict()`: every net's copper by layer, no ports asked for) with `footprints` (`[dict(ref, value, layer, through, box, pads=[dict(name, net)])]`, model mm) and `layout_of` (the file), to show before anything is run; `net_at(layout, layer, x, y)` and `part_at(layout, layer, x, y)`: the net whose copper, and the part whose pads' box, is under a point, or `None` |
| `kicad2ems.core.lines.builder` | `build` (Board → LineModel; `field=True`: every section by the field solver) |
| `kicad2ems.core.lines.reference` | `RefCopper` (the line model's reference copper, built once), `FIELD`, `FIELD_CPW`, `FIELD_REACH` |
| `kicad2ems.core.overlay` | the line model drawn on the board: `load_lines`, `reference`, `span`, `section_colour`, `z0_colour`, `drawn`, `nearest`, `source_note`, `describe`, `section_polygon`, `relief`, `plan_segments` |
| `kicad2ems.core.lines.sections` | one section's field: `modes`, `solve` |
| `kicad2ems.core.lines.calc` | a stack-up's impedance without a board: `Line`, `board_layers`, `calculate`, `fit`, `element`, `describe`, `report` |
| `kicad2ems.core.config` | `Settings`, `build_settings`, `read_toml`, `all_options`, `default_out`, `PATH_KEYS`, `OPTIONS` (`{key: Option}`), `CORE` (kicad2ems's own options), `ConfigError`, `setting_keys(cfg)` (where a config's settings are written, [its older forms](usage.md#older-forms) too) |
| `kicad2ems.core.solvers` | `registry`, `get`, `resolve_lines`, `AUTO`, `LINES` |
| `kicad2ems.core.analyses` | `registry()` (`{name: Analysis}`: every analysis), `analysis_of(folder)`, `read_config(config)` (`{name: {key: value}}` of a config's `[analysis]` tables; an analysis given several: its first), `read_sets(config)` (`{name: [{key: value}, ...]}`: every table of each, [a run for each](usage.md#several)) |
| `kicad2ems.core.study` | `study_tree()`, `questions()` (`{name: Question}`), `engines()` (`{name: Engine}`), `provided`, `dump_options`, `runs_for(asked)`; a config's: `Study`, `read_config`, `write_config`, `plan`, `unmet`, `engine_named`, `default_fields`, `compare`, `rf_needs`, `load_config(config)` (its tables, [older forms](usage.md#older-forms) migrated), `RF`; `check_lines()` (`--check`'s lines), `main(argv)` (`kicad2ems study`) ([Questions and engines](#study-api)) |
| `kicad2ems.core.runs` | `Run`, `EventTail`, `stop_runs`, `find_results`, `toml_value`, `write_toml`, `update_toml` (a config edited in place, its comments kept), `load_toml`, `read_summary`; where a front end's runs go: `run_dir`, `preview_dir`, `tool_dir`, `tool_preview_dir`, `board_name`; a run folder's mark: `mark`, `ended`, `outcome(code, stopped, crashed)`, `marked`, `MARK`; the runs: `info(folder)`, `index(base, board, running)` (a `RunInfo` per run), `latest_results`, `run_log`, `same_config`, `when_text`; a run's process tree: `process_children`, `descendants(pid)`, `tree_of(pid)`, `kill_tree(pid, also)` |
| `kicad2ems.core.formats` | `check` (a JSON of kicad2ems's, e.g. `python -m kicad2ems.core.sysinfo`'s: None, or why this kicad2ems cannot read it) |
| `kicad2ems.core.touchstone` | `read_touchstone`, `port_names` (a kicad2ems Touchstone file's port names), `read_matrix` (the file's matrices as written: S, Y, Z, H or G), `to_s` |
| results | `core.fields.antenna` (`read`, `read_sphere`, `sphere_cuts`, `sphere_gain`), `core.fields.frames` (`find_dumps`, `write_frames`), `core.meshes`, `core.phased` ([For solvers](#for-solvers)) |
| `kicad2ems.examples` | `examples()` (`{name: config path}`), `index()` (every example as a menu's entry: `[dict(name, config, group, title, source)]`, the analyses' own after kicad2ems's), `prepare_example(name, folder)` (an example copied, its board made, into a folder of the user's), `user_folder()`, `board_of(config)` |
| `kicad2ems.emsdev.cpu` | `core_threads` |
| `kicad2ems.gui.planview`, `kicad2ems.gui.sectionview` | `PlanView`, `SectionView` ([The plan view](#planview)) |
## The command line and its files
A front end runs kicad2ems as a separate process (`kicad2ems.core.runs.Run` makes the command line:
`python -m kicad2ems .toml --events [--preview]`; dfsynth runs `python -m kicad2ems.core.cli`) and
reads what it writes. Each file another program reads names its format and version, `format` and
`format_version` ([`kicad2ems.core.formats`](reference/index.md)); the readers below take a version up to
their own and say to update kicad2ems for a newer one. A version goes up only when a key is removed or changes
meaning; a new key needs none. A file without them was written before they were added: version 1.
| File | Format | Reader |
|---|---|---|
| `_run.json`, the run summary | `kicad2ems-run` 1 | `read_summary(path)` |
| the event stream (`--events FILE`, JSON lines; its first line names the format) | `kicad2ems-events` 1 | `EventTail(path).read()` |
| `python -m kicad2ems.core.sysinfo`'s JSON on stdout: solvers, GPUs, memory, threads | `kicad2ems-sysinfo` 1 | `formats.check(d, 'kicad2ems-sysinfo')` |
| `[_]_antenna.json`, an antenna run's results (`sphere_file`: its far field) | `kicad2ems-antenna` 1 | `fields.antenna.read(path)` |
| `_board.json`, the board every solver gets | `kicad2ems-board`, `version` 1 | `Board.load(path)` |
| `_.sNp`, Touchstone, the ports named in a `! ports: 1=P1, 2=P2d, ...` comment | Touchstone 1 / 2 | `read_touchstone(path)`, `port_names(path)` |
The events are `format` (first), `stage` (`name`), `log` (`text`), `status` (a solver's progress: `run`,
`fraction`, `eta` and the solver's own numbers), `file` (`label`, `path`) and `done` (`code`); a reader passes
over a kind it does not know. [Usage](usage.md#events) shows a stream. A run is stopped from outside with
`stop_runs(out_dir)`, which lets it finish its step and write what it has. To end one at once, end what it
started too: `kill_tree(pid)` kills the process and everything below it by parent pid (Windows:
`taskkill /T /F`), including an analysis's MPI ranks, which run in sessions of their own. `tree_of(pid)`,
taken when the run was asked to stop, lets a later `kill_tree(pid, also=...)` reach children that a tool
which ended on SIGTERM left to init (Linux: each with its start time, so a pid used again is not touched).
## gfdtd's engine
gfdtd runs openEMS's models: its `ContinuousStructure` and `openEMS` classes stand in for CSXCAD's and openEMS's
own. kicad2ems.fdtd connects it (`kicad2ems.fdtd.gfdtd`). What it relies on:
| Name | What |
|---|---|
| `ContinuousStructure`, `openEMS(..., backend=)` | openEMS's and CSXCAD's Python interface, as openEMS scripts use it; `backend`: `'auto'`, `'gpu'`, `'vulkan'`, `'core'`, `'numpy'` |
| `engine.gpu_info()`, `engine.core_info()` | `(usable, one line)` of the GPU and the compiled CPU core |
| `engine.resolve_backend(name)` | `'vulkan'`, `'core'` or `'numpy'` for `'auto'`, `'gpu'`, `'cpu'`, ... |
| `engine.concurrent_runs(cells, runs)` | how many runs to keep on the GPU at once |
| `__version__` | the release |
Its conducting sheets are openEMS's model, lossy (`--sigma`), and take more:
`AddConductingSheet(..., roughness=, finish=, finish_share=, face=)`, rough
copper, a surface finish on a share of the sheet's loss, and a sheet that is one
face of thick copper.
openEMS itself is the other engine, imported only by `kicad2ems.fdtd.openems.engine`.
## The plan view
The KiCad plugin's map is the GUI's plan view: `kicad2ems.gui.planview.PlanView`, the board seen from above. A subclass may use, beside
its public methods (`load`, `set_board`, `set_lines_visible`, `current_layer`, `z_of`, `redraw`, `fit`,
`select`) and its `selected` signal: `plot` (the pyqtgraph `PlotWidget` it draws in), `mesh` (the mesh selector),
and override `redraw()` and the mouse hooks `_moved(scene_pos)` and `_clicked(event)`, calling the base's for
what it does not handle itself.
## `dfsynth --describe --json`
kicad2ems-gui's Filter page never imports dfsynth: it builds its form from this description and runs dfsynth as a
process.
| Key | What |
|---|---|
| `format` | `1`; the page reads format 1 and says which package to update otherwise |
| `version` | dfsynth's release |
| `kinds` | `{type: [topologies]}`: `lowpass`, `highpass`, `bandpass`, `bandstop` |
| `presets` | `{name: {h, er, tand, material}}`: the substrate presets |
| `options` | `[{key, flag, kind, default, choices, help, group}]`, every option, `kind` one of `str`, `float`, `int`, `flag` |
[← Architecture](architecture.md) · [Index](index.md) · [Next: KiCad import →](kicad-import.md)