Probes¶
A probe is a reading named the way the result accessors are typed. Index a result by one to get it at every stored sample:
res = pulsim.simulate(b, t_end=2e-4, dt=1e-7, switch_fn=sf)
res["v(out)"] # node voltage (= res.v("out"))
res["v(sw,out)"] # voltage difference (= res.v("sw") - res.v("out"))
res["i(L1)"] # device current (= res.i("L1"))
res["i(R1.to)"] # current INTO the device at its `to` terminal
res["p(D1)"] # absorbed power v(from, to) * i(into from)
res["S1.on"] # 1.0 / 0.0: the mode the solver stamped (recorded mask)
res["C1.power"] # a channel of a recorded device trace (res.device_output)
Every name is resolved by the kernel (record::ProbeSet) onto a reading
it already has: a solved branch unknown (inductor, transformer winding,
voltage-source family, branch-form switch), the law the solver stamped
(resistor, PWL switch / diode under each row's mode, current sources,
VCCS, CCCS, gyrator) or a static Newton device's law. res.i takes the
same readings, so res["i(X)"] and res.i("X") are equal bit for bit.
Two errors:
- An unknown node, device, pin or channel, or a name outside the
grammar, raises
NetlistErrornaming the probe and the nearest valid names (no device "RL1"; nearest: RL). - A reading the run did not record raises
UnsupportedErrornaming what to declare. A capacitor's current and power are the companion current the integrator committed, recorded only when the run names it:simulate(..., record_currents=["C1"])orb.add_probe("i(C1)")(pwl and trbdf2).
S1.on is the recorded bit of every row, an unsolved one included (a
seeded initial_state row: res.switch_states_unsolved), whereas a
switched branch's current and power there hold the next solved row.
Pins are from and to (the first and second terminal of the branch).
A current source, VCCS or CCCS reads res.i OUT of its n_pos
terminal, so its i(I1.from) is -res.i("I1"). A gyrator's (and a
winding's) two ports are read with res.i(name, port=1|2); its p(G) is
the sum over both ports (zero to round-off: it is lossless). A
power_mosfet composite reads i(M) (its drain) and refuses pin forms.
res[...] returns a plain NumPy array; on a variable-step grid average it
with res.avg(probe) (time-weighted), not .mean().
Declaring probes on the circuit¶
b.add_probe("v(out)") # resolved now: an unknown name raises NetlistError
b.add_probe("i(C1)") # the same recording as record_currents=["C1"]
b.probes() # ['v(out)', 'i(C1)']
Declared probes travel with the circuit: b.build(), Circuit.to_yaml() /
from_yaml() (a top-level probes: list) and the netlist YAML key
circuit.probes: (below). A name is resolved against the devices the
circuit has when it is declared, so declare it after its device.
What a declaration changes in a run:
- A probe that is a function of the stored row and mode record (
v(),i()/p()of everything but a capacitor,S1.on) adds nothing: the run is the run without it, andres[...]evaluates it from the rows. i(C)/p(C)of a linear capacitor (or of apower_mosfetcomposite'sC_gd/C_ds) records the committed companion current at every stored row: one mechanism withrecord_currents=, the same table and law, equal bit for bit.- A Newton device whose current needs the committed charge (nonlinear capacitor, Lauritzen diode, IGBT with a tail) is recorded on every run that has one, declared or not.
circuit:
devices:
- {type: resistor, name: R1, from: in, to: out, R: 1000.0}
- {type: capacitor, name: C1, from: out, to: gnd, C: 1.0e-6}
probes: ["v(out)", "i(C1)"]
Keeping only the selected probes¶
res = pulsim.simulate(b, t_end=1.0, dt=1e-7, switch_fn=sf, recorders=[
pulsim.RecordOptions(what=pulsim.Probes(["i(La)", "v(fa,fb)", "p(Ra)"]))])
res["i(La)"] # one column per selected probe, equal bit for bit to the full run's
res.states # UnsupportedError naming what=Probes([...])
what=pulsim.Probes() with no names keeps the circuit's declared probes.
The result then holds one real per selected probe per row (plus times
and the switch mode record); reading states, or a probe that was not
selected, raises UnsupportedError (feature == "what"), and so does
every accessor that reads the rows (res.v, res.i, res.avg, res.at):
the kept columns are read with res[name], under the name as written in
Probes([...]) (blanks removed). Event rows (right_limit_states,
inner_events) are kept. The state rows
are released after the run: during the run the engine still holds them,
so the peak memory of the run is that of a full one.