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

Restart FmuModel on failure #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions agentlib/models/fmu_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FmuModelConfig(ModelConfig):
tolerance: float = 0.001
extract_fmu: bool = False
log_fmu: bool = True
restart_on_failure: bool = False
only_config_variables: bool = pydantic.Field(
default=True,
description="If True, only the variables passed to this model by a simulator "
Expand Down Expand Up @@ -110,10 +111,17 @@ def do_step(self, *, t_start, t_sample=None):
communicationStepSize=t_samples[_idx + 1] - _t_sample,
)
except FMICallException as e:
# Raise a different error, as simpy does not work well with FMI Errors
raise RuntimeError(
"The fmu had an internal error. Please check the logs to analyze it."
) from e
if self.config.restart_on_failure:
logger.warning("The FMU had an internal error and restarts: %s", e)
self.system.reset()
self.system.setupExperiment(startTime=t_start+t_sample)
self.system.enterInitializationMode()
self.system.exitInitializationMode()
else:
# Raise a different error, as simpy does not work well with FMI Errors
raise RuntimeError(
"The FMU had an internal error. Please check the logs to analyze it."
) from e
# Read current values from system
self.__read_values()
return True
Expand Down