-
Notifications
You must be signed in to change notification settings - Fork 40
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
Memory handling on an infinite loop simulation #195
Comments
Hi @pedro-ricardo, thank you for reaching out about your question. I have a couple of follow-up questions to understand your situation better.
|
Thanks for the quick response...
No, the FMUs don't even have an algorithm part, it's just
All are CS FMUs
Yes, I do the following in the loop: step = 0.5
std_opt = master.simulate_options()
std_opt['step_size'] = 0.01
std_opt['result_handling'] = "none"
if (current_time>0.0):
std_opt['initialize'] = False
master.simulate( start_time=current_time, final_time=current_time+step, options=std_opt )
current_time = current_time+step
time.sleep(step)
1000 seconds in real time, but it does happen faster if I fix the sleep step to 0.5s and enlarge the
I don't see any file getting large ... but I do set the same log file for all models with: |
Hi @pedro-ricardo, is |
The I'll ommit the |
The memory still explodes and now I also have a bunch of |
@pedro-ricardo I wonder if the memory goes up because when you do |
Hello there @modelonrobinandersson, About the test you asked for, I've added an 11 iterations loop with 100s in each step (that will get me close to 1000s where the problem occurs) without the sleep and waited for and input after the loop finished. As you can see, the memory keeps high after the loop ended. That time span after the loop ended is 4 minutes. |
@pedro-ricardo can you share more of the code snippet you shared earlier just so we can understand the situation fully, it would be nice to find the issue to avoid more people running into this. |
Ok, I've built a simple debug function, tested it and got the same behaviour. Here it is: # --------------------
@staticmethod
def debug_start(models:dict, connections:list, initial_params:dict):
''' A simplified execution loop for debugging the Master algorithm\n
* `models`: Dictionary with model name as key and the result of `pyfmi.load_fmu`
functions as value. Example:\n
```
{'model_name1':<pyfmi.fmi.FMUModelCS2 object at 0x159dba0>,
'model_name2': <pyfmi.fmi.FMUModelCS2 object at 0x159c650>}
```
* `connections`: List of connection dictionaries in the format:
`{'from':(model_obj,variable_name),'to':(model_obj,variable_name)}`. Example:\n
```
[ {'from': (<pyfmi.fmi.FMUModelCS2 object at 0x159dba0>, 'Out1'),
'to': (<pyfmi.fmi.FMUModelCS2 object at 0x15c16e0>, 'Inp1')},
{'from': (<pyfmi.fmi.FMUModelCS2 object at 0x159dba0>, 'Out2'),
'to': (<pyfmi.fmi.FMUModelCS2 object at 0x15c16e0>, 'Inp2')} ]
```
* `initial_params`: Dictionary with model names the initial values
for model inputs and parameters. Example:\n
```
{'model_name1':{'Par1': 500, 'Inp1': 530},
'model_name2': {'Par1': 50, 'Par2': 40} }
```
'''
# Go though all model objects and set the initial parameters
for m_name in models.keys():
for prop, val in initial_params[m_name].items():
models[m_name].set(prop,val)
# Parse models and connections to pyfmi Master format.
model_list = list(models.values())
connection_list = [c['from']<
8000
span class="pl-c1">+c['to'] for c in connections]
# Build master algorithm
master = pyfmi.Master(model_list, connection_list)
# Set initial configurations
current_time = 0.0
std_opt = master.simulate_options()
std_opt['step_size'] = 0.01
std_opt['result_handling'] = "none"
# Simulate
for i in range(11):
if (i>0):
# Disable initialization after first iteration
std_opt['initialize'] = False
# Call master simulation
master.simulate( start_time=current_time,
final_time=current_time+100, options=std_opt)
# Update simulation Time
current_time = current_time+100
# Wait after finish
input('Press any Key to end ....')
# -------------------- |
I'm not using the |
Isn't it possible that this This coupled simulation I'm doing is pretty big and the |
@pedro-ricardo thank you a lot. Sorry for the questions but I have a couple of suspicions:
Let me know your findings. |
Comparing the subsequent debug files with 34c34
< 'result': <pyfmi.common.io.ResultHandlerDummy object at 0x7f80c8d3bee0>}),
---
> 'result': <pyfmi.common.io.ResultHandlerDummy object at 0x7f80c8d3bdf0>}),
68c68
< 'result': <pyfmi.common.io.ResultHandlerDummy object at 0x7f80c8d3bf40>}),
---
> 'result': <pyfmi.common.io.ResultHandlerDummy object at 0x7f80c8d3bee0>}),
And so on for all other models ... This change occurs for all iterations. |
@pedro-ricardo thank you. I will see if I can reproduce this on my end in order to debug it further. |
Let me know if you can reproduce it. |
@modelonrobinandersson |
Hi @pedro-ricardo, sorry I have not had time yet. I hopefully will get some time later this week. |
Hi @pedro-ricardo This is what I tried: from pyfmi import Master, load_fmu
fmu1 = load_fmu('LinearStability_SubSystem1.fmu')
fmu2 = load_fmu('LinearStability_SubSystem2.fmu')
models = [fmu1, fmu2]
connections = [(fmu1, "y1", fmu2, "u2"),
(fmu2, "y2", fmu1, "u1")]
master = Master(models, connections)
current_time = 0.0
delta = 0.005 # small value just to force the simulation to run for a while
opts = master.simulate_options()
opts['step_size'] = 0.0001
opts['result_handling'] = "none"
# Simulate
for i in range(1000):
if i>0:
opts['initialize'] = False
master.simulate( start_time = current_time, final_time = current_time+delta, options = opts)
current_time += delta |
Hello there ... firstly thank you for maintaining this library 👍
I have a question about how I can handle memory correctly.
I'm using
PyFMI
to set an infinite simulation coupled with an OpcUa Server to keep track and interact with the running model.Here is some characteristics of my algorithm:
Master
algorithm because I have lots of FMUs to link in my model.sleep
to make it realtime.Master
class do not have ado_step
function so to do this I'm using thesimulate(start_time=time, final_time=time+step)
function with{'initialize':False}
set in options.My problem is that running this long enough will lead to a memory increasing until it reaches a maximum allowed by the OS.
I do not need the FMUs to keep track of the history of values of the simulations, I only want the latest values in each step ...
I believe the error is here...
Assuming the error is that ... could you guide me to call the correct functions to clean this history so I can run the simulation indefinitely?
Also if you think that the error is somewhere else, could you give me some advice on how to setup this correctly?
Thank you.
The text was updated successfully, but these errors were encountered: