SOFTWARE SUSTAINABILITY AND TOOLKITS: HOW TO PROGRAM FOR THE - - PowerPoint PPT Presentation

software sustainability and toolkits how to program for
SMART_READER_LITE
LIVE PREVIEW

SOFTWARE SUSTAINABILITY AND TOOLKITS: HOW TO PROGRAM FOR THE - - PowerPoint PPT Presentation

SOFTWARE SUSTAINABILITY AND TOOLKITS: HOW TO PROGRAM FOR THE ACCELERATOR SIMULATION PROBLEMS OF TOMORROW David Sagan Cornell Laboratory for Accelerator Based Sciences and Education Linac and Storage Ring Programs No Longer Used: AGS,


slide-1
SLIDE 1

SOFTWARE SUSTAINABILITY AND TOOLKITS: HOW TO PROGRAM FOR THE ACCELERATOR SIMULATION PROBLEMS OF TOMORROW

David Sagan Cornell Laboratory for Accelerator Based Sciences and Education

slide-2
SLIDE 2

Linac and Storage Ring Programs No Longer Used:

■ AGS, ■ ALIGN ■ COMFORT ■ DESIGN ■ DIMAD ■ GUINEA-PIG ■ HARMON ■ LEGO ■ LIAR ■ MAGIC ■ MARYLIE ■ PATRICIA ■ PETROS ■ PLACET ■ RACETRACK ■ SYNCH ■ TRACY ■ TRANSPORT ■ TURTLE ■ UAL

David Sagan KEK September 18-19, 2019 2

Ho How many man-ye years of effort went into to these programs? Ho How can we, as an accelerator physics community do bet etter? Ho How can software be developed that is useful and is used year after year?

slide-3
SLIDE 3

David Sagan KEK September 18-19, 2019 3

Outline of the Talk

■ Software Sustainability – What is it? ■ Software Toolkits – What is a toolkit? How do toolkits help sustainability? ■ Bmad – An example of a toolkit.

slide-4
SLIDE 4

SOFTWARE SUSTAINABILITY

David Sagan KEK September 18-19, 2019

4

slide-5
SLIDE 5

What is Software Sustainability?

David Sagan KEK September 18-19, 2019 5

A definition of Software Sustainability: "the capacity of the software to endure. In other words, sustainability means that the software will continue to be available in the future, on

  • n ne

new pl plat atforms, s, meeting ng ne new ne needs.”

From: Daviel Katz https://danielskatzblog.wordpress.com/2016/09/13/defining-software-sustainability/

slide-6
SLIDE 6

Readability / Understandability Extensibility / Evolvability Portability / Installability Scalability Speed Learnability Documentation Modularity / Reusability Correctness / Testability

David Sagan KEK September 18-19, 2019 6

What Goes Into Software Sustainability?

■ Intrinsic: The characteristics of the software itself. ■ Extrinsic: The environment in which the software is developed and/or used. Accessibility / Openly Available?-------- Usefulness--- Licensing- Funding Community- Version-Control--- Actively Maintained--------

Intrinsic Extrinsic

slide-7
SLIDE 7

David Sagan KEK September 18-19, 2019 7

SOFTWARE EVALUATION: CRITERIA-BASED NOVEMBER 2011

Software Evaluation: Criteria-based Assessment

Mike Jackson, Steve Crouch and Rob Baxter Criteria-based assessment is a quantjtatjve assessment of the sofuware in terms of sustainability, maintainability, and usability. This can inform high-level decisions on specific areas for sofuware improvement. A criteria-based assessment gives a measurement of quality in a number of areas. These areas are derived from ISO/IEC 9126-1 Sofuware engineering — Product quality1 and include usability, sustainability and maintainability. The assessment involves checking whether the sofuware, and the project that develops it, conforms

And there exists Standards for Code Quality

slide-8
SLIDE 8

Example of Non-Sustainable Code

David Sagan KEK September 18-19, 2019 8 ”Piled Higher and Deeper" by Jorge Cham www.phdcomics.com. Used with permission.

"Software decays relatively quickly if it is not maintained and this is especially true for software used in research"

Mario Rosado de Souza, Robert Haines, Markel Vigo, Caroline Jay, "What Makes Research Software Sustainable? An Interview Study With Research Software Engineers."

slide-9
SLIDE 9

SOFTWARE TOOLKITS

David Sagan KEK September 18-19, 2019

9

slide-10
SLIDE 10

Problem: Developing simulation code takes time.

David Sagan KEK September 18-19, 2019 10

⾞輪の再発明

In general, accelerator simulation problems have some common needs like reading in lattice information or calculating orbits. Writing code from scratch to do this is like reinventing the wheel. How can we do better? What does it take to create programs efficiently?

Accelerator Physicist

Ac Actual Simulation Pr Program De Desired Simulation

  • n

Pr Program

slide-11
SLIDE 11

What is a Software Toolkit?

David Sagan KEK September 18-19, 2019 11

Definition of a Toolkit:

An integrated set of modular software routines that are used to develop and maintain applications or databases.

slide-12
SLIDE 12

A Toolkit is like a bunch of Lego blocks

David Sagan KEK September 18-19, 2019 12

Advantages of a toolkit:

  • Cuts down on the time needed to develop programs.
  • Cuts down on programming errors (via module reuse).
  • Standardizes sharing of lattice information between

programs.

  • Increased safety: Modular code provides a firewall. For

example, a buggy module introduced into the toolkit will not affect programs that do not use it.

Toolkit Dynamic Aperture Program Control System Programs Lattice Design Program

Etc.

IBS Simulation Programs

A toolkit, by making the softwa ware more useful, helps make the softwa ware sustainable.

slide-13
SLIDE 13

Accelerator Simulation Toolkits

David Sagan KEK September 18-19, 2019 13

Accelerator Toolbox

Bmad

COSY INFINITY

____ __ ______ ______ / \/ \ / _ \ / _ \ / __ / / /_/ / / /_/ / /__/ /_/ /__/ /_/ /_____ / MAD-NG

Merlin/Merlin++ FPP/PTC

Matlab based. Used extensively at light sources for such things as orbit response matrix analysis. Includes modules for spin tracking, low energy space charge, etc. Has interface to PTC In development by Laurent Denieu (CERN). Replacement for MAD-X. Recent developments oriented towards simulating wakefields and particle/matter interactions. Uses Differential Algebra (DA) for tracking. Has Differential Algebra (DA), symplectic tracking, power series map, normal form analysis, etc.

slide-14
SLIDE 14

BMAD

David Sagan KEK September 18-19, 2019

14

slide-15
SLIDE 15

In the Beginning…

Brief History: § Born at Cornell in mid 1990’s § Started life as modest project: Just wanted to calculate Twiss functions and closed

  • rbits within control system programs.

§ Initially Bmad used a subset of the MAD lattice syntax. Hence the name: “Baby MAD” or “Bmad” for short.

David Sagan KEK September 18-19, 2019 15

slide-16
SLIDE 16

And Baby Grows Up...

Currently: § >100,000 lines of code § ~1,000 routines

David Sagan KEK September 18-19, 2019 16

slide-17
SLIDE 17

And Bmad can do Much More:

§ Lattice design § X-ray simulations § Spin tracking § Wakefields and HOMs § Beam breakup (BBU) simulations in ERLs § Intra-beam scattering (IBS) simulations § Coherent Synchrotron Radiation (CSR) § Touschek Simulations § Frequency map analysis § Dark current tracking § Etc., etc.

David Sagan KEK September 18-19, 2019 17

slide-18
SLIDE 18

Overview

§ Written in object oriented Fortran 2008. § With certain restrictions, Bmad can be run multi-threaded. § Lattice files use a MAD like syntax. § Well documented (Manual is >500 pages). § Open Source: http://www.classe.cornell.edu/bmad/ § And Bmad is indeed a toolkit:

David Sagan KEK September 18-19, 2019 18

type (lat_struct) lat call bmad_parser (‘lat.bmad’, lat) Data Lego block Action Lego block

slide-19
SLIDE 19

Bmad Features

David Sagan KEK September 18-19, 2019 19

Bmad has a number

  • f features

that over the years have proven useful. Among these are:

Sup Super erposition – Define overlapping elements. Co Controller elements – Elements controlling attributes of other elements. Mu Multiple connected beam beam lines nes in n one

  • ne lat

attice e – Example: Injection line attached to a ring. Mu Multipass lin lines – Multiple beams sharing a common line such as the IR region in a dual ring colliding beam machine. Cus Custom elements and cu cust stom particl cle tr tracking. Define beam beam cham hamber ber wal alls. Example of how a lattice can contain multiple attached beam lines and this can be used to describe complicated machine geometries

6 MeV 42, 78, 114, 150 MeV Mirror Merger Injector Merger Diagnostics

slide-20
SLIDE 20

Bmad Ecosystem

20 David Sagan KEK September 18-19, 2019

Due to its flexibility, Bmad has been used in a number of programs including:

  • Ta

Tao: General purpose design and simulation.

  • Sy

Synrad3d 3d: 3D tracking of synch photons, including reflections, within the beam chamber walls.

  • BBU

BBU: Beam breakup instability simulations.

  • dar

dark_c k_cur urrent ent_t _trac acker er: Dark current electron simulation.

  • ib

ibs_sim im: Analytic intra-beam scattering (IBS) calculation.

  • to

touschek_track: Tracking of Touschek particles.

  • fre

freq_map: Frequency map analysis.

  • MO

MOGA: : Multi-Objective Genetic Algorithm optimization.

  • Lu

Lux: Photon tracking in X-ray beam lines.

  • et

etc...

Co Code de reus use: Modules developed for one program can, via Bmad, be used in other programs.

Tu Tune Scan for CESR Ring Upgrade

Circles = design tunes, Diamonds = current tunes.

BBU BBU threshold cur urrent nt for CBETA as a function of the phase advance between cavities.

slide-21
SLIDE 21

Tao: Tool for Accelerator Optics

■ Pr Problem: Bmad is not a program so it cannot be used “out of the box.” for simple calculations. ■ So Solution: Develop Tao - a general purpose simulation & design program

  • Twiss and orbit calculations.
  • Nonlinear optimization.
  • Lattice design.
  • Etc.

■ Ad Additionally: Tao’s object oriented coding makes it relatively easy to extend it. ■ Fo For example: Can add custom commands to interface Tao with a control system (EG: CBETA ERL).

21 David Sagan KEK September 18-19, 2019

Ø Bm Bmad ad with Ta Tao gives the flexibility of a Toolkit with the convenience of a program.

Ex Exampl ple: Modifying the CESR ring to stay within the existing building. Ex Exampl ple: Element misalignment in the CBETA ERL followed by a steering correction.

s (m) Orbit (mm) Energy (MeV) 150 114 78 42 Energy (MeV) 150 114 78 42 s (m) Orbit (mm)

Orbits w/ misalignment Orbits after correction

slide-22
SLIDE 22

Synrad3D was created to calculate the initial distribution of photoelectrons for electron cloud studies. It has also been used for studying the efficiency of beam masks. Simulation Procedure:

  • 1. Calculate beam orbit
  • 2. Emission of photons from the beam
  • 3. 3D tracking of photons to the vacuum chamber wall
  • 4. Scattering or absorption at the chamber wall
  • 5. If not absorbed, further tracking until absorption

Synrad3D Program

22 David Sagan KEK September 18-19, 2019

slide-23
SLIDE 23

Synrad3D Development

23 David Sagan KEK September 18-19, 2019

Electron cloud distribution vs position after 10 bunch train

At the start of development, Bmad provided code for:

  • Lattice parsing
  • Calculation of the closed orbit
  • Photon generation
  • Defining the vacuum chamber wall

Synrad3d development involved creating code for:

  • Tracking of photons.
  • Reflection/absorption at the chamber wall.

èThe use of Bmad saved considerable development time. Also: The code for defining the vacuum chamber wall came from dark electron simulation development. èCode developed for one purpose can be used in other places saving development time.

slide-24
SLIDE 24

Synrad3d: SuperKEKB Simulation

50 100 150 200 250 100 200 300 400

Simulations by Jim Crittenden SuperKEKB wall profile courtesy Takuya Ishibashi Problem: Photoelectrons can be trapped in the field of a quadrupole. The electrons will react with the beam and if the density is high enough, this can cause problems. Simulation to determine the number of photons absorbed near a particular quadrupole

Entries Mean RMS 3521 50.92 75.89

100 200 300 400 500 600 700 800 200 400 25 50 75 100 125 150 175 200 3015.2 3015.3 3015.4 3015.5 3015.6

Photon number Energy Spectrum Angular distribution

24 David Sagan KEK September 18-19, 2019

slide-25
SLIDE 25

25 David Sagan KEK September 18-19, 2019 12 cm

Problem: SuperKEKB lattices have a chicane with px ~ 0.03. But MAD8/X uses the paraxial approximation which assumes that px, py << 1. So in this case a MAD dr drift element is a poor approximation for the chicane drifts.

SAD To MAD Lattice Translation for SuperKEKB

slide-26
SLIDE 26

26 David Sagan KEK September 18-19, 2019

Translation Solution

Translation is done in two steps:

  • 1. SAD -> Bmad
  • 2. Bmad -> MAD

In the Bmad -> MAD step, Bmad uses Etienne’s PTC Toolkit to construct a 2nd order map for the chicane drifts which is then instantiated as a MAD ma matrix element. Since Bmad and PTC are toolkits, the translation code is integrated into a unified program.

LATTICE TRANSLATION BETWEEN ACCELERATOR SIMULATION

  • D. Zhou , H. Koiso, A. Morita, Y. Ohnishi, K. Oide, H. Sugimoto, KEK, Tsukuba, Japan

M.E. Biagini, INFN/LNF, Frascati, Italy

  • N. Carmignani †

, S.M. Liuzzo, ESRF, Grenoble, France

  • D. Sagan ‡

, Cornell University, Ithaca, NY, USA

CODES FOR SuperKEKB

Proceedings of IPAC2016, Busan, Korea WEPOY040

slide-27
SLIDE 27
  • point

chamber Beam vacuum Tangential reference line 1.25 Muon orbit Beam line Injection

G-2 Simulation Program

■ Dave Rubin at Cornell has been developing a simulation program to simulate the Mu Muon g-2 2 experim iment nt at Fermilab. ■ Need to track the polarized muons with:

  • Injection line into a storage ring.
  • Three dimensional field of the injection

line.

  • Scattering of muons as they cross the

inflector wall

  • Electrostatic quadrupoles
  • Muon decay
  • Tracking of electron decay product

27

Polarized Muons

David Sagan KEK September 18-19, 2019

slide-28
SLIDE 28

G-2 Simulation

■ At the start of program development Bm Bmad ad pr provided: – Ability to define the geometry of the injection line and storage ring. – Ability to define the geometry of the inflector wall – Ability to define custom fields for the injection line and the ability to simulate electrostatic quadrupoles ■ Ne Needed t to d develop f for t the p program: m: – Scattering of muons through the inflector wall – muon decay. – etc.

28

è Bmad reduced the development time for creating the program and provides a flexible framework for future program modifications.

David Sagan KEK September 18-19, 2019

slide-29
SLIDE 29

CONCLUSIONS

29 David Sagan KEK September 18-19, 2019

slide-30
SLIDE 30

Some Thoughts

David Sagan KEK September 18-19, 2019 30

Main advantage of a software toolkit: The flexibility so that programs can be developed in less time and with fewer bugs. Main disadvantages of a toolkit: Increased work for the toolkit developers in terms of documentation and stricter code quality requirements. Personal opinion: The advantages of a toolkit fa far outweigh the disadvantages for accelerator simulation software. In particular, Bmad has been successful due to it’s modular, object-oriented design which allows it to be adapted to ever changing simulation needs. The quality and quantity of Bmad based programs would not be possible if Bmad where not a toolkit. Bmad has been used at Cornell, CERN, KEK, DESY, ANL, BNL, Cockcroft Institute, for simulating CESR, ILC, LCLS2, SuperKEK-B, CBETA, ALS-U, Fermilab g-2 muon project, etc. Bmad is always in continual development with about 1.5 FTEs. Supported by Cornell Laboratory for Accelerator-based Sciences and Education (CLASSE). Bmad is evolving towards being able to do “complete” start-to-end simulations.

slide-31
SLIDE 31

Thanks to Contibutors

Dan Abell Ivan Bazarov Moritz Beckmann Martin Berz Joel Brock Desmond Barber Sarah Buchan Avishek Chatterjee Jing Yee Chee Christie Chiu Joseph Choi Robert Cope Jim Crittenden Attilio De Falco Gerry Dugan Michael Ehrlichman Ken Finkelstein Et Etienne nne Forest Mike Forster Hans Grote Richard Helms Georg Hoffstaetter Chris Mayes Karthik Narayan Katsunobu Oide Mark Palmer Tia Plautz Matt Randazzo Matt Rendina Dave Rubin Michael Saelim Frank Schmidt Jim Shanks Jeff Smith Jeremy Urban Mark Woodley Demin Zhou

31 David Sagan KEK September 18-19, 2019

slide-32
SLIDE 32

END

32 David Sagan KEK September 18-19, 2019

slide-33
SLIDE 33

Programming with Bmad

David Sagan KEK September 18-19, 2019 33

For programmers, to maximize Bmad’s usefulness, Bmad is designed to be modular and object oriented from the ground up:

There are tw

two ty

types es of Bmad users:

The majority are non non- pr prog

  • grammers who use

Bmad based programs. A minority are pr prog

  • grammers who develop

Bmad based programs.

type (lat_struct) lat call bmad_parser (‘lat.bmad’, lat)

slide-34
SLIDE 34

Tao Examples

■ Bm Bmad ad with Ta Tao gives the fl flexibility o

  • f a

f a To Toolkit with the co convenience ce of a a progr gram am.

34

■ Ex Exampl ple: Designing or modifying a machine to be/stay within an existing building. ■ Ex Exampl ple: Element misalignment in CBETA followed by steering correction.

s (m) Orbit (mm) Energy (MeV) 150 114 78 42 Energy (MeV) 150 114 78 42 s (m) Orbit (mm)

Orbits w/ misalignment Orbits after correction

David Sagan KEK September 18-19, 2019