Skip to content

[WIP] Create matplotlib backend for plotting functions.#1707

Closed
ytknzw wants to merge 6 commits intooptuna:masterfrom
ytknzw:matplotlib_backend
Closed

[WIP] Create matplotlib backend for plotting functions.#1707
ytknzw wants to merge 6 commits intooptuna:masterfrom
ytknzw:matplotlib_backend

Conversation

@ytknzw
Copy link
Contributor

@ytknzw ytknzw commented Aug 24, 2020

This PR proposes to implement matplotlib backend for plotting functions.

Motivation

To provide another visualization option for users, who have only plotly now.
See issue #1539 for the original motivation.

Description of the changes

Created file in optuna.visualization Implemented function Corresponding function with Plotly backend
_optimization_history_matplotlib.py _get_optimization_history_plot_matplotlib _get_optimization_history_plot
_intermediate_values_matplotlib.py _get_intermediate_plot_matplotlib _get_intermediate_plot
_edf_matplotlib.py _get_edf_plot_matplotlib _get_edf_plot

List of Plotly backend functions to be implemented

  • visualization._contour.plot_contour
  • visualization._contour._get_contour_plot
  • visualization._contour._generate_contour_subplot
  • visualization._edf.plot_edf
  • visualization._edf._get_edf_plot
  • visualization._intermediate_values.plot_intermediate_values
  • visualization._intermediate_values._get_intermediate_plot
  • visualization._optimization_history.plot_optimization_history
  • visualization._optimization_history._get_optimization_history_plot
  • visualization._parallel_coordinate.plot_parallel_coordinate
  • visualization._parallel_coordinate._get_parallel_coordinate_plot
  • visualization._param_importances.plot_param_importances
  • visualization._param_importances._get_distribution
  • visualization._param_importances._get_color
  • visualization._param_importances._make_hovertext
  • visualization._slice.plot_slice
  • visualization._slice._get_slice_plot
  • visualization._slice._generate_slice_subplot
  • multi_objective.visualization._pareto_front.plot_pareto_front
  • multi_objective.visualization._pareto_front._get_pareto_front_2d
  • multi_objective.visualization._pareto_front._get_pareto_front_3d
  • multi_objective.visualization._pareto_front._make_hovertext

@github-actions github-actions bot added the optuna.visualization Related to the `optuna.visualization` submodule. This is automatically labeled by github-actions. label Aug 24, 2020
@toshihikoyanase toshihikoyanase added the feature Change that does not break compatibility, but affects the public interfaces. label Aug 24, 2020
@toshihikoyanase toshihikoyanase self-assigned this Aug 24, 2020
Copy link
Member

@toshihikoyanase toshihikoyanase left a comment

Choose a reason for hiding this comment

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

Thank you for your PR. It looks great!

I created a notebook to check the generated graphs and they look nice.

Minimization
image

Maximization
image

A nit-picky, but I have some comments on the code comments. Please take a look.

@ytknzw
Copy link
Contributor Author

ytknzw commented Aug 24, 2020

Thank you for your quick review. Just updated the code comments.

@ytknzw ytknzw changed the title Create matplotlib backend for plotting optimization history. [WIP] Create matplotlib backend for plotting functions. Aug 24, 2020
@Chillee
Copy link
Contributor

Chillee commented Aug 24, 2020

I think this is quite nice - plotly has always been fairly difficult for me to install (particularly to get them to show up in jupyter).

@hvy hvy self-assigned this Aug 25, 2020
@hvy
Copy link
Member

hvy commented Aug 25, 2020

Great, you've already implemented several of them. I'm just curious what the scope of this PR is. I believe we should also discuss how to introduce the matplotlib dependency and how to expose these features to the user. The sooner the better?

@ytknzw
Copy link
Contributor Author

ytknzw commented Aug 25, 2020

Yes, we should discuss how to bring features to users. Sooner is better.

The scope of this PR itself is to implement the matplotlib backend as internal functions.
#1539 (comment)

@hvy
Copy link
Member

hvy commented Aug 26, 2020

Did you plan to cover all of them? I'm wondering if some visualization functions aren't somewhat tricky to implement, such as the parallel coordinate plot. As you've already done a great job implementing several of the existing functions, how about moving on to designing the public API? I think we can cover the logic for how Optuna should behave when a function is not implemented with either library there, and then work on the visualization functions one by one. Having separate PRs for each one would make reviewing easier as well, which presumably would benefit us all.

@ytknzw
Copy link
Contributor Author

ytknzw commented Aug 26, 2020

Thank you for your comments.

  1. Scope

Did you plan to cover all of them?

Yes, I intend to implement all the functions with matplotlib backend in this PR.

  1. Point of dev focus

how about moving on to designing the public API? I think we can cover the logic for how Optuna should behave when a function is not implemented with either library there, and then work on the visualization functions one by one.

I'm confused. @toshihikoyanase commented in issue #1539 as follows:

how about just keeping the current API for now and adding a matplotlib version of get_optimization_history? It may be an internal function in the first PR, and then we can discuss how to make it public in the second PR.

On the other hand, in my understanding, your suggestion is to stop implementing matplotlib backend functions now and to start thinking about the modification of current APIs (e.g. plot_optimization_history) first. Please correct if I misunderstand.

  1. PR size

Having separate PRs for each one would make reviewing easier as well, which presumably would benefit us all.

OK, I close this PR and will instead make separate PRs later.

@HideakiImamura HideakiImamura self-assigned this Aug 27, 2020
@hvy
Copy link
Member

hvy commented Aug 27, 2020

I’m sorry if my comment confused you, it was just an idea to open up a discussion. Let me try to make up for it.

First and foremost, you don’t have to close this PR. Instead, we could continue working on this one to discuss the public API.
Once that is fixed/this PR is merged. We can continue implementing the remaining visualization functions.

What do you think @toshihikoyanase, @ytknzw?

Some approaches for how we could go about designing the public API.

  1. Introduce a “backend” parameter to existing visualization functions.
    • User must consider the argument in each call, implementation becomes somewhat complicated, and the return value becomes a Union.
  2. Define a global/thread local state.
    • User only have to configure it once. Other cons remain. We introduce a global state.
  3. Introduce optuna.visualization.matplotlib to define plot_*
    • User switched between backends by changing the top import statement(s). Pro that we don’t have to keep a global state, code is clearly separated. What functions are implemented in what backend becomes very clear. Return value is not a Union.

I would suggest 3., as you might have noticed. And if so, changes required from this PR are not that large and we could incorporate them here.

@toshihikoyanase
Copy link
Member

@ytknzw @hvy I'm sorry for confusing you. When I suggested separating the PRs, we didn't have implementation and I couldn't imagine the pros & cons of the Interface choices. Now, thanks to the hard work of @ytknzw , we have three visualization functions and IMO, we can discuss the interface now.

@hvy Thank you for your comments on the interface. I agree with your suggestion to introduce optuna.visualization.matplotlib. It doesn't affect existing code, and we may be able to build the implementation based on the first and second approaches on top of it. In addition, I don't think it requires more code changes than the other approaches (I think (1) add public plot functions, (2) create the sub module directory, and move the files).

@ytknzw I'm really sorry for changing my mind, but I think we can keep this PR and add a few changes to create the minimum public interface. What do you think?

@ytknzw
Copy link
Contributor Author

ytknzw commented Aug 28, 2020

@hvy @toshihikoyanase Thank you for clarifications and sorry for my slow reply! I agree with you two. To introduce optuna.visualization.matplotlib would be the best option.
Let me try it in this PR, or another PR is better for review?

@hvy
Copy link
Member

hvy commented Aug 28, 2020

Not slow at all, thanks for taking your time.

Let me try it in this PR, or another PR is better for review?

I'm fine with either. What do you feel more comfortable with?

It would be easier to focus on the implementation/review if we create different PRs, one for fixing the API, followed by PRs for implementing the graphics. It's not a strong opinion.

@ytknzw
Copy link
Contributor Author

ytknzw commented Aug 28, 2020

Thanks. I agree with your points. Modifying API and implementing matplotlib backend are different tasks. I'll creat another PR for optuna.visualization.matplotlib.

@HideakiImamura
Copy link
Member

Thanks, @ytknzw for the great work for plotting functions! I'm very excited to merge these functions into Optuna. I will check and review this and subsequent PRs.

@ytknzw
Copy link
Contributor Author

ytknzw commented Aug 30, 2020

@HideakiImamura
Thank you!
Unfortunately, the API structure in #1756 is now largely changed from this PR, so I close this PR and instead create 1 PR for each graph style (function) based on #1756 .

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

Labels

feature Change that does not break compatibility, but affects the public interfaces. optuna.visualization Related to the `optuna.visualization` submodule. This is automatically labeled by github-actions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants