NTNU-IHB / PythonFMU

A lightweight framework that enables the packaging of Python3.x code as co-simulation FMUs
MIT License
136 stars 38 forks source link

Error after generating FMU #194

Open levanthanh3005 opened 11 months ago

levanthanh3005 commented 11 months ago

Hi, In my python code, I has "import ctype", I use ubuntu20.04, python3.9, I run fmu file with openmcx It can generate fmu file, but when I test the file, it shows:

Current thread 0x00007fe341b77740 (most recent call first):
<no Python frame>
ERROR: The element FMU caused an unrecoverable error. Shutting down.

Any ideas to fix it, Regards, T

markaren commented 11 months ago

I really can't say.. Perhaps the script can't find the shared library?

levanthanh3005 commented 11 months ago

My code is super simple, I just import ctype and its crash. I test it with fmpy but with openmcx, it crashes, I have no idea why. I think it can find the library because it can work with fmpy, but somehow, with other systems, ctype has problem. Do you know anyway to debug it and fix it. Or is there anyway to pack all of the shared library so I can bring it to other environment

from pythonfmu import Fmi2Causality, Fmi2Slave, Boolean, Integer, Real, String

import ctypes

class PythonSlave(Fmi2Slave):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.intOut = 1
        self.realOut = 3.0
        self.realIn = 3.0
        self.booleanVariable = True
        self.stringVariable = "Hello World!"

        self.register_variable(Real("realIn", causality=Fmi2Causality.input))
        self.register_variable(Real("realOut", causality=Fmi2Causality.output))        

    def do_step(self, current_time, step_size):
        return True
markaren commented 11 months ago

So it works with FMPy? Are you getting the same issue using say Ecos, which is also a C++ framework?

levanthanh3005 commented 11 months ago

Hi @markaren Thank you a lot for your support, also in the Ecos repo. image The problem is still the same, as you can see in the image. If I remove import ctypes it can work, but I need it, could you try from your side, Regards, T

markaren commented 11 months ago

Sorry, it would be too time consuming for me to look into this at the moment.