Thursday, July 26, 2018

Importing and exporting parameters in the Django web app

The main reason for creating the Django based web app was to have a single interface for most tasks related to simulating circuits. For example, in the command line interface, you would need to do the following:

1. Create circuit schematics in a spreadsheet.
2. Launch the circuit simulator in command line with "python"
3. Enter the simulation parameters in circuit_inputs.csv.
4. Enter the component parameters in the parameter spreadsheets.
5. Enter the control variables in the control descriptors.
6. When the simulation is running, run separate plot commands in either matplotlib or gnuplot to view results.

There are a few steps that are fundamental and unlikely to change. Those are circuits will be designed in circuit schematics with a spreadsheet software and saved as .csv files and control functions will have to be written in text files as .py files. But the command line needs a lot of back and forth between spreadsheets and also plotting the output needs a whole new set of commands and the need to learn gnuplot or matplotlib.

The Django web app simplified that. Only circuit schematics and control functions are still independent. All other parameters and commands can be given in the web interface by clicking on buttons and filling forms. Much more convenient without needing to go back and forth. However, the problem came while transferring simulations. Because now the simulation is stored in a SQLITE database and copy pasting the database will transfer the entire simulation collection rather than just what you want. What is needed is a way to extract the simulation as a set of simple files that can be zipped and copied or emailed.

What I have now added to the Django app has been an export button and an import button. After creating your simulation and checking that it runs the way you expect it to, you can click on export buttons on every circuit component parameters edit page and export all the parameters of that circuit schematic as a .csv file. Additionally, when you want to recreate a simulation in another computer or transfer it to someone else, you need to send the .csv files and use the import button to upload the parameter spreadsheet and copy the parameters to the database. The same process can be performed for control functions as well.

These features are available in version 2.0.7 for Python 2 and in version 4.0.3 for Python 3.

I am already finding this tool useful in maintaining simulations in all my computers and creating and arranging libraries of simulations. Try it out and let me know if you have any questions or comments. To know more about installing the software, check out my You Tube video:

Monday, July 2, 2018

Transformer circuits, Python 3/Django 2

I have been traveling since June 1 and have not been able to make any YouTube videos. I will get back to Canada on July 9 which is next week. The past month I have been trying out different circuits and also testing the migration to Python 3. The plan is to completely migrate both the command line and web app to Python 3 within six months as Python 2 is already legacy software.

While simulating a flyback converter, I found a bug in how I calculate the number of independent loops in a circuit. From fundamental network analysis, the number of loops is equal to B-N+1 where B is the number of branches, N the number of nodes. I never bothered to question where the "1" came from. The "1" stands for the number if connected sub-circuits. So, in a normal circuit without any transformer or any other machine that has electrically isolated parts, there is only one connected circuit. In such a case, the number of loops will be B-N+1.

But if the circuit has a transformer or a machine like an induction motor, there will be parts of the circuit that are electrically isolated from each other. So for a transformer with two windings, there will be two sub-circuits. In such as case, the number of independent loops will be B-N+2. In general, if there are M isolated sub-circuits, the number of loops will be B-N+M.

I was already calculating the number of connected sub-circuits by an iterative algorithm. Start with one branch and look for branches that are incident at either of it's nodes and keep growing the connected circuit. Count the number of connected circuits. This count is used to determine the number of independent loops that are expected so that additional loops will be considered linear combinations of the previous loops and can be deleted.

The next bug I found was with using the Django based web app with Python 3. Previously I was using Python 2.7 and Django 1.8. Both of these are grossly outdated. Latest version of Python is 3.6 and Django is 2.0.5. Turns out in versions of Django after 1.9, apps are not loaded when the server is started. An app is a component of the project which contains the view functions that define behaviour when a URL is accessed and also defines the database structure. In the circuit simulator, there is one app called simulations. This is listed in INSTALLED_APPS list in the file. Usually, Django will load all apps that are listed once the runserver command is executed. Turns out in Django 1.9 and later, this doesn't happen automatically. I guess this is to allow lazy loading. Which means, if an app is not used, no need to load it and burden the server.

So, if I run the server, everything works fine until I reach the stage of the running the simulation. At this point, it throws an error that apps are not loaded yet. To solve this, at the top of the file I need to add "import django" and "django.setup()". This causes the app to be loaded and now the simulator works as before.

It will be another week before I get back to Canada. Quite a few updates to the website are pending. Will be happy to get back with my Linux machine soon. Developing on Windows sucks.

Saturday, May 26, 2018

YouTube playlists and lecture series on using the simulator

I reorganized my YouTube channel into playlists:

So now there is a playlist for every topic rather than just a collection of videos. I am trying to break the videos up into pieces as it is easier to record them and also upload them on YouTube. A playlist ensures everything is in order inside a topic.

Recording videos has been a learning experience. I am gradually getting the hang of using recording and editing software. I use Kazam in Linux to record the screen while programming or going through slides. I use Kdenlive to edit the videos. Initially the videos needed only a clipping of the last extra seconds. Now I need to boost up the volume as I find the volume is quite low. Also as simulations will get longer, it will be needed to pause the video often and that means cut out parts that are just pauses.

The first major lecture series is one on how to use the circuit simulator web app version. How to install the circuit simulator is a separate playlist:

This playlist contains videos on how to install Python Power Electronics in Windows and Linux.

The lecture series on how to use the simulator should be watched after you have installed a version of the circuit simulator on your system.

The circuit chosen is a single-phase diode bridge rectifier with a dc capacitor at the output. The load consists of a constant resistor load and a switched resistor load. The first part of the lecture series describes the simulator without using any control functions. The latter part of the simulator describes how to write control functions. The main emphasis here is on the special variables that can be defined with control functions and how they are to be used.

As time goes on more detailed simulation results will be described in the videos. For now the above tutorial is to get you started with Python Power Electronics so that you can use it for your own projects. The video lecture references two short papers that are available on my website:

And of course for details on the simulator and how control functions are processed or the user interface is handled, check out my book:

The book contains entire chapters on user interface, control functions and an entire example on how to simulate a reactive power compensator for a three-phase distribution system.

Making videos is fun and I will continue making them. I feel that videos engage people much more than documents or even slide shows. Stay tuned for more videos on the YouTube channel:

For continuous news and updates, follow my Facebook page:

Wednesday, May 2, 2018

Releasing the command line version compatible with Python 3

So finally I started with migration to Python 3. Find the download link:

It wasn't too tough a migration. Mainly the print statement have become functions. So a lot of editing of these statements. Another change which I can't quite understand the necessity of was that raw_input function to get inputs from the user has been removed and an input function is available instead. A more subtle change and this is something which can cause errors to crop up much later is the nature of division.

In Python 2, dividing an integer by an integer yields an integer. So 5/2 will produce 2. In most languages it is the same. To produce exact division, you would have to write 5/2.0 or 5/(2*1.0) etc. Basically one of the operands must be a float. But in Python 3, 5/2 will produce 2.5. To produce an integer result, this would have to be an integer division 5//2.

I many of my loops I use integer division to iterate up to the mid-point of an array. I changed in a couple of places the regular division to integer division or else the for-loop throws an error because the index cannot be a float. But errors are expected later as there a number of such for loops which act on special conditions and it would take a vast number of different circuits before all these loops are discovered and changed.

The next step is to migrate the Django based web app to Python 3. Until then feel free to download and check out the CLI above with Python 3 with your circuits. And please do report errors so that I can fix bugs.

Friday, April 20, 2018

Virtual environments and HOW-TO videos

The first major issue that most people have with a new software is being able to install and execute it. To make this process easier, I make two video lectures on how to install Python Power Electronics in Windows and Linux. I am a Linux user but a vast majority of engineers will be Windows users.

In Windows, I used Anaconda Python which is an entire Python ecosystem. You can download and install it for free on your computer. After which you can create an environment. The advantage of creating an environment is to be able to create a separate isolated container for a particular application. This is particularly when you use your computer for work or study with a different version of Python and do not want an experimental software from messing up your work system. Inside this environment install Django and MatPlotLib which are dependencies for Python Power Electronics besides  Python. The entire video is here:

In Linux, I use virtualenv to create a similar Python virtual environment. Inside this environment, I use pip to install Django and MatPlotLib. The entire video can be found here:

Now that these lectures describe how to install Python Power Electronics in Windows and Linux, the next part will be on how to simulate a circuit with it. There are three aspects to this. First is the basic circuit simulation. How would you simulate a circuit without any control. Just the circuit, the parameters of the components and how to run it and check the results. This video describes that:

The next video will describe how to detect and fix bugs in a simulation. There are a few common mistakes that are made quite often and can be fixed fairly easily. The more complex errors are those that occur due to control problems and these are a bit tough to decode. Control problems will be deferred to a later video lecture along with describing how control can be included in a simulation.

Friday, April 13, 2018

The road ahead in 2018

There has been a lot of changes this year and also the past year. Moved to Germany last year in May 2017 and came back in March 2018. Now that I have published a book with Springer, I would like to keep publishing and would not like my first book to be my last. And with this, I need to set some goals particularly for this year.

To begin with, I plan to create video lectures on my YouTube channel fairly regularly. The link to the channel is:

Feel free to subscribe and check out what will be uploaded there. I find that creating a video lecture helps to put together my thoughts for more elaborate reports and tutorials.

My plan is to create mini books in different topics in power electronics, bringing together similar topics or breaking a large topic into smaller sub-topics. Each book will be introduced with a series of video lectures and accompanied by a simulation package. I am planning the first mini-book on simulating many of the known topologies of dc-dc converters.

The theme of these books will be description from fundamental concepts with the minimal amount of mathematical analysis. The reason for doing so is to make power electronics learning accessible to working people who have limited time and energy after their day jobs.

And of course, if you would like to read all about the circuit simulator, feel free to check out my book on circuit simulation:

Most of the updates to the project will be on my Facebook page:

So feel free to like and follow the page for regular updates.

Sunday, January 28, 2018

Book published with Springer International

I am happy to make a couple of announcements. The first is that my book on the circuit simulator has been published with Springer International and can be found on their website:

The second is that I have launched a video lecture series on power electronics with my circuit simulator. For this I have started a You Tube channel: