SPICE Model Generation and Validation

GX-TXT DEV112 P011-bis

Configure the generation of a SPICE model and follow the validation with the Generator’s reference datasets.

Prepare the frozen parameters and the domain

Generate the Session Triode Curve Fitting and SPICE Validation with Session → New Session → Generate Session. First run the family fit with shared parameters. In the Session folder, analysis/curvefit.family_global will contain fit_parameters.csv and fit_domain.csv. Enable SPICE Build and Validation from Configuration → Modules and keep the fit out of the next run with Run / recalculate now disabled on the fit tab.

Selection of Triode Curve Fitting and SPICE Validation in Generate Session before the Session is created.
Selection of Triode Curve Fitting and SPICE Validation in Generate Session before the Session is created.

Choose triode.koren_v1 in Mathematical model. Parameters… shows the model parameters to check the correspondence with the CSV. In Frozen parameter CSV and Training-domain CSV press Browse… and open the two files above. The second is optional and keeps the information needed to tell observations inside the training domain from those outside it. In the tested release the module preflight rejects the relative path prefilled by the Generator, even after the CSV has been created by the fit (bug 151). Choosing the files with an absolute path allowed the run.

Generator configuration before the CSV paths were corrected.
Generator configuration before the CSV paths were corrected.
Parameters available for the selected mathematical model.
Parameters available for the selected mathematical model.

Set validation, SPICE model, thresholds and sweep

Command
Validation dataset (optional)
Choice and meaning
Use triode.family.source to repeat the comparison on the fit measurements. The field is declared optional. In testing the preflight rejected the empty value, even with a binding on auto (bug 154). To repeat the comparison use the source Dataset and the bindings preset by the Generator. In Input variable bindings assign X_V, Vg_V and Y_mA to the X, family and measurement roles. With auto check in the results which columns were resolved.
Command
Validation dataset relationship to fitting data
Choice and meaning
training_reused identifies the same observations as the fit, independent observations obtained and kept separate from training, other a known but different relationship and unspecified a relationship left undetermined. The declaration informs the interpretation in the report. In an interface test the output also gave independent applied to the same Dataset: the field records what the user declared. Check the provenance of the observations before using the independent interpretation. The Generator test uses training_reused.
Command
Generated SPICE subcircuit name and ngspice executable or path
Choice and meaning
Use GXTXT_MODEL as the subcircuit name. Leave ngspice when it can be resolved by the installation, or give its executable. The test used ngspice 44.2. The generated file contains the directive .SUBCKT with the chosen name.
Command
SPICE vs analytical absolute tolerance and SPICE vs analytical relative tolerance
Choice and meaning
In the lab they are 10⁻⁶ mA and 10⁻⁷ dimensionless. The point-by-point comparison threshold combines the absolute tolerance and the one relative to the analytical quantity. Choose the tolerances based on the numerical precision and the magnitude of the model.
Command
Minimum |analytical Y| for relative-error metrics
Choice and meaning
The initial threshold of 10⁻⁹ in the model unit defines which denominators have a useful scale for the relative metrics. For values near zero check the absolute residual. The buttons Reset of the three fields restore their respective initial values.
Command
Points per generated sweep curve and Generated curves per sweep profile
Choice and meaning
41 points per curve and 7 curves per profile in the test. The module varies X and the family parameter in complementary profiles. The number of analytical comparisons is 2×41×7=574.
Command
Model X minimum override, Model X maximum override, Model family minimum override, Model family maximum override
Choice and meaning
These are the four limits of the sweep domain. Empty uses the domain derived from the relevant inputs. You can give ordered numerical limits in the model units to change the interval to check. Compare the effective limits listed in the report.

Check a sweep with an imposed domain

In a new Generator Session use the frozen CSVs of the verified fit and keep the initial Dataset bindings. Write GUIDA_TRIODE as the subcircuit name and give the path of the ngspice executable, if your installation requires an explicit path. Set X min/max to 20/200 V and family min/max to -30/-10 V. Use 11 points and 3 curves per profile, absolute tolerance 10⁻⁵ mA, relative 10⁻⁶ and denominator threshold 10⁻⁸ mA. Use Disable all to focus on the report. Verification bounds gives the requested limits, the file contains .SUBCKT GUIDA_TRIODE and the analytical comparison gives 66 points with outcome PASS. The second comparison still uses the 439 reused measurements.

Run and tell the two comparisons apart

  1. Tick Run / recalculate now. In Graphs offered by module choose the individual checkboxes or Enable all. Disable all leaves the numerical validation available. Configure… changes the corresponding figure and Module graphics… the common settings. In Run start Run enabled analyses.
  2. In Results check spice_model.lib, the testbenches .cir, the report spice_validation_summary.txt, prediction and metrics tables. The subcircuit is reusable with the terminal order given in the file. The report records model, adapter, units, executable, domain, thresholds and comparison result.
  3. For the analytical comparison check 574 points, a maximum absolute residual of about 1.36×10⁻¹² mA and PASS. This test checks the numerical equivalence between the analytical expression and the subcircuit over the evaluated domain. For the comparison with the reused measurements, check 439 observations and an RMSE of about 1.08838 mA. A test with new independent measurements has a different purpose and must be declared in the relationship field.

In Plots look for the analytical/SPICE overlay, the residuals and the parity plot for the sweeps. With a measured validation Dataset, the overlay plot, the residuals SPICE − measured and the plot of the points against the domain describe the second comparison. The domain plot is used to spot extrapolation. Open with Graph → Open PNG 1:1 to read legend and axes.

Select the variant with the figure Analytical vs SPICE parity, open Presentation → Title and labels…, write Parità fra modello e SPICE and save. Use Render → Rerender to update the image. The two axes and the diagonal reference stay the same.

In Configure… you can adjust title, labels, markers and X/Y limits. An empty limit uses the automatic scale. The figure-specific settings let you show the comparison you want.

  • Overlay and residuals offer Profile to display x_sweep, family_sweep or validation. For the overlay choose the measured traces when available, the analytical ones and the SPICE ones. For the residuals choose the SPICE−analytical or SPICE−measured difference and the zero line. The profile validation requires the observations.
  • In the parity plot set the marker size and Use the same numeric range on X and Y to compare the outputs on the same scale.
  • In the validation overlay enable measured points and analytical and SPICE predictions separately. Distinguish in-domain / out-of-domain measured points uses the training domain to tell the groups apart when available.
  • In the validation residuals Residual quantity absolute shows the differences in the model unit and relative_percent shows them as a percentage where defined. The other choices show the zero line, the points inside/outside the domain, the marker size and the width of the family guides.
  • In the domain plot Show convex-hull training-domain boundary shows the convex hull of the training points when available. Adjust markers and outline width to make the points readable.

In Module graphics… sets only the module preferences you want to differentiate. The others inherit the global ones.

Options of the plot of the observations against the training domain.
Options of the plot of the observations against the training domain.
Analytical–SPICE parity before renaming the variant.
Analytical–SPICE parity before renaming the variant.
The same figure after the title change and regeneration.
The same figure after the title change and regeneration.
Results after the analytical comparison and the re-evaluation of the Generator measurements.
Results after the analytical comparison and the re-evaluation of the Generator measurements.