Ejemplo n.º 1
0
def run_background(cfg_dir):
    res = {}
    data = simulation_db.read_json(template_common.INPUT_BASE_NAME)
    distribution = data['models']['bunch']['distribution']
    run_with_mpi = distribution == 'lattice' or distribution == 'file'
    try:
        with pkio.save_chdir(cfg_dir):
            if run_with_mpi:
                mpi.run_script(
                    pkio.read_text(template_common.PARAMETERS_PYTHON_FILE))
            else:
                #TODO(pjm): MPI doesn't work with rsbeams distributions yet
                exec(pkio.read_text(template_common.PARAMETERS_PYTHON_FILE),
                     locals(), locals())
    except Exception as e:
        res = {
            'error': str(e),
        }
    if run_with_mpi and 'error' in res:
        text = pkio.read_text('mpi_run.out')
        m = re.search(r'^Traceback .*?^\w*Error: (.*?)\n\n', text,
                      re.MULTILINE | re.DOTALL)
        if m:
            res['error'] = m.group(1)
            # remove output file - write_result() will not overwrite an existing error output
            pkio.unchecked_remove(
                simulation_db.json_filename(template_common.OUTPUT_BASE_NAME))
    simulation_db.write_result(res)
Ejemplo n.º 2
0
def run_background(cfg_dir):
    """Run code in ``cfg_dir`` with mpi

    Args:
        cfg_dir (str): directory to run code in
    """
    with pkio.save_chdir(cfg_dir):
        mpi.run_script(_script())
        simulation_db.write_result({})
Ejemplo n.º 3
0
def run_background(cfg_dir):
    """Run srw with mpi in ``cfg_dir``

    Args:
        cfg_dir (str): directory to run srw in
    """
    with pkio.save_chdir(cfg_dir):
        mpi.run_script(pkio.read_text(template_common.PARAMETERS_PYTHON_FILE))
        simulation_db.write_result({})
Ejemplo n.º 4
0
def run_background(cfg_dir):
    """Run srw with mpi in ``cfg_dir``

    Args:
        cfg_dir (str): directory to run srw in
    """
    with pkio.save_chdir(cfg_dir):
        script = pkio.read_text(template_common.PARAMETERS_PYTHON_FILE)
        p = dict(pkcollections.map_items(cfg))
        if pkconfig.channel_in('dev'):
            p['particles_per_core'] = 5
        p['cores'] = mpi.cfg.cores
        script += '''
    v.wm_na = v.sm_na = {particles_per_core}
    # Number of "iterations" per save is best set to num processes
    v.wm_ns = v.sm_ns = {cores}
    srwl_bl.SRWLBeamline(_name=v.name).calc_all(v, op)

main()
'''.format(**p)
        mpi.run_script(script)
        simulation_db.write_result({})
Ejemplo n.º 5
0
def run_background(cfg_dir):
    """Run srw with mpi in ``cfg_dir``

    Args:
        cfg_dir (str): directory to run srw in
    """
    with pkio.save_chdir(cfg_dir):
        script = pkio.read_text(template_common.PARAMETERS_PYTHON_FILE)
        p = dict(pkcollections.map_items(cfg))
        if pkconfig.channel_in('dev'):
            p['particles_per_core'] = 5
        p['cores'] = mpi.cfg.cores
        script += '''
    v.wm_na = v.sm_na = {particles_per_core}
    # Number of "iterations" per save is best set to num processes
    v.wm_ns = v.sm_ns = {cores}
    srwl_bl.SRWLBeamline(_name=v.name).calc_all(v, op)

main()
'''.format(**p)
        mpi.run_script(script)
        simulation_db.write_result({})
Ejemplo n.º 6
0
def run_background(cfg_dir):
    """Run warpvnd in ``cfg_dir`` with mpi

    Args:
        cfg_dir (str): directory to run warpvnd in
    """
    with pkio.save_chdir(cfg_dir):
        data = simulation_db.read_json(template_common.INPUT_BASE_NAME)
        #TODO(pjm): only run with mpi for 3d case for now
        if data.models.simulationGrid.simulation_mode == '3d' \
           and not data.report == 'optimizerAnimation' \
           and data.models.simulation.executionMode == 'parallel':
            pkdc('RUNNING MPI')
            simulation_db.write_json(
                py.path.local(cfg_dir).join(template.MPI_SUMMARY_FILE), {
                    'mpiCores': mpi.cfg.cores,
                })
            mpi.run_script(_script())
        else:
            pkdc('RUNNING SINGLE PROCESS')
            exec(_script(), locals(), locals())
        simulation_db.write_result({})
Ejemplo n.º 7
0
def run_background(cfg_dir):
    res = {}
    data = simulation_db.read_json(template_common.INPUT_BASE_NAME)
    distribution = data['models']['bunch']['distribution']
    run_with_mpi = distribution == 'lattice' or distribution == 'file'
    try:
        with pkio.save_chdir(cfg_dir):
            if run_with_mpi:
                mpi.run_script(pkio.read_text(template_common.PARAMETERS_PYTHON_FILE))
            else:
                #TODO(pjm): MPI doesn't work with rsbeams distributions yet
                exec(pkio.read_text(template_common.PARAMETERS_PYTHON_FILE), locals(), locals())
    except Exception as e:
        res = {
            'error': str(e),
        }
    if run_with_mpi and 'error' in res:
        text = pkio.read_text('mpi_run.out')
        m = re.search(r'^Traceback .*?^\w*Error: (.*?)\n\n', text, re.MULTILINE|re.DOTALL)
        if m:
            res['error'] = m.group(1)
            # remove output file - write_result() will not overwrite an existing error output
            pkio.unchecked_remove(simulation_db.json_filename(template_common.OUTPUT_BASE_NAME))
    simulation_db.write_result(res)