Commit 96a209e4 authored by Tjerk Vreeken's avatar Tjerk Vreeken

Use Python 3's super() for DRY

parent f0cceab6
...@@ -136,7 +136,7 @@ We turn on ensemble mode by setting ``csv_ensemble_mode = True``: ...@@ -136,7 +136,7 @@ We turn on ensemble mode by setting ``csv_ensemble_mode = True``:
The method ``pre()`` is already defined in RTC-Tools, but we would like to add The method ``pre()`` is already defined in RTC-Tools, but we would like to add
a line to it to create a variable for storing intermediate results. To do a line to it to create a variable for storing intermediate results. To do
this, we declare a new ``pre()`` method, call ``super(Example, self).pre()`` this, we declare a new ``pre()`` method, call ``super().pre()``
to ensure that the original method runs unmodified, and add in a variable to ensure that the original method runs unmodified, and add in a variable
declaration to store our list of intermediate results. This variable is a declaration to store our list of intermediate results. This variable is a
dict, reflecting the need to store results from multiple ensemble. dict, reflecting the need to store results from multiple ensemble.
......
...@@ -188,7 +188,7 @@ methods. ...@@ -188,7 +188,7 @@ methods.
The method ``pre()`` is already defined in RTC-Tools, but we would like to add The method ``pre()`` is already defined in RTC-Tools, but we would like to add
a line to it to create a variable for storing intermediate results. To do this, a line to it to create a variable for storing intermediate results. To do this,
we declare a new ``pre()`` method, call ``super(Example, self).pre()`` to ensure we declare a new ``pre()`` method, call ``super().pre()`` to ensure
that the original method runs unmodified, and add in a variable declaration to that the original method runs unmodified, and add in a variable declaration to
store our list of intermediate results: store our list of intermediate results:
......
...@@ -107,7 +107,7 @@ classes. ...@@ -107,7 +107,7 @@ classes.
The method ``pre()`` is already defined in RTC-Tools, but we would like to add The method ``pre()`` is already defined in RTC-Tools, but we would like to add
a line to it to create a variable for storing intermediate results. To do this, a line to it to create a variable for storing intermediate results. To do this,
we declare a new ``pre()`` method, call ``super(Example, self).pre()`` to ensure we declare a new ``pre()`` method, call ``super().pre()`` to ensure
that the original method runs unmodified, and add in a variable declaration to that the original method runs unmodified, and add in a variable declaration to
store our list of intermediate results. store our list of intermediate results.
......
...@@ -17,7 +17,7 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem): ...@@ -17,7 +17,7 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem):
def path_constraints(self, ensemble_member): def path_constraints(self, ensemble_member):
# Call super() class to not overwrite default behaviour # Call super() class to not overwrite default behaviour
constraints = super(Example, self).path_constraints(ensemble_member) constraints = super().path_constraints(ensemble_member)
# Constrain the volume of storage between 380000 and 420000 m^3 # Constrain the volume of storage between 380000 and 420000 m^3
constraints.append((self.state('storage.V'), 380000, 420000)) constraints.append((self.state('storage.V'), 380000, 420000))
return constraints return constraints
......
...@@ -13,7 +13,7 @@ import numpy as np ...@@ -13,7 +13,7 @@ import numpy as np
class WaterVolumeRangeGoal(StateGoal): class WaterVolumeRangeGoal(StateGoal):
def __init__(self, optimization_problem): def __init__(self, optimization_problem):
# Call super class first, and pass in the optimization problem # Call super class first, and pass in the optimization problem
super(WaterVolumeRangeGoal, self).__init__(optimization_problem) super().__init__(optimization_problem)
# Assign V_min and V_max the the target range # Assign V_min and V_max the the target range
self.target_min = optimization_problem.get_timeseries('V_min') self.target_min = optimization_problem.get_timeseries('V_min')
self.target_max = optimization_problem.get_timeseries('V_max') self.target_max = optimization_problem.get_timeseries('V_max')
...@@ -41,7 +41,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin, ...@@ -41,7 +41,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin,
def pre(self): def pre(self):
# Do the standard preprocessing # Do the standard preprocessing
super(Example, self).pre() super().pre()
# Create a dict of empty lists for storing intermediate results from # Create a dict of empty lists for storing intermediate results from
# each ensemble # each ensemble
...@@ -82,7 +82,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin, ...@@ -82,7 +82,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin,
def control_tree_options(self): def control_tree_options(self):
# We want to modify the control tree options, so we override the default # We want to modify the control tree options, so we override the default
# control_tree_options method. We call super() to get the default options # control_tree_options method. We call super() to get the default options
options = super(Example, self).control_tree_options() options = super().control_tree_options()
# Change the branching_times list to only contain the fifth timestep # Change the branching_times list to only contain the fifth timestep
options['branching_times'] = [self.times()[5]] options['branching_times'] = [self.times()[5]]
return options return options
...@@ -111,7 +111,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin, ...@@ -111,7 +111,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin,
q_release_integral)) q_release_integral))
def post(self): def post(self):
super(Example, self).post() super().post()
for e_m in range(self.ensemble_size): for e_m in range(self.ensemble_size):
print('\n\nResults for Ensemble Member {}:'.format(e_m)) print('\n\nResults for Ensemble Member {}:'.format(e_m))
for priority, n_level_satisfied, q_release_integral in \ for priority, n_level_satisfied, q_release_integral in \
...@@ -123,7 +123,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin, ...@@ -123,7 +123,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin,
# Any solver options can be set here # Any solver options can be set here
def solver_options(self): def solver_options(self):
options = super(Example, self).solver_options() options = super().solver_options()
# When mumps_scaling is not zero, errors occur. RTC-Tools does its own # When mumps_scaling is not zero, errors occur. RTC-Tools does its own
# scaling, so mumps scaling is not critical. Proprietary HSL solvers # scaling, so mumps scaling is not critical. Proprietary HSL solvers
# do not exhibit this error. # do not exhibit this error.
......
...@@ -67,7 +67,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin, ...@@ -67,7 +67,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
# We want to add a few hard constraints to our problem. The goal # We want to add a few hard constraints to our problem. The goal
# programming mixin however also generates constraints (and objectives) # programming mixin however also generates constraints (and objectives)
# from on our goals, so we have to call super() here. # from on our goals, so we have to call super() here.
constraints = super(Example, self).path_constraints(ensemble_member) constraints = super().path_constraints(ensemble_member)
# Release through orifice downhill only. This constraint enforces the # Release through orifice downhill only. This constraint enforces the
# fact that water only flows downhill # fact that water only flows downhill
...@@ -108,7 +108,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin, ...@@ -108,7 +108,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
def pre(self): def pre(self):
# Call super() class to not overwrite default behaviour # Call super() class to not overwrite default behaviour
super(Example, self).pre() super().pre()
# We keep track of our intermediate results, so that we can print some # We keep track of our intermediate results, so that we can print some
# information about the progress of goals at the end of our run. # information about the progress of goals at the end of our run.
self.intermediate_results = [] self.intermediate_results = []
...@@ -134,7 +134,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin, ...@@ -134,7 +134,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
def post(self): def post(self):
# Call super() class to not overwrite default behaviour # Call super() class to not overwrite default behaviour
super(Example, self).post() super().post()
for priority, n_level_satisfied, q_pump_integral, q_pump_sum_changes \ for priority, n_level_satisfied, q_pump_integral, q_pump_sum_changes \
in self.intermediate_results: in self.intermediate_results:
print('\nAfter finishing goals of priority {}:'.format(priority)) print('\nAfter finishing goals of priority {}:'.format(priority))
...@@ -145,7 +145,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin, ...@@ -145,7 +145,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
# Any solver options can be set here # Any solver options can be set here
def solver_options(self): def solver_options(self):
options = super(Example, self).solver_options() options = super().solver_options()
options['print_level'] = 1 options['print_level'] = 1
return options return options
......
...@@ -16,7 +16,7 @@ class WaterVolumeRangeGoal(StateGoal): ...@@ -16,7 +16,7 @@ class WaterVolumeRangeGoal(StateGoal):
# this goal. # this goal.
def __init__(self, optimization_problem): def __init__(self, optimization_problem):
# Call super class first, and pass in the optimization problem # Call super class first, and pass in the optimization problem
super(WaterVolumeRangeGoal, self).__init__(optimization_problem) super().__init__(optimization_problem)
# Assign V_min and V_max the the target range # Assign V_min and V_max the the target range
self.target_min = optimization_problem.get_timeseries('V_min') self.target_min = optimization_problem.get_timeseries('V_min')
self.target_max = optimization_problem.get_timeseries('V_max') self.target_max = optimization_problem.get_timeseries('V_max')
...@@ -41,7 +41,7 @@ class Example(GoalProgrammingMixin, CSVLookupTableMixin, CSVMixin, ...@@ -41,7 +41,7 @@ class Example(GoalProgrammingMixin, CSVLookupTableMixin, CSVMixin,
""" """
def pre(self): def pre(self):
super(Example, self).pre() super().pre()
# Empty list for storing intermediate_results # Empty list for storing intermediate_results
self.intermediate_results = [] self.intermediate_results = []
...@@ -91,7 +91,7 @@ class Example(GoalProgrammingMixin, CSVLookupTableMixin, CSVMixin, ...@@ -91,7 +91,7 @@ class Example(GoalProgrammingMixin, CSVLookupTableMixin, CSVMixin,
def post(self): def post(self):
# Call super() class to not overwrite default behaviour # Call super() class to not overwrite default behaviour
super(Example, self).post() super().post()
for priority, n_level_satisfied, q_release_integral in self.intermediate_results: for priority, n_level_satisfied, q_release_integral in self.intermediate_results:
print("\nAfter finishing goals of priority {}:".format(priority)) print("\nAfter finishing goals of priority {}:".format(priority))
print("Volume goal satisfied at {} of {} time steps".format( print("Volume goal satisfied at {} of {} time steps".format(
...@@ -100,7 +100,7 @@ class Example(GoalProgrammingMixin, CSVLookupTableMixin, CSVMixin, ...@@ -100,7 +100,7 @@ class Example(GoalProgrammingMixin, CSVLookupTableMixin, CSVMixin,
# Any solver options can be set here # Any solver options can be set here
def solver_options(self): def solver_options(self):
options = super(Example, self).solver_options() options = super().solver_options()
options['print_level'] = 1 options['print_level'] = 1
return options return options
......
...@@ -24,7 +24,7 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem): ...@@ -24,7 +24,7 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem):
# Timeseries rather than a single number. # Timeseries rather than a single number.
def path_constraints(self, ensemble_member): def path_constraints(self, ensemble_member):
# Call super to get default constraints # Call super to get default constraints
constraints = super(Example, self).path_constraints(ensemble_member) constraints = super().path_constraints(ensemble_member)
# M is a handy big number # M is a handy big number
M = 1e10 M = 1e10
...@@ -54,7 +54,7 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem): ...@@ -54,7 +54,7 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem):
# Any solver options can be set here # Any solver options can be set here
def solver_options(self): def solver_options(self):
options = super(Example, self).solver_options() options = super().solver_options()
# Restrict solver output # Restrict solver output
options['print_level'] = 1 options['print_level'] = 1
return options return options
......
...@@ -143,7 +143,7 @@ class DiagHandler(logging.Handler): ...@@ -143,7 +143,7 @@ class DiagHandler(logging.Handler):
def close(self): def close(self):
self.flush() self.flush()
super(DiagHandler, self).close() super().close()
class ParameterConfig: class ParameterConfig:
......
...@@ -66,11 +66,11 @@ class CSVLookupTableMixin(OptimizationProblem): ...@@ -66,11 +66,11 @@ class CSVLookupTableMixin(OptimizationProblem):
self._lookup_table_folder = kwargs['lookup_table_folder'] self._lookup_table_folder = kwargs['lookup_table_folder']
# Call parent # Call parent
super(CSVLookupTableMixin, self).__init__(**kwargs) super().__init__(**kwargs)
def pre(self): def pre(self):
# Call parent class first for default behaviour. # Call parent class first for default behaviour.
super(CSVLookupTableMixin, self).pre() super().pre()
# Get curve fitting options from curvefit_options.ini file # Get curve fitting options from curvefit_options.ini file
ini_path = os.path.join( ini_path = os.path.join(
......
...@@ -57,11 +57,11 @@ class CSVMixin(OptimizationProblem): ...@@ -57,11 +57,11 @@ class CSVMixin(OptimizationProblem):
self._output_timeseries = set() self._output_timeseries = set()
# Call parent class first for default behaviour. # Call parent class first for default behaviour.
super(CSVMixin, self).__init__(**kwargs) super().__init__(**kwargs)
def pre(self): def pre(self):
# Call parent class first for default behaviour. # Call parent class first for default behaviour.
super(CSVMixin, self).pre() super().pre()
# Helper function to check if initiale state array actually defines # Helper function to check if initiale state array actually defines
# only the initial state # only the initial state
...@@ -180,7 +180,7 @@ class CSVMixin(OptimizationProblem): ...@@ -180,7 +180,7 @@ class CSVMixin(OptimizationProblem):
@cached @cached
def parameters(self, ensemble_member): def parameters(self, ensemble_member):
# Call parent class first for default values. # Call parent class first for default values.
parameters = super(CSVMixin, self).parameters(ensemble_member) parameters = super().parameters(ensemble_member)
# Load parameters from parameter config # Load parameters from parameter config
for parameter in self.dae_variables['parameters']: for parameter in self.dae_variables['parameters']:
...@@ -217,7 +217,7 @@ class CSVMixin(OptimizationProblem): ...@@ -217,7 +217,7 @@ class CSVMixin(OptimizationProblem):
@cached @cached
def bounds(self): def bounds(self):
# Call parent class first for default values. # Call parent class first for default values.
bounds = super(CSVMixin, self).bounds() bounds = super().bounds()
# Load bounds from timeseries # Load bounds from timeseries
for variable in self.dae_variables['free_variables']: for variable in self.dae_variables['free_variables']:
...@@ -263,7 +263,7 @@ class CSVMixin(OptimizationProblem): ...@@ -263,7 +263,7 @@ class CSVMixin(OptimizationProblem):
@cached @cached
def initial_state(self, ensemble_member): def initial_state(self, ensemble_member):
# Call parent class first for default values. # Call parent class first for default values.
initial_state = super(CSVMixin, self).initial_state(ensemble_member) initial_state = super().initial_state(ensemble_member)
# Load parameters from parameter config # Load parameters from parameter config
for variable in self.dae_variables['free_variables']: for variable in self.dae_variables['free_variables']:
...@@ -280,7 +280,7 @@ class CSVMixin(OptimizationProblem): ...@@ -280,7 +280,7 @@ class CSVMixin(OptimizationProblem):
@cached @cached
def seed(self, ensemble_member): def seed(self, ensemble_member):
# Call parent class first for default values. # Call parent class first for default values.
seed = super(CSVMixin, self).seed(ensemble_member) seed = super().seed(ensemble_member)
# Load seed values from CSV # Load seed values from CSV
for variable in self.dae_variables['free_variables']: for variable in self.dae_variables['free_variables']:
...@@ -299,7 +299,7 @@ class CSVMixin(OptimizationProblem): ...@@ -299,7 +299,7 @@ class CSVMixin(OptimizationProblem):
def post(self): def post(self):
# Call parent class first for default behaviour. # Call parent class first for default behaviour.
super(CSVMixin, self).post() super().post()
# Write output # Write output
times = self.times() times = self.times()
...@@ -378,7 +378,7 @@ class CSVMixin(OptimizationProblem): ...@@ -378,7 +378,7 @@ class CSVMixin(OptimizationProblem):
@property @property
def output_variables(self): def output_variables(self):
variables = super(CSVMixin, self).output_variables variables = super().output_variables
variables.extend([MX.sym(variable) variables.extend([MX.sym(variable)
for variable in self._output_timeseries]) for variable in self._output_timeseries])
return variables return variables
......
...@@ -281,7 +281,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta): ...@@ -281,7 +281,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
def __init__(self, **kwargs): def __init__(self, **kwargs):
# Call parent class first for default behaviour. # Call parent class first for default behaviour.
super(GoalProgrammingMixin, self).__init__(**kwargs) super().__init__(**kwargs)
# Initialize empty lists, so that the overridden methods may be called outside of the goal programming loop, # Initialize empty lists, so that the overridden methods may be called outside of the goal programming loop,
# for example in pre(). # for example in pre().
...@@ -301,7 +301,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta): ...@@ -301,7 +301,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
return self._subproblem_path_epsilons + [variable for (variable, value) in self._subproblem_path_timeseries] return self._subproblem_path_epsilons + [variable for (variable, value) in self._subproblem_path_timeseries]
def bounds(self): def bounds(self):
bounds = super(GoalProgrammingMixin, self).bounds() bounds = super().bounds()
for epsilon in self._subproblem_epsilons + self._subproblem_path_epsilons: for epsilon in self._subproblem_epsilons + self._subproblem_path_epsilons:
bounds[epsilon.name()] = (0.0, 1.0) bounds[epsilon.name()] = (0.0, 1.0)
for (variable, value) in self._subproblem_path_timeseries: for (variable, value) in self._subproblem_path_timeseries:
...@@ -312,7 +312,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta): ...@@ -312,7 +312,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
def seed(self, ensemble_member): def seed(self, ensemble_member):
if self._first_run: if self._first_run:
seed = super(GoalProgrammingMixin, self).seed(ensemble_member) seed = super().seed(ensemble_member)
else: else:
# Seed with previous results # Seed with previous results
seed = AliasDict(self.alias_relation) seed = AliasDict(self.alias_relation)
...@@ -348,20 +348,20 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta): ...@@ -348,20 +348,20 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
return MX(0) return MX(0)
def constraints(self, ensemble_member): def constraints(self, ensemble_member):
constraints = super(GoalProgrammingMixin, self).constraints(ensemble_member) constraints = super().constraints(ensemble_member)
for l in self._subproblem_constraints[ensemble_member].values(): for l in self._subproblem_constraints[ensemble_member].values():
constraints.extend(((constraint.function(self), constraint.min, constraint.max) for constraint in l)) constraints.extend(((constraint.function(self), constraint.min, constraint.max) for constraint in l))
return constraints return constraints
def path_constraints(self, ensemble_member): def path_constraints(self, ensemble_member):
path_constraints = super(GoalProgrammingMixin, self).path_constraints(ensemble_member) path_constraints = super().path_constraints(ensemble_member)
for l in self._subproblem_path_constraints[ensemble_member].values(): for l in self._subproblem_path_constraints[ensemble_member].values():
path_constraints.extend(((constraint.function(self), constraint.min, constraint.max) for constraint in l)) path_constraints.extend(((constraint.function(self), constraint.min, constraint.max) for constraint in l))
return path_constraints return path_constraints
def solver_options(self): def solver_options(self):
# Call parent # Call parent
options = super(GoalProgrammingMixin, self).solver_options() options = super().solver_options()
# Make sure constant states, such as min/max timeseries for violation variables, # Make sure constant states, such as min/max timeseries for violation variables,
# are turned into parameters for the final optimization problem. # are turned into parameters for the final optimization problem.
...@@ -805,7 +805,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta): ...@@ -805,7 +805,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
goal, epsilon, ensemble_member, options, min_series, max_series) goal, epsilon, ensemble_member, options, min_series, max_series)
# Solve subproblem # Solve subproblem
success = super(GoalProgrammingMixin, self).optimize( success = super().optimize(
preprocessing=False, postprocessing=False, log_solver_failure_as_error=log_solver_failure_as_error) preprocessing=False, postprocessing=False, log_solver_failure_as_error=log_solver_failure_as_error)
if not success: if not success:
break break
...@@ -937,4 +937,4 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta): ...@@ -937,4 +937,4 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
# If self._results is not up to date, do the super().extract_results # If self._results is not up to date, do the super().extract_results
# method # method
return super(GoalProgrammingMixin, self).extract_results(ensemble_member) return super().extract_results(ensemble_member)
...@@ -24,7 +24,7 @@ class HomotopyMixin(OptimizationProblem): ...@@ -24,7 +24,7 @@ class HomotopyMixin(OptimizationProblem):
""" """
def seed(self, ensemble_member): def seed(self, ensemble_member):
seed = super(HomotopyMixin, self).seed(ensemble_member) seed = super().seed(ensemble_member)
if self._theta > 0: if self._theta > 0:
# Add previous results to seed # Add previous results to seed
# Do not override any previously seeded values, such as goal programming results. # Do not override any previously seeded values, such as goal programming results.
...@@ -37,7 +37,7 @@ class HomotopyMixin(OptimizationProblem): ...@@ -37,7 +37,7 @@ class HomotopyMixin(OptimizationProblem):
return seed return seed
def parameters(self, ensemble_member): def parameters(self, ensemble_member):
parameters = super(HomotopyMixin, self).parameters(ensemble_member) parameters = super().parameters(ensemble_member)
options = self.homotopy_options() options = self.homotopy_options()
parameters[options['homotopy_parameter']] = self._theta parameters[options['homotopy_parameter']] = self._theta
...@@ -87,7 +87,7 @@ class HomotopyMixin(OptimizationProblem): ...@@ -87,7 +87,7 @@ class HomotopyMixin(OptimizationProblem):
while self._theta <= 1.0: while self._theta <= 1.0:
logger.info("Solving with homotopy parameter theta = {}.".format(self._theta)) logger.info("Solving with homotopy parameter theta = {}.".format(self._theta))
success = super(HomotopyMixin, self).optimize(preprocessing=False, postprocessing=False, log_solver_failure_as_error=False) success = super().optimize(preprocessing=False, postprocessing=False, log_solver_failure_as_error=False)
if success: if success:
self._results = [self.extract_results(ensemble_member) for ensemble_member in range(self.ensemble_size)] self._results = [self.extract_results(ensemble_member) for ensemble_member in range(self.ensemble_size)]
......
...@@ -70,7 +70,7 @@ class InitialStateEstimationMixin(GoalProgrammingMixin): ...@@ -70,7 +70,7 @@ class InitialStateEstimationMixin(GoalProgrammingMixin):
return [] return []
def goals(self): def goals(self):
g = super(InitialStateEstimationMixin, self).goals() g = super().goals()
for measurement in self.initial_state_measurements(): for measurement in self.initial_state_measurements():
g.append(_MeasurementGoal(*measurement)) g.append(_MeasurementGoal(*measurement))
......
...@@ -15,7 +15,7 @@ class LinearizationMixin(OptimizationProblem): ...@@ -15,7 +15,7 @@ class LinearizationMixin(OptimizationProblem):
""" """
def parameters(self, ensemble_member): def parameters(self, ensemble_member):
parameters = super(LinearizationMixin, self).parameters(ensemble_member) parameters = super().parameters(ensemble_member)
for parameter, timeseries_id in self.linearization_parameters().items(): for parameter, timeseries_id in self.linearization_parameters().items():
parameters[parameter] = self.timeseries_at(timeseries_id, self.initial_time, ensemble_member) parameters[parameter] = self.timeseries_at(timeseries_id, self.initial_time, ensemble_member)
......
...@@ -108,7 +108,7 @@ class ModelicaMixin(OptimizationProblem): ...@@ -108,7 +108,7 @@ class ModelicaMixin(OptimizationProblem):
self._nominals = {} self._nominals = {}
self._discrete = {} self._discrete = {}
for v in itertools.chain(self._pymola_model.states, self._pymola_model.alg_states, self._pymola_model.inputs): for v in itertools.chain(self._pymola_model.states, self._pymola_model.alg_states, self._pymola_model.inputs):
sym_name = v.symbol.name() sym_name = v.symbol.name()
if v.nominal != 0 and v.nominal != 1: if v.nominal != 0 and v.nominal != 1:
self._nominals[sym_name] = abs(float(v.nominal)) self._nominals[sym_name] = abs(float(v.nominal))
...@@ -131,7 +131,7 @@ class ModelicaMixin(OptimizationProblem): ...@@ -131,7 +131,7 @@ class ModelicaMixin(OptimizationProblem):
self._initial_residual = MX() self._initial_residual = MX()
# Call parent class first for default behaviour. # Call parent class first for default behaviour.
super(ModelicaMixin, self).__init__(**kwargs) super().__init__(**kwargs)
@cached @cached
def compiler_options(self): def compiler_options(self):
...@@ -173,7 +173,7 @@ class ModelicaMixin(OptimizationProblem): ...@@ -173,7 +173,7 @@ class ModelicaMixin(OptimizationProblem):
return compiler_options return compiler_options
def delayed_feedback(self): def delayed_feedback(self):
delayed_feedback = super(ModelicaMixin, self).delayed_feedback() delayed_feedback = super().delayed_feedback()
delayed_feedback.extend([(dfb.origin, dfb.name, dfb.delay) for dfb in self._pymola_model.delayed_states]) delayed_feedback.extend([(dfb.origin, dfb.name, dfb.delay) for dfb in self._pymola_model.delayed_states])
return delayed_feedback return delayed_feedback
...@@ -192,7 +192,7 @@ class ModelicaMixin(OptimizationProblem): ...@@ -192,7 +192,7 @@ class ModelicaMixin(OptimizationProblem):
@cached @cached
def parameters(self, ensemble_member): def parameters(self, ensemble_member):
# Call parent class first for default values. # Call parent class first for default values.
parameters = super(ModelicaMixin, self).parameters(ensemble_member) parameters = super().parameters(ensemble_member)
# Return parameter values from pymola model # Return parameter values from pymola model
for v in self._pymola_model.parameters: for v in self._pymola_model.parameters:
...@@ -204,7 +204,7 @@ class ModelicaMixin(OptimizationProblem): ...@@ -204,7 +204,7 @@ class ModelicaMixin(OptimizationProblem):
@cached @cached
def constant_inputs(self, ensemble_member): def constant_inputs(self, ensemble_member):
# Call parent class first for default values. # Call parent class first for default values.
constant_inputs = super(ModelicaMixin, self).constant_inputs(ensemble_member) constant_inputs = super().constant_inputs(ensemble_member)
# Return input values from pymola model # Return input values from pymola model
times = self.times() times = self.times()
...@@ -248,7 +248,7 @@ class ModelicaMixin(OptimizationProblem): ...@@ -248,7 +248,7 @@ class ModelicaMixin(OptimizationProblem):
@cached @cached
def bounds(self): def bounds(self):
# Call parent class first for default values. # Call parent class first for default values.
bounds = super(ModelicaMixin, self).bounds() bounds = super().bounds()
# Parameter values # Parameter values
parameters = self.parameters(0) parameters = self.parameters(0)
......
...@@ -62,11 +62,11 @@ class PIMixin(OptimizationProblem): ...@@ -62,11 +62,11 @@ class PIMixin(OptimizationProblem):
self._output_timeseries = set() self._output_timeseries = set()
# Call parent class first for default behaviour. # Call parent class first for default behaviour.
super(PIMixin, self).__init__(**kwargs) super().__init__(**kwargs)
def pre(self): def pre(self):
# Call parent class first for default behaviour. # Call parent class first for default behaviour.
super(PIMixin, self).pre() super().pre()
# rtcParameterConfig # rtcParameterConfig
self._parameter_config = [] self._parameter_config = []
...@@ -139,7 +139,7 @@ class PIMixin(OptimizationProblem): ...@@ -139,7 +139,7 @@ class PIMixin(OptimizationProblem):
def solver_options(self): def solver_options(self):
# Call parent # Call parent
options = super(PIMixin, self).solver_options() options = super().solver_options()
# Only do this if we have a rtcParameterConfig_Numerical # Only do this if we have a rtcParameterConfig_Numerical
if self._parameter_config_numerical is None: if self._parameter_config_numerical is None:
...@@ -155,7 +155,7 @@ class PIMixin(OptimizationProblem): ...@@ -155,7 +155,7 @@ class PIMixin(OptimizationProblem):
@cached @cached
def parameters(self, ensemble_member): def parameters(self, ensemble_member):
# Call parent class first for default values. # Call parent class first for default values.
parameters = super(PIMixin, self).parameters(ensemble_member) parameters = super().parameters(ensemble_member)
# Load parameters from parameter config # Load parameters from parameter config
for parameter_config in self._parameter_config: for parameter_config in self._parameter_config:
...@@ -177,7 +177,7 @@ class PIMixin(OptimizationProblem): ...@@ -177,7 +177,7 @@ class PIMixin(OptimizationProblem):
@cached @cached
def constant_inputs(self, ensemble_member): def constant_inputs(self, ensemble_member):
# Call parent class first for default values. # Call parent class first for default values.
constant_inputs = super(PIMixin, self).constant_inputs(ensemble_member) constant_inputs = super().constant_inputs(ensemble_member)
# Load bounds from timeseries # Load bounds from timeseries
for variable in self.dae_variables['constant_inputs']: for variable in self.dae_variables['constant_inputs']:
...@@ -198,7 +198,7 @@ class PIMixin(OptimizationProblem): ...@@ -198,7 +198,7 @@ class PIMixin(OptimizationProblem):
@cached