Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ jobs:
with:
python-version: "3.12"
enable-cache: true
# solver estimates plotted on the benchmark pages (orphan branch, missing
# before the first benchmark run)
- name: Fetch solver estimates
run: |
mkdir -p estimates
if git fetch --depth 1 origin estimates; then
git archive FETCH_HEAD | tar -x -C estimates
fi
- name: Install
run: uv sync --locked --no-dev --group doc
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr_smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ jobs:
run: >
uv run benchopt run benchmarks/${{ matrix.benchmark }}
-r 1 --no-plot --no-display --no-cache
--output "$RUNNER_TEMP/${{ matrix.benchmark }}.csv"
--output "$RUNNER_TEMP/${{ matrix.benchmark }}.parquet"
- name: Collect results (dry run)
run: >
uv run python scripts/collect_results.py ${{ matrix.benchmark }}
"$RUNNER_TEMP/${{ matrix.benchmark }}.csv" --dry-run
"$RUNNER_TEMP/${{ matrix.benchmark }}.parquet" --dry-run
60 changes: 57 additions & 3 deletions .github/workflows/run_benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,33 @@ jobs:
uv run benchopt run benchmarks/${{ matrix.benchmark }}
--config benchmarks/${{ matrix.benchmark }}/run_config.yml
--no-plot --no-display --no-cache
--output "$RUNNER_TEMP/${{ matrix.benchmark }}.csv"
--output "$RUNNER_TEMP/${{ matrix.benchmark }}.parquet"
# the orphan `estimates` branch holds the solver estimates of all the
# rows in results/*.csv (it does not exist before the first run): the
# ones of this benchmark are needed to prune the stale files
- name: Fetch committed estimates
env:
BENCH: ${{ matrix.benchmark }}
run: |
mkdir -p estimates
if git fetch --depth 1 origin estimates \
&& git cat-file -e "FETCH_HEAD:$BENCH" 2>/dev/null; then
git archive FETCH_HEAD "$BENCH" | tar -x -C estimates
fi
- name: Update result table
run: >
uv run python scripts/collect_results.py ${{ matrix.benchmark }}
"$RUNNER_TEMP/${{ matrix.benchmark }}.csv"
"$RUNNER_TEMP/${{ matrix.benchmark }}.parquet"
- uses: actions/upload-artifact@v4
with:
name: results-${{ matrix.benchmark }}
path: results/${{ matrix.benchmark }}.csv
if-no-files-found: error
- uses: actions/upload-artifact@v4
with:
name: estimates-${{ matrix.benchmark }}
path: estimates/
if-no-files-found: ignore

commit:
needs: run
Expand All @@ -111,10 +128,47 @@ jobs:
pattern: results-*
merge-multiple: true
path: results
- name: Commit results
- uses: actions/download-artifact@v4
# no estimates are uploaded if every run failed
continue-on-error: true
with:
pattern: estimates-*
merge-multiple: true
path: ${{ runner.temp }}/estimates
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# the estimates are force-pushed to the orphan `estimates` branch as a
# single parentless commit, so that they never pile up in the history
- name: Publish estimates
run: |
tree_dir="$RUNNER_TEMP/estimates-tree"
mkdir -p "$tree_dir"
old_tree=""
if git fetch --depth 1 origin estimates; then
git archive FETCH_HEAD | tar -x -C "$tree_dir"
old_tree=$(git rev-parse "FETCH_HEAD^{tree}")
fi
# every artifact holds all the estimates of its benchmark
for dir in "$RUNNER_TEMP"/estimates/*/; do
[ -d "$dir" ] || continue
bench=$(basename "$dir")
rm -rf "${tree_dir:?}/$bench"
cp -r "$dir" "$tree_dir/$bench"
done
# build the commit in a separate index, leaving the checkout alone
export GIT_INDEX_FILE="$RUNNER_TEMP/estimates.index"
git -C "$tree_dir" --git-dir="$GITHUB_WORKSPACE/.git" --work-tree=. add -A
tree=$(git write-tree)
if [ "$tree" = "$old_tree" ]; then
echo "No estimate changes"
exit 0
fi
commit=$(git commit-tree "$tree" -m "Update solver estimates")
git push --force origin "$commit:refs/heads/estimates"
- name: Commit results
run: |
git add results/*.csv
if git diff --cached --quiet; then
echo "No result changes"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,6 @@ benchmarks/*/data/

# Generated docs pages
docs/auto_benchmarks/

# Solver estimates (published on the `estimates` branch)
/estimates/
34 changes: 29 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ benchmarks/<name>/ one BenchOpt benchmark per problem
README.md description shown on the website
benchmarks/_template/ copy-me skeleton
results/<name>.csv one result table per benchmark (written by CI)
estimates/<name>/ solver estimates (written by CI to the `estimates` branch)
scripts/ result collection
docs/ Sphinx website built from results/
```
Expand Down Expand Up @@ -47,6 +48,12 @@ uv sync --all-groups # creates .venv with the package, tests (dev) and docs
that returns a matplotlib `Figure` of the true model and the data (import
matplotlib inside the method). The website draws it for every dataset
configuration in the result table and shows it above its leaderboard.
7. Optionally, add a `plot_estimate(self, x_true, x, meta)` method to each
dataset that returns a `Figure` comparing the estimate `x` of a solver with
the true model (e.g. true model, estimate and error, with the same colour
scales as `plot`). The website draws it for every row of the leaderboard
that has a saved estimate and links it from the *Figure* column; the solver
name and PSNR are added as a title.

## Add a solver

Expand All @@ -57,7 +64,9 @@ of solver and regularizer/preconditioner:
other hyperparameters exposed as `parameters` (lists of values are swept);
- build all operators in `set_objective` (not timed) and only solve in `run`
(timed);
- `get_result` returns `dict(x=...)` with `x` of shape `meta["dims"]`;
- `get_result` returns `dict(x=...)` with `x` of shape `meta["dims"]`
(the objective saves it with `save_final_results`, to plot it on the
website);
- if the solver uses randomness (e.g. a starting vector for power
iterations), seed it.

Expand All @@ -78,20 +87,33 @@ to force a fresh run (e.g. to get new timings).
To update the result table from a run (CI does this automatically):

```bash
uv run benchopt run benchmarks/<name> --no-plot --no-cache --output /tmp/raw.csv
uv run python scripts/collect_results.py <name> /tmp/raw.csv
uv run benchopt run benchmarks/<name> --no-plot --no-cache --output /tmp/raw.parquet
uv run python scripts/collect_results.py <name> /tmp/raw.parquet
```

Rows are keyed on objective, dataset, solver and all their parameters: a
rerun replaces the corresponding row (and its `run_date`), a new
configuration adds a row.

Only `.parquet` outputs hold the solver estimates: they are saved in
`estimates/<name>/<key>.npz` (single precision) and the file name goes in the
`estimate` column of the table. Files no longer referenced by the table are
removed. A `.csv` output also works, but its rows get no estimate.

Build the website:

```bash
uv run sphinx-build -W docs docs/_build/html
```

The estimates are not stored on `main`, but on the orphan `estimates`
branch, which CI overwrites with a single commit at every run. To show them
on a local build, extract that branch into `estimates/`:

```bash
git fetch origin estimates && mkdir -p estimates && git archive FETCH_HEAD | tar -x -C estimates
```

## Continuous integration

All workflows install the locked environment with `uv sync --locked`.
Expand All @@ -102,6 +124,8 @@ All workflows install the locked environment with `uv sync --locked`.
- **Run benchmarks** (`run_benchmarks.yml`): on push to `main` (changed
benchmarks only) or manually (one or all benchmarks, optionally against a
PyLops git ref). Results are upserted into `results/<name>.csv` and
committed by `github-actions[bot]`.
committed by `github-actions[bot]`. The solver estimates are merged with
those on the `estimates` branch, which is force-pushed as a single
parentless commit (so binaries never pile up in the history).
- **Docs** (`docs.yml`): manually or weekly, builds the website from
`results/` and deploys it to GitHub Pages.
`results/` and the `estimates` branch, and deploys it to GitHub Pages.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ the true model using PyLops' MAE and PSNR.
| [`seismic_poststack`](benchmarks/seismic_poststack) | Seismic post-stack inversion |
| [`seismic_prestack`](benchmarks/seismic_prestack) | Seismic pre-stack inversion |

Results are stored in [`results/`](results) (one CSV per benchmark) and
published at https://pylops.github.io/pylops-benchmarks.
Results are stored in [`results/`](results) (one CSV per benchmark), the
estimates of the solvers in the
[`estimates`](https://github.com/PyLops/pylops-benchmarks/tree/estimates)
branch, and both are published at https://pylops.github.io/pylops-benchmarks.

## Quick start

Expand All @@ -48,10 +50,14 @@ To preview the pages with results from a local run instead of the committed
ones, collect them into a separate folder and point the build to it:

```bash
uv run benchopt run benchmarks/seismic_interpolation --no-plot --no-cache --output /tmp/raw.csv
uv run python scripts/collect_results.py seismic_interpolation /tmp/raw.csv --results-dir /tmp/results
uv run sphinx-build -W -D results_dir=/tmp/results docs docs/_build/html
uv run benchopt run benchmarks/seismic_interpolation --no-plot --no-cache --output /tmp/raw.parquet
uv run python scripts/collect_results.py seismic_interpolation /tmp/raw.parquet --results-dir /tmp/results --estimates-dir /tmp/estimates
uv run sphinx-build -W -D results_dir=/tmp/results -D estimates_dir=/tmp/estimates docs docs/_build/html
```

The leaderboards link a figure of the estimate of every solver, plotted from
the estimates stored on the `estimates` branch (see
[CONTRIBUTING.md](CONTRIBUTING.md)).

See [CONTRIBUTING.md](CONTRIBUTING.md) to add problems and solvers, and for
details on the CI.
78 changes: 78 additions & 0 deletions asession/estimate-figures/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Session summary: solver estimate figures on benchmark pages

**Date:** 2026-10-23
**Outcome:** PR [#17](https://github.com/PyLops/pylops-benchmarks/pull/17) from branch `estimate-figures` (based on `main`, separate from the PnP/RED work on `pnp-red`)

## Goal

The benchmark pages showed the true model and data of each dataset, and a
leaderboard of metrics. The user wanted to know whether a figure could be made
for every inversion, and then either shown on the page or linked from the
table rows.

## Decisions taken with the user

| Topic | Decision |
| ----- | -------- |
| Display | A **Figure** column in each leaderboard, with a `view` link to the PNG of that row. There is no gallery |
| Storage | An orphan **`estimates`** branch, force-pushed as a single parentless commit at every run, so it adds no git history |
| Format | Raw estimates (`.npz`), plotted at Sphinx build time like the dataset figures, so a change of plot style needs no re-run |
| CI git steps | The user did not want them tried locally against a bare remote, and will test them in CI |

### Why this design

- BenchOpt keeps only the metrics, and running the solvers again at docs time is not possible (runs take up to 6 h).
- BenchOpt 1.10 has an `Objective.save_final_results(**result)` hook. What it returns is stored inline in the **parquet** output (as safetensors/pickle bytes), and `benchopt.results.read_results` unpacks it back into an ndarray. A CSV output would turn the arrays into strings, so CI now writes `.parquet`.
- If the estimates were committed to `main`, every run would add MBs to the git history (Ascent is 512x512 per solver). Workflow artifacts expire after 90 days.

## What was built

```
benchmarks/*/objective.py save_final_results(self, x): return x
pylops_bench/results.py update_results reads .csv/.parquet (benchopt read_results);
tidy keeps the last repetition's estimate (_estimate column);
estimate_key: md5 of the non-empty normalised key values;
save_estimates: <key>.npz in float32/complex64, prunes
files no longer in the table; new `estimate` CSV column
scripts/collect_results.py --estimates-dir (default estimates/)
benchmarks/*/datasets/*.py optional plot_estimate(x_true, x, meta): true | estimate | error
(1D: overlay plus error; prestack: 3x3 grid, one row per parameter)
docs/generate_benchmarks.py _load_dataset (once per dataset configuration), _figure,
_estimate_figures (title "<solver> (<params>): PSNR xx dB"),
Figure column in _leaderboard; config value estimates_dir
docs/conf.py estimates_dir = <repo>/estimates
.github/workflows/run_benchmarks.yml
run job --output .parquet; fetch this benchmark from the estimates
branch (git archive); collect; upload estimates-<bench>
commit job rebuild the tree from the branch plus the artifacts, then
GIT_INDEX_FILE + write-tree + commit-tree + force-push
to refs/heads/estimates; then the CSV commit as before
.github/workflows/docs.yml extract the estimates branch into estimates/ before the build
.github/workflows/pr_smoke.yml --output .parquet (dry-run collect)
.gitignore /estimates/
README.md, CONTRIBUTING.md plot_estimate, the estimates branch, local preview commands
tests/ estimate saving/keying/overwrite/prune/dry-run/CSV tests;
a plot_estimate test per benchmark
```

## Findings along the way

- **With `run_once`, every repetition row has the estimate** in `final_results`. `tidy` keeps the last one.
- **pandas `groupby.agg` rejects functions that return arrays**, so the estimates are aggregated with a list comprehension over the groups.
- **Keys must be stable.** Empty values are skipped in the hash, so that parameter columns added by other solvers, and integers read back as floats from the CSV, do not change a row's key.
- **MyST turns links to existing local files into download links** (`_downloads/<hash>/...png`), so the figures need no extra Sphinx config.
- **Sizes:** the estimates were 40 KB for compressive sensing (9 rows) and 496 KB for image deblurring (12 rows).

## Verification done

- `uv run pytest`: 56 passed.
- `compressive_sensing` and `image_deblurring` were run locally with parquet output, collected into scratch folders and built with `sphinx-build -W -D results_dir=... -D estimates_dir=...`. The Figure column and the download links render. The deblurring, compressive sensing, poststack and template figures were checked visually.
- The CI git plumbing was **not** tested locally.

## Follow-ups

- Watch the first `run_benchmarks.yml` run after the merge (it re-runs every benchmark, because every `objective.py` changed). It creates the `estimates` branch. Check the publish step, and check that `download-artifact` with no matching artifacts does not block the CSV commit (`continue-on-error`).
- Trigger `docs.yml` by hand afterwards to see the links, instead of waiting for the Monday build.
- If all of a benchmark's estimates are pruned, it uploads no artifact, so its old folder stays on the branch. This is a rare edge case.
- The estimate figures of denoising, MRI, deblending, interpolation and prestack have tests but have not been checked visually.
- `benchmarks/_template/README.md` does not mention `plot_estimate` (CONTRIBUTING.md and the template dataset cover it).
17 changes: 17 additions & 0 deletions benchmarks/_template/datasets/blocky_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,20 @@ def plot(self, x_true, Op, y, meta):
ax.legend()
fig.tight_layout()
return fig

def plot_estimate(self, x_true, x, meta):
"""True model, estimate of a solver and error, shown on the benchmark
page (optional)."""
import matplotlib.pyplot as plt

x = np.real(x).reshape(meta["dims"])
fig, axs = plt.subplots(
2, 1, sharex=True, figsize=(9, 4.5), height_ratios=(2, 1)
)
axs[0].plot(x_true, "k", lw=2, label="True model")
axs[0].plot(x, "r", lw=1, label="Estimate")
axs[0].legend()
axs[1].plot(x - x_true, "k", lw=1)
axs[1].set_title("Error")
fig.tight_layout()
return fig
4 changes: 4 additions & 0 deletions benchmarks/_template/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def set_data(self, x_true, Op, y, meta):
def evaluate_result(self, x):
return compute_metrics(self.x_true, x)

def save_final_results(self, x):
# stored in the parquet output, then plotted on the benchmark page
return x

def get_one_result(self):
return dict(x=np.zeros(self.meta["dims"]))

Expand Down
18 changes: 18 additions & 0 deletions benchmarks/compressive_sensing/datasets/sparse_spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,21 @@ def plot(self, x_true, Op, y, meta):
axs[1].set_title("Data")
fig.tight_layout()
return fig

def plot_estimate(self, x_true, x, meta):
"""True sparse vector, estimate and error."""
import matplotlib.pyplot as plt

x = np.real(x).reshape(meta["dims"])
fig, axs = plt.subplots(
2, 1, sharex=True, figsize=(10, 4.5), height_ratios=(2, 1)
)
axs[0].stem(
x_true, linefmt="k-", markerfmt="ko", basefmt="k-", label="True model"
)
axs[0].plot(x, "r.", ms=8, label="Estimate")
axs[0].legend()
axs[1].plot(x - x_true, "k.-", lw=1)
axs[1].set_title("Error")
fig.tight_layout()
return fig
4 changes: 4 additions & 0 deletions benchmarks/compressive_sensing/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def set_data(self, x_true, Op, y, meta):
def evaluate_result(self, x):
return compute_metrics(self.x_true, x)

def save_final_results(self, x):
# stored in the parquet output, then plotted on the benchmark page
return x

def get_one_result(self):
return dict(x=np.zeros(self.meta["dims"]))

Expand Down
18 changes: 18 additions & 0 deletions benchmarks/image_deblurring/datasets/python_logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,21 @@ def plot(self, x_true, Op, y, meta):
ax.axis("off")
fig.tight_layout()
return fig

def plot_estimate(self, x_true, x, meta):
"""True image, deblurred image and error."""
import matplotlib.pyplot as plt

x = np.real(x).reshape(meta["dims"])
opts = dict(cmap="viridis", vmin=0, vmax=250)
fig, axs = plt.subplots(1, 3, figsize=(10, 3.5))
axs[0].imshow(x_true, **opts)
axs[0].set_title("True model")
axs[1].imshow(x, **opts)
axs[1].set_title("Estimate")
axs[2].imshow(x - x_true, cmap="RdBu_r", vmin=-50, vmax=50)
axs[2].set_title("Error")
for ax in axs:
ax.axis("off")
fig.tight_layout()
return fig
Loading
Loading