Skip to content

Commit 8b57b75

Browse files
committed
Merge branch 'feat/swopp3-clean' into scripts/swopp3-analysis
2 parents 6b79cc0 + d4dd1f6 commit 8b57b75

100 files changed

Lines changed: 23771 additions & 1263 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copilot Instructions for routetools
2+
3+
This repository implements weather-routing optimization with JAX and CMA-ES. Keep changes focused, reproducible, and validated.
4+
5+
Write and reason in English.
6+
7+
## Required Workflow
8+
9+
1. Read relevant source files and matching tests before editing.
10+
2. Make the smallest change that satisfies the request.
11+
3. Add or update tests when behavior changes.
12+
4. After each update, run both commands:
13+
- `make hooks`
14+
- `make test`
15+
5. If either command fails, fix the issues and rerun both commands.
16+
6. Do not finalize work until both commands pass.
17+
18+
## Code Conventions
19+
20+
- Use the repository toolchain (`uv` via `make` targets).
21+
- Preserve existing public APIs unless the request explicitly requires a breaking change.
22+
- Follow `ruff` and `pytest` settings in `pyproject.toml`.
23+
- Keep docstrings in NumPy style for public functions.
24+
- Prefer vectorized/JAX-friendly implementations in performance-sensitive code paths.
25+
26+
## Testing Conventions
27+
28+
- Place tests in `tests/` near the relevant domain file.
29+
- For bug fixes, add a regression test first whenever practical.
30+
- Keep tests deterministic and lightweight unless a larger benchmark is explicitly requested.
31+
32+
## Data and Artifacts
33+
34+
- Do not commit large generated outputs.
35+
- Treat `data/` contents as potentially large and optional in local environments.
36+
- Fail with clear error messages when optional datasets are missing.
37+
38+
## Permissions
39+
40+
- Make sure you have the necessary permissions to push to the repository. If you do not have permissions, stop and ask for them, guiding the user to the appropriate process to gain access.
41+
- You can add, commit and push changes to this repository. Never commit to 'main' or 'swopp' branches directly.
42+
- If you are on 'main' or 'swopp', create a new branch for your changes and open a pull request for review.
43+
- Create tests before implementing new features or fixing bugs. Tests should be in the `tests/` directory and follow existing patterns.
44+
- Make sure to run all tests and hooks before pushing your changes. If you encounter any issues, please fix them before pushing.
45+
- Do small commits, preferably one per logical change. This makes it easier to review and understand the history of changes.

.github/workflows/pre-commit-pr.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
name: pre-commit-pr
1+
name: post-commit-push
22

33
on:
4-
pull_request:
4+
push:
55

66
concurrency:
77
group: ${{ github.workflow }}-${{ github.ref }}
88
cancel-in-progress: true
99

1010
jobs:
11-
pre-commit:
11+
post-commit:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
@@ -30,5 +30,5 @@ jobs:
3030
uv pip install pip
3131
- uses: pre-commit/action@v3.0.1
3232
with:
33-
# Ejecutar solo en ficheros que hayan cambiado https://github.com/pre-commit/action/issues/7
34-
extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
33+
# Run hooks after commits are pushed
34+
extra_args: --color=always --all-files --hook-stage post-commit

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,16 @@ output*
167167
# User files
168168
nohup.out
169169
*.zip
170+
output/
171+
172+
# CodaBench competition — large data & build artifacts
173+
codabench/reference_data/*.nc
174+
codabench/reference_data/*.shp
175+
codabench/reference_data/*.shx
176+
codabench/reference_data/*.dbf
177+
codabench/reference_data/*.prj
178+
codabench/logo/
179+
codabench/test_submission/
180+
181+
# Separate repo
182+
routingviz/

README.md

Lines changed: 112 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Tools:
2222
- [prettier](https://prettier.io/): format YAML and Markdown
2323
- [codespell](https://github.com/codespell-project/codespell): check spelling in source code
2424

25+
## Documentation
26+
27+
- [Parametric Performance Model](docs/parametric_model.md) — closed-form RISE model for ship power prediction (hull, wind, wave, and wingsail components).
28+
2529
## Installation
2630

2731
### Application
@@ -38,7 +42,18 @@ Install package and pinned dependencies with the [`uv`](https://docs.astral.sh/u
3842
uv sync
3943
```
4044

41-
4. Run any command or Python script with `uv run`, for instance:
45+
4. (Optional) Install the SWOPP3 performance model:
46+
47+
```{bash}
48+
uv sync --extra swopp3 --find-links release_package/wheels
49+
```
50+
51+
If the pre-built wheels are available locally in `release_package/wheels/`,
52+
`uv` will resolve `swopp3-performance-model` from that directory. Wheels are
53+
available for Python 3.10 – 3.13 on Linux (manylinux) and Windows
54+
(win_amd64).
55+
56+
5. Run any command or Python script with `uv run`, for instance:
4257

4358
```{bash}
4459
uv run routetools/cmaes.py
@@ -50,63 +65,6 @@ Install package and pinned dependencies with the [`uv`](https://docs.astral.sh/u
5065
source .venv/bin/activate
5166
```
5267

53-
### Git credentials for VCS dependencies
54-
55-
When `uv` installs a package from a git repository (VCS dependency), Git may need credentials to fetch the remote. On non-interactive environments this commonly fails with:
56-
57-
```bash
58-
fatal: could not read Username for 'https://github.com': terminal prompts disabled
59-
```
60-
61-
Use one of the following approaches to make VCS fetches non-interactive.
62-
63-
**Option A: SSH (preferred)**
64-
65-
Generate an SSH key (WSL / Linux):
66-
67-
```bash
68-
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_ed25519 -N ""
69-
eval "$(ssh-agent -s)"
70-
ssh-add ~/.ssh/id_ed25519
71-
cat ~/.ssh/id_ed25519.pub
72-
```
73-
74-
Add the printed public key to GitHub (Settings → SSH and GPG keys). Test access:
75-
76-
```bash
77-
ssh -T git@github.com
78-
git ls-remote git@github.com:Weather-Routing-Research/weather-routing-benchmarks.git refs/heads/main
79-
```
80-
81-
Then use an SSH pip URL when adding or declaring the dependency:
82-
83-
```bash
84-
uv add 'git+ssh://git@github.com/Weather-Routing-Research/weather-routing-benchmarks.git@main#egg=wrr_bench'
85-
uv sync
86-
```
87-
88-
If you run `uv` from PowerShell on Windows, ensure the Windows SSH agent is running and the key is loaded (Start-Service ssh-agent; ssh-add $env:USERPROFILE\\.ssh\\id_ed25519), or run `uv` from WSL where the key was created.
89-
90-
**Option B: HTTPS with credentials (fallback)**
91-
92-
Use Git Credential Manager or GitHub CLI to cache credentials so Git won't prompt:
93-
94-
PowerShell (Windows):
95-
96-
```powershell
97-
git config --global credential.helper manager-core
98-
gh auth login --hostname github.com --git-protocol https
99-
```
100-
101-
WSL / Linux (use gh or configure a credential helper that works in your environment):
102-
103-
```bash
104-
gh auth login --hostname github.com --git-protocol https
105-
# or configure `git config --global credential.helper cache` for short-term caching
106-
```
107-
108-
After configuring credentials, retry the `uv add` / `uv sync` command.
109-
11068
### Library
11169

11270
Install a specific version of the package with `pip` or `uv pip`:
@@ -157,6 +115,102 @@ If your computer does not have a GPU, you can force JAX to use the CPU with `JAX
157115
JAX_PLATFORMS=cpu uv run scripts/single_run.py
158116
```
159117

118+
### ERA5 weather data pipeline
119+
120+
The `routetools.era5` module provides real-world ERA5 wind and wave fields
121+
for weather routing. Two download backends are available:
122+
123+
- **GCS** (default) — Google Cloud archive, no API key required.
124+
- **CDS** — Copernicus Climate Data Store (requires `cdsapi` + API key).
125+
126+
**1. Download ERA5 data** for the Atlantic corridor (USNYC ↔ DEHAM):
127+
128+
```bash
129+
uv run scripts/download_era5.py --corridor atlantic --year 2023
130+
```
131+
132+
This creates `data/era5/era5_wind_atlantic_2023.nc` and
133+
`data/era5/era5_waves_atlantic_2023.nc`.
134+
135+
**2. Run the real-world benchmark** (New York → Hamburg, Jan 8 2023):
136+
137+
```bash
138+
uv run scripts/era5_benchmark.py --departure 2023-01-08T00:00:00
139+
```
140+
141+
See `scripts/download_era5.py --help` and `scripts/era5_benchmark.py --help`
142+
for all available options.
143+
144+
### SWOPP3 ERA5 pipeline
145+
146+
The default SWOPP3 competition pipeline is:
147+
148+
```bash
149+
uv run scripts/download_era5.py
150+
uv run scripts/swopp3_run.py
151+
```
152+
153+
These two commands line up without extra path flags. The downloader writes the
154+
four default 2024 files that `scripts/swopp3_run.py` expects:
155+
156+
```text
157+
data/era5/era5_wind_atlantic_2024.nc
158+
data/era5/era5_waves_atlantic_2024.nc
159+
data/era5/era5_wind_pacific_2024.nc
160+
data/era5/era5_waves_pacific_2024.nc
161+
```
162+
163+
`scripts/swopp3_run.py` validates these files before running any case. If one
164+
or more inputs are missing, it exits immediately with a precise error message
165+
instead of silently substituting a great-circle route or running without
166+
weather data. This is intentional:
167+
168+
- GC cases still require wind and wave data for SWOPP3 energy evaluation.
169+
- Optimised cases require wind data for the CMA-ES vectorfield and wind/wave
170+
data for the final SWOPP3 energy evaluation.
171+
172+
If you download a different year or only one corridor, pass matching
173+
`--wind-path*` and `--wave-path*` options to `scripts/swopp3_run.py`.
174+
175+
### Reproducible SWOPP3 experiment profiles
176+
177+
`scripts/swopp3_run.py` supports named experiment profiles stored in
178+
`config.toml`.
179+
180+
Run a named experiment:
181+
182+
```bash
183+
uv run scripts/swopp3_run.py k15_p400_w1000
184+
```
185+
186+
Use another TOML file if needed:
187+
188+
```bash
189+
uv run scripts/swopp3_run.py k15_p400_w1000 --config-path path/to/experiments.toml
190+
```
191+
192+
Relative paths inside a profile are resolved from the directory that contains
193+
the TOML file, not from your current working directory.
194+
195+
Each profile can define shared defaults plus one or more runs.
196+
197+
The runner writes a resolved manifest to:
198+
199+
```text
200+
output/<experiment>/experiment_manifest.json
201+
```
202+
203+
This records the experiment name, config file, source script, and resolved run
204+
parameters used for the launch.
205+
206+
To add a new experiment:
207+
208+
1. Add a new `[swopp3.experiments.<name>]` section to `config.toml`.
209+
2. Put shared parameters under `[swopp3.experiments.<name>.defaults]`.
210+
3. Add one or more `[[swopp3.experiments.<name>.runs]]` entries.
211+
4. Set `source_script` to the script or workflow the profile replaces.
212+
5. Run `uv run scripts/swopp3_run.py <name>`.
213+
160214
## Reproduce the results (paper)
161215

162216
To reproduce the results from the paper, run the following command:

0 commit comments

Comments
 (0)