Skip to content

Commit ff888c2

Browse files
authored
Merge branch 'dev' into robertode/local-cluster-integration-tests
2 parents 2699827 + 36463a9 commit ff888c2

26 files changed

+3808
-909
lines changed

notebooks/deepmc/mc_forecast.ipynb

Lines changed: 254 additions & 302 deletions
Large diffs are not rendered by default.

notebooks/deepmc/notebook_lib/forecast.py

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import time
21
from datetime import datetime, timedelta
32
from typing import Any, Dict, List, Tuple, cast
43

@@ -8,7 +7,7 @@
87
from shapely.geometry import Point
98

109
from vibe_core.client import FarmvibesAiClient, get_default_vibe_client
11-
from vibe_core.datamodel import RunConfig, RunConfigUser, RunDetails, SpatioTemporalJson
10+
from vibe_core.datamodel import RunConfig, RunConfigUser, SpatioTemporalJson
1211

1312

1413
class Forecast:
@@ -31,7 +30,8 @@ def submit_download_request(self):
3130
"""
3231
Submit request to worker to download forecast data
3332
"""
34-
run_list = []
33+
run_metadata_list = []
34+
runs = []
3535
for parameter in self.parameters:
3636
run_name = f"forecast_{parameter['weather_type']}"
3737
run = self.client.run(
@@ -42,57 +42,40 @@ def submit_download_request(self):
4242
parameters=parameter,
4343
)
4444

45-
try:
46-
run.block_until_complete(5)
47-
except RuntimeError:
48-
print(run)
49-
50-
run_list.append(
45+
run_metadata_list.append(
5146
{
5247
"id": run.id,
5348
"weather_type": parameter["weather_type"],
5449
}
5550
)
51+
runs.append(run)
52+
53+
self.client.monitor(runs, 5)
5654

57-
return run_list
55+
return run_metadata_list
5856

5957
def get_run_status(self, run_list: List[Dict[str, str]]):
6058
clear_output(wait=True)
61-
all_done = True
62-
out_ = []
59+
out = []
6360
for run_item in run_list:
6461
o = self.client.describe_run(run_item["id"])
6562
print(f"Execution status for {run_item['weather_type']}: {o.details.status}")
6663

6764
if o.details.status == "done":
68-
out_.append(o)
69-
elif o.details.status == "failed":
70-
print(o.details)
65+
out.append(o)
7166
else:
72-
all_done = False
73-
cnt_complete = 0
74-
for key, value in o.task_details.items():
75-
value = cast(RunDetails, value)
76-
assert value.subtasks is not None, "Subtasks don't exist"
77-
for subtask in value.subtasks:
78-
if subtask.status == "done":
79-
cnt_complete += 1
80-
print(
81-
"\t",
82-
f"Subtask {key}",
83-
cnt_complete,
84-
"/",
85-
len(value.subtasks),
86-
)
87-
cnt_complete = 0
88-
return all_done, out_
67+
raise Exception(
68+
f"Execution status for {run_item['weather_type']}: {o.details.status}"
69+
)
70+
71+
return out
8972

9073
def get_all_assets(self, details: RunConfigUser):
9174
asset_files = []
9275
output = details.output["weather_forecast"]
9376
record: Dict[str, Any]
9477
for record in cast(List[Dict[str, Any]], output):
95-
for _, value in record["assets"].items():
78+
for value in record["assets"].values():
9679
asset_files.append(value["href"])
9780
df_assets = [pd.read_csv(f, index_col=False) for f in asset_files]
9881
df_out = pd.concat(df_assets)
@@ -104,21 +87,15 @@ def get_downloaded_data(self, run_list: List[Dict[str, str]], offset_hours: int
10487
check the download status. If status is done, fetch the downloaded data
10588
"""
10689
forecast_dataset = pd.DataFrame()
107-
status = False
108-
out_ = []
109-
while status is False:
110-
status, out_ = self.get_run_status(run_list)
111-
time.sleep(10)
112-
113-
if status:
114-
for detail in out_:
115-
df = self.get_all_assets(detail)
90+
out = self.get_run_status(run_list)
91+
for detail in out:
92+
df = self.get_all_assets(detail)
11693

117-
# Offset from UTC to specified timezone
118-
df.index = df.index + pd.offsets.Hour(offset_hours)
94+
# Offset from UTC to specified timezone
95+
df.index = df.index + pd.offsets.Hour(offset_hours)
11996

120-
if not df.empty:
121-
forecast_dataset = pd.concat([forecast_dataset, df], axis=1)
97+
if not df.empty:
98+
forecast_dataset = pd.concat([forecast_dataset, df], axis=1)
12299

123100
return forecast_dataset
124101

notebooks/deepmc/notebook_lib/modules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ def training_step(self, train_batch: Tensor, _):
5959
x, y = train_batch[:6], train_batch[6]
6060
y_hat = self.deepmc(x)
6161
loss = self.loss(y_hat, y)
62-
self.log("train_loss/total", loss)
62+
self.log("train_loss/total", loss, on_epoch=True, prog_bar=True, logger=True, on_step=True)
6363
return loss
6464

6565
def validation_step(self, validation_batch: Tensor, _):
6666
x, y = validation_batch[:6], validation_batch[6]
6767
y_hat = self.deepmc(x)
6868
loss = self.loss(y_hat, y)
69-
self.log("val_loss/total", loss, on_epoch=True)
69+
self.log("val_loss/total", loss, on_epoch=True, prog_bar=True, logger=True, on_step=True)
7070
return loss
7171

7272

notebooks/deepmc/notebook_lib/post_models.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)