Skip to content

Commit

Permalink
First Cython3 changes; work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMeisrimelModelon committed Jan 17, 2024
1 parent 842ff21 commit 42b84e0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 17 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
-------------
- `FMI Library (at least 2.0.1) <https://github.com/modelon-community/fmi-library>`_
- `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
Expand All @@ -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 = ""
Expand Down Expand Up @@ -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)):

Expand Down
6 changes: 3 additions & 3 deletions src/common/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
7 changes: 7 additions & 0 deletions src/pyfmi/fmi.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 42b84e0

Please sign in to comment.