Skip to content

Result reference — SimulationResult

Every engine returns the same class: pulsim.simulate(...) on pwl, trbdf2 and exact (dsed) gives a pulsim.SimulationResult (isinstance(res, pulsim.SimulationResult) holds on all three). The exact engine's former _PEDSimulationResult is gone (breaking for code that tested the class name; see the CHANGELOG).

Rows and the grid they sit on

Member What it is
times sample times, 1-D float array
states read-only (num_steps, state_size) view, zero-copy
num_steps(), empty() row count; True when nothing was recorded
grid GridKind.Uniform (pwl), Accepted (trbdf2, exact: the accepted steps, packed at edges) or Requested
switch_states, switch_states_unsolved per-row switch / diode mask the solve stamped; rows not produced by a solve under it
engine_used, engine_route_reason the engine that ran and why engine='auto' chose it

Row 0 of a pwl or trbdf2 run is the start solved at t_start: the capacitor voltages and inductor currents of the start vector (builder ICs, the zero start or an explicit initial_state=) are kept, the other node voltages and the source currents are solved under the mode row 0 records, as the exact engine's row 0 (in-loop recorders, the live stream and a loss port's tracker take it as their start). The integration still starts from the vector as given, and controllers primed at t_start and step_observer's calls up to the first step read that vector. Static Newton laws (Shockley / Newton diode, level-1 MOSFET, level-1 IGBT without tail) are solved by a Newton iteration; a free diode the solved row contradicts is re-decided for row 0 alone (row 0's recorded bits follow it; the first step still decides from the given vector). Row 0 keeps the given vector when the circuit has a stateful device (nonlinear capacitor, saturable inductor, Lauritzen diode, IGBT tail), a machine, a line, a flux node or a b_extra_fn, when that Newton solve does not converge (res.start_row_newton_failed is then True), when the declarations contradict the circuit, when no diode mode holds, or above 512 unknowns plus capacitors (docs/known-limitations.md). A resumed run's row 0 is the snapshot's state; a start_from_dc_op=True row 0 is the DC point.

On an Accepted grid a plain .mean() weights samples, not seconds. Use the time-weighted readers below or time_average. When the stored times are not uniform, res.v(name), res.i(name), res.p(name), res[probe] and a recording's rec[probe] (on its own times) return a pulsim.Signal: an ndarray that carries t and offers .avg() / .rms() (time-weighted, over an optional [t0, t1]); its .mean() / .std() (and np.mean / np.std of it) emit pulsim.GridWarning. Indexing indexes t with it (v[t > t0] is still a Signal); elementwise arithmetic on the same grid keeps it; reductions, np.* functions and anything that would change the grid give a plain ndarray. np.asarray(v) is the plain array sharing memory. A uniform grid (pwl) returns a plain ndarray.

Reading a probe

A probe is a text such as "v(out)", "v(a,b)", "i(L1)", "p(R1)" or an expression of them ("v(out)*i(L1)").

Method Returns
v(name, t=None), i(name, t=None, port=None) node voltage / branch current per row (or at row index / slice t)
at(probe, t) value at time(s) t: linear on the step that holds it, the right limit at an event where the engine stored one
avg(probe, t0=None, t1=None) time average over [t0, t1], window clipped exactly
rms(probe, t0, t1), integral(probe, t0, t1), minmax(probe, t0, t1) the same window, exact for the linear dense output
currents(), power(device), signal(name), signals() all branch currents; average device power; observer traces
loss_events(device), device_energy(device) per-event loss records; energy split per device
flux(name), b_field(name), h_field(name) magnetic network quantities

Run statistics

res.stats is a RunStats: engine-independent counters, zero where an engine does not report one — engine, n_steps, n_accept, n_reject, n_solves, n_factorizations, n_newton_iterations, n_newton_retries, n_forced_accepts, n_mode_events, n_state_events, n_gate_events, n_ctrl_ticks, n_chatter_breaks, n_exact_steps, n_rk45_steps, n_bdf2_steps, n_gate_undersampled, gate_pulse_min, gate_sample_spacing_max, cpu_time_seconds.

The exact engine's old attributes stay as read-only aliases of res.stats: n_accept, n_reject, n_events (= n_mode_events), n_rk45_steps, n_bdf2_steps, n_exact_steps, cpu_time_seconds.

Engine-specific diagnostics: newton (NewtonCounters), counters (pwl loop counters), commutation_events, dt_retries, event_iteration_breaches, reinit_records, resolution (pwl with resolution_diagnostics), mode_diagnostics / diagnostics, n_restart_steps, n_restart_factorizations, newton_roundoff_*, control_tick_counts, control_tick_jitter_max, step_loop_python_callbacks, final_snapshot (for simulate(resume_from=...)), states_bytes / total_bytes.

Snapshots: final_snapshot and resume_from

result.final_snapshot is the solver's state at the run's last time. Passing it as simulate(..., resume_from=snap) continues from there, and it can be pickled. Besides the circuit state it can carry the step controller's memory, which snap.controller_state shows as (kind, values) or None:

kind written by what a resume does with it
2, LTE engine='trbdf2' the next step is the step the stopped run would have taken
3, exact engine='exact' engine='dsed' resumes from it; the other engines refuse it
None engine='pwl', or a snapshot without the block trbdf2 restarts its controller; pwl steps on its dt

What to expect from a split run (tests in python/tests/test_trbdf2_resume_controller.py):

  • Bit-identical on trbdf2 when the controller block is the run's whole loop state, for example an RLC with no switches or diodes, split at one of the continuous run's step times.
  • Not bit-identical on a switched circuit. The edge-learning and hold state of the TR-BDF2 loop is not in the snapshot, so the next gate edge can land in a different 14th digit. The resumed run still agrees to tolerance.
  • Across engines. A pwl snapshot resumes on trbdf2 and the reverse, to the engines' tolerance.
  • A run with a control graph refuses to resume between two of its ticks.

Recorders: recorded and recorder_feed

With simulate(recorders=[pulsim.Recorder(...)]):

  • res.recorded[name] is a pulsim.Recording: probes, times, values[probe] (or rec[probe]), interpolated, n_samples, windows[probe][field] and periods[probe][field] (fields integral, avg, rms, min, t_min, max, t_max, t0, t1), the event rows event_t, event_left[probe], event_right[probe], event_t_right, event_resolution ('exact', 'settled', 'within_dt'), and feeding.
  • res.recorder_feed says which feed ran: mode ('in-loop' or 'stored-arrays'); in the loop also n_steps, n_events, n_jumps, n_dropped; on the stored-array pass why; after simulate(resume_from=...) a resume note when the record did not continue from the snapshot.

  • res.events (a pulsim.EventRows, only when a recorder sets event_rows=True; such a recorder may have no probes): the whole state vector and switch mask on both sides of every event — t, t_right, resolution, left_states, right_states, left_masks, right_masks, sample_index. 'exact' (exact engine) and 'settled' (trbdf2's settled post-event state, a restart-rule line's start, and the fixed engine's right limit at the grid point where the step stamped with the new mask starts — a gate edge at t_e is reported at t_e - dt, since the step ending at t_e already runs under the new mask — re-solved under the new mask and the post-jump sources with the capacitor voltages and inductor currents held) rows hold the right limit at t. 'within_dt' rows are brackets: the right side is the end of the first step solved under the new mask, at t_right (the fixed engine where its right-limit solve does not apply: a nonlinear mode, a b_extra_fn, device losses, transmission lines, or a solve that did not hold the step's mask). A stored step whose mask changed with no reported event (a restart-rule line through a point where nothing jumps) is a bracket over that step. On the fixed engine a PWM / pulse source edge that changes no mask has a row where the solve applies (no row otherwise); on trbdf2 it has none. Only res.events holds these right limits: a probe recorder's own event rows stay brackets on the fixed engine. An instant can carry two rows (a restart's jump and the commutation there). Under store_every > 1 the rows added from stored masks span a stored interval. Runs that do not ask pay nothing: no feed is attached. A pwl / trbdf2 route that cannot be fed in the loop is refused (UnsupportedError, feature event_rows).

The arithmetic, window rules and feeding table are in Kernel recorders.

Recorder(stream=pulsim.NativeLiveStream(...)) pushes kept rows into the stream's ring as (t, one value per probe) — every decimate-th one (the stream's own setting, default 100; pass decimate=1 for all); in the loop (pwl, trbdf2) while the engine runs, on the stored-array pass after it. Each run re-attaches the stream (a new ring, read from its start); a run that falls back from the loop to the stored pass keeps the rows the loop pushed. Give each recorder its own stream.

A run that throws. The recorder's feed is detached from the Simulation object when simulate() returns or raises. A later run on the same object starts with no feed attached and records nothing from the failed run: call simulate(..., recorders=[...]) again with fresh Recorder objects (or the same ones: a Recorder holds no run state; its stream, if any, is re-attached).