I always get questions from my coworkers as well as my readers like the ones below.
- Where do I start learning python?
- Why/How should a hardware engineer learn python in 2019?
- How python could be used to eliminate manual tasks?
- Why python is preferred over other scripting languages?
But, what if we use python to design, simulate and implement hardware circuits in silicon? Is it possible to take the amazing advantages that python offer over other hardware related programming languages such as HDL (verilog or vhdl), Tcl, Perl or Shell? Come let’s explore!
Why Python is so popular?
If you are a beginner to the programming world, I would highly suggest you to learn python first. This is because of the following major reasons.
- Simple: Python is simple to learn because its very similar to how we humans think.
- More Productive: Python is highly productive when compared to other languages such as c, c++ or java as it is much more readable, concise, expressive and takes lesser time and effort to write code.
- One-liners: Python has so many one-liners and english-like commands (keywords) that boosts programmers productivity a lot.
- Community: Python has a very big developer friendly community and its very easy to find python developers around the world in platforms such as GitHub or Stack Overflow.
- Libraries: Python has rich set of well documented libraries and frameworks for different tech domains as shown here.
- Open-Source: Python ecosystem is so popular because most of the libraries and frameworks available online are open-source (meaning anyone can use it for their development purposes adhering to the licenses provided).
Despite its advantages, python is much slower compared to languages such as c++. But wait! It’s not a big disadvantage. You can still use python for most of the tasks that require minimal execution time (not speed-intensive applications such as games). That’s why data-intensive domains such as deep learning libraries use python as a high-level wrapper for a human to code and beneath that wrapper, they use C++ for faster execution.
How to learn python for free?
When I started learning python three years back, I used the following resources. I guess, these resources are more than enough to get you comfortable with python.
- HackerRank is the best learning platform for python. You have to learn and solve programs based on levels of difficulty. Once you solve programs here, you will get that confidence in using the language for your own purposes.
- Learn Python - Socratica has an excellent playlist full of neatly made python tutorials in YouTube for free. If you love learning by videos, this is the best ever python tutorial playlist out there.
- Corey Schafer is another awesome YouTube channel that delivers no-bullshit python tutorials.
Other than these, you can check out some extensive list of learning resources that I collected for you here.
Python for Automation
The main use of python lies in automating repeated manual tasks that we perform daily. These manual tasks might include opening a terminal, going to a path, finding some file, parsing some values in that file, putting that parsed value in a csv file and sending a mail with that csv file attached. This is one of the classic examples where you can write a single python script to do all the steps that are mentioned.
Other examples where python scripts can be used are organizing files in a particular path, manipulating strings, csv files, excel spreadsheets etc., sending email and text messages and much more. Automate the boring stuff with python is a great learning resource that you can read on how to do these.
Python for Text Processing
Manipulating text files is a common task in any domain whether you are in VLSI, computer networking, image processing, signal processing etc., Python offers rich set of libraries and modules to do this.
Some of the most commonly used text processing modules in python using which you can manipulate text files (such as CSV files, JSON files, YAML file, HTML files etc.,), perform shell operations, parse large text files, load/store very large text files and manipulate file formats are
- string module
- os module
- sys module
- re module
- csv module
- json module
- yaml module
- h5py module
- bs4 module
Python for Logic Design
Ok cool! Now you understood, python could be used to create automation utilities that involve text processing which reduces time involved in solving repeated manual tasks in your day-to-day work life.
Can python be used in designing hardware circuits which typically need a HDL for writing code? Of course, there is a great open-source python project called MyHDL that turns python into a hardware description and verification language, providing hardware engineers with the power of the python ecosystem.
Moreover, MyHDL designs can be converted to verilog or VHDL automatically and implemented using a standard tool flow. Before getting too much excited about this library, please read What MyHDL is not?
Another python based hardware modeling framework is PyMTL. Following links provide training resources on using this library.
- Verilog Hardware Description Language
- PyMTL Hardware Modeling Framework Tutorial
- PyMTL CL Modeling Tutorial
- PyMTL/HLS Tutorial
- PyMTL-Based ASIC Toolflow Tutorial
Python for ML/DL in Hardware
Apart from the hypes that machine learning (ML) and deep learning (DL) have created in the recent years, still VLSI domain isn’t deeply affected by ML or DL. This is because, VLSI industry is so complex because of conflicting goals to optimize hardware designs for timing, power and area with lesser time to market.
This is definitely the time to use ML or DL in hardware design, particularly creating ML models for smaller tasks in a bigger design flow. I have documented some of the current research papers and articles related to using ML or DL in VLSI chip design here.
But, for a beginner who is interested to use ML or DL in hardware design, below are the python libraries needed to get started.
Scientific Computing Stack
Python for EDA
As far as technology node reduces, the need for electronic design automation tools increases. You can’t design a multi-million instances based design manually. You need EDA tools that helps in implementation.
Python for Web Dashboards
To analyze your design data which has lots of files with millions of lines, you need a simpler way to look at important metrics, reports and status of your design in a nice looking web interface. Python provides cool libraries to create web dashboards that speeds up your productivity as well as reducing your analysis time.
As you can see, python can be used in multiple areas in hardware design. According to me, python has just started to find its place in hardware design. Also, I feel that it will be used by engineers around the world very soon due to its simpler nature. If you have found anything related to python that could be used for hardware design, please leave that in the comments below. Peace!
In case if you found something useful to add to this article or you found a bug in the code or would like to improve some points mentioned, feel free to write it down in the comments. Hope you found something useful here.