Example #1
0
def api_copyNonSessionSimulation():
    req = http_request.parse_json()
    sim_type = req['simulationType']
    src = py.path.local(
        simulation_db.find_global_simulation(
            sim_type,
            req['simulationId'],
            checked=True,
        ))
    data = simulation_db.open_json_file(
        sim_type,
        src.join(simulation_db.SIMULATION_DATA_FILE),
    )
    if 'report' in data:
        del data['report']
    data['models']['simulation']['isExample'] = False
    data['models']['simulation']['outOfSessionSimulationId'] = req[
        'simulationId']
    res = _save_new_and_reply(data)
    target = simulation_db.simulation_dir(sim_type,
                                          simulation_db.parse_sid(data))
    template_common.copy_lib_files(
        data,
        simulation_db.lib_dir_from_sim_dir(src),
        simulation_db.lib_dir_from_sim_dir(target),
    )
    template = sirepo.template.import_module(data)
    if hasattr(template, 'copy_related_files'):
        template.copy_related_files(data, str(src), str(target))
    return res
Example #2
0
def api_copyNonSessionSimulation():
    req = _json_input()
    sim_type = req['simulationType']
    global_path = simulation_db.find_global_simulation(sim_type,
                                                       req['simulationId'])
    if global_path:
        data = simulation_db.open_json_file(
            sim_type,
            os.path.join(global_path, simulation_db.SIMULATION_DATA_FILE),
        )
        data['models']['simulation']['isExample'] = False
        data['models']['simulation']['outOfSessionSimulationId'] = req[
            'simulationId']
        res = _save_new_and_reply(data)
        target = simulation_db.simulation_dir(sim_type,
                                              simulation_db.parse_sid(data))
        template_common.copy_lib_files(
            data,
            py.path.local(os.path.dirname(global_path)).join('lib'),
            target.join('../lib'),
        )
        template = sirepo.template.import_module(data)
        if hasattr(template, 'copy_related_files'):
            template.copy_related_files(data, global_path, str(target))
        return res
    werkzeug.exceptions.abort(404)
Example #3
0
def test_prepare_aux_files():
    from sirepo.template import template_common
    from pykern.pkdebug import pkdp
    from pykern import pkcollections
    import sirepo.auth
    import sirepo.auth.guest

    sirepo.auth.login(sirepo.auth.guest)

    # Needed to initialize simulation_db
    data = pkcollections.json_load_any('''{
        "simulationType": "srw",
        "models": {
            "simulation": {
                "sourceType": "t"
            },
            "tabulatedUndulator": {
                "undulatorType": "u_t",
                "magneticFile": "magnetic_measurements.zip"
            },
            "beamline": { }
        },
        "report": "intensityReport"
    }''')
    d = pkunit.work_dir()
    template_common.copy_lib_files(data, None, d)
Example #4
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 #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
Example #6
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