Example #1
0
def create_experiment(args):
    '''start a new experiment'''
    experiment_id = ''.join(random.sample(string.ascii_letters + string.digits, 8))
    config_path = os.path.abspath(args.config)
    if not os.path.exists(config_path):
        print_error('Please set correct config path!')
        exit(1)
    experiment_config = get_yml_content(config_path)

    try:
        validate_all_content(experiment_config, config_path)
    except Exception:
        print_warning('Validation with V1 schema failed. Trying to convert from V2 format...')
        try:
            config = ExperimentConfig(**experiment_config)
            experiment_config = convert.to_v1_yaml(config)
        except Exception as e:
            print_error(f'Conversion from v2 format failed: {repr(e)}')
        try:
            validate_all_content(experiment_config, config_path)
        except Exception as e:
            print_error(f'Config in v1 format validation failed. {repr(e)}')
            exit(1)

    try:
        launch_experiment(args, experiment_config, 'new', experiment_id)
    except Exception as exception:
        restServerPid = Experiments().get_all_experiments().get(experiment_id, {}).get('pid')
        if restServerPid:
            kill_command(restServerPid)
        print_error(exception)
        exit(1)
Example #2
0
def create_experiment(args):
    '''start a new experiment'''
    experiment_id = ''.join(
        random.sample(string.ascii_letters + string.digits, 8))
    nni_config = Config(experiment_id)
    nni_config.set_config('experimentId', experiment_id)
    config_path = os.path.abspath(args.config)
    if not os.path.exists(config_path):
        print_error('Please set correct config path!')
        exit(1)
    experiment_config = get_yml_content(config_path)
    try:
        config = ExperimentConfig(**experiment_config)
        experiment_config = convert.to_v1_yaml(config)
    except Exception:
        pass
    try:
        validate_all_content(experiment_config, config_path)
    except Exception as e:
        print_error(e)
        exit(1)

    nni_config.set_config('experimentConfig', experiment_config)
    nni_config.set_config('restServerPort', args.port)
    try:
        launch_experiment(args, experiment_config, 'new', experiment_id)
    except Exception as exception:
        nni_config = Config(experiment_id)
        restServerPid = nni_config.get_config('restServerPid')
        if restServerPid:
            kill_command(restServerPid)
        print_error(exception)
        exit(1)