From 18650418afd91504d825b263e8f565aabd7c7184 Mon Sep 17 00:00:00 2001 From: Rob Hammond <13874373+RHammond2@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:09:15 -0700 Subject: [PATCH 1/2] Bug Fix: Ensure waiting times reach the end of the simulation (#106) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate (#79) updates: - [github.com/pre-commit/mirrors-mypy: v0.991 → v1.0.1](https://github.com/pre-commit/mirrors-mypy/compare/v0.991...v1.0.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Rob Hammond <13874373+RHammond2@users.noreply.github.com> * fix infinite loop bug * update changelog * ensure wombat datetime is always in nanosecond resolution * update docs examples generation --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ docs/source/conf.py | 2 +- wombat/core/environment.py | 9 +++++++-- wombat/core/service_equipment.py | 13 +++++++++---- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08042f22..f425d74f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased (TBD) + +- Fixes a bug where servicing equipment waiting for the next operational period at the end of a simulation get stuck in an infinite loop because the timeout is set for just prior to the end of the simulation, and not just after the end of the simulation's maximum run time. + ## v0.8.0 (16 August 2023) ### Bug Fixes diff --git a/docs/source/conf.py b/docs/source/conf.py index 6d250c4a..11cbcd82 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -95,7 +95,7 @@ } # toggle this between auto/off to rerun full documentation build -nb_execution_mode = "off" +nb_execution_mode = "auto" nb_execution_timeout = -1 nb_execution_allow_errors = True # nb_execution_excludepatterns.append("*_demonstration.md") diff --git a/wombat/core/environment.py b/wombat/core/environment.py index db5dfae3..49116345 100644 --- a/wombat/core/environment.py +++ b/wombat/core/environment.py @@ -418,7 +418,7 @@ def _weather_setup( weather_file: str, start_year: int | None = None, end_year: int | None = None, - ) -> pd.DataFrame: + ) -> pl.DataFrame: """Reads the weather data from the "/weather" directory, and creates the ``start_date`` and ``end_date`` time stamps for the simulation. @@ -476,7 +476,12 @@ def _weather_setup( .reset_index(drop=False) ) .with_row_count() - .with_columns((pl.col("datetime").dt.hour()).alias("hour")) + .with_columns( + [ + pl.col("datetime").cast(pl.Datetime).dt.cast_time_unit("ns"), + (pl.col("datetime").dt.hour()).alias("hour"), + ] + ) ) missing = set(REQUIRED).difference(weather.columns) diff --git a/wombat/core/service_equipment.py b/wombat/core/service_equipment.py index 019fe5db..95ad28af 100644 --- a/wombat/core/service_equipment.py +++ b/wombat/core/service_equipment.py @@ -1662,10 +1662,15 @@ def run_unscheduled_in_situ(self) -> Generator[Process, None, None]: self.settings.non_operational_dates_set ) if intersection: - hours_to_next = self.hours_to_next_operational_date( - start_search_date=max(intersection), - exclusion_days=mobilization_days, - ) + intersection_end = max(intersection) + sim_end = self.env.end_datetime.date() + if intersection_end != sim_end: + hours_to_next = self.hours_to_next_operational_date( + start_search_date=intersection_end, + exclusion_days=mobilization_days, + ) + else: + hours_to_next = self.env.max_run_time - self.env.now self.env.log_action( agent=self.settings.name, action="delay", From 45a37e755b1cde99ca4e31dc736c5fd725ab6447 Mon Sep 17 00:00:00 2001 From: RHammond2 <13874373+RHammond2@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:11:15 -0700 Subject: [PATCH 2/2] bump version --- CHANGELOG.md | 2 +- wombat/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f425d74f..045eb14e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## Unreleased (TBD) +## v0.8.1 (28 August 2023) - Fixes a bug where servicing equipment waiting for the next operational period at the end of a simulation get stuck in an infinite loop because the timeout is set for just prior to the end of the simulation, and not just after the end of the simulation's maximum run time. diff --git a/wombat/__init__.py b/wombat/__init__.py index afb41ca5..ec239fff 100644 --- a/wombat/__init__.py +++ b/wombat/__init__.py @@ -4,4 +4,4 @@ from wombat.core.library import create_library_structure -__version__ = "0.8.0" +__version__ = "0.8.1"