-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_simulation
executable file
·55 lines (44 loc) · 1.57 KB
/
run_simulation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
##import re
from numpy import sqrt
from docopt import docopt
from inform import Error, Inform, comment, display, done, fatal, os_error
from psf_utils import PSF
from quantiphy import Quantity
from shlib import Run, render_command, set_prefs as shlib_set_prefs, to_path
#####################
# Change a parameter in an existing netlist
#####################
# open seed file and chage parameter
fin = open("source_models/cs_amplifier.scs", "rt")
data = fin.read()
param_change = "1.2"
# Replace a string by another
data = data.replace("[PARAMETER]", param_change)
fin.close()
# Generate input.scs with new param
out_file = "input" + ".scs"
fout = open(out_file, "wt")
fout.write(data)
fout.close()
#####################
# Simulte netlist
#####################
spectre_exe = "spectre" # Spectre executable
netlist_file = to_path(out_file) # Spectre netlist file
log_file = netlist_file.with_suffix(".log") # Spectre logfile
results_dir = netlist_file.with_suffix(".raw") # simulation results directory
## Analysis type
psf_file_dc = results_dir / "dc1.dc" # Input PSF file for dc simulation
psf_file_ac = results_dir / "ac1.dc" # Input PSF file for ac simulation
## Simulation Command
sim_cmd = (spectre_exe, "=log", log_file, "-format", "psfascii", netlist_file, "-64")
## simulate
try:
comment("\nRunning:")
comment(" ", render_command(sim_cmd, {"=log": 1, "-format": 1}))
spectre = Run(sim_cmd, "soEW0")
except Error as e:
if e.stdout:
comment(e.stdout)
e.terminate(culprit=spectre_exe, codicil=f"See {log_file} for more information.")