Skip to content

Regression from v0.6.5 to v0.6.7 #238

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

Open
elac-safran opened this issue May 5, 2025 · 15 comments
Open

Regression from v0.6.5 to v0.6.7 #238

elac-safran opened this issue May 5, 2025 · 15 comments

Comments

@elac-safran
Copy link

elac-safran commented May 5, 2025

Hello. I am experiencing a crash from version 0.6.5 to version 0.6.7 in a piece of code that has been running seamlessly for years.
Technically, the error is raised by fmilib through pyfmi, but I have tried with different versions of this library, and the only trigger seems to be pythonfmu v0.6.7.

The code (a unit test) goes something like:

fmu_file: Path = to_fmu(
    vector_syst,
    dest=tmp_path,
    inputs=[...],   # irrelevant
    outputs=[...],  # irrelevant
)

assert fmu_file.is_file()  # OK

# Load the FMU
model = pyfmi.load_fmu(fmu_file, log_level=4)   # crashes with v 0.6.7

Function to_fmu is on my end, and uses FmuBuilder.build_FMU.

Log with v0.6.5:

FMIL: module = FMI2XML, log level = 4: [Line:26] Detected during parsing:
FMIL: module = FMI2XML, log level = 2: Only Real variables can have variability='continuous'
FMIL: module = FMI2XML, log level = 4: [Line:32] Detected during parsing:
FMIL: module = FMI2XML, log level = 2: Only Real variables can have variability='continuous'
FMIL: module = FMIXML, log level = 4: Could not find or open terminalsAndIcons.xml: 'C:\Users\XXX\AppData\Local\Temp\JModelica.org\jm_tmp8ba7rtu3/terminalsAndIcons\terminalsAndIcons.xml'. Continuing.
FMIL: module = FMILIB, log level = 4: Loading 'win64' binary with 'default' platform types

Log with v0.6.7:

FMIL: module = FMI2XML, log level = 4: [Line:26] Detected during parsing:
FMIL: module = FMI2XML, log level = 2: Only Real variables can have variability='continuous'
FMIL: module = FMI2XML, log level = 4: [Line:32] Detected during parsing:
FMIL: module = FMI2XML, log level = 2: Only Real variables can have variability='continuous'
FMIL: module = FMIXML, log level = 4: Could not find or open terminalsAndIcons.xml: 'C:\Users\XXX\AppData\Local\Temp\JModelica.org\jm_tmpneay2csd/terminalsAndIcons\terminalsAndIcons.xml'. Continuing.
FMIL: module = FMILIB, log level = 4: Loading 'win64' binary with 'default' platform types
FMIL: module = Model, log level = 1: [][FMU status:Fatal] Fatal py exception encountered: [initialize] PyObject_Call
FileNotFoundError(2, 'No such file or directory')

Do you have any idea as to what could trigger the FileNotFoundError in the second case?

@elac-safran elac-safran changed the title Regression from v0.6.5 to 0.6.7 Regression from v0.6.5 to v0.6.7 May 5, 2025
@markaren
Copy link
Member

markaren commented May 5, 2025

As far as I can tell, the only runtime change to PythonFMU between these versions is #220 . I guess this might affect calling executables etc. which you might do in your application.

@markaren
Copy link
Member

markaren commented May 5, 2025

Can you compare

import sys
print("sys.executable:", sys.executable)
print("sys.path:", sys.path)

between versions?

@markaren
Copy link
Member

markaren commented May 5, 2025

On second thought, this codepath should not run when loaded in pyfmi (as the Python interpreter is already running).

@elac-safran
Copy link
Author

Hello @markaren. Thank you very much for your reply. Did you mean #225, rather than #220?
I have only skimmed through this commit, and will look into it more seriously.

@markaren
Copy link
Member

markaren commented May 6, 2025

I was originally thinking 220, but I don't think that one is the issue at this point.

@elac-safran can you provide more insights into what the model does as part of running the constructor? Access to files, running executables etc.

@Jorgelmh any insights?

@elac-safran
Copy link
Author

Maybe @fcollonval can help, too, as he participated in both projects.

@elac-safran
Copy link
Author

elac-safran commented May 6, 2025

Here is the fmu file (renamed as a zip file) generated by v0.6.7:

VectorSystFMU.zip

@markaren
Copy link
Member

markaren commented May 6, 2025

I got this error:

fmi2Fatal Fatal py exception encountered: [ctor] findClass AssertionError('SRE module mismatch')

I will look more into it.

@elac-safran
Copy link
Author

Thank you for the update. Some module name I do not provide in my code?

@markaren
Copy link
Member

markaren commented May 6, 2025

Seems like a separate issue for now.

@markaren
Copy link
Member

markaren commented May 6, 2025

I am able to reproduce the issue with v0.6.6. 0.6.5 works fine.

@markaren
Copy link
Member

markaren commented May 6, 2025

Sorry, I was to quick. What I have found is that the model do in fact work the same way with these versions. However, the model fails when it is reloaded (also with older versions) within the same process (after it as successfully been run). I used FMPy for this.

I also ran the 0.6.7 model with ecos (C++) successfully.

Reloading worked with one of the samples in /examples.

The separate issue I encountered is that I have issues running models with Python 3.12. I'm on Windows. I used 3.10 for the successful tests.

@elac-safran
Copy link
Author

Hmm, that suggests I have room for improvement on my side; thank you very much for your time and your feedback.

Just to be sure I understand: the model I sent you works for all versions of pythonfmu, but fails when reloaded; is that correct?

@markaren
Copy link
Member

markaren commented May 6, 2025

Basically, yes. I tested with 0.6.3, 0.6.5, 0.6.6, 0.6.7. And as far as I can tell (Windows, Python 3.10). It behaves the same. FMpy is the only tool I tried reloading, and that is were it fails with the error you previously showed. I tested multiple instances of the model with ecospy and that went fine. However, the temp dir could not be deleted, which suggests a dll is still in use after teardown.

@elac-safran
Copy link
Author

Thank you for this clarification. The way things go south in my code is still mysterious to me, but your tests really help. I definitely have homework to do!

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

2 participants