Skip to content

Commit b492c47

Browse files
committed
Merge main
2 parents 792e5cf + 6e5ba43 commit b492c47

31 files changed

Lines changed: 1423 additions & 357 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ output.log
3838
.data_cache/
3939
configs/schemas/
4040
/playpen
41+
*.env
42+
build/
43+
.pytype/
44+
.claude/

AGENTS.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to automated agents when working with code in this repository.
4+
5+
## Overview
6+
7+
Ocean Emulator is a PyTorch-based machine learning project for training and evaluating models that emulate ocean physics. Currently, it implements a ConvNeXt U-Net neural network architecture.
8+
9+
## Development Commands
10+
11+
### Environment Setup
12+
13+
```bash
14+
# Install dependencies with uv
15+
uv sync --dev
16+
source .venv/bin/activate
17+
```
18+
19+
### Running Tests
20+
21+
```bash
22+
# Run standard tests (excluding manual and CUDA tests)
23+
uv run pytest -m "not manual and not cuda"
24+
25+
# Run tests with multiple CPU cores
26+
uv run pytest -m "not manual and not cuda" -n auto
27+
28+
# Run CUDA tests (requires GPU)
29+
uv run pytest -m cuda
30+
31+
# Run manual tests
32+
uv run pytest -m manual -k test_whatever
33+
34+
# Run specific test file
35+
uv run pytest tests/test_train.py
36+
37+
# Run benchmarks
38+
uv run pytest --benchmark-only --benchmark-autosave
39+
```
40+
41+
### Code Quality Checks
42+
43+
```bash
44+
# Run all pre-commit checks (linting, formatting, type checking)
45+
uvx pre-commit run --all-files
46+
```
47+
48+
### Training, Evaluation, and Visualization
49+
50+
Please ask if you need to train or evaluate a model.
51+
52+
For vizualization or other long-running tasks:
53+
54+
* Run with `PYTHONUNBUFFERED=1 uv run ... > /tmp/logfile.txt 2>&1`
55+
* Wait for a while with `timeout $time tail --pid=$pid -f /tmp/logfile.txt`
56+
* You may need to run this repeatedly.
57+
58+
## High-Level Architecture
59+
60+
### Core Components
61+
62+
1. **Model Architecture** (`src/ocean_emulators/models/`)
63+
* `convnext_unet.py`: Main neural network implementing ocean predictions
64+
* `modules/`: Reusable network blocks (ConvNext, etc.)
65+
* Models predict ocean variables from ocean model data
66+
67+
2. **Data Pipeline** (`src/ocean_emulators/datasets.py`)
68+
* Handles OM4 and CM4 ocean model data via Zarr format
69+
* Supports time-based train/validation splits
70+
* Variables include temperature, salinity, u/v velocities, sea surface height, and heat
71+
* Data normalization and preprocessing
72+
73+
3. **Training Loop** (`src/ocean_emulators/train.py`)
74+
* Distributed training support via PyTorch DDP
75+
* Checkpointing with model state and optimizer
76+
* Weights & Biases integration for experiment tracking
77+
* Learning rate scheduling and warmup
78+
* Initializes data loaders and training datasets.
79+
80+
4. **Evaluation System** (`src/ocean_emulators/eval.py`, `aggregator/`)
81+
* Comprehensive metrics including RMSE, bias, correlations
82+
* Ocean heat content (OHC) analysis
83+
* ENSO metrics and basin-specific analysis
84+
* Visualization tools for maps, time series, PDFs
85+
* Aggregator pattern for metric collection
86+
87+
5. **Configuration System** (`src/ocean_emulators/config.py`)
88+
* YAML-based configuration with JSON schema validation
89+
* Hierarchical configs with `!include` directives
90+
* Pydantic models for type safety
91+
* Command-line overrides supported
92+
93+
### Key Design Patterns
94+
95+
1. **Multiton Pattern**: Used for managing global state in tests via `MultitonScope`
96+
2. **Factory Pattern**: For creating network blocks dynamically
97+
3. **Configuration-Driven**: All major components configured via YAML
98+
4. **Aggregator Pattern**: For collecting distributed metrics during evaluation
99+
100+
### Project Structure
101+
102+
```text
103+
src/ocean_emulators/
104+
├── train.py # Training entry point
105+
├── eval.py # Evaluation entry point
106+
├── config.py # Configuration classes
107+
├── config_schema.py # JSON schema generation
108+
├── datasets.py # Data loading
109+
├── models/ # Neural network architectures
110+
├── aggregator/ # Metric aggregation
111+
└── utils/ # Utilities for distributed training, logging
112+
113+
configs/ # YAML configuration files
114+
tests/ # Comprehensive test suite
115+
scripts/ # Data download and preprocessing
116+
```
117+
118+
### Important Considerations
119+
120+
1. **Data Format**: Uses Zarr format for efficient array storage
121+
2. **Distributed Training**: Supports multi-GPU via PyTorch DDP
122+
3. **Performance Mindset**: We include profiling tools (memray, py-spy, scalene) and aim to keep the code performant core train and eval loops.
123+
4. **Testing Philosophy**: Tests marked as `manual` or `cuda` for selective execution
124+
5. **Pre-commit Hooks**: Enforces code quality (ruff, mypy, detect-secrets)
125+
6. **Cloud Training**: Supports SkyPilot for remote job execution

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

CONTRIBUTING.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,28 @@ git push --force-with-lease
162162
```bash
163163
DATA_PATH=path/to/save/data
164164
uv run scripts/clone_data.py $DATA_PATH --compact_variables
165-
uv run -m ocean_emulators.train configs/train_om4.yaml --data_root $DATA_PATH
165+
uv run -m ocean_emulators.train configs/train_om4.yaml --experiment.data_root $DATA_PATH
166166
```
167167

168168
You can run `uv run -m ocean_emulators.train --help` to see all the options available.
169169

170170
To learn more about other datasets used during training, please see the _Data Engineering_ section below.
171171

172+
To run a remote training job with Skypilot, use the following command:
173+
```shell
174+
# export WANDB_API_KEY=<my-key> # Get your key at https://wandb.ai/authorize
175+
# sky launch -c fomo-cluster train.sky.yaml --env WANDB_API_KEY --env-file <my-vars>.env
176+
```
177+
178+
Please read the docstring in the `train.sky.yaml` for more information.
179+
172180
### Evaluating the model
173181

174182
```bash
175183
DATA_PATH=path/to/save/data
176184
uv run scripts/clone_data.py $DATA_PATH --compact_variables
177185
# (then put a checkpoint of the model at path/to/checkpoint)
178-
uv run -m ocean_emulators.eval configs/eval_om4.yaml --ckpt_path path/to/checkpoint --data_root $DATA_PATH
186+
uv run -m ocean_emulators.eval configs/eval_om4.yaml --ckpt_path path/to/checkpoint --experiment.data_root $DATA_PATH
179187
```
180188

181189
You can run `uv run -m ocean_emulators.eval --help` to see all the options available.

configs/data/om4_sky_local.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# yaml-language-server: $schema=../schemas/DataConfig.json
2+
3+
data_location:
4+
type: local
5+
path: OM4.zarr
6+
7+
data_means_location:
8+
type: local
9+
path: OM4_means.zarr
10+
11+
data_stds_location:
12+
type: local
13+
path: OM4_stds.zarr
14+
15+
static_data_vars:
16+
- sea_surface_fraction
17+
- hfgeou

configs/slurm_perlmutter_train_cm4.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ save_freq: 5
77
epochs: 120
88
batch_size: 3
99
learning_rate: 0.0001
10-
scheduler: true
10+
scheduler: {type: cosine}
1111
loss: mse
1212
finetune: false
1313
resume_ckpt_path: null

configs/slurm_perlmutter_train_om4.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ save_freq: 5
77
epochs: 70
88
batch_size: 4
99
learning_rate: 0.0002
10-
scheduler: true
10+
scheduler: {type: cosine}
1111
loss: mse
1212
finetune: false
1313
resume_ckpt_path: null

configs/train_cm4.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ save_freq: 5
77
epochs: 120
88
batch_size: 3 # 4
99
learning_rate: 0.0001
10-
scheduler: false
10+
scheduler: null
1111
loss: mse
1212
finetune: false
1313
resume_ckpt_path: null

configs/train_default.test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ epochs: 2
1010
batch_size: 1
1111
preemptible: false
1212
learning_rate: 0.0001
13-
scheduler: false
13+
scheduler: null
1414
loss: mse
1515
finetune: false
1616
resume_ckpt_path: null

configs/train_default_2step.test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ epochs: 1
1010
batch_size: 1
1111
preemptible: false
1212
learning_rate: 0.0001
13-
scheduler: false
13+
scheduler: null
1414
loss: mse
1515
finetune: false
1616
resume_ckpt_path: null

0 commit comments

Comments
 (0)