catch uninitialized interventions
@@ -483,13 +483,16 @@ class Sim(cvb.BaseSim):
people.infect(inds=importation_inds, hosp_max=hosp_max, icu_max=icu_max, layer='importation')
# Apply interventions
- for intervention in self['interventions']:
+ for i,intervention in enumerate(self['interventions']):
if isinstance(intervention, cvi.Intervention):
+ if not intervention.initialized: # pragma: no cover
+ errormsg = f'Intervention {i} (label={intervention.label}, {type(intervention)}) has not been initialized'
+ raise RuntimeError(errormsg)
intervention.apply(self) # If it's an intervention, call the apply() method
elif callable(intervention):
intervention(self) # If it's a function, call it directly
else:
- errormsg = f'Intervention {intervention} is neither callable nor an Intervention object'
+ errormsg = f'Intervention {i} ({intervention}) is neither callable nor an Intervention object'
raise ValueError(errormsg)
people.update_states_post() # Check for state changes after interventions
@@ -537,13 +540,16 @@ class Sim(cvb.BaseSim):
self.results[key][t] += count
# Apply analyzers -- same syntax as interventions
- for analyzer in self['analyzers']:
+ for i,analyzer in enumerate(self['analyzers']):
if isinstance(analyzer, cva.Analyzer):
+ if not analyzer.initialized: # pragma: no cover
+ errormsg = f'Analyzer {i} (label={analyzer.label}, {type(analyzer)}) has not been initialized'
+ raise RuntimeError(errormsg)
analyzer.apply(self) # If it's an intervention, call the apply() method
elif callable(analyzer):
analyzer(self) # If it's a function, call it directly
else:
- errormsg = f'Analyzer {analyzer} is neither callable nor an Analyzer object'
+ errormsg = f'Analyzer {i} ({analyzer}) is neither callable nor an Analyzer object'
raise ValueError(errormsg)
# Tidy up
