Skip to content

Commit

Permalink
Improve error messages, ignore bit slices
Browse files Browse the repository at this point in the history
  • Loading branch information
mole99 committed Oct 1, 2024
1 parent e170819 commit 2e85d18
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
37 changes: 36 additions & 1 deletion cace/parameter/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ def run(self):
self.result_type = ResultType.ERROR
self.canceled = True

self.evaluate_result()
if self.result_type != ResultType.SKIPPED:
self.evaluate_result()

# Set done before calling end cb
self.done = True
Expand Down Expand Up @@ -901,11 +902,19 @@ def makeplot(
and not 'xaxis' in self.param['plot'][plot_name]
):
err(f'Neither yaxis nor xaxis specified in plot {plot_name}.')
self.result_type = ResultType.ERROR
return None

xvariable = None
if 'xaxis' in self.param['plot'][plot_name]:

xvariable = self.param['plot'][plot_name]['xaxis']

# Remove any bit slices
pmatch = self.vectrex.match(xvariable)
if pmatch:
xvariable = pmatch.group(1)

xdisplay = xvariable
xunit = ''

Expand All @@ -917,6 +926,12 @@ def makeplot(
if not isinstance(yvariables, list):
yvariables = [yvariables]

for i, yvariable in enumerate(yvariables):
# Remove any bit slices
pmatch = self.vectrex.match(yvariable)
if pmatch:
yvariables[i] = pmatch.group(1)

ydisplays = {key: key for key in yvariables}
yunits = {key: '' for key in yvariables}

Expand Down Expand Up @@ -1189,6 +1204,7 @@ def makeplot(
xvalues = conditions[xvariable].values
else:
err(f'Unknown variable: {xvariable} in plot {plot_name}.')
self.result_type = ResultType.ERROR
return None

xvalues_list.append(xvalues)
Expand All @@ -1206,6 +1222,7 @@ def makeplot(
err(
f'Unknown variable: {yvariable} in plot {plot_name}.'
)
self.result_type = ResultType.ERROR
return None

yvalues_list.append(yvalues)
Expand All @@ -1232,6 +1249,15 @@ def makeplot(
marker = 'o'

for yvalue in yvalues:

# Check length of x and y
if len(xvalues) != len(yvalue):
err(
f'Length of x and y is not the same ({len(xvalues)}, {len(yvalue)}).'
)
self.result_type = ResultType.ERROR
return None

self.plot(
xvalues,
yvalue,
Expand All @@ -1243,6 +1269,15 @@ def makeplot(
)

if not yvalues:

# Check length of x and y
if len(xvalues) != len(yvalues):
err(
f'Length of x and y is not the same ({len(xvalues)}, {len(yvalues)}).'
)
self.result_type = ResultType.ERROR
return None

self.plot(
xvalues,
yvalues,
Expand Down
36 changes: 27 additions & 9 deletions cace/parameter/parameter_ngspice.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ def implementation(self):
# First remove the collate condition from the conditions
if self.get_argument('collate'):
collate_variable = self.get_argument('collate')

# Remove any bit slices
pmatch = self.vectrex.match(collate_variable)
if pmatch:
collate_variable = pmatch.group(1)

info(f'Collating results using condition "{collate_variable}"')

if collate_variable in conditions:
Expand Down Expand Up @@ -637,10 +643,13 @@ def implementation(self):

dbg(f'collated values: {collated_values}')

# Put back the collate condition for script and plotting
if self.get_argument('collate'):
condition_set[collate_variable] = collate_values
condition_sets[index][collate_variable] = collate_values

dbg(f'collated condition: {condition_set[collate_variable]}')
dbg(
f'collated condition: {condition_sets[index][collate_variable]}'
)

dbg(f'Extending final result…')

Expand Down Expand Up @@ -685,7 +694,7 @@ def write(self, text):
text = text.rstrip()
if len(text) == 0:
return
info(f'User script: {text}')
info(text)

def flush(self):
self._stdout.flush()
Expand All @@ -694,26 +703,30 @@ def __getattr__(self, attr):
return getattr(self._stdout, attr)

with CustomPrint() as output:
collated_values = user_script.postprocess(
script_values = user_script.postprocess(
collated_values, condition_set
)

except Exception as e:
err(f'Error in user script: {e}')
# Merge collated and script variables
collated_values.update(script_values)

except Exception:
err(f'Error in user script:')
traceback.print_exc()
self.result_type = ResultType.ERROR
return

for variable in script_variables:
if variable != None:
# Check for variable in results
if variable not in collated_values:
err(f'Variable "{variable}" not in results.')
if variable not in script_values:
err(f'Variable "{variable}" not in script results.')
self.result_type = ResultType.ERROR
return

# Extend the final result
self.get_result(variable).values.extend(
collated_values[variable]
script_values[variable]
)

simulation_values.append(collated_values)
Expand All @@ -722,6 +735,11 @@ def __getattr__(self, attr):
dbg(f'simulation_values: {simulation_values}')
dbg(f'results_dict: {self.results_dict}')

# Put back the collate_condition
# TODO find a better way
if self.get_argument('collate'):
conditions[collate_variable] = collate_condition

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

0 comments on commit 2e85d18

Please sign in to comment.