Using the SIMBA Python Library
This tutorial explores the use of "SIMBA Python Library" feature.
The Python Library named "aesim.simba" contains hundreds of functions providing direct access to SIMBA which can help you to:
- create or modify a circuit
- modify parameters
- run simulation
- retrieve and display results
Moreover, it is worth being noted that "aesim.simba" is independent and does not require to have SIMBA Desktop installed to be used. The simple activation key of SIMBA is enough to use the package.
How to use the "SIMBA Python Library: aesim.simba"
To describe this feature, 2 python scripts named "Run_Simulation.py" and "Pararameter_Sweep.py" are considered. The first script runs a transient analysis for Flyback converter and the second one performs a sweep of the duty cycle for a buckboost converter.
✔ Step 1: First, you'll need to install python (this can be done with the official python website). Note that, to use python, your PATH environment variable must include the python executable location. You can check the option "add path in variable environment" while installing Python.
✔ Step 2: Now, let's install Simba Python Module which is named "aesim.simba": it is available on the pypi website and can be installed via the package manager pip.
Open the "command line" terminal and use this command pip install aesim.simba
in order to install the SIMBA python package.
Important
It is important to say that the deployment key available on your SIMBA account profile page must be used to activate "aesim.simba". The easiest way to activate the simba package is to set the environment variable SIMBA_DEPLOYMENT_KEY value with your deployment key.
✔ Step 3: You may need to download other packages such as matplotlib for mathematical equations and plot curve purposes.
Matplotlib requires numpy package so both will be installed.
Feel free to use such commands in "command line" terminal as well: pip install matplotlib
✔ Step 4: It is not mandatory, but you can download Visual Studio Code for editing python script:
You can also install the python extension to get linting, code formatting features and jupyter notebook. You can also add the Python path in the VS settings:
"File" tab --> Preferences --> Settings --> Extension --> Python --> Default Interpret path
"Set the path of your 'python.exe' installation"
More information can be found at:
✔ Step 5: Secondly, let's consider simple SIMBA examples. The collection of examples is also available in this github repository. Feel free to download and run all of them.
You'll be able to create a circuit from scratch with SIMBA GUI, run any circuits, save results and display them, etc.
The easiest way is to clone the repository or download the zip file of this collection of examples. For example:
- Unzip the zip file in your work folder (if you have chosen to download it),
- Open Visual Studio Code and open your work folder with VS Code.
Let’s consider the first example Run_Simulation.py which aims to run a transient analysis of the Flyback converter from SIMBA design examples.
✔ Step 5.a: Open this first example into VS and click on "Run" tab --> "Run without debugging" or directly go in VS "terminal" window and type:
python Run_Simulation.py
A few seconds later the simulation has succeeded and the script has been well executed.
It is also possible to click on Execute above
in one cell: all the above cells will be executed and the transient analysis plot should appear.
✔ Step 5.b: If you want to get more information about the simulation (in case of simulation failure for example), you can print the "job summary" as following:
print(job.Summary())
✔ Step 5.c: To display the output voltage of the flyback and save the figure you can add those lines at the end of the python script:
plt.show()
fig.savefig('result.png')
You can now re-run the simulation by typing in the terminal window: python Run_Simulation.py
and once it is over, you can directly see the output voltage "Vout" on y axis and "time" on x axis.
If you go through the folder where your simba files are located, you'll find the "result.png" picture saved.
✔ Step 6: You can now re-start the process for the second example "Parameter_Sweep.py". The goal of this example is to sweep several duty cycle values and calculate the average of output voltage for t > 2 ms of the buckboost converter from SIMBA design examples. The figure plots the output voltage depending on the duty cycle.
✔ Step 7: To keep on exploring the "aesim.simba" python module here are some explanation of the few commands which are used above:
-
from aesim.simba import DesignExamples
to import all the SIMBA examples already created from Start Page GUI by using this code: -
job = BuckBoostConverter.TransientAnalysis.NewJob()
to simulate a circuit. -
Vout = np.array(job.GetSignalByName('R1 - Instantaneous Voltage').DataPoints)
to retrieve any results.
✔ Step 8: Several classes of "aesim.simba" module can also be reached in the API section of SIMBA documentation. Below the list of those classes:
- ProjectRepository
- Design
- Circuit
- Device
- DesignExamples
- TransientAnalysisJob
- ThermalData
- ACSweep
✔ Step 9: Last important thing with SIMBA python Library is the capability to build any interactive file such as ".ipynb" extension. The IPython Notebook is now known as the Jupyter Notebook. It is an interactive computational environment, in which you can combine code execution, rich text, mathematics, plots and rich media. For more details on the Jupyter Notebook, please see the Jupyter website.
✔ Step 9.a: Feel free to open in VS the example "direct_current_power_flow_control.ipynb" that you can found on github SIMBA collection examples mentionned above.
✔ Step 9.b: You'll see that this "ipynb" file is really interactive because you can display any pictures, mathematical equations, and portion of python script that you can even run (debug) for updating the results/graphs displayed.
Running a simulation using the Python Library is significantly faster than using the SIMBA User interface because there is no overhead.
This concludes this tutorial about the usage of "SIMBA Python Library" feature.