class_docstr: A trial is a process of evaluating an objective function.
  
  This object is passed to an objective function and provides interfaces to get parameter
  suggestion, manage the trial's state, and set/get user-defined attributes of the trial.
  
  Note that the direct use of this constructor is not recommended.
  This object is seamlessly instantiated and passed to the objective function behind
  the :func:`optuna.study.Study.optimize()` method; hence library users do not care about
  instantiation of this object.
  
  Args:
      study:
          A :class:`~optuna.study.Study` object.
      trial_id:
          A trial ID that is automatically generated.
class_docstr_tok: ["A","trial","is","a","process","of","evaluating","an","objective","function",".","This","object","is","passed","to","an","objective","function","and","provides","interfaces","to","get","parameter","suggestion",",","manage","the","trial","'s","state",",","and","set\/get","user-defined","attributes","of","the","trial",".","Note","that","the","direct","use","of","this","constructor","is","not","recommended",".","This","object","is","seamlessly","instantiated","and","passed","to","the","objective","function","behind","the",":","func",":","`","optuna.study.Study.optimize","(",")","`","method",";","hence","library","users","do","not","care","about","instantiation","of","this","object",".","Args",":","study",":","A",":","class",":","`","~optuna.study.Study","`","object",".","trial_id",":","A","trial","ID","that","is","automatically","generated","."]
docstr: Set user attributes to the trial.
  
  The user attributes in the trial can be access via :func:`optuna.trial.Trial.user_attrs`.
  
  .. seealso::
  
      See the recipe on :ref:`attributes`.
  
  Example:
  
      Save fixed hyperparameters of neural network training.
  
      .. testcode::
  
          import numpy as np
          from sklearn.datasets import load_iris
          from sklearn.model_selection import train_test_split
          from sklearn.neural_network import MLPClassifier
  
          import optuna
  
          X, y = load_iris(return_X_y=True)
          X_train, X_valid, y_train, y_valid = train_test_split(X, y, random_state=0)
  
  
          def objective(trial):
              trial.set_user_attr("BATCHSIZE", 128)
              momentum = trial.suggest_float("momentum", 0, 1.0)
              clf = MLPClassifier(
                  hidden_layer_sizes=(100, 50),
                  batch_size=trial.user_attrs["BATCHSIZE"],
                  momentum=momentum,
                  solver="sgd",
                  random_state=0,
              )
              clf.fit(X_train, y_train)
  
              return clf.score(X_valid, y_valid)
  
  
          study = optuna.create_study(direction="maximize")
          study.optimize(objective, n_trials=3)
          assert "BATCHSIZE" in study.best_trial.user_attrs.keys()
          assert study.best_trial.user_attrs["BATCHSIZE"] == 128
  
  
  Args:
      key:
          A key string of the attribute.
      value:
          A value of the attribute. The value should be JSON serializable.
docstr_tok: ["Set","user","attributes","to","the","trial",".","The","user","attributes","in","the","trial","can","be","access","via",":","func",":","`","optuna.trial.Trial.user_attrs","`",".","..","seealso",":",":","See","the","recipe","on",":","ref",":","`","attributes","`",".","Example",":","Save","fixed","hyperparameters","of","neural","network","training",".","..","testcode",":",":","import","numpy","as","np","from","sklearn.datasets","import","load_iris","from","sklearn.model_selection","import","train_test_split","from","sklearn.neural_network","import","MLPClassifier","import","optuna","X",",","y","=","load_iris","(","return_X_y=True",")","X_train",",","X_valid",",","y_train",",","y_valid","=","train_test_split","(","X",",","y",",","random_state=0",")","def","objective","(","trial",")",":","trial.set_user_attr","(","``","BATCHSIZE","''",",","128",")","momentum","=","trial.suggest_float","(","``","momentum","''",",","0",",","1.0",")","clf","=","MLPClassifier","(","hidden_layer_sizes=","(","100",",","50",")",",","batch_size=trial.user_attrs","[","``","BATCHSIZE","''","]",",","momentum=momentum",",","solver=","''","sgd","''",",","random_state=0",",",")","clf.fit","(","X_train",",","y_train",")","return","clf.score","(","X_valid",",","y_valid",")","study","=","optuna.create_study","(","direction=","''","maximize","''",")","study.optimize","(","objective",",","n_trials=3",")","assert","``","BATCHSIZE","''","in","study.best_trial.user_attrs.keys","(",")","assert","study.best_trial.user_attrs","[","``","BATCHSIZE","''","]","==","128","Args",":","key",":","A","key","string","of","the","attribute",".","value",":","A","value","of","the","attribute",".","The","value","should","be","JSON","serializable","."]
code: def set_user_attr(self, key: str, value: Any) -> None:
      """Set user attributes to the trial.
  
      The user attributes in the trial can be access via :func:`optuna.trial.Trial.user_attrs`.
  
      .. seealso::
  
          See the recipe on :ref:`attributes`.
  
      Example:
  
          Save fixed hyperparameters of neural network training.
  
          .. testcode::
  
              import numpy as np
              from sklearn.datasets import load_iris
              from sklearn.model_selection import train_test_split
              from sklearn.neural_network import MLPClassifier
  
              import optuna
  
              X, y = load_iris(return_X_y=True)
              X_train, X_valid, y_train, y_valid = train_test_split(X, y, random_state=0)
  
  
              def objective(trial):
                  trial.set_user_attr("BATCHSIZE", 128)
                  momentum = trial.suggest_float("momentum", 0, 1.0)
                  clf = MLPClassifier(
                      hidden_layer_sizes=(100, 50),
                      batch_size=trial.user_attrs["BATCHSIZE"],
                      momentum=momentum,
                      solver="sgd",
                      random_state=0,
                  )
                  clf.fit(X_train, y_train)
  
                  return clf.score(X_valid, y_valid)
  
  
              study = optuna.create_study(direction="maximize")
              study.optimize(objective, n_trials=3)
              assert "BATCHSIZE" in study.best_trial.user_attrs.keys()
              assert study.best_trial.user_attrs["BATCHSIZE"] == 128
  
  
      Args:
          key:
              A key string of the attribute.
          value:
              A value of the attribute. The value should be JSON serializable.
      """
  
      self.storage.set_trial_user_attr(self._trial_id, key, value)
      self._cached_frozen_trial.user_attrs[key] = value
  
imports: from __future__ import annotations
  from collections import UserDict
  import copy
  import datetime
  from typing import Any
  from typing import Dict
  from typing import Optional
  from typing import overload
  from typing import Sequence
  import warnings
  import optuna
  from optuna import distributions
  from optuna import logging
  from optuna import pruners
  from optuna._convert_positional_args import convert_positional_args
  from optuna._deprecated import deprecated_func
  from optuna.distributions import BaseDistribution
  from optuna.distributions import CategoricalChoiceType
  from optuna.distributions import CategoricalDistribution
  from optuna.distributions import FloatDistribution
  from optuna.distributions import IntDistribution
  from optuna.trial import FrozenTrial
  from optuna.trial._base import _SUGGEST_INT_POSITIONAL_ARGS
  from optuna.trial._base import BaseTrial
label_desc: Use image node_id 17 for calling the Trial obj's underlying member method code with example usage: obj.set_user_attr(key, value) without return types