Hi community, I have an interesting question for y...
# xschem
r
Hi community, I have an interesting question for you. I have a schematic in xschem and the xschemrc file and I am able to simulate the schematic, now the question is, how can I run the simulation from a script in python? Theoretically what I done with the GUI, push "netlist" button and than "simulate", but how can I do this command? any example?
s
to generate a netlist use this command:
xschem -x -r -n -s -q /path/to/schematic.sch
the -x and -r are optional (do not open X windows and do not use tclreadline shell) -n: generate a netlist -s: spice netlist -q: quit when done. To run a simulation call ngspice directly on the netlist:
ngspice -i schematic.spice
r
but, how can I manager xschemrc file?
t
@Roberto Di Lorenzo: I think what you need is to use the
subprocess
package for python, not
os.system()
. The
subprocess.run()
subroutine has options for setting the environment and setting the directory from where the application is launched. So you can run the
xschem
application from a directory containing the
xschemrc
file that you want to apply.
r
I am close to the solution, but still something is wrong. I looked in the directory and the netlist is not generated.
c
Xschem is just a schematic editing tool. If you want to use Python to run the simulation, all you need is to just interface with
ngspice
:
Copy code
import os
os.system('ngspice -b -o <some_name>.log <some_name>.spice')
r
I agree with you. How can I generate a netlist ? I would like to run a simulation with python because I can write a script to change the corner (SS, FF, SF...) in the schematic, and than, run all the simulation one by one. Any example of working code?
c
There is no such a very automated way to generate a netlist, to what I know. What I would do is create the schematic in xschem, export the netlist, and use Python to update the netlist.
s
You can generate the netlist by launching an xschem subprocess, it is very fast. The following example launches xschem with a specific xschemrc file and specifies a directory and a file name for the netlist.
xschem --rcfile /path/to/xschemrc -n -s -x -r -q -o /path/for/netlist -N netlist_filename /path/to/circuit.sch
example i just ran on my system:
xschem --rcfile /home/schippes/share/pdk/sky130A/libs.tech/xschem/xschemrc -n -s -x -r -q -o /tmp -N netlist.spice /home/schippes/share/pdk/sky130A/libs.tech/xschem/sky130_tests/test_ac.sch
it produces the file
netlist.spice
in
/tmp
of the schematic
test_ac.sch
For the meaning of the various options do a
xschem -h
. It is important to give the
-q
option so xschem quits after creating the netlist.
r
If I use this command i am able to generate the netlist.
Copy code
os.system("xschem --rcfile /home/roberto/Documents/circuits/ids_vds_test/xschemrc -n -s -x -r -q -o /home/roberto/Documents/circuits/ids_vds_test/ -N netlist.spice /home/roberto/Documents/circuits/ids_vds_test/ids_vds_2.sch")
But with subprocess i am not able to run netlist
Copy code
subprocess.run(["/usr/local/bin/xschem", "-c","xschem --rcfile /home/roberto/Documents/circuits/ids_vds_test/xschemrc -n -s -x -r -q -o /home/roberto/Documents/circuits/ids_vds_test/ -N netlist.spice /home/roberto/Documents/circuits/ids_vds_test/ids_vds_2.sch"])
I really don't understand this command "subprocess"...
t
@Roberto Di Lorenzo: All arguments to the program to run in "subprocess" go into a list as the first argument; the way you have it written above, you are effectively trying to call xschem twice. It should be something like:
Copy code
subprocess.run(["/usr/local/bin/xschem", "--rcfile /home/roberto/Documents/circuits/ids_vds_test/xschemrc", "-n", "-s", "-x", "-r", "-q", "-o /home/roberto/Documents/circuits/ids_vds_test/", "-N netlist.spice", "/home/roberto/Documents/circuits/ids_vds_test/ids_vds_2.sch"])
Since the point of using "subprocess" was that you could launch xschem in a specific directory, you might want to add at the end a 2nd argument
Copy code
cwd='/home/roberto/Documents/circuits/ids_vds_test'
But I think setting the cwd means that you don't need to specify the startup file which is in the same directory, so that should reduce the call to:
Copy code
subprocess.run(["/usr/local/bin/xschem", "-n", "-s", "-x", "-r", "-q", "-o .", "-N netlist.spice", "ids_vds_2.sch"], cwd='/home/roberto/Documents/circuits/ids_vds_test')
Possibly
-o .
isn't needed, either.
r
Maybe
--xschemrc
is missed? but i don't know where to take into account...
Copy code
subprocess.run(["/usr/local/bin/xschem", "-n", "-s", "-x", "-r", "-q", "-o", "-N netlist.spice", "ids_vds_2.sch"], cwd='/home/roberto/Documents/circuits/ids_vds_test')
Using this command, i get this answer.
Warning: PDK_ROOT env. var. not found or empty, trying to find an open_pdks install
open_pdks installation: using /usr/local/share/pdk
SKYWATER_MODELS: /usr/local/share/pdk/sky130A/libs.tech/ngspice
SKYWATER_STDCELLS: /usr/local/share/pdk/sky130A/libs.ref/sky130_fd_sc_hd/spice
load_schematic(): unable to open file: /home/roberto/ids_vds_2.sch, fname=/home/roberto/ids_vds_2.sch
global_spice_netlist(): problems opening netlist file
seems part of the path is lost. this is wrong path:
fname=/home/roberto/ids_vds_2.sch
@Tim Edwards
t
I'm guessing that it would work either to specify the filename as
./ids_vds_2.sch
or
/home/roberto/Documents/circuits/ids_vds_test/ids_vds_2.sch
. If you have to modify the
xschemrc
file to get it to add the current directory to xschem's search path, then I guess you do need the
--rcfile=
option, maybe
--rcfile=./xschemrc
. If all else fails, ask Stefan Schippers.
r
@Stefan Schippers I am trying to create a netlist with this command.
subprocess.run(["/usr/local/bin/xschem", "--rcfile=xschemrc", "-n", "-s", "-x", "-r", "-q", "-N netlist.spice", "ids_vds_2.sch"], cwd='/home/roberto/Documents/circuits/ids_vds_test/')
in the folder of schematic I have also
xschemrc
file, how can i do a netlist with this specific xschem rc file that is in the same folder of the schematic? I get this when I run this command.
Copy code
runfile('/home/roberto/Documents/circuits/ids_vds_test/netlist_run.py', wdir='/home/roberto/Documents/circuits/ids_vds_test')
Unknown option:  netlist.spice
Unknown option: etlist.spice
Unknown option: .spice
Unknown option: e
xschem: cant do a netlist without a filename
s
`"-N netlist.spice`" is wrong, split into two arguments:
"-N", "netlist.spice"
r
I tried all the options.
Copy code
process_1 =subprocess.run(["/usr/local/bin/xschem", "--rcfile=/home/roberto/Documents/circuits/ids_vds_test/xschemrc", "-n", "-s", "-q", "-N","netlist.spice","ids_vds_2.sch"], 
                          cwd='/home/roberto/Documents/circuits/ids_vds_test/')
Still the path is wrong and i don't know why....
s
I think you need to inspect the
xschemrc
file and see the list of paths assigned to
XSCHEM_LIBRARY_PATH
.If everything fails add
[pwd]
to the list of paths assigned to `XSCHEM_LIBRARY_PATH`:
append XSCHEM_LIBRARY_PATH :[pwd]
r
Now i have this setup:
Copy code
#### xschemrc system configuration file

#### Flush any previous definition
set XSCHEM_LIBRARY_PATH {}
#### include devices/*.sym
append XSCHEM_LIBRARY_PATH ${XSCHEM_SHAREDIR}/xschem_library
#### include skywater libraries. Here i use [pwd]. This works if i start xschem from here.
append XSCHEM_LIBRARY_PATH :$env(PWD)
#### add ~/.xschem/xschem_library (USER_CONF_DIR is normally ~/.xschem)
append XSCHEM_LIBRARY_PATH :$USER_CONF_DIR/xschem_library 
################


append XSCHEM_LIBRARY_PATH :[pwd]


###########################################################################
#### list of tcl files to preload.
# lappend tcl_files ${XSCHEM_SHAREDIR}/change_index.tcl
lappend tcl_files ${XSCHEM_SHAREDIR}/ngspice_backannotate.tcl
Running this command with everything defined, still not produce the spice netlist.
Copy code
subprocess.run(["/usr/local/bin/xschem", "--rcfile=/home/roberto/Documents/circuits/ids_vds_test/xschemrc", "-n", "-s", "-q", "-N", "netlist.spice","ids_vds_2.sch"], 
                          cwd='/home/roberto/Documents/circuits/ids_vds_test/')
s
You need to specify the path where you want the netlist, by default netlist goes to
~/.xschem/simulations
subprocess.run(["/usr/local/bin/xschem", "--rcfile=/home/roberto/Documents/circuits/ids_vds_test/xschemrc", "-n", "-s", "-q", "-N", "netlist.spice", "ids_vds_2.sch", *"-o", "/home/roberto/Documents/circuits/ids_vds_test"*], cwd='/home/roberto/Documents/circuits/ids_vds_test/')
😀 1
r
thanks, it works... the only things that is not clear is, what is the order of the command. everything is clear until
"ids_vds_2.sch"
, but than how the command know that the spice netlist should be put in the next path? why the definition of the
cwd
is not took into account.
s
Arguments that begin with '-' or '--' are xschem command options. They are all read and parsed before doing anything, so the order does not matter. The directory where netlist is generated is by default ~/.xschem/simulations, it can be changed using the '-o' switch and does not depend on CWD.