DSIM API for Use with Python
DSIM provides API functions that can be called by Python code, covering all aspects such as circuit diagram modification, simulation control, and data post-processing. It supports direct modification of circuit parameters, batch parallel simulation, and data acquisition within the Python environment, and integrates with many mainstream AI frameworks, truly becoming an ideal simulation tool for reinforcement learning and other artificial intelligence algorithms.
DSIM API (Python) Supports the Following Interfaces:
The following demonstrates how to use the DSIM API (Python) to scan the LCL filter parameters of a three-phase PWM rectifier circuit. This example presents a parameter sweep of the LCL filter under a specific operating condition, where six values are scanned for the inverter-side inductance, filter capacitor, and grid-side inductance, respectively, resulting in a total of 216 simulations (the parameter settings are shown in the figure below).
How to Perform LCL Parameter Sweep Using DSIM API (Python)
The circuit topology used in this case is shown in the figure below. The performance of the LCL filter parameters is evaluated by analyzing the total harmonic distortion (THD) of the phase-A grid-connected current. Specifically, the average THD value over the last 1000 sampling points of the phase-A current waveform is used as the performance metric. The parameter set that yields the minimum average THD is identified as the optimal LCL parameter combination.
The Python script is executed on a personal computer. The optimal LCL filter parameters corresponding to the minimum THD are obtained, and the resulting grid-connected current waveform is presented in the figure below.
Results Analysis of LCL Parameter Scanning Using the DSIM API (Python)
|
Creation and release of handle
|
Create handle from schematic; Set simulation schematic; Release handle
|
|
Schematic operations
|
Get element parameter value; Set element parameter value; Get parameter file content; Set parameter file content; Get subcircuit variable value; Set subcircuit variable value; Get simulation control parameter; Modify simulation control parameter; Save schematic
|
|
Simulation process
|
Get simulation curve; Initialize simulation; Set output curve; Start simulation; Pause simulation; Continue simulation; Cancel simulation; Get Simulation Status
|
|
Data operation
|
Get curve name; Get specified curve data; Get all curve data; Delete specified curve data; Delete all curve data; Delete curve file
|
|
Callback function
|
Simulation data generation callback; Simulation progress information callback; Simulation process information callback; Simulation completion callback |
| Other |
View schematic; View curve; Get curve file data
|
For more information, please refer to "Tutorial - DSIM API Document (Python)". (The tutorial is attached at the bottom of this page for download.)
The code centrally sets initialization configuration parameters, allowing modification of parameters for each parameter combination, initialization callback functions (acquiring and processing data after simulation), saving the circuit, and starting the simulation. Once the circuit simulation for each set of parameters begins, it immediately processes the next set of parameters without waiting. The simulation of each circuit is performed in parallel within separate threads, making full use of computing resources. After each circuit simulation is complete, a simulation end callback processes the data and closes the handle, ensuring timely release of computer resources.
* Tutorial-DSIM API Document (Python):
-
2025-12-26 Tutorial - DSIM API Document(Python).pdf
끂24 359.95 KB