Example #1
0
def run(cfg_dir):
    data = simulation_db.read_json(template_common.INPUT_BASE_NAME)
    report = data['report']
    if 'bunchReport' in report or report == 'twissReport' or report == 'twissReport2':
        template_common.exec_parameters()
        template.save_sequential_report_data(data, py.path.local(cfg_dir))
    else:
        raise AssertionError('unknown report: {}'.format(report))
Example #2
0
def run_background(cfg_dir):
    data = simulation_db.read_json(template_common.INPUT_BASE_NAME)
    distribution = data['models']['bunch']['distribution']
    run_with_mpi = distribution == 'lattice' or distribution == 'file'
    if run_with_mpi:
        template_common.exec_parameters_with_mpi()
    else:
        #TODO(pjm): MPI doesn't work with rsbeams distributions yet
        template_common.exec_parameters()
Example #3
0
def run(cfg_dir):
    template_common.exec_parameters()
    d = pkio.py_path(cfg_dir)
    template_common.write_sequential_result(
        PKDict(elementValues=template._read_summary_line(
            d,
            simulation_db.get_schema(template.SIM_TYPE).constants.maxBPMPoints,
        )),
        run_dir=d,
    )
Example #4
0
def run(cfg_dir):
    template_common.exec_parameters()
    data = simulation_db.read_json(template_common.INPUT_BASE_NAME)
    if data['report'] == 'fieldReport':
        res = template.generate_field_report(data, cfg_dir)
        res['tof_expected'] = field_results.tof_expected
        res['steps_expected'] = field_results.steps_expected,
        res['e_cross'] = field_results.e_cross
    elif data['report'] == 'fieldComparisonReport':
        wp.step(template.COMPARISON_STEP_SIZE)
        res = template.generate_field_comparison_report(data, cfg_dir)
    else:
        raise AssertionError('unknown report: {}'.format(data['report']))
    template_common.write_sequential_result(res)
Example #5
0
def _run_beam_statistics(cfg_dir, data):
    template_common.exec_parameters()
    report = data.models.beamStatisticsReport
    d = pkjson.load_any(py.path.local(cfg_dir).join(template.BEAM_STATS_FILE))
    x = [record.s for record in d]
    plots = []

    for y in ('y1', 'y2', 'y3'):
        if report[y] == 'none':
            continue
        label = report[y]
        if label in ('sigmax', 'sigmaz'):
            label += ' [m]'
        elif label in ('sigdix', 'sigdiz', 'angxz', 'angxpzp'):
            label += ' [rad]'
        plots.append(PKDict(
            field=report[y],
            label=label,
        ))
    for item in d:
        for p in plots:
            if p.field == 'angxz':
                sigmax = numpy.array(_beam_statistics_values(d, 'sigmax'))
                sigmaz = numpy.array(_beam_statistics_values(d, 'sigmaz'))
                sigmaxz = numpy.array(_beam_statistics_values(d, 'sigmaxz'))
                p.points = ((1 / 2) *
                            numpy.arctan(2.e-4 * sigmaxz /
                                         (sigmax**2 - sigmaz**2))).tolist()
            elif p.field == 'angxpzp':
                sigdix = numpy.array(_beam_statistics_values(d, 'sigdix'))
                sigdiz = numpy.array(_beam_statistics_values(d, 'sigdiz'))
                sigmaxpzp = numpy.array(_beam_statistics_values(
                    d, 'sigmaxpzp'))
                p.points = ((1 / 2) *
                            numpy.arctan(2 * sigmaxpzp /
                                         (sigdix**2 - sigdiz**2))).tolist()
            else:
                p.points = _beam_statistics_values(d, p.field)
    return PKDict(
        aspectRatio=0.3,
        title='',
        x_range=[min(x), max(x)],
        y_label='',
        x_label='s [m]',
        x_points=x,
        plots=plots,
        y_range=template_common.compute_plot_color_and_range(plots),
    )
Example #6
0
def _run_opal(with_mpi=False, compute_positions=False):
    if with_mpi and mpi.cfg.cores < 2:
        with_mpi = False
    if with_mpi:
        mpi.run_program(
            ['opal', template.OPAL_INPUT_FILE],
            output=template.OPAL_OUTPUT_FILE,
        )
    else:
        pksubprocess.check_call_with_signals(
            ['opal', template.OPAL_INPUT_FILE],
            output=template.OPAL_OUTPUT_FILE,
            msg=pkdlog,
        )
    if compute_positions:
        template_common.exec_parameters(template.OPAL_POSITION_FILE)
Example #7
0
def _run_jspec(data):
    _elegant_to_madx(data['models']['ring'])
    r = template_common.exec_parameters()
    f = template.JSPEC_INPUT_FILENAME
    pkio.write_text(f, r.jspec_file)
    pksubprocess.check_call_with_signals(['jspec', f],
                                         msg=pkdlog,
                                         output=template.JSPEC_LOG_FILE)
Example #8
0
def _run_hellweg(cfg_dir):
    r = template_common.exec_parameters()
    pkio.write_text(template.HELLWEG_INPUT_FILE, r.input_file)
    pkio.write_text(template.HELLWEG_INI_FILE, r.ini_file)
    s = solver.BeamSolver(template.HELLWEG_INI_FILE, template.HELLWEG_INPUT_FILE)
    s.solve()
    s.save_output(template.HELLWEG_SUMMARY_FILE)
    s.dump_bin(template.HELLWEG_DUMP_FILE)
Example #9
0
def _run_tunes_report(cfg_dir, data):
    r = template_common.exec_parameters()
    pkio.write_text(template.TUNES_INPUT_FILE, r.tunes_file)
    #TODO(pjm): uses datafile from animation directory
    os.symlink('../animation/zgoubi.fai', 'zgoubi.fai')
    subprocess.call([_TUNES_PATH])
    template_common.write_sequential_result(
        template.extract_tunes_report(cfg_dir, data))
Example #10
0
def run_background(cfg_dir):
    """Run warpvnd in ``cfg_dir`` with mpi

    Args:
        cfg_dir (str): directory to run warpvnd in
    """
    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':
        simulation_db.write_json(
            py.path.local(cfg_dir).join(template.MPI_SUMMARY_FILE), {
                'mpiCores': mpi.cfg.cores,
            })
        template_common.exec_parameters_with_mpi()
    else:
        template_common.exec_parameters()
Example #11
0
def _run_code():
    """Run code program with isolated locals()
    """
    r = template_common.exec_parameters()
    # advance the window until zmin is >= 0 (avoids mirroring in output)
    i = r.inc_steps
    if r.USE_BEAM:
        for x in range(0, r.diag_period, i):
            r.step(i)
    else:
        while r.w3d.zmmin + r.top.zgrid < 0:
            r.step(i)
Example #12
0
def run_elegant(with_mpi=False):
    # also used by pkcli.rcscon
    r = template_common.exec_parameters()
    pkio.write_text('elegant.lte', r.lattice_file)
    ele = 'elegant.ele'
    pkio.write_text(ele, r.elegant_file)
    kwargs = {
        'output': ELEGANT_LOG_FILE,
        'env': elegant_common.subprocess_env(),
    }
    #TODO(robnagler) Need to handle this specially, b/c different binary
    if r.execution_mode == 'parallel' and with_mpi and mpi.cfg.cores > 1:
        mpi.run_program(['Pelegant', ele], **kwargs)
    else:
        pksubprocess.check_call_with_signals(['elegant', ele],
                                             msg=pkdlog,
                                             **kwargs)
Example #13
0
File: srw.py Project: ahebnl/Sirepo
def run(cfg_dir):
    """Run srw in ``cfg_dir``

    Args:
        cfg_dir (str): directory to run srw in
    """
    sim_in = simulation_db.read_json(template_common.INPUT_BASE_NAME)
    r = template_common.exec_parameters()
    # special case for importing python code
    m = sim_in.report
    if m == 'backgroundImport':
        template_common.write_sequential_result(
            PKDict({sirepo.template.srw.PARSED_DATA_ATTR: r.parsed_data}))
    else:
        template_common.write_sequential_result(
            sirepo.template.srw.extract_report_data(
                sirepo.template.srw.get_filename_for_model(m),
                sim_in,
            ), )
Example #14
0
def run_background(cfg_dir):
    template_common.exec_parameters()
Example #15
0
def run(cfg_dir):
    template_common.exec_parameters()
    data = simulation_db.read_json(template_common.INPUT_BASE_NAME)
    template.extract_report_data(py.path.local(cfg_dir), data)
Example #16
0
def _run_zgoubi(cfg_dir, python_file=template_common.PARAMETERS_PYTHON_FILE):
    template_common.exec_parameters(python_file)
    subprocess.call([_EXE_PATH])
Example #17
0
def run_background(cfg_dir):
    data = simulation_db.read_json(template_common.INPUT_BASE_NAME)
    if data.report == 'elegantAnimation':
        return _run_elegant_simulation(cfg_dir)
    template_common.exec_parameters()
Example #18
0
def _run_shadow(cfg_dir, data):
    beam = template_common.exec_parameters().beam
    model = data['models'][data['report']]
    column_values = _SCHEMA['enum']['ColumnValue']

    if 'y' in model:
        x_range = None
        y_range = None
        if model['overrideSize'] == '1':
            x_range = (numpy.array([
                model['horizontalOffset'] - model['horizontalSize'] / 2,
                model['horizontalOffset'] + model['horizontalSize'] / 2,
            ]) * _MM_TO_CM).tolist()
            y_range = (numpy.array([
                model['verticalOffset'] - model['verticalSize'] / 2,
                model['verticalOffset'] + model['verticalSize'] / 2,
            ]) * _MM_TO_CM).tolist()
        ticket = beam.histo2(
            int(model['x']),
            int(model['y']),
            nbins=template_common.histogram_bins(model['histogramBins']),
            ref=int(model['weight']),
            nolost=1,
            calculate_widths=0,
            xrange=x_range,
            yrange=y_range,
        )
        _scale_ticket(ticket)
        values = ticket['histogram'].T
        assert not numpy.isnan(values).any(), 'nan values found'
        res = PKDict(
            x_range=[
                ticket['xrange'][0], ticket['xrange'][1], ticket['nbins_h']
            ],
            y_range=[
                ticket['yrange'][0], ticket['yrange'][1], ticket['nbins_v']
            ],
            x_label=_label_with_units(model['x'], column_values),
            y_label=_label_with_units(model['y'], column_values),
            z_label='Intensity' if int(model['weight']) else 'Rays',
            title=u'{}, {}'.format(_label(model['x'], column_values),
                                   _label(model['y'], column_values)),
            z_matrix=values.tolist(),
            frameCount=1,
        )
    else:
        weight = int(model['weight'])
        ticket = beam.histo1(
            int(model['column']),
            nbins=template_common.histogram_bins(model['histogramBins']),
            ref=weight,
            nolost=1,
            calculate_widths=0,
        )
        _scale_ticket(ticket)
        res = PKDict(
            title=_label(model['column'], column_values),
            x_range=[
                ticket['xrange'][0], ticket['xrange'][1], ticket['nbins']
            ],
            y_label=u'{}{}'.format(
                'Number of Rays', u' weighted by {}'.format(
                    _label_for_weight(model['weight'], column_values))
                if weight else ''),
            x_label=_label_with_units(model['column'], column_values),
            points=ticket['histogram'].T.tolist(),
            frameCount=1,
        )
        #pkdlog('range amount: {}', res['x_range'][1] - res['x_range'][0])
        #1.55431223448e-15
        dist = res['x_range'][1] - res['x_range'][0]
        #TODO(pjm): only rebalance range if outside of 0
        if dist < 1e-14:
            #TODO(pjm): include offset range for client
            res['x_range'][0] = 0
            res['x_range'][1] = dist
    return res
Example #19
0
def run(cfg_dir):
    """Run shadow in ``cfg_dir``

    Args:
        cfg_dir (str): directory to run shadow in
    """
    beam = template_common.exec_parameters().beam
    data = simulation_db.read_json(template_common.INPUT_BASE_NAME)
    model = data['models'][data['report']]
    column_values = _SCHEMA['enum']['ColumnValue']

    if 'y' in model:
        x_range = None
        y_range = None
        if model['overrideSize'] == '1':
            x_range = (numpy.array([
                model['horizontalOffset'] - model['horizontalSize'] / 2,
                model['horizontalOffset'] + model['horizontalSize'] / 2,
            ]) * _MM_TO_CM).tolist()
            y_range = (numpy.array([
                model['verticalOffset'] - model['verticalSize'] / 2,
                model['verticalOffset'] + model['verticalSize'] / 2,
            ]) * _MM_TO_CM).tolist()
        ticket = beam.histo2(int(model['x']),
                             int(model['y']),
                             nbins=template_common.histogram_bins(
                                 model['histogramBins']),
                             ref=int(model['weight']),
                             nolost=1,
                             calculate_widths=0,
                             xrange=x_range,
                             yrange=y_range)
        _scale_ticket(ticket)
        values = ticket['histogram'].T
        assert not numpy.isnan(values).any(), 'nan values found'
        res = {
            'x_range':
            [ticket['xrange'][0], ticket['xrange'][1], ticket['nbins_h']],
            'y_range':
            [ticket['yrange'][0], ticket['yrange'][1], ticket['nbins_v']],
            'x_label':
            _label_with_units(model['x'], column_values),
            'y_label':
            _label_with_units(model['y'], column_values),
            'z_label':
            'Frequency',
            'title':
            u'{}, {}'.format(_label(model['x'], column_values),
                             _label(model['y'], column_values)),
            'z_matrix':
            values.tolist(),
            'frameCount':
            1,
        }
    else:
        weight = int(model['weight'])
        ticket = beam.histo1(int(model['column']),
                             nbins=template_common.histogram_bins(
                                 model['histogramBins']),
                             ref=weight,
                             nolost=1,
                             calculate_widths=0)
        _scale_ticket(ticket)
        res = {
            'title':
            _label(model['column'], column_values),
            'x_range':
            [ticket['xrange'][0], ticket['xrange'][1], ticket['nbins']],
            'y_label':
            u'{}{}'.format(
                'Number of Rays', u' weighted by {}'.format(
                    _label_for_weight(model['weight'], column_values))
                if weight else ''),
            'x_label':
            _label_with_units(model['column'], column_values),
            'points':
            ticket['histogram'].T.tolist(),
            'frameCount':
            1,
        }
        #pkdlog('range amount: {}', res['x_range'][1] - res['x_range'][0])
        #1.55431223448e-15
        dist = res['x_range'][1] - res['x_range'][0]
        #TODO(pjm): only rebalance range if outside of 0
        if dist < 1e-14:
            #TODO(pjm): include offset range for client
            res['x_range'][0] = 0
            res['x_range'][1] = dist
    template_common.write_sequential_result(res)
Example #20
0
def _run_simulation_loop(server_address):
    l = template_common.exec_parameters()
    return _wait_for_beam_steering(server_address, l.update_and_run_simulation)