From 408aa446558e2a6e09b8fc94e0c935f0c2c21c51 Mon Sep 17 00:00:00 2001 From: Paul Moeller Date: Thu, 19 Sep 2024 21:52:42 +0000 Subject: [PATCH] fix #7152 added "canvas" app for lattice code comparison --- sirepo/package_data/static/js/impactt.js | 14 +++++++------- .../template/impactx/parameters.py.jinja | 3 +-- sirepo/pkcli/canvas.py | 19 ++++++++++--------- sirepo/template/canvas.py | 5 +++-- sirepo/template/impactx.py | 3 ++- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/sirepo/package_data/static/js/impactt.js b/sirepo/package_data/static/js/impactt.js index 3989a4cd20..fd5d1eca23 100644 --- a/sirepo/package_data/static/js/impactt.js +++ b/sirepo/package_data/static/js/impactt.js @@ -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 = ''; @@ -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', @@ -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); @@ -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; @@ -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: { diff --git a/sirepo/package_data/template/impactx/parameters.py.jinja b/sirepo/package_data/template/impactx/parameters.py.jinja index 45859f0e68..2f169b074e 100644 --- a/sirepo/package_data/template/impactx/parameters.py.jinja +++ b/sirepo/package_data/template/impactx/parameters.py.jinja @@ -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() diff --git a/sirepo/pkcli/canvas.py b/sirepo/pkcli/canvas.py index 1b73ffd2d4..4d110539d2 100644 --- a/sirepo/pkcli/canvas.py +++ b/sirepo/pkcli/canvas.py @@ -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"], @@ -89,7 +92,7 @@ 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(), @@ -97,7 +100,7 @@ def _run_all(): with pkio.save_chdir("impactx"): pksubprocess.check_call_with_signals( - ["python", "run.py"], + ["python", _IMPACTX_RUN_FILE], msg=pkdlog, output="impactx.log", ) @@ -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") @@ -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") @@ -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") diff --git a/sirepo/template/canvas.py b/sirepo/template/canvas.py index eb47d656e2..356cd249fc 100644 --- a/sirepo/template/canvas.py +++ b/sirepo/template/canvas.py @@ -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 diff --git a/sirepo/template/impactx.py b/sirepo/template/impactx.py index 2d3c5a7203..2ae9a1058d 100644 --- a/sirepo/template/impactx.py +++ b/sirepo/template/impactx.py @@ -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" @@ -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) @@ -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