Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_comparison(self, yaml_config, yaml_diff_config):
"""Test that different configs are detected as conflict."""
old_config = {'metadata': {'user_args': yaml_config}}
new_config = {'metadata': {'user_args': yaml_diff_config}}
backward.populate_priors(old_config['metadata'])
backward.populate_priors(new_config['metadata'])
conflicts = list(conflict.ScriptConfigConflict.detect(old_config, new_config))
assert len(conflicts) == 1
def test_rename_missing_changed_marked(self, parent_config, child_config):
"""Test if renaming is automatically applied with all conflicts resolved including
the new one caused by prior change
"""
child_config['metadata']['user_args'].append('-w_a~uniform(0,1)')
child_config['metadata']['user_args'].append('-w_b~+normal(0,1)')
child_config['metadata']['user_args'][1] = '-x~>w_b'
backward.populate_priors(child_config['metadata'])
conflicts = detect_conflicts(parent_config, child_config)
ExperimentBranchBuilder(conflicts, {'manual_resolution': True})
assert len(conflicts.get()) == 5
assert conflicts.get([ExperimentNameConflict])[0].is_resolved
assert conflicts.get(dimension_name='x')[0].is_resolved
assert conflicts.get([NewDimensionConflict], dimension_name='w_b')[0].is_resolved
assert conflicts.get([ChangedDimensionConflict], dimension_name='w_b')[0].is_resolved
assert not conflicts.get(dimension_name='w_a')[0].is_resolved
resolved_conflicts = conflicts.get_resolved()
assert len(resolved_conflicts) == 4
assert resolved_conflicts[1].resolution is resolved_conflicts[2].resolution
assert isinstance(resolved_conflicts[1].resolution,
resolved_conflicts[1].RenameDimensionResolution)
def parent_version_config():
"""Return a configuration for an experiment."""
config = dict(
_id='parent_config',
name="old_experiment",
version=1,
algorithms='random',
metadata={'user': 'corneauf', 'datetime': datetime.datetime.utcnow(),
'user_args': ['--x~normal(0,1)']})
backward.populate_priors(config['metadata'])
return config
def list_arg_with_equals_cli_config(child_config):
"""Create a child config with an argument of the
form --args=1 --args=2 --args=3
"""
child_config['metadata']['user_args'] += ['--args=1',
'--args=2', '--args=3']
backward.populate_priors(child_config['metadata'])
return child_config
def missing_config(child_config):
"""Create a child config with a missing dimension"""
del(child_config['metadata']['user_args'][1]) # del -x
del(child_config['metadata']['user_args'][1]) # del -y
backward.populate_priors(child_config['metadata'])
return child_config
def new_config(child_config):
"""Create a child config with a new dimension"""
child_config['metadata']['user_args'].append('-w_d~normal(0,1)')
backward.populate_priors(child_config['metadata'])
return child_config
"HEAD_sha": "fsa7df7a8sdf7a8s7",
"active_branch": None,
"diff_sha": "diff"}},
version=1,
pool_size=10,
max_trials=1000,
working_dir=None,
algorithms={'dumbalgo': {}},
producer={'strategy': 'NoParallelStrategy'},
# attrs starting with '_' also
_id='fasdfasfa',
# and in general anything which is not in Experiment's slots
something_to_be_ignored='asdfa'
)
backward.populate_priors(new_config['metadata'])
return new_config
def config(exp_config):
"""Return a configuration."""
config = exp_config[0][0]
config['metadata']['user_args'] = ['--x~uniform(-50, 50)']
config['name'] = 'exp'
config['working_dir'] = "/tmp/orion"
backward.populate_priors(config['metadata'])
return config
def add_priors(experiment):
"""Add priors to metadata if not present"""
backward.populate_priors(experiment['metadata'])
self.version = version
if self.version > max_version:
log.warning("Version %s was specified but most recent version is only %s. "
"Using %s.", self.version, max_version, max_version)
self.version = min(self.version, max_version)
log.info("Many versions for experiment %s have been found. Using latest "
"version %s.", name, self.version)
config = filter(lambda exp: exp.get('version', 1) == self.version, config)
config = sorted(config, key=lambda x: x['metadata']['datetime'],
reverse=True)[0]
backward.populate_priors(config['metadata'])
for attrname in self.__slots__:
if not attrname.startswith('_') and attrname in config:
setattr(self, attrname, config[attrname])
self._id = config['_id']