Optimizer
This class orchestrates hyperparameter optimization trials using the Optuna library. It manages the creation of optimization studies, defines an objective function to be evaluated, and controls the number of trials and concurrency level. The optimizer can log trial progress and asynchronously execute trials, reporting results back to the Optuna study.
Attributes
-
n_trials: int
- the number of trials to run
-
concurrency: int = 1
- the number of trials to run concurrently
-
objective: callable
- the objective function to optimize
-
delay: float = 0.1
- the delay between trials
-
log_delay: float = 0.1
- the delay between logging
-
study: optuna.Study
- the optuna study object
Constructors
-
Initializes the Optimizer with an objective function, number of trials, and optional concurrency and delay settings.
-
Parameters
- objective: callable
- The objective function to optimize. It should accept a dictionary of parameters and return a value.
- n_trials: int
- The total number of trials to run.
- concurrency: int
- The maximum number of trials to run concurrently.
- delay: float
- The delay in seconds between the completion of one trial and the start of another.
- study: Optional[optuna.Study]
- An optional existing Optuna study to use. If not provided, a new study will be created.
- log_delay: float
- The delay in seconds between logging trial status updates.
- objective: callable
Methods
def log()
-
Logs the current state of the study trials periodically.
-
Return Value: None
- This method does not return any value.
def spawn(semaphore: asyncio.Semaphore) - > None
-
Spawns a single trial, managing concurrency and handling trial execution and result reporting.
-
Parameters
- semaphore: asyncio.Semaphore
- An asyncio semaphore to limit concurrent executions.
- semaphore: asyncio.Semaphore
-
Return Value: None
- This method does not return any value.