def METHOD_NAME(objective, config, total_number_trials):
    try:
        seed = int(config['numerical_settings']['seed'])
        study_name = config['training']['study_name']
        direction = config['training']['direction']
        storage_url = config['training']['storage']
        storage_timeout = config['training']['storage_timeout']
        load_if_exists = config['training']['load_if_exists']
        n_trials = int(config['training']['trials'])
        n_jobs = int(config['training']['jobs'])
        job_timeout = config['training']['timeout']
        job_timeout = int(job_timeout) if job_timeout is not None else job_timeout
        logDir = objective.objConfig['log_dir']
        if storage_url:
            storage = optuna.storages.RDBStorage(
            url=storage_url,
            engine_kwargs={"connect_args": {"timeout": storage_timeout}},
            )
        else:
            storage = None
        if n_trials==0 and storage is None:
            logging.error('Storage must be specified if the number of hpo trials is set to zero.')
            return
        study = create_study(direction=direction, seed=seed, storage=storage, study_name=study_name, load_if_exists=load_if_exists)
        decorator = create_objective_decorator(objective, total_number_trials)
        logging.info('starting HPO')
        study.optimize(decorator, n_trials=n_trials, n_jobs=n_jobs, timeout=job_timeout,
                catch = (RuntimeError, ValueError, TypeError), callbacks=[callback_on_trial_finished],
                gc_after_trial=True)
        logging.info('finished HPO')
        log_and_save(study, logDir, get_statistics(study))
        best_value = study.best_trial.value
        return best_value
    except BaseException as exc:
        print(exc)
        logging.exception('finished with exception', exc_info=True)
        raise exc
    else:
        logging.info('finished successfully')