Commit fe6b3a2f authored by Jorn Baayen's avatar Jorn Baayen

Merge branch 'casadi3-fixes' into 'casadi3'

Casadi3 fixes

See merge request !66
parents 64d3fa62 179f8d9c
......@@ -57,9 +57,9 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'RTC-Tools'
copyright = u'2016 Deltares'
author = u'Jorn Baayen, Matthijs den Toom, et al.'
project = 'RTC-Tools'
copyright = '2016 Deltares'
author = 'Jorn Baayen, Matthijs den Toom, et al.'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
......@@ -268,8 +268,8 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'RTC-Tools.tex', u'RTC-Tools Documentation',
u'Jorn Baayen, Matthijs den Toom, et al.', 'manual'),
(master_doc, 'RTC-Tools.tex', 'RTC-Tools Documentation',
'Jorn Baayen, Matthijs den Toom, et al.', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
......@@ -310,7 +310,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'rtc-tools', u'RTC-Tools Documentation',
(master_doc, 'rtc-tools', 'RTC-Tools Documentation',
[author], 1)
]
......@@ -325,7 +325,7 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'RTC-Tools', u'RTC-Tools Documentation',
(master_doc, 'RTC-Tools', 'RTC-Tools Documentation',
author, 'RTC-Tools', 'One line description of project.',
'Miscellaneous'),
]
......
......@@ -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
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
declaration to store our list of intermediate results. This variable is a
dict, reflecting the need to store results from multiple ensemble.
......
......@@ -188,7 +188,7 @@ methods.
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,
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
store our list of intermediate results:
......
......@@ -107,7 +107,7 @@ classes.
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,
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
store our list of intermediate results.
......
......@@ -20,8 +20,8 @@ axarr[0].set_title('Water Volume and Discharge')
f.autofmt_xdate()
# Upper subplot
axarr[0].set_ylabel(u'Water Volume [m\u00B3]')
axarr[0].ticklabel_format(style='sci', axis='y', scilimits=(0,0))
axarr[0].set_ylabel('Water Volume [m³]')
axarr[0].ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
axarr[0].plot(results['time'], results['V_storage'], label='Storage',
linewidth=2, color='b')
axarr[0].plot(results['time'], [420000]*len(results['time']), label='Storage Max',
......@@ -30,7 +30,7 @@ axarr[0].plot(results['time'], [380000]*len(results['time']), label='Storage Min
linewidth=2, color='g', linestyle='--')
# Lower Subplot
axarr[1].set_ylabel(u'Flow Rate [m\u00B3/s]')
axarr[1].set_ylabel('Flow Rate [m³/s]')
# axarr[1].plot(results['time'], results['Q_in'], label='Inflow',
# linewidth=2, color='g')
axarr[1].plot(results['time'], results['Q_release'], label='Release',
......
......@@ -25,11 +25,11 @@ shades = [0.5, 0.8]
f.autofmt_xdate()
# Upper Subplot
axarr[0].set_ylabel(u'Water Volume in Storage [m\u00B3]')
axarr[0].ticklabel_format(style='sci', axis='y', scilimits=(0,0))
axarr[0].set_ylabel('Water Volume in Storage [m³]')
axarr[0].ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
# Lower Subplot
axarr[1].set_ylabel(u'Flow Rate [m\u00B3/s]')
axarr[1].set_ylabel('Flow Rate [m³/s]')
# Plot Ensemble Members
for idx, forecast in enumerate(forecast_names):
......
......@@ -35,7 +35,7 @@ axarr[1].plot(results['time'], 0.43 * np.ones_like(results['time']), label='Stor
linewidth=2, color='g', linestyle='--')
# Lower Subplot
axarr[2].set_ylabel(u'Flow Rate [m\u00B3/s]')
axarr[2].set_ylabel('Flow Rate [m³/s]')
axarr[2].plot(results['time'], results['Q_orifice'], label='Orifice',
linewidth=2, color='g')
axarr[2].plot(results['time'], results['Q_pump'], label='Pump',
......
......@@ -20,8 +20,8 @@ axarr[0].set_title('Water Volume and Discharge')
f.autofmt_xdate()
# Upper subplot
axarr[0].set_ylabel(u'Water Volume [m\u00B3]')
axarr[0].ticklabel_format(style='sci', axis='y', scilimits=(0,0))
axarr[0].set_ylabel('Water Volume [m³]')
axarr[0].ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
axarr[0].plot(results['time'], results['storage_V'], label='Storage',
linewidth=2, color='b')
axarr[0].plot(results['time'], results['V_max'], label='Storage Max',
......@@ -30,7 +30,7 @@ axarr[0].plot(results['time'], results['V_min'], label='Storage Min',
linewidth=2, color='g', linestyle='--')
# Lower Subplot
axarr[1].set_ylabel(u'Flow Rate [m\u00B3/s]')
axarr[1].set_ylabel('Flow Rate [m³/s]')
axarr[1].plot(results['time'], results['Q_in'], label='Inflow',
linewidth=2, color='g')
axarr[1].plot(results['time'], results['Q_release'], label='Release',
......
......@@ -27,7 +27,7 @@ axarr[0].plot(results['time'], 0.5 * np.ones_like(results['time']), label='Stora
linewidth=2, color='r', linestyle='--')
# Lower Subplot
axarr[1].set_ylabel(u'Flow Rate [m\u00B3/s]')
axarr[1].set_ylabel('Flow Rate [m³/s]')
axarr[1].plot(results['time'], results['Q_orifice'], label='Orifice',
linewidth=2, color='g')
axarr[1].plot(results['time'], results['Q_pump'], label='Pump',
......
......@@ -17,7 +17,7 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem):
def path_constraints(self, ensemble_member):
# 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
constraints.append((self.state('storage.V'), 380000, 420000))
return constraints
......
......@@ -13,7 +13,7 @@ import numpy as np
class WaterVolumeRangeGoal(StateGoal):
def __init__(self, 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
self.target_min = optimization_problem.get_timeseries('V_min')
self.target_max = optimization_problem.get_timeseries('V_max')
......@@ -41,7 +41,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin,
def pre(self):
# Do the standard preprocessing
super(Example, self).pre()
super().pre()
# Create a dict of empty lists for storing intermediate results from
# each ensemble
......@@ -82,7 +82,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin,
def control_tree_options(self):
# 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
options = super(Example, self).control_tree_options()
options = super().control_tree_options()
# Change the branching_times list to only contain the fifth timestep
options['branching_times'] = [self.times()[5]]
return options
......@@ -111,7 +111,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin,
q_release_integral))
def post(self):
super(Example, self).post()
super().post()
for e_m in range(self.ensemble_size):
print('\n\nResults for Ensemble Member {}:'.format(e_m))
for priority, n_level_satisfied, q_release_integral in \
......@@ -123,7 +123,7 @@ class Example(GoalProgrammingMixin, ControlTreeMixin, CSVLookupTableMixin,
# Any solver options can be set here
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
# scaling, so mumps scaling is not critical. Proprietary HSL solvers
# do not exhibit this error.
......
......@@ -67,7 +67,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
# We want to add a few hard constraints to our problem. The goal
# programming mixin however also generates constraints (and objectives)
# 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
# fact that water only flows downhill
......@@ -108,7 +108,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
def pre(self):
# 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
# information about the progress of goals at the end of our run.
self.intermediate_results = []
......@@ -134,7 +134,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
def post(self):
# 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 \
in self.intermediate_results:
print('\nAfter finishing goals of priority {}:'.format(priority))
......@@ -145,7 +145,7 @@ class Example(GoalProgrammingMixin, CSVMixin, ModelicaMixin,
# Any solver options can be set here
def solver_options(self):
options = super(Example, self).solver_options()
options = super().solver_options()
options['print_level'] = 1
return options
......
......@@ -16,7 +16,7 @@ class WaterVolumeRangeGoal(StateGoal):
# this goal.
def __init__(self, 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
self.target_min = optimization_problem.get_timeseries('V_min')
self.target_max = optimization_problem.get_timeseries('V_max')
......@@ -41,7 +41,7 @@ class Example(GoalProgrammingMixin, CSVLookupTableMixin, CSVMixin,
"""
def pre(self):
super(Example, self).pre()
super().pre()
# Empty list for storing intermediate_results
self.intermediate_results = []
......@@ -91,7 +91,7 @@ class Example(GoalProgrammingMixin, CSVLookupTableMixin, CSVMixin,
def post(self):
# 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:
print("\nAfter finishing goals of priority {}:".format(priority))
print("Volume goal satisfied at {} of {} time steps".format(
......@@ -100,7 +100,7 @@ class Example(GoalProgrammingMixin, CSVLookupTableMixin, CSVMixin,
# Any solver options can be set here
def solver_options(self):
options = super(Example, self).solver_options()
options = super().solver_options()
options['print_level'] = 1
return options
......
......@@ -24,7 +24,7 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem):
# Timeseries rather than a single number.
def path_constraints(self, ensemble_member):
# 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 = 1e10
......@@ -54,7 +54,7 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem):
# Any solver options can be set here
def solver_options(self):
options = super(Example, self).solver_options()
options = super().solver_options()
# Restrict solver output
options['print_level'] = 1
return options
......
......@@ -143,7 +143,7 @@ class DiagHandler(logging.Handler):
def close(self):
self.flush()
super(DiagHandler, self).close()
super().close()
class ParameterConfig:
......@@ -178,12 +178,12 @@ class ParameterConfig:
"pi:group[@id='{}']".format(group_id), ns)
for group in groups:
el = group.find("pi:locationId", ns)
if location_id != None and el != None:
if location_id is not None and el is not None:
if location_id != el.text:
continue
el = group.find("pi:model", ns)
if model != None and el != None:
if model is not None and el is not None:
if model != el.text:
continue
......@@ -209,12 +209,12 @@ class ParameterConfig:
"pi:group[@id='{}']".format(group_id), ns)
for group in groups:
el = group.find("pi:locationId", ns)
if location_id != None and el != None:
if location_id is not None and el is not None:
if location_id != el.text:
continue
el = group.find("pi:model", ns)
if model != None and el != None:
if model is not None and el is not None:
if model != el.text:
continue
......@@ -282,13 +282,13 @@ class ParameterConfig:
# get Id's if present
el_columnIds = child.find("pi:columnIds", ns)
if el_columnIds != None:
if el_columnIds is not None:
for key, value in el_columnIds.attrib.items():
columnId[key] = value
# get Types if present
el_columnTypes = child.find("pi:columnTypes", ns)
if el_columnTypes != None:
if el_columnTypes is not None:
for key, value in el_columnTypes.attrib.items():
columnType[key] = self._parse_type(value)
......@@ -383,7 +383,7 @@ class Timeseries:
# Read timezone
timezone = self._xml_root.find('pi:timeZone', ns)
if timezone != None:
if timezone is not None:
self._timezone = float(timezone.text)
else:
self._timezone = None
......@@ -435,7 +435,7 @@ class Timeseries:
variable, os.path.join(self._folder, basename + '.xml')))
el = header.find('pi:forecastDate', ns)
if el != None:
if el is not None:
forecast_datetime = _parse_date_time(el)
else:
# the timeseries has no forecastDate, so the forecastDate
......@@ -444,12 +444,12 @@ class Timeseries:
if self._forecast_datetime is None:
self._forecast_datetime = forecast_datetime
else:
if el != None and forecast_datetime != self._forecast_datetime:
if el is not None and forecast_datetime != self._forecast_datetime:
raise Exception(
'PI: Not all timeseries share the same forecastDate.')
el = header.find('pi:ensembleMemberIndex', ns)
if el != None:
if el is not None:
contains_ensemble = True
if int(el.text) > self._ensemble_size - 1: # Assume zero-based
self._ensemble_size = int(el.text) + 1
......@@ -485,7 +485,7 @@ class Timeseries:
if not set(self._times).issuperset(set(times)):
raise Exception('PI: Not all timeseries share the same time step spacing. Make sure the time steps of all series are a subset of the global time steps.')
if self._forecast_datetime != None:
if self._forecast_datetime is not None:
if self._dt:
self._forecast_datetime = _floor_date_time(
dt=self._forecast_datetime, tdel=self._dt)
......@@ -510,7 +510,7 @@ class Timeseries:
make_virtual_ensemble = False
el = header.find('pi:ensembleMemberIndex', ns)
if el != None:
if el is not None:
ensemble_member = int(el.text)
while ensemble_member >= len(self._values):
self._values.append({})
......@@ -533,7 +533,7 @@ class Timeseries:
n_values = bisect.bisect_left(self._times, end_datetime) - bisect.bisect_left(self._times, start_datetime) + 1
if self._binary:
if f != None:
if f is not None:
self._values[ensemble_member][variable] = np.fromstring(
f.read(self._pi_dtype(0).itemsize * n_values), dtype=self._pi_dtype)
else:
......@@ -598,7 +598,7 @@ class Timeseries:
# times automatically from global start/end datetime.
self._times = self._times[bisect.bisect_left(self._times, self._start_datetime) : bisect.bisect_left(self._times, self._end_datetime)+1]
if f != None and self._binary:
if f is not None and self._binary:
f.close()
def _add_header(self, variable, location_parameter_id, ensemble_member=0, miss_val=-999, unit='unit_unknown'):
......@@ -667,7 +667,7 @@ class Timeseries:
if self._binary:
f = io.open(self.binary_path, 'wb')
if self.timezone != None:
if self.timezone is not None:
timezone = self._xml_root.find('pi:timeZone', ns)
if timezone is None:
timezone = ET.Element('{%s}' % (ns['pi'], ) + 'timeZone')
......@@ -688,7 +688,7 @@ class Timeseries:
# First check ensembleMemberIndex, to see if it is the correct one.
el = header.find('pi:ensembleMemberIndex', ns)
if el != None:
if el is not None:
if ensemble_member != int(el.text):
# Skip over this series, wrong index.
continue
......
......@@ -966,13 +966,13 @@ class CollocatedIntegratedOptimizationProblem(OptimizationProblem, metaclass = A
pass
else:
nominal = self.variable_nominal(variable)
if bound[0] != None:
if bound[0] is not None:
if isinstance(bound[0], Timeseries):
lbx[offset:offset + n_times] = self.interpolate(
times, bound[0].times, bound[0].values, -np.inf, -np.inf) / nominal
else:
lbx[offset:offset + n_times] = bound[0] / nominal
if bound[1] != None:
if bound[1] is not None:
if isinstance(bound[1], Timeseries):
ubx[offset:offset + n_times] = self.interpolate(
times, bound[1].times, bound[1].values, +np.inf, +np.inf) / nominal
......@@ -1145,13 +1145,13 @@ class CollocatedIntegratedOptimizationProblem(OptimizationProblem, metaclass = A
pass
else:
nominal = self.variable_nominal(variable)
if bound[0] != None:
if bound[0] is not None:
if isinstance(bound[0], Timeseries):
lbx[offset] = self.interpolate(self.initial_time, bound[0].times, bound[
0].values, -np.inf, -np.inf) / nominal
else:
lbx[offset] = bound[0] / nominal
if bound[1] != None:
if bound[1] is not None:
if isinstance(bound[1], Timeseries):
ubx[offset] = self.interpolate(self.initial_time, bound[1].times, bound[
1].values, +np.inf, +np.inf) / nominal
......@@ -1170,13 +1170,13 @@ class CollocatedIntegratedOptimizationProblem(OptimizationProblem, metaclass = A
pass
else:
nominal = self.variable_nominal(variable)
if bound[0] != None:
if bound[0] is not None:
if isinstance(bound[0], Timeseries):
lbx[offset:offset + n_times] = self.interpolate(
times, bound[0].times, bound[0].values, -np.inf, -np.inf) / nominal
else:
lbx[offset:offset + n_times] = bound[0] / nominal
if bound[1] != None:
if bound[1] is not None:
if isinstance(bound[1], Timeseries):
ubx[offset:offset + n_times] = self.interpolate(
times, bound[1].times, bound[1].values, +np.inf, +np.inf) / nominal
......@@ -1191,9 +1191,9 @@ class CollocatedIntegratedOptimizationProblem(OptimizationProblem, metaclass = A
except KeyError:
pass
else:
if bound[0] != None:
if bound[0] is not None:
lbx[offset + k] = bound[0]
if bound[1] != None:
if bound[1] is not None:
ubx[offset + k] = bound[1]
# Initial guess based on provided seeds, defaulting to zero if no
......@@ -1255,9 +1255,7 @@ class CollocatedIntegratedOptimizationProblem(OptimizationProblem, metaclass = A
# elimination.
f = Function('f', [self.solver_input], [
vertcat(*self.integrators_mx)])
f.setInput(X[0:])
f.evaluate()
integrators_output = f.getOutput()
integrators_output = f(X)
j = 0
for variable in self.integrated_states:
n = self.integrators[variable].size1()
......
......@@ -154,7 +154,7 @@ class ControlTreeMixin(OptimizationProblem):
branch(current_branch + str(i))
current_branch = ''
branches[current_branch] = range(self.ensemble_size)
branches[current_branch] = list(range(self.ensemble_size))
branch(current_branch)
logger.debug("ControlTreeMixin: Control tree is:")
......@@ -176,7 +176,7 @@ class ControlTreeMixin(OptimizationProblem):
nnz = np.count_nonzero(els)
for member in members:
self._control_indices[control_input][
member, els] = range(count, count + nnz)
member, els] = list(range(count, count + nnz))
count += nnz
# Construct bounds and initial guess
......@@ -202,14 +202,14 @@ class ControlTreeMixin(OptimizationProblem):
pass
else:
nominal = self.variable_nominal(variable)
if bound[0] != None:
if bound[0] is not None:
if isinstance(bound[0], Timeseries):
lbx[self._control_indices[variable][ensemble_member, :]] = self.interpolate(
times, bound[0].times, bound[0].values, -sys.float_info.max, -sys.float_info.max) / nominal
else:
lbx[self._control_indices[variable][
ensemble_member, :]] = bound[0] / nominal
if bound[1] != None:
if bound[1] is not None:
if isinstance(bound[1], Timeseries):
ubx[self._control_indices[variable][ensemble_member, :]] = self.interpolate(
times, bound[1].times, bound[1].values, +sys.float_info.max, +sys.float_info.max) / nominal
......
......@@ -66,11 +66,11 @@ class CSVLookupTableMixin(OptimizationProblem):
self._lookup_table_folder = kwargs['lookup_table_folder']
# Call parent
super(CSVLookupTableMixin, self).__init__(**kwargs)
super().__init__(**kwargs)
def pre(self):
# Call parent class first for default behaviour.
super(CSVLookupTableMixin, self).pre()
super().pre()
# Get curve fitting options from curvefit_options.ini file
ini_path = os.path.join(
......
......@@ -57,11 +57,11 @@ class CSVMixin(OptimizationProblem):
self._output_timeseries = set()
# Call parent class first for default behaviour.
super(CSVMixin, self).__init__(**kwargs)
super().__init__(**kwargs)
def pre(self):
# Call parent class first for default behaviour.
super(CSVMixin, self).pre()
super().pre()
# Helper function to check if initiale state array actually defines
# only the initial state
......@@ -180,7 +180,7 @@ class CSVMixin(OptimizationProblem):
@cached
def parameters(self, ensemble_member):
# Call parent class first for default values.
parameters = super(CSVMixin, self).parameters(ensemble_member)
parameters = super().parameters(ensemble_member)
# Load parameters from parameter config
for parameter in self.dae_variables['parameters']:
......@@ -217,7 +217,7 @@ class CSVMixin(OptimizationProblem):
@cached
def bounds(self):
# Call parent class first for default values.
bounds = super(CSVMixin, self).bounds()
bounds = super().bounds()
# Load bounds from timeseries
for variable in self.dae_variables['free_variables']:
......@@ -244,15 +244,15 @@ class CSVMixin(OptimizationProblem):
logger.debug("CSVMixin: Read upper bound for variable {}".format(variable))
# Replace NaN with +/- inf, and create Timeseries objects
if m != None:
if m is not None:
m[np.isnan(m)] = np.finfo(m.dtype).min
m = Timeseries(self._timeseries_times_sec, m)
if M != None:
if M is not None:
M[np.isnan(M)] = np.finfo(M.dtype).max
M = Timeseries(self._timeseries_times_sec, M)
# Store
if m != None or M != None:
if m is not None or M is not None:
bounds[variable] = (m, M)
return bounds
......@@ -263,7 +263,7 @@ class CSVMixin(OptimizationProblem):
@cached
def initial_state(self, ensemble_member):
# 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
for variable in self.dae_variables['free_variables']:
......@@ -280,7 +280,7 @@ class CSVMixin(OptimizationProblem):
@cached
def seed(self, ensemble_member):
# Call parent class first for default values.
seed = super(CSVMixin, self).seed(ensemble_member)
seed = super().seed(ensemble_member)
# Load seed values from CSV
for variable in self.dae_variables['free_variables']:
......@@ -299,7 +299,7 @@ class CSVMixin(OptimizationProblem):
def post(self):
# Call parent class first for default behaviour.
super(CSVMixin, self).post()
super().post()
# Write output
times = self.times()
......@@ -378,7 +378,7 @@ class CSVMixin(OptimizationProblem):
@property
def output_variables(self):
variables = super(CSVMixin, self).output_variables
variables = super().output_variables
variables.extend([MX.sym(variable)
for variable in self._output_timeseries])
return variables
......
......@@ -281,7 +281,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
def __init__(self, **kwargs):
# 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,
# for example in pre().
......@@ -301,7 +301,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
return self._subproblem_path_epsilons + [variable for (variable, value) in self._subproblem_path_timeseries]
def bounds(self):
bounds = super(GoalProgrammingMixin, self).bounds()
bounds = super().bounds()
for epsilon in self._subproblem_epsilons + self._subproblem_path_epsilons:
bounds[epsilon.name()] = (0.0, 1.0)
for (variable, value) in self._subproblem_path_timeseries:
......@@ -312,7 +312,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
def seed(self, ensemble_member):
if self._first_run:
seed = super(GoalProgrammingMixin, self).seed(ensemble_member)
seed = super().seed(ensemble_member)
else:
# Seed with previous results
seed = AliasDict(self.alias_relation)
......@@ -348,20 +348,20 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
return MX(0)
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():
constraints.extend(((constraint.function(self), constraint.min, constraint.max) for constraint in l))
return constraints
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():
path_constraints.extend(((constraint.function(self), constraint.min, constraint.max) for constraint in l))
return path_constraints
def solver_options(self):
# Call parent
options = super(GoalProgrammingMixin, self).solver_options()
options = super().solver_options()
# Make sure constant states, such as min/max timeseries for violation variables,
# are turned into parameters for the final optimization problem.
......@@ -805,7 +805,7 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):
goal, epsilon, ensemble_member, options, min_series, max_series)
# Solve subproblem
success = super(GoalProgrammingMixin, self).optimize(
success = super().optimize(
preprocessing=False, postprocessing=False, log_solver_failure_as_error=log_solver_failure_as_error)
if not success:
break
......@@ -937,4 +937,4 @@ class GoalProgrammingMixin(OptimizationProblem, metaclass = ABCMeta):