minto.v0#

Submodules#

Classes#

Experiment

Manage and track mathematical optimization experiments efficiently.

SchemaBasedTable

Functions#

load(→ minto.v0.experiment.experiment.Experiment)

Package Contents#

class Experiment(name: str | None = None, savedir: str | pathlib.Path = DEFAULT_RESULT_DIR)#

Manage and track mathematical optimization experiments efficiently.

This class is designed to simplify the process of managing and analyzing data from mathematical optimization experiments. It abstracts away the complexities associated with data logging, storage, and retrieval, making it easier to focus on experiment design and result interpretation. Users are encouraged to utilize the logging functions provided to capture comprehensive details about their experiments, thereby enhancing the reproducibility and accessibility of their experimental work.

Parameters:
  • name (str, optional) – The unique name of the experiment, automatically generated if not provided, to identify and differentiate it from others.

  • savedir (str or pathlib.Path, optional) – The directory path for saving experiment data, including logs, solver configurations, parameters, and results. If not specified, a default directory is used.

Examples

Basic usage with manual parameter and result logging: >>> import minto >>> exp = minto.v0.Experiment(name=”trial_01”) >>> x = 2 >>> y = x ** 2 >>> with exp.run(): … exp.log_parameter(“x”, x) … exp.log_result(“y”, y) >>> exp.table()

experiment_name run_id x y

0 trial_01 0 2 4

Logging in iterative processes: >>> exp = minto.v0.Experiment(name=”trial_02”) >>> for x in range(3): … y = x ** 2 … with exp.run(): … exp.log_parameter(“x”, x) … exp.log_result(“y”, y) >>> exp.table()

experiment_name run_id x y

0 trial_02 0 0 0 1 trial_02 1 1 1 2 trial_02 2 2 4

Integrating with optimization solvers and logging complex objects such as problems and samplesets: >>> import jijzept as jz >>> import jijmodeling as jm >>> problem = jm.Problem(“test”) >>> x = jm.BinaryVar(“x”, shape=(3,)) >>> problem += x[:].sum() >>> problem += jm.Constraint(“onehot”, x[:].sum() == 1) >>> sampler = jz.JijSASampler(config=”config.toml”) >>> sampler_args = {“search”: True, “num_search”: 10} >>> sampleset = sampler.sample_model(problem, {}, **sampler_args) >>> exp = minto.v0.Experiment(“trial_03”) >>> with exp.run(): … exp.log_parameter(“problem”, problem) … exp.log_parameters(sampler_args) … exp.log_solver(“solver”, sampler.sample_model) … exp.log_result(“sampleset”, sampleset) >>> exp.table() Output is a DataFrame with experiment results, including solver and sampleset details.

Saving experiment data for future reference and reproducibility: >>> exp.save()

name = ''#
savedir#
run() Experiment#

Start the experiment and create a unique ID. This method updates the internal database of the experiment, creating a new record that records the experiment data. It creates an environment for recording parameters, solvers, and results.

Returns:

Returns the Experiment instance.

Return type:

Experiment

table(key: Literal['solver', 'parameter', 'result'] | None = None, enable_sampleset_expansion: bool = True) pandas.DataFrame#

Compiled the logged data and returned as a pandas DataFrame.

Parameters:
  • key ({'solver', 'parameter', 'result', None}, optional) – Specifies which part of the experiment data to return. If None, merges all available data into a single DataFrame.

  • enable_sampleset_expansion (bool, default True) – Enables the expansion of SampleSet objects into tabular form, if present within the results data.

Returns:

If no key is specified, a merged DataFrame of the entire experiment, or a partial DataFrame specified by the key.

Return type:

DataFrame

log_solver(name: str, solver: Callable[Ellipsis, Any]) None#

Log data about the solver used in the experiment.

Parameters:
  • name (str) – The name assigned to the solver for identification.

  • solver (Callable[..., Any]) – The solver object to be logged.

log_solvers(solvers: dict[str, Callable[Ellipsis, Any]]) None#

Logs multiple solvers at once.

Parameters:

solvers (dict[str, Callable[..., Any]]) – A dictionary where keys are solver names and values are the solver objects.

log_parameter(name: str, parameter: Any) None#

Log a single parameter used in the experiment.

Parameters:
  • name (str) – The name assigned to the parameter for identification.

  • parameter (Any) – The value of the parameter to be logged.

log_parameters(parameters: dict[str, Any]) None#

Logs multiple parameters at once.

Parameters:

parameters (dict[str, Any]) – A dictionary where keys are parameter names and values are the parameter values to be logged.

log_result(name: str, result: Any) None#

Log a single result from the experiment.

Parameters:
  • name (str) – The name assigned to the result for identification.

  • result (Any) – The data or outcome to be logged as a result.

log_results(results: dict[str, Any]) None#

Logs multiple results at once.

Parameters:

results (dict[str, Any]) – A dictionary where keys are result names and values are the data or outcomes to be logged.

save() None#

Writes out all log data for parameters, solvers, and results. The data is saved under “savedir / experiment.name” directory.

load(experiment_name: str, savedir: str | pathlib.Path = DEFAULT_RESULT_DIR) minto.v0.experiment.experiment.Experiment#
class SchemaBasedTable(schema: dict[str, Type[Any]])#
property records: list[minto.v0.records.records.Record]#
property schema: dict[str, Type[Any]]#
property pandas_dtypes: dict[str, Any]#
classmethod from_dataframe(dataframe: pandas.DataFrame) SchemaBasedTable#
classmethod from_dict(dct: minto.v0.typing.ArtifactDataType) SchemaBasedTable#
insert(record: dict[str, Any] | minto.v0.records.records.Record | pandas.Series[Any] | list[Any] | tuple[Any, Ellipsis]) None#

Insert a new record.

Parameters:

record (dict[str, Any] | Record | Series[Any] | list[Any] | tuple[Any, ...]) – The record to be appended.

empty() bool#

Returns True if the Container is empty.

dataframe() pandas.DataFrame#
dict() minto.v0.typing.ArtifactDataType#