Skip to content

Commit 95c6b0f

Browse files
committed
🚨 modifications from pre-commit run --all-files
1 parent 5691c0e commit 95c6b0f

36 files changed

Lines changed: 1352 additions & 902 deletions

.github/workflows/manual_tests_CPU.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,3 @@ jobs:
3737
- name: Run pytest
3838
run: |
3939
python -m pytest --cov=bihc --cov-report=term-missing -vv
40-
41-

.github/workflows/nightly_tests_CPU_p3.11.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ jobs:
3737
- name: Run pytest
3838
run: |
3939
python -m pytest --cov=bihc --cov-report=term-missing -vv
40-

.github/workflows/nightly_tests_CPU_p3.12.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ jobs:
3737
- name: Run pytest
3838
run: |
3939
python -m pytest --cov=bihc --cov-report=term-missing -vv
40-

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ jobs:
5959
- name: Publish to PyPI
6060
uses: pypa/gh-action-pypi-publish@release/v1
6161
with:
62-
verbose: true
62+
verbose: true

.github/workflows/publish_to_testPyPI.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ jobs:
111111
uses: pypa/gh-action-pypi-publish@release/v1
112112
with:
113113
repository-url: https://test.pypi.org/legacy/
114-
verbose: true
114+
verbose: true

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ sphinx:
3232
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
3333
python:
3434
install:
35-
- requirements: docs/requirements.txt
35+
- requirements: docs/requirements.txt

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors:
88
given-names: "Leonardo"
99
orcid: "https://orcid.org/0000-0002-1405-2739"
1010
title: "BIHC"
11-
version: 0.0.8.10
12-
doi:
11+
version: 0.0.8.10
12+
doi:
1313
date-released: 01-01-2025
1414
url: "https://github.com/ImpedanCEI/BIHC"

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ include pyproject.toml
44
include *.md
55

66
# Include the license file
7-
include LICENSE.txt
7+
include LICENSE.txt

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For specific needs, please contact the maintainers :woman_technologist: :man_tec
2020
There is a [paper about `bihc`](10.18429/JACoW-HB2023-THBP52), presented at 8th ICFA Advanced Beam Dynamics Workshop on High-Intensity and High-Brightness Hadron Beam (0ct. 2023).
2121
If you are using `bihc` in your scientific research, please help our scientific
2222
visibility by citing our work:
23-
> [1] E. de la Fuente, L. Sito, F. Giordano, G. Rumolo, B. Salvant, and C. Zannini, “A Python Package to Compute Beam-Induced Heating in Particle Accelerators and Applications,” JACoW, vol. HB2023, pp. 611–614, 2024, doi: [https://doi.10.18429/JACoW-HB2023-THBP52](https://jacow.org/hb2023/papers/thbp52.pdf).
23+
> [1] E. de la Fuente, L. Sito, F. Giordano, G. Rumolo, B. Salvant, and C. Zannini, “A Python Package to Compute Beam-Induced Heating in Particle Accelerators and Applications,” JACoW, vol. HB2023, pp. 611–614, 2024, doi: [https://doi.10.18429/JACoW-HB2023-THBP52](https://jacow.org/hb2023/papers/thbp52.pdf).
2424
2525
Bibtex:
2626
```
@@ -34,28 +34,28 @@ Bibtex:
3434
year = "2024"
3535
}
3636
```
37-
:mag_right: About `bihc` python package
37+
:mag_right: About `bihc` python package
3838
---
3939

40-
`bihc` is a computational package that integrates over a decade of experience in beam-induced heating calculations from the Impedance and Coherent Effects Section (see [^1], [^3], [^4], [^5], [^6], [^7]) into a comprehensive and flexible Python-based tool.
40+
`bihc` is a computational package that integrates over a decade of experience in beam-induced heating calculations from the Impedance and Coherent Effects Section (see [^1], [^3], [^4], [^5], [^6], [^7]) into a comprehensive and flexible Python-based tool.
4141

4242
The package has been presented at the 68th ICFA Advanced Beam Dynamics Workshop on High-Intensity and High-Brightness Hadron Beam (0ct. 2023)[^8], and is under continuous development to face the beam-induce heating challenges that become more relevant as the beam total intensity and bunch length is pushed.
4343

4444
`bihc` has been succesfully employed to assess the mitigation strategy for the CERN-SPS Beam Wire Scanners after the wire failure in 2023, and was extensively used to study the CERN-LHC Warm Vacuum modules limitations in intensity and bunch length for the 2024 run.
4545

46-
[^1]: B. Salvant et al., “Beam induced heating”, 2012, [Online]. Available: https://cds.cern.ch/record/1975499
46+
[^1]: B. Salvant et al., “Beam induced heating”, 2012, [Online]. Available: https://cds.cern.ch/record/1975499
4747

48-
[^3]: C. Zannini, et al. "Power Loss Calculation in Separated and Common Beam Chambers of the LHC". Proceedings of the 5th Int. Particle Accelerator Conf., vol. IPAC2014, 2014, p. 3 pages, 1.928 MB. DOI.org (Datacite), https://doi.org/10.18429/JACOW-IPAC2014-TUPRI061.
48+
[^3]: C. Zannini, et al. "Power Loss Calculation in Separated and Common Beam Chambers of the LHC". Proceedings of the 5th Int. Particle Accelerator Conf., vol. IPAC2014, 2014, p. 3 pages, 1.928 MB. DOI.org (Datacite), https://doi.org/10.18429/JACOW-IPAC2014-TUPRI061.
4949

50-
[^4]: C. Zannini, "Electromagnetic Simulation of CERN accelerator Components and Experimental Applications", 2013. [Online]. Available: https://cds.cern.ch/record/1561199
50+
[^4]: C. Zannini, "Electromagnetic Simulation of CERN accelerator Components and Experimental Applications", 2013. [Online]. Available: https://cds.cern.ch/record/1561199
5151

52-
[^5]: C. Zannini, “Multiphysics Simulations of Impedance Effects in Accelerators,” CERN Yellow Rep. Conf. Proc., vol. 1, pp. 141–144, 2018, doi: 10.23732/CYRCP-2018-001.141.
52+
[^5]: C. Zannini, “Multiphysics Simulations of Impedance Effects in Accelerators,” CERN Yellow Rep. Conf. Proc., vol. 1, pp. 141–144, 2018, doi: 10.23732/CYRCP-2018-001.141.
5353

5454
[^6]: G. Rumolo, “Beam Instabilities”, 21 pages contribution to the CAS - CERN Accelerator School: Advanced Accelerator Physics Course, Trondheim, Norway, 2014, doi: 10.5170/CERN-2014-009.199. Available; https://cds.cern.ch/record/1982422
5555

5656
[^7]: F. Giordano, ‘Simulation Analysis and Machine Learning Based Detection of Beam-Induced Heating in Particle Accelerator at CERN’, University of Naples Federico II, 2020.
5757

58-
[^8]: L. Sito, E. de la Fuente, F. Giordano, G. Rumolo, B. Salvant, and C. Zannini, “A Python Package to Compute Beam-Induced Heating in Particle Accelerators and Applications,” in Proc. 68th Adv. Beam Dyn. Workshop High-Intensity High-Brightness Hadron Beams (HB’23), Geneva, Switzerland, Apr. 2024, no. 68, pp. 611–614. doi: 10.18429/JACoW-HB2023-THBP52.
58+
[^8]: L. Sito, E. de la Fuente, F. Giordano, G. Rumolo, B. Salvant, and C. Zannini, “A Python Package to Compute Beam-Induced Heating in Particle Accelerators and Applications,” in Proc. 68th Adv. Beam Dyn. Workshop High-Intensity High-Brightness Hadron Beams (HB’23), Geneva, Switzerland, Apr. 2024, no. 68, pp. 611–614. doi: 10.18429/JACoW-HB2023-THBP52.
5959

6060
## :zap: Installation
6161
This section explains how to set up the environment to start using BIHC package for power loss computations.
@@ -72,7 +72,7 @@ git clone git@github.com:ImpedanCEI/BIHC.git
7272
git clone https://github.com/ImpedanCEI/BIHC.git
7373
```
7474

75-
#### Users: pip install
75+
#### Users: pip install
7676
```
7777
pip install bihc
7878
```
@@ -89,10 +89,10 @@ In your /user or /work directory, do:
8989
# If miniconda is not installed
9090
# Get, install and activate miniconda
9191
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
92-
bash Miniconda3-latest-Linux-x86_64.sh
92+
bash Miniconda3-latest-Linux-x86_64.sh
9393
source miniconda3/bin/activate
9494
95-
# Get standard packages
95+
# Get standard packages
9696
# (to have all spark functionalities pandas needs to be installed before pytimber)
9797
pip install numpy scipy matplotlib ipython pandas
9898
@@ -105,11 +105,11 @@ pip install pytimber
105105
# Change python package index back to default
106106
pip uninstall acc-py-pip-config
107107
```
108-
Test the installation with
108+
Test the installation with
109109
```
110110
$ ipython
111111
import pytimber
112-
ldb = pytimber.LoggingDB(source="nxcals")
112+
ldb = pytimber.LoggingDB(source="nxcals")
113113
ldb.search('LHC%BEAM_ENERGY%')
114114
ldb.get(ldb.search('LHC%BEAM_ENERGY%')[0], t1='2022-06-15 15:10:30.0000')
115115
```
@@ -120,4 +120,3 @@ ldb.get(ldb.search('LHC%BEAM_ENERGY%')[0], t1='2022-06-15 15:10:30.0000')
120120
[![nightly_tests_CPU_py3.12](https://github.com/ImpedanCEI/BIHC/actions/workflows/nightly_tests_CPU_p3.12.yml/badge.svg)](https://github.com/ImpedanCEI/BIHC/actions/workflows/nightly_tests_CPU_p3.12.yml)
121121
[![nightly_tests_CPU_py3.13](https://github.com/ImpedanCEI/BIHC/actions/workflows/nightly_tests_CPU_p3.13.yml/badge.svg)](https://github.com/ImpedanCEI/BIHC/actions/workflows/nightly_tests_CPU_p3.13.yml)
122122
[![nightly_tests_CPU_py3.14](https://github.com/ImpedanCEI/BIHC/actions/workflows/nightly_tests_CPU_p3.14.yml/badge.svg)](https://github.com/ImpedanCEI/BIHC/actions/workflows/nightly_tests_CPU_p3.14.yml)
123-

bihc/beam.py

Lines changed: 30 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def __init__(
116116
exp=2.5,
117117
verbose=False,
118118
):
119-
120119
self.M = M # Default max numebr of buckets
121120
self.A_GLOBAL = A
122121
self.BUNCH_LENGTH_GLOBAL = bunchLength / 4 # Bunch lenght (sigma) [s]
@@ -130,7 +129,9 @@ def __init__(
130129
self.exp = exp
131130
self.J = 1
132131
self.fillMode = fillMode
133-
self._fillNumber = fillNumber # Fill number relative to a particular fill of the machine
132+
self._fillNumber = (
133+
fillNumber # Fill number relative to a particular fill of the machine
134+
)
134135

135136
self._isSpectrumReady = False
136137
self.isATimberFill = False
@@ -292,9 +293,7 @@ def spectrum(self):
292293
"! When using spectrum == 'user', set the spectrum data via:\n \
293294
>>> beam.setSpectrum(newSpectrum)\n"
294295
)
295-
return (
296-
self._spectrum
297-
) # spectrum must be provided through the setter
296+
return self._spectrum # spectrum must be provided through the setter
298297

299298
else:
300299
if self._spectrumtype == "numeric":
@@ -342,41 +341,31 @@ def spectrum(self):
342341
)
343342

344343
elif self._bunchShape == "GAUSSIAN":
345-
for p in progressbar(
346-
range(len(S)), "Computing analytic FFT: ", 20
347-
):
344+
for p in progressbar(range(len(S)), "Computing analytic FFT: ", 20):
348345
lambdas[p] = np.exp(
349-
-(p * p * wrev * wrev * sigma * sigma)
350-
/ (2 * c * c)
346+
-(p * p * wrev * wrev * sigma * sigma) / (2 * c * c)
351347
)
352348
S[p] = np.abs(
353-
A
354-
* lambdas[p]
355-
* np.sum(an * np.exp(1j * p * wrev * n * t0))
349+
A * lambdas[p] * np.sum(an * np.exp(1j * p * wrev * n * t0))
356350
)
357351

358352
elif self._bunchShape == "COS2":
359353
for p in progressbar(
360354
range(1, len(S)), "Computing analytic FFT: ", 20
361355
): # TODO fix
362-
Fc = (
363-
(F**2) * (sigmacos**2) * ((p * wrev) ** 2) / (c**2)
364-
)
356+
Fc = (F**2) * (sigmacos**2) * ((p * wrev) ** 2) / (c**2)
365357
lambdas[p] = (
366358
-1.14
367359
* np.sqrt(2 * np.pi)
368360
/ np.pi
369361
/ (sigmacos * p * wrev / c * (-2 + Fc))
370362
* (np.sqrt(2 / np.pi))
371363
* np.sin(
372-
(np.pi * sigmacos * p * wrev * F)
373-
/ (np.sqrt(2) * c)
364+
(np.pi * sigmacos * p * wrev * F) / (np.sqrt(2) * c)
374365
)
375366
)
376367
S[p] = np.abs(
377-
A
378-
* lambdas[p]
379-
* np.sum(an * np.exp(1j * p * wrev * n * t0))
368+
A * lambdas[p] * np.sum(an * np.exp(1j * p * wrev * n * t0))
380369
)
381370

382371
elif self._bunchShape == "PARABOLIC":
@@ -389,17 +378,11 @@ def spectrum(self):
389378
lambdas[p] = (
390379
-3
391380
* c**3
392-
/ (
393-
(np.sqrt(5) ** 3)
394-
* (sigmapar**3)
395-
* (p * wrev) ** 3
396-
)
381+
/ ((np.sqrt(5) ** 3) * (sigmapar**3) * (p * wrev) ** 3)
397382
* CosSin
398383
)
399384
S[p] = np.abs(
400-
A
401-
* lambdas[p]
402-
* np.sum(an * np.exp(1j * p * wrev * n * t0))
385+
A * lambdas[p] * np.sum(an * np.exp(1j * p * wrev * n * t0))
403386
)
404387

405388
f = (
@@ -475,10 +458,7 @@ def _setBunches(self):
475458
self.filledSlots += 1 # TODO: how to match the bunch length
476459
if self._bunchShape == "BINOMIAL":
477460
lambda_0 = (2 * gamma(1.5 + self.exp)) / (
478-
(
479-
self._bunchLength[i]
480-
* (2 * np.sqrt(3 + 2 * self.exp))
481-
)
461+
(self._bunchLength[i] * (2 * np.sqrt(3 + 2 * self.exp)))
482462
* np.sqrt(np.pi)
483463
* gamma(1 + self.exp)
484464
) # normalization factor
@@ -487,10 +467,7 @@ def _setBunches(self):
487467
- 4
488468
* (
489469
(tTemp - self.phi[i])
490-
/ (
491-
self._bunchLength[i]
492-
* (2 * np.sqrt(3 + 2 * self.exp))
493-
)
470+
/ (self._bunchLength[i] * (2 * np.sqrt(3 + 2 * self.exp)))
494471
)
495472
** 2
496473
) # Binomial definition from RF-BR
@@ -529,10 +506,7 @@ def _setBunches(self):
529506
elif self._bunchShape == "COS2":
530507
tc = self._bunchLength[i] * 2.77 # 4*0.854
531508
sTemp = (
532-
1
533-
/ tc
534-
* (np.cos(np.pi * (tTemp - self.phi[i]) / (2 * tc)))
535-
** 2
509+
1 / tc * (np.cos(np.pi * (tTemp - self.phi[i]) / (2 * tc))) ** 2
536510
) # cos^2 function
537511
mask = (np.abs(tTemp - self.phi[i])) < self.l
538512
mask2 = abs(tTemp) < tc
@@ -544,10 +518,7 @@ def _setBunches(self):
544518
# sTemp=(1-(1/(4*0.744653*self._bunchLength[i]**2))*(tTemp- self.phi[i])**2) #Parabolic function
545519
self.exp = 1
546520
lambda_0 = (2 * gamma(1.5 + self.exp)) / (
547-
(
548-
self._bunchLength[i]
549-
* (2 * np.sqrt(3 + 2 * self.exp))
550-
)
521+
(self._bunchLength[i] * (2 * np.sqrt(3 + 2 * self.exp)))
551522
* np.sqrt(np.pi)
552523
* gamma(1 + self.exp)
553524
) # normalization factor
@@ -556,15 +527,10 @@ def _setBunches(self):
556527
- 4
557528
* (
558529
(tTemp - self.phi[i])
559-
/ (
560-
self._bunchLength[i]
561-
* (2 * np.sqrt(3 + 2 * self.exp))
562-
)
530+
/ (self._bunchLength[i] * (2 * np.sqrt(3 + 2 * self.exp)))
563531
)
564532
** 2
565-
) ** (
566-
self.exp
567-
) # Parabolic definition, same as Binomial with exp=1
533+
) ** (self.exp) # Parabolic definition, same as Binomial with exp=1
568534
mask = (np.abs(tTemp - self.phi[i])) < self.l
569535
mask2 = sTemp > 0
570536
sTemp = sTemp * mask * mask2
@@ -586,8 +552,7 @@ def _Cq(q):
586552
return np.sqrt(np.pi)
587553
elif q >= 1.005827 and q < 3.0:
588554
return (
589-
np.sqrt(np.pi)
590-
* Gamma((3.0 - q) / 2.0 / (q - 1.0))
555+
np.sqrt(np.pi) * Gamma((3.0 - q) / 2.0 / (q - 1.0))
591556
) / (np.sqrt(q - 1.0) * Gamma(1.0 / (q - 1.0)))
592557
else:
593558
raise Exception("q>3.0")
@@ -607,9 +572,7 @@ def _eq(x, q):
607572
q = self.q # [TODO] pass 1 q-val per bunch
608573
b = 1 / ((self._bunchLength[i] ** 2) * (5 - 3 * q))
609574
mu = self.phi[i]
610-
sTemp = (
611-
np.sqrt(b) / _Cq(q) * _eq(-b * (tTemp - mu) ** 2, q)
612-
)
575+
sTemp = np.sqrt(b) / _Cq(q) * _eq(-b * (tTemp - mu) ** 2, q)
613576

614577
mask = (np.abs(tTemp - self.phi[i])) < self.l
615578
mask2 = sTemp > 0
@@ -640,9 +603,7 @@ def _eq(x, q):
640603
t = np.linspace(np.min(tn), np.max(tn), len(s))
641604

642605
self.totalBeamCharge = self.Np * e * self.filledSlots
643-
if (
644-
self.Np_arr is not None
645-
): # weigth the longitudinal profile amplitudes
606+
if self.Np_arr is not None: # weigth the longitudinal profile amplitudes
646607
for i, Npi in enumerate(self.Np_arr):
647608
s[i * self.ppbk : (i + 1) * self.ppbk] = (
648609
s[i * self.ppbk : (i + 1) * self.ppbk] * Npi / self.Np
@@ -668,9 +629,7 @@ def _eq(x, q):
668629
self.profile_1_bunch = profile_1_bunch
669630
self.longitudinalProfile = [t, s]
670631

671-
def setBeamFromFillNumber(
672-
self, fillNumber, fillMode="FLATTOP", beamNumber=1
673-
):
632+
def setBeamFromFillNumber(self, fillNumber, fillMode="FLATTOP", beamNumber=1):
674633
"""Set beam from fill number
675634
676635
Retrieves beam fill information from Timber provided a fill Number
@@ -776,15 +735,9 @@ def setBeamFromFillNumber(
776735

777736
self._bunchLength = self._bunchLength[0 : self.M]
778737
if self.verbose:
779-
print(
780-
f"Avg. bunch length off all bunches: {np.mean(self._bunchLength)}"
781-
)
782-
print(
783-
f"Max. bunch length off all bunches: {np.max(self._bunchLength)}"
784-
)
785-
print(
786-
f"Min. bunch length off all bunches: {np.min(self._bunchLength)}"
787-
)
738+
print(f"Avg. bunch length off all bunches: {np.mean(self._bunchLength)}")
739+
print(f"Max. bunch length off all bunches: {np.max(self._bunchLength)}")
740+
print(f"Min. bunch length off all bunches: {np.min(self._bunchLength)}")
788741

789742
self.phi = self.phi[0 : self.M]
790743
self.setNpFromFillNumber()
@@ -850,9 +803,9 @@ def setBeamFromLPC(self):
850803

851804
if start_line:
852805
try:
853-
self._fillingScheme[
854-
int((int(row[0]) - 1) / 10)
855-
] = True # we take beam one
806+
self._fillingScheme[int((int(row[0]) - 1) / 10)] = (
807+
True # we take beam one
808+
)
856809
except Exception:
857810
break
858811

@@ -877,16 +830,12 @@ def setCustomBeamWithFillingScheme(self):
877830
)
878831
elif len(self._fillingScheme) < self.M:
879832
padding = [False] * (self.M - len(self._fillingScheme))
880-
self._fillingScheme = np.concatenate(
881-
(self._fillingScheme, padding), axis=0
882-
)
833+
self._fillingScheme = np.concatenate((self._fillingScheme, padding), axis=0)
883834

884835
self._bunchLength = np.zeros(
885836
self.M
886837
) # std vector of a single turn in the machine
887-
self.A = np.zeros(
888-
self.M
889-
) # amplitude vector of a single turn in the machine
838+
self.A = np.zeros(self.M) # amplitude vector of a single turn in the machine
890839
self.phi = np.zeros(self.M)
891840
for j in range(self.M):
892841
if self._fillingScheme[j]:

0 commit comments

Comments
 (0)