From 42b84e0b387c95939d68c48461c6d88e0ee89154 Mon Sep 17 00:00:00 2001 From: PeterMeisrimelModelon <92585725+PeterMeisrimelModelon@users.noreply.github.com> Date: Wed, 17 Jan 2024 13:35:28 +0100 Subject: [PATCH] First Cython3 changes; work in progress --- setup.cfg | 2 +- setup.py | 27 +++++++++++++++++---------- src/common/io.py | 6 +++--- src/pyfmi/fmi.pxd | 7 +++++++ 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/setup.cfg b/setup.cfg index 5457637e..0460464e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,6 +8,6 @@ install_requires = numpy >= 1.26.3 scipy >= 1.11.4 cython >= 3.0.7 - nose >= 1.3.7 + nose-py3 >= 1.6.3 matplotlib > 3 assimulo >= 3.5.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 2c7dbd59..d535c25a 100644 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ ------------- - `FMI Library (at least 2.0.1) `_ - `Python-headers (usually included on Windows, python-dev on Ubuntu)`_ -- `Python 3.7 or newer`_ +- `Python 3.11 or newer`_ - Python package dependencies are listed in file setup.cfg. Optional @@ -90,9 +90,10 @@ copy_args = sys.argv[1:] -if os.getenv("FMIL_HOME"): #Check for if there exists and environment variable that specifies FMIL - incdirs = os.path.join(os.getenv("FMIL_HOME"), 'include') - libdirs = os.path.join(os.getenv("FMIL_HOME"), 'lib') +fmil_home = os.getenv("FMIL_HOME") +if fmil_home: #Check for environment variable that specifies FMIL + incdirs = os.path.join(fmil_home, 'include') + libdirs = os.path.join(fmil_home, 'lib') else: incdirs = "" libdirs = "" @@ -214,29 +215,35 @@ def check_extensions(): incl_path = [".", "src", os.path.join("src", "pyfmi")] #FMI PYX ext_list += cythonize([os.path.join("src", "pyfmi", "fmi.pyx")], - include_path = incl_path) + include_path = incl_path, + compiler_directives={'language_level' : "3str"}) #FMI UTIL ext_list += cythonize([os.path.join("src", "pyfmi", "fmi_util.pyx")], - include_path = incl_path) + include_path = incl_path, + compiler_directives={'language_level' : "3str"}) #FMI Extended PYX ext_list += cythonize([os.path.join("src", "pyfmi", "fmi_extended.pyx")], - include_path = incl_path) + include_path = incl_path, + compiler_directives={'language_level' : "3str"}) #FMI Coupled PYX ext_list += cythonize([os.path.join("src", "pyfmi", "fmi_coupled.pyx")], - include_path = incl_path) + include_path = incl_path, + compiler_directives={'language_level' : "3str"}) #Simulation interface PYX ext_list += cythonize([os.path.join("src", "pyfmi", "simulation", "assimulo_interface.pyx")], - include_path = incl_path) + include_path = incl_path, + compiler_directives={'language_level' : "3str"}) #MASTER PYX compile_time_env = {'WITH_OPENMP': with_openmp} ext_list += cythonize([os.path.join("src", "pyfmi", "master.pyx")], include_path = incl_path, - compile_time_env=compile_time_env) + compile_time_env=compile_time_env, + compiler_directives={'language_level' : "3str"}) for i in range(len(ext_list)): diff --git a/src/common/io.py b/src/common/io.py index c0eb2538..736f786f 100644 --- a/src/common/io.py +++ b/src/common/io.py @@ -370,20 +370,20 @@ class ResultWriter(): Base class for writing results to file. """ - def write_header(): + def write_header(self): """ The header is intended to be used for writing general information about the model. This is intended to be called once. """ pass - def write_point(): + def write_point(self): """ This method does the writing of the actual result. """ pass - def write_finalize(): + def write_finalize(self): """ The finalize method can be used to for instance close the file. """ diff --git a/src/pyfmi/fmi.pxd b/src/pyfmi/fmi.pxd index 0296ff2c..3df66bc5 100644 --- a/src/pyfmi/fmi.pxd +++ b/src/pyfmi/fmi.pxd @@ -162,6 +162,7 @@ cdef class FMUModelME1(FMUModelBase): cdef public object _preinit_nominal_continuous_states cdef class __ForTestingFMUModelME1(FMUModelME1): + cdef int __get_nominal_continuous_states(self, FMIL.fmi1_real_t* xnominal, size_t nx) cpdef set_allocated_fmu(self, int value) cdef class FMUModelBase2(ModelBase): @@ -275,4 +276,10 @@ cdef class WorkerClass2: cpdef verify_dimensions(self, int dim) cdef class __ForTestingFMUModelME2(FMUModelME2): + cdef int __get_real(self, FMIL.fmi2_value_reference_t* vrefs, size_t size, FMIL.fmi2_real_t* values) + cdef int __set_real(self, FMIL.fmi2_value_reference_t* vrefs, FMIL.fmi2_real_t* values, size_t size) + cdef int _get_real(self, FMIL.fmi2_value_reference_t[:] valueref, size_t size, FMIL.fmi2_real_t[:] values) + cdef int _get_integer(self, FMIL.fmi2_value_reference_t[:] valueref, size_t size, FMIL.fmi2_integer_t[:] values) + cdef int _get_boolean(self, FMIL.fmi2_value_reference_t[:] valueref, size_t size, FMIL.fmi2_real_t[:] values) + cdef int __get_nominal_continuous_states(self, FMIL.fmi2_real_t* xnominal, size_t nx) cpdef set_initialized_fmu(self, int value)