예제 #1
0
def get_metamodel(metamodel_id, content_only, version):
    """ Get a Metamodel """
    response = EvolvClient(EVOLV_CONFIG).get_metamodel(metamodel_id, account_id=EVOLV_ACCOUNT_ID,
                                                       version=version, content_only=content_only)
    if content_only:
        if response.get('response_yaml'):
            _print_dict_as_yaml(response)
        else:
            _print_dict_as_json(response)
    else:
        _print_dict(response)
예제 #2
0
def create_experiment(
        name,
        metamodel_id,
        optimization_targets,
        environment_id,
        experiment_type,
        population_size,
        budget,
        metamodel_version,
        precursor,
        algorithm_version,
        estimated_cr,
        long_tail_correction,
        sample_rate,
        target_confidence,
        audience_query_file,
        config):
    """ Create an Experiment """
    _confirm_account()

    evolv_client = EvolvClient(EVOLV_CONFIG)
    if not metamodel_version:
        # if no Metamodel version use latest
        metamodel = evolv_client.get_metamodel(metamodel_id, account_id=EVOLV_ACCOUNT_ID)
        if not metamodel:
            raise Exception("There was no Metamodel with the id {}".format(metamodel_id))
        metamodel_version = metamodel['content_version']

    audience_query = None
    content = None
    content_type = None

    if audience_query_file:
        with open(audience_query_file, 'r') as json_data:
            audience_query = json_data.read()

    if config is not None:
        assert config.endswith('.yml') or config.endswith('.json')

        content = Path(config).read_text()
        content_type = APPLICATION_YAML if config.endswith('.yml') else APPLICATION_JSON

    response = evolv_client.create_experiment(name=name, metamodel_id=metamodel_id, metamodel_version=metamodel_version,
                                              account_id=EVOLV_ACCOUNT_ID,
                                              optimization_targets=optimization_targets.split(','),
                                              environment_id=environment_id, experiment_type=experiment_type,
                                              population_size=population_size,
                                              budget=budget, precursor=precursor, algorithm_version=algorithm_version,
                                              estimated_cr=estimated_cr, long_tail_correction=long_tail_correction,
                                              sample_rate=sample_rate, target_confidence=target_confidence,
                                              audience_query=audience_query, content=content, content_type=content_type)
    _print_dict(response)
예제 #3
0
def update_metamodel(metamodel_id, file):
    """ Update the content of an existing Metamodel """
    _confirm_account()

    evolv_client = EvolvClient(EVOLV_CONFIG)
    metamodel = evolv_client.get_metamodel(metamodel_id, account_id=EVOLV_ACCOUNT_ID)
    if not metamodel:
        raise Exception("Failed to retrieve the previous metamodel.")

    response = evolv_client.update_metamodel(metamodel_id=metamodel_id, name=metamodel['name'],
                                             content=file.read().decode('utf-8'),
                                             content_type=APPLICATION_YAML,
                                             account_id=EVOLV_ACCOUNT_ID)
    _print_dict(response)
예제 #4
0
def update_environment(environment_id, file):
    """ Update the content of an existing Environment """
    _confirm_account()

    evolv_client = EvolvClient(EVOLV_CONFIG)
    environment = evolv_client.get_environment(environment_id, account_id=EVOLV_ACCOUNT_ID)
    if not environment:
        raise Exception("Failed to retrieve the previous environments.")

    response = evolv_client.update_environment(environment_id=environment_id, name=environment['name'],
                                               content=file.read().decode('utf-8'),
                                               content_type=APPLICATION_YAML
                                               if '.yml' in file.name else APPLICATION_JSON,
                                               account_id=EVOLV_ACCOUNT_ID)
    _print_dict(response)
예제 #5
0
def create_account(name):
    """
    Create a new account

    :param name: The name of the account to create
    """
    response = EvolvClient(EVOLV_CONFIG).create_account(name)
    _print_dict(response)
예제 #6
0
def update_experiment(experiment_id, metamodel_id, abort, abort_reason):
    """ Update an existing Experiment """
    _confirm_account()

    response = EvolvClient(EVOLV_CONFIG).update_experiment(experiment_id=experiment_id, abort=abort,
                                                           abort_reason=abort_reason,
                                                           account_id=EVOLV_ACCOUNT_ID, metamodel_id=metamodel_id)
    _print_dict(response)
예제 #7
0
def create_candidate(metamodel_id, metamodel_version, environment_id, experiment_id, file, allocation_probability):
    """ Create a candidate. """
    _confirm_account()

    with open(file, 'r') as json_data:
        genome = json_data.read()

    response = EvolvClient(EVOLV_CONFIG).create_candidate(metamodel_id=metamodel_id,
                                                          metamodel_version=metamodel_version, genome=genome,
                                                          account_id=EVOLV_ACCOUNT_ID, environment_id=environment_id,
                                                          experiment_id=experiment_id,
                                                          allocation_probability=allocation_probability)
    _print_dict(response)
예제 #8
0
def create_environment(name, config, protected):
    """ Create a new Environment """
    _confirm_account()

    content = None
    content_type = None

    if config is not None:
        assert config.endswith('.yml') or config.endswith('.json')
        content = Path(config).read_text()
        content_type = APPLICATION_YAML if config.endswith('.yml') else APPLICATION_JSON

    response = EvolvClient(EVOLV_CONFIG).create_environment(name, account_id=EVOLV_ACCOUNT_ID, default=False,
                                                            content=content, content_type=content_type,
                                                            protected=protected)
    _print_dict(response)
예제 #9
0
def get_account():
    """ Get the current account information """
    response = EvolvClient(EVOLV_CONFIG).get_account(EVOLV_ACCOUNT_ID)
    _print_dict(response)
예제 #10
0
def get_candidate(candidate_id, metamodel_id, experiment_id):
    """ Get a Candidate """
    response = EvolvClient(EVOLV_CONFIG).get_candidate(candidate_id, account_id=EVOLV_ACCOUNT_ID,
                                                       metamodel_id=metamodel_id, experiment_id=experiment_id)
    _print_dict(response)
예제 #11
0
def list_environments(query=None):
    """ List Environments """
    response = EvolvClient(EVOLV_CONFIG).list_environments(account_id=EVOLV_ACCOUNT_ID, query=query)
    _print_list_of_dicts(response)
예제 #12
0
def _confirm_account():
    account = EvolvClient(EVOLV_CONFIG).get_account(EVOLV_ACCOUNT_ID)
    if not click.confirm('You are currently set to interact with {} (id: {}),'
                         ' do you want to continue?'.format(account['name'], account['id'])):
        sys.exit(0)
예제 #13
0
def list_metamodels(query=None):
    """ List Metamodel """
    response = EvolvClient(EVOLV_CONFIG).list_metamodels(account_id=EVOLV_ACCOUNT_ID, query=query)
    _print_list_of_dicts(response)
예제 #14
0
def list_experiments(metamodel_id, query=None, statuses=None):
    """ List Experiments """
    response = EvolvClient(EVOLV_CONFIG).list_experiments(account_id=EVOLV_ACCOUNT_ID, metamodel_id=metamodel_id,
                                                          query=query, statuses=statuses)
    _print_list_of_dicts(response)
예제 #15
0
def list_candidates(metamodel_id, experiment_id, query=None):
    """ List Candidates """
    response = EvolvClient(EVOLV_CONFIG).list_candidates(account_id=EVOLV_ACCOUNT_ID, metamodel_id=metamodel_id,
                                                         experiment_id=experiment_id, query=query)
    _print_list_of_dicts(response)
예제 #16
0
def create_metamodel(name, file):
    """ Create a new Metamodel """
    _confirm_account()
    response = EvolvClient(EVOLV_CONFIG).create_metamodel(name, yaml=file.read().decode('utf-8'),
                                                          account_id=EVOLV_ACCOUNT_ID)
    _print_dict(response)
예제 #17
0
def list_accounts():
    """ List Accounts """
    response = EvolvClient(EVOLV_CONFIG).list_accounts()
    _print_list_of_dicts(response)