Skip to content

Fix user attributes of enqueued trials returned by ask - #299

Merged
c-bata merged 1 commit into
mainfrom
c-bata/enqueued-trial-user-attrs
Oct 30, 2026
Merged

c-bata merged 1 commit into
mainfrom
c-bata/enqueued-trial-user-attrs

Conversation

@c-bata

@c-bata c-bata commented Oct 28, 2026

Copy link
Copy Markdown
Member

Motivation

Trial.user_attrs of a trial returned by Study.ask() does not include the user attrs given to Study.enqueue_trial(). They are stored in the storage, but the trial object does not show them. This is different from Optuna, where Trial.user_attrs returns them.

import rustuna

study = rustuna.create_study()
study.enqueue_trial({}, user_attrs={"key": "value"})
trial = study.ask()

print(trial.user_attrs)  # {} (expected: {"key": "value"})
print(study._storage.get_trial(trial._trial_id).user_attrs)  # {"key": "value"}

This happens because Trial keeps user attrs in a cache (cached_user_attrs). The cache always starts empty and is only updated by Trial.set_user_attr(s).

Description of the changes

  • When Study.ask() takes a trial from the trial queue, fill the user attr cache of the trial with the user attrs in the storage. This is the same place where the fixed params are read.
  • Keep the design that caches user attrs in Trial. Only the initial value of the cache changes.
  • Add a Rust test (test_ask_returns_user_attrs_of_enqueued_trial), and check trial.user_attrs in the existing Python test test_enqueue_trial_with_user_attrs, which runs for every trial queue type.

@c-bata
c-bata merged commit 8fb626e into main Oct 30, 2026
10 checks passed
@c-bata
c-bata deleted the c-bata/enqueued-trial-user-attrs branch October 30, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant