Skip to content

Commit

Permalink
Add support for user-defined scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mole99 committed Sep 24, 2024
1 parent 6987df2 commit 0222a2b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cace/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ def get_layout_path(projname, paths, check_magic=False):

dbg('No compressed GDS layout found.')

err('Neither magic nor (compressed) GDS layout found.')
if check_magic:
err('Neither magic nor (compressed) GDS layout found.')
else:
err('No (compressed) GDS layout found.')

return (None, None)

Expand Down
43 changes: 41 additions & 2 deletions cace/parameter/parameter_ngspice.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import threading
import subprocess
from multiprocessing.pool import ThreadPool
from importlib.machinery import SourceFileLoader

from ..common.misc import mkdirp
from ..common.spiceunits import spice_unit_convert
Expand Down Expand Up @@ -66,6 +67,8 @@ def __init__(
self.add_argument(Argument('format', None, False))
self.add_argument(Argument('suffix', None, False))
self.add_argument(Argument('variables', [], False))
self.add_argument(Argument('script', None, False))
self.add_argument(Argument('script_variables', [], False))

# Total number of simulations
# used for the progress bar
Expand Down Expand Up @@ -159,6 +162,13 @@ def implementation(self):
if variable != None:
self.add_result(Result(variable))

script_variables = self.get_argument('script_variables')

# Add all named results from the user-defined script
for variable in script_variables:
if variable != None:
self.add_result(Result(variable))

template = self.get_argument('template')
template_path = os.path.join(self.paths['templates'], template)
run_template_path = os.path.join(self.param_dir, template)
Expand Down Expand Up @@ -637,14 +647,43 @@ def implementation(self):
collated_values[variable]
)

# Postprocess using user-defined script
script = self.get_argument('script')
if script:
script_path = os.path.join(
self.datasheet['paths']['scripts'], script
)

if not os.path.isfile(script_path):
err(f'No such user script {script_path}.')
self.result_type = ResultType.ERROR
return

try:
user_script = SourceFileLoader(
'user_script', script_path
).load_module()
collated_values = user_script.postprocess(
collated_values, condition_set
)
except Exception as e:
err(f'Error in user script: {e}')
self.result_type = ResultType.ERROR
return

for variable in script_variables:
if variable != None:
# Extend the final result
self.get_result(variable).values.extend(
collated_values[variable]
)

simulation_values.append(collated_values)
self.result_type = ResultType.SUCCESS

dbg(f'simulation_values: {simulation_values}')
dbg(f'results_dict: {self.results_dict}')

# TODO other tools?

# Create a plot if specified
if 'plot' in self.param:
# Create the plots and save them
Expand Down

0 comments on commit 0222a2b

Please sign in to comment.