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_broken_property(): """Check experiment stopping conditions for maximum number of broken.""" MAX_BROKEN = 5 stati = (["reserved"] * 10) + (["broken"] * (MAX_BROKEN - 1)) with OrionState(trials=generate_trials(stati)) as cfg: exp = Experiment("supernaekei", mode="x") exp._id = cfg.trials[0]["experiment"] exp.max_broken = MAX_BROKEN assert not exp.is_broken stati = (["reserved"] * 10) + (["broken"] * (MAX_BROKEN)) with OrionState(trials=generate_trials(stati)) as cfg: exp = Experiment("supernaekei", mode="x") exp._id = cfg.trials[0]["experiment"] exp.max_broken = MAX_BROKEN assert exp.is_broken
def test_configurable_broken_property(): """Check if max_broken changes after configuration.""" MAX_BROKEN = 5 stati = (["reserved"] * 10) + (["broken"] * (MAX_BROKEN)) with OrionState(trials=generate_trials(stati)) as cfg: exp = Experiment("supernaekei", mode="x") exp._id = cfg.trials[0]["experiment"] exp.max_broken = MAX_BROKEN assert exp.is_broken exp.max_broken += 1 assert not exp.is_broken
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