sirepo.template package

Templates are used to configure codes

copyright:

Copyright (c) 2016-2022 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

sirepo.template.assert_sim_type(*args, **kwargs)[source]

DEPRECATED

sirepo.template.import_module(type_or_data)[source]

Load the simulation_type module

Parameters:

type_or_data (str or dict) – simulation type or description

Returns:

simulation type module instance

Return type:

module

sirepo.template.is_sim_type(*args, **kwargs)[source]

DEPRECATED

sirepo.template.run_epilogue(sim_type)[source]

Submodules

sirepo.template.activait module

sirepo.template.canvas module

sirepo.template.code_variable module

Code variables.

copyright:

Copyright (c) 2020 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

class sirepo.template.code_variable.CodeVar(variables, evaluator, case_insensitive=False)[source]

Bases: object

canonicalize(expr)[source]
compute_cache(data, schema)[source]
eval_var(expr)[source]
eval_var_with_assert(expr)[source]
generate_variables(variable_formatter, postfix=False)[source]
get_expr_dependencies(expr, depends=None, visited=None)[source]
classmethod infix_to_postfix(expr)[source]
classmethod is_var_value(value)[source]
recompute_cache(cache)[source]
stateful_compute_recompute_rpn_cache_values(data, schema, **kwargs)[source]
stateful_compute_rpn_value(data, schema, **kwargs)[source]
stateful_compute_validate_rpn_delete(data, schema, **kwargs)[source]
validate_var_delete(name, data, schema)[source]
class sirepo.template.code_variable.CodeVarDeleteIterator(code_var, name)[source]

Bases: ModelIterator

field(model, field_schema, field)[source]
class sirepo.template.code_variable.CodeVarIterator(code_var, data, schema)[source]

Bases: ModelIterator

add_to_cache(name, value)[source]
field(model, field_schema, field)[source]
class sirepo.template.code_variable.PurePythonEval(constants=None)[source]

Bases: object

eval_var(expr, depends, variables)[source]
classmethod postfix_to_infix(expr)[source]

sirepo.template.controls module

sirepo.template.cortex module

sirepo.template.elegant module

sirepo.template.elegant_command_importer module

sirepo.template.elegant_command_parser module

elegant command parser.

copyright:

Copyright (c) 2016 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

sirepo.template.elegant_command_parser.parse_file(command_text, update_filenames)[source]

sirepo.template.elegant_common module

sirepo.template.elegant_lattice_importer module

sirepo.template.elegant_lattice_parser module

elegant lattice parser.

copyright:

Copyright (c) 2015 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

sirepo.template.elegant_lattice_parser.parse_file(lattice_text, rpn_variables, maxId=0)[source]

sirepo.template.epicsllrf module

sirepo.template.flash module

sirepo.template.flash_parser module

Flash Config parser.

copyright:

Copyright (c) 2021 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

class sirepo.template.flash_parser.ConfigParser[source]

Bases: object

parse(config_text)[source]
class sirepo.template.flash_parser.ParameterParser[source]

Bases: object

parse(sim_in, par_text)[source]
class sirepo.template.flash_parser.SetupParameterParser(setup_dir)[source]

Bases: object

generate_schema()[source]
classmethod model_name_from_flash_unit_name(text)[source]
classmethod parse_string_or_number(field_type, value, maybe_quoted=False)[source]
classmethod remove_quotes(value)[source]

sirepo.template.flash_views module

Flash Config parser.

copyright:

Copyright (c) 2021 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

class sirepo.template.flash_views.SpecializedViews[source]

Bases: object

update_schema(schema)[source]

sirepo.template.genesis module

sirepo.template.hdf5_util module

sirepo.template.hellweg module

sirepo.template.hellweg_dump_reader module

Hellweg dump parser.

copyright:

Copyright (c) 2017 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

class sirepo.template.hellweg_dump_reader.TBeamHeader[source]

Bases: Structure

beam_current

Structure/Union member

beam_h

Structure/Union member

beam_lmb

Structure/Union member

input_current

Structure/Union member

class sirepo.template.hellweg_dump_reader.TDimension[source]

Bases: Structure

Nx

Structure/Union member

Ny

Structure/Union member

Nz

Structure/Union member

class sirepo.template.hellweg_dump_reader.TField[source]

Bases: Structure

r

Structure/Union member

th

Structure/Union member

z

Structure/Union member

class sirepo.template.hellweg_dump_reader.TFieldMap2D[source]

Bases: Structure

Dim

Structure/Union member

Field

Structure/Union member

Piv

Structure/Union member

class sirepo.template.hellweg_dump_reader.THeader[source]

Bases: Structure

NParticles

Structure/Union member

NPoints

Structure/Union member

class sirepo.template.hellweg_dump_reader.TParticle[source]

Bases: Structure

Th

Structure/Union member

g

Structure/Union member

gb

Structure/Union member

lost

Structure/Union member

phi

Structure/Union member

r

Structure/Union member

z

Structure/Union member

class sirepo.template.hellweg_dump_reader.TPivot[source]

Bases: Structure

X

Structure/Union member

Y

Structure/Union member

Z

Structure/Union member

class sirepo.template.hellweg_dump_reader.TStructure[source]

Bases: Structure

AF

Structure/Union member

B

Structure/Union member

Bmap

Structure/Union member

CellNumber

Structure/Union member

E

Structure/Union member

P

Structure/Union member

Ra

Structure/Union member

Rp

Structure/Union member

alpha

Structure/Union member

betta

Structure/Union member

dF

Structure/Union member

drift

Structure/Union member

jump

Structure/Union member

ksi

Structure/Union member

lmb

Structure/Union member

sirepo.template.hellweg_dump_reader.beam_header(filename)[source]
sirepo.template.hellweg_dump_reader.beam_info(filename, idx)[source]
sirepo.template.hellweg_dump_reader.get_label(field)[source]
sirepo.template.hellweg_dump_reader.get_parameter(info, field)[source]
sirepo.template.hellweg_dump_reader.get_parameter_label(field)[source]
sirepo.template.hellweg_dump_reader.get_parameter_title(field)[source]
sirepo.template.hellweg_dump_reader.get_points(info, field, particle_species)[source]
sirepo.template.hellweg_dump_reader.parameter_index(name)[source]
sirepo.template.hellweg_dump_reader.particle_info(filename, field, count, particle_species)[source]

sirepo.template.impactt module

sirepo.template.impactt_parser module

sirepo.template.impactx module

sirepo.template.jspec module

sirepo.template.lattice module

Lattice utilities.

copyright:

Copyright (c) 2019 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

class sirepo.template.lattice.ElementIterator(filename_map, formatter)[source]

Bases: ModelIterator

Iterate all fields, adding any set to non-default values to the results.

IS_DISABLED_FIELD = 'isDisabled'
end(model)[source]
field(model, field_schema, field)[source]
is_ignore_field(field)[source]
start(model)[source]
class sirepo.template.lattice.InputFileIterator(sim_data, update_filenames=True)[source]

Bases: ModelIterator

Iterate and extract all InputFile filenames.

field(model, field_schema, field)[source]
class sirepo.template.lattice.LatticeIterator(filename_map, formatter)[source]

Bases: ElementIterator

Iterate all lattice elements/fields which are not set to the default value.

is_ignore_field(field)[source]
class sirepo.template.lattice.LatticeParser(sim_data)[source]

Bases: object

COMMAND_PREFIX = 'command_'
parse_file(lattice_text)[source]
class sirepo.template.lattice.LatticeUtil(data, schema)[source]

Bases: object

explode_beamline(beamline_id)[source]
classmethod file_id(model_id, field_index)[source]
classmethod file_id_from_output_model_name(name)[source]
classmethod find_first_command(data, command_type)[source]
classmethod fixup_output_files(data, schema, output_file_iterator)[source]
get_item(item_id)[source]
classmethod get_lattice_id_from_file_id(data, file_id)[source]
classmethod has_command(data, command_type)[source]
classmethod is_beamline(model)[source]

Is the model a beamline?

classmethod is_command(model)[source]

Is the model a command or a lattice element?

iterate_models(iterator, name=None)[source]

Iterate the models in the named container. By default the commands and elements containers are iterated.

classmethod max_id(data)[source]
classmethod model_name_for_data(model)[source]

Returns the model’s schema name.

classmethod output_model_name(file_id)[source]
render_lattice(fields, quote_name=False, want_semicolon=False, want_name=True, want_var_assign=False, madx_name=False, comment='//')[source]

Render lattice elements.

render_lattice_and_beamline(iterator, **kwargs)[source]
select_beamline()[source]

Returns the beamline to use based for the selected report.

sort_elements_and_beamlines()[source]

Sort elements and beamline models in place, by (type, name) and (name)

classmethod type_for_data(model)[source]
class sirepo.template.lattice.ModelIterator[source]

Bases: object

Base class for model iterators with stubbed out methods. When iterate_models() is called, the iterator calls are made:

it.start(model) foreach field in model:

it.field(model, field_schema, field)

it.end(model)

end(model)[source]
field(model, field_schema, field)[source]
start(model)[source]
class sirepo.template.lattice.UpdateIterator(update_func)[source]

Bases: ModelIterator

field(model, field_schema, field)[source]

sirepo.template.line_parser module

Simple line parser.

Parses a line of input one character at a time.

copyright:

Copyright (c) 2016 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

class sirepo.template.line_parser.LineParser(next_id=0)[source]

Bases: object

Parses a line of input one character at a time. Call set_line() prior to other metho calls.

assert_char(char)[source]

Raises an Error unless the current character matches

assert_end_of_line(comment_char='!')[source]

Raises an error unless the remaining line is empty

get_index()[source]
has_char()[source]
ignore_whitespace()[source]

Skip whitespace

increment_line_number()[source]
next_char()[source]

Advance to the next character. Returns None if end of line

next_id()[source]
parse_quoted_value()[source]
parse_value(end_regex='[\\s,=\\!)*]')[source]

Parses a value, possibly quoted.

peek_char()[source]
raise_error(message)[source]
read_until(regex)[source]

Reads until the end-of-line or the character regex is matched

reset_index(index)[source]

Reset the character index

set_line(line)[source]

Prepares a line for parsing.

sirepo.template.madx module

sirepo.template.madx_converter module

sirepo.template.madx_parser module

MAD-X parser.

copyright:

Copyright (c) 2020 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

class sirepo.template.madx_parser.MadXParser[source]

Bases: LatticeParser

parse_file(lattice_text, downcase_variables=False)[source]
sirepo.template.madx_parser.parse_file(lattice_text, downcase_variables=False)[source]
sirepo.template.madx_parser.parse_tfs_file(tfs_file, header_only=False, want_page=-1)[source]
sirepo.template.madx_parser.parse_tfs_page_info(tfs_file)[source]

sirepo.template.myapp module

sirepo.template.omega module

sirepo.template.opal module

sirepo.template.opal_parser module

OPAL parser.

copyright:

Copyright (c) 2020 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

class sirepo.template.opal_parser.OpalParser[source]

Bases: LatticeParser

parse_file(lattice_text, update_filenames)[source]
sirepo.template.opal_parser.parse_file(lattice_text, filename=None, update_filenames=True)[source]
sirepo.template.opal_parser.set_simulation_name(data, filename)[source]

sirepo.template.openmc module

sirepo.template.openmc_util module

sirepo.template.particle_beam module

sirepo.template.radia module

sirepo.template.radia_util module

sirepo.template.raydata module

sirepo.template.sdds_util module

sirepo.template.shadow module

sirepo.template.silas module

sirepo.template.srw module

sirepo.template.srw_common module

SRW simulation_db/template/sim_data independent routines

copyright:

Copyright (c) 2019 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

sirepo.template.srw_common.process_beam_parameters(ebeam)[source]

sirepo.template.srw_debug module

sirepo.template.srw_fixup module

sirepo.template.srw_importer module

sirepo.template.srw_shadow module

sirepo.template.srwl_uti_brightness module

sirepo.template.template_common module

Common execution template.

copyright:

Copyright (c) 2015 RadiaSoft LLC. All Rights Reserved.

license:

http://www.apache.org/licenses/LICENSE-2.0.html

sirepo.template.template_common.INPUT_BASE_NAME = 'in.json'

Input json file

class sirepo.template.template_common.JobCmdFile(**kwargs)[source]

Bases: PKDict

Returned by dispatched job commands

analysis_job_dispatch, stateless_compute_dispatch, and stateful_compute_dispatch support file returns.

Parameters:
  • reply_content (object) – what to send [reply_path.read()]

  • reply_path (py.path) – py.path of file to read

  • reply_uri (str) – what to call the file [reply_path.basename]

class sirepo.template.template_common.LogParser(run_dir, **kwargs)[source]

Bases: PKDict

parse_for_errors()[source]
class sirepo.template.template_common.ModelUnits(unit_def)[source]

Bases: object

Convert model fields from native to sirepo format, or from sirepo to native format.

Examples::
def _xpas(value, is_native):

# custom field conversion code would go here return value

mu = ModelUnits({
‘CHANGREF’: {

‘XCE’: ‘cm_to_m’, ‘YCE’: ‘cm_to_m’, ‘ALE’: ‘deg_to_rad’, ‘XPAS’: _xpas,

},

}) m = mu.scale_from_native(‘CHANGREF’, {

‘XCE’: 2, ‘YCE’: 0, ‘ALE’: 8, ‘XPAS’: ‘#20|20|20’,

}) assert m[‘XCE’] == 2e-2 assert ModelUnits.scale_value(2, ‘cm_to_m’, True) == 2e-2 assert ModelUnits.scale_value(0.02, ‘cm_to_m’, False) == 2

scale_from_native(name, model)[source]

Scale values from native values into sirepo units.

scale_to_native(name, model)[source]

Scale values from sirepo units to native values.

classmethod scale_value(value, scale_type, is_native)[source]

Scale one value using the specified handler.

sirepo.template.template_common.NUMERIC_RE = re.compile('^\\s*(\\-|\\+)?(\\d+|(\\d*(\\.\\d*)))([eE][+-]?\\d+)?\\s*$')

Test if value is numeric text

class sirepo.template.template_common.NamelistParser[source]

Bases: object

parse_text(text)[source]
exception sirepo.template.template_common.NoH5PathError[source]

Bases: KeyError

The given path into an h5 file does not exist

sirepo.template.template_common.OUTPUT_BASE_NAME = 'out'

Output json file

sirepo.template.template_common.PARAMETERS_PYTHON_FILE = 'parameters.py'

Python file (not all simulations)

class sirepo.template.template_common.ParticleEnergy[source]

Bases: object

Computes the energy related fields for a particle from one field. Units:

mass [GeV/c^2] pc [GeV/c] energy [GeV] brho [Tm]

ENERGY_PRIORITY = {'impactx': ['energy'], 'madx': ['energy', 'pc', 'gamma', 'beta', 'brho'], 'opal': ['gamma', 'energy', 'pc']}
PARTICLE_MASS_AND_CHARGE = {'antiproton': [0.938272046, -1], 'electron': [0.000510998928, -1], 'muon': [0.1056583755, -1], 'positron': [0.000510998928, 1], 'proton': [0.938272046, 1]}
SPEED_OF_LIGHT = 299792458
classmethod compute_energy(sim_type, particle, energy)[source]
classmethod get_charge(sim_type, particle, beam)[source]
classmethod get_mass(sim_type, particle, beam)[source]
sirepo.template.template_common.RUN_LOG = 'run.log'

stderr and stdout

sirepo.template.template_common.analysis_job_dispatch(data, **kwargs)[source]
sirepo.template.template_common.compute_field_range(args, compute_range, run_dir)[source]

Computes the fieldRange values for all parameters across all animation files. Caches the value on the animation input file. compute_range() is called to read the simulation specific datafiles and extract the ranges by field.

sirepo.template.template_common.compute_plot_color_and_range(plots, plot_colors=None, fixed_y_range=None)[source]

For parameter plots, assign each plot a color and compute the full y_range. If a fixed range is provided, use that instead

sirepo.template.template_common.enum_text(schema, name, value)[source]
sirepo.template.template_common.exec_parameters(path=None)[source]
sirepo.template.template_common.exec_parameters_with_mpi()[source]
sirepo.template.template_common.file_extension_ok(file_path, white_list=None, black_list=['py', 'pyc'])[source]

Determine whether a file has an acceptable extension

Parameters:
  • file_path (str) – name of the file to examine

  • white_list ([str]) – list of file types allowed (defaults to empty list)

  • black_list ([str]) – list of file types rejected (defaults to [‘py’, ‘pyc’]). Ignored if white_list is not empty

Returns:

True If white_list non-empty: True if the file’s extension matches any in the list, otherwise False If white_list is empty: False if the file’s extension matches any in black_list, otherwise True

Return type:

If file is a directory

sirepo.template.template_common.flatten_data(d, res, prefix='')[source]

Takes a nested dictionary and converts it to a single level dictionary with flattened keys.

sirepo.template.template_common.generate_parameters_file(data, is_run_mpi=False)[source]
sirepo.template.template_common.get_exec_parameters_cmd(is_mpi=False)[source]
sirepo.template.template_common.h5_to_dict(hf, path=None)[source]
sirepo.template.template_common.heatmap(values, model, plot_fields=None, weights=None)[source]

Computes a report histogram (x_range, y_range, z_matrix) for a report model.

sirepo.template.template_common.histogram_bins(nbins)[source]

Ensure the histogram count is in a valid range

sirepo.template.template_common.jinja_filename(filename)[source]
sirepo.template.template_common.model_from_frame_args(frame_args)[source]
sirepo.template.template_common.parameter_plot(x, plots, model, plot_fields=None, plot_colors=None)[source]
sirepo.template.template_common.parse_enums(enum_schema)[source]

Returns a list of enum values, keyed by enum name.

sirepo.template.template_common.parse_mpi_log(run_dir)[source]
sirepo.template.template_common.read_dict_from_h5(file_path, h5_path=None)[source]
sirepo.template.template_common.read_last_csv_line(path)[source]
sirepo.template.template_common.read_sequential_result(run_dir)[source]

Read result data file from simulation

Parameters:

run_dir (py.path) – where to find output

Returns:

result

Return type:

dict

sirepo.template.template_common.render_jinja(sim_type, v, name='parameters.py', jinja_env=None)[source]

Render the values into a jinja template.

Parameters:
  • sim_type (str) – application name

  • v – flattened model data

Returns:

source text

Return type:

str

async sirepo.template.template_common.sim_frame(frame_id, op, qcall)[source]
sirepo.template.template_common.sim_frame_dispatch(frame_args)[source]
sirepo.template.template_common.stateful_compute_dispatch(data, **kwargs)[source]
sirepo.template.template_common.stateless_compute_dispatch(data, **kwargs)[source]
sirepo.template.template_common.subprocess_output(cmd, env=None)[source]

Run cmd and return output or None, logging errors.

Parameters:

cmd (list) – what to run

Returns:

output is None on error else a stripped string

Return type:

str

sirepo.template.template_common.text_data_file(filename, run_dir)[source]

Return a datafile with a .txt extension so the text/plain mimetype is used.

sirepo.template.template_common.validate_model(model_data, model_schema, enum_info)[source]

Ensure the value is valid for the field type. Scales values as needed.

sirepo.template.template_common.validate_models(model_data, model_schema)[source]

Validate top-level models in the schema. Returns enum_info.

sirepo.template.template_common.write_dict_to_h5(d, file_path, h5_path=None)[source]

Store the contents of a dict in an h5 file starting at the provided path. Stores the data recursively so that

{a: A, b: {c: C, d: D}}

maps the data to paths

<h5_path>/a -> A <h5_path>/b/c -> C <h5_path>/b/d -> D

h5_to_dict() performs the reverse process

sirepo.template.template_common.write_sequential_result(result, run_dir=None)[source]

Write the results of a sequential simulation to disk.

Parameters:
  • result (dict) – The results of the simulation

  • run_dir (py.path) – Defaults to current dir

sirepo.template.transfer_mat_bl module

sirepo.template.warppba module

sirepo.template.warpvnd module

sirepo.template.zgoubi module

sirepo.template.zgoubi_importer module

sirepo.template.zgoubi_parser module

zgoubi input file parser.

l:copyright: Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved. :license: http://www.apache.org/licenses/LICENSE-2.0.html

sirepo.template.zgoubi_parser.parse_file(zgoubi_text, max_id=0)[source]
sirepo.template.zgoubi_parser.parse_float(v)[source]
sirepo.template.zgoubi_parser.tosca_file_count(el)[source]