<jupyter_start><jupyter_text>LUME-Genesis example<jupyter_code># Useful for debugging
%load_ext autoreload
%autoreload 2
# Nicer plotting
import matplotlib.pyplot as plt
import matplotlib
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
matplotlib.rcParams['figure.figsize'] = (20,6)
from genesis import Genesis
import numpy as np
import os

# Genesis binary
if 'GENESIS_BIN' not in os.environ:
    os.environ['GENESIS_BIN'] = os.path.expandvars('$HOME/cori/genesis/bin/genesis2')
    
WORKDIR='/global/cscratch1/sd/cmayes/test_jacek1'
!rm -rf {WORKDIR}
!mkdir {WORKDIR}<jupyter_output><empty_output><jupyter_text>Setup Genesis object and write basic input<jupyter_code># Make genesis object with default input
G = Genesis('hxr_cutbeam9_5keV02invL.in', verbose=True, use_tempdir=False, workdir=WORKDIR)

# Turn on field output
G['idmpfld'] = 1

# Turn on particle output
G['idmppar'] = 1

# Write input
G.write_input()<jupyter_output>Parsed beam file: /global/u2/c/cmayes/test/test_jacek/curr_cutCM02.txt with 14 columns
loading lattice:  /global/u2/c/cmayes/test/test_jacek/lcls2_hxr_SASE_inv.lat
Configured to run in: /global/cscratch1/sd/cmayes/test_jacek1
Beam written: /global/cscratch1/sd/cmayes/test_jacek1/genesis_beam.in
/global/cscratch1/sd/cmayes/test_jacek1 genesis_lattice.in
Lattice written: /global/cscratch1/sd/cmayes/test_jacek1/genesis_lattice.in<jupyter_text>Run at CoriThis will use an interactive session. This will take a few minutes.<jupyter_code>!cd {WORKDIR};salloc -N 4 -C haswell -q interactive -t 00:30:00 srun -n 128 ~/cori/genesis/bin/genesis2_mpi_fastcat genesis.in >log.txt;tail log.txt<jupyter_output>salloc: Granted job allocation 30828381
salloc: Waiting for resource configuration
salloc: Nodes nid00[124-127] are ready for job
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are [...]<jupyter_text>Load that output and archive<jupyter_code>G.load_output()
G.output['data']['dpa'].shape
sf = G.output['data']['dpa'][100, :, :]
##. 0      1.    2. 3.  4.     5
## gamma, phase, x, y, px/mc, py/mc
plt.scatter(sf[1, :], sf[0, :], marker='.')
G.archive()<jupyter_output><empty_output><jupyter_text>Write wavefront<jupyter_code>G.write_wavefront()
AWlist = [ele['strength'] for ele in G.lattice['eles'] if ele['type'] == 'AW']
def set_aw(lattice, awlist):
    for ele in lattice['eles']:
        if ele<jupyter_output><empty_output><jupyter_text>Plot some output<jupyter_code>G.output['data']['power'].shape
# Power of all slices, final z position
plt.plot(G.output['data']['power'][:, -1])
# Visualize some output data
for k in G.output['data']:
    dat = G.output['data'][k]
    
    # Skip the 1D arrays (current, z, aw, q)
    if len(dat.shape) != 2:
        print('skipping', k)
        continue
    plt.title(k)
    plt.xlabel('z index')
    plt.ylabel('slice index')
    plt.imshow(dat, origin='lower')
    plt.show()<jupyter_output><empty_output><jupyter_text>Raw Field<jupyter_code>dat = G.output['data']['dfl']
dat.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11654037104781813, 'fraction_numerical': 0.018029788345962895, 'mean_word_length': 5.799289520426288, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '300201', 'license': 'Apache-2.0', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1348, 'n_words': 323, 'path': 'models/genesis/lume-genesis-run-cori.ipynb', 'repo_name': 'LUME-SIMEX/lume-simex-demo-1', 'size': '3827'}