Skip to content

Era5 autoencoder#68

Open
Stephen Haddad (stevehadd) wants to merge 9 commits into
mainfrom
era5_autoencoder
Open

Era5 autoencoder#68
Stephen Haddad (stevehadd) wants to merge 9 commits into
mainfrom
era5_autoencoder

Conversation

@stevehadd

Copy link
Copy Markdown
Collaborator

Here is the tutorial on the gridded data which I will be running.

See the readme for more details of individual files, primarily about the difference in training and evaluating models with gridded data compared to tabular data.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an ERA5/WeatherBench gridded-data tutorial that prepares ERA5 data into Zarr, trains a convolutional autoencoder in PyTorch, and provides SLURM submission helpers plus environment specs.

Changes:

  • Added an ERA5 Zarr data-prep CLI and an autoencoder training/evaluation CLI.
  • Added JASMIN/SLURM run + submit scripts and a README describing the workflow.
  • Updated/added PyTorch environment requirement files for the tutorial stack.

Reviewed changes

Copilot reviewed 10 out of 13 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
ml_examples/era5_autoencoder/train_era5_autoencoder.py Training/evaluation CLI with WeatherBench Zarr Dataset, autoencoder model, and training loop.
ml_examples/era5_autoencoder/era5_autoencoder_data_prep.py CLI to compute stats and write original/normalised ERA5 data to Zarr.
ml_examples/era5_autoencoder/ERA5_data_prep.ipynb Notebook walkthrough for the ERA5 data-prep workflow.
ml_examples/era5_autoencoder/README.md Tutorial documentation and execution instructions (direct + SLURM).
ml_examples/era5_autoencoder/config.json Platform path configuration used by tutorial scripts.
ml_examples/era5_autoencoder/run_era5_data_prep.sh SLURM batch script intended to run the data-prep pipeline.
ml_examples/era5_autoencoder/submit_era5_data_prep.sh Convenience wrapper to submit the data-prep batch job.
ml_examples/era5_autoencoder/run_era5_ae_train.sh SLURM batch script intended to stage data and run training on GPU.
ml_examples/era5_autoencoder/submit_era5_ae.sh Convenience wrapper to submit the training batch job.
environments/requirements_pytorch.yml Conda environment spec updates for the tutorial dependencies.
environments/requirements_pytorch.txt Pip requirements file for the tutorial dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +73 to +77
def __str__(self):
return str(self._wb_ds)

def __repr_html__(self):
return self._wb_ds.__rept_html__()
Comment on lines +276 to +281
epoch_val_loss = 0.0
for batch_ix_val, X_batch_val in enumerate(val_loader):
predictions_val = ae_model.forward(X_batch_val.to(device))
loss_batch_val = loss_function(predictions_val, X_batch_val.to(device))
epoch_val_loss += loss_batch_val.to('cpu').item()
epoch_val_loss /= len(val_loader)

print(epoch_train_loss)
print(epoch_val_loss)
epoch_duration_minutes = (datetime.datetime.now() - epoch_start_dt) // 60
mlflow.log_artifact(cp_path)


train_duration_minutes = (datetime.datetime.now() - train_start_dt) // 60
epoch_duration_minutes = (datetime.datetime.now() - epoch_start_dt) // 60
print(f'epoch train loop time {epoch_duration_minutes} minutes')
if checkpoint_dir is not None:
cp_fname = f'era5_autoencoder_checkoint_{epoch_num:03d}.pth'
wb_zarr_norm_dir.mkdir(parents=True)
era5_norm_ds = xarray.merge(var_norm_ds_list).chunk({'time':240})
era5_norm_ds.to_zarr(wb_zarr_norm_dir)
print(f'zarr of original data written to {wb_zarr_norm_dir}')
Comment on lines +14 to +16
cd ~/prog/ai4c_hackathon/

python src/ai4c_hack/era5_autoencoder_data_prep.py --start-year 1980 --end-year 2016 --data-out-dir /gws/ssde/j25a/mmh_storage/ai4c_data/weatherbench/mlready --config notebooks/config.json
export STD_OUT_PATH=/gws/nopw/j04/mohc_shared/users/shaddad/log/era5_data_prep_log_$(date '+%Y%m%d%H%M').out
export STD_ERR_PATH=/gws/nopw/j04/mohc_shared/users/shaddad/log/era5_data_prep_log_$(date '+%Y%m%d%H%M').err

sbatch -o $STD_OUT_PATH -e $STD_ERR_PATH util/run_era5_data_prep.sh

conda activate ${CONDA_ENV}

python ERA5_autoencoder.py --config-path config.json --model-out-dir /gws/ssde/j25a/mmh_storage/user/shaddad/experiments/era5_autoencoder --batch-size=${BATCH_SIZE} --num-epochs ${NUM_EPOCHS} --learning-rate ${LEARNING_RATE} --data-dir $DATA_CACHE_DIR # --mlflow-url "http://localhost" --mlflow-port ${MLFLOW_PORT}

export WEATHERBENCH_NORM_DIR=/gws/ssde/j25a/mmh_storage/ai4c_data/weatherbench/mlready/norm/
export DATA_CACHE_DIR=/tmp/era5_autoencoder/
mkdir $DATA_CACHE_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants