Beispiel #1
0
def settle_run_options(n_workers=None,
                       job_dir=None,
                       job_name=None,
                       narration=None,
                       configuration=None,
                       start_hash=None):
    """

    Parameters
    ----------
    n_workers :
         (Default value = None)
    job_dir :
         (Default value = None)
    job_name :
         (Default value = None)
    narration :
         (Default value = None)

    \b
    Returns
    -------

    """

    # the default for the job name is the start hash if none is given
    if job_name == START_HASH:
        job_name = start_hash

    # if the job_name is given and the default value for the job_dir
    # is given (i.e. not specified by the user) we set the job-dir as
    # the job_name
    if job_name is not None and job_dir == CURDIR:
            job_dir = job_name

    # if the special value for curdir is given we get the systems
    # current directory, this is the default.
    if job_dir == CURDIR:
        job_dir = osp.curdir

    # normalize the job_dir
    job_dir = osp.realpath(job_dir)

    # if a path for a configuration was given we want to use it so we
    # unpickle it and return it, otherwise return None and use the
    # default one in the orchestrator
    config = None
    if configuration is not None:
         with open(configuration, 'rb') as rf:
             config = Orchestrator.deserialize(rf.read())

    # we need to reparametrize the configuration here since the
    # orchestrator API will ignore reparametrization values if a
    # concrete Configuration is given.
    if config is not None:
        # collect the kwargs for the work mapper to be reparametrized
        work_mapper_pkwargs = {'num_workers' : n_workers}

        config = config.reparametrize(work_dir=job_dir,
                                      config_name=job_name,
                                      narration=narration,
                                      work_mapper_partial_kwargs=work_mapper_pkwargs)

    return job_dir, job_name, narration, config
Beispiel #2
0
def settle_run_options(
    n_workers=None,
    job_dir=None,
    job_name=None,
    narration=None,
    monitor_http_port=None,
    tag=None,
    configuration=None,
    start_hash=None,
):
    """

    Parameters
    ----------
    n_workers :
         (Default value = None)
    job_dir :
         (Default value = None)
    job_name :
         (Default value = None)
    narration :
         (Default value = None)

    \b
    Returns
    -------

    """

    # the default for the job name is the start hash if none is given
    if job_name == START_HASH:
        job_name = start_hash

    # if the job_name is given and the default value for the job_dir
    # is given (i.e. not specified by the user) we set the job-dir as
    # the job_name
    if job_name is not None and job_dir == CURDIR:
        job_dir = job_name

    # if the special value for curdir is given we get the systems
    # current directory, this is the default.
    if job_dir == CURDIR:
        job_dir = osp.curdir

    # normalize the job_dir
    job_dir = osp.realpath(job_dir)

    # if a path for a configuration was given we want to use it so we
    # unpickle it and return it, otherwise return None and use the
    # default one in the orchestrator
    config = None
    if configuration is not None:
        with open(configuration, 'rb') as rf:
            config = Orchestrator.deserialize(rf.read())

    ## Monitoring

    # nothing to do, just use the port or tag if its given
    monitor_pkwargs = {
        'tag': tag,
        'port': monitor_http_port,
    }

    # we need to reparametrize the configuration here since the
    # orchestrator API will ignore reparametrization values if a
    # concrete Configuration is given.
    if config is not None:

        # if there is a change in the number of workers we need to
        # recalculate all of the partial kwargs

        work_mapper_pkwargs = deepcopy(config.work_mapper_partial_kwargs)

        # if the number of workers has changed update all the relevant
        # fields, otherwise leave it alone
        if work_mapper_pkwargs['num_workers'] != n_workers:

            work_mapper_pkwargs['num_workers'] = n_workers
            work_mapper_pkwargs['device_ids'] = [
                str(i) for i in range(n_workers)
            ]

        config = config.reparametrize(
            work_dir=job_dir,
            config_name=job_name,
            narration=narration,
            work_mapper_partial_kwargs=work_mapper_pkwargs,
            monitor_partial_kwargs=monitor_pkwargs,
        )

    return job_dir, job_name, narration, config