Skip to content

Refactor Generic Plot to Dispatch to Specialized Plotters#268

Open
abdelghanibelgaid wants to merge 2 commits into
Deltakit:mainfrom
abdelghanibelgaid:main
Open

Refactor Generic Plot to Dispatch to Specialized Plotters#268
abdelghanibelgaid wants to merge 2 commits into
Deltakit:mainfrom
abdelghanibelgaid:main

Conversation

@abdelghanibelgaid
Copy link
Copy Markdown

@abdelghanibelgaid abdelghanibelgaid commented Jun 3, 2026

Summary

Closes #233.

This PR refactors the plotting call structure so that the generic plot() function acts as a dispatcher, while result-specific plotting logic is owned by the specialized plotting functions.

Previously, specialized plotting functions such as plot_lambda() and plot_logical_error_probability_per_round() delegated back to the generic plot() implementation. This inverted the intended responsibility: the generic function contained rendering logic, while the specialized functions mainly prepared/interpolated data.

After this change:

  • plot() only dispatches based on result type.
  • plot_lambda() owns Lambda-specific rendering.
  • plot_logical_error_probability_per_round() owns LEPPR-specific rendering.
  • Interpolation remains inside the specialized plotting functions when raw data is provided.

Motivation

The goal is to make the plotting API easier to maintain and extend.

The generic plot() function should provide a convenient high-level entry point, but it should not contain result-specific rendering details. Moving that logic into the specialized functions keeps responsibilities clearer and makes future plotting extensions easier to implement.

Files changed

  • deltakit-explorer/src/deltakit_explorer/plotting/plotting.py

    • Refactored plot() into a pure dispatcher.
    • Dispatches LambdaResult to plot_lambda().
    • Dispatches LogicalErrorProbabilityPerRoundResult to plot_logical_error_probability_per_round().
    • Removed direct plotting/rendering logic from the generic function.
  • deltakit-explorer/src/deltakit_explorer/plotting/_lambda.py

    • Moved Lambda-specific plot rendering into the specialized Lambda plotter.
    • Added support for plotting both raw LambdaData and already-interpolated LambdaResult.
    • Kept Lambda interpolation inside plot_lambda() when raw Lambda data is passed.
  • deltakit-explorer/src/deltakit_explorer/plotting/_leppr.py

    • Moved LEPPR-specific plot rendering into the specialized LEPPR plotter.
    • Added support for plotting both raw LogicalErrorProbabilityPerRoundData and already-interpolated LogicalErrorProbabilityPerRoundResult.
    • Kept LEPPR interpolation inside the specialized function when raw data is passed.
    • Preserved observation plotting and validation for rounds/probability inputs.
  • deltakit-explorer/src/deltakit_explorer/plotting/_utils.py

    • Added a shared helper for validating or creating matplotlib Figure and Axes objects.
    • Avoids duplicating fig / ax validation logic across plotters.
  • deltakit-explorer/tests/plotting/test_results_and_plot.py

    • Added tests verifying that plot() dispatches to the correct specialized plotter.
    • Added tests for specialized Lambda and LEPPR plotters.
    • Added validation coverage for raw LEPPR data requiring observation inputs.

Technical changes

  • Reversed the dependency direction between generic and specialized plotting functions.
  • Removed result-specific rendering branches from plot().
  • Added private helper functions for rendering interpolated Lambda and LEPPR results.
  • Preserved the public plotting API while improving the internal structure.
  • Preserved support for custom fig, ax, and title arguments.
  • Preserved error handling for unsupported result types.

Validation

  • Ran linting on the modified files.
  • Ran Python compile checks.
  • Added/updated tests for dispatch behavior and specialized plotting paths.

Notes

This PR is intended as a focused refactor for #233 and does not aim to change the user-facing plotting API.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 3, 2026

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Labels

deltakit-explorer UnitaryHACK26 Issues that are part of the Unitary Hack 2026.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

request: Generic Plot should dispatch to plot_lambda instead of vice versa

3 participants