|
| 1 | +.. _examples-ml-surrogate: |
| 2 | + |
| 3 | +9 stage laser-plasma accelerator surrogate example |
| 4 | +================================================== |
| 5 | + |
| 6 | +Nine stages of laser-plasma accelerators. |
| 7 | +The laser-plasma accelerator elements are neural network surrogate models, |
| 8 | +previously trained and included in ``models``. |
| 9 | +The neural networks require normalized input data, the normalizations can be found in ``datasets``. |
| 10 | + |
| 11 | + |
| 12 | +We use a 1 GeV electron beam with initial normalized rms emittance of 1 mm-mrad. |
| 13 | + |
| 14 | +In this test, the initial and final values of :math:`\sigma_x`, :math:`\sigma_y`, :math:`\sigma_t`, :math:`\epsilon_x`, :math:`\epsilon_y`, and :math:`\epsilon_t` must agree with nominal values. |
| 15 | + |
| 16 | + |
| 17 | +Run |
| 18 | +--- |
| 19 | + |
| 20 | +This example can be **only** be run with **Python**: |
| 21 | + |
| 22 | +* **Python** script: ``python3 run_ml_surrogate.py``` |
| 23 | + |
| 24 | +For `MPI-parallel <https://www.mpi-forum.org>`__ runs, prefix these lines with ``mpiexec -n 4 ...`` or ``srun -n 4 ...``, depending on the system. |
| 25 | + |
| 26 | +.. tab-set:: |
| 27 | + |
| 28 | + .. tab-item:: Python: Script |
| 29 | + |
| 30 | + .. literalinclude:: run_fodo.py |
| 31 | + :language: python3 |
| 32 | + :caption: You can copy this file from ``examples/fodo/run_fodo.py``. |
| 33 | + |
| 34 | + |
| 35 | +Analyze |
| 36 | +------- |
| 37 | + |
| 38 | +We run the following script to analyze correctness: |
| 39 | + |
| 40 | +.. dropdown:: Script ``analyze_ml_surrogate.py`` |
| 41 | + |
| 42 | + .. literalinclude:: analyze_ml_surrogate.py |
| 43 | + :language: python3 |
| 44 | + :caption: You can copy this file from ``examples/pytorch_surrogate_model/run_ml_surrogate.py``. |
| 45 | + |
| 46 | + |
| 47 | +Visualize |
| 48 | +--------- |
| 49 | + |
| 50 | +You can run the following script to visualize the beam evolution over time: |
| 51 | + |
| 52 | +.. dropdown:: Script ``visualize_ml_surrogate.py`` |
| 53 | + |
| 54 | + .. literalinclude:: visualize_ml_surrogate.py |
| 55 | + :language: python3 |
| 56 | + :caption: You can copy this file from ``examples/pytorch_surrogate_model/visualize_ml_surrogate.py``. |
| 57 | + |
| 58 | +.. figure:: lpa_ml_surrogate_moments.png |
| 59 | + :alt: Evolution of beam moments through 9 stage LPA via neural network surrogates. |
| 60 | + |
| 61 | + 9 stage LPA (via neural network surrogates) beam moments |
| 62 | + |
| 63 | +.. figure:: initial_phase_spaces.png |
| 64 | + :alt: Initial phase space projections |
| 65 | + |
| 66 | + Initial phase space projections going into 9 stage LPA (via neural network surrogates) simulation |
| 67 | + |
| 68 | +.. figure:: stage_8_phase_spaces.png |
| 69 | + :alt: Final phase space projections after 9 stage LPA (via neural network surrogates) simulation |
| 70 | + |
| 71 | + Final phase space projections after 9 stage LPA (via neural network surrogates) simulation |
0 commit comments