def create_experiments( session: Session, container_spec: ContainerSpec, script_args: List[str], experiment_config: conf.ExpConf, xgroup: Optional[str] = None, ) -> List[Experiment]: '''create experiment instances Args: session: sqlalchemy session container_spec: container spec for the generated experiments script_args: these are extra arguments that will be passed to every job executed, in addition to the arguments created by expanding out the experiment config. experiment_config: dict of string to list, boolean, string or int. Any lists will trigger a cartesian product out with the rest of the config. A job will be submitted for every combination of parameters in the experiment config. xgroup: experiment group name for the generated experiments ''' xg = ExperimentGroup.get_or_create(session=session, name=xgroup) session.add(xg) # this ensures that any new objects get persisted return [ Experiment.get_or_create( xgroup=xg, container_spec=container_spec, args=script_args, kwargs=kwargs, ) for kwargs in conf.expand_experiment_config(experiment_config) ]
def run_app(args): """Main function to run the Caliban app. Accepts a Namespace-type output of an argparse argument parser. """ conf = args.experiment_config expanded = c.expand_experiment_config(conf) if args.print_flags: _print_flags(expanded) else: _print_json(expanded, pprint=args.pprint)
def test_expand_experiment_config(self): # An empty config expands to a singleton list. This is important so that # single job submission without a spec works. self.assertListEqual([{}], c.expand_experiment_config({}))
def test_compound_key_handling(self): tests = [{ 'input': { '[a,b]': [['c', 'd'], ['e', 'f']] }, 'after_tupleization': { ('a', 'b'): [('c', 'd'), ('e', 'f')] }, 'after_dictproduct': [{ ('a', 'b'): ('c', 'd') }, { ('a', 'b'): ('e', 'f') }], 'after_expansion': [{ 'a': 'c', 'b': 'd' }, { 'a': 'e', 'b': 'f' }] }, { 'input': { '[a,b]': ['c', 'd'] }, 'after_tupleization': { ('a', 'b'): ('c', 'd') }, 'after_dictproduct': [{ ('a', 'b'): ('c', 'd') }], 'after_expansion': [{ 'a': 'c', 'b': 'd' }] }, { 'input': { 'hi': 'there', '[k1,k2]': [['v1a', 'v2a'], ['v1b', 'v2b']] }, 'after_tupleization': { 'hi': 'there', ('k1', 'k2'): [('v1a', 'v2a'), ('v1b', 'v2b')] }, 'after_dictproduct': [{ 'hi': 'there', ('k1', 'k2'): ('v1a', 'v2a') }, { 'hi': 'there', ('k1', 'k2'): ('v1b', 'v2b') }], 'after_expansion': [{ 'hi': 'there', 'k1': 'v1a', 'k2': 'v2a' }, { 'hi': 'there', 'k1': 'v1b', 'k2': 'v2b' }] }, { 'input': { 'hi': 'there', '[a,b]': ['c', 'd'] }, 'after_tupleization': { 'hi': 'there', ('a', 'b'): ('c', 'd') }, 'after_dictproduct': [{ 'hi': 'there', ('a', 'b'): ('c', 'd') }], 'after_expansion': [{ 'hi': 'there', 'a': 'c', 'b': 'd' }] }, { 'input': { '[a,b]': [0, 1] }, 'after_tupleization': { ('a', 'b'): (0, 1) }, 'after_dictproduct': [{ ('a', 'b'): (0, 1) }], 'after_expansion': [{ 'a': 0, 'b': 1 }] }, { 'input': { '[a,b]': [[0, 1]] }, 'after_tupleization': { ('a', 'b'): [(0, 1)] }, 'after_dictproduct': [{ ('a', 'b'): (0, 1) }], 'after_expansion': [{ 'a': 0, 'b': 1 }] }, { 'input': { 'hi': 'blueshift', '[a,b]': [[0, 1]] }, 'after_tupleization': { 'hi': 'blueshift', ('a', 'b'): [(0, 1)] }, 'after_dictproduct': [{ 'hi': 'blueshift', ('a', 'b'): (0, 1) }], 'after_expansion': [{ 'hi': 'blueshift', 'a': 0, 'b': 1 }] }] for test in tests: self.assertListEqual(test['after_expansion'], c.expand_experiment_config(test['input']))