From a1a73db68a421816cc67f8e45b89730480902094 Mon Sep 17 00:00:00 2001 From: Riley Bode Date: Wed, 12 Jul 2023 14:30:54 -0400 Subject: [PATCH 1/2] Added empty beamline built-in simulation --- .../testuser/srw/emptysim/sirepo-data.json | 463 ++++++++++++++++++ 1 file changed, 463 insertions(+) create mode 100644 sirepo_bluesky/tests/SIREPO_SRDB_ROOT/user/testuser/srw/emptysim/sirepo-data.json diff --git a/sirepo_bluesky/tests/SIREPO_SRDB_ROOT/user/testuser/srw/emptysim/sirepo-data.json b/sirepo_bluesky/tests/SIREPO_SRDB_ROOT/user/testuser/srw/emptysim/sirepo-data.json new file mode 100644 index 00000000..93d1fbf8 --- /dev/null +++ b/sirepo_bluesky/tests/SIREPO_SRDB_ROOT/user/testuser/srw/emptysim/sirepo-data.json @@ -0,0 +1,463 @@ +{ + "models": { + "arbitraryMagField": { + "interpolationOrder": 1, + "longitudinalPosition": 0, + "magneticFile": "ivu21_srx_g6_2c.dat" + }, + "beamline": [], + "beamline3DReport": { + "condenseBeamline": "1", + "includeSource": "1", + "projection": "parallel", + "showLabels": "1", + "showPosition": "1" + }, + "beamlineAnimation0": { + "_super": "_INTENSITY_REPORT", + "aspectRatio": "1", + "characteristic": 0, + "colorMap": "grayscale", + "copyCharacteristic": "0", + "horizontalOffset": 0, + "horizontalSize": 0.4, + "intensityPlotsWidth": "0", + "maxIntensityLimit": 14618198217326592, + "minIntensityLimit": 1085991288832, + "notes": "", + "plotScale": "linear", + "polarization": 6, + "precision": 0.01, + "rotateAngle": 0, + "rotateReshape": "1", + "useIntensityLimits": "0", + "usePlotRange": "0", + "verticalOffset": 0, + "verticalSize": 0.6 + }, + "brillianceReport": { + "brightnessComponent": "k-tuning", + "detuning": 0, + "energyDelta": 10, + "energyPointCount": 100, + "finalHarmonic": 5, + "harmonic": "5", + "initialHarmonic": 1, + "minDeflection": 0.2, + "notes": "", + "plotScale": "linear", + "reportType": "0" + }, + "coherenceXAnimation": { + "aspectRatio": "1", + "colorMap": "grayscale", + "intensityPlotsWidth": "0", + "plotScale": "linear" + }, + "coherenceYAnimation": { + "aspectRatio": "1", + "colorMap": "grayscale", + "intensityPlotsWidth": "0", + "plotScale": "linear" + }, + "coherentModesAnimation": { + "_super": "_INTENSITY_REPORT", + "aspectRatio": "1", + "characteristic": "0", + "colorMap": "grayscale", + "distanceFromSource": 20, + "finalPosition": 0, + "horizontalOffset": 0, + "horizontalPointCount": 100, + "horizontalPosition": 0, + "horizontalRange": "0.4", + "horizontalSize": 1, + "initialPosition": 0, + "intensityPlotsWidth": "0", + "jobRunMode": "parallel", + "maxIntensityLimit": 1e+30, + "method": "1", + "minIntensityLimit": 0, + "mpiGroupCount": 2, + "notes": "", + "numberOfCoherentModes": 100, + "numberOfMacroElectrons": 1000, + "photonEnergy": "9000", + "plotModesEnd": 100, + "plotModesStart": 1, + "plotScale": "linear", + "polarization": "6", + "precision": 0.01, + "rotateAngle": 0, + "rotateReshape": "1", + "sampleFactor": 1, + "samplingMethod": 2, + "sbatchCores": 128, + "sbatchHours": 0.4, + "sbatchProject": "", + "sbatchQueue": "debug", + "tasksPerNode": 128, + "useIntensityLimits": "0", + "usePlotRange": "0", + "verticalOffset": 0, + "verticalPointCount": 100, + "verticalPosition": 0, + "verticalRange": "0.6", + "verticalSize": 1 + }, + "electronBeam": { + "beamDefinition": "t", + "beamSelector": "NSLS-II Low Beta Final", + "current": 0.5, + "energy": 3, + "energyDeviation": 0, + "horizontalAlpha": 0, + "horizontalBeta": 1.84, + "horizontalDispersion": 0, + "horizontalDispersionDerivative": 0, + "horizontalEmittance": 0.55, + "isReadOnly": true, + "name": "NSLS-II Low Beta Final", + "rmsDivergX": 17.28910187, + "rmsDivergY": 2.6148818, + "rmsSizeX": 31.81194744, + "rmsSizeY": 3.05941171, + "rmsSpread": 0.00089, + "verticalAlpha": 0, + "verticalBeta": 1.17, + "verticalDispersion": 0, + "verticalDispersionDerivative": 0, + "verticalEmittance": 0.008, + "xxprX": 0, + "xxprY": 0 + }, + "electronBeamPosition": { + "drift": -1.54, + "driftCalculationMethod": "auto", + "horizontalAngle": 0, + "horizontalPosition": 0, + "verticalAngle": 0, + "verticalPosition": 0 + }, + "exportRsOpt": { + "characteristic": "1", + "elements": [], + "maxOuputDimension": 32, + "numCores": 4, + "numSamples": 100, + "numWorkers": 1, + "randomSeed": "", + "scanType": "random", + "totalSamples": 100 + }, + "fluxAnimation": { + "azimuthalPrecision": 1, + "distanceFromSource": 20, + "finalEnergy": 20000, + "finalHarmonic": 15, + "fluxType": 1, + "horizontalApertureSize": "1", + "horizontalPosition": 0, + "initialEnergy": 10000, + "initialHarmonic": 1, + "longitudinalPrecision": 1, + "magneticField": 2, + "method": 1, + "notes": "", + "numberOfMacroElectrons": 1000, + "numberOfMacroElectronsAvg": 5, + "photonEnergyPointCount": 1000, + "plotScale": "linear", + "polarization": 6, + "precision": 0.01, + "savingPeriodicity": 5, + "verticalApertureSize": "1", + "verticalPosition": 0 + }, + "fluxReport": { + "azimuthalPrecision": 1, + "distanceFromSource": 20, + "finalEnergy": 20000, + "finalHarmonic": 15, + "fluxType": 1, + "horizontalApertureSize": "1", + "horizontalPosition": 0, + "initialEnergy": "100", + "initialHarmonic": 1, + "longitudinalPrecision": 1, + "magneticField": 1, + "method": -1, + "notes": "", + "numberOfMacroElectrons": 1, + "photonEnergyPointCount": 10000, + "plotScale": "linear", + "polarization": 6, + "precision": 0.01, + "verticalApertureSize": "1", + "verticalPosition": 0 + }, + "gaussianBeam": { + "energyPerPulse": "0.001", + "photonEnergy": "9000", + "polarization": 1, + "rmsDivergenceX": 0, + "rmsDivergenceY": 0, + "rmsPulseDuration": 0.1, + "rmsSizeX": "9.78723", + "rmsSizeY": "9.78723", + "sizeDefinition": "1", + "waistAngleX": 0, + "waistAngleY": 0, + "waistX": 0, + "waistY": 0, + "waistZ": 0 + }, + "initialIntensityReport": { + "_super": "_INTENSITY_REPORT", + "aspectRatio": "1", + "characteristic": 0, + "colorMap": "grayscale", + "copyCharacteristic": "0", + "horizontalOffset": 0, + "horizontalSize": 0.4, + "intensityPlotsWidth": "0", + "maxIntensityLimit": 14618198217326592, + "minIntensityLimit": 1085991288832, + "notes": "", + "plotScale": "linear", + "polarization": 6, + "precision": 0.01, + "rotateAngle": 0, + "rotateReshape": "1", + "useIntensityLimits": "0", + "usePlotRange": "0", + "verticalOffset": 0, + "verticalSize": 0.6 + }, + "intensityReport": { + "distanceFromSource": 20, + "fieldUnits": "1", + "finalEnergy": "20000", + "horizontalPosition": "0", + "initialEnergy": "100", + "magneticField": "1", + "method": "1", + "notes": "", + "photonEnergyPointCount": 10000, + "plotScale": "linear", + "polarization": 6, + "precision": 0.01, + "verticalPosition": 0 + }, + "machineLearningAnimation": { + "jobRunMode": "parallel", + "sbatchCores": 128, + "sbatchHours": 0.4, + "sbatchProject": "", + "sbatchQueue": "debug", + "tasksPerNode": 128 + }, + "mirrorReport": { + "intensityPlotsWidth": "0", + "notes": "", + "plotScale": "linear" + }, + "multiElectronAnimation": { + "_super": "_INTENSITY_REPORT", + "aspectRatio": "1", + "calcCoherence": "0", + "coherentModesFile": "", + "colorMap": "grayscale", + "horizontalOffset": 0, + "horizontalPosition": 0, + "horizontalRange": "0.4", + "horizontalSize": 1, + "integrationMethod": "0", + "intensityPlotsWidth": "0", + "jobRunMode": "parallel", + "maxIntensityLimit": 1e+30, + "minIntensityLimit": 0, + "notes": "", + "numberOfMacroElectrons": 1000, + "numberOfMacroElectronsAvg": 5, + "photonEnergyBandWidth": 0, + "plotScale": "linear", + "rotateAngle": 0, + "rotateReshape": "1", + "savingPeriodicity": 5, + "sbatchCores": 128, + "sbatchHours": 0.4, + "sbatchProject": "", + "sbatchQueue": "debug", + "stokesParameter": "0", + "tasksPerNode": 128, + "useIntensityLimits": "0", + "usePlotRange": "0", + "verticalOffset": 0, + "verticalPosition": 0, + "verticalRange": "0.6", + "verticalSize": 1, + "watchpointId": 3, + "wavefrontSource": "source" + }, + "multipole": { + "bx": 0, + "by": 0.4, + "length": 3 + }, + "postPropagation": [ + 0, + 0, + 1, + 0, + 0, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "powerDensityReport": { + "_super": "_INTENSITY_REPORT", + "aspectRatio": "1", + "colorMap": "grayscale", + "distanceFromSource": 20, + "horizontalOffset": 0, + "horizontalPointCount": 100, + "horizontalPosition": "0", + "horizontalRange": "15", + "horizontalSize": 1, + "intensityPlotsWidth": "0", + "maxIntensityLimit": 1e+30, + "method": 1, + "minIntensityLimit": 0, + "notes": "", + "plotScale": "linear", + "precision": "1", + "rotateAngle": 0, + "rotateReshape": "1", + "useIntensityLimits": "0", + "usePlotRange": "0", + "verticalOffset": 0, + "verticalPointCount": 100, + "verticalPosition": 0, + "verticalRange": "15", + "verticalSize": 1 + }, + "propagation": {}, + "simulation": { + "distanceFromSource": 20, + "documentationUrl": "", + "fieldUnits": 1, + "folder": "/", + "framesCleared": false, + "horizontalPointCount": 100, + "horizontalPosition": 0, + "horizontalRange": "0.4", + "isExample": "", + "lastModified": 1689186143332, + "name": "Empty", + "notes": "", + "outOfSessionSimulationId": "", + "photonEnergy": "9000", + "sampleFactor": 1, + "samplingMethod": 1, + "simulationId": "emptysim", + "simulationSerial": 1689186143331604, + "sourceType": "u", + "verticalPointCount": 100, + "verticalPosition": 0, + "verticalRange": "0.6" + }, + "sourceIntensityReport": { + "_super": "_INTENSITY_REPORT", + "aspectRatio": "1", + "characteristic": 0, + "colorMap": "grayscale", + "distanceFromSource": 20, + "fieldUnits": 1, + "finalPosition": 0, + "horizontalOffset": 0, + "horizontalPointCount": 100, + "horizontalPosition": 0, + "horizontalRange": "0.4", + "horizontalSize": 1, + "initialPosition": 0, + "intensityPlotsWidth": "0", + "maxIntensityLimit": 1e+30, + "method": "1", + "minIntensityLimit": 0, + "notes": "", + "photonEnergy": "9000", + "plotScale": "linear", + "polarization": 6, + "precision": 0.01, + "rotateAngle": 0, + "rotateReshape": "1", + "sampleFactor": 1, + "samplingMethod": 2, + "useIntensityLimits": "0", + "usePlotRange": "0", + "verticalOffset": 0, + "verticalPointCount": 100, + "verticalPosition": 0, + "verticalRange": "0.6", + "verticalSize": 1 + }, + "tabulatedUndulator": { + "gap": 6.72, + "id": " 1", + "indexFileName": "", + "magneticFile": "magnetic_measurements.zip", + "name": "Undulator", + "phase": 0, + "undulatorSelector": "Undulator", + "undulatorType": "u_t" + }, + "trajectoryReport": { + "finalTimeMoment": 0, + "initialTimeMoment": 0, + "magneticField": "2", + "notes": "", + "numberOfPoints": 10000, + "plotAxisX": "Z", + "plotAxisY": "X", + "plotAxisY2": "None", + "timeMomentEstimation": "auto" + }, + "undulator": { + "effectiveDeflectingParameter": 1.65776086, + "horizontalAmplitude": "0", + "horizontalDeflectingParameter": 0, + "horizontalInitialPhase": 0, + "horizontalSymmetry": 1, + "length": 3, + "longitudinalPosition": 0, + "period": "20", + "verticalAmplitude": "0.88770981", + "verticalDeflectingParameter": 1.65776086, + "verticalInitialPhase": 0, + "verticalSymmetry": -1 + } + }, + "rsmanifest": { + "image": { + "git_commit": "6241198561b849e5101304d5eb2fadf534374eb9", + "git_remote_origin_url": "https://github.com/radiasoft/sirepo", + "name": "radiasoft/sirepo", + "type": "docker", + "uri": "https://registry.hub.docker.com/radiasoft/sirepo:20230707.023551", + "version": "20230707.023551" + }, + "version": "20190612.150000" + }, + "simulationType": "srw", + "version": "20230707.4548" +} From 9faa8ddae5a8a86030015c88656bc2e77355d04d Mon Sep 17 00:00:00 2001 From: Riley Bode Date: Wed, 12 Jul 2023 14:58:12 -0400 Subject: [PATCH 2/2] Added test for empty sim --- sirepo_bluesky/tests/conftest.py | 7 +++++++ sirepo_bluesky/tests/test_bl_elements_as_ophyd_objs.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/sirepo_bluesky/tests/conftest.py b/sirepo_bluesky/tests/conftest.py index d67c483b..facce9cd 100644 --- a/sirepo_bluesky/tests/conftest.py +++ b/sirepo_bluesky/tests/conftest.py @@ -65,6 +65,13 @@ def make_dirs(): _ = make_dir_tree(datetime.datetime.now().year, base_path=root_dir) +@pytest.fixture(scope="function") +def srw_empty_simulation(make_dirs): + connection = SirepoBluesky("http://localhost:8000") + data, _ = connection.auth("srw", "emptysim") + return connection + + @pytest.fixture(scope="function") def srw_youngs_double_slit_simulation(make_dirs): connection = SirepoBluesky("http://localhost:8000") diff --git a/sirepo_bluesky/tests/test_bl_elements_as_ophyd_objs.py b/sirepo_bluesky/tests/test_bl_elements_as_ophyd_objs.py index 5bf2948d..b49178f8 100644 --- a/sirepo_bluesky/tests/test_bl_elements_as_ophyd_objs.py +++ b/sirepo_bluesky/tests/test_bl_elements_as_ophyd_objs.py @@ -28,6 +28,14 @@ def test_beamline_elements_as_ophyd_objects(srw_tes_simulation): pprint.pprint(mono_crystal1.read()) # noqa +def test_empty_simulation(srw_empty_simulation): + classes, objects = create_classes(srw_empty_simulation.data, connection=srw_empty_simulation) + globals().update(**objects) + + assert not srw_empty_simulation.data["models"]["beamline"] + assert not objects + + @pytest.mark.parametrize("method", ["set", "put"]) def test_beamline_elements_set_put(srw_tes_simulation, method): classes, objects = create_classes(srw_tes_simulation.data, connection=srw_tes_simulation)