|
| 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 |
0 commit comments