Skip to content
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

Adds Voronoi cost landscape plot #531

Merged
merged 15 commits into from
Oct 21, 2024

Conversation

BradyPlanden
Copy link
Member

@BradyPlanden BradyPlanden commented Oct 10, 2024

Description

  • Adds a Voronoi cost landscape plot (pybop.plot.surface)
  • Refactors Optimiser.log for consistent object types
  • Breaking change for plotting. pybop.plot_XXX methods become pybop.plot.XXX

Plots

Here's the voronoi for a particle swarm parameterisation workflow. The voronoi works well for the heuristic / global optimisation algorithms, as they tend to explore the landscape.
image

For gradient based optimisers, the landscape is less informative. I believe this is intentionally helpful to the user, as it actually conveys the lack of information we know about the search space.

image

This PR should probably have a follow up that improves the documentation on how to use this plot, as it's not very common.

Issue reference

Fixes #361

Review

Before you mark your PR as ready for review, please ensure that you've considered the following:

  • Updated the CHANGELOG.md in reverse chronological order (newest at the top) with a concise description of the changes, including the PR number.
  • Noted any breaking changes, including details on how it might impact existing functionality.

Type of change

  • New Feature: A non-breaking change that adds new functionality.
  • Optimization: A code change that improves performance.
  • Examples: A change to existing or additional examples.
  • Bug Fix: A non-breaking change that addresses an issue.
  • Documentation: Updates to documentation or new documentation for new features.
  • Refactoring: Non-functional changes that improve the codebase.
  • Style: Non-functional changes related to code style (formatting, naming, etc).
  • Testing: Additional tests to improve coverage or confirm functionality.
  • Other: (Insert description of change)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All unit tests pass: $ nox -s tests
  • The documentation builds: $ nox -s doctest

You can run integration tests, unit tests, and doctests together at once, using $ nox -s quick.

Further checks:

  • Code is well-commented, especially in complex or unclear areas.
  • Added tests that prove my fix is effective or that my feature works.
  • Checked that coverage remains or improves, and added tests if necessary to maintain or increase coverage.

Thank you for contributing to our project! Your efforts help us to deliver great software.

@BradyPlanden BradyPlanden linked an issue Oct 10, 2024 that may be closed by this pull request
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 99.48980% with 1 line in your changes missing coverage. Please review.

Project coverage is 99.09%. Comparing base (c8b00e6) to head (1315108).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
pybop/plot/voronoi.py 99.07% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop     #531    +/-   ##
=========================================
  Coverage    99.08%   99.09%            
=========================================
  Files           52       54     +2     
  Lines         3605     3752   +147     
=========================================
+ Hits          3572     3718   +146     
- Misses          33       34     +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BradyPlanden BradyPlanden added the ask This PR needs a review for merging label Oct 11, 2024
Copy link
Member

@NicolaCourtier NicolaCourtier left a comment

Choose a reason for hiding this comment

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

Thanks @BradyPlanden, this is a really nice addition! Please see my suggestions.

pybop/optimisers/base_optimiser.py Outdated Show resolved Hide resolved
pybop/optimisers/scipy_optimisers.py Outdated Show resolved Hide resolved
pybop/optimisers/scipy_optimisers.py Outdated Show resolved Hide resolved
pybop/optimisers/scipy_optimisers.py Outdated Show resolved Hide resolved
pybop/optimisers/scipy_optimisers.py Outdated Show resolved Hide resolved
pybop/plotting/plot2d.py Outdated Show resolved Hide resolved
@BradyPlanden
Copy link
Member Author

Thanks @NicolaCourtier, this should be ready for another review after the tests pass.

Any input on the method name? I'm torn between something simple like plot_surface or more informative plot_voronoi2d. Perhaps, surface is more understandable for users.. For reference, Pints call their implementation surface. I'll also replace more of the plot2d calls in the examples with this once we are happy with the name, as it's faster and more representative of the cost landscape from the optimisation perspective.

@NicolaCourtier
Copy link
Member

Thanks, I completely agree with updating the default 2d plot to this one for both speed and accuracy. I'd be happy with either plot_surface or plot_voronoi/2d, but then I think we should also update the name of plot2d to distinguish between the two, perhaps this could become plot_contours?

@BradyPlanden
Copy link
Member Author

This now has a breaking change for the plotting methods as described in the changelog. Essentially, pybop.plot_XXX becomes pybop.plot.XXX where possible. This adds clearer separation for the plotting methods, and allows for better method naming. A few of the methods have a larger rename, such as, plot2d becoming plot.contour and plot_voronoi_2d is now plot.surface

Copy link
Member

@NicolaCourtier NicolaCourtier left a comment

Choose a reason for hiding this comment

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

The new plots look great! Thanks @BradyPlanden!

@BradyPlanden BradyPlanden merged commit 87da4d7 into develop Oct 21, 2024
31 checks passed
@BradyPlanden BradyPlanden deleted the 361-add-voronoi-diagram-from-optimiser-queries branch October 21, 2024 08:33
BradyPlanden added a commit that referenced this pull request Nov 25, 2024
* feat: initial voronoi plotting methods

* fix: Optimiser.log object updates for aligned shape, adds SciPy optimiser support for Voronoi

* refactor: update Optim.log for input conversion, cleanup

* plots: updates to voronoi format, changelog entry

* fix: clean examples, voronoi docstrings

* tests: adds coverage for BaseOptimiser

* tests: adds no cover to skip conditions

* Apply suggestions from code review

Co-authored-by: NicolaCourtier <[email protected]>

* plots: updates gradient plotting to reduce cost calls.

Co-authored-by: NicolaCourtier <[email protected]>

* updates local stored cost name

* breaking: refactors plotting to `pybop.plot` subdirectory, `plot2d` to `plot.contour`, `plot.surface` to become default 2d visualisation

* notebooks: plot2d -> plot.contour, adds plot.surface

---------

Co-authored-by: NicolaCourtier <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ask This PR needs a review for merging
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add voronoi diagram from optimiser queries
2 participants