Skip to content

Python for ASIC/SoC Engineers

Python tutorial

Goal of this tutorial

While learning a new programming language, two things happen

  1. Your brain continuously tries to draw parallels with another language you are already familiar with. For us hardware engineers, this is SystemVerilog.
  2. With every new concept you learn, your mind looks for patterns and evaluates how you could apply this in your work.

So, this tutorial is written keeping in mind the typical needs and use cases for RTL design, DV, emulation and validation engineers. For example,

  • In chapter 1 we will study the two workhorse data structures, lists and dictionaries, and compare them to SystemVerilog queues and associative arrays.
  • Chapter 2 is all about numbers and strings. Here we learn to generate random numbers, and examine how wide data types in SV, such as logic [127:0], can be handled in Python.
  • In the chapter on file access, we will learn to work with JSON and CSV files.

This tutorial will help you

  • Formalize your knowledge, become a confident Python programmer, and produce code straight from your finger tips without having to google the little things
  • Build scripts and tools to improve your workflow and productivity
  • Analyze and extract information from logs and reports
  • Handle JSON and CSV files and convert them from one format to another

Practicing examples

Here are two convenient ways to try out the examples included in this tutorial

  • Online web Python interpreter
  • Launch Python by typing python3 on your Linux or MacOS terminal
  • In the chapter examples, you will see code such as the following; >>> is the prompt you will see when you run python3 on a Linux terminal
    % python3
    Python 3.9.6 (default, Oct  4 2024, 08:01:31) 
    Type "help", "copyright", "credits" or "license" for more information.
    >>> hex(500)
    '0x1f4'

Table of contents

Chapter 1: Lists and dictionaries
Comparing the two main python data structures with SystemVerilog queues and associative arrays

Chapter 2: Numbers
Converting between int, hex and bin numbers, and generating random numbers

Work-In-Progress

Chapter 3: Control flow - if and for loops

Chapter 4: Working with files, paths and directories

Chapter 5: The right way to create a Python script

Chapter 6: Reading and Writing files

Chapter 7: Functions

Chapter 8: Regular Expressions

Chapter 9: Subprocess.run

Chapter 10: Passing command line arguments with argparse

Chapter 11: Bonus: Cool things you should be doing in your Python code

Appendix A: Code editors - VSCode, VIM

Appendix B: Installing packages with pip and venv