L i ddlmZddlmZddlmZddlmZddlZddlmZddl Z ddl m Z ddl m Z dd l m Z dd l mZdd l mZdd l mZddlZddlZddlZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%ddl$m&Z&ddl'm(Z(ddl)m*Z*ddl)m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3dd l4m5Z5dd!l4m6Z6dd"l7m8Z8dd#l7m9Z9e!d$Z:erdd%l;mZ>e d(gee?ee?ffZ@d)ZAejeCZDGd*d+e jZFGd,d-ZGegd.d/d01dddddd2dd3 dBd6ZHegd7d/d01ddd8 dCd9ZIed5d4gd/d01 dDd:ZJegd;d dEd?ZK dF dGd@ZLdHdAZMy)I) annotations) Container)Iterable)MappingN)Real)Any)Callable)cast)Sequence) TYPE_CHECKING)Union) exceptions)logging)pruners)samplers)storages)convert_positional_args)deprecated_func)experimental_func) _LazyImport)JSONSerializable)-_convert_old_distribution_to_new_distribution)BaseDistribution)is_heartbeat_enabled)_CONSTRAINTS_KEY)_get_feasible_trials)_get_pareto_front_trials) _optimize)StudyDirection) StudySummary)_get_frozen_trial)_tell_with_warning) create_trial) TrialStatezoptuna.study._dataframe)pd) FrozenTrial)Trialr'zstudy:metric_namesc*eZdZUdZded<dZded<y)_ThreadLocalStudyAttributeFboolin_optimize_loopNzlist[FrozenTrial] | Nonecached_all_trials)__name__ __module__ __qualname__r+__annotations__r,X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/optuna/study/study.pyr)r)>s"d"26/6r2r)creZdZdZ d% d&dZd'dZd(dZed)dZed*dZ ed+dZ ed,d Z ed-d Z ed.d Z ed,d Z d/ d0d Z d1 d2dZd3dZed)dZeeddd)dZed4dZ d5 d6dZd7d8dZ d9 d:dZd;dZeddd;dZ d< d=dZd>dZ d? d@dZdAdZdBdZe ddCd Z!dDd!Z"dEd"Z#dFd#Z$ dGd$Z%y)HStudyaA study corresponds to an optimization task, i.e., a set of trials. This object provides interfaces to run a new :class:`~optuna.trial.Trial`, access trials' history, set/get user-defined attributes of the study itself. Note that the direct use of this constructor is not recommended. To create and load a study, please refer to the documentation of :func:`~optuna.study.create_study` and :func:`~optuna.study.load_study` respectively. NcF||_tj|}|j|}||_||_|j ||_|xstj|_ |xstj|_ t|_d|_yNF) study_namer get_storageget_study_id_from_name _study_id_storageget_study_directions _directionsr TPESamplersamplerr MedianPrunerprunerr) _thread_local _stop_flag)selfr8storager@rBstudy_ids r3__init__zStudy.__init__Os%&&w/11*=! "77A7("5"5"7 6 4 4 6 79r2c@|jj}|d=|S)NrC)__dict__copyrEstates r3 __getstate__zStudy.__getstate__cs! ""$ / " r2cX|jj|t|_yN)rJupdater)rCrLs r3 __setstate__zStudy.__setstate__hs U#79r2c.|jjS)zReturn parameters of the best trial in the study. .. note:: This feature can only be used for single-objective optimization. Returns: A dictionary containing parameters of the best trial. ) best_trialparamsrEs r3 best_paramszStudy.best_paramsls%%%r2c:|jj}|J|S)zReturn the best objective value in the study. .. note:: This feature can only be used for single-objective optimization. Returns: A float representing the best objective value. )rTvalue)rE best_values r3rZzStudy.best_valuezs%__** %%%r2c&|jdS)aReturn the best trial in the study. .. note:: This feature can only be used for single-objective optimization. If your study is multi-objective, use :attr:`~optuna.study.Study.best_trials` instead. Returns: A :class:`~optuna.trial.FrozenTrial` object of the best trial. .. seealso:: The :ref:`reuse_best_trial` tutorial provides a detailed example of how to use this method. Tdeepcopy)_get_best_trialrVs r3rTzStudy.best_trials"##T#22r2cd|jd}td|D}t||S)aReturn trials located at the Pareto front in the study. A trial is located at the Pareto front if there are no trials that dominate the trial. It's called that a trial ``t0`` dominates another trial ``t1`` if ``all(v0 <= v1) for v0, v1 in zip(t0.values, t1.values)`` and ``any(v0 < v1) for v0, v1 in zip(t0.values, t1.values)`` are held. Returns: A list of :class:`~optuna.trial.FrozenTrial` objects. Fr\c3@K|]}t|jvywrP)r system_attrs).0trials r3 z$Study.best_trials..sZ%.%2D2DDZs)consider_constraint) get_trialsanyr)rEtrialsis_constraineds r3 best_trialszStudy.best_trialss2%0ZSYZZ'.QQr2cV|jr td|jdS)aHReturn the direction of the study. .. note:: This feature can only be used for single-objective optimization. If your study is multi-objective, use :attr:`~optuna.study.Study.directions` instead. Returns: A :class:`~optuna.study.StudyDirection` object. zA single direction cannot be retrieved from a multi-objective study. Consider using Study.directions to retrieve a list containing all directions.r)_is_multi_objective RuntimeError directionsrVs r3 directionzStudy.directions4  # # %W  q!!r2c|jS)zReturn the directions of the study. Returns: A list of :class:`~optuna.study.StudyDirection` objects. )r>rVs r3rnzStudy.directionssr2c(|jddS)arReturn all trials in the study. The returned trials are ordered by trial number. This is a short form of ``self.get_trials(deepcopy=True, states=None)``. Returns: A list of :class:`~optuna.trial.FrozenTrial` objects. .. seealso:: See :func:`~optuna.study.Study.get_trials` for related method. TNr]states)rfrVs r3rhz Study.trialss T::r2c*|j||dS)afReturn all trials in the study. The returned trials are ordered by trial number. .. seealso:: See :attr:`~optuna.study.Study.trials` for related property. Example: .. testcode:: import optuna def objective(trial): x = trial.suggest_float("x", -1, 1) return x**2 study = optuna.create_study() study.optimize(objective, n_trials=3) trials = study.get_trials() assert len(trials) == 3 Args: deepcopy: Flag to control whether to apply ``copy.deepcopy()`` to the trials. Note that if you set the flag to :obj:`False`, you shouldn't mutate any fields of the returned trial. Otherwise the internal state of the study may corrupt and unexpected behavior may happen. states: Trial states to filter on. If :obj:`None`, include all states. Returns: A list of :class:`~optuna.trial.FrozenTrial` objects. F) use_cache) _get_trials)rEr]rss r3rfzStudy.get_trialssP&EBBr2c|r|jj6|jj|jd|j_|jj}||Dcgc]}|j |vs|}}n|}|rt j|S|S|jj|j||Scc}w)NFr\rr)rCr,r<get_all_trialsr;rMrKr])rEr]rsrurhtfiltered_trialss r3rvzStudy._get_trials s !!33;7;}}7S7SNNU8T8""4''99F!.4"J68I1"J"J"(5=4==1 R? R}}++DNNXV\+]] #Ks +C ?C c8|jr td|jj|j}|j j t}|t|Dcgc]}|dkD c}r|jdtjg}t|}t|dk(r td|jt j"k(rt%|d}nt'|d }|rt)j*|S|Scc}w) aReturn the best trial in the study. Args: deepcopy: Flag to control whether to apply ``copy.deepcopy()`` to the trial. If :obj:`False`, returns the trial without deep copying for better performance. Note that if you set this to :obj:`False`, you shouldn't mutate any fields of the returned trial. Returns: A :class:`~optuna.trial.FrozenTrial` object of the best trial. zA single best trial cannot be retrieved from a multi-objective study. Consider using Study.best_trials to retrieve a list containing the best trials.Frrrz%No feasible trials are completed yet.c6tt|jSrPr floatrYrys r3z'Study._get_best_trial..@UAGG@Tr2keyc6tt|jSrPr~rs r3rz'Study._get_best_trial..Brr2)rlrmr<get_best_trialr;ragetrrgrfr$COMPLETErlen ValueErrorrorMAXIMIZEmaxminrKr])rEr]rT constraintsxcomplete_trialsfeasible_trialss r3r^zStudy._get_best_trial!s  # # %Y  ]]11$..A !--112BC  "s[+IAG+I'J"ooujFYFYEZo[O2?CO?#q( !HII~~!8!88 6TU  6TU ,4t}}Z(D*D,Js+ Dcrtj|jj|jS)aReturn user attributes. .. seealso:: See :func:`~optuna.study.Study.set_user_attr` for related method. Example: .. testcode:: import optuna def objective(trial): x = trial.suggest_float("x", 0, 1) y = trial.suggest_float("y", 0, 1) return x**2 + y**2 study = optuna.create_study() study.set_user_attr("objective function", "quadratic function") study.set_user_attr("dimensions", 2) study.set_user_attr("contributors", ["Akiba", "Sano"]) assert study.user_attrs == { "objective function": "quadratic function", "dimensions": 2, "contributors": ["Akiba", "Sano"], } Returns: A dictionary containing all user attributes. )rKr]r<get_study_user_attrsr;rVs r3 user_attrszStudy.user_attrsFs'J}}T]]??OPPr2z3.1.05.0.0crtj|jj|jS)zoReturn system attributes. Returns: A dictionary containing all system attributes. )rKr]r<get_study_system_attrsr;rVs r3razStudy.system_attrsms&}}T]]AA$..QRRr2cr|jj|jjtS)aReturn metric names. .. note:: Use :meth:`~optuna.study.Study.set_metric_names` to set the metric names first. Returns: A list with names for each dimension of the returned values of the objective function. )r<rr;r_SYSTEM_ATTR_METRIC_NAMESrVs r3 metric_nameszStudy.metric_namesxs)}}33DNNCGGHabbr2c dt|||||t|tr t|n|f||| y)a@Optimize an objective function. Optimization is done by choosing a suitable set of hyperparameter values from a given range. Uses a sampler which implements the task of value suggestion based on a specified distribution. The sampler is specified in :func:`~optuna.study.create_study` and the default choice for the sampler is TPE. See also :class:`~optuna.samplers.TPESampler` for more details on 'TPE'. Optimization will be stopped when receiving a termination signal such as SIGINT and SIGTERM. Unlike other signals, a trial is automatically and cleanly failed when receiving SIGINT (Ctrl+C). If ``n_jobs`` is greater than one or if another signal than SIGINT is used, the interrupted trial state won't be properly updated. Example: .. testcode:: import optuna def objective(trial): x = trial.suggest_float("x", -1, 1) return x**2 study = optuna.create_study() study.optimize(objective, n_trials=3) Args: func: A callable that implements objective function. n_trials: The number of trials for each process. :obj:`None` represents no limit in terms of the number of trials. The study continues to create trials until the number of trials reaches ``n_trials``, ``timeout`` period elapses, :func:`~optuna.study.Study.stop` is called, or a termination signal such as SIGTERM or Ctrl+C is received. .. seealso:: :class:`optuna.study.MaxTrialsCallback` can ensure how many times trials will be performed across all processes. timeout: Stop study after the given number of second(s). :obj:`None` represents no limit in terms of elapsed time. The study continues to create trials until the number of trials reaches ``n_trials``, ``timeout`` period elapses, :func:`~optuna.study.Study.stop` is called or, a termination signal such as SIGTERM or Ctrl+C is received. n_jobs: The number of parallel jobs. If this argument is set to ``-1``, the number is set to CPU count. .. note:: ``n_jobs`` allows parallelization using :obj:`threading` and may suffer from `Python's GIL `__. It is recommended to use :ref:`process-based parallelization` if ``func`` is CPU bound. catch: A study continues to run even when a trial raises one of the exceptions specified in this argument. Default is an empty tuple, i.e. the study will stop for any exception except for :class:`~optuna.exceptions.TrialPruned`. callbacks: List of callback functions that are invoked at the end of each trial. Each function must accept two parameters with the following types in this order: :class:`~optuna.study.Study` and :class:`~optuna.trial.FrozenTrial`. .. seealso:: See the tutorial of :ref:`optuna_callback` for how to use and implement callback functions. gc_after_trial: Flag to determine whether to automatically run garbage collection after each trial. Set to :obj:`True` to run the garbage collection, :obj:`False` otherwise. When it runs, it runs a full collection by internally calling :func:`gc.collect`. If you see an increase in memory consumption over several trials, try setting this flag to :obj:`True`. .. seealso:: :ref:`out-of-memory-gc-collect` show_progress_bar: Flag to show progress bars or not. To show progress bar, set this :obj:`True`. Note that it is disabled when ``n_trials`` is :obj:`None`, ``timeout`` is not :obj:`None`, and ``n_jobs`` :math:`\ne 1`. Raises: RuntimeError: If nested invocation of this method occurs. ) studyfuncn_trialstimeoutn_jobscatch callbacksgc_after_trialshow_progress_barN)r isinstancertuple) rErrrrrrrrs r3optimizezStudy.optimizes9L ",UH"=%,E8)/ r2c|jjs*t|jrt j d|xsi}|j Dcic]\}}|t|}}}d|j_|j}|%|jj|j}tj||}|j D]\}}|j|||Scc}}w)aCCreate a new trial from which hyperparameters can be suggested. This method is part of an alternative to :func:`~optuna.study.Study.optimize` that allows controlling the lifetime of a trial outside the scope of ``func``. Each call to this method should be followed by a call to :func:`~optuna.study.Study.tell` to finish the created trial. .. seealso:: The :ref:`ask_and_tell` tutorial provides use-cases with examples. Example: Getting the trial object with the :func:`~optuna.study.Study.ask` method. .. testcode:: import optuna study = optuna.create_study() trial = study.ask() x = trial.suggest_float("x", -1, 1) study.tell(trial, x**2) Example: Passing previously defined distributions to the :func:`~optuna.study.Study.ask` method. .. testcode:: import optuna study = optuna.create_study() distributions = { "optimizer": optuna.distributions.CategoricalDistribution(["adam", "sgd"]), "lr": optuna.distributions.FloatDistribution(0.0001, 0.1, log=True), } # You can pass the distributions previously defined. trial = study.ask(fixed_distributions=distributions) # `optimizer` and `lr` are already suggested and accessible with `trial.params`. assert "optimizer" in trial.params assert "lr" in trial.params Args: fixed_distributions: A dictionary containing the parameter names and parameter's distributions. Each parameter in this dictionary is automatically suggested for the returned trial, even when the suggest method is not explicitly invoked by the user. If this argument is set to :obj:`None`, no parameter is automatically suggested. Returns: A :class:`~optuna.trial.Trial`. z@Heartbeat of storage is supposed to be used with Study.optimize.N)rCr+rr<warningswarnitemsrr,_pop_waiting_trial_idcreate_new_trialr;optunar'_suggest)rEfixed_distributionsrdisttrial_idrcnameparams r3askz Study.asks@!!227KDMM7Z MM\ ]17R1668 T >tD D  04,--/  }}55dnnEH T8,.446 (KD% NN4 ' ( ! sC=c`t|||||tjt||S)a5 Finish a trial created with :func:`~optuna.study.Study.ask`. .. seealso:: The :ref:`ask_and_tell` tutorial provides use-cases with examples. Example: .. testcode:: import optuna from optuna.trial import TrialState def f(x): return (x - 2) ** 2 def df(x): return 2 * x - 4 study = optuna.create_study() n_trials = 30 for _ in range(n_trials): trial = study.ask() lr = trial.suggest_float("lr", 1e-5, 1e-1, log=True) # Iterative gradient descent objective function. x = 3 # Initial value. for step in range(128): y = f(x) trial.report(y, step=step) if trial.should_prune(): # Finish the trial with the pruned state. study.tell(trial, state=TrialState.PRUNED) break gy = df(x) x -= gy * lr else: # Finish the trial with the final value after all iterations. study.tell(trial, y) Args: trial: A :class:`~optuna.trial.Trial` object or a trial number. values: Optional objective value or a sequence of such values in case the study is used for multi-objective optimization. Argument must be provided if ``state`` is :class:`~optuna.trial.TrialState.COMPLETE` and should be :obj:`None` if ``state`` is :class:`~optuna.trial.TrialState.FAIL` or :class:`~optuna.trial.TrialState.PRUNED`. state: State to be reported. Must be :obj:`None`, :class:`~optuna.trial.TrialState.COMPLETE`, :class:`~optuna.trial.TrialState.FAIL` or :class:`~optuna.trial.TrialState.PRUNED`. If ``state`` is :obj:`None`, it will be updated to :class:`~optuna.trial.TrialState.COMPLETE` or :class:`~optuna.trial.TrialState.FAIL` depending on whether validation for ``values`` reported succeed or not. skip_if_finished: Flag to control whether exception should be raised when values for already finished trial are told. If :obj:`True`, tell is skipped without any error when the trial is already finished. Returns: A :class:`~optuna.trial.FrozenTrial` representing the resulting trial. A returned trial is deep copied thus user can modify it as needed. )rrcvalue_or_valuesrMskip_if_finished)r"rKr]r!)rErcvaluesrMrs r3tellz Study.tellLs5h "-  }}.tU;<%%  &&t~~e&Lr2c4|D]}|j|y)aAdd trials to study. The trials are validated before being added. Example: .. testcode:: import optuna def objective(trial): x = trial.suggest_float("x", 0, 10) return x**2 study = optuna.create_study() study.optimize(objective, n_trials=3) assert len(study.trials) == 3 other_study = optuna.create_study() other_study.add_trials(study.trials) assert len(other_study.trials) == len(study.trials) other_study.optimize(objective, n_trials=2) assert len(other_study.trials) == len(study.trials) + 2 .. seealso:: See :func:`~optuna.study.Study.add_trial` for addition of each trial. Args: trials: Trials to add. N)r)rErhrcs r3 add_trialszStudy.add_trialss J "E NN5 ! "r2z3.2.0ct|jt|k7r td|jj |j t |y)aSet metric names. This method names each dimension of the returned values of the objective function. It is particularly useful in multi-objective optimization. The metric names are mainly referenced by the visualization functions. Example: .. testcode:: import optuna import pandas def objective(trial): x = trial.suggest_float("x", 0, 10) return x**2, x + 1 study = optuna.create_study(directions=["minimize", "minimize"]) study.set_metric_names(["x**2", "x+1"]) study.optimize(objective, n_trials=3) df = study.trials_dataframe(multi_index=True) assert isinstance(df, pandas.DataFrame) assert list(df.get("values").keys()) == ["x**2", "x+1"] .. seealso:: The names set by this method are used in :meth:`~optuna.study.Study.trials_dataframe` and :func:`~optuna.visualization.plot_pareto_front`. Args: metric_names: A list of metric names for the objective function. zCThe number of objectives must match the length of the metric names.N)rrnrr<rr;r)rErs r3set_metric_nameszStudy.set_metric_namessEH t 3|#4 4bc c ++ NN5| r2c2t|jdkDS)zReturn :obj:`True` if the study has multiple objectives. Returns: A boolean value indicates if `self.directions` has more than 1 element or not. )rrnrVs r3rlzStudy._is_multi_objective)s4??#a''r2c~|jj|jdtjfD]j} |jj |j tjs: tjd|jd|j cSy#tj$rYwxYw)NFrr)rMTrial z popped from the trial queue.) r<rxr;r$rset_trial_state_values _trial_idRUNNINGrUpdateFinishedTrialErrorrdebugnumberrs r3rzStudy._pop_waiting_trial_id2s]]11 NNUJ4F4F3H2  #E }};;OO$,,<  MMF5<<.0MN O?? "% #( 66  s5B&&B<;B<c^|jdD]}|jjd|j}|j |j k7rLg}|j D]\}}||}t |t|s|jd2t |trJtjt|xs/tjt|t|dn||k(}|jt|t|syy)NFr\rr|)atolT)rfrarrUkeysrrtypeappendrnpisnanriscloser*all) rErUrc trial_paramsrepeated_params param_name param_valueexisting_param is_repeateds r3rzStudy._should_skip_enqueueIs__e_4 E --11.%,,OL  "fkkm3*,O+1<<> :' K!-j!9!+tN/CD $**51 "+t4HHU;/0Wzz% "4eN6KRUV$6   &&tK'89! :$?#5 8r2c (tjtjsy|j}t |dkDrD||}nt ||Dcic]\}}|| }}}tjd|d|d|dyt |dk(rg||d}n |d|di}d|d|d|d} |jd } | d | jd | jdz } tj| yJd cc}}w#t$rY.wxYw) Nrrz finished with values: z and parameters: .rz finished with value: Fr\z Best is trial z with value: zShould not reach.) r isEnabledForrINFOrrziprr^rrYr) rErrrUr trial_valuesrrY trial_valuemessagerTs r3_log_completed_trialzStudy._log_completed_trialhsL##GLL1 (( v;?#% ?B->,?}ZM]M]L^^_`` LL ! -- -5- Z"  s C?02D DD)NN) r8strrFstr | storages.BaseStorager@'samplers.BaseSampler' | NonerBpruners.BasePruner | NonereturnNone)rdict[Any, Any])rMr rr)rdict[str, Any])rr)rr&)rlist[FrozenTrial])rr)rzlist[StudyDirection])TN)r]r*rsContainer[TrialState] | Nonerr )TNF)r]r*rsr rur*rr )r]r*rr&)rzlist[str] | None)NNrr1NFF)rObjectiveFuncTyper int | Nonerz float | Nonerintrz+Iterable[type[Exception]] | type[Exception]rz5Iterable[Callable[[Study, FrozenTrial], None]] | Nonerr*rr*rrrP)rz"dict[str, BaseDistribution] | Nonerr')NNF) rcz Trial | intrzfloat | Sequence[float] | NonerMzTrialState | Nonerr*rr&)rrrYrrr)) rrYdatetime_startdatetime_completedurationrUrrarMF)rztuple[str, ...]rr*rz'pd.DataFrame')rrr7)rUr rzdict[str, Any] | Nonerr*rr)rcr&rr)rhzIterable[FrozenTrial]rr)r list[str]rr)rr*)rr)rUzMapping[str, JSONSerializable]rr*)rz list[float]rrrUr rr)&r-r.r/__doc__rHrNrRpropertyrWrZrTrjrornrhrfrvr^rrrarrrrrrrrrrrrrrlrrrr1r2r3r5r5CsZ 26,0   , /  *    ( : & & 33$RR$""*  ;;&/3(C(C-(C  (CX/3 ^^-^ ^  ^(#EJ$Q$QLWg&S'S c c $ $=?KO$"'p p p  p  p ; p Ip p  p  p dTr26#'!& [=[=/[=! [=  [=  [=z*FXWg& H' H " "BFBFBF BFH#P-1$ ? ? *?  ?  ? BFMP&"Pw(  ( T(.>#.!#.+.#.8F#. #.r2r5)rFr@rBr8roload_if_existsz3.0.0r)previous_positional_arg_namesdeprecated_versionremoved_versionF)rFr@rBr8rorrnrFr8c||dg}nP| | td|/t|trt|ts td|g}n| t |}nJt |dkr tdt d|Drtd|d|Dcgc]+}t|tr|nt|j-}}tj|} |j||} |"t |dkDrt#j$}|j'| }t)|||| } | Scc}w#tj$r5|r/|Jtjd |d |j!|} nYwxYw) a= Create a new :class:`~optuna.study.Study`. Example: .. testcode:: import optuna def objective(trial): x = trial.suggest_float("x", 0, 10) return x**2 study = optuna.create_study() study.optimize(objective, n_trials=3) Args: storage: Database URL. If this argument is set to None, :class:`~optuna.storages.InMemoryStorage` is used, and the :class:`~optuna.study.Study` will not be persistent. .. note:: When a database URL is passed, Optuna internally uses `SQLAlchemy`_ to handle the database. Please refer to `SQLAlchemy's document`_ for further details. If you want to specify non-default options to `SQLAlchemy Engine`_, you can instantiate :class:`~optuna.storages.RDBStorage` with your desired options and pass it to the ``storage`` argument instead of a URL. .. _SQLAlchemy: https://www.sqlalchemy.org/ .. _SQLAlchemy's document: https://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls .. _SQLAlchemy Engine: https://docs.sqlalchemy.org/en/latest/core/engines.html sampler: A sampler object that implements background algorithm for value suggestion. If :obj:`None` is specified, :class:`~optuna.samplers.TPESampler` is used during single-objective optimization and :class:`~optuna.samplers.NSGAIISampler` during multi-objective optimization. See also :class:`~optuna.samplers`. pruner: A pruner object that decides early stopping of unpromising trials. If :obj:`None` is specified, :class:`~optuna.pruners.MedianPruner` is used as the default. See also :class:`~optuna.pruners`. study_name: Study's name. If this argument is set to None, a unique name is generated automatically. direction: Direction of optimization. Set ``minimize`` for minimization and ``maximize`` for maximization. You can also pass the corresponding :class:`~optuna.study.StudyDirection` object. ``direction`` and ``directions`` must not be specified at the same time. .. note:: If none of `direction` and `directions` are specified, the direction of the study is set to "minimize". load_if_exists: Flag to control the behavior to handle a conflict of study names. In the case where a study named ``study_name`` already exists in the ``storage``, a :class:`~optuna.exceptions.DuplicatedStudyError` is raised if ``load_if_exists`` is set to :obj:`False`. Otherwise, the creation of the study is skipped, and the existing one is returned. directions: A sequence of directions during multi-objective optimization. ``direction`` and ``directions`` must not be specified at the same time. Returns: A :class:`~optuna.study.Study` object. See also: :func:`optuna.create_study` is an alias of :func:`optuna.study.create_study`. See also: The :ref:`rdb` tutorial provides concrete examples to save and resume optimization using RDB. minimizez1Specify only one of `direction` and `directions`.zIUse `directions` instead of `direction` for multi-objective optimization.rz0The number of objectives must be greater than 0.c3dK|](}|ddtjtjfv*yw)rmaximizeN)rMINIMIZEr)rbds r3rdzcreate_study..s2   *j.*A*A>CZCZ[[ s.0zA`directions` must be a list of `minimize` or `maximize`, but got zT. For single-objective optimization, please use `direction` instead of `directions`.z#Using an existing study with name 'z ' instead of creating a new one.r8rFr@rB)rrr rlistrrgrupperrr9create_new_studyrDuplicatedStudyErrorrrr:r NSGAIISamplerget_study_name_from_idr5) rFr@rBr8rorrnrdirection_objectsrGrs r3 create_studyr(sFZ/ \  :#9LMM   i *:i3M[  [  *% u :KLL    OPZ|\a a  T^NOZ> *qwwy0II""7+G ++,=zJ301A5((*//9J Z'RX YE L3  * *  ) )) LL5j\B&& 55jAH   s0D7D<.sT%QRQXQXEYr2rc6tt|jSrPr~rs r3rz)get_all_study_summaries..ur;r2)default) r8rorTrrarrrGrn)rr9get_all_studiesrxr;rMr$rrrnrorrrrrrr r8rra) rFinclude_best_trialfrozen_studiesstudy_summariess all_trialsrycompleted_trialsrrornrTrs r3get_all_study_summariesrE.sol""7+G,,.NO % ++AKK8 '1T!QWW @S@S5SATTz? q||  ! IJ!c*:&;q&@ 7 77!$%5;Y!ZJ!$%5;Y!ZJ! IJJ'1 R!Q5E5E5QQ   R\`   <<#%<<^^!-%  3% N KU( Ss "E=0E=F F ctj|}|jDcgc]}|j}}|Scc}w)aGet all study names stored in a specified storage. Example: .. testsetup:: import os if os.path.exists("example.db"): raise RuntimeError("'example.db' already exists. Please remove it.") .. testcode:: import optuna def objective(trial): x = trial.suggest_float("x", -10, 10) return (x - 2) ** 2 study = optuna.create_study(study_name="example-study", storage="sqlite:///example.db") study.optimize(objective, n_trials=3) study_names = optuna.study.get_all_study_names(storage="sqlite:///example.db") assert len(study_names) == 1 assert study_names[0] == "example-study" .. testcleanup:: os.remove("example.db") Args: storage: Database URL such as ``sqlite:///example.db``. Please see also the documentation of :func:`~optuna.study.create_study` for further details. Returns: List of all study names in the storage. See also: :func:`optuna.get_all_study_names` is an alias of :func:`optuna.study.get_all_study_names`. )rr9r>r8)rFrr+s r3r*r*sC`""7+G181H1H1JK5##KKK Ls?)rFz!str | storages.BaseStorage | Noner@rrBrr8 str | Nonerozstr | StudyDirection | Nonerr*rnz%Sequence[str | StudyDirection] | Nonerr5) r8rGrFrr@rrBrrr5)r8rrFrrr) r/rr0rr1rr2rGrr)T)rFrr?r*rzlist[StudySummary])rFrrr)N __future__rcollections.abcrrrrKnumbersr threadingtypingrr r r r r rnumpyrrrrrrroptuna._convert_positional_argsroptuna._deprecatedroptuna._experimentalroptuna._importsroptuna._typingroptuna.distributionsrroptuna.storages._heartbeatr&optuna.study._constrained_optimizationrroptuna.study._multi_objectiveroptuna.study._optimizeroptuna.study._study_directionroptuna.study._study_summaryr optuna.study._tellr!r" optuna.trialr#r$roptuna.study._dataframer%r&r'rr r get_loggerr-rlocalr)r5r(r,r.r8rEr*r1r2r3r_s"%$#   C.2'+N1;CGB,8401%#2 3 *("gYeXe_.D(EEF1 '  X &77 H.H.V"# 26-1(,!-1 8<J .J+J & J  J + JJ6J J JZ#  .2(, NN(N+ N & N  N Nb# 1#1#(1# 1#1#h#   !% bUbU-bU+ bU  bU  bU bULEIa 'a=AaaH3r2