Skip to content

buildings_bench.utils

Common Utilities

buildings_bench.utils

set_seed(seed: int = 42) -> None

Set random seed for reproducibility.

save_model_checkpoint(model, optimizer, scheduler, step, path)

Save model checkpoint.

load_model_checkpoint(path, model, optimizer, scheduler, local_rank)

Load model checkpoint.

worker_init_fn_eulp(worker_id)

Set random seed for each worker and init file pointer for Buildings-900K dataset workers.

Parameters:

Name Type Description Default
worker_id int

worker id

required
time_features_to_datetime(time_features: np.ndarray, year: int) -> np.array

Convert time features to datetime objects.

Parameters:

Name Type Description Default
time_features np.ndarray

Array of time features. [:,0] is day of year, [:,1] is day of week, [:,2] is hour of day.

required
year int

Year to use for datetime objects.

required

Returns:

Type Description
np.array

np.array: Array of datetime objects.

get_puma_county_lookup_table(metadata_dir: Path) -> pd.DataFrame

Build a puma-county lookup table.

The weather files are organized by U.S. county. We need to map counties to PUMAs and ensure we drop counties without weather data (only done when using weather).

Parameters:

Name Type Description Default
metadata_dir Path

Path to the metadata folder of BuildingsBench

required

Returns:

Type Description
pd.DataFrame

pd.DataFrame: the puma-county lookup table