Do you know from where Python technology gets its name? It is not from the snake, it is named after the Monty Python comedy group. And indeed, one of the main guidelines behind it is to be fun to use (check out the Zen of Python). Therefore, Python is intuitive, readable, and easy to learn - all of these make it not only fun to use but also highly productive. Does this sound familiar? If you are an e user, it should. Apparently, e and Python share many common characteristics.
Why supporting Python?
Specman has already interfaces with C and SystemVerilog DPI. However, if you want to extract data during Specman’s runs, analyze it for either debugging or machine learning modules- Python might be the right language since there are many open source libraries for graphs, mathematical calculations, machine learning, etc.
Can I connect to Python with old Specman?
Yes, you can. Both Specman and Python have interface to C. Therefore, you can write a C glue code to bridge the two. However, this is not trivial, and it means you need to get familiar with Python Interpreter. Since e like Python is mainly about usability and productivity - having an easy way to connect e code to Python code seems almost a MUST.
What are we adding in 19.05?
In 19.05, all C glue code is generated behind the scenes by Specman during the run. In your e code, you just need to specify that the methods you are calling should be invoked from external Python module (a Python module is a file containing Python definitions and statements).
What is the syntax?
To define a method that is imported from Python, you need do two things:
- Add “is imported” as part of the method signature. This means that the method can be imported from either C (basic or FLI), SystemVerilog DPI or Python. (If you are already familiar with a different syntax to connect to C or DPI, note that we are adding a new syntax for all external languages, but this is a subject for a different blog).
- Annotate this line of code with the predefined annotation: import_python (if you are not familiar with e annotations, you can read about them here).
Let’s look at the following simple example:
‘<
In this example, every call to setVal calls the Python setVal method defined in pyModuleEx.py:
# pyModuleEx.py
Do I need to add any configuration?
- You need to define two environment variables for Specman: SPECMAN_PYTHON_INCLUDE_DIR and SPECMAN_PYTHON_LIB_DIR which point to the location of include and lib directories under your Python installation directory.
- You should ensure that the location of all Python modules you are referring to form your e code are included in Python search path environment variable: PYTHONPATH.
Can I pass a struct from e to Python?
Yes, you can pass a struct from e to Python as shown in the following example:
#exStruct.py
Are there limitations?
In 19.05, only Python 2 is supported and exporting e methods (calling e methods from Python) is not supported yet. These limitations will be removed in future versions.
What’s next?
There are many things you can do now that you have an easy way to export data during the run to improve your verification environment. It might be a call for you to think of using Machine Learning knowledge to make your verification a state of the art. We will publish few examples soon, stay tuned!
We fully recommend to stay up to date for more examples and updates by joining the Specman Users Groups in Linkedin or Team Specman in Facebook.
Orit Kirshenberg
Specman Team