Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #5942 match silas notebook #5964

Merged
merged 75 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
cdff73c
create schema conversion script
garsuga Mar 1, 2023
0fd5fd5
remove old file
garsuga Mar 1, 2023
c50384b
create beamline and layout helper
garsuga Mar 2, 2023
ee4bcd9
add shadow schema
garsuga Mar 2, 2023
417c2f8
prepare interpolation for custom types
garsuga Mar 7, 2023
760a391
use better pattern for interpolation
garsuga Mar 7, 2023
86d3033
allow custom validators on generic inputs
garsuga Mar 7, 2023
cffb38c
add array type and beamline type, add custom input types
garsuga Mar 7, 2023
5e41b2a
fix schema and model resolution errors
garsuga Mar 8, 2023
e5243b5
wip
garsuga Mar 17, 2023
6664bd9
wip basic beamline functionality
garsuga Mar 17, 2023
4f21beb
wip add edit functionality to beamline
garsuga Mar 21, 2023
7a3adcf
wip add watchpoint reports
garsuga Mar 22, 2023
173f25c
fmt
garsuga Mar 22, 2023
5262bc7
simplify and fix waterfall layout
Mar 23, 2023
c6507c3
fix layout render order and cleanup
Mar 23, 2023
2d671ed
remove console logs and fix wiggler beamline
Mar 23, 2023
60c311b
test commit
garsuga Mar 23, 2023
c1788f2
wip refactor data to be more flexible
garsuga Mar 30, 2023
aa97143
wip refactor data
garsuga Mar 31, 2023
38e2c1d
wip refactor data
garsuga Mar 31, 2023
e61db8c
wip continue data refactor
garsuga Apr 5, 2023
374d6ed
wip update react data management
garsuga Apr 10, 2023
1a5f711
wip debug data changes
garsuga Apr 10, 2023
1b721ca
undo accidental delete
garsuga Apr 10, 2023
a036b7f
wip complete new data work and continue working on shadow beamline co…
garsuga Apr 13, 2023
6fef812
complete shadow basic functionality
garsuga Apr 20, 2023
53f649e
add middleware to schema
garsuga Apr 21, 2023
4a6f0bd
Merge branch 'master' into 5464-shadow-rev-branch
garsuga Apr 21, 2023
478bcb6
fixup waterfall
garsuga Apr 21, 2023
0665f88
remove console logs
garsuga Apr 21, 2023
1e25abd
fix schema conversion script and begin to convert schema for madx
garsuga Apr 21, 2023
eca0cd6
organize madx schema
garsuga Apr 24, 2023
0bed6e5
namespace shadow beamline elements
garsuga Apr 24, 2023
5fd66a4
wip implement missing types
garsuga Apr 25, 2023
17d39fa
add missing types and convert schema models to new arrays
garsuga Apr 26, 2023
47bd8fa
change server handling of array types
garsuga Apr 26, 2023
8191b3b
reorganize schema
garsuga Apr 26, 2023
386186a
add autosave middleware, being lattice
garsuga May 1, 2023
0533905
finish autosave middleware
garsuga May 2, 2023
792aae5
wip fix save function
garsuga May 2, 2023
2c92f0e
wip create beamline elements component
garsuga May 3, 2023
ba9c36f
finish beamline elements component and add beamliens picker component
garsuga May 4, 2023
3c6ff83
wip create beamline editor
garsuga May 5, 2023
442ceb4
wip
garsuga May 11, 2023
8955d08
complete manual reports
garsuga May 17, 2023
dc7e15d
remove log
garsuga May 18, 2023
c040827
fix error on edit
garsuga May 18, 2023
f891dfd
fix route formatting
garsuga May 18, 2023
3ff2fa6
add beamline elements editor functions and fix simulation info handling
garsuga May 18, 2023
07e57f6
fix child form saving for beamline editor
garsuga May 18, 2023
20bf246
add missing functions and styling
garsuga May 22, 2023
1092209
fix row styling
garsuga May 23, 2023
543da72
Merge remote-tracking branch 'origin/master' into 5333-madx-react
garsuga May 23, 2023
27d45a1
fix shadow beamline scrollbar
garsuga May 24, 2023
b81a46b
move react assets to new folder
garsuga May 26, 2023
1770a4a
fix use index for deleting beamline elements, remove description
garsuga May 29, 2023
94b2513
add element descriptions
garsuga May 30, 2023
eac91bb
for #5914 reverse shadow server changes
moellep May 30, 2023
2840008
for #5914 react/shadow data format/unformat
moellep May 30, 2023
1b0c66f
for #5914 madx to/from react format
moellep May 31, 2023
da5336c
for #5914 revert madx server
moellep May 31, 2023
0921f71
for #5914 update shadow tests
moellep May 31, 2023
4570d30
for #5914 unformat in api save, with TODO
moellep May 31, 2023
315bb24
pass nextRequest info to runStatus, models is optional
moellep Jun 1, 2023
385b14b
for #5914 move react un/format to http_request
moellep Jun 1, 2023
2b9247a
for #5914 fix shadow report dependencies
moellep Jun 1, 2023
0ad14ec
fix #5942 match silas sim to notebook results
moellep Jun 13, 2023
fc3c5a6
merged with master
moellep Jun 13, 2023
b968610
Merge branch 'master' into 5942-match-silas-notebook
moellep Jun 13, 2023
36a73fd
undo formatting change
moellep Jun 13, 2023
c25a5d6
merge with master
moellep Jun 16, 2023
4d921f8
added _MAX_H5_READ_TRIES constant and fixed missing crystal plots
moellep Jun 16, 2023
dfc6d48
Merge branch 'master' into 5942-match-silas-notebook
moellep Jun 16, 2023
a2eeb68
Merge branch 'master' into 5942-match-silas-notebook
moellep Jun 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sirepo/package_data/static/html/silas-source.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
</div>
</div>
</div>
<!-- required to have the intensityViewHandler update the SINGLE_FRAME_ANIMATION list -->
<div data-modal-editor="" data-view-name="laserPulseAnimation" data-sr-laserpulseanimation-editor=""></div>
<div data-modal-editor="" data-view-name="laserPulse2Animation" data-sr-laserpulse2animation-editor=""></div>
11 changes: 3 additions & 8 deletions sirepo/package_data/static/js/sirepo-plotting.js
Original file line number Diff line number Diff line change
Expand Up @@ -1822,19 +1822,14 @@ SIREPO.app.service('layoutService', function(panelState, plotting, utilities) {
const v0 = applyUnit(tickValues[0], base, unit);
const v1 = applyUnit(tickValues[1], base, unit);
const vn = applyUnit(tickValues[tickValues.length - 1], base, unit);
let decimals;
if (Math.abs(v0) > Math.abs(vn)) {
decimals = d3_precisionRound(v1 - v0, Math.abs(v0));
}
else {
decimals = d3_precisionRound(v1 - v0, vn);
}
const max = Math.abs(v0) > Math.abs(vn) ? Math.abs(v0) : vn;
let decimals = d3_precisionRound(v1 - v0, max);
if (decimals > 1) {
decimals -= 1;
}
if (useFloatFormat(v0) && useFloatFormat(vn)) {
code = 'f';
decimals -= valuePrecision(vn);
decimals -= valuePrecision(max);
if (decimals < 0) {
decimals = 0;
}
Expand Down
20 changes: 14 additions & 6 deletions sirepo/package_data/static/json/silas-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@
"pump_gaussian_order": ["Pump Gaussian Order", "Float", 2.0],
"pump_type": ["Pump Type", "PumpType", "dual"],
"origin": ["Crystal", "CrystalOrigin", "new"],
"reuseCrystal": ["Select Crystal", "SelectCrystal", 0]
"reuseCrystal": ["Select Crystal", "SelectCrystal", 0],
"pump_offset_x": ["Pump Offset X [m]", "Float", 0],
"pump_offset_y": ["Pump Offset X [m]", "Float", 0],
"pump_rep_rate": ["Pump Rep Rate", "Float", 1.0]
},
"crystalAnimation": {},
"crystalSettings": {
Expand Down Expand Up @@ -160,7 +163,8 @@
"pulseE": ["Total Laser Pulse Energy [J]", "Float", 0.001],
"distribution": ["Distribution Type", "DistributionType", "gaussian"],
"sigx_waist": ["Horizontal RMS Waist Size [m]", "Float", 0.001],
"sigy_waist": ["Vertical RMS Waist Size [m]", "Float", 0.001]
"sigy_waist": ["Vertical RMS Waist Size [m]", "Float", 0.001],
"phase_flatten_cutoff": ["Phase Flatten Cutoff", "Float", 0.85]
},
"laserPulseAnimation": {
"_super": ["_", "model", "initialIntensityReport"]
Expand All @@ -171,7 +175,7 @@
},
"initialIntensityReport": {
"colorMap": ["Color Map", "ColorMap", "viridis"],
"watchpointPlot": ["Value to Plot", "WatchpointPlot", "intensity"]
"watchpointPlot": ["Value to Plot", "WatchpointPlot", "total_intensity"]
},
"lens": {
"_super": ["_", "model", "beamElement"],
Expand Down Expand Up @@ -218,18 +222,21 @@
"C",
"D",
"l_scale",
"pump_type",
"radial_n2",
"calc_gain"
]],
["Pump Pulse", [
"pump_type",
"inversion_n_cells",
"inversion_mesh_extent",
"crystal_alpha",
"pump_waist",
"pump_wavelength",
"pump_energy",
"pump_gaussian_order"
"pump_gaussian_order",
"pump_rep_rate",
"pump_offset_x",
"pump_offset_y"
]]
]
},
Expand Down Expand Up @@ -281,7 +288,8 @@
"basic": [
["Energy", [
"photon_e_ev",
"pulseE"
"pulseE",
"phase_flatten_cutoff"
]],
["Transverse", [
"num_sig_trans",
Expand Down
1 change: 1 addition & 0 deletions sirepo/package_data/template/silas/parameters.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pulse = LaserPulse(
'sigx_waist',
'sigy_waist',
'tau_fwhm',
'phase_flatten_cutoff',
'tau_0',
) %}
{{ f }}={{ laserPulse[f] }},
Expand Down
115 changes: 61 additions & 54 deletions sirepo/template/silas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
import numpy
import re
import sirepo.sim_data

# TODO(pjm): currently aligned with rslaser version
# git checkout `git rev-list -n 1 --first-parent --before="2023-04-24 13:37" main`
import time

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

_CRYSTAL_CSV_FILE = "crystal.csv"
_RESULTS_FILE = "results{}.h5"
_CRYSTAL_FILE = "crystal{}.h5"
_MAX_H5_READ_TRIES = 3


def background_percent_complete(report, run_dir, is_running):
Expand Down Expand Up @@ -134,8 +133,7 @@ def write_parameters(data, run_dir, is_parallel):


def _beamline_animation_percent_complete(run_dir, res, data):
def _output_append(frame_count, filename, count, element, res, total_count):
total_count += 1
def _output_append(frame_count, filename, count, element, res):
if run_dir.join(filename).exists():
res.outputInfo.append(
PKDict(
Expand Down Expand Up @@ -170,15 +168,14 @@ def _frames(element, data):
total_count = 1
for e in data.models.beamline:
if e.type in ("watch", "crystal"):
total_count += 1
_output_append(
_frames(e, data),
_file(e, count),
count,
e,
res,
total_count,
)

res.percentComplete = res.frameCount * 100 / total_count
return res

Expand Down Expand Up @@ -308,6 +305,9 @@ def _generate_crystal(crystal):
pop_inversion_pump_gaussian_order={crystal.pump_gaussian_order},
pop_inversion_pump_energy={crystal.pump_energy},
pop_inversion_pump_type="{crystal.pump_type}",
pop_inversion_pump_rep_rate={crystal.pump_rep_rate},
pop_inversion_pump_offset_x={crystal.pump_offset_x},
pop_inversion_pump_offset_y={crystal.pump_offset_y},
),
),
["{crystal.propagationType}", {crystal.calc_gain == "1"}, {crystal.radial_n2 == "1"}],
Expand Down Expand Up @@ -382,6 +382,11 @@ def _fname(element):
return _CRYSTAL_FILE
return _RESULTS_FILE

def _index(index, plot_type):
if plot_type == "longitudinal_photons":
return index
return index + 1

def _is_crystal(element):
return element and element.type == "crystal"

Expand All @@ -407,6 +412,13 @@ def _title(plot_type, slice_index):
return plot_type.replace("_", " ").title()
return plot_type.replace("_", " ").title() + " Slice #" + str(slice_index + 1)

def _x_label(plot_type):
return PKDict(
excited_states_longitudinal="Crystal Slice",
longitudinal_photons="Crystal width [cm]",
longitudinal_intensity="Pulse Slice",
)[plot_type]

def _y_value(element, index, file, cell_volume):
if _is_crystal(element):
return numpy.sum(numpy.array(file[f"{index}/excited_states"]) * cell_volume)
Expand All @@ -425,53 +437,48 @@ def _z_label(plot_type):
excited_states="Number [1/m³]",
)[plot_type]

def _x_label(plot_type):
return PKDict(
excited_states_longitudinal="Crystal Slice",
longitudinal_photons="Crystal width [cm]",
longitudinal_intensity="Pulse Slice",
)[plot_type]

def _index(index, plot_type):
if plot_type == "longitudinal_photons":
return index
return index + 1

with h5py.File(run_dir.join(_fname(element).format(element_index)), "r") as f:
if _is_longitudinal_plot(plot_type):
x = []
y = []
nslice = _nslice(element, f)
if element:
element.nslice = nslice
for idx in range(nslice):
x.append(_index(idx, plot_type))
y.append(_y_value(element, idx, f, _cell_volume(element)))
return template_common.parameter_plot(
x,
[
PKDict(
points=y,
label=_label(plot_type, slice_index),
),
],
PKDict(),
PKDict(
x_label=_x_label(plot_type),
),
)
d = template_common.h5_to_dict(f, str(slice_index))
r = d.ranges
z = d[plot_type]
return PKDict(
title=_title(plot_type, slice_index),
x_range=[r.x[0], r.x[1], len(z)],
y_range=[r.y[0], r.y[1], len(z[0])],
x_label="Horizontal Position [m]",
y_label="Vertical Position [m]",
z_label=_z_label(plot_type),
z_matrix=z,
)
for _ in range(_MAX_H5_READ_TRIES):
try:
with h5py.File(
run_dir.join(_fname(element).format(element_index)), "r"
) as f:
if _is_longitudinal_plot(plot_type):
x = []
y = []
nslice = _nslice(element, f)
if element:
element.nslice = nslice
for idx in range(nslice):
x.append(_index(idx, plot_type))
y.append(_y_value(element, idx, f, _cell_volume(element)))
return template_common.parameter_plot(
x,
[
PKDict(
points=y,
label=_label(plot_type, 0),
),
],
PKDict(),
PKDict(
x_label=_x_label(plot_type),
),
)
d = template_common.h5_to_dict(f, str(slice_index))
r = d.ranges
z = d[plot_type]
return PKDict(
title=_title(plot_type, slice_index),
x_range=[r.x[0], r.x[1], len(z)],
y_range=[r.y[0], r.y[1], len(z[0])],
x_label="Horizontal Position [m]",
y_label="Vertical Position [m]",
z_label=_z_label(plot_type),
z_matrix=z,
)
except BlockingIOError as e:
time.sleep(3)
raise AssertionError("Report is unavailable")


def _laser_pulse_report(value_index, filename, title, label):
Expand Down
9 changes: 8 additions & 1 deletion tests/karma/plotAxis_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ describe('plotting: plotAxis', function() {
tickValues('', [-0.0002, -0.0018], {width: 315, height: 200}, 'y', 'left'),
['-1.5e-3', '-1.0e-3', '-5.0e-4'],
);

assertTicks(
tickValues('', [-0.02, 0], {width: 350, height: 180}, 'y', 'left'),
['-0.02', '-0.01', '0'],
);
assertTicks(
tickValues('', [0, 0.02], {width: 350, height: 180}, 'y', 'left'),
['0', '0.01', '0.02'],
);
}));
it('should format units', inject(function(layoutService) {
expect(layoutService.formatUnits('m')).toEqual('[m]');
Expand Down