Skip to content

feat(examples): add scripts to run all examples and compare outputs across runs#782

Open
PabloCarmona wants to merge 2 commits into
masterfrom
feat/examples-runner
Open

feat(examples): add scripts to run all examples and compare outputs across runs#782
PabloCarmona wants to merge 2 commits into
masterfrom
feat/examples-runner

Conversation

@PabloCarmona

@PabloCarmona PabloCarmona commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Description

There was no easy way to smoke-test that all the example scripts still work after a change, or to compare numeric outputs (loss curves, accuracy, injected noise levels, etc.) between runs to catch regressions.

  • Add examples/run_examples.py, a runner that executes every example script in examples/ (in numeric order) with the current environment's Python, stops immediately on the first failure/crash/timeout and prints the error, and otherwise writes a timestamped report (report.md + metrics.json + full per-example logs) under examples/run_results/.
  • Add examples/compare_runs.py, a helper that diffs the captured metrics (loss/accuracy/noise/etc. values) between two runs — defaults to the two most recent — to make regressions easy to spot across kit changes.
  • Ignore the generated examples/run_results/ output directory in .gitignore.

How to use it

Run every example, in order, stopping at the first failure:

python examples/run_examples.py

Preview which examples would run (and in what order) without executing anything:

python examples/run_examples.py --list

Run only a subset, or skip known slow/environment-specific ones (e.g. the ones needing a local ImageNet copy, multiple GPUs, or long downloads):

python examples/run_examples.py --only "0*.py" "1*.py"
python examples/run_examples.py --exclude "17_resnet34_imagenet_conversion_to_analog.py" "20_mnist_ddp.py" "24_bert_on_squad.py" "36_gpt2_on_wikitext.py"

Cap how long any single example is allowed to run, and keep going past failures instead of stopping:

python examples/run_examples.py --timeout 900 --continue-on-error

Use a specific Python interpreter instead of the current environment's:

python examples/run_examples.py --python /path/to/other/python

Each run produces examples/run_results/run_<timestamp>/ with report.md (human-readable summary), metrics.json (machine-readable), and logs/*.log (full stdout/stderr per example). To compare two runs (defaults to the two most recent):

python examples/compare_runs.py
python examples/compare_runs.py run_20260101_120000 run_20260102_090000

Details

  • Runs examples with sys.executable by default (--python to override).
  • Sets MPLBACKEND=Agg so examples that call plt.show() don't hang waiting on a GUI.
  • Supports --only/--exclude glob filters, --timeout, --continue-on-error, and --list (preview execution order without running).
  • Every run appends a summary line to examples/run_results/history.jsonl for lightweight trend tracking.

Test plan

  • Ran python examples/run_examples.py --list to confirm all 36 examples are discovered in the correct order.
  • Ran python examples/run_examples.py --only "01_simple_layer.py" "02_multiple_layer.py" to confirm the runner executes, logs, stops on failure, and produces report.md/metrics.json correctly.
  • Run the full suite end-to-end against a built aihwkit environment.

@PabloCarmona PabloCarmona self-assigned this Jul 6, 2026
@PabloCarmona PabloCarmona added enhancement New feature or request build Issues related to build system and compilation/installing qa Quality assurance and testing-related issues labels Jul 6, 2026
@PabloCarmona PabloCarmona requested a review from anu-pub July 6, 2026 11:10
@PabloCarmona PabloCarmona force-pushed the feat/examples-runner branch from 99eb8c5 to 1c7d672 Compare July 6, 2026 11:10
Signed-off-by: Pablo Carmona Gonzalez <pablocarmonagonzalez@gmail.com>
Signed-off-by: Pablo Carmona Gonzalez <pablocarmonagonzalez@gmail.com>
@PabloCarmona PabloCarmona force-pushed the feat/examples-runner branch from 593f7e1 to fe5b348 Compare July 6, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Issues related to build system and compilation/installing enhancement New feature or request qa Quality assurance and testing-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant