Compiled Python module development for IMPACT interface Kei

  • Slides: 15
Download presentation
Compiled Python module development for IMPACT interface Kei Fukushima, Michigan State University, FRIB This

Compiled Python module development for IMPACT interface Kei Fukushima, Michigan State University, FRIB This material is based upon work supported by the U. S. Department of Energy Office of Science under Cooperative Agreement DE-SC 0000661, the State of Michigan and Michigan State University designs and establishes FRIB as a DOE Office of Science National User Facility in support of the mission of the Office of Nuclear Physics.

Facility for Rare Isotope Beams @Michigan State Univ. - Exploring new, unexplored regions of

Facility for Rare Isotope Beams @Michigan State Univ. - Exploring new, unexplored regions of the nuclear chart Accelerator simulation codes for FRIB (online model) FLAME (Fast Linear Accelerator Model Engine) • Envelope tracking • Dedicate to fast simulation ü Simulate FRIB-linac beam envelope in milli-sec order • Native Python interface (C++ python extension) • IMPACT-Z (FRIB-branch) • Refactoring from IMPACT-Z developed by LBNL • Particle tracking and PIC method • Dedicate to precise simulation • Compiled Python module for application developments User can switch the beam data source from FLAME, IMPACT, or Real Machine through the online model application K. Fukushima, BLAST Workshop 2018, Slide 2

Why Python ? • Interactive simulation ü The compiled module accomplish the simulation process

Why Python ? • Interactive simulation ü The compiled module accomplish the simulation process without losing computational efficiency • Flexible inputs and direct outputs management in memory ü Change element setting and initial beam condition w/o reloading lattice file ü Re-run simulation by using cached data • Easy and direct connection to the modern scientific tools ü Optimization (Sci. Py/Num. Py, Dakota, Tensor. Flow, etc. ) ü Data archiving (HDF 5, JSON, SQL, etc. ) ü Data visualization (Matplotlib, Bokeh, Open. GL, etc. ) ü Online model (virtual-accelerator) engine K. Fukushima, BLAST Workshop 2018, Slide 3

Code Design Python package provides shared memory communication for simulation process Source Directory Tree

Code Design Python package provides shared memory communication for simulation process Source Directory Tree Original Directories impact/ Contrl/ Build Directory Tree build/ bin/ - Executable Files lib/ - Physics Library python/ - Python Package Appl/ Data. Struct/ Func/ Docs/ Adv. Contrl/ python/ • Build is managed by CMake • Python module is generated by F 2 PY • Support MPI parallelize by mpi 4 py K. Fukushima, BLAST Workshop 2018, Slide 4

Benchmark Python interface has the same efficiency and benefits iterative running Sample Lattice: FRIB

Benchmark Python interface has the same efficiency and benefits iterative running Sample Lattice: FRIB LS 1 and FS 1 (include charge stripper) • without space charge calculation • using 2 types of 3 D field files (data size: 188 MB and 235 MB) LS 1 / 1000 particles LS 1+FS 1 / 1000 particles 1 st run iterative run (field data cached) Original IMPACT 12. 29 s No data 13. 29 s No data Python Interface 11. 95 s 0. 53 s (Load: 11. 42) 12. 67 s 1. 24 s (Load: 11. 43) LS 1 / 10000 particles LS 1+FS 1 / 10000 particles 1 st run iterative run (field data cached) Original IMPACT 13. 92 s No data 17. 97 s No data Python Interface 13. 50 s 2. 07 s (Load: 11. 43) 17. 41 s 5. 90 s (Load: 11. 51) Running on Intel(R) Core(TM) i 7 -6820 HQ CPU @ 2. 70 GHz with 4 cores K. Fukushima, BLAST Workshop 2018, Slide 5

Module Design Basic process of the simulation in Python interface (e. g. scratch-script, command-line,

Module Design Basic process of the simulation in Python interface (e. g. scratch-script, command-line, jupyter-notebook, etc. ) 1. Import python-IMPACT package >>> from impact import Sequence 2. Construct Sequence object with input lattice file >>> sq = Sequence('FRIB_sample. in') 3. Generate the initial distribution by using lattice file data >>> sq. distribute() 4. Run particle tracking >>> sq. run() Here, Sequence object contains all simulation results K. Fukushima, BLAST Workshop 2018, Slide 6

Extra Information for Lattice File # User can put ‘tag’ in the lattice file

Extra Information for Lattice File # User can put ‘tag’ in the lattice file 1 1 6 20642 2 0 1 65 65 129 4 0. 14 0. 1025446 Simulation condition and 19 0 0 2 10111 10531 initial beam parameter 0. 0 These parameters are also 1. 4885271891392098 E-10 1. 5336340736585796 E-10 0. 0022734189 8. 8312578 E-5 0. 0 1. 0 0. 0 configurable in Python interface 0. 0022734189 8. 8312578 E-5 0. 0 1. 0 0. 076704772 3. 4741445 E-6 0. 0 1. 0 0. 0 500000. 0 9. 3149432 E 8 0. 13865546218487396 8. 05 E 7 0. 0 99. 9 0. 072 4 20 0 0. 02 / # first lattice element 0. 135064 4 20 0 0. 02 / 0. 24 60 20 110 0. 64 8. 05 E 7 349. 740866 421 0. 017 0. 0 0. 0 1. 2. / tag={'cav 1'} 0. 064263 4 20 0 0. 02 / 0. 05588 4 20 0 0. 02 / 0. 076123 4 20 0 0. 02 / 0. 1 1 1 3 5. 34 0 0. 02 / tag={'sol 1', ‘sol 1_part 1'} # user can set multiple tags 0 0 0 -21 0. 02 0 0 0 / 0. 1 1 1 3 5. 34 0 0. 02 / tag=['sol 1', 'sol 1_part 2'] # user can set the same tag name 0. 076123 4 20 0 0. 02 / 0. 06727 4 20 0 0. 02 / 0. 0 0 100 -2 0. 0 1 / tag=('moni 1', 'pm 1') # (), {}, [] brackets are available K. Fukushima, BLAST Workshop 2018, Slide 7

Simulation Result Usage [1/2] # Get simulation results >>> sq. hxrms() # returns x

Simulation Result Usage [1/2] # Get simulation results >>> sq. hxrms() # returns x rms size (default unit is [m]) array([ 3. 3444 e-06, 3. 5751 e-06, . . . , -3. 9116 e-05, -3. 9767 e-05]) # Auto linear interpolation and unit conversion >>> sq. hxcen(0. 5, 'mm') # returns x centroid [mm] at s = 0. 5 [m] array([ 0. 01071064]) >>> sq. hxcen([0. 5, 0. 6, 0. 7], 'mm') # support list input array([ 0. 01071064, 0. 01260737, 0. 00144759]) >>> sq. hxcen('cav 1', 'mm') # support tag input array([ 0. 00758989]) All simulation results are available to access through shared memory K. Fukushima, BLAST Workshop 2018, Slide 8

Simulation Result Usage [2/2] # Get current beam distribution >>> sq. getx() # returns

Simulation Result Usage [2/2] # Get current beam distribution >>> sq. getx() # returns current x distribution array([ 0. 00190219, -0. 00270052, . . . , -0. 0002277, -0. 00259636]) # For example, >>> >>> sq. distribute() sq. getx() sq. run() sq. getx() # # generate initial distribution -> returns initial distribution run particle tracking -> returns finite distribution # Get beam distribution at flag element >>> sq. getx(100, 'mm') # returns x distribution at the flag element array([ 3. 00496309, -2. 23733725, . . . , -4. 09860108, -2. 0038936]) >>> sq. getx('pm 1', 'mm') # support tag input array([ 3. 00496309, -2. 23733725, . . . , -4. 09860108, -2. 0038936]) K. Fukushima, BLAST Workshop 2018, Slide 9

Parameter Configuration # Simulation/initial-sbeam parameter configuration >>> sq. Energy = 5. 5 e 5

Parameter Configuration # Simulation/initial-sbeam parameter configuration >>> sq. Energy = 5. 5 e 5 #[e. V] set new value for the initial beam energy >>> sq. Distxtwiss = [0. 1, 0. 6, 1. 3 e-7] # set initial twiss [a, b, e] # Get element parameters >>> sq. conf('sol 1_part 2') # support tag or index input / returns dict index : 10 (start : 0. 64333 , end : length : 0. 1 [m] segment : 1 step : 1 type : 3 (solenoid) bz 0 ('bz', 'b') : 5. 34 [T] fileid ('file', 'id') : 0. 0 aperture ('aper', 'pipe', 'radius') : dx ('dx 0', ) : 0. 0 [m] dy ('dy 0', ) : 0. 0 [m] pitch ('dx 1', ) : 0. 0 [rad] yaw ('dy 1', ) : 0. 0 [rad] roll : 0. 0 [rad] tag : ['sol 1', 'sol 1_part 2'] 0. 74333 [m]) 0. 02 [m] # Element parameter configuration >>> sq. conf('sol 1_part 2', {'Bz': 3. 14}) # set new parameter K. Fukushima, BLAST Workshop 2018, Slide 10

A to B run (partial run) # distribute() method supports to input user defined

A to B run (partial run) # distribute() method supports to input user defined initial distribution >>> dst = np. zeros(9, 1000) # 1000 particles # User can set own distribution # index 0 -5 : 6 D phase space information # index 7 : charge to mass ratios # index 8 : charge per macro-particle weight # index 9 : ID numbers >>> sq. distribute(particles=dst, unit='physical') # unit='physical' : use [m, rad, deg, Me. V] for 6 D info. # run() method supports to input ‘start’ and ‘end’ point of the simulation >>> sq. run(start='cav 1', end=11) # simulate from the 1 st cavity (index=3) to 11 th element K. Fukushima, BLAST Workshop 2018, Slide 11

Use Case Easy to develop user own scripts and applications Simulation example in jupyter-notebook

Use Case Easy to develop user own scripts and applications Simulation example in jupyter-notebook Transverse matching by using scipy. optimize K. Fukushima, BLAST Workshop 2018, Slide 12

Sphinx-base Documentation import Python code’s docstrings automatically, keep up-to-date easily K. Fukushima, BLAST Workshop

Sphinx-base Documentation import Python code’s docstrings automatically, keep up-to-date easily K. Fukushima, BLAST Workshop 2018, Slide 13

Other Features • Unit test covers physics aspect and Python API module • Parallelized

Other Features • Unit test covers physics aspect and Python API module • Parallelized simulation in Python interface (include jupyter-notebook) • Element search by using element ‘type’ or ‘name’ • Lattice construction from Python interface (insert element etc. ) • Save simulation results to the file (compatible with original IMPACT) • Save lattice data to the file (compatible with original IMPACT) Physics features: • RFQ element with 8 term potential • Synchronous phase input for RF cavities (CCL, 3 D field) • 3 D bending field element K. Fukushima, BLAST Workshop 2018, Slide 14

Summary • Python interface for the numerical simulation codes will benefit both the end-user

Summary • Python interface for the numerical simulation codes will benefit both the end-user and the application developer. • Compiled module is the best solution to accomplish both the data communication flexibility and the computational efficiency. Work supported by the U. S. Department of Energy Office of Science under Cooperative Agreement DESC 0000661. K. Fukushima, BLAST Workshop 2018, Slide 15