class_docstr: Callable objective function to be used with optuna.
class_docstr_tok: ["Callable","objective","function","to","be","used","with","optuna","."]
code: def __call__(self, trial: BaseTrial) -> float:
      if self.artifacts:
          trial_folder = self.artifacts_folder / str(trial.number)
          trial_folder.mkdir(parents=True, exist_ok=True)
      # Sample hyperparameters
      hyperparams = suggest_callable_hyperparams(trial, self.configs)
      hyperparams.pop("classpath", None)
      # Separate hyperparameters of each part
      (
          inprocessing_hyperparams,
          preprocessing_hyperparams,
          postprocessing_hyperparams,
      ) = self.separate_configs(hyperparams)
  
      # Construct model parts
      preprocessing = self.preprocessing_method(
          **preprocessing_hyperparams
      )
      inprocessing = self.inprocessing_method(
          **inprocessing_hyperparams
      )
      postprocessing = self.postprocessing_method(
          **postprocessing_hyperparams
      )
  
      # Train model
      start_time = time.process_time()
      preprocessing.fit(self.X_train, self.y_train, self.s_train)
      preprocessing_output = preprocessing.transform(
          self.X_train,
          self.y_train,
          self.s_train,
      )
      inprocessing.fit(*preprocessing_output)
  
      elapsed_process_time = time.process_time() - start_time
      logging.info(
          f"Trial {trial.number} took {elapsed_process_time}s to train."
      )
  
      # Evaluate model on validation data
      val_results = self.evaluate_model(
          model=(
              preprocessing,
              inprocessing,
              postprocessing,
              self.threshold,
          ),
          X=self.X_val,
          y=self.y_val,
          s=self.s_val,
          number=trial.number,
          type="validation",
      )
      if "methods" in self.artifacts:
          with open(
              trial_folder / "preprocessing.pickle", "wb"
          ) as file:
              pickle.dump(preprocessing, file)
          with open(trial_folder / "inprocessing.pickle", "wb") as file:
              pickle.dump(inprocessing, file)
          with open(
              trial_folder / "postprocessing.pickle", "wb"
          ) as file:
              pickle.dump(postprocessing, file)
          with open(trial_folder / "threshold.pickle", "wb") as file:
              pickle.dump(self.threshold, file)
      # Optionally, evaluate on test data as well (just to save results)
      test_results = None
      if self.X_test is not None and self.y_test is not None:
          test_results = self.evaluate_model(
              model=(
                  preprocessing,
                  inprocessing,
                  postprocessing,
                  self.threshold,
              ),
              X=self.X_test,
              y=self.y_test,
              s=self.s_test,
              number=trial.number,
              type="test",
          )
  
      # Store trial's results
      self._models_results.append(
          Result(
              id=trial.number,
              hyperparameters=hyperparams,
              validation_results=val_results,
              test_results=test_results,
              fit_time=elapsed_process_time,
          )
      )
  
      # Return scalarized evaluation metric
      if self.other_eval_metric:
          assert self.alpha is not None
          return val_results[
              self.eval_metric
          ] * self.alpha + val_results[self.other_eval_metric] * (
              1 - self.alpha
          )
  
      # Or simply a single evaluation metric value
      else:
          return val_results[self.eval_metric]
  
imports: import dataclasses
  import logging
  import pickle
  import time
  from pathlib import Path
  from typing import Optional, Union
  import numpy
  import pandas
  from hpt.suggest import suggest_callable_hyperparams
  from omegaconf import DictConfig, OmegaConf
  from optuna.trial import BaseTrial
  from ..evaluation import evaluate_fairness, evaluate_performance
  from ..methods import InProcessing, PostProcessing, PreProcessing
  from ..methods.postprocessing.threshold import Threshold
label_desc: Use image node_id 6 for calling the ObjectiveFunction obj's underlying member method code with example usage: obj.__call__(trial) and returns: unknown, val_results