def create_experiment(mode, space, algorithm): experiment = Experiment("supernaekei", mode=mode) experiment.space = space experiment.algorithms = algorithm experiment.max_broken = 5 experiment.max_trials = 5 return experiment
def test_is_done_property_with_pending(algorithm): """Check experiment stopping conditions when there is pending trials.""" completed = ['completed'] * 10 reserved = ['reserved'] * 5 with OrionState(trials=generate_trials(completed + reserved)) as cfg: exp = Experiment('supernaekei') exp._id = cfg.trials[0]['experiment'] exp.algorithms = algorithm exp.max_trials = 10 assert exp.is_done exp.max_trials = 15 # There is only 10 completed trials assert not exp.is_done exp.algorithms.algorithm.done = True # Algorithm is done but 5 trials are pending assert not exp.is_done
def create_experiment(name, version, space, **kwargs): """Instantiate the experiment and its attribute objects All unspecified arguments will be replaced by system's defaults (orion.core.config.*). Parameters ---------- name: str Name of the experiment. version: int Version of the experiment. space: dict or Space object Optimization space of the algorithm. If dict, should have the form `dict(name='<prior>(args)')`. algorithms: str or dict, optional Algorithm used for optimization. strategy: str or dict, optional Parallel strategy to use to parallelize the algorithm. max_trials: int, optional Maximum number or trials before the experiment is considered done. storage: dict, optional Configuration of the storage backend. """ experiment = Experiment(name=name, version=version) experiment._id = kwargs.get('_id', None) # pylint:disable=protected-access experiment.pool_size = kwargs.get('pool_size') if experiment.pool_size is None: experiment.pool_size = orion.core.config.experiment.get( 'pool_size', deprecated='ignore') experiment.max_trials = kwargs.get('max_trials', orion.core.config.experiment.max_trials) experiment.space = _instantiate_space(space) experiment.algorithms = _instantiate_algo(experiment.space, kwargs.get('algorithms')) experiment.producer = kwargs.get('producer', {}) experiment.producer['strategy'] = _instantiate_strategy( experiment.producer.get('strategy')) experiment.working_dir = kwargs.get( 'working_dir', orion.core.config.experiment.working_dir) experiment.metadata = kwargs.get( 'metadata', {'user': kwargs.get('user', getpass.getuser())}) experiment.refers = kwargs.get('refers', { 'parent_id': None, 'root_id': None, 'adapter': [] }) experiment.refers['adapter'] = _instantiate_adapters( experiment.refers.get('adapter', [])) return experiment
def test_view_is_done_property_no_pending(algorithm): """Check experiment stopping conditions from view when there is no pending trials.""" completed = ['completed'] * 10 broken = ['broken'] * 5 with OrionState(trials=generate_trials(completed + broken)) as cfg: exp = Experiment('supernaekei') exp._id = cfg.trials[0]['experiment'] exp.algorithms = algorithm exp.max_trials = 100 exp_view = ExperimentView(exp) exp.algorithms = algorithm exp.max_trials = 15 # There is only 10 completed trials and algo not done. assert not exp_view.is_done exp.algorithms.algorithm.done = True # Algorithm is done and no pending trials assert exp_view.is_done
def test_is_done_property_no_pending(algorithm): """Check experiment stopping conditions when there is no pending trials.""" completed = ["completed"] * 10 broken = ["broken"] * 5 with OrionState(trials=generate_trials(completed + broken)) as cfg: exp = Experiment("supernaekei", mode="x") exp._id = cfg.trials[0]["experiment"] exp.algorithms = algorithm exp.max_trials = 15 # There is only 10 completed trials and algo not done. assert not exp.is_done exp.algorithms.algorithm.done = True # Algorithm is done and no pending trials assert exp.is_done
def create_experiment(name, version, mode, space, **kwargs): """Instantiate the experiment and its attribute objects All unspecified arguments will be replaced by system's defaults (orion.core.config.*). Parameters ---------- name: str Name of the experiment. version: int Version of the experiment. mode: str The access rights of the experiment on the database. 'r': read access only 'w': can read and write to database 'x': can read and write to database, algo is instantiated and can execute optimization space: dict or Space object Optimization space of the algorithm. If dict, should have the form `dict(name='<prior>(args)')`. algorithms: str or dict, optional Algorithm used for optimization. strategy: str or dict, optional Parallel strategy to use to parallelize the algorithm. max_trials: int, optional Maximum number or trials before the experiment is considered done. max_broken: int, optional Number of broken trials for the experiment to be considered broken. storage: dict, optional Configuration of the storage backend. """ experiment = Experiment(name=name, version=version, mode=mode) experiment._id = kwargs.get("_id", None) # pylint:disable=protected-access experiment.max_trials = kwargs.get("max_trials", orion.core.config.experiment.max_trials) experiment.max_broken = kwargs.get("max_broken", orion.core.config.experiment.max_broken) experiment.space = _instantiate_space(space) experiment.algorithms = _instantiate_algo( experiment.space, experiment.max_trials, kwargs.get("algorithms"), ignore_unavailable=mode != "x", ) # TODO: Remove for v0.4 _instantiate_strategy(kwargs.get("producer", {}).get("strategy")) experiment.working_dir = kwargs.get( "working_dir", orion.core.config.experiment.working_dir) experiment.metadata = kwargs.get( "metadata", {"user": kwargs.get("user", getpass.getuser())}) experiment.refers = kwargs.get("refers", { "parent_id": None, "root_id": None, "adapter": [] }) experiment.refers["adapter"] = _instantiate_adapters( experiment.refers.get("adapter", [])) log.debug("Created experiment with config:\n%s", pprint.pformat(experiment.configuration)) return experiment