Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ema_workbench/analysis/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def boxes(self):
# based on
# http://stackoverflow.com/questions/20224526/how-to-extract-the-
# decision-rules-from-scikit-learn-decision-tree
assert self.clf
if not self.clf:
raise AssertionError

left = self.clf.tree_.children_left
right = self.clf.tree_.children_right
Expand Down
6 changes: 4 additions & 2 deletions ema_workbench/analysis/plotting_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,10 @@ def make_continuous_grouping_specifiers(array, nr_of_groups=5):
maximum = np.max(array)
step = (maximum - minimum) / nr_of_groups
a = [(minimum + step * x, minimum + step * (x + 1)) for x in range(nr_of_groups)]
assert a[0][0] == minimum
assert a[-1][1] == maximum
if a[0][0] != minimum:
raise AssertionError
if a[-1][1] != maximum:
raise AssertionError
return a


Expand Down
6 changes: 4 additions & 2 deletions ema_workbench/analysis/prim_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def get_quantile(data, quantile):
the desired quantile

"""
assert quantile > 0
assert quantile < 1
if quantile <= 0:
raise AssertionError
if quantile >= 1:
raise AssertionError

data = np.sort(data)

Expand Down
3 changes: 2 additions & 1 deletion ema_workbench/analysis/scenario_discovery_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ def _setup(results, classify, incl_unc=[]):
else:
raise TypeError("unknown type for classify")

assert y.ndim == 1
if y.ndim != 1:
raise AssertionError

return x, y, mode

Expand Down
3 changes: 2 additions & 1 deletion ema_workbench/connectors/simio_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def __init__(

"""
super().__init__(name, wd=wd, model_file=model_file)
assert main_model != None
if main_model == None:
raise AssertionError
self.main_model_name = main_model
self.output = {}
self.n_replications = n_replications
Expand Down
9 changes: 6 additions & 3 deletions ema_workbench/em_framework/evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,12 @@ def robust_optimize(

"""
for rf in robustness_functions:
assert isinstance(rf, ScalarOutcome)
assert rf.kind != AbstractOutcome.INFO
assert rf.function is not None
if not isinstance(rf, ScalarOutcome):
raise AssertionError
if rf.kind == AbstractOutcome.INFO:
raise AssertionError
if rf.function is None:
raise AssertionError

problem = to_robust_problem(
model,
Expand Down
18 changes: 12 additions & 6 deletions ema_workbench/em_framework/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,18 @@ def __init__(

super().__init__(len(parameters), len(outcome_names), nconstrs=len(constraints))
# assert len(parameters) == len(parameter_names)
assert searchover in ("levers", "uncertainties", "robust")
if searchover not in ("levers", "uncertainties", "robust"):
raise AssertionError

if searchover == "levers":
assert not reference or isinstance(reference, Scenario)
if not (not reference or isinstance(reference, Scenario)):
raise AssertionError
elif searchover == "uncertainties":
assert not reference or isinstance(reference, Policy)
if not (not reference or isinstance(reference, Policy)):
raise AssertionError
else:
assert not reference
if reference:
raise AssertionError

self.searchover = searchover
self.parameters = parameters
Expand All @@ -140,7 +144,8 @@ def __init__(
self, parameters, outcome_names, scenarios, robustness_functions, constraints
):
super().__init__("robust", parameters, outcome_names, constraints)
assert len(robustness_functions) == len(outcome_names)
if len(robustness_functions) != len(outcome_names):
raise AssertionError
self.scenarios = scenarios
self.robustness_functions = robustness_functions

Expand Down Expand Up @@ -604,7 +609,8 @@ def __init__(
self.logging_freq = logging_freq

for metric in metrics:
assert isinstance(metric, AbstractConvergenceMetric)
if not isinstance(metric, AbstractConvergenceMetric):
raise AssertionError
metric.reset()

def __call__(
Expand Down
6 changes: 4 additions & 2 deletions ema_workbench/em_framework/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ class Constraint(ScalarOutcome):
"""

def __init__(self, name, parameter_names=None, outcome_names=None, function=None):
assert callable(function)
if not callable(function):
raise AssertionError
if not parameter_names:
parameter_names = []
elif isinstance(parameter_names, str):
Expand All @@ -574,7 +575,8 @@ def __init__(self, name, parameter_names=None, outcome_names=None, function=None

def process(self, values):
value = super().process(values)
assert value >= 0
if value < 0:
raise AssertionError
return value


Expand Down
5 changes: 3 additions & 2 deletions ema_workbench/em_framework/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ def from_dist(cls, name, dist, **kwargs):
**kwargs : valid keyword arguments for Parameter instance

"""
assert isinstance(
if not isinstance(
dist, sp.stats._distn_infrastructure.rv_frozen
) # @UndefinedVariable
):
raise AssertionError
self = cls.__new__(cls)
self.dist = dist
self.name = name
Expand Down