Skip to content

Add n_recent_trials to plot_timeline#6110

Merged
HideakiImamura merged 6 commits intooptuna:masterfrom
msdsm:feature/update-plot_timeline
May 31, 2025
Merged

Add n_recent_trials to plot_timeline#6110
HideakiImamura merged 6 commits intooptuna:masterfrom
msdsm:feature/update-plot_timeline

Conversation

@msdsm
Copy link
Copy Markdown
Contributor

@msdsm msdsm commented May 31, 2025

Motivation

Description of the changes

Added n_recent_trials parameter to plot_timeline() to limit the number of trials displayed.

Changes

  • Added n_recent_trials: int | None = None parameter
  • When specified, only the most recent N trials are plotted
  • Raises ValueError if n_recent_trials <= 0
  • Updated docstring and added comprehensive tests

Usage

# Plot all trials (default)
plot_timeline(study)

# Plot only the 10 most recent trials
plot_timeline(study, n_recent_trials=10)

@HideakiImamura HideakiImamura self-assigned this May 31, 2025
@not522 not522 added the sprint-20250531 PR from the online sprint event May 31, 2025. label May 31, 2025
@toshihikoyanase toshihikoyanase self-assigned this May 31, 2025
@toshihikoyanase toshihikoyanase added the feature Change that does not break compatibility, but affects the public interfaces. label May 31, 2025
@toshihikoyanase toshihikoyanase changed the title add n_recent_trials to plot_timeline Add n_recent_trials to plot_timeline May 31, 2025
@toshihikoyanase
Copy link
Copy Markdown
Member

@msdsm Could you fill in the PR description, please?

Copy link
Copy Markdown
Member

@contramundum53 contramundum53 left a comment

Choose a reason for hiding this comment

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

LGTM.

@contramundum53
Copy link
Copy Markdown
Member

contramundum53 commented May 31, 2025

Memo: "Recent trials" are defined by the trial number (not start datetime or finish datetime.

@codecov
Copy link
Copy Markdown

codecov bot commented May 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.35%. Comparing base (3128bee) to head (12e8fc5).
⚠️ Report is 505 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6110      +/-   ##
==========================================
- Coverage   88.36%   88.35%   -0.01%     
==========================================
  Files         207      207              
  Lines       14002    14010       +8     
==========================================
+ Hits        12373    12379       +6     
- Misses       1629     1631       +2     

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

Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

LGTM.

@HideakiImamura HideakiImamura merged commit de89e1a into optuna:master May 31, 2025
17 checks passed
@HideakiImamura HideakiImamura added this to the v4.4.0 milestone May 31, 2025
) -> None:
states = [TrialState.COMPLETE, TrialState.PRUNED, TrialState.FAIL, TrialState.RUNNING]
study = _create_study(states)
with pytest.raises(ValueError, match="n_recent_trials must be a positive integer or None"):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checking error messages can be fragile, so let me remove the match argument in a follow-up PR.

@toshihikoyanase toshihikoyanase removed their assignment May 31, 2025
toshihikoyanase added a commit to toshihikoyanase/optuna that referenced this pull request May 31, 2025
nabenabe0928 added a commit that referenced this pull request Jun 4, 2025
Improve test cases for `n_recent_trials` of `plot_timeline` (follow-up #6110).
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. sprint-20250531 PR from the online sprint event May 31, 2025.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants