Skip to content

Commit

Permalink
Bug Fix: Ensure waiting times reach the end of the simulation (#106)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate (#79)

updates:
- [github.com/pre-commit/mirrors-mypy: v0.991 → v1.0.1](pre-commit/mirrors-mypy@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 <[email protected]>

* 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>
  • Loading branch information
RHammond2 and pre-commit-ci[bot] authored Aug 28, 2023
1 parent 97f0cdf commit 1865041
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 7 additions & 2 deletions wombat/core/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<inputs>/weather" directory, and creates the
``start_date`` and ``end_date`` time stamps for the simulation.
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions wombat/core/service_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Check warning on line 1666 in wombat/core/service_equipment.py

View check run for this annotation

Codecov / codecov/patch

wombat/core/service_equipment.py#L1665-L1666

Added lines #L1665 - L1666 were not covered by tests
if intersection_end != sim_end:
hours_to_next = self.hours_to_next_operational_date(

Check warning on line 1668 in wombat/core/service_equipment.py

View check run for this annotation

Codecov / codecov/patch

wombat/core/service_equipment.py#L1668

Added line #L1668 was not covered by tests
start_search_date=intersection_end,
exclusion_days=mobilization_days,
)
else:
hours_to_next = self.env.max_run_time - self.env.now

Check warning on line 1673 in wombat/core/service_equipment.py

View check run for this annotation

Codecov / codecov/patch

wombat/core/service_equipment.py#L1673

Added line #L1673 was not covered by tests
self.env.log_action(
agent=self.settings.name,
action="delay",
Expand Down

0 comments on commit 1865041

Please sign in to comment.