Commit cc216f6f authored by Jorn Baayen's avatar Jorn Baayen

Move utilities to a toplevel '_internal' submodule.

parent e2b7db2b
......@@ -4,10 +4,11 @@ import numpy as np
import itertools
import logging
from rtctools._internal.alias_tools import AliasDict
from rtctools._internal.casadi_helpers import *
from .optimization_problem import OptimizationProblem
from .timeseries import Timeseries
from .casadi_helpers import *
from .alias_tools import AliasDict
logger = logging.getLogger("rtctools")
......
......@@ -2,7 +2,7 @@ from rtctools.data.interpolation.bspline1d import BSpline1D
from rtctools.data.interpolation.bspline2d import BSpline2D
import rtctools.data.csv as csv
from scipy.interpolate import splrep, bisplrep, splev, bisplev
from casadi import SX, Function
import casadi as ca
import numpy as np
import configparser
import logging
......@@ -172,8 +172,8 @@ class CSVLookupTableMixin(OptimizationProblem):
output], linestyle='', marker='x', markersize=10)
figure_filename = filename.replace('.csv', '.png')
pylab.savefig(figure_filename)
symbols = [SX.sym(inputs[0])]
function = Function('f', symbols, [BSpline1D(*tck)(symbols[0])])
symbols = [ca.SX.sym(inputs[0])]
function = ca.Function('f', symbols, [BSpline1D(*tck)(symbols[0])])
self._lookup_tables[output] = LookupTable(symbols, function)
elif len(csvinput.dtype.names) == 3:
......@@ -205,8 +205,8 @@ class CSVLookupTableMixin(OptimizationProblem):
pylab.plot_surface(i1, i2, o)
figure_filename = filename.replace('.csv', '.png')
pylab.savefig(figure_filename)
symbols = [SX.sym(inputs[0]), SX.sym(inputs[1])]
function = Function('f',
symbols = [ca.SX.sym(inputs[0]), ca.SX.sym(inputs[1])]
function = ca.Function('f',
symbols, [BSpline2D(*tck)(symbols[0], symbols[1])])
self._lookup_tables[output] = LookupTable(symbols, function)
......
from datetime import datetime, timedelta
from casadi import MX
import casadi as ca
import numpy as np
import logging
import os
import sys
import rtctools.data.csv as csv
from rtctools._internal.alias_tools import AliasDict
from rtctools._internal.caching import cached
from .timeseries import Timeseries
from .optimization_problem import OptimizationProblem
from .alias_tools import AliasDict
from .caching import cached
logger = logging.getLogger("rtctools")
......@@ -379,7 +380,7 @@ class CSVMixin(OptimizationProblem):
@property
def output_variables(self):
variables = super().output_variables
variables.extend([MX.sym(variable)
variables.extend([ca.MX.sym(variable)
for variable in self._output_timeseries])
return variables
......
......@@ -5,11 +5,12 @@ import itertools
import logging
import os
from rtctools._internal.alias_tools import AliasRelation, AliasDict
from rtctools._internal.caching import cached
from rtctools._internal.casadi_helpers import substitute_in_external, array_from_mx
from .timeseries import Timeseries
from .optimization_problem import OptimizationProblem
from .alias_tools import AliasRelation, AliasDict
from .casadi_helpers import substitute_in_external, array_from_mx
from .caching import cached
logger = logging.getLogger("rtctools")
......
from casadi import Function, nlpsol, MX, vertcat
from abc import ABCMeta, abstractmethod, abstractproperty
from numba import jit
import casadi as ca
import numpy as np
import itertools
import logging
from rtctools._internal.alias_tools import AliasDict
from .timeseries import Timeseries
from .alias_tools import AliasDict
logger = logging.getLogger("rtctools")
......@@ -91,7 +92,7 @@ class OptimizationProblem(metaclass = ABCMeta):
self.pre()
# Check if control inputs are bounded
self._check_bounds_control_input()
self.__check_bounds_control_input()
else:
logger.debug(
'Skipping Preprocessing in OptimizationProblem.optimize()')
......@@ -119,12 +120,12 @@ class OptimizationProblem(metaclass = ABCMeta):
if self.__mixed_integer:
nlpsol_options['discrete'] = discrete
solver = nlpsol('nlp', my_solver, nlp, nlpsol_options)
solver = ca.nlpsol('nlp', my_solver, nlp, nlpsol_options)
# Solve NLP
logger.info("Calling solver")
results = solver(x0 = x0, lbx = lbx, ubx = ubx, lbg = vertcat(*lbg), ubg = vertcat(*ubg))
results = solver(x0 = x0, lbx = lbx, ubx = ubx, lbg = ca.veccat(*lbg), ubg = ca.veccat(*ubg))
# Extract relevant stats
self.__objective_value = float(results['f'])
......@@ -166,7 +167,7 @@ class OptimizationProblem(metaclass = ABCMeta):
return success
def _check_bounds_control_input(self):
def __check_bounds_control_input(self):
# Checks if at the control inputs have bounds, log warning when a control input is not bounded.
bounds = self.bounds()
......@@ -440,7 +441,7 @@ class OptimizationProblem(metaclass = ABCMeta):
:returns: An :class:`MX` object representing F in the initial equation F = 0.
"""
return MX(0)
return ca.MX()
def seed(self, ensemble_member):
"""
......@@ -470,7 +471,7 @@ class OptimizationProblem(metaclass = ABCMeta):
return self.state_at('x', times[-1], ensemble_member)
"""
return MX(0)
return ca.MX()
def path_objective(self, ensemble_member):
"""
......@@ -489,7 +490,7 @@ class OptimizationProblem(metaclass = ABCMeta):
return self.state('x')
"""
return MX(0)
return ca.MX()
def constraints(self, ensemble_member):
"""
......
from datetime import timedelta
from casadi import MX
import casadi as ca
import numpy as np
import logging
import bisect
......@@ -7,10 +7,11 @@ import bisect
import rtctools.data.rtc as rtc
import rtctools.data.pi as pi
from rtctools._internal.alias_tools import AliasDict
from rtctools._internal.caching import cached
from .optimization_problem import OptimizationProblem
from .timeseries import Timeseries
from .alias_tools import AliasDict
from .caching import cached
logger = logging.getLogger("rtctools")
......@@ -431,7 +432,7 @@ class PIMixin(OptimizationProblem):
@property
def output_variables(self):
variables = super().output_variables
variables.extend([MX.sym(variable)
variables.extend([ca.MX.sym(variable)
for variable in self._output_timeseries])
return variables
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment