Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
2

Communicate end of RunPeriod to Python Plugin

asked 2021-12-22 09:18:29 -0600

spqr's avatar

Is there a mechanism in the Python Plugin API to communicate the impending end of a RunPeriod to a Python Plugin? I have checked the various Python classes (datatransfer.py, plugin.py, state.py, etc), and I don't see an obvious way to do this. My specific use case is signaling to a Python Plugin the end of a RunPeriod / simluation so that it can dump a log file at the end of a simulation. If I continuously log data at each time-step, this nearly doubles the simulation time. It would be much more efficient to write this log file to disk a single time at the end of the simulation.

I could see other use cases where knowing that a RunPeriod is in it's last timestep would be helpful for a plugin developer, especially as plugins become more complex and more than just simple ERL script replacements.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-12-22 14:53:59 -0600

Do you need to use the the API in Plugin Mode? Saving a log file at the end of the simulation is easy when using the Python API in Library mode, because you simply put the log command after the simulation command. For example, if you have one function that runs the simulation (run_simulation) and another to save the log (save_ep_history), you can simply call the functions in that order:

run_simulation(...)

save_ep_history(...)

This way, each time you execute the script, it runs the simulations once and saves the log once after simulation completes. I'm not sure if/how you could do this using the API in Plugin Mode.

edit flag offensive delete link more

Comments

I'm not currently using the Plugin in API mode, but maybe this would be a reason to re-structure my workflow. At least now I know this is not currently possible with a Python Plugin.

An alternative I'm currently employing is to read the source IDF with Eppy from within the plugin class, and check if the simulation date and time match the end of a run-period, and dump the data file then.

spqr's avatar spqr  ( 2021-12-25 15:15:07 -0600 )edit
1

It's not impossible in Plugin mode, I just think it would be easier in Library mode.

Another way to do it in Plugin mode, instead of using Eppy, is to make a simple EMS program that utilizes the built-in Erl variables (Month, Day, Hour, DayofYear, etc) to indicate to your Plugin script whether to save the log file (e.g. when DayOfYear == 365 && Hour == 23).

ericmartinpe's avatar ericmartinpe  ( 2021-12-27 21:05:13 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

3 followers

Stats

Asked: 2021-12-22 09:18:29 -0600

Seen: 224 times

Last updated: Dec 22 '21