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

FMUs that contain Spawn are not self contained #2054

Closed
kbenne opened this issue Jul 29, 2020 · 16 comments · Fixed by #2447
Closed

FMUs that contain Spawn are not self contained #2054

kbenne opened this issue Jul 29, 2020 · 16 comments · Fixed by #2447
Assignees
Labels
spawn Development for Spawn of EnergyPlus

Comments

@kbenne
Copy link
Contributor

kbenne commented Jul 29, 2020

This is in referenced to any "parent" FMU that contains a Spawn model, not about the EnergyPlus FMU. If you ask the Modelica compiler to compile a model to FMU, any resources consumed by the model using the Modelica function Modelica.Utilities.Files.loadResource will be copied into the resulting FMU's resources directory. For example idf files are loaded using LoadResource

idfName = Modelica.Utilities.Files.loadResource(
.

The binary requirements of Spawn including epfmi.so and spawn(exe) are not however loaded as resources. Instead the buildingsLibraryRoot is passed to C extensions and the paths into the MBL are determined from there.

input String buildingsLibraryRoot "Root directory of the Buildings library (used to find the spawn executable)";
The result is that any FMU using Spawn will have attachments to the MBL path that is outside of the context of the FMU.

It would be better to identify epfmi and spawn using loadResource so that 1. The Modelica compiler will copy the resource if you ask for an FMU 2. The correct path for these resources will be identified at simulation time.

@kbenne kbenne added the spawn Development for Spawn of EnergyPlus label Jul 29, 2020
@kbenne kbenne self-assigned this Jul 29, 2020
@kbenne
Copy link
Contributor Author

kbenne commented Jul 29, 2020

@mwetter

@mwetter
Copy link
Member

mwetter commented Jul 29, 2020

Will be added for BOPTEST support.

mwetter added a commit that referenced this issue Jul 29, 2020
@mwetter
Copy link
Member

mwetter commented Jul 29, 2020

This is addressed through e410c6f

The parameter Boolean generatePortableFMU = false can be used to exclude/include binaries. By default they are excluded because with OPTIMICA, including them adds on Linux about 5 seconds to the translation time.

@mwetter mwetter closed this as completed Jul 29, 2020
@kbenne
Copy link
Contributor Author

kbenne commented Jul 29, 2020

Nice. I like the option to turn this off and on. This looks like it will get the resources into the FMU, but I think there is code in the C extension that needs to be updated also. I believe the argument to the C function(s) is path to MBL, not the exe/so paths.

@mwetter
Copy link
Member

mwetter commented Jul 29, 2020

That's correct and need to be fixed. OPTIMICA generates

  inflating: modelDescription.xml    
  inflating: binaries/linux64/Buildings_ThermalZones_EnergyPlus_Validation_ThermalZone_OneZone.so  
  inflating: binaries/linux64/libfmilib_shared.so  
  inflating: resources/2/libepfmi-9.0.1.so  
  inflating: resources/0/Zones1.fmu  
  inflating: resources/3/libfmilib_shared.so  
  inflating: resources/1/spawn

Let me see why there is a number after the resources and how I can know what the number is, other than scanning the file system for resources/spawn and resources/*/spawn. (Modelon 2020072939000511)

@mwetter
Copy link
Member

mwetter commented Nov 4, 2020

To reproduce:

  1. generate FMU with OPTIMICA and Dymola.
  2. run from PyFMI in a way that it does not see the Buildings library.

Kyle has some prototype code with fixes.

@mwetter mwetter reopened this Nov 4, 2020
@kbenne
Copy link
Contributor Author

kbenne commented Nov 18, 2020

Here is what I have so far https://github.com/lbl-srg/modelica-buildings/tree/issue2054_self_contained_spawn. It needs a fair bit of work before considering for merge. At minimum it is hard coded to linux, and that needs to be resolved. I think there are other issues too, but I'll need to dive back into this to remind myself because it has been a while. Gregor's team at CU has reported it working on Dymola.

kbenne added a commit to Helarga/modelica-buildings that referenced this issue Feb 26, 2021
kbenne added a commit to Helarga/modelica-buildings that referenced this issue Feb 26, 2021
kbenne added a commit to Helarga/modelica-buildings that referenced this issue Feb 26, 2021
@mwetter mwetter self-assigned this Aug 19, 2021
mwetter added a commit that referenced this issue Aug 19, 2021
@mwetter
Copy link
Member

mwetter commented Aug 19, 2021

The development branch is issue2443_spawn_portable

@lambtt
Copy link

lambtt commented Feb 9, 2022

This is addressed through e410c6f

The parameter Boolean generatePortableFMU = false can be used to exclude/include binaries. By default they are excluded because with OPTIMICA, including them adds on Linux about 5 seconds to the translation time.

May I ask if the Boolean variable is True, will it add some time to the simulation time of the FMU which include Spawn?
Thanks a lot.

@mwetter
Copy link
Member

mwetter commented Feb 9, 2022

The binaries are included by default and there is no more parameter generatePortableFMU. This has been removed in #2759.

I didn't see a noticeable overhead for including the binaries, so we prefer to keep them in rather than providing many options that may at the end not work across the various Modelica and FMI simulation environments.

@lambtt
Copy link

lambtt commented Feb 10, 2022

The binaries are included by default and there is no more parameter generatePortableFMU. This has been removed in #2759.

I didn't see a noticeable overhead for including the binaries, so we prefer to keep them in rather than providing many options that may at the end not work across the various Modelica and FMI simulation environments.

Many thanks for that!

@vincavitabile97
Copy link

Hi all,
I'm Vincenzo Avitabile a student of mechanical engineering for energy and environment from University of Naples Federico II. I'm working about a project that involved Spawn of Energy plus. I have a question for you... Do you know if it's possible to export a readble FMU from Dymola containing Spawn model? When I test FMU with pyFMI I obtain this error "C:/Users/AVITABVi/AppData/Local/Temp/JModelica.org/jm_tmph2v32kf2/resources/Resources/bin/spawn-win64/bin/spawn.exe' does not exist: 'No such file or directory."
Every time I launch pyFMI is generated a folder like jm_tmph2v32kf2 (changing name everytime) but inside effectively there isn’t the spawn.exe.
Do you also have the same problem? How did you solve?
I hope you can help me.
Thanks for your availability

Kind regards,
Vincenzo Avitabile
@mwetter @kbenne

@vincavitabile97
Copy link

Generating an FMU in Dymola 2021x of "Buildings.ThermalZones.EnergyPlus.Examples.SingleFamilyHouse.Unconditioned" and testing it with pyFMI I obtain the same error (spawn.exe ' does not exist: 'No such file or directory."), below:
image

So, is it possible to generate an FMU containing a spawn thermal zone?
@mwetter @kbenne

@mwetter
Copy link
Member

mwetter commented Feb 22, 2022

@vincavitabile97: can you try to put the directory that contains your spawn.exe on the system PATH (or add a new system environment variable SPAWNPATH) and try with the master branch of the Buildings library? This should be fixed in the next release. See also Buildings.ThermalZones.EnergyPlus.UsersGuide.InvokingEnergyPlus

@vincavitabile97
Copy link

Hi @mwetter,
Thanks for the information. I try all the passages suggested before but I still get an error :
image

Kind regards,
Vincenzo

@mwetter
Copy link
Member

mwetter commented Feb 24, 2022

@vincavitabile97 : Are you using the master branch of the Buildings library? Searching on SPAWNPATH is not implemented for the 8.0 or 8.1 release. It is implemented on the master branch and will be part of the next release (9.0.0).

If you use the master, can you set
logLevel=Buildings.ThermalZones.EnergyPlus.Types.LogLevels.Verbose in the building instance. Then you should see in the log file where the spawn executable is searched. (The debug message will be improved through #2901).

Searching the PATH works on Linux and Windows. I tested it by creating

modelica-buildings$ tree test
test
└── spawn-win64
    ├── bin
    │   ├── epfmi.dll
    │   ├── spawn-0.3.0-d6204d26f6.exe
    │   └── VCRUNTIME140.dll
    ├── etc
    │   └── Energy+.idd
    ├── lib
    │   └── epfmi.lib
    └── README.md

deleting these files from the local installation, putting e:\modelica-buildings\test\spawn-win64\bin on my Windows PATH, restarting Dymola and simulating a model that uses the EnergyPlus coupling.

Executing the version that is packaged with the fmu (in Buildings 8.1) won't work in general as some if not all tool remove the executable flag. This is one reason why for the next release, we search on PATH and SPAWNPATH if it can't be found at the default location.

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

Successfully merging a pull request may close this issue.

4 participants