Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not passing FMUchecker - undefined symbol: _Py_NoneStruct #202

Open
jamargi2 opened this issue Dec 19, 2023 · 12 comments
Open

Not passing FMUchecker - undefined symbol: _Py_NoneStruct #202

jamargi2 opened this issue Dec 19, 2023 · 12 comments

Comments

@jamargi2
Copy link

Hello there, I have an issue on the FMU generated by the tool. The FMUchecker is giving back the following information:

[INFO][FMUCHK] FMI compliance checker 2.0.4 [FMILibrary: 2.0.3] build date: Nov  6 2017
[INFO][FMUCHK] Called with following options:
[INFO][FMUCHK] ./fmuCheck.linux64 ../Springmass.fmu
[INFO][FMUCHK] Will process FMU ../Springmass.fmu
[INFO][FMILIB] XML specifies FMI standard version 2.0
[INFO][FMUCHK] Model name: Springmass
[INFO][FMUCHK] Model GUID: d2136f02-9e7e-11ee-8498-a4bf016e1504
[INFO][FMUCHK] Model version: 
[INFO][FMUCHK] FMU kind: CoSimulation
[INFO][FMUCHK] The FMU contains:
0 constants
3 parameters
0 discrete variables
5 continuous variables
1 inputs
2 outputs
2 local variables
0 independent variables
0 calculated parameters
8 real variables
0 integer variables
0 enumeration variables
0 boolean variables
0 string variables

[INFO][FMUCHK] No input data provided. In case of simulation initial values from FMU will be used.
[INFO][FMUCHK] Printing output file header
"time","y","v"
[INFO][FMUCHK] Model identifier for CoSimulation: Springmass
[INFO][FMILIB] Loading 'linux64' binary with 'default' platform types
[FATAL][FMICAPI] Could not load the DLL: /tmp/fmucktmpOLwXUt/binaries/linux64/Springmass.so: undefined symbol: _Py_NoneStruct
[FATAL][FMUCHK] Could not create the DLL loading mechanism(C-API) for CoSimulation.
FMU check summary:
FMU reported:
	0 warning(s) and error(s)
Checker reported:
	0 Warning(s)
	2 Error(s)

The python code is pretty straightforward:


from pythonfmu import Fmi2Causality, Fmi2Variability, Fmi2Slave, Real


class Springmass(Fmi2Slave):

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

        self.mi_sei = 0.071e-3
        self.mi_cat = 0.123e-3               	
        self.mi_e = 0.016e-3
        self.mi_an = 0.191e-3
        self.DeltaAlpha = 0.0     
        self.DeltaAlpha_SEI = 0.1   
        self.DeltaAlpha_an = 0.1     
        self.DeltaAlpha_cat = 0.1     
        self.DeltaAlpha_e = 0.1   
        self.output = 0.0
        self.register_variable(Real("DeltaAlpha", causality=Fmi2Causality.local))   
        self.register_variable(Real("output", causality=Fmi2Causality.output))        
        self.register_variable(Real("mi_sei", causality=Fmi2Causality.parameter, variability=Fmi2Variability.tunable))           
        self.register_variable(Real("mi_cat", causality=Fmi2Causality.parameter, variability=Fmi2Variability.tunable))           
        self.register_variable(Real("mi_an", causality=Fmi2Causality.parameter, variability=Fmi2Variability.tunable))           
        self.register_variable(Real("mi_e", causality=Fmi2Causality.parameter, variability=Fmi2Variability.tunable))                     
        self.register_variable(Real("DeltaAlpha_SEI", causality=Fmi2Causality.input))
        self.register_variable(Real("DeltaAlpha_an", causality=Fmi2Causality.input))
        self.register_variable(Real("DeltaAlpha_cat", causality=Fmi2Causality.input))
        self.register_variable(Real("DeltaAlpha_e", causality=Fmi2Causality.input))

    def do_step(self, current_time, step_size):
    
        self.DeltaAlpha = self.mi_sei*self.DeltaAlpha_SEI + self.mi_cat*self.DeltaAlpha_cat + self.mi_an*self.DeltaAlpha_an + self.mi_e*self.DeltaAlpha_e
        self.output = self.DeltaAlpha
        return True
        
    Any idea? Thanks in advance!
@markaren
Copy link
Member

markaren commented Dec 19, 2023

I guess this is related to #187
v0.6.3 no longer links with Python, so the importing appliction would need to (FMUChecker does not).
You could downgrade to 0.6.2 or manually revert the CMake linking and build from source.

Basicially PythonFMU on Linux has the following issue:
(1) If it links with Python it (generally) does not work with applications that uses Python
(2) If it does not link with Python it does not work with applications that do not link with Python

Solution? Use Windows ^_^

@jamargi2
Copy link
Author

Okay, I'll try that way. To be honest I don't know much in detail what goes behind the code...

I suppose it will work. I am trying to CoSimulate with StarCCM, and it was giving me the very same error, so I suppose that going back to 0.6.2 will solve the issue.

Cannot go to windows as some of these simulations need to run on Linux machines.

Thanks!

@jamargi2
Copy link
Author

I have tried downgrading to 0.6.2, but now the checker just crashes.

Can you develop on how to build from source? I have seen a post in which you indicate to run "build_unix.sh" from the package folders, but not sure where the target ".py" should be located for that purpose.

Thanks again

@jamargi2 jamargi2 reopened this Dec 20, 2023
@jamargi2
Copy link
Author

Closed accidentally

@markaren
Copy link
Member

markaren commented Dec 20, 2023

pip install . from the root would install pythonfmu from source. This assumes that you have built the native sources using e.g. the build_unix.sh helper script first.

Then you would invoke pythonfmu as usual.

@jamargi2
Copy link
Author

Thanks once again.

It gives me the same issue as when using Python3.9, the tester and CCM+ crash with a segmentation fault. Not sure which is the issue. I assume not related with your tool...

[INFO][FMUCHK] FMI compliance checker 2.0.4 [FMILibrary: 2.0.3] build date: Nov  6 2017
[INFO][FMUCHK] Called with following options:
[INFO][FMUCHK] ./FMUChecker-2.0.4-linux64/fmuCheck.linux64 ./Springmass.fmu
[INFO][FMUCHK] Will process FMU ./Springmass.fmu
[INFO][FMILIB] XML specifies FMI standard version 2.0
[INFO][FMUCHK] Model name: Springmass
[INFO][FMUCHK] Model GUID: 3761daca-9f14-11ee-a432-7d23c11a127e
[INFO][FMUCHK] Model version: 
[INFO][FMUCHK] FMU kind: CoSimulation
[INFO][FMUCHK] The FMU contains:
0 constants
3 parameters
0 discrete variables
5 continuous variables
1 inputs
2 outputs
2 local variables
0 independent variables
0 calculated parameters
8 real variables
0 integer variables
0 enumeration variables
0 boolean variables
0 string variables

[INFO][FMUCHK] No input data provided. In case of simulation initial values from FMU will be used.
[INFO][FMUCHK] Printing output file header
"time","y","v"
[INFO][FMUCHK] Model identifier for CoSimulation: Springmass
[INFO][FMILIB] Loading 'linux64' binary with 'default' platform types
[INFO][FMUCHK] Version returned from CS FMU:   2.0
Violación de segmento (`core' generado)

@SADPR
Copy link

SADPR commented Jan 2, 2024

I have exactly the same issue and couldn't manage to solve it :/. Have you?

@SADPR
Copy link

SADPR commented Jan 2, 2024

I guess this is related to #187 v0.6.3 no longer links with Python, so the importing appliction would need to (FMUChecker does not). You could downgrade to 0.6.2 or manually revert the CMake linking and build from source.

Basicially PythonFMU on Linux has the following issue: (1) If it links with Python it (generally) does not work with applications that uses Python (2) If it does not link with Python it does not work with applications that do not link with Python

Solution? Use Windows ^_^

I have tried to use windows to build the FMU and still getting the same error:

[INFO][FMUCHK] FMI compliance checker Test [FMILibrary: Test] build date: Dec 29 2023
[INFO][FMUCHK] Called with following options:
[INFO][FMUCHK] /home/sares/FMUCheckerInstall/fmuCheck.linux64 SimpleModel_.fmu
[INFO][FMUCHK] Will process FMU SimpleModel_.fmu
[INFO][FMILIB] XML specifies FMI standard version 2.0
[INFO][FMUCHK] Model name: SimpleModel
[INFO][FMUCHK] Model GUID: 083a6cfd-a35c-11ee-a03a-08719027def8
[INFO][FMUCHK] Model version: 
[INFO][FMUCHK] FMU kind: CoSimulation
[INFO][FMUCHK] The FMU contains:
0 constants
0 parameters
0 discrete variables
2 continuous variables
1 inputs
1 outputs
0 local variables
0 independent variables
0 calculated parameters
2 real variables
0 integer variables
0 enumeration variables
0 boolean variables
0 string variables

[INFO][FMUCHK] No input data provided. In case of simulation initial values from FMU will be used.
[INFO][FMUCHK] Printing output file header
"time","y"
[INFO][FMUCHK] Model identifier for CoSimulation: SimpleModel
[INFO][FMILIB] Loading 'linux64' binary with 'default' platform types
[FATAL][FMICAPI] Could not load the DLL: /tmp/fmucktmp4vkB3x/binaries/linux64/SimpleModel.so: undefined symbol: _Py_NoneStruct
[FATAL][FMUCHK] Could not create the DLL loading mechanism(C-API) for CoSimulation.
FMU check summary:
FMU reported:
	0 warning(s) and error(s)
Checker reported:
	0 Warning(s)
	2 Error(s)
	2 Fatal error(s) occurred during processing

@SADPR
Copy link

SADPR commented Jan 2, 2024

I also tested downgrading to 0.6.2 and was obtaining segmentation fault.

@markaren
Copy link
Member

markaren commented Jan 2, 2024

I have tried to use windows to build the FMU and still getting the same error:

This would have zero effect. It's a runtime thing.

@jamargi2
Copy link
Author

jamargi2 commented Jan 2, 2024

I also tested downgrading to 0.6.2 and was obtaining segmentation fault.

Let me know if you manage to make it work through 0.6.2 to bypass the segmentation fault.

I've managed to use the tool, but with the version 0.5.0, and didn't crash.

@StephenSmith25
Copy link

I won't comment on the CCM error, but you can get it work with the latest version using

LD_PRELOAD=$CONDA_PREFIX/lib/libpython3.so ./fmuCheck.linux64 Springmass.fmu

Reflecting the fact that the explicit link has been removed. This should remove the undefined symbol error.

I'm not sure about the segmentation fault, but given this is just loading shared libraries you're at the mercy of the linker... You can always try the LD_DEBUG var https://bnikolic.co.uk/blog/linux-ld-debug.html.

Also you can check if it works with python tools (e.g. fmpy)

(this is for a conda & linux setup)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants