diff --git a/cace/parameter/parameter.py b/cace/parameter/parameter.py index d767d68..07cbc8e 100755 --- a/cace/parameter/parameter.py +++ b/cace/parameter/parameter.py @@ -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 @@ -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 = '' @@ -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} @@ -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) @@ -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) @@ -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, @@ -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, diff --git a/cace/parameter/parameter_ngspice.py b/cace/parameter/parameter_ngspice.py index 953a176..54d98a7 100755 --- a/cace/parameter/parameter_ngspice.py +++ b/cace/parameter/parameter_ngspice.py @@ -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: @@ -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…') @@ -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() @@ -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) @@ -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