OpenPELS / docs /architecture /simulation_workflow.md
minjiechen's picture Elvis0001's picture
Add qualified 2:1 SI2, SP2, RSC2, and Buck_Stacked workflows (#1)
0a53b5b
|
Raw History Blame Contribute Delete
12.1 kB

Simulation workflow

The integrated simulator runs one curated NGSpice preset at a time. Its starting schematic is the circuit encoded in a bundled testbench. The browser editor's current project and the analytical model are independent inputs to their own workflows. A structural SPICE or Spectre export from the editor is a separate artifact for an external testbench workflow. See circuit data model.

sequenceDiagram
    actor U as User
    participant H as Workbench shell
    participant F as Simulator iframe
    participant A as Python job API
    participant N as Pinned engine and NGSpice
    participant D as Local run files
    U->>H: Select XFLY6S in Gallery and open Simulator
    H->>F: Preset ID, ratio, Vout and Iout
    U->>F: Run with numeric testbench controls
    F->>A: POST simulation job
    A-->>F: 202 and job ID
    A->>N: Dispatch job and select bundled template
    N->>D: Write executed deck, log and raw data
    N->>D: Write metrics and waveform artifacts
    F->>A: Poll job by ID
    A-->>F: Settings, measurements and artifact URLs
    F->>A: Fetch waveform PNG or download files

XFLY6S from selection to executed deck

  1. Select a preset. Gallery maps analytical ID xfly2p to simulation ID xfly6s. simulationAvailable() requires a preset, 4:1 selection, output voltage 0.30–1.10 V and output current 0.1–40 A. createSimulator() health-checks the service, loads /simulator/, and sends pe:select-topology. The frame sets target voltage and current and initializes Vin as ratio × Vout; the simulation controls remain editable. With the shell defaults this handoff is 0.8 V, 2 A and 3.2 V input. gallery.js:5, pe.js:27, pe.js:61, simulator.js:53, simulator_bridge.js:101
  2. Submit numeric settings. /simulator/ serves HTML adapted from the pinned engine's original GUI. simulator_html() substitutes one preset selector, per-preset frequency, scoped images, opt-in sweep, and the async bridge. On Run, the form supplies voltage/current, inductance, flying capacitance, frequency, coupling, winding DCR, switch resistance and off-capacitance, gate drive and capacitance, stop time, and maximum step. openpelsSimulationFetch() wraps these as {kind, payload} in a POST to /api/simulation/jobs. It polls the job ID about every 500 ms, with a 15-second timeout per poll and a 30-minute overall polling window. server.py:45, simulator_frame.py:4, engine:967, simulator_bridge.js:2
  3. Validate and dispatch. WorkbenchHandler.do_POST() caps the request body at 16 KiB and accepts only the job endpoint. validate_request() allows run, sweep-case, or source, allowlists fields, and checks finite numeric values and the topology/case selector. One worker executes jobs and at most three may be active or queued. The HTTP layer uses 202 on submission, 400 for invalid input, 413 for invalid body size, 429 for a full queue and 404 for a missing job ID. Job states are queued, running, succeeded, and failed. The bridge converts a failed job into a response the preserved GUI can render. server.py:49, server.py:68, simulator_service.py:40, simulator_service.py:161, simulator_bridge.js:21
  4. Generate the executed netlist. Simulator.__init__() verifies the bundled Python engine against simulator-source.json, imports it, and points its template map at static/testbenches/netlists/*_transient.cir. settings_from_payload() clamps or defaults inputs and converts units. settings_for_operating_point() sets a resistive load Rload = Vout_target / Iout_target. infer_topology_duty() uses half the input voltage, average winding DCR, and a topology calibration factor to estimate duty, then clamps it to 0.12–0.78. This is a preset-specific open-loop calculation. prepare_deck() substitutes deck parameters, DCR, model resistance, .tran, measurement window and output paths and adds probes while retaining the template's circuit and gate expressions. simulator_service.py:86, engine:1072, engine:1123, engine:1439
  5. Execute and measure. run_ngspice() invokes ngspice -b with the generated deck as an argument, captures output in a log, and uses a 120-second subprocess timeout. read_selected_ascii_raw() reads the expected per-topology channels. analyze_case() computes winding and summed currents, capacitor differential voltages, output ripple, averages, phase imbalance, Pin = −Vin × i(Vvin), and Pout = Vout²/Rload. Time averages integrate over the selected window, ordinarily at most the last 0.2 µs. Reported efficiency uses input power adjusted for estimated energy storage and a simplified gate-capacitance term. It is a modeled result from the deck and postprocessor. engine:1167, engine:1185, engine:1232, engine:1282
  6. Render and download. make_plot() creates an Agg-rendered PNG with voltage and flying-capacitor transients, phase and summed winding currents, and a final-window capacitor zoom. The service adds a CSV with up to 4,000 rows sampled by index and removes raw and full time-series files after success. It returns the engine revision, executed settings, metrics, plot URL and artifact list. The browser renders an image and metrics table and offers the executed deck, log, sampled CSV, JSON and available PNG. Files are stored under <work>/output/xfly_gui/<run_id>/. Completed jobs are pruned on subsequent submissions when older than an hour measured from creation or when the retained count reaches 64. Job metadata is memory-only. engine:1355, simulator_service.py:113, simulator_service.py:184, simulator_service.py:214, simulator_bridge.js:38

Sweeps and original testbenches

Path Semantics Evidence
kind: run One topology with topologies: [id]. Returns metrics and a waveform plot. simulator_service.py:50, engine:1480
kind: sweep-case One topology with topology: id. The browser submits 15 cases if enabled, using 0.65, 0.75, and 0.85 V at 20, 40, 60, 80, and 100% of base current. Each case copies base parameters except the operating point. The backend recomputes duty/load and returns a metric and artifacts. The browser assembles SVG efficiency curves. Up to three browser requests can be in flight while execution remains serial. engine:743, engine:880, engine:1515, simulator_frame.py:40
kind: source A developer-facing job using an exact manifest case_id. source_run() checks the original deck checksum and changes output instrumentation and probe saves in the executed copy. Circuit, models, gating, initial conditions and transient command stay intact. The UI has no original-case selector. Legacy #testbenches opens Simulator. simulator_service.py:74, simulator_service.py:123, pe.js:389
Standalone testbench runner The manifest covers three variants per topology: startup (2 µs), long settling (20 µs), and DCR mismatch (20 µs). run_testbench.py verifies source bytes, prepares paths, runs NGSpice and requires finite measurements. With --validate, only waveform-file writes are suppressed in a temporary copy. testbench manifest:1, run_testbench.py:21, testbench README

The original XFLY6S source deck and a parameterized XFLY6S run can give different results for the same nominal topology. The original fixes gate timing, devices and .tran settings in the source, while the parameterized path adjusts run settings and infers duty. To reproduce a result, record which path, deck, engine revision/version, settings, and measurement window were used. source deck:103, simulator_service.py:123, engine:1123

Adding an engine such as Cadence Spectre

Current evidence. The native netlist code can print a structural Spectre dialect through printSpectreNetlist(). The archived upstream SimulationEngine type includes ngspice and vacask. Neither the OpenPELS Simulator job API nor its launcher exposes an engine selector, native VACASK execution, or a Spectre runner. Spectre syntax generation alone does not establish executable testbenches or compatible device libraries. printers.ts:500, profile-engine.ts:7, simulator_service.py:17, server.py:105

Possible extension, not implemented. A runner boundary could keep the existing job and result interfaces while making deck preparation, invocation, diagnostics and result parsing engine-specific. A Spectre implementation would need a licensed installation, approved local device models if applicable, dialect-appropriate gate sources and saves, and a supported method to read output into a common time, voltage, current and capacitor-signal representation. The present parser expects NGSpice ASCII raw data and topology-specific probe names, and the present deck uses NGSpice .control statements. An acceptance case could compare XFLY6S waveforms and metrics under equivalent model parameters and record engine versions, measurement windows, signal sign conventions and tolerances. A separate design decision is required to compile arbitrary edited schematics into testbenches, regardless of engine. engine:62, engine:1185, xfly6s_transient.cir:120