Example #1
0
def prepare_simulation(data, run_dir):
    """Create and install files, update parameters, and generate command.

    Copies files into the simulation directory (``run_dir``)
    Updates the parameters in ``data`` and save.
    Generate the pkcli command.

    Args:
        data (dict): report and model parameters
        run_dir (py.path.local): dir simulation will be run in
    Returns:
        list, py.path: pkcli command, simulation directory
    """
    import sirepo.sim_data
    sim_type = data.simulationType
    template = sirepo.template.import_module(data)
    s = sirepo.sim_data.get_class(sim_type)
    s.lib_files_to_run_dir(data, run_dir)
    update_rsmanifest(data)
    write_json(run_dir.join(template_common.INPUT_BASE_NAME), data)
    #TODO(robnagler) encapsulate in template
    is_p = s.is_parallel(data)
    template.write_parameters(
        data,
        run_dir=run_dir,
        is_parallel=is_p,
    )
    cmd = [
        pkinspect.root_package(template),
        pkinspect.module_basename(template),
        'run-background' if is_p else 'run',
        str(run_dir),
    ]
    return cmd, run_dir
Example #2
0
def prepare_simulation(data, tmp_dir=None):
    """Create and install files, update parameters, and generate command.

    Copies files into the simulation directory (``run_dir``), or (if
    specified) a ``tmp_dir``.
    Updates the parameters in ``data`` and save.
    Generate the pkcli command to pass to task runner.

    Args:
        data (dict): report and model parameters
        tmp_dir (py.path.local):
    Returns:
        list, py.path: pkcli command, simulation directory
    """
    if tmp_dir is None:
        # This is the legacy (pre-runner-daemon) code path
        run_dir = simulation_run_dir(data, remove_dir=True)
        #TODO(robnagler) create a lock_dir -- what node/pid/thread to use?
        #   probably can only do with celery.
        pkio.mkdir_parent(run_dir)
        out_dir = run_dir
        # Only done on the legacy path, because the runner daemon owns the
        # status file.
        write_status('pending', out_dir)
    else:
        # This is the runner-daemon code path -- tmp_dir is always given, as a
        # new temporary directory we have to create.
        run_dir = simulation_run_dir(data)
        pkio.mkdir_parent(tmp_dir)
        out_dir = tmp_dir
    sim_type = data['simulationType']
    sid = parse_sid(data)
    template = sirepo.template.import_module(data)
    template_common.copy_lib_files(data, None, out_dir)

    write_json(out_dir.join(template_common.INPUT_BASE_NAME), data)
    #TODO(robnagler) encapsulate in template
    is_p = is_parallel(data)
    template.write_parameters(
        data,
        run_dir=out_dir,
        is_parallel=is_p,
    )
    cmd = [
        pkinspect.root_package(template),
        pkinspect.module_basename(template),
        'run-background' if is_p else 'run',
        str(run_dir),
    ]
    return cmd, run_dir
Example #3
0
def prepare_simulation(data, run_dir=None):
    """Create and install files, update parameters, and generate command.

    Copies files into the simulation directory (``run_dir``)
    Updates the parameters in ``data`` and save.
    Generate the pkcli command to pass to task runner.

    Args:
        data (dict): report and model parameters
        run_dir (py.path.local): defaults to `simulation_run_dir`
    Returns:
        list, py.path: pkcli command, simulation directory
    """
    import sirepo.sim_data
    if run_dir is None:
        # This is the legacy (pre-runner-daemon) code path
        run_dir = simulation_run_dir(data, remove_dir=True)
        #TODO(robnagler) create a lock_dir -- what node/pid/thread to use?
        #   probably can only do with celery.
        pkio.mkdir_parent(run_dir)
        write_status('pending', run_dir)
    sim_type = data.simulationType
    template = sirepo.template.import_module(data)
    s = sirepo.sim_data.get_class(sim_type)
    s.lib_files_to_run_dir(data, run_dir)
    update_rsmanifest(data)
    write_json(run_dir.join(template_common.INPUT_BASE_NAME), data)
    #TODO(robnagler) encapsulate in template
    is_p = s.is_parallel(data)
    template.write_parameters(
        data,
        run_dir=run_dir,
        is_parallel=is_p,
    )
    cmd = [
        pkinspect.root_package(template),
        pkinspect.module_basename(template),
        'run-background' if is_p else 'run',
        str(run_dir),
    ]
    return cmd, run_dir
Example #4
0
def prepare_simulation(data):
    """Create and install files, update parameters, and generate command.

    Copies files into the simulation directory (``run_dir``).
    Updates the parameters in ``data`` and save.
    Generate the pkcli command to pass to task runner.

    Args:
        data (dict): report and model parameters
    Returns:
        list, py.path: pkcli command, simulation directory
    """
    run_dir = simulation_run_dir(data, remove_dir=True)
    #TODO(robnagler) create a lock_dir -- what node/pid/thread to use?
    #   probably can only do with celery.
    pkio.mkdir_parent(run_dir)
    write_status('pending', run_dir)
    sim_type = data['simulationType']
    sid = parse_sid(data)
    template = sirepo.template.import_module(data)
    template_common.copy_lib_files(data, None, run_dir)

    write_json(run_dir.join(template_common.INPUT_BASE_NAME), data)
    #TODO(robnagler) encapsulate in template
    is_p = is_parallel(data)
    template.write_parameters(
        data,
        run_dir=run_dir,
        is_parallel=is_p,
    )
    cmd = [
        pkinspect.root_package(template),
        pkinspect.module_basename(template),
        'run-background' if is_p else 'run',
        str(run_dir),
    ]
    return cmd, run_dir
Example #5
0
def prepare_simulation(data):
    """Create and install files, update parameters, and generate command.

    Copies files into the simulation directory (``run_dir``).
    Updates the parameters in ``data`` and save.
    Generate the pkcli command to pass to task runner.

    Args:
        data (dict): report and model parameters
    Returns:
        list, py.path: pkcli command, simulation directory
    """
    run_dir = simulation_run_dir(data, remove_dir=True)
    #TODO(robnagler) create a lock_dir -- what node/pid/thread to use?
    #   probably can only do with celery.
    pkio.mkdir_parent(run_dir)
    write_status('pending', run_dir)
    sim_type = data['simulationType']
    sid = parse_sid(data)
    template = sirepo.template.import_module(data)
    template_common.copy_lib_files(data, None, run_dir)

    write_json(run_dir.join(template_common.INPUT_BASE_NAME), data)
    #TODO(robnagler) encapsulate in template
    is_p = is_parallel(data)
    template.write_parameters(
        data,
        run_dir=run_dir,
        is_parallel=is_p,
    )
    cmd = [
        pkinspect.root_package(template),
        pkinspect.module_basename(template),
        'run-background' if is_p else 'run',
        str(run_dir),
    ]
    return cmd, run_dir