Skip to content
Snippets Groups Projects
Commit f832c751 authored by Martin Lange's avatar Martin Lange
Browse files

the scheduler tries to determine the minimum starting time of components

parent f3fa9a98
No related branches found
No related tags found
1 merge request!206Handle different start and end times of components
......@@ -140,7 +140,7 @@ class Composition(Loggable):
self.is_initialized = True
def connect(self, time):
def connect(self, time=None):
"""Performs the connect and validate phases of the composition
If this was not called by the user, it is called at the start of :meth:`.run`.
......@@ -157,6 +157,18 @@ class Composition(Loggable):
"t must be None for a composition without time components"
)
else:
if time is None:
t_min = None
for mod in time_modules:
if mod.time is not None:
if t_min is None or mod.time < t_min:
t_min = mod.time
if t_min is None:
raise ValueError(
"Unable to determine starting time of the composition."
"Please provide a starting time in ``run()`` or ``connect()``"
)
time = t_min
if not isinstance(time, datetime):
raise ValueError(
"t must be of type datetime for a composition with time components"
......
......@@ -437,6 +437,8 @@ class TimeComponent(ITimeComponent, Component, ABC):
@property
def time(self):
"""The component's current simulation time."""
if self._time is None and self.status in (ComponentStatus.CREATED or ComponentStatus.INITIALIZED):
"""A time of None is ok before the connect phase"""
if not isinstance(self._time, datetime):
with ErrorLogger(self.logger):
raise ValueError("Time must be of type datetime")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment