Skip to content

Commit

Permalink
fix #7152 added "canvas" app for lattice code comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
moellep committed Sep 19, 2024
1 parent e2f94e9 commit 408aa44
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
14 changes: 7 additions & 7 deletions sirepo/package_data/static/js/impactt.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ SIREPO.app.factory('impacttService', function(appState) {


SIREPO.app.controller('SourceController', function(appState, $scope) {
const self = this;
var self = this;
});

SIREPO.app.controller('VisualizationController', function (appState, frameCache, panelState, persistentSimulation, $scope) {
SIREPO.app.controller('VisualizationController', function (appState, frameCache, impacttService, panelState, persistentSimulation, $scope) {
const self = this;
self.simScope = $scope;
self.errorMessage = '';
Expand All @@ -49,7 +49,7 @@ SIREPO.app.controller('VisualizationController', function (appState, frameCache,
function loadReports(reports) {
self.outputFiles = [];
reports.forEach((info) => {
const outputFile = {
var outputFile = {
info: info,
reportType: 'heatmap',
viewName: 'elementAnimation',
Expand All @@ -67,7 +67,7 @@ SIREPO.app.controller('VisualizationController', function (appState, frameCache,
if (! appState.models[info.modelKey]) {
appState.models[info.modelKey] = {};
}
const m = appState.models[info.modelKey];
var m = appState.models[info.modelKey];
appState.setModelDefaults(m, 'elementAnimation');
appState.saveQuietly(info.modelKey);
frameCache.setFrameCount(1, info.modelKey);
Expand All @@ -91,8 +91,8 @@ SIREPO.app.controller('VisualizationController', function (appState, frameCache,
};
});

SIREPO.app.controller('LatticeController', function(latticeService) {
const self = this;
SIREPO.app.controller('LatticeController', function(latticeService, appState) {
var self = this;
self.latticeService = latticeService;

self.advancedNames = SIREPO.APP_SCHEMA.constants.advancedElementNames;
Expand All @@ -104,7 +104,7 @@ SIREPO.app.controller('LatticeController', function(latticeService) {

});

SIREPO.app.directive('appFooter', function(impacttService) {
SIREPO.app.directive('appFooter', function() {
return {
restrict: 'A',
scope: {
Expand Down
3 changes: 1 addition & 2 deletions sirepo/package_data/template/impactx/parameters.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ sim.lattice.extend(beamline_elements("{{ selectedBeamline }}"))

sim.evolve()

#TODO(pjm): file name
sim.particle_container().to_df(local=True).to_hdf('diags/final_distribution.h5', 'final')
sim.particle_container().to_df(local=True).to_hdf("{{ finalDistributionOutputFile }}", "final")

sim.finalize()
19 changes: 10 additions & 9 deletions sirepo/pkcli/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import sirepo.template.sdds_util

_SCHEMA = sirepo.sim_data.get_class("canvas").schema()
_ELEGANT_INPUT_FILE = "elegant.ele"
_IMPACTX_RUN_FILE = "run.py"
_MADX = sirepo.sim_data.get_class("madx")
_MADX_INPUT_FILE = "in.madx"
_MODEL_FIELD_MAP = PKDict(
DRIFT=PKDict(
_fields=["name", "type", "l", "_id"],
Expand Down Expand Up @@ -89,15 +92,15 @@ def _run_all():

with pkio.save_chdir("elegant"):
pksubprocess.check_call_with_signals(
["elegant", "elegant.ele"],
["elegant", _ELEGANT_INPUT_FILE],
msg=pkdlog,
output=sirepo.pkcli.elegant.ELEGANT_LOG_FILE,
env=sirepo.template.elegant_common.subprocess_env(),
)

with pkio.save_chdir("impactx"):
pksubprocess.check_call_with_signals(
["python", "run.py"],
["python", _IMPACTX_RUN_FILE],
msg=pkdlog,
output="impactx.log",
)
Expand Down Expand Up @@ -138,8 +141,8 @@ def madx_to_elegant(madx_in, source_file):
return d

s = sirepo.lib.SimData(
madx_to_elegant("madx/in.madx", input_file),
pkio.py_path("elegant.ele"),
madx_to_elegant(f"madx/{_MADX_INPUT_FILE}", input_file),
pkio.py_path(_ELEGANT_INPUT_FILE),
sirepo.template.import_module("elegant").LibAdapter(),
)
pkio.unchecked_remove("elegant")
Expand Down Expand Up @@ -171,10 +174,8 @@ def update_beam(data, input_file):

i = sirepo.template.import_module("impactx").LibAdapter()
s = sirepo.lib.SimData(
# TODO(pjm): file name
update_beam(i.parse_file("madx/in.madx"), input_file),
# TODO(pjm): file name
pkio.py_path("run.py"),
update_beam(i.parse_file(f"madx/{_MADX_INPUT_FILE}"), input_file),
pkio.py_path(_IMPACTX_RUN_FILE),
i,
)
pkio.unchecked_remove("impactx")
Expand All @@ -190,7 +191,7 @@ def _write_madx(data, input_file):
)
s = sirepo.lib.SimData(
_to_madx(data, input_file),
pkio.py_path("in.madx"),
pkio.py_path(_MADX_INPUT_FILE),
sirepo.template.import_module("madx").LibAdapter(),
)
pkio.unchecked_remove("madx")
Expand Down
5 changes: 3 additions & 2 deletions sirepo/template/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ def background_percent_complete(report, run_dir, is_running):
if is_running:
return res
# TODO(pjm): check enable code output files
# TODO(pjm): file name hard coded
if run_dir.join("impactx/diags/final_distribution.h5").exists():
if run_dir.join(
f"impactx/{ sirepo.template.impactx.FINAL_DISTRIBUTION_OUTPUT_FILE }"
).exists():
res.frameCount = 1
return res

Expand Down
3 changes: 2 additions & 1 deletion sirepo/template/impactx.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import sirepo.template.sdds_util


FINAL_DISTRIBUTION_OUTPUT_FILE = "diags/final_distribution.h5"
# _DEFAULT_NSLICE = 12
_DEFAULT_NSLICE = 1
_MONITOR_NAME = "monitor"
Expand Down Expand Up @@ -124,7 +125,6 @@ def _fixup_element(self, element_in, element_out):
element_out.rc = self.__val(element_out.l) / self.__val(
element_in.angle
)
# self.bends[element_out._id] = self.__val(element_in.angle)
elif element_in.type == "DIPEDGE":
element_out.rc = 1.0 / self.__val(element_in.h)
element_out.g = 2 * self.__val(element_in.hgap)
Expand Down Expand Up @@ -366,3 +366,4 @@ def _generate_particles(data, res, v):
v.speciesMassMeV = round(mc[0] * 1e3, 9)
v.speciesCharge = mc[1]
v.createParticles = template_common.render_jinja(SIM_TYPE, v, "particles.py")
v.finalDistributionOutputFile = FINAL_DISTRIBUTION_OUTPUT_FILE

0 comments on commit 408aa44

Please sign in to comment.