Skip to content

Commit

Permalink
Use spiceinit from the pdk
Browse files Browse the repository at this point in the history
  • Loading branch information
mole99 committed Oct 24, 2024
1 parent 8759d49 commit 28c60ff
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cace/cace_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def cli():
'-j',
'--jobs',
type=int,
help="""total number of jobs running in parallel""",
help="""maximum number of jobs running in parallel""",
)
parser.add_argument(
'-s',
Expand Down Expand Up @@ -206,7 +206,7 @@ def cli():

# Create the ParameterManager
parameter_manager = ParameterManager(
max_runs=args.max_runs, run_path=args.run_path, jobs=args.jobs
max_runs=args.max_runs, run_path=args.run_path, max_jobs=args.jobs
)

# Load the datasheet
Expand Down
2 changes: 2 additions & 0 deletions cace/parameter/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def __init__(
paths,
runtime_options,
run_dir,
max_jobs,
jobs_sem,
start_cb=None,
end_cb=None,
Expand All @@ -215,6 +216,7 @@ def __init__(
self.paths = paths
self.runtime_options = runtime_options
self.run_dir = run_dir
self.max_jobs = max_jobs
self.jobs_sem = jobs_sem
self.start_cb = start_cb
self.end_cb = end_cb
Expand Down
23 changes: 12 additions & 11 deletions cace/parameter/parameter_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class ParameterManager:
manipulate it.
"""

def __init__(self, datasheet={}, max_runs=None, run_path=None, jobs=None):
def __init__(
self, datasheet={}, max_runs=None, run_path=None, max_jobs=None
):
"""Initialize the object with a datasheet"""
self.datasheet = datasheet
self.max_runs = max_runs
Expand Down Expand Up @@ -101,16 +103,15 @@ def __init__(self, datasheet={}, max_runs=None, run_path=None, jobs=None):

self.set_default_paths()

# Set the number of jobs to the number of cores
# if jobs=None
if not jobs:
jobs = os.cpu_count()
# If not specified, set the number
# of jobs to the number of cpu threads
self.max_jobs = max_jobs
if not self.max_jobs:
self.max_jobs = os.cpu_count()

self.jobs_sem = CustomSemaphore(
value=jobs
) # threading.Semaphore(value=jobs)
self.jobs_sem = CustomSemaphore(value=self.max_jobs)

dbg(f'Parameter manager: total number of jobs is {jobs}')
info(f'Maximum number of jobs is {self.max_jobs}.')

### datasheet functions ###

Expand Down Expand Up @@ -512,8 +513,8 @@ def queue_parameter(
paths,
self.runtime_options,
self.run_dir,
# Semaphore for starting
# new jobs
self.max_jobs,
# Semaphore for starting new jobs
self.jobs_sem,
# Callbacks
start_cb,
Expand Down
43 changes: 34 additions & 9 deletions cace/parameter/parameter_ngspice.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def __init__(
self.add_argument(Argument('variables', [], False))
self.add_argument(Argument('script', None, False))
self.add_argument(Argument('script_variables', [], False))
self.add_argument(
Argument('spiceinit_path', None, False)
) # Specify spiceinit other than PDK spiceinit

# Total number of simulations
# used for the progress bar
Expand Down Expand Up @@ -179,13 +182,9 @@ def implementation(self):
if jobs == 'max':
# Set the number of jobs to the number of cores
jobs = os.cpu_count()

# Fallback jobs
if not jobs:
jobs = 4
else:
# Make sure that jobs don't exceed max jobs
jobs = min(jobs, os.cpu_count())
# Make sure that jobs doesn't exceed max jobs
jobs = min(jobs, self.max_jobs)

template = self.get_argument('template')
template_path = os.path.join(self.paths['templates'], template)
Expand Down Expand Up @@ -341,10 +340,11 @@ def implementation(self):
reserved = {
'filename': os.path.splitext(template)[0],
'templates': os.path.abspath(self.paths['templates']),
'root': os.path.abspath(self.paths['root']),
'simpath': os.path.abspath(outpath),
'DUT_name': self.datasheet['name'],
'netlist_source': source,
'jobs': jobs, # TODO self.param['jobs'],
'jobs': jobs,
'N': index,
'DUT_path': os.path.abspath(dutpath),
'PDK_ROOT': get_pdk_root(),
Expand All @@ -353,9 +353,17 @@ def implementation(self):
'random': str(int(time.time() * 1000) & 0x7FFFFFFF),
}

# Set the reserved conditions
# Set the reserved variables
for cond in condition_set:
if cond in reserved:
# Hack until reserved variables and conditions are properly separated
if (
collate_index == 0
and condition_set[cond] != None
):
warn(
f'Condition uses name of reserved variable: {cond}'
)
condition_set[cond] = reserved[cond]

# Add the collate condition
Expand Down Expand Up @@ -481,6 +489,23 @@ def implementation(self):
self.result_type = ResultType.ERROR
return"""

# Copy the .spiceinit file to the simulation directory
spiceinit_path = self.get_argument('spiceinit_path')

# Get the spiceinit file from the PDK
if spiceinit_path == None:
spiceinit_path = os.path.join(
pdk_root, pdk, 'libs.tech', 'ngspice', 'spiceinit'
)

if os.path.isfile(spiceinit_path):
# Copy spiceinit file to run dir
shutil.copyfile(
spiceinit_path, os.path.join(outpath, '.spiceinit')
)
else:
err(f'No "spiceinit" file found in the {pdk} PDK.')

# We directly got a spice netlist,
# perform the substitutions on it
elif template_ext == '.spice':
Expand Down Expand Up @@ -1158,7 +1183,7 @@ def run(self):
# Run ngspice
returncode = self.run_subprocess(
'ngspice',
['--batch', '--no-spiceinit', self.simfile],
['--batch', self.simfile],
cwd=self.outpath,
)

Expand Down

0 comments on commit 28c60ff

Please sign in to comment.