CellModules
pythonlib.OptunaWrapper.OptunaDB Class Reference

Public Member Functions

def __init__ (self, str db_path, bool readonly=True)
 
def close (self)
 
list[str] studies (self)
 
str trial_to_study (self, int trial_id)
 
dict[str, Any] study_attrs (self, str study_name)
 
pd.DataFrame trial_attrs (self, str study_name, Optional[str] key=None)
 
pd.DataFrame fitness_long (self, Optional[str] study_name=None)
 
pd.DataFrame fitness_wide (self, Optional[str] study_name=None)
 
pd.DataFrame params (self, Optional[str] study_name=None)
 
pd.DataFrame get_trial_timeseries (self, str key, study_name=None, trial_ids=None)
 
pd.DataFrame get_trial_data (self, str key, study_name=None, trial_ids=None, raw=False, sep='.')
 
Any context_value (self, str name)
 
dict[str, Any] load_context (self)
 
dict[str, Any] get_trial_params_flat (self, int trial_id)
 
def build_params (self, int trial_id)
 
def plot_param_distributions (self, float fitness_threshold=1500, int objective=0, study_name=None, trial_ids=None, float figsize_width=11, float row_height=0.42, float min_fig_height=3.0, int label_fontsize=8, float min_cat_label_width=0.08, int max_cat_label_len=14)
 

Public Attributes

 db_path
 
 con
 
 suggest_fn
 
 run_fn
 
 eval_fn
 

Static Public Attributes

string CONTEXT_ID = "__default__"
 

Private Member Functions

def _normalize_ids (self, x, cast=int, name="ids")
 
def _sql_in_clause (self, values)
 
bool _has_isicell_tables (self)
 
list[tuple[str, str, str]] _read_isicell_context_rows (self)
 
dict[str, str] _read_isicell_entrypoints (self)
 

Static Private Member Functions

Any _decode_json_runtime_value (Any v)
 
Any _coerce_param_value (Any x)
 

Detailed Description

Read-only Optuna SQLite helper (fast SQL) + archived function loading (exec) + replay-ready helpers.

Context and entrypoints are read from custom tables:
  - isicell_context
  - isicell_context_entrypoints

Study-specific metadata (axes, timeseries specs, etc.) remains in study_user_attributes.

Definition at line 565 of file OptunaWrapper.py.

Constructor & Destructor Documentation

◆ __init__()

def pythonlib.OptunaWrapper.OptunaDB.__init__ (   self,
str  db_path,
bool   readonly = True 
)

Definition at line 578 of file OptunaWrapper.py.

Member Function Documentation

◆ _coerce_param_value()

Any pythonlib.OptunaWrapper.OptunaDB._coerce_param_value ( Any  x)
staticprivate

Definition at line 1139 of file OptunaWrapper.py.

◆ _decode_json_runtime_value()

Any pythonlib.OptunaWrapper.OptunaDB._decode_json_runtime_value ( Any  v)
staticprivate

Definition at line 1071 of file OptunaWrapper.py.

◆ _has_isicell_tables()

bool pythonlib.OptunaWrapper.OptunaDB._has_isicell_tables (   self)
private

Definition at line 1022 of file OptunaWrapper.py.

◆ _normalize_ids()

def pythonlib.OptunaWrapper.OptunaDB._normalize_ids (   self,
  x,
  cast = int,
  name = "ids" 
)
private
Normalize None | scalar | iterable -> None | list[cast(x)].
Strings are treated as scalars (not iterables).

Definition at line 741 of file OptunaWrapper.py.

◆ _read_isicell_context_rows()

list[tuple[str, str, str]] pythonlib.OptunaWrapper.OptunaDB._read_isicell_context_rows (   self)
private
Returns rows: (key, mode, payload) for CONTEXT_ID.

Definition at line 1033 of file OptunaWrapper.py.

◆ _read_isicell_entrypoints()

dict[str, str] pythonlib.OptunaWrapper.OptunaDB._read_isicell_entrypoints (   self)
private
Returns {"suggest": "optim", "run": "run_simu", ...}

Definition at line 1050 of file OptunaWrapper.py.

◆ _sql_in_clause()

def pythonlib.OptunaWrapper.OptunaDB._sql_in_clause (   self,
  values 
)
private
Returns ('(?,?,?)', [..]) for SQL IN clauses.
values must be a non-empty list.

Definition at line 760 of file OptunaWrapper.py.

◆ build_params()

def pythonlib.OptunaWrapper.OptunaDB.build_params (   self,
int  trial_id 
)
Rebuild structured params from flat optuna params using archived suggest_fn.
Handles categorical params stored as category indices.

Definition at line 1175 of file OptunaWrapper.py.

◆ close()

def pythonlib.OptunaWrapper.OptunaDB.close (   self)

Definition at line 597 of file OptunaWrapper.py.

◆ context_value()

Any pythonlib.OptunaWrapper.OptunaDB.context_value (   self,
str  name 
)
Return a data object from the shared isicell context (json/pickle only).

Definition at line 1081 of file OptunaWrapper.py.

◆ fitness_long()

pd.DataFrame pythonlib.OptunaWrapper.OptunaDB.fitness_long (   self,
Optional[str]   study_name = None 
)

Definition at line 669 of file OptunaWrapper.py.

◆ fitness_wide()

pd.DataFrame pythonlib.OptunaWrapper.OptunaDB.fitness_wide (   self,
Optional[str]   study_name = None 
)

Definition at line 694 of file OptunaWrapper.py.

◆ get_trial_data()

pd.DataFrame pythonlib.OptunaWrapper.OptunaDB.get_trial_data (   self,
str  key,
  study_name = None,
  trial_ids = None,
  raw = False,
  sep = '.' 
)

Definition at line 947 of file OptunaWrapper.py.

◆ get_trial_params_flat()

dict[str, Any] pythonlib.OptunaWrapper.OptunaDB.get_trial_params_flat (   self,
int  trial_id 
)

Definition at line 1161 of file OptunaWrapper.py.

◆ get_trial_timeseries()

pd.DataFrame pythonlib.OptunaWrapper.OptunaDB.get_trial_timeseries (   self,
str  key,
  study_name = None,
  trial_ids = None 
)

Definition at line 769 of file OptunaWrapper.py.

◆ load_context()

dict[str, Any] pythonlib.OptunaWrapper.OptunaDB.load_context (   self)
Build exec namespace from shared isicell_context + caller namespace.
Source-backed symbols are exec'ed into the same namespace.
Entrypoints are resolved from isicell_context_entrypoints.

Definition at line 1102 of file OptunaWrapper.py.

◆ params()

pd.DataFrame pythonlib.OptunaWrapper.OptunaDB.params (   self,
Optional[str]   study_name = None 
)

Definition at line 708 of file OptunaWrapper.py.

◆ plot_param_distributions()

def pythonlib.OptunaWrapper.OptunaDB.plot_param_distributions (   self,
float   fitness_threshold = 1500,
int   objective = 0,
  study_name = None,
  trial_ids = None,
float   figsize_width = 11,
float   row_height = 0.42,
float   min_fig_height = 3.0,
int   label_fontsize = 8,
float   min_cat_label_width = 0.08,
int   max_cat_label_len = 14 
)
Plot normalized distributions of selected trials' parameters:
- numeric params: violin plots on x in [0, 1]
- categorical params: stacked horizontal bars of frequencies on x in [0, 1]

Selection logic:
- keep completed trials with fitness(objective) < fitness_threshold
- optional filter by study_name and/or trial_ids

Notes
-----
- Requires self.suggest_fn (loaded from isicell context) to infer param bounds/types.
- Assumes categorical params in trial_params are stored as category indices (Optuna/LHSIterator path).
- Uses seaborn + matplotlib (imported lazily).

Definition at line 1202 of file OptunaWrapper.py.

◆ studies()

list[str] pythonlib.OptunaWrapper.OptunaDB.studies (   self)

Definition at line 603 of file OptunaWrapper.py.

◆ study_attrs()

dict[str, Any] pythonlib.OptunaWrapper.OptunaDB.study_attrs (   self,
str  study_name 
)

Definition at line 621 of file OptunaWrapper.py.

◆ trial_attrs()

pd.DataFrame pythonlib.OptunaWrapper.OptunaDB.trial_attrs (   self,
str  study_name,
Optional[str]   key = None 
)

Definition at line 633 of file OptunaWrapper.py.

◆ trial_to_study()

str pythonlib.OptunaWrapper.OptunaDB.trial_to_study (   self,
int  trial_id 
)

Definition at line 607 of file OptunaWrapper.py.

Member Data Documentation

◆ con

pythonlib.OptunaWrapper.OptunaDB.con

Definition at line 581 of file OptunaWrapper.py.

◆ CONTEXT_ID

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

Definition at line 576 of file OptunaWrapper.py.

◆ db_path

pythonlib.OptunaWrapper.OptunaDB.db_path

Definition at line 579 of file OptunaWrapper.py.

◆ eval_fn

pythonlib.OptunaWrapper.OptunaDB.eval_fn

Definition at line 587 of file OptunaWrapper.py.

◆ run_fn

pythonlib.OptunaWrapper.OptunaDB.run_fn

Definition at line 586 of file OptunaWrapper.py.

◆ suggest_fn

pythonlib.OptunaWrapper.OptunaDB.suggest_fn

Definition at line 585 of file OptunaWrapper.py.


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