multiml.agent package

Subpackages

Submodules

Module contents

class multiml.agent.Agent

Bases: object

Base class of Agent.

abstract execute()

Execute Agent.

abstract finalize()

Finalize Agent.

class multiml.agent.Metric

Bases: object

Abstraction class of metric calculation.

abstract calculate()

Return calculated metric.

class multiml.agent.BaseAgent(saver=None, storegate=None, task_scheduler=None, metric=None, metric_args=None)

Bases: Agent

Base class of agent.

All agent class need to inherit this BaseAgent class.

__init__(saver=None, storegate=None, task_scheduler=None, metric=None, metric_args=None)

Initialize base agent.

Parameters:
  • saver (Saver or str) – Saver class instance. If saver is None, Saver class instance is created without any args. If If saver is str, Saver` class instance is created with given save_dir.

  • storegate (StoreGate or dict) – StoreGate class instance. If dict is given, StoreGate class instance is created with given dict args.

  • task_scheduler (TaskScheduler or list) – TaskScheduler class instance. If ordered tasks (list) are given, TaskScheduler is initialized with ordered tasks. Please see TaskScheduler class for details.

  • metric (str or BaseMetric) – str or Metric class instance. If str is given, Metric class is searched from multiml.agent.metric, and initialized with metric_args below.

  • metric_args (dict) – arbitrary args of Metric class. This option is valid only if metric is str.

execute()

Execute base agent.

Users need to implement algorithms.

finalize()

Finalize base agent.

execute_finalize()

Execute and finalize base agent.

property storegate

Return storegate of base agent.

property saver

Return saver of base agent.

property task_scheduler

Return task_scheduler of base agent.

property metric

Return metric of base agent.

class multiml.agent.SequentialAgent(differentiable=None, diff_pretrain=False, diff_task_args=None, num_trials=None, **kwargs)

Bases: BaseAgent

Agent execute sequential tasks.

Examples

>>> task0 = your_task0
>>> task1 = your_task1
>>> task2 = your_task2
>>>
>>> agent = SequentialAgent(storegate=storegate,
>>>                         task_scheduler=[task0, task1, task2],
>>>                         metric=your_metric)
>>> agent.execute()
>>> agent.finalize()
__init__(differentiable=None, diff_pretrain=False, diff_task_args=None, num_trials=None, **kwargs)

Initialize sequential agent.

Parameters:
  • differentiable (str) – keras or pytorch. If differentiable is given, ConnectionTask() is created based on sequential tasks. If differentiable is None (default), sequential tasks are executed step by step.

  • diff_pretrain (bool) – If True, each subtask is trained before creating ConnectionTask()`.

  • diff_task_args (dict) – arbitrary args passed to ConnectionTask().

  • num_trials (ine) – number of trials. Average value of trials is used as final metric.

property result

Return result of execution.

execute()

Execute sequential agent.

finalize()

Finalize sequential agent.

execute_subtasktuples(subtasktuples, counter)

Execute given subtasktuples.

execute_pipeline(subtasktuples, counter, trial=None)

Execute pipeline.

execute_differentiable(subtasktuples, counter, trial=None)

Execute connection model.

class multiml.agent.RandomSearchAgent(samplings=None, seed=0, metric_type=None, num_workers=None, context='spawn', dump_all_results=False, disable_tqdm=True, **kwargs)

Bases: SequentialAgent

Agent executing random search..

__init__(samplings=None, seed=0, metric_type=None, num_workers=None, context='spawn', dump_all_results=False, disable_tqdm=True, **kwargs)

Initialize simple agent.

Parameters:
  • samplings (int or list) – If int, number of random samplings. If list, indexes of combination.

  • seed (int) – seed of random samplings.

  • metric_type (str) – ‘min’ or ‘max’ for indicating direction of metric optimization. If it is None, type is retrieved from metric class instance.

  • num_workers (int or list) – number of workers for multiprocessing or lsit of GPU ids. If num_workers is given, multiprocessing is enabled.

  • context (str) – fork (default) or spawn.

  • dump_all_results (bool) – dump all results or not.

  • disable_tqdm (bool) – enable tqdm bar.

property history

Return history of execution.

execute()

Execute simple agent.

finalize()

Finalize grid scan agent.

execute_jobs(ctx, queue, args)

(expert method) Execute multiprocessing jobs.

execute_pool_jobs(ctx, queue, args)

(expert method) Execute multiprocessing pool jobs.

execute_wrapper(queue, subtasktuples, counter, cuda_id)

(expert method) Wrapper method to execute multiprocessing pipeline.

class multiml.agent.GridSearchAgent(**kwargs)

Bases: RandomSearchAgent

Agent scanning all possible subtasks and hyper parameters.

__init__(**kwargs)

Initialize grid scan agent.

Parameters:

kwargs (dict) – arbitrary kwargs passed to RandomSearchAgent class.

execute()

Execute grid scan agent.