Skip to content

Commit

Permalink
work in progress; fixing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMeisrimelModelon committed Jan 19, 2024
1 parent 2d92964 commit ea01cd4
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/common/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _exec_algorithm(self, module, algorithm, options):
Exception if algorithm is not a subclass of
common.algorithm_drivers.AlgorithmBase.
"""
from .algorithm_drivers import AlgorithmBase
from pyfmi.algorithm_drivers import AlgorithmBase

if isinstance(algorithm, str):
module = __import__(module, globals(), locals(), [algorithm], 0)
Expand Down Expand Up @@ -182,7 +182,7 @@ def _exec_simulate_algorithm(self,
Exception if algorithm is not a subclass of
common.algorithm_drivers.AlgorithmBase.
"""
from .algorithm_drivers import AlgorithmBase
from pyfmi.algorithm_drivers import AlgorithmBase

if isinstance(algorithm, str):
module = __import__(module, globals(), locals(), [algorithm], 0)
Expand Down
4 changes: 2 additions & 2 deletions src/common/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
The log analysis toolkit.
"""

from .parser import parse_xml_log, parse_xml_log, extract_xml_log, parse_fmu_xml_log
from .prettyprinter import prettyprint_to_file
from pyfmi.common.log.parser import parse_xml_log, parse_xml_log, extract_xml_log, parse_fmu_xml_log
from pyfmi.common.log.prettyprinter import prettyprint_to_file

__all__=['parser','tree','prettyprinter']
2 changes: 1 addition & 1 deletion src/common/log/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import os
import numpy as np
from distutils.util import strtobool
from .tree import *
from pyfmi.common.log.tree import *
from pyfmi.fmi_util import python3_flag
from pyfmi.fmi import FMUException

Expand Down
2 changes: 1 addition & 1 deletion src/common/log/prettyprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

from numpy import ndarray
from .tree import *
from pyfmi.common.log.tree import *

def prettyprint(write, node):
"""Prettyprint a log node to the write callback write."""
Expand Down
10 changes: 5 additions & 5 deletions src/pyfmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
__all__ = ['fmi_algorithm_drivers', 'examples', 'fmi', 'common']

#Import the model class allowing for users to type e.g.,: from pyfmi import FMUModelME1
from .fmi import load_fmu, FMUModelME1, FMUModelME2
from .fmi import FMUModelCS1, FMUModelCS2
from .fmi_coupled import CoupledFMUModelME2
from .master import Master
from .fmi_extended import FMUModelME1Extended
from pyfmi.fmi import load_fmu, FMUModelME1, FMUModelME2
from pyfmi.fmi import FMUModelCS1, FMUModelCS2
from pyfmi.fmi_coupled import CoupledFMUModelME2
from pyfmi.master import Master
from pyfmi.fmi_extended import FMUModelME1Extended
import numpy as N
import os.path
import sys
Expand Down
3 changes: 3 additions & 0 deletions src/pyfmi/fmi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION

"""
Module containing the FMI interface Python wrappers.
"""
Expand Down
4 changes: 3 additions & 1 deletion src/pyfmi/fmi_coupled.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION

import pyfmi.fmi as fmi
from fmi cimport FMUModelME2
from pyfmi.fmi cimport FMUModelME2
cimport fmil_import as FMIL

from pyfmi.fmi_util import cpr_seed, enable_caching, Graph
Expand Down
9 changes: 6 additions & 3 deletions src/pyfmi/fmi_extended.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION

"""
Module containing the FMI interface Python wrappers.
"""
Expand All @@ -30,9 +33,9 @@ cimport numpy as N
N.import_array()

cimport fmil_import as FMIL
from fmi cimport FMUModelME1
from fmi import FMUException
from fmi import FMI_OK, FMI_DEFAULT_LOG_LEVEL, FMI_ME
from pyfmi.fmi cimport FMUModelME1
from pyfmi.fmi import FMUException
from pyfmi.fmi import FMI_OK, FMI_DEFAULT_LOG_LEVEL, FMI_ME


cdef class FMUModelME1Extended(FMUModelME1):
Expand Down
5 changes: 4 additions & 1 deletion src/pyfmi/fmi_util.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION

"""
Module containing the FMI interface Python wrappers.
"""
Expand All @@ -34,7 +37,7 @@ from pyfmi.fmi cimport FMUModelME2, FMUModelBase

import functools
import marshal
import fmi
import pyfmi.fmi as fmi
import sys

python3_flag = True if sys.hexversion > 0x03000000 else False
Expand Down
26 changes: 14 additions & 12 deletions src/pyfmi/master.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION

import pyfmi.fmi as fmi
from pyfmi.common.algorithm_drivers import OptionBase, InvalidAlgorithmOptionException, AssimuloSimResult
from pyfmi.common.io import ResultDymolaTextual, ResultHandlerFile, ResultHandlerDummy, ResultHandlerBinaryFile, ResultDymolaBinary
Expand All @@ -37,10 +39,10 @@ import scipy.sparse.linalg as splin
import scipy.optimize as sopt
import scipy.version

from fmi cimport FMUModelCS2
from pyfmi.fmi cimport FMUModelCS2
from cpython cimport bool
cimport fmil_import as FMIL
from fmi_util import Graph
from pyfmi.fmi_util import Graph
from cython.parallel import prange, parallel

IF WITH_OPENMP:
Expand Down Expand Up @@ -373,7 +375,7 @@ cdef class Master:
cdef public dict statistics, models_id_mapping
cdef public object opts
cdef public object models_dict, L, L_discrete
cdef public object I
cdef public object _ident_matrix
cdef public object y_prev, yd_prev, input_traj
cdef public object DL_prev
cdef public int algebraic_loops, storing_fmu_state
Expand Down Expand Up @@ -466,7 +468,7 @@ cdef class Master:

self.y_prev = None
self.input_traj = None
self.I = sp.eye(self._len_inputs, self._len_outputs, format="csr") #y = Cx + Du , u = Ly -> DLy DL[inputsXoutputs]
self._ident_matrix = sp.eye(self._len_inputs, self._len_outputs, format="csr") #y = Cx + Du , u = Ly -> DLy DL[inputsXoutputs]

self._error_data = {"time":[], "error":[], "step-size":[], "rejected":[]}

Expand Down Expand Up @@ -853,7 +855,7 @@ cdef class Master:
else:
return C.dot(xd)+D.dot(ud)
else: #First step
return splin.spsolve((self.I-D.dot(self.L)),C.dot(xd)).reshape((-1,1))
return splin.spsolve((self._ident_matrix-D.dot(self.L)),C.dot(xd)).reshape((-1,1))

y_last = self.get_last_y()
if y_last is not None:
Expand Down Expand Up @@ -898,7 +900,7 @@ cdef class Master:
if ud is not None and udd is not None:
return C.dot(A.dot(xd))+C.dot(B.dot(ud+self.get_current_step_size()*udd))+D.dot(udd)
else: #First step
return splin.spsolve((self.I-D.dot(self.L)),C.dot(A.dot(xd)+B.dot(self.L.dot(yd_cur)))).reshape((-1,1))
return splin.spsolve((self._ident_matrix-D.dot(self.L)),C.dot(A.dot(xd)+B.dot(self.L.dot(yd_cur)))).reshape((-1,1))

yd_last = self.get_last_yd()
if yd_last is not None:
Expand Down Expand Up @@ -965,7 +967,7 @@ cdef class Master:
z = yd - D.dot(uhat)
yd = splin.spsolve((self.I-DL),z).reshape((-1,1))
yd = splin.spsolve((self._ident_matrix-DL),z).reshape((-1,1))
"""
return ydd

Expand All @@ -980,7 +982,7 @@ cdef class Master:

z = yd - D.dot(uhat)

yd = splin.spsolve((self.I-DL),z).reshape((-1,1))
yd = splin.spsolve((self._ident_matrix-DL),z).reshape((-1,1))

return yd

Expand Down Expand Up @@ -1016,7 +1018,7 @@ cdef class Master:
z = y - DL.dot(y_prev)
#z = y - matvec(DL, y_prev.ravel())

y = splin.spsolve((self.I-DL),z).reshape((-1,1))
y = splin.spsolve((self._ident_matrix-DL),z).reshape((-1,1))
#y = splin.lsqr((sp.eye(*DL.shape)-DL),z)[0].reshape((-1,1))

elif self.algebraic_loops and self.support_directional_derivatives:
Expand Down Expand Up @@ -1339,15 +1341,15 @@ cdef class Master:
C = self.compute_global_C()
if C is not None:
C = C.todense()
I = np.eye(*DL.shape)
LIDLC = self.L.dot(lin.solve(I-DL,C))
_ident_matrix = np.eye(*DL.shape)
LIDLC = self.L.dot(lin.solve(_ident_matrix-DL,C))
print(" , rho(L(I-DL)^(-1)C)=%s"%(str(numpy.linalg.eig(LIDLC)[0])))
A = self.compute_global_A()
B = self.compute_global_B()
if C is not None and A is not None and B is not None:
A = A.todense(); B = B.todense()
eAH = slin.expm(A*step_size)
K1 = lin.solve(I-DL,C)
K1 = lin.solve(_ident_matrix-DL,C)
K2 = lin.solve(A,(eAH-np.eye(*eAH.shape)).dot(B.dot(self.L.todense())))
R1 = np.hstack((eAH, K1))
R2 = np.hstack((K2.dot(eAH), K2.dot(K1)))
Expand Down
2 changes: 1 addition & 1 deletion src/pyfmi/simulation/assimulo_interface.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import numpy as N
cimport numpy as N
import logging

from pyfmi.fmi cimport FMUModelME2

Expand All @@ -33,7 +34,6 @@ if assimulo_present:
from assimulo.problem import Implicit_Problem
from assimulo.problem import Explicit_Problem
from assimulo.problem cimport cExplicit_Problem
from assimulo.exception import *
else:
class Implicit_Problem:
pass
Expand Down
4 changes: 3 additions & 1 deletion src/pyfmi/simulation/assimulo_interface.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION

"""
This file contains code for mapping FMUs to the Problem specifications
required by Assimulo.
Expand Down Expand Up @@ -54,7 +56,7 @@ if assimulo_present:
from assimulo.problem import Implicit_Problem
from assimulo.problem import Explicit_Problem
from assimulo.problem cimport cExplicit_Problem
from assimulo.exception import *
from assimulo.exception import AssimuloRecoverableError, TerminateSimulation
else:
class Implicit_Problem:
pass
Expand Down

0 comments on commit ea01cd4

Please sign in to comment.