Skip to content

Fully auto-generate rerun examples#908

Open
blooop wants to merge 2 commits into
mainfrom
refactor/autogenerate-rerun-examples
Open

Fully auto-generate rerun examples#908
blooop wants to merge 2 commits into
mainfrom
refactor/autogenerate-rerun-examples

Conversation

@blooop
Copy link
Copy Markdown
Owner

@blooop blooop commented Apr 9, 2026

Summary

  • Delete 3 hand-written rerun examples (example_rerun.py, example_rerun2.py, example_rerun_over_time.py)
  • Inline ControlSystemSweep class into generated examples via inspect.getsource(), matching the pattern used by the performance generator
  • Generated example_rerun_sweep.py and example_rerun_regression.py are now self-contained
  • Update demo_rerun pixi task to point at the generated capture_window example

Test plan

  • All 1249 tests pass
  • Formatting and linting clean
  • Generated files are stable across regeneration cycles
  • pixi run python bencher/example/meta/generate_meta_rerun.py succeeds

🤖 Generated with Claude Code

Summary by Sourcery

Auto-generate self-contained rerun examples and remove legacy hand-written ones.

Enhancements:

  • Inline the ControlSystemSweep example class into generated rerun examples so they are self-contained and no longer depend on separate example modules.
  • Update rerun example generation to import rerun directly and align with the pattern used by other meta generators.
  • Adjust the demo_rerun task to invoke the generated capture_window example instead of a removed hand-written script.
  • Refresh generated rerun example files to reflect the new inlined class and import structure.

Chores:

  • Remove obsolete hand-written rerun example scripts and update the project plan to drop remaining references to them.

Delete example_rerun.py (replaced by generated capture_window),
example_rerun2.py (niche utility demo), and example_rerun_over_time.py
(support module). Inline ControlSystemSweep via inspect.getsource()
in the meta-generator so sweep and regression examples are self-contained.
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 9, 2026

Reviewer's Guide

Auto-generates rerun examples so they are self-contained, inlining the ControlSystemSweep class into generated files and updating tooling and references to rely on the generated examples instead of deleted hand-written ones.

Class diagram for rerun meta generator and ControlSystemSweep inlining

classDiagram
    class MetaGeneratorBase {
        +output_dir str
        +template_filename str
        +generate_example_file(function_name, imports, body, class_code, run_kwargs)
    }

    class MetaRerun {
        +benchmark()
        +_generate_regression()
        +_generate_sweep()
    }

    MetaGeneratorBase <|-- MetaRerun

    class ControlSystemSweep {
        +to_bench(run_cfg)
        +benchmark(bench_cfg)
    }

    class GeneratedExampleRerunRegression {
        +example_rerun_regression(run_cfg)
        +ControlSystemSweep inlined
    }

    class GeneratedExampleRerunSweep {
        +example_rerun_sweep(run_cfg)
        +ControlSystemSweep inlined
    }

    MetaRerun ..> ControlSystemSweep : imports_source
    MetaRerun ..> GeneratedExampleRerunRegression : generates
    MetaRerun ..> GeneratedExampleRerunSweep : generates
Loading

Flow diagram for ControlSystemSweep source inlining into generated rerun examples

flowchart TD
    A[Start rerun example generation] --> B[Call _get_control_system_class_code]
    B --> C["Try inspect.getsource(ControlSystemSweep)"]
    C -->|success| D[Return ControlSystemSweep source string]
    C -->|OSError| E[Resolve example_rerun_sweep.py with importlib.resources.files]
    E --> F[Read file text with UTF-8 encoding]
    F --> G[Return ControlSystemSweep source string from file]
    D --> H[Pass class_code to generate_example_file]
    G --> H[Pass class_code to generate_example_file]
    H --> I[Write self-contained generated rerun example file]
Loading

File-Level Changes

Change Details Files
Inline ControlSystemSweep source into generated rerun examples so they are self-contained.
  • Import ControlSystemSweep from the generated sweep example into the meta generator.
  • Add a helper function that extracts ControlSystemSweep source via inspect.getsource, with a fallback to reading the generated .py file from bencher.example.generated.rerun.
  • Pass the extracted class code into generated regression and sweep examples via the meta-generator API.
bencher/example/meta/generate_meta_rerun.py
bencher/example/generated/rerun/example_rerun_regression.py
bencher/example/generated/rerun/example_rerun_sweep.py
Adjust generated rerun regression and sweep examples to depend only on rerun and bencher, not on legacy example modules.
  • Update imports used for generated regression example to include rerun and bencher only, removing dependency on the removed example_rerun_over_time module.
  • Update imports used for generated sweep example to include rerun and bencher only, removing dependency on the removed example_rerun_over_time module.
bencher/example/meta/generate_meta_rerun.py
bencher/example/generated/rerun/example_rerun_regression.py
bencher/example/generated/rerun/example_rerun_sweep.py
Remove legacy hand-written rerun examples now superseded by generated examples.
  • Delete example_rerun.py, example_rerun2.py, and example_rerun_over_time.py.
  • Update PLAN.md to no longer reference example_rerun.py in the conversion checklist.
bencher/example/example_rerun.py
bencher/example/example_rerun2.py
bencher/example/example_rerun_over_time.py
PLAN.md
Point the demo_rerun task at the generated capture_window example instead of a deleted hand-written example.
  • Change the demo_rerun pixi task in pyproject.toml to run the generated example_rerun_capture_window.py script under bencher/example/generated/rerun.
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The generator now depends on ControlSystemSweep from a generated module at import time; consider moving ControlSystemSweep into a non-generated, stable module to avoid bootstrapping or circular-dependency issues when regenerating examples or changing generated paths.
  • In _get_control_system_class_code, the importlib fallback currently reads the entire example_rerun_sweep.py file rather than just the ControlSystemSweep definition; if the file grows or gains additional top-level code this may produce incorrect inlined output, so it may be safer to parse and extract only the class body.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The generator now depends on `ControlSystemSweep` from a generated module at import time; consider moving `ControlSystemSweep` into a non-generated, stable module to avoid bootstrapping or circular-dependency issues when regenerating examples or changing generated paths.
- In `_get_control_system_class_code`, the importlib fallback currently reads the entire `example_rerun_sweep.py` file rather than just the `ControlSystemSweep` definition; if the file grows or gains additional top-level code this may produce incorrect inlined output, so it may be safer to parse and extract only the class body.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

Performance Report for 6cbcec9

Metric Value
Total tests 1254
Total time 109.90s
Mean 0.0876s
Median 0.0020s
Top 10 slowest tests
Test Time (s)
test.test_bench_examples.TestBenchExamples::test_example_meta 21.595
test.test_over_time_save_perf::test_save_faster_without_aggregated_tab 5.344
test.test_hash_persistent.TestCrossProcessDeterminism::test_hash_stable_across_two_processes[ResultBool] 4.037
test.test_over_time_repeats.TestMaxSliderPoints::test_default_subsampling_caps_at_max 3.168
test.test_generated_examples::test_generated_example[cartesian_animation/example_cartesian_animation.py] 3.083
test.test_generated_examples::test_generated_example[result_types/result_image/example_result_image_to_video.py] 2.861
test.test_bencher.TestBencher::test_combinations_over_time 1.448
test.test_optuna_result.TestOptunaResult::test_collect_optuna_plots_with_repeats 1.050
test.test_bench_runner.TestBenchRunner::test_bench_reuse_report_cleared 1.017
test.test_over_time_repeats.TestMaxSliderPoints::test_no_subsampling_when_below_default_max 0.938

Full report

Updated by Performance Tracking workflow

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

Performance Report for 472f388

Metric Value
Total tests 1254
Total time 105.41s
Mean 0.0841s
Median 0.0020s
Top 10 slowest tests
Test Time (s)
test.test_bench_examples.TestBenchExamples::test_example_meta 21.055
test.test_over_time_save_perf::test_save_faster_without_aggregated_tab 5.152
test.test_hash_persistent.TestCrossProcessDeterminism::test_hash_stable_across_two_processes[ResultBool] 3.780
test.test_generated_examples::test_generated_example[cartesian_animation/example_cartesian_animation.py] 3.037
test.test_over_time_repeats.TestMaxSliderPoints::test_default_subsampling_caps_at_max 2.931
test.test_generated_examples::test_generated_example[result_types/result_image/example_result_image_to_video.py] 2.814
test.test_bencher.TestBencher::test_combinations_over_time 1.417
test.test_optuna_result.TestOptunaResult::test_collect_optuna_plots_with_repeats 1.024
test.test_bencher.TestBencher::test_combinations 0.901
test.test_over_time_repeats.TestMaxSliderPoints::test_no_subsampling_when_below_default_max 0.896

Full report

Updated by Performance Tracking workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant