APIs¶
← Architecture · Index · Next: KiCad import →
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 (in the documentation site) lists every
module, class and function.
Interface |
Provided by |
Used by |
|---|---|---|
core |
fdtd, mom25d, fem, pcbqs |
|
core |
pcbqs, fem |
|
core |
gui, ipc, dfsynth |
|
fdtd, mom25d, fem, pcbqs |
core |
|
pcbqs, fem |
core, gui |
|
core |
gui, ipc, dfsynth |
|
gfdtd |
fdtd |
|
gui |
ipc |
|
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 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drives, grids, tapers: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
SOLVERS = ('kicad2ems.core.solvers.lines.solver:Qucs', ...,
'kicad2ems.mom25d.solvers.mom:MoM25D', ...)
It declares, as class attributes:
Attribute |
Meaning |
|---|---|
|
|
|
|
|
whether |
|
the keys of its options a run is set up with (its main cell size: |
|
|
|
rough cost (cheap solvers run first); its place in lists |
|
|
|
its settings, |
and implements, in the order the pipeline calls them:
Method |
Returns |
|---|---|
|
|
|
a message when its settings cannot be used together, or |
|
why it cannot model this board, a list ( |
|
|
|
its own form of the board (openEMS: the boundaries and mesh); a preview stops here |
|
a |
|
|
|
what its own model holds, in the board’s terms, for the parity checks; or |
|
whether an earlier run’s result may stand for its solve in this run ( |
|
its own extra outputs (optional) |
|
the GPUs it would run on here and why there are none, or |
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 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 |
|---|---|
|
|
|
|
maps for a viewer |
|
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, a board’s coupling, a channel in
time, the line parameters and the radiated EMC questions among
them:
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 |
|---|---|
|
|
|
one line: what it gives |
|
its place in lists, and in a run of several |
|
it has a preview (the model and its mesh, no solve) |
|
the analyses it cannot run without the results of |
|
the file a finished run (a preview) leaves in its folder ( |
|
the options whose values are paths: relative to the config file they are read from |
|
|
|
what the board can propose settings for ( |
|
environment variables its command runs with |
|
the questions it answers, from one run: |
|
the program’s name as a list shows it beside a question: |
|
|
|
the bool option that makes it write field dumps too ( |
|
its engines when it is several to choose from beside a question: |
and implements:
Method |
Returns |
|---|---|
|
|
|
its settings, |
|
a short name for a run of these settings (the rail, the converter): its folder’s |
|
the command line that runs it into folder |
|
the progress a line of its output states, or |
|
a command that proposes settings from the board, and its output as |
|
what a result holds, to read: |
|
what a result holds, to plot: |
|
settings a result proposes for other analyses: |
|
the examples it ships: |
|
its settings for a run asked only some of its questions (a rail’s drop without its impedance) |
|
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 |
|
whether the folder holds its result: by default, that its result file is there. An engine whose file another also writes looks inside it |
|
the figures of its answer by name, |
|
what a run of these settings still needs before it is started: |
|
the analyses whose latest result it can start from when there is one (the temperature, from a circuit’s losses): not required, as |
|
what a study may hold several settings of it by, each a run of its own, as a front end names them ( |
|
the options that differ from one of those runs to the next ( |
Its maps need no method: an analysis writes them as field dumps under <out>/<name>/exc_<what>/ with its board
as <out>/<name>_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.<name>] (or [[analysis.<name>]], several), which
kicad2ems itself leaves alone; its [study] says which run (usage):
[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 |
|
the ports’ S-parameters |
every solver |
RF |
|
a driven port’s far field |
the solvers whose |
RF |
|
every trace’s impedance and delay |
the line model’s solvers |
Power |
|
a rail’s DC drop, current density and loss |
an analysis that |
Power |
|
the impedance a rail’s loads see (shares |
|
Power |
|
a converter’s input loop and its magnetic field |
|
Power |
|
a switching circuit on the board’s copper |
|
Power |
|
the capacitance between nets |
|
Thermal |
|
the board’s steady temperature |
|
EMC |
|
a switching circuit’s conducted emission through a LISN in each supply line, against CISPR 32 or CISPR 25 |
pcbqs’s |
EMC |
|
the board’s ports driven by a clock or data: the field at a test site’s antenna against CISPR 32 |
|
EMC |
|
the voltage a plane wave puts on each port, the worst over direction and polarisation |
|
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). 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 <folder>/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 <load> and loss for a rail’s own copper,
hottest and <part> for the temperature, C <net>,<net> for capacitance. An
engine may add figures of its own (drop with return <load>).
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 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
the line model drawn on the board: |
|
one section’s field: |
|
a stack-up’s impedance without a board: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
results |
|
|
|
|
|
|
|
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 <settings>.toml --events <file> [--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); 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 |
|---|---|---|
|
|
|
the event stream ( |
|
|
|
|
|
|
|
|
|
|
|
|
Touchstone 1 / 2 |
|
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 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 |
|---|---|
|
openEMS’s and CSXCAD’s Python interface, as openEMS scripts use it; |
|
|
|
|
|
how many runs to keep on the GPU at once |
|
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 |
|---|---|
|
|
|
dfsynth’s release |
|
|
|
|
|
|