sirepo.template package

Submodules

sirepo.template.adm module

Myapp execution template.

copyright:Copyright (c) 2017-2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.template.adm.get_server_data(id)[source]

sirepo.template.elegant module

sirepo.template.elegant_command_importer 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_command_importer.import_file(text)[source]

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)[source]

sirepo.template.elegant_common module

Common values for elegant

copyright:Copyright (c) 2017 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.template.elegant_common.RESOURCE_DIR = local('/home/docs/checkouts/readthedocs.org/user_builds/sirepo/checkouts/latest/sirepo/package_data/template/elegant')

Where to get files

sirepo.template.elegant_common.SIM_TYPE = 'elegant'

Application name

sirepo.template.elegant_common.sort_elements_and_beamlines(data)[source]
sirepo.template.elegant_common.subprocess_env()[source]

Adds RPN_DEFNS to os.environ

Returns:copy of env
Return type:dict
sirepo.template.elegant_common.subprocess_output(cmd)[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.elegant_lattice_importer 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_importer.build_variable_dependency(value, variables, depends)[source]
sirepo.template.elegant_lattice_importer.import_file(text, data=None)[source]
sirepo.template.elegant_lattice_importer.is_rpn_value(value)[source]
sirepo.template.elegant_lattice_importer.max_id(data)[source]
sirepo.template.elegant_lattice_importer.parse_rpn_value(value, variable_list)[source]
sirepo.template.elegant_lattice_importer.validate_fields(el, rpn_cache, rpn_variables)[source]

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, maxId=0)[source]

sirepo.template.hellweg module

Hellweg execution template.

copyright:Copyright (c) 2017 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.template.hellweg.SIM_TYPE = 'hellweg'

Simulation type

sirepo.template.hellweg.background_percent_complete(report, run_dir, is_running)[source]
sirepo.template.hellweg.extract_beam_histrogram(report, run_dir, frame)[source]
sirepo.template.hellweg.extract_beam_report(report, run_dir, frame)[source]
sirepo.template.hellweg.extract_parameter_report(report, run_dir)[source]
sirepo.template.hellweg.extract_particle_report(report, run_dir)[source]
sirepo.template.hellweg.fixup_old_data(data)[source]
sirepo.template.hellweg.get_animation_name(data)[source]
sirepo.template.hellweg.get_application_data(data)[source]
sirepo.template.hellweg.get_simulation_frame(run_dir, data, model_data)[source]
sirepo.template.hellweg.lib_files(data, source_lib)[source]

What models are required for this data[‘report’]

Parameters:data (dict) – simulation
Returns:Named models, model fields or values (dict, list) that affect report
Return type:list
sirepo.template.hellweg.python_source_for_model(data, model)[source]
sirepo.template.hellweg.remove_last_frame(run_dir)[source]
sirepo.template.hellweg.validate_delete_file(data, filename, file_type)[source]

Returns True if the filename is in use by the simulation data.

sirepo.template.hellweg.write_parameters(data, run_dir, is_parallel)[source]

Write the parameters file

Parameters:
  • data (dict) – input
  • run_dir (py.path) – where to write
  • is_parallel (bool) – run in background?

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: _ctypes.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: _ctypes.Structure

Nx

Structure/Union member

Ny

Structure/Union member

Nz

Structure/Union member

class sirepo.template.hellweg_dump_reader.TField[source]

Bases: _ctypes.Structure

r

Structure/Union member

th

Structure/Union member

z

Structure/Union member

class sirepo.template.hellweg_dump_reader.TFieldMap2D[source]

Bases: _ctypes.Structure

Dim

Structure/Union member

Field

Structure/Union member

Piv

Structure/Union member

class sirepo.template.hellweg_dump_reader.THeader[source]

Bases: _ctypes.Structure

NParticles

Structure/Union member

NPoints

Structure/Union member

class sirepo.template.hellweg_dump_reader.TParticle[source]

Bases: _ctypes.Structure

Th

Structure/Union member

beta

Structure/Union member

beta0

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: _ctypes.Structure

X

Structure/Union member

Y

Structure/Union member

Z

Structure/Union member

class sirepo.template.hellweg_dump_reader.TStructure[source]

Bases: _ctypes.Structure

AF

Structure/Union member

B

Structure/Union member

CellNumber

Structure/Union member

E

Structure/Union member

Hext

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)[source]
sirepo.template.hellweg_dump_reader.parameter_index(name)[source]
sirepo.template.hellweg_dump_reader.particle_info(filename, field, count)[source]

sirepo.template.jspec module

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.myapp module

Myapp execution template.

copyright:Copyright (c) 2017-2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.template.myapp.fixup_old_data(data)[source]
sirepo.template.myapp.get_data_file(run_dir, model, frame, options=None)[source]
sirepo.template.myapp.lib_files(data, source_lib)[source]
sirepo.template.myapp.python_source_for_model(data, model)[source]
sirepo.template.myapp.write_parameters(data, run_dir, is_parallel)[source]

sirepo.template.rs4pi module

sirepo.template.sdds_util module

sirepo.template.shadow module

sirepo.template.srw module

sirepo.template.srw_importer module

sirepo.template.srwl_uti_brightness module

sirepo.template.srwl_uti_brightness.CalcAngularfluxUnd(Ib, kx, kz, phix, phiz, n, nPer, E_elec, lam_u, enDetPar, relEnSpr, sigpxsq, sigpzsq)[source]
sirepo.template.srwl_uti_brightness.CalcBrightnessUnd(Ib, kx, kz, phix, phiz, n, E_elec, lam_u, nPer, enDetPar, relEnSpr, L, sigxsq, sigzsq, sigxpsq, sigzpsq)[source]
sirepo.template.srwl_uti_brightness.CalcDivergenceUnd(sigpsq, L, K, E_elec, lam_u, n, nPer, enDetPar, relEnSpr)[source]
sirepo.template.srwl_uti_brightness.CalcFluxUnd(Ib, kx, kz, phix, phiz, n, nPer, enDetPar, relEnSpr)[source]
sirepo.template.srwl_uti_brightness.CalcK(B, lam_u)[source]
sirepo.template.srwl_uti_brightness.CalcSizeUnd(sigsq, L, K, E_elec, lam_u, n, nPer, enDetPar, relEnSpr)[source]
sirepo.template.srwl_uti_brightness.KtoE(K, E_elec, lam_u, n)[source]
sirepo.template.srwl_uti_brightness.getE(nHarm, Ebeam, K, lam_u)[source]

Return energy [eV] of nth harmonic :param nHarm: harmonic number :param Ebeam: electron beam energy [GeV] :param K: deflection parameter :param lam_u: undulator period [m]

sirepo.template.srwl_uti_brightness.getK(By, lam_u)[source]

Return K value :param By: vertical magnetic field [T] :param lam_u: undulator period [m]

sirepo.template.srwl_uti_brightness.interpBright(x, y, W, xmin, ymin, xstep, ystep, nx, ny)[source]
sirepo.template.srwl_uti_brightness.srwl_und_ang_flux_en(Ib, kxmax, kzmax, kmin, numkpts, E_elec, lam_u, phix, phiz, n, nPer, enDetPar, relEnSpr, sigpxsq, sigpzsq)[source]
sirepo.template.srwl_uti_brightness.srwl_und_bright_en(Ib, kx, kz, phix, phiz, n, E_elec, lam_u, nPer, epeak, enDetPar, relEnSpr, L, sigxsq, sigzsq, sigxpsq, sigzpsq, kxmax, kzmax, kmin, numkpts)[source]
sirepo.template.srwl_uti_brightness.srwl_und_bright_en_fixedK(Ib, kx, kz, phix, phiz, n, E_elec, lam_u, nPer, epeak, emin, emax, numepts, relEnSpr, L, sigxsq, sigysq, sigxpsq, sigypsq)[source]
sirepo.template.srwl_uti_brightness.srwl_und_div_en(kxmax, kzmax, kmin, numkpts, E_elec, lam_u, phix, phiz, n, nPer, enDetPar, relEnSpr, sigpsq)[source]
sirepo.template.srwl_uti_brightness.srwl_und_div_en_fixedK(sigsq, L, K, E_elec, lam_u, n, nPer, epeak, emin, emax, numepts, relEnSpr)[source]
sirepo.template.srwl_uti_brightness.srwl_und_flux_en(Ib, kxmax, kzmax, kmin, numkpts, E_elec, lam_u, phix, phiz, n, nPer, enDetPar, relEnSpr)[source]
sirepo.template.srwl_uti_brightness.srwl_und_flux_en_fixedK(Ib, kx, kz, E_elec, lam_u, phix, phiz, n, nPer, epeak, emin, emax, numepts, relEnSpr)[source]
sirepo.template.srwl_uti_brightness.srwl_und_size_en(kxmax, kzmax, kmin, numkpts, E_elec, lam_u, phix, phiz, n, nPer, enDetPar, relEnSpr, sigsq)[source]
sirepo.template.srwl_uti_brightness.srwl_und_size_en_fixedK(sigsq, L, K, E_elec, lam_u, n, nPer, epeak, emin, emax, numepts, relEnSpr)[source]

sirepo.template.synergia module

sirepo.template.template_common module

SRW 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'

Input json file

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)

sirepo.template.template_common.RUN_LOG = 'run.log'

stderr and stdout

sirepo.template.template_common.compute_field_range(args, compute_range)[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)[source]

For parameter plots, assign each plot a color and compute the full y_range.

sirepo.template.template_common.copy_lib_files(data, source, target)[source]

Copy auxiliary files to target

Parameters:
  • data (dict) – simulation db
  • target (py.path) – destination directory
sirepo.template.template_common.enum_text(schema, name, value)[source]
sirepo.template.template_common.file_extension_ok(file_path, white_list=[], 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.filename_to_path(files, source_lib)[source]

Returns full, unique paths of simulation files

Returns:py.path.local to files
Return type:list
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.heatmap(values, model, plot_fields=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.is_watchpoint(name)[source]
sirepo.template.template_common.lib_file_name(model_name, field, value)[source]
sirepo.template.template_common.lib_files(data, source_lib=None)[source]

Return list of files used by the simulation

Parameters:data (dict) – sim db
Returns:py.path.local to files
Return type:list
sirepo.template.template_common.model_defaults(name, schema)[source]

Returns a set of default model values from the schema.

sirepo.template.template_common.parameter_plot(x, plots, model, plot_fields=None)[source]
sirepo.template.template_common.parse_animation_args(data, key_map)[source]

Parse animation args according to key_map

Parameters:
  • data (dict) – contains animationArgs
  • key_map (dict) – version to keys mapping, default is ‘’
Returns:

mapped animationArgs with version

Return type:

Dict

sirepo.template.template_common.parse_enums(enum_schema)[source]

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

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

Render the values into a jinja template.

Parameters:
  • sim_type (str) – application name
  • v – flattened model data
Returns:

source text

Return type:

str

sirepo.template.template_common.report_fields(data, report_name, style_fields)[source]
sirepo.template.template_common.report_parameters_hash(data)[source]

Compute a hash of the parameters for his report.

Only needs to be unique relative to the report, not globally unique so MD5 is adequate. Long and cryptographic hashes make the cache checks slower.

Parameters:data (dict) – report and related models
Returns:url safe encoded hash
Return type:str
sirepo.template.template_common.resource_dir(sim_type)[source]

Where to get library files from

Parameters:sim_type (str) – application name
Returns:absolute path to folder
Return type:py.path.Local
sirepo.template.template_common.update_model_defaults(model, name, schema)[source]
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.validate_safe_zip(zip_file_name, target_dir='.', *args)[source]

Determine whether a zip file is safe to extract from

Performs the following checks:

  • Each file must end up at or below the target directory
  • Files must be 100MB or smaller
  • If possible to determine, disallow “non-regular” and executable files
  • Existing files cannot be overwritten
Parameters:
  • zip_file_name (str) – name of the zip file to examine
  • target_dir (str) – name of the directory to extract into (default to current directory)
  • *args – list of validator functions taking a zip file as argument and returning True or False and a string
Throws:
AssertionError if any test fails, otherwise completes silently
sirepo.template.template_common.watchpoint_id(report)[source]
sirepo.template.template_common.zip_path_for_file(zf, file_to_find)[source]

Find the full path of the specified file within the zip.

For a zip zf containing:
foo1 foo2 bar/ bar/foo3

zip_path_for_file(zf, ‘foo3’) will return ‘bar/foo3’

Parameters:
  • zf (zipfile.ZipFile) – the zip file to examine
  • file_to_find (str) – name of the file to find
Returns:

The first path in the zip that matches the file name, or None if no match is found

sirepo.template.warppba module

sirepo.template.warpvnd module

sirepo.template.zgoubi module

zgoubi execution template.

copyright:Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.template.zgoubi.background_percent_complete(report, run_dir, is_running)[source]
sirepo.template.zgoubi.column_data(col, col_names, rows)[source]
sirepo.template.zgoubi.extract_first_twiss_row(run_dir)[source]
sirepo.template.zgoubi.fixup_old_data(data)[source]
sirepo.template.zgoubi.get_animation_name(data)[source]
sirepo.template.zgoubi.get_application_data(data)[source]
sirepo.template.zgoubi.get_simulation_frame(run_dir, data, model_data)[source]
sirepo.template.zgoubi.lib_files(data, source_lib)[source]
sirepo.template.zgoubi.parse_error_log(run_dir)[source]
sirepo.template.zgoubi.prepare_output_file(report_info, data)[source]
sirepo.template.zgoubi.python_source_for_model(data, model)[source]
sirepo.template.zgoubi.read_data_file(path)[source]
sirepo.template.zgoubi.remove_last_frame(run_dir)[source]
sirepo.template.zgoubi.save_report_data(data, run_dir)[source]
sirepo.template.zgoubi.simulation_dir_name(report_name)[source]
sirepo.template.zgoubi.write_parameters(data, run_dir, is_parallel, python_file='parameters.py')[source]

sirepo.template.zgoubi_importer module

zgoubi datafile parser

copyright:Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.template.zgoubi_importer.import_file(text)[source]

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]

Module contents

Templates are used to configure codes

copyright:Copyright (c) 2016 RadiaSoft LLC. All Rights Reserved.
license:http://www.apache.org/licenses/LICENSE-2.0.html
sirepo.template.assert_sim_type(sim_type)[source]

Validate simulation type

Parameters:sim_type (str) – to check
Returns:sim_type
Return type:str
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