odatse.algorithm.ttopt module#
- class odatse.algorithm.ttopt.Algorithm(info: Info, runner: Runner | None = None, domain: Region | None = None, run_mode: str = 'initial')[source]#
Bases:
AlgorithmBaseTensor-Train Optimization (TTOpt) algorithm implementation.
This class implements the TTOpt algorithm. It is an optimization method that searches for function minima by considering an implicit tensor-train decomposition of a large tensor whose elements correspond to evaluation of the target function at various points in the parameter space.
- bounds#
Lower and upper bounds along each dimension. It is constructed from a Domain object based on the min_list and max_list parameters.
- Type:
np.ndarray
- p_points#
The number of coarse modes in the parameter space for each dimension (default: [2]*n_dim). Each dimension is effectively discretized into p^q uniformly-spaced points. It is recommended to have p=2 along each dimension.
- Type:
np.ndarray
- q_points#
The number of fine submodes in the parameter space for each dimension (default: [1]*n_dim). Each dimension is effectively discretized into p^q uniformly-spaced points. This parameter determines the fineness of each mode.
- Type:
np.ndarray
- r_max#
The maximum rank of the implicit tensor-train decomposition (default: 4).
- Type:
int
- max_f_eval#
The maximum number of function evaluations (default: 10000).
- Type:
int
- maxvol_tol#
The tolerance needed for early stopping in the maxvol subroutine. Meaningful values are larger than 1 (default: 1.001).
- Type:
float
- maxvol_max_it#
The maximum number of maxvol iterations each time the maxvol subroutine is called (default: 1000).
- Type:
int
- save_eval_history#
If True, stream
ttopt_eval_history.txtunder the output directory while running (rank 0 only; default: True). Rows are flushed when the in-memory buffer reacheseval_history_buffer_rowspoints.- Type:
bool
- eval_history_buffer_rows#
Number of evaluation rows to buffer in memory before appending to disk (default: 256).
- Type:
int
- init_points#
Initial points in physical coordinates to evaluate at the start of optimization. (default: None).
- Type:
Optional[np.ndarray]
- xopt#
The optimal solution.
- Type:
Optional[np.ndarray]
- fopt#
The optimal function value.
- Type:
Optional[float]
Initialize the Algorithm class.
- Parameters:
info (odatse.Info) – Information object containing algorithm parameters.
runner (odatse.Runner, optional) – Runner object for executing the algorithm.
run_mode (str, optional) – Mode to run the algorithm in, by default “initial”.
- __init__(info: Info, runner: Runner | None = None, domain: Region | None = None, run_mode: str = 'initial') None[source]#
Initialize the Algorithm class.
- Parameters:
info (odatse.Info) – Information object containing algorithm parameters.
runner (odatse.Runner, optional) – Runner object for executing the algorithm.
run_mode (str, optional) – Mode to run the algorithm in, by default “initial”.
- _apply_state(data: dict, mode: str = 'resume', restore_rng: bool = True) None[source]#
Restore algorithm state from a checkpoint snapshot.
Validates the MPI configuration and structural consistency (n_q_dims), optionally restores the RNG, then applies all fields listed in
_checkpoint_attrs. The structural fields rebuilt by_setup_structure()(grids, n_points, etc.) are not restored from the checkpoint because they are deterministic functions of the configuration parameters.Must be called after
_setup_structure()so thatself.n_q_dimsreflects the current configuration and can be compared with the saved value.- Parameters:
data (dict) – Snapshot previously produced by
__getstate__.mode (str) –
"resume"or"continue"; TTOpt treats them identically.restore_rng (bool) – When True, restore the RNG state from data.
- _init_counters() None[source]#
Reset evaluation counters and the eval-history file handle.
Called on every run mode so that the history file is opened fresh.
- _init_poi() None[source]#
Evaluate init_points and initialize poi/tt_ranks via maxvol.
Called only for fresh runs (mode
"initial"). On resume the poi and tt_ranks are restored from the checkpoint instead.
- _initialize()[source]#
Set up initial algorithm state for a fresh run (init mode).
Called by
prepare()whenmodestarts with"init". Must not use the runner (evaluation happens later in_run()).
- _load_state(filename, mode='resume', restore_rng=True) None[source]#
Read a checkpoint file and defer applying it until
_prepare().The snapshot is not applied here:
_prepare()first rebuilds the deterministic structural fields (which would otherwise clobber the restored poi/tt_ranks/counters), and only then calls_apply_state.- Parameters:
filename (str) – Path to the checkpoint file.
mode (str, optional) –
"resume"or"continue". TTOpt does not distinguish between them: the evaluation budgetmax_f_evalis re-read from the input file on every run and is deliberately not checkpointed, whilef_eval_countis. Raisingmax_f_evaland restarting therefore extends the search in either mode.restore_rng (bool, optional) – Whether the RNG state should be restored when the snapshot is applied.
- _prepare() None[source]#
Prepare the TT decomposition structure and (for fresh runs) the initial poi.
The deterministic structural fields are always rebuilt from config and the counters reset. On resume the checkpoint snapshot (already read by prepare()’s dispatch into
self._resume_data) is applied here, after the structural rebuild, so that the restored poi/tt_ranks/counters are not clobbered by_setup_structure()/_init_counters(). For a fresh run the initial poi is built frominit_pointsinstead.