def from_optuna()

in hiplot/experiment.py [0:0]


    def from_optuna(study: "optuna.study.Study") -> "Experiment":  # No type hint to avoid having optuna as an additional dependency
        """
        Creates a HiPlot experiment from a Optuna Study.

        :param study: Optuna Study
        """

        # Create a list of dictionary objects using study trials
        # All parameters are taken using params.copy()
        # pylint: disable=redefined-outer-name
        import optuna

        hyper_opt_data = []
        for each_trial in study.get_trials(states=(optuna.trial.TrialState.COMPLETE, )):
            trial_params = {}
            # This checks if the trial was fully completed
            # the value will be None if the trial was interrupted halfway (e.g. via KeyboardInterrupt)
            if not each_trial.values:
                continue
            num_objectives = len(each_trial.values)

            if num_objectives == 1:
                # name = value, as it could be RMSE / accuracy, or any value that the user selects for tuning
                trial_params["value"] = each_trial.value
            else:
                for objective_id, value in enumerate(each_trial.values):
                    trial_params[f"value_{objective_id}"] = value

            trial_params["uid"] = each_trial.number
            trial_params.update(each_trial.params.copy())
            hyper_opt_data.append(trial_params)
        experiment = Experiment.from_iterable(hyper_opt_data)

        return experiment