Python Library for Simulated Commissioning of Synchrotrons Accelerator Toolbox Workshop

undefined
 
Lukáš
 Malina
 
On behalf of:
 
Thorsten Hellert, Simone Liuzzo, Lina Hoummi, Bianca Veglia, and Elaf Musa
 
Grenoble, October 2
nd
, 2023
 
P
y
t
h
o
n
 
l
i
b
r
a
r
y
 
f
o
r
 
s
i
m
u
l
a
t
e
d
c
o
m
m
i
s
s
i
o
n
i
n
g
 
o
f
 
s
y
n
c
h
r
o
t
r
o
n
s
 
A
c
c
e
l
e
r
a
t
o
r
 
T
o
o
l
b
o
x
 
W
o
r
k
s
h
o
p
 
Commissioning simulations and/in Python
Translation from Matlab with the help of AI
Contents of the Python library
 
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
 
 
O
u
t
l
i
n
e
 
D
e
s
i
g
n
e
d
:
 
G
r
o
u
p
s
 
o
f
 
p
e
r
f
e
c
t
 
a
n
d
 
i
d
e
n
t
i
c
a
l
 
e
l
e
m
e
n
t
s
 
w
h
i
c
h
 
a
r
e
 
p
e
r
f
e
c
t
l
y
 
a
l
i
g
n
e
d
Specify (realistic) tolerances on the components themselves and their alignment
C
a
n
 
w
e
 
p
a
s
s
 
f
r
o
m
 
B
u
i
l
t
 
t
o
 
O
p
e
r
a
t
i
o
n
a
l
?
 
-
>
 
C
o
m
m
i
s
s
i
o
n
i
n
g
 
s
i
m
u
l
a
t
i
o
n
s
Store and “interface” errors, which are different for each single element
P
r
o
v
i
d
e
 
h
i
g
h
-
l
e
v
e
l
 
c
o
r
r
e
c
t
i
o
n
 
m
e
t
h
o
d
s
 
a
n
d
 
s
e
p
a
r
a
t
e
d
 
p
e
r
f
o
r
m
a
n
c
e
 
a
n
a
l
y
s
i
s
Replicate many machines with all sorts of random errors (given the tolerances)
 
 
B
u
i
l
t
:
 
N
e
i
t
h
e
r
 
p
e
r
f
e
c
t
 
n
o
r
 
i
d
e
n
t
i
c
a
l
 
e
l
e
m
e
n
t
s
,
 
w
h
i
c
h
 
f
e
a
t
u
r
e
 
r
e
s
i
d
u
a
l
 
m
i
s
a
l
i
g
n
m
e
n
t
s
D
o
e
s
 
n
o
t
 
w
o
r
k
!
Need to commission, i.e. adjust settings using beam as a diagnostics tool
Single replication with errors -> Commissioning simulation with only changed interface
O
p
e
r
a
t
i
o
n
a
l
:
 
S
a
m
e
 
a
s
 
b
u
i
l
t
.
 
H
o
w
e
v
e
r
,
 
w
i
t
h
 
a
d
j
u
s
t
e
d
 
s
e
t
t
i
n
g
s
,
 
i
t
 
p
r
o
v
i
d
e
s
 
a
 
d
e
s
i
g
n
e
d
 
p
e
r
f
o
r
m
a
n
c
e
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
H
o
w
 
d
o
e
s
 
i
t
 
d
e
f
i
n
e
 
c
o
m
m
i
s
s
i
o
n
i
n
g
 
s
i
m
u
l
a
t
i
o
n
s
?
W
h
a
t
 
c
o
n
s
i
s
t
s
 
a
n
 
a
c
c
e
l
e
r
a
t
o
r
?
 
P
y
t
h
o
n
 
l
i
b
r
a
r
y
 
f
o
r
 
c
o
m
m
i
s
s
i
o
n
i
n
g
 
b
e
i
n
g
 
d
e
v
e
l
o
p
e
d
 
A
d
v
a
n
c
i
n
g
 
c
o
r
r
e
c
t
i
o
n
 
m
e
t
h
o
d
s
Implementing robust methods for the typically
skipped steps in the commissioning chain
Trajectory BBA, RF-setup
New features
Charge-scaled BPM noise, error propagation
 
 
 
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
 
 
B
o
t
t
o
m
-
u
p
 
a
p
p
r
o
a
c
h
Focus (temporarily) on single cases and fixing them
Advancing incrementally from the (commissioning)
start to its end
 
 
C
o
l
l
a
b
o
r
a
t
i
o
n
 
w
i
t
h
 
E
S
R
F
 
(
E
U
R
I
Z
O
N
 
p
r
o
j
e
c
t
)
 
a
n
d
 
L
B
N
L
W
r
i
t
t
e
n
 
i
n
 
P
y
t
h
o
n
 
a
n
d
 
p
y
A
T
 
f
o
r
 
b
e
a
m
 
d
y
n
a
m
i
c
s
Python-based solutions gain momentum and user base
Translated the SC library with the help of AI
Improved the code maintainability and test coverage
undefined
 
C
h
a
t
G
P
T
-
a
i
d
e
d
 
t
r
a
n
s
l
a
t
i
o
n
 
Creating a project stub
Raw conversion by ChatGPT (Engine: code-davinci-002)
Python API or browser-based
Quotas and lower quality with distance in the text
Stripping off comments
Fix problems and “stitch” together manually
Method signatures, implicit definitions, etc
Create reasonable data structures, write type hints
Making everything run, producing correct results
Write automated tests
 
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
 
 
T
r
a
n
s
l
a
t
i
o
n
 
w
o
r
k
f
l
o
w
 
m
a
d
e
 
m
o
r
e
 
e
f
f
i
c
i
e
n
t
 
 
 
 
 
 
 
 
 
 
Run on all SC Matlab files
 A bigger part of the SC was roughly translated within an hour!
 
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
 
P
y
t
h
o
n
 
A
P
I
 
C
h
a
t
G
P
T
 
h
e
l
p
e
d
 
t
o
 
t
r
a
n
s
l
a
t
e
 
S
C
def 
remove_comments_in_file
(ffile: 
str
, 
source_dir: 
str 
= 
""
) -> 
str
:
    
with 
open
(
f"
{
source_dir
}{
ffile
}
"
, 
"r"
) 
as 
mfile:
        lines = mfile.readlines()
    new_lines = [l.replace(
"
\t
"
, 
"    "
).strip(
"
\n
"
) 
for 
l 
in 
lines 
if not 
l.strip().strip(
"
\t
"
).startswith(
"%"
)]
    new_lines = [l 
for 
l 
in 
new_lines 
if 
l.strip(
" 
\t\n
"
)]
    
return 
"
\n
"
.join(new_lines)
def 
matlab_to_python
(matlab_code: 
str
, 
python_start: 
str 
= 
""
) -> 
str
:
    intro = 
"# Convert this from Matlab to Python:
\n
# Matlab version 
\n\n
"
    
ending = 
"
\n
# End
\n
# Python version
\n\n
    prompt = intro + matlab_code + ending + python_start
    response = openai.Completion.create(
model
=
"code-davinci-002"
, 
temperature
=
0
, 
top_p
=
1
,
frequency_penalty
=
0
,
                                        
presence_penalty
=
0
, 
max_tokens
=
len
(prompt)
, 
stop
=[intro[:
20
]]
, 
prompt
=prompt)
    
return 
python_start + response.choices[
0
].text
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
B
r
o
w
s
e
r
-
b
a
s
e
d
 
t
r
a
n
s
l
a
t
i
o
n
C
h
a
t
G
P
T
 
h
e
l
p
e
d
 
t
o
 
t
r
a
n
s
l
a
t
e
 
S
C
undefined
 
P
y
t
h
o
n
 
l
i
b
r
a
r
y
 
c
o
n
t
e
n
t
s
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
 
C
o
m
m
i
s
s
i
o
n
i
n
g
 
s
i
m
u
l
a
t
i
o
n
 
l
i
b
r
a
r
y
:
 
G
e
n
e
r
a
l
 
w
o
r
k
f
l
o
w
pyAT Lattice
Uncertainties
S
e
t
t
i
n
g
s
 
i
n
t
e
r
f
a
c
e
Adds errors to
ideal setpoints
B
P
M
 
r
e
a
d
i
n
g
Adds errors to
tracking data
S
i
m
u
l
a
t
e
d
C
o
m
m
i
s
s
i
o
n
i
n
g
 
c
l
a
s
s
Ideal lattice
Uncertainties data
R
e
a
l
i
s
t
i
c
 
l
a
t
t
i
c
e
H
i
g
h
-
l
e
v
e
l
 
m
e
t
h
o
d
s
Moddeling
Trajectory
Orbit
BBA
RF setup
P
h
y
s
i
c
a
l
m
a
c
h
i
n
e
 
E
r
r
o
r
 
s
o
u
r
c
e
s
 
i
n
c
l
u
d
e
d
 
B
P
M
 
E
r
r
o
r
s
:
BPM offsets (3D)
BPM noise (CO, TBT)
BPM roll (1D)
BPM calibration
M
a
g
n
e
t
 
E
r
r
o
r
s
:
Magnet offsets (3D)
Magnet rolls (3D)
Magnet calibration (strength)
Multipole errors (offsets and calibration)
R
i
n
g
 
c
i
r
c
u
m
f
e
r
e
n
c
e
 
e
r
r
o
r
 
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
 
 
S
u
p
p
o
r
t
 
s
t
r
u
c
t
u
r
e
s
 
(
3
 
s
t
a
c
k
a
b
l
e
 
t
y
p
e
s
)
:
Offsets (3D)
Rolls (3D)
R
F
 
e
r
r
o
r
s
:
RF phase
RF frequency
RF Voltage
I
n
j
e
c
t
i
o
n
 
e
r
r
o
r
s
:
Static errors (6D)
Jitter (6D)
M
e
t
h
o
d
s
 
c
h
a
i
n
e
d
 
i
n
 
c
o
m
m
i
s
s
i
o
n
i
n
g
 
s
i
m
u
l
a
t
i
o
n
:
 
P
E
T
R
A
 
I
V
 
First turn steering
Trajectory BBA
Multipole ramp-up
RF setup
Tune scan
Orbit BBA
Orbit correction
Tune correction
Optics correction (LOCO and TBT)
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
 
Done
Done
Done
Done
Done
Done
In progress
 
Dynamic Aperture
 
W
h
e
r
e
 
t
o
 
f
i
n
d
 
i
t
?
 
 
P
u
b
l
i
c
 
r
e
p
o
s
i
t
o
r
y
 
o
n
 
G
i
t
H
u
b
https://github.com/lmalina/pySC
https://lmalina.github.io/pySC/
 
S
o
o
n
 
t
o
 
b
e
 
r
e
l
e
a
s
e
d
 
o
n
 
P
y
P
I
With a possible name change
 
I
C
A
L
E
P
C
S
 
2
3
 
c
o
n
f
e
r
e
n
c
e
 
(
n
e
x
t
 
w
e
e
k
)
L. Malina et al., “Python library for simulated
commissioning of storage-ring accelerators”
 
 
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
 
 
Commissioning simulations are an indispensable part of the design accelerator
Presented a Python library to facilitate the task
Started as a translation from Matlab (SC toolkit)
We are approaching the first (alpha) release
 
 
 
Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al.
 
 
C
o
n
c
l
u
s
i
o
n
s
 
a
n
d
 
p
l
a
n
s
undefined
 
Luk
áš
 Malina
Lukas.malina@desy.de
+49 40 8998 
5475
 
Thank you for your attention
Slide Note
Embed
Share

This workshop presented by Lukas Malina introduces a Python library for simulated commissioning of synchrotrons, focusing on commissioning simulations using AI translation from Matlab. The Python library aims to replicate machines with random errors, provide correction methods, and enhance performance analysis in accelerator commissioning. Collaboration with ESRF and LBNL has led to the development of robust correction methods and new features like charge-scaled BPM noise. The bottom-up approach and incremental advancements in correction methods are emphasized, aiming to improve the efficiency of the commissioning process.


Uploaded on May 13, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Python library for simulated commissioning of synchrotrons Accelerator Toolbox Workshop Luk Malina On behalf of: Thorsten Hellert, Simone Liuzzo, Lina Hoummi, Bianca Veglia, and Elaf Musa Grenoble, October 2nd, 2023

  2. Outline Commissioning simulations and/in Python Translation from Matlab with the help of AI Contents of the Python library DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 2

  3. What consists an accelerator? How does it define commissioning simulations? Designed: Groups of perfect and identical elements which are perfectly aligned Specify (realistic) tolerances on the components themselves and their alignment Can we pass from Built to Operational? -> Commissioning simulations Store and interface errors, which are different for each single element Provide high-level correction methods and separated performance analysis Replicate many machines with all sorts of random errors (given the tolerances) Built: Neither perfect nor identical elements, which feature residual misalignments Does not work! Need to commission, i.e. adjust settings using beam as a diagnostics tool Single replication with errors -> Commissioning simulation with only changed interface Operational: Same as built. However, with adjusted settings, it provides a designed performance DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 3

  4. Python library for commissioning being developed Collaboration with ESRF (EURIZON project) and LBNL Written in Python and pyAT for beam dynamics Python-based solutions gain momentum and user base Translated the SC library with the help of AI Improved the code maintainability and test coverage Advancing correction methods Bottom-up approach Implementing robust methods for the typically skipped steps in the commissioning chain Focus (temporarily) on single cases and fixing them Advancing incrementally from the (commissioning) start to its end Trajectory BBA, RF-setup New features Charge-scaled BPM noise, error propagation DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 4

  5. ChatGPT-aided translation

  6. Translation workflow made more efficient Creating a project stub Raw conversion by ChatGPT (Engine: code-davinci-002) Python API or browser-based Quotas and lower quality with distance in the text Stripping off comments Fix problems and stitch together manually Method signatures, implicit definitions, etc Create reasonable data structures, write type hints Making everything run, producing correct results Write automated tests DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 6

  7. ChatGPT helped to translate SC Python API def remove_comments_in_file(ffile: str, source_dir: str = "") -> str: with open(f"{source_dir}{ffile}", "r") as mfile: lines = mfile.readlines() new_lines = [l.replace("\t", " ").strip("\n") for l in lines if not l.strip().strip("\t").startswith("%")] new_lines = [l for l in new_lines if l.strip(" \t\n")] return "\n".join(new_lines) def matlab_to_python(matlab_code: str, python_start: str = "") -> str: intro = "# Convert this from Matlab to Python:\n# Matlab version \n\n" ending = "\n# End\n# Python version\n\n prompt = intro + matlab_code + ending + python_start response = openai.Completion.create(model="code-davinci-002", temperature=0, top_p=1, frequency_penalty=0, presence_penalty=0, max_tokens=len(prompt), stop=[intro[:20]], prompt=prompt) return python_start + response.choices[0].text Run on all SC Matlab files A bigger part of the SC was roughly translated within an hour! DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 7

  8. ChatGPT helped to translate SC Browser-based translation DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 8

  9. Python library contents

  10. Commissioning simulation library: General workflow SimulatedCommissioning class High-level methods Ideal lattice pyAT Lattice Moddeling Settings interface Adds errors to ideal setpoints Uncertainties data Physical Uncertainties Trajectory Orbit BBA RF setup Realistic lattice machine BPM reading Adds errors to tracking data DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 10

  11. Error sources included BPM Errors: Support structures (3 stackable types): BPM offsets (3D) Offsets (3D) BPM noise (CO, TBT) Rolls (3D) BPM roll (1D) RF errors: BPM calibration RF phase RF frequency Magnet Errors: Magnet offsets (3D) RF Voltage Magnet rolls (3D) Injection errors: Magnet calibration (strength) Static errors (6D) Multipole errors (offsets and calibration) Jitter (6D) Ring circumference error DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 11

  12. Methods chained in commissioning simulation: PETRA IV First turn steering Done Done Trajectory BBA Multipole ramp-up Done RF setup Done Tune scan Done Orbit BBA Dynamic Aperture Orbit correction Done Tune correction Optics correction (LOCO and TBT) DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 12

  13. Where to find it? Public repository on GitHub https://github.com/lmalina/pySC https://lmalina.github.io/pySC/ Soon to be released on PyPI With a possible name change ICALEPCS 23 conference (next week) L. Malina et al., Python library for simulated commissioning of storage-ring accelerators DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 13

  14. Conclusions and plans Commissioning simulations are an indispensable part of the design accelerator Presented a Python library to facilitate the task Started as a translation from Matlab (SC toolkit) We are approaching the first (alpha) release DESY. | Accelerator Toolbox Workshop | Python library for simulated commissionning of synchrotrons | Lukas Malina et al. Page 14

  15. Thank Thankyou youfor foryour yourattention attention Contact Contact Luk Malina Lukas.malina@desy.de +49 40 8998 5475 DESY. Deutsches Elektronen-Synchrotron www.desy.de

Related


More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#