(self, value: float, step: int)
Report an objective function value for a given step.

        The reported values are used by the pruners to determine whether this trial should be
        pruned.

        .. seealso::
            Please refer to :class:`~optuna.pruners.BasePruner`.

        .. note::
            The reported value is converted to ``float`` type by applying ``float()``
            function internally. Thus, it accepts all float-like types (e.g., ``numpy.float32``).
            If the conversion fails, a ``TypeError`` is raised.

        .. note::
            If this method is called multiple times at the same ``step`` in a trial,
            the reported ``value`` only the first time is stored and the reported values
            from the second time are ignored.

        Example:

            Report intermediate scores of `SGDClassifier <https://scikit-learn.org/stable/modules/
            generated/sklearn.linear_model.SGDClassifier.html>`_ training.

            .. testcode::

                import numpy as np
                from sklearn.datasets import load_iris
                from sklearn.linear_model import SGDClassifier
                from sklearn.model_selection import train_test_split

                import optuna

                X, y = load_iris(return_X_y=True)
                X_train, X_valid, y_train, y_valid = train_test_split(X, y)


                def objective(trial):
                    clf = SGDClassifier(random_state=0)
                    for step in range(100):
                        clf.partial_fit(X_train, y_train, np.unique(y))
                        intermediate_value = clf.score(X_valid, y_valid)
                        trial.report(intermediate_value, step=step)
                        if trial.should_prune():
                            raise optuna.TrialPruned()

                    return clf.score(X_valid, y_valid)


                study = optuna.create_study(direction="maximize")
                study.optimize(objective, n_trials=3)


        Args:
            value:
                A value returned from the objective function.
            step:
                Step of the trial (e.g., Epoch of neural network training). Note that pruners
                assume that ``step`` starts at zero. For example,
                :class:`~optuna.pruners.MedianPruner` simply checks if ``step`` is less than
                ``n_warmup_steps`` as the warmup mechanism.

        Raises:
            :exc:`NotImplementedError`:
                If trial is being used for multi-objective optimization.
            :exe:`ValueError`:
                If ``step`` is negative.
            :exe:`TypeError`:
                If the type of ``value`` is not :obj:`float`.
Report an objective function value for a given step.
Report an objective function value for a given step .
def report(self, value: float, step: int) -> None:
        """Report an objective function value for a given step.

        The reported values are used by the pruners to determine whether this trial should be
        pruned.

        .. seealso::
            Please refer to :class:`~optuna.pruners.BasePruner`.

        .. note::
            The reported value is converted to ``float`` type by applying ``float()``
            function internally. Thus, it accepts all float-like types (e.g., ``numpy.float32``).
            If the conversion fails, a ``TypeError`` is raised.

        .. note::
            If this method is called multiple times at the same ``step`` in a trial,
            the reported ``value`` only the first time is stored and the reported values
            from the second time are ignored.

        Example:

            Report intermediate scores of `SGDClassifier <https://scikit-learn.org/stable/modules/
            generated/sklearn.linear_model.SGDClassifier.html>`_ training.

            .. testcode::

                import numpy as np
                from sklearn.datasets import load_iris
                from sklearn.linear_model import SGDClassifier
                from sklearn.model_selection import train_test_split

                import optuna

                X, y = load_iris(return_X_y=True)
                X_train, X_valid, y_train, y_valid = train_test_split(X, y)


                def objective(trial):
                    clf = SGDClassifier(random_state=0)
                    for step in range(100):
                        clf.partial_fit(X_train, y_train, np.unique(y))
                        intermediate_value = clf.score(X_valid, y_valid)
                        trial.report(intermediate_value, step=step)
                        if trial.should_prune():
                            raise optuna.TrialPruned()

                    return clf.score(X_valid, y_valid)


                study = optuna.create_study(direction="maximize")
                study.optimize(objective, n_trials=3)


        Args:
            value:
                A value returned from the objective function.
            step:
                Step of the trial (e.g., Epoch of neural network training). Note that pruners
                assume that ``step`` starts at zero. For example,
                :class:`~optuna.pruners.MedianPruner` simply checks if ``step`` is less than
                ``n_warmup_steps`` as the warmup mechanism.

        Raises:
            :exc:`NotImplementedError`:
                If trial is being used for multi-objective optimization.
            :exe:`ValueError`:
                If ``step`` is negative.
            :exe:`TypeError`:
                If the type of ``value`` is not :obj:`float`.
        """

        if len(self.study.directions) > 1:
            raise NotImplementedError(
                "Trial.report is not supported for multi-objective optimization."
            )

        try:
            # For convenience, we allow users to report a value that can be cast to `float`.
            value = float(value)
        except (TypeError, ValueError):
            message = "The `value` argument is of type '{}' but supposed to be a float.".format(
                type(value).__name__
            )
            raise TypeError(message) from None

        if step < 0:
            raise ValueError("The `step` argument is {} but cannot be negative.".format(step))

        intermediate_values = self.storage.get_trial(self._trial_id).intermediate_values

        if step in intermediate_values:
            # Do nothing if already reported.
            warnings.warn(
                "The reported value is ignored because this `step` {} is already reported.".format(
                    step
                )
            )
            return

        self.storage.set_trial_intermediate_value(self._trial_id, step, value)
def report ( self , value : float , step : int ) -> None : if len ( self . study . directions ) > 1 : raise NotImplementedError ( "Trial.report is not supported for multi-objective optimization." ) try : # For convenience, we allow users to report a value that can be cast to `float`. value = float ( value ) except ( TypeError , ValueError ) : message = "The `value` argument is of type '{}' but supposed to be a float." . format ( type ( value ) . __name__ ) raise TypeError ( message ) from None if step < 0 : raise ValueError ( "The `step` argument is {} but cannot be negative." . format ( step ) ) intermediate_values = self . storage . get_trial ( self . _trial_id ) . intermediate_values if step in intermediate_values : # Do nothing if already reported. warnings . warn ( "The reported value is ignored because this `step` {} is already reported." . format ( step ) ) return self . storage . set_trial_intermediate_value ( self . _trial_id , step , value )