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

Main timing loop #121

Merged
merged 20 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
04c42a1
Changed last_update to no longer be initially hardcoded
jacobcook1995 Nov 21, 2022
de069c3
Seperated main time step from model time steps
jacobcook1995 Nov 21, 2022
a233da6
Updated soil schema to fix broken tests
jacobcook1995 Nov 22, 2022
0dec341
Made very rough start on a function to extract model timing details
jacobcook1995 Nov 22, 2022
d7d31b7
Made setting up model time a seperate function
jacobcook1995 Nov 22, 2022
f0d03fc
Fleshed out extract timings function
jacobcook1995 Nov 23, 2022
f93d0a5
Added a fast model timestep check
jacobcook1995 Nov 24, 2022
45b1139
Added a test for the fast model checking function
jacobcook1995 Nov 25, 2022
b2d4f7f
Added warning when the update interval doesn't cover the time span well
jacobcook1995 Nov 25, 2022
05aa7a4
Added in function to split models based on whether they should update
jacobcook1995 Nov 28, 2022
da7565e
Added test for get_models_to_update function
jacobcook1995 Nov 28, 2022
7c2d2cb
Merge branch 'develop' into feature/basic_timing_loop
jacobcook1995 Nov 28, 2022
a0d35d7
Merge branch 'develop' into feature/basic_timing_loop
jacobcook1995 Nov 28, 2022
07dd788
Moved setting current time out of setup_timing_loop
jacobcook1995 Nov 29, 2022
da0efa4
Switched from using a fixed end date to using a run length
jacobcook1995 Dec 1, 2022
c015785
Switched to list comp for deciding which models to update
jacobcook1995 Dec 1, 2022
6f24c43
Switched to using 10 minute time kernel with model specific update times
jacobcook1995 Dec 1, 2022
aed4777
Removed remaining references to the main model time step
jacobcook1995 Dec 1, 2022
31a0bf6
Returned update interval to being configurable
jacobcook1995 Dec 2, 2022
8544bc8
Merge branch 'develop' into feature/basic_timing_loop
jacobcook1995 Dec 2, 2022
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
Prev Previous commit
Next Next commit
Added test for get_models_to_update function
  • Loading branch information
jacobcook1995 committed Nov 28, 2022
commit da7565eaaa0edabd9b491573e0fc3687e9238994
28 changes: 28 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
check_for_fast_models,
configure_models,
extract_timing_details,
get_models_to_update,
select_models,
setup_timing_loop,
vr_run,
Expand Down Expand Up @@ -386,3 +387,30 @@ def test_setup_timing_loop(caplog, update_interval, expected_log_entries):
assert start_time == current_time

log_check(caplog, expected_log_entries)


@pytest.mark.parametrize(
"current_time,refreshed",
[(datetime64("2020-03-12"), False), (datetime64("2020-04-01"), True)],
)
def test_get_models_to_update(current_time, refreshed):
"""Test to check that splitting models based on update status works."""

# Create SoilModel for testing
model = SoilModel.__new__(SoilModel)
model.update_interval = timedelta64(3, "W")
models = [model]

for model in models:
model.start_model_timing(datetime64("2020-03-01"))

to_refresh, fixed = get_models_to_update(current_time, models)

if refreshed is True:
assert len(to_refresh) == 1
assert len(fixed) == 0
assert models[0].last_update == datetime64("2020-04-01")
else:
assert len(to_refresh) == 0
assert len(fixed) == 1
assert models[0].last_update == datetime64("2020-03-01")
4 changes: 3 additions & 1 deletion virtual_rainforest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def setup_timing_loop(
return start_time


# TODO - TEST THIS
def get_models_to_update(
current_time: datetime64, models: list[BaseModel]
) -> tuple[list[BaseModel], list[BaseModel]]:
Expand Down Expand Up @@ -258,6 +257,9 @@ def vr_run(
to_refresh, fixed = get_models_to_update(current_time, models_cfd)

# TODO - Solve models to steady state

models_cfd = to_refresh + fixed

# TODO - Save model state

LOGGER.info("Virtual rainforest model run completed!")
Expand Down