Skip to content

Implementation of matplotlib backend for criterion_plot() #599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

r3kste
Copy link
Contributor

@r3kste r3kste commented May 19, 2025

Summary of Changes

  1. Added backend parameter to criterion_plot() which accepts "plotly" or "matplotlib"
  2. criterion_plot() now returns the figure object corresponding to the chosen backend.
  3. Added backends.py which serves as a registry for all backends

To-Do

It is very much still a work in progress.

  • Discuss on whether the dispatch mechanism can be improved.
  • Add examples in documentation
  • Add suitable tests

Plot

Plotly Matplotlib
t t

Copy link

codecov bot commented May 19, 2025

Codecov Report

❌ Patch coverage is 92.92035% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/optimagic/visualization/backends.py 90.47% 8 Missing ⚠️
Files with missing lines Coverage Δ
src/optimagic/config.py 100.00% <100.00%> (ø)
src/optimagic/exceptions.py 88.57% <100.00%> (+0.33%) ⬆️
src/optimagic/visualization/history_plots.py 93.56% <100.00%> (+1.01%) ⬆️
src/optimagic/visualization/plotting_utilities.py 95.42% <100.00%> (+0.38%) ⬆️
src/optimagic/visualization/backends.py 90.47% <90.47%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@r3kste r3kste force-pushed the backend_plotting branch from 3efa340 to f780bf9 Compare May 19, 2025 19:11
@r3kste r3kste changed the title Barebones implementation of matplotlib backend for criterion_plot() Implementation of matplotlib backend for criterion_plot() May 20, 2025
@r3kste r3kste force-pushed the backend_plotting branch 4 times, most recently from 556334a to d0c6856 Compare May 25, 2025 18:35
@r3kste r3kste closed this Jul 31, 2025
@r3kste r3kste force-pushed the backend_plotting branch from d0c6856 to 1f95f25 Compare July 31, 2025 16:43
@r3kste r3kste reopened this Jul 31, 2025
@r3kste r3kste force-pushed the backend_plotting branch from 97d9169 to e187294 Compare July 31, 2025 16:50
Copy link
Member

@timmens timmens left a comment

Choose a reason for hiding this comment

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

Thanks a lot! I have a few comments, if you have any questions let me know here or via Zulip. I think it will be important to get this PR right such that we don't complicate our lives when handling the other visualization functions.

My main concern is that I'd like the usage of the plotting class to feel more natural. See one of my comments in the backends module.

On an abstract level, a plotting class supporting the criterion plot needs to be able to:

  • Create a figure
  • Add lines to that figure
  • Set a template
  • Set a legend position
  • Set axis labels

Now I would expect that our plotting class somehow incorporates / supports these actions or an action that combines a subset of them (e.g., if we think that some of these actions comprise one block, like we currently do with the PlotConfig).

Additionally

  1. As I am saying in one of the comments, we need to check whether we actually need the PlotConfig class.
  2. I thought about your proposal to rename OptimizeResultOrPath to ResultOrPath, and I think I prefer that! Could you change that?

Thanks a lot!!

@r3kste r3kste requested a review from timmens August 2, 2025 14:02
Copy link
Member

@timmens timmens left a comment

Choose a reason for hiding this comment

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

Thanks! This looks very very good now for the first proper version.

I only have a few comments. Most importantly, we need to make sure that matplotlib is treated as an optional dependency. Once this is handled we can move on to the other functions 🎉

@r3kste r3kste requested a review from timmens August 5, 2025 17:31
Copy link
Member

@timmens timmens left a comment

Choose a reason for hiding this comment

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

Very nice, thanks a lot! Only a few clarifying comments, and then we are hopefully through with this.

@r3kste r3kste force-pushed the backend_plotting branch from 95b665d to f15d982 Compare August 7, 2025 12:53
@r3kste r3kste requested a review from timmens August 7, 2025 18:00
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.

2 participants