discrete_optimization.generic_tools.study package

Submodules

discrete_optimization.generic_tools.study.database module

class discrete_optimization.generic_tools.study.database.Database[source]

Bases: ABC

Base class for database storing experiments.

By default, we assume a database is associated with a given study. But it could be implemented so that it can store several studies at once.

d-o experiments: - instance => string representing problem used - config:

  • name: can be empty, but useful to have a simple name for the config

  • solver: e.g. class name

  • params: hyperparameters used (nested dict whose leaves should be hashable, and preferably jsonable)

  • status: status of tge solver at then of the solve process

  • metrics: timeseries of objective, bound, …

close() None[source]

Close the database.

abstract get_new_experiment_id() int[source]
abstract load() list[Experiment][source]

Load all experiments of the study.

load_results() list[DataFrame][source]

Load all experiments as time-indexes dataframes with metadata in attrs attribute.

abstract store(xp: Experiment) None[source]

Store the experiment in the database.

Could store a complete experiment. Depending on implementations, could also support storing a partial experiment, and then overwriting with a complete experiment by re-calling store on an experiment with same id and more data.

class discrete_optimization.generic_tools.study.database.Hdf5Database(filepath: str)[source]

Bases: Database

Database based on hdf5 format.

close() None[source]

Close the database.

get_new_experiment_id() int[source]
load() list[Experiment][source]

Load all experiments of the study.

store(xp: Experiment) None[source]

Store the experiment in the database.

Could store a complete experiment. Depending on implementations, could also support storing a partial experiment, and then overwriting with a complete experiment by re-calling store on an experiment with same id and more data.

store_metadata(xp: Experiment) None[source]
store_metrics(xp: Experiment) None[source]

discrete_optimization.generic_tools.study.experiment module

class discrete_optimization.generic_tools.study.experiment.DoJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

default(o)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class discrete_optimization.generic_tools.study.experiment.Experiment(xp_id: int, instance: str, status: str, config: SolverJsonableConfig, metrics: DataFrame, reason: str = '')[source]

Bases: object

Experiment of a d-o study.

config: SolverJsonableConfig
classmethod from_solver_config(xp_id: int, instance: str, status: str | StatusSolver, solver_config: SolverConfig, metrics: DataFrame, config_name: str | None = None, reason: str = '')[source]
get_metadata_as_a_record() dict[str, Any][source]
get_metadata_as_nested_dict() dict[str, ConfigDict | Hashable][source]
instance: str
metrics: DataFrame
reason: str = ''
status: str
to_df()[source]

Convert to a dataframe (metrics) with metadata store in attrs attribute.

xp_id: int
class discrete_optimization.generic_tools.study.experiment.SolverConfig(cls: 'type[SolverDO]', kwargs: 'dict[str, Any]')[source]

Bases: object

cls: type[SolverDO]
kwargs: dict[str, Any]
class discrete_optimization.generic_tools.study.experiment.SolverJsonableConfig(solver: str, parameters: dict[str, ConfigDict | Hashable], name: str | None = None)[source]

Bases: object

Config representing solver used with its tuning.

as_nested_dict() dict[str, ConfigDict | Hashable][source]
classmethod from_record(record)[source]
classmethod from_solver_config(config: SolverConfig, name: str | None = None)[source]
classmethod from_xp_metadata_record(record)[source]
get_json_parameters() str[source]

Jsonify the config parameters attribute.

get_record() dict[str, str | None][source]
name: str | None = None
parameters: dict[str, ConfigDict | Hashable]
solver: str
class discrete_optimization.generic_tools.study.experiment.Study(name: 'str', instances: 'list[str]', solver_configs: 'list[SolverConfig]')[source]

Bases: object

instances: list[str]
name: str
solver_configs: list[SolverConfig]

Module contents