CellModules
pythonlib.OptunaWrapper.OptunaArchive Class Reference

Public Member Functions

def __init__ (self, study=None)
 
def set_study (self, study)
 
def register (self)
 
def context_add (self, str name, Any value)
 
def context_add_many (self, dict[str, Any] mapping)
 
def set_suggest_entrypoint (self, str name)
 
def set_run_entrypoint (self, str name)
 
def set_eval_entrypoint (self, str name)
 
def study_add_data (self, str key, Any value)
 
def study_add_axis (self, str name, Any values)
 
def trial_add_timeseries (self, trial, str key, Any values, list[str] axes, Optional[list[str]] columns=None, str value_col="value", str layout="aligned")
 
def check_minimal (self, bool require_run_function=True)
 

Static Public Member Functions

def trial_add_data (trial, str key, Any value)
 

Public Attributes

 study
 

Static Public Attributes

string KEY_ENTRY_SUGGEST = "entrypoint:suggest"
 
string KEY_ENTRY_RUN = "entrypoint:run"
 
string KEY_ENTRY_EVAL = "entrypoint:eval"
 
string KEY_CONTEXT = "backupContext"
 
string CONTEXT_ID = "__default__"
 

Private Member Functions

def _require_custom_db (self)
 
def _require_study (self)
 
def _ensure_isicell_tables (self)
 
def _flush_context_if_possible (self)
 
def _flush_entrypoints_if_possible (self)
 
dict[str, Any] _encode_context_value (self, Any value)
 
str _extract_sqlite_path_from_study (self, study)
 
def _set_entrypoint (self, str key, str name)
 

Static Private Member Functions

Any _to_jsonable (Any x)
 

Private Attributes

 _db_path
 
 _con_custom
 

Detailed Description

Lightweight helper to standardize what is stored in Optuna study/trial user_attrs.

Main idea:
- Typed helpers for trial outputs (timeseries)
- Explicit function registration (suggest/run/eval)
- Optional context capture via `with archiver.register(): ...`
  to archive helper functions + runtime objects automatically
  into study_user_attributes['backupContext'].

Definition at line 135 of file OptunaWrapper.py.

Constructor & Destructor Documentation

◆ __init__()

def pythonlib.OptunaWrapper.OptunaArchive.__init__ (   self,
  study = None 
)

Definition at line 155 of file OptunaWrapper.py.

Member Function Documentation

◆ _encode_context_value()

dict[str, Any] pythonlib.OptunaWrapper.OptunaArchive._encode_context_value (   self,
Any  value 
)
private
Context encoding policy:
- functions/classes/callables -> source code (mode='source') if possible
- JSON-serializable (after _to_jsonable) -> mode='json'
- fallback -> pickle64b

Definition at line 306 of file OptunaWrapper.py.

◆ _ensure_isicell_tables()

def pythonlib.OptunaWrapper.OptunaArchive._ensure_isicell_tables (   self)
private

Definition at line 201 of file OptunaWrapper.py.

◆ _extract_sqlite_path_from_study()

str pythonlib.OptunaWrapper.OptunaArchive._extract_sqlite_path_from_study (   self,
  study 
)
private
Extract sqlite file path from an Optuna study backed by RDBStorage(sqlite),
even if wrapped by _CachedStorage.

Definition at line 376 of file OptunaWrapper.py.

◆ _flush_context_if_possible()

def pythonlib.OptunaWrapper.OptunaArchive._flush_context_if_possible (   self)
private
Flush in-memory backupContext to custom table.
Upsert behavior (safe if called multiple times).

Definition at line 226 of file OptunaWrapper.py.

◆ _flush_entrypoints_if_possible()

def pythonlib.OptunaWrapper.OptunaArchive._flush_entrypoints_if_possible (   self)
private
Flush cached entrypoints to custom table.

Definition at line 258 of file OptunaWrapper.py.

◆ _require_custom_db()

def pythonlib.OptunaWrapper.OptunaArchive._require_custom_db (   self)
private

Definition at line 189 of file OptunaWrapper.py.

◆ _require_study()

def pythonlib.OptunaWrapper.OptunaArchive._require_study (   self)
private

Definition at line 196 of file OptunaWrapper.py.

◆ _set_entrypoint()

def pythonlib.OptunaWrapper.OptunaArchive._set_entrypoint (   self,
str  key,
str  name 
)
private
API inchangée:
  - vérifie que le symbole existe dans backupContext et est source-backed
  - stocke en cache + flush si possible

Definition at line 418 of file OptunaWrapper.py.

◆ _to_jsonable()

Any pythonlib.OptunaWrapper.OptunaArchive._to_jsonable ( Any  x)
staticprivate

Definition at line 282 of file OptunaWrapper.py.

◆ check_minimal()

def pythonlib.OptunaWrapper.OptunaArchive.check_minimal (   self,
bool   require_run_function = True 
)

Definition at line 531 of file OptunaWrapper.py.

◆ context_add()

def pythonlib.OptunaWrapper.OptunaArchive.context_add (   self,
str  name,
Any  value 
)

Definition at line 368 of file OptunaWrapper.py.

◆ context_add_many()

def pythonlib.OptunaWrapper.OptunaArchive.context_add_many (   self,
dict[str, Any]  mapping 
)

Definition at line 372 of file OptunaWrapper.py.

◆ register()

def pythonlib.OptunaWrapper.OptunaArchive.register (   self)
Capture newly created symbols in caller scope and store them in backupContext.

Example
-------
archiver = OptunaArchive(study)
with archiver.register():
    data = {...}
    def dataCatcherOnStep(...): ...
    def run_simu(...): ...
    def optim(trial): ...
# all new symbols now archived in study_user_attributes['backupContext']

Definition at line 328 of file OptunaWrapper.py.

◆ set_eval_entrypoint()

def pythonlib.OptunaWrapper.OptunaArchive.set_eval_entrypoint (   self,
str  name 
)

Definition at line 456 of file OptunaWrapper.py.

◆ set_run_entrypoint()

def pythonlib.OptunaWrapper.OptunaArchive.set_run_entrypoint (   self,
str  name 
)

Definition at line 453 of file OptunaWrapper.py.

◆ set_study()

def pythonlib.OptunaWrapper.OptunaArchive.set_study (   self,
  study 
)

Definition at line 172 of file OptunaWrapper.py.

◆ set_suggest_entrypoint()

def pythonlib.OptunaWrapper.OptunaArchive.set_suggest_entrypoint (   self,
str  name 
)

Definition at line 450 of file OptunaWrapper.py.

◆ study_add_axis()

def pythonlib.OptunaWrapper.OptunaArchive.study_add_axis (   self,
str  name,
Any  values 
)

Definition at line 473 of file OptunaWrapper.py.

◆ study_add_data()

def pythonlib.OptunaWrapper.OptunaArchive.study_add_data (   self,
str  key,
Any  value 
)

Definition at line 462 of file OptunaWrapper.py.

◆ trial_add_data()

def pythonlib.OptunaWrapper.OptunaArchive.trial_add_data (   trial,
str  key,
Any  value 
)
static

Definition at line 467 of file OptunaWrapper.py.

◆ trial_add_timeseries()

def pythonlib.OptunaWrapper.OptunaArchive.trial_add_timeseries (   self,
  trial,
str  key,
Any  values,
list[str]  axes,
Optional[list[str]]   columns = None,
str   value_col = "value",
str   layout = "aligned" 
)
Store trial-level flattened values and a study-level spec.

layout='product' : cartesian product of axes
layout='aligned' : zipped/aligned axes (same length as values)

Definition at line 480 of file OptunaWrapper.py.

Member Data Documentation

◆ _con_custom

pythonlib.OptunaWrapper.OptunaArchive._con_custom
private

Definition at line 182 of file OptunaWrapper.py.

◆ _db_path

pythonlib.OptunaWrapper.OptunaArchive._db_path
private

Definition at line 174 of file OptunaWrapper.py.

◆ CONTEXT_ID

string pythonlib.OptunaWrapper.OptunaArchive.CONTEXT_ID = "__default__"
static

Definition at line 153 of file OptunaWrapper.py.

◆ KEY_CONTEXT

string pythonlib.OptunaWrapper.OptunaArchive.KEY_CONTEXT = "backupContext"
static

Definition at line 150 of file OptunaWrapper.py.

◆ KEY_ENTRY_EVAL

string pythonlib.OptunaWrapper.OptunaArchive.KEY_ENTRY_EVAL = "entrypoint:eval"
static

Definition at line 149 of file OptunaWrapper.py.

◆ KEY_ENTRY_RUN

string pythonlib.OptunaWrapper.OptunaArchive.KEY_ENTRY_RUN = "entrypoint:run"
static

Definition at line 148 of file OptunaWrapper.py.

◆ KEY_ENTRY_SUGGEST

string pythonlib.OptunaWrapper.OptunaArchive.KEY_ENTRY_SUGGEST = "entrypoint:suggest"
static

Definition at line 147 of file OptunaWrapper.py.

◆ study

pythonlib.OptunaWrapper.OptunaArchive.study

Definition at line 156 of file OptunaWrapper.py.


The documentation for this class was generated from the following file: