Skip to content

Commit

Permalink
fix #7253 show code versions in checkbox labels (#7276)
Browse files Browse the repository at this point in the history
* use newly available impactx beta_x and beta_y for plots
  • Loading branch information
moellep authored Sep 27, 2024
1 parent 8d2a719 commit 1077ac8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
34 changes: 32 additions & 2 deletions sirepo/package_data/static/js/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,38 @@ SIREPO.app.config(() => {
};
});

SIREPO.app.factory('canvasService', function(appState) {
SIREPO.app.factory('canvasService', function(appState, requestSender) {
const self = {};
let codeLabels = null;
appState.setAppService(self);
self.computeModel = analysisModel => 'animation';

const updateCodeLabels = () => {
const m = SIREPO.APP_SCHEMA.model.simulationSettings;
for (const c of SIREPO.APP_SCHEMA.constants.codes) {
// update the schema simulationSettings labels
m[c][0] = codeLabels[c];
}
};

self.updateCodeVersions = (scope) => {
if (codeLabels) {
updateCodeLabels();
return;
}
requestSender.sendStatelessCompute(
appState,
function(data) {
if (data.elegant) {
codeLabels = data;
updateCodeLabels();
}
},
{
method: 'code_versions',
},
);
};
return self;
});

Expand Down Expand Up @@ -99,7 +127,7 @@ SIREPO.app.controller('SourceController', function(latticeService) {
latticeService.initSourceController(self);
});

SIREPO.app.controller('ComparisonController', function(frameCache, persistentSimulation, $scope) {
SIREPO.app.controller('ComparisonController', function(canvasService, frameCache, persistentSimulation, $scope) {
var self = this;
self.simScope = $scope;
self.errorMessage = '';
Expand All @@ -111,4 +139,6 @@ SIREPO.app.controller('ComparisonController', function(frameCache, persistentSim

self.simState = persistentSimulation.initSimulationState(self);
self.simState.errorMessage = () => self.errorMessage;

canvasService.updateCodeVersions($scope);
});
13 changes: 7 additions & 6 deletions sirepo/package_data/static/json/canvas-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}
},
"constants": {
"codes": ["elegant", "madx", "impactx"],
"particleMassAndCharge": {
"positron": [0.510998950e-03, 1],
"electron": [0.510998950e-03, -1],
Expand Down Expand Up @@ -164,9 +165,9 @@
"notes": ["Notes", "Text", ""]
},
"simulationSettings": {
"useElegant": ["elegant", "Boolean", "1"],
"useMadx": ["MAD-X", "Boolean", "1"],
"useImpactX": ["ImpactX", "Boolean", "1"]
"elegant": ["elegant {{ elegantVersion }}", "Boolean", "1"],
"madx": ["MAD-X {{ madxVersion }}", "Boolean", "1"],
"impactx": ["ImpactX {{ impactxVersion }}", "Boolean", "1"]
},
"twissAnimation": {
"includeLattice": ["Show Lattice Overlay", "Boolean", "1"],
Expand Down Expand Up @@ -334,9 +335,9 @@
"basic": [
"simulation.visualizationBeamlineId",
"*Compare Codes",
"useElegant",
"useMadx",
"useImpactX"
"elegant",
"madx",
"impactx"
],
"advanced": []
},
Expand Down
34 changes: 26 additions & 8 deletions sirepo/template/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""

from pykern import pkio
from pykern.pkcollections import PKDict
from pykern.pkdebug import pkdp, pkdc, pkdlog
from sirepo.template import code_variable
from sirepo.template import madx_parser
from sirepo.template import sdds_util
from sirepo.template import template_common
from sirepo.template.madx_converter import MadxConverter
import impactx
import math
import pandas
import pykern.pkio
import pykern.pksubprocess
import re
import sirepo.sim_data
import sirepo.template.impactx
import sirepo.template.madx
import sirepo.template.sdds_util
import tempfile

_SIM_DATA, SIM_TYPE, SCHEMA = sirepo.sim_data.template_globals()

Expand Down Expand Up @@ -264,6 +268,24 @@ def sim_frame_sigmaAnimation(frame_args):
)


def stateless_compute_code_versions(data, **kwargs):
def _run_code(name, regexp):
t = tempfile.NamedTemporaryFile()
pykern.pksubprocess.check_call_with_signals([name], output=t.name)
m = re.match(regexp, pykern.pkio.read_text(t.name), re.MULTILINE | re.DOTALL)
if not m:
raise AssertionError(f"Unable to parse version for code: {name}")
return m.group(1)

return PKDict(
elegant="elegant ("
+ _run_code("elegant", r".*?This is elegant ([\d\.]{4,}),")
+ ")",
madx="MAD-X (" + _run_code("madx", r".*?MAD-X\s([\d\.]{4,})\s") + ")",
impactx=f"ImpactX ({ impactx.__version__ })",
)


def stateful_compute_import_file(data, **kwargs):
res = CanvasMadxConverter().from_madx_text(data.args.file_as_str)
res.models.simulation.name = data.args.purebasename
Expand Down Expand Up @@ -308,12 +330,8 @@ def sim_frame_twissAnimation(frame_args):
)
impactx = PKDict(
s=list(impactx_sigma["s"].values),
bx=list(
impactx_sigma["sig_x"].values ** 2 / impactx_sigma["emittance_x"].values
),
by=list(
impactx_sigma["sig_y"].values ** 2 / impactx_sigma["emittance_y"].values
),
bx=list(impactx_sigma["beta_x"].values),
by=list(impactx_sigma["beta_y"].values),
)
madx_twiss = madx_parser.parse_tfs_file("madx/twiss.file.tfs")
madx = PKDict(
Expand Down Expand Up @@ -377,7 +395,7 @@ def sim_frame_twissAnimation(frame_args):


def write_parameters(data, run_dir, is_parallel):
pkio.write_text(
pykern.pkio.write_text(
run_dir.join(template_common.PARAMETERS_PYTHON_FILE),
_generate_parameters_file(data),
)
Expand Down

0 comments on commit 1077ac8

Please sign in to comment.