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

Enhance Optuna Visualization with Advanced Plotting for Optimization History #182

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ repos:
types_or: [python, pyi]
- id: ruff-format
types_or: [python, pyi]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies: [
"types-PyYAML",
]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
- id: mypy
additional_dependencies:
- mdformat-frontmatter
# Ignore only the `README.md` for this repository and check the others in `packages`.
exclude: ^(.github/|README.md)
- types-PyYAML

# Uncomment this section if you want to include mdformat with exclusions
# - repo: https://github.com/executablebooks/mdformat
# rev: 0.7.16
# hooks:
# - id: mdformat
# additional_dependencies:
# - mdformat-frontmatter
# exclude: ^(README.md|.github/)
21 changes: 21 additions & 0 deletions optuna_enhanced_visualization/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 <DSBA Couscous Team>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions optuna_enhanced_visualization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
author: DSBA Couscous Team
title: Optuna Enhanced Visualization
description: Advanced visualization tools for Optuna, including optimization history plotting with detailed customization options.
tags: [visualization]
optuna_versions: ['3.6.1']
license: MIT License
---

## Abstract

This package offers advanced visualization functionalities for Optuna, enabling users to analyze optimization histories with customizable options, such as log-scale views and detailed parameter labels. This is useful for interpreting and optimizing complex hyperparameter tuning processes.

## Class or Function Names

- `plot_optimization_history`

## Installation

No additional dependencies are required beyond those included in Optuna.

## Example

```python
import optuna
from optuna_enhanced_visualization import plot_optimization_history
Copy link
Member

Choose a reason for hiding this comment

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

Please use optunahub.load_module to load your package.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your feedback! I'll make the changes asap


def objective(trial):
x = trial.suggest_float("x", -5, 5)
return x**2

study = optuna.create_study()
study.optimize(objective, n_trials=100)

# Use the enhanced visualization
plot_optimization_history(study)
4 changes: 4 additions & 0 deletions optuna_enhanced_visualization/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .visualization._optimization_history import plot_optimization_history


__all__ = ["plot_optimization_history"]
38 changes: 38 additions & 0 deletions optuna_enhanced_visualization/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
This example is only for sampler.
You can verify your sampler code using this file as well.
Please feel free to remove this file if necessary.
"""

from __future__ import annotations

import optuna
import optunahub


def objective(trial: optuna.Trial) -> float:
x = trial.suggest_float("x", -5, 5)
y = trial.suggest_float("y", -5, 5)
return x**2 + y**2


# TODO: Change package_name to test your package.
package_name = "samplers/your_sampler"
test_local = True

if test_local:
# This is an example of how to load a sampler from your local optunahub-registry.
sampler = optunahub.load_local_module(
package=package_name,
registry_root="./", # Path to the root of the optunahub-registry.
).YourSampler()
else:
# This is an example of how to load a sampler from your fork of the optunahub-registry.
# Please remove repo_owner and ref arguments before submitting a pull request.
sampler = optunahub.load_module(
package=package_name, repo_owner="nourbc211", ref="main"
).YourSampler()

study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=30)
print(study.best_trials)
4 changes: 4 additions & 0 deletions optuna_enhanced_visualization/visualization/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from ._optimization_history import plot_optimization_history


__all__ = ["plot_optimization_history"]
Loading