Skip to content

Commit 1fcc51a

Browse files
authored
Merge branch 'atcollab:master' into master
2 parents 23f9bd3 + f4554a9 commit 1fcc51a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1634
-1096
lines changed

.github/workflows/build-python-wheels.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ${{ matrix.os }}
1414
strategy:
1515
matrix:
16-
os: [ubuntu-20.04, macos-12, windows-2022]
16+
os: [ubuntu-22.04, macos-12, windows-2022]
1717

1818
steps:
1919
- uses: actions/checkout@v4
@@ -23,12 +23,12 @@ jobs:
2323
fetch-depth: 0
2424

2525
- name: Install Python
26-
uses: actions/setup-python@v4
26+
uses: actions/setup-python@v5
2727
with:
2828
python-version: '3.9'
2929

3030
- name: Build wheels
31-
uses: pypa/[email protected].0
31+
uses: pypa/[email protected].2
3232

3333
- name: Upload wheels
3434
uses: actions/upload-artifact@v3
@@ -38,7 +38,7 @@ jobs:
3838
if-no-files-found: error
3939

4040
build_sdist:
41-
runs-on: ubuntu-20.04
41+
runs-on: ubuntu-22.04
4242

4343
steps:
4444
- uses: actions/checkout@v4
@@ -48,7 +48,7 @@ jobs:
4848
fetch-depth: 0
4949

5050
- name: Install Python
51-
uses: actions/setup-python@v4
51+
uses: actions/setup-python@v5
5252
with:
5353
python-version: '3.9'
5454

.github/workflows/docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ jobs:
2020
fetch-depth: 0
2121

2222
- name: Set up Python
23-
uses: actions/setup-python@v4
23+
uses: actions/setup-python@v5
2424
with:
2525
python-version: 3.9
26+
cache: pip
2627

2728
- name: Build and install at
2829
run: python -m pip install ".[plot, doc]"

.github/workflows/matlab-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ jobs:
2727
- uses: actions/checkout@v4
2828

2929
- name: Set up python 3.9
30-
uses: actions/setup-python@v4
30+
uses: actions/setup-python@v5
3131
with:
3232
python-version: '3.9'
33+
cache: pip
3334

3435
- name: Set up MATLAB
3536
uses: matlab-actions/setup-matlab@v1

.github/workflows/python-tests.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
19+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
2020
os: [macos-latest, ubuntu-latest, windows-latest]
2121
exclude:
2222
- os: windows-latest
@@ -27,9 +27,10 @@ jobs:
2727
- uses: actions/checkout@v4
2828

2929
- name: Set up Python ${{ matrix.python-version }}
30-
uses: actions/setup-python@v4
30+
uses: actions/setup-python@v5
3131
with:
3232
python-version: ${{ matrix.python-version }}
33+
cache: pip
3334

3435
- name: Build and install at with tests
3536
run: python -m pip install -e ".[dev]"
@@ -39,8 +40,8 @@ jobs:
3940
run: |
4041
# stop the build if there are Python syntax errors or undefined names
4142
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
42-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
43-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
43+
# exit-zero treats all errors as warnings. Options compatible with the 'black' code formatter
44+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --extend-ignore=E203,E704 --extend-select=W504 --per-file-ignores='*/__init__.py:F401,F403' --statistics
4445
4546
- name: Test with pytest and coverage
4647
working-directory: pyat

LICENSE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
License pending

_custom_build/backend.py

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from setuptools import build_meta as _orig
1+
"""Implements PEP 517 and PEP 660 hooks for custom build"""
2+
23
import os
34

4-
# Mandatory hooks
5-
build_sdist = _orig.build_sdist
5+
from setuptools import build_meta as _orig
6+
from setuptools.build_meta import * # noqa: F401, F403
67

78

89
def _get_option(config, key, default_value):
@@ -12,30 +13,43 @@ def _get_option(config, key, default_value):
1213
return eval(val)
1314

1415

15-
def build_wheel(wheel_dir, config_settings=None, metadata_dir=None):
16-
print("** Entering build_wheel. "
17-
"Config settings:", config_settings)
18-
os.environ["MPI"] = str(_get_option(config_settings, 'MPI', '0'))
19-
os.environ["OPENMP"] = str(_get_option(config_settings, 'OPENMP', '0'))
20-
omp_threshold = _get_option(config_settings,
21-
'OMP_PARTICLE_THRESHOLD', 'None')
22-
if omp_threshold is not None:
23-
os.environ["OMP_PARTICLE_THRESHOLD"] = str(omp_threshold)
24-
print("** MPI:", os.environ.get('MPI', 'None'))
25-
print("** OPENMP:", os.environ.get('OPENMP', 'None'))
26-
ret = _orig.build_wheel(wheel_dir, config_settings, metadata_dir)
27-
print("** Leaving build_wheel")
28-
return ret
29-
30-
31-
# Optional hook
32-
def get_requires_for_build_wheel(config_settings=None):
33-
print("** Entering get_requires_for_build_wheel. "
34-
"Config settings:", config_settings)
35-
mpi = _get_option(config_settings, 'MPI', '0')
36-
print("** MPI:", mpi)
37-
addlist = ["mpi4py"] if mpi else []
38-
print("** Additional modules:", addlist)
39-
ret = _orig.get_requires_for_build_wheel(config_settings) + addlist
40-
print("** Leaving get_requires_for_build_wheel")
41-
return ret
16+
def _set_environ(func):
17+
"""Set environment for building according to config"""
18+
19+
def build(wheel_dir, config_settings=None, metadata_dir=None):
20+
print("** Entering set_environ. " "Config settings:", config_settings)
21+
os.environ["MPI"] = str(_get_option(config_settings, "MPI", "0"))
22+
os.environ["OPENMP"] = str(_get_option(config_settings, "OPENMP", "0"))
23+
omp_threshold = _get_option(config_settings, "OMP_PARTICLE_THRESHOLD", "None")
24+
if omp_threshold is not None:
25+
os.environ["OMP_PARTICLE_THRESHOLD"] = str(omp_threshold)
26+
print("** MPI:", os.environ.get("MPI", "None"))
27+
print("** OPENMP:", os.environ.get("OPENMP", "None"))
28+
ret = func(wheel_dir, config_settings, metadata_dir)
29+
print("** Leaving set_environ")
30+
return ret
31+
32+
return build
33+
34+
35+
def _requirements(func):
36+
"""Add build requirements according to config"""
37+
38+
def get_requires(config_settings=None):
39+
print("** Entering get_requires. Config settings:", config_settings)
40+
mpi = _get_option(config_settings, "MPI", "0")
41+
print("** MPI:", mpi)
42+
addlist = ["mpi4py"] if mpi else []
43+
print("** Additional modules:", addlist)
44+
ret = func(config_settings) + addlist
45+
print("** Leaving get_requires")
46+
return ret
47+
48+
return get_requires
49+
50+
51+
build_wheel = _set_environ(_orig.build_wheel)
52+
build_editable = _set_environ(_orig.build_editable)
53+
54+
get_requires_for_build_wheel = _requirements(_orig.get_requires_for_build_wheel)
55+
get_requires_for_build_editable = _requirements(_orig.get_requires_for_build_editable)

atintegrators/BeamLoadingCavityPass.c

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct elem
1414
int nturnsw;
1515
int blmode;
1616
int cavitymode;
17+
int buffersize;
1718
double normfact;
1819
double phasegain;
1920
double voltgain;
@@ -34,7 +35,16 @@ struct elem
3435
double *vbeam;
3536
double *vcav;
3637
double *vgen;
38+
double *vgen_buffer;
39+
double *vbeam_buffer;
40+
double *vbunch_buffer;
3741
};
42+
43+
44+
void write_buffer(double *data, double *buffer, int datasize, int buffersize){
45+
memmove(buffer, buffer + datasize, datasize*buffersize*sizeof(double));
46+
memcpy(buffer + datasize*(buffersize-1), data, datasize*sizeof(double));
47+
}
3848

3949

4050
void BeamLoadingCavityPass(double *r_in,int num_particles,int nbunch,
@@ -48,6 +58,7 @@ void BeamLoadingCavityPass(double *r_in,int num_particles,int nbunch,
4858
long nslice = Elem->nslice;
4959
long nturnsw = Elem->nturnsw;
5060
long blmode = Elem->blmode;
61+
long buffersize = Elem->buffersize;
5162
double normfact = Elem->normfact;
5263
double le = Elem->Length;
5364
double energy = Elem->Energy;
@@ -58,6 +69,9 @@ void BeamLoadingCavityPass(double *r_in,int num_particles,int nbunch,
5869
double rshunt = Elem->Rshunt;
5970
double beta = Elem->Beta;
6071
double *turnhistory = Elem->turnhistory;
72+
double *vgen_buffer = Elem->vgen_buffer;
73+
double *vbeam_buffer = Elem->vbeam_buffer;
74+
double *vbunch_buffer = Elem->vbunch_buffer;
6175
double *z_cuts = Elem->z_cuts;
6276
double *vbunch = Elem->vbunch;
6377
double phasegain = Elem->phasegain;
@@ -89,7 +103,6 @@ void BeamLoadingCavityPass(double *r_in,int num_particles,int nbunch,
89103
/*Track RF cavity is always done. */
90104
trackRFCavity(r_in,le,vgen/energy,rffreq,harmn,tlag,-psi,nturn,circumference/C0,num_particles);
91105

92-
93106
/*Only allocate memory if current is > 0*/
94107
if(tot_current>0){
95108
void *buffer = atMalloc(sz);
@@ -126,6 +139,11 @@ void BeamLoadingCavityPass(double *r_in,int num_particles,int nbunch,
126139
if(cavitymode==1){
127140
update_vgen(vbeamk,vcavk,vgenk,phasegain,voltgain);
128141
}
142+
if(buffersize>0){
143+
write_buffer(vbeamk, vbeam_buffer, 2, buffersize);
144+
write_buffer(vgenk, vgen_buffer, 2, buffersize);
145+
write_buffer(vbunch, vbunch_buffer, 2*nbunch, buffersize);
146+
}
129147
atFree(buffer);
130148
}
131149
}
@@ -138,10 +156,13 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
138156
double rl = Param->RingLength;
139157
int nturn=Param->nturn;
140158
if (!Elem) {
141-
long nslice,nturns,blmode,cavitymode;
159+
long nslice,nturns,blmode,cavitymode, buffersize;
142160
double wakefact;
143161
double normfact, phasegain, voltgain;
144162
double *turnhistory;
163+
double *vgen_buffer;
164+
double *vbeam_buffer;
165+
double *vbunch_buffer;
145166
double *z_cuts;
146167
double Energy, Frequency, TimeLag, Length;
147168
double qfactor,rshunt,beta;
@@ -160,6 +181,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
160181
nslice=atGetLong(ElemData,"_nslice"); check_error();
161182
nturns=atGetLong(ElemData,"_nturns"); check_error();
162183
blmode=atGetLong(ElemData,"_blmode"); check_error();
184+
buffersize=atGetLong(ElemData,"_buffersize"); check_error();
163185
cavitymode=atGetLong(ElemData,"_cavitymode"); check_error();
164186
wakefact=atGetDouble(ElemData,"_wakefact"); check_error();
165187
qfactor=atGetDouble(ElemData,"Qfactor"); check_error();
@@ -174,6 +196,9 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
174196
vcav=atGetDoubleArray(ElemData,"_vcav"); check_error();
175197
vgen=atGetDoubleArray(ElemData,"_vgen"); check_error();
176198
vbeam_phasor=atGetDoubleArray(ElemData,"_vbeam_phasor"); check_error();
199+
vgen_buffer=atGetDoubleArray(ElemData,"_vgen_buffer"); check_error();
200+
vbeam_buffer=atGetDoubleArray(ElemData,"_vbeam_buffer"); check_error();
201+
vbunch_buffer=atGetDoubleArray(ElemData,"_vbunch_buffer"); check_error();
177202
/*optional attributes*/
178203

179204
z_cuts=atGetOptionalDoubleArray(ElemData,"ZCuts"); check_error();
@@ -207,6 +232,10 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
207232
Elem->voltgain = voltgain;
208233
Elem->vbeam_phasor = vbeam_phasor;
209234
Elem->cavitymode = cavitymode;
235+
Elem->buffersize = buffersize;
236+
Elem->vgen_buffer = vgen_buffer;
237+
Elem->vbeam_buffer = vbeam_buffer;
238+
Elem->vbunch_buffer = vbunch_buffer;
210239
}
211240
if(num_particles<Param->nbunch){
212241
atError("Number of particles has to be greater or equal to the number of bunches.");
@@ -245,7 +274,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
245274
int num_particles = mxGetN(prhs[1]);
246275
struct elem El, *Elem=&El;
247276

248-
long nslice,nturns,blmode,cavitymode;
277+
long nslice,nturns,blmode,cavitymode, buffersize;
249278
double wakefact;
250279
double normfact, phasegain, voltgain;
251280
double *turnhistory;
@@ -257,6 +286,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
257286
double *vbeam;
258287
double *vgen;
259288
double *vcav;
289+
double *vgen_buffer;
290+
double *vbeam_buffer;
291+
double *vbunch_buffer;
260292
/*attributes for RF cavity*/
261293
Length=atGetDouble(ElemData,"Length"); check_error();
262294
Energy=atGetDouble(ElemData,"Energy"); check_error();
@@ -266,6 +298,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
266298
nslice=atGetLong(ElemData,"_nslice"); check_error();
267299
nturns=atGetLong(ElemData,"_nturns"); check_error();
268300
blmode=atGetLong(ElemData,"_blmode"); check_error();
301+
buffersize=atGetLong(ElemData,"_buffersize"); check_error();
269302
cavitymode=atGetLong(ElemData,"_cavitymode"); check_error();
270303
wakefact=atGetDouble(ElemData,"_wakefact"); check_error();
271304
qfactor=atGetDouble(ElemData,"Qfactor"); check_error();
@@ -280,6 +313,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
280313
vcav=atGetDoubleArray(ElemData,"_vcav"); check_error();
281314
vgen=atGetDoubleArray(ElemData,"_vgen"); check_error();
282315
vbeam_phasor=atGetDoubleArray(ElemData,"_vbeam_phasor"); check_error();
316+
vgen_buffer=atGetDoubleArray(ElemData,"_vgen_buffer"); check_error();
317+
vbeam_buffer=atGetDoubleArray(ElemData,"_vbeam_buffer"); check_error();
318+
vbunch_buffer=atGetDoubleArray(ElemData,"_vbunch_buffer"); check_error();
283319
/*optional attributes*/
284320
z_cuts=atGetOptionalDoubleArray(ElemData,"ZCuts"); check_error();
285321

@@ -306,6 +342,10 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
306342
Elem->phasegain = phasegain;
307343
Elem->voltgain = voltgain;
308344
Elem->vbeam_phasor = vbeam_phasor;
345+
Elem->buffersize = buffersize;
346+
Elem->vgen_buffer = vgen_buffer;
347+
Elem->vbeam_buffer = vbeam_buffer;
348+
Elem->vbunch_buffer = vbunch_buffer;
309349

310350
if (mxGetM(prhs[1]) != 6) mexErrMsgIdAndTxt("AT:WrongArg","Second argument must be a 6 x N matrix");
311351
/* ALLOCATE memory for the output array of the same size as the input */
@@ -318,7 +358,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
318358
}
319359
else if (nrhs == 0)
320360
{ /* return list of required fields */
321-
plhs[0] = mxCreateCellMatrix(19,1);
361+
plhs[0] = mxCreateCellMatrix(24,1);
322362
mxSetCell(plhs[0],0,mxCreateString("Length"));
323363
mxSetCell(plhs[0],1,mxCreateString("Energy"));
324364
mxSetCell(plhs[0],2,mxCreateString("Frequency"));
@@ -339,6 +379,10 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
339379
mxSetCell(plhs[0],17,mxCreateString("_vcav"));
340380
mxSetCell(plhs[0],18,mxCreateString("_vgen"));
341381
mxSetCell(plhs[0],19,mxCreateString("_vbeam_phasor"));
382+
mxSetCell(plhs[0],20,mxCreateString("_vgen_buffer"));
383+
mxSetCell(plhs[0],21,mxCreateString("_vbeam_buffer"));
384+
mxSetCell(plhs[0],22,mxCreateString("_vbunch_buffer"));
385+
mxSetCell(plhs[0],23,mxCreateString("_buffersize"));
342386
if(nlhs>1) /* optional fields */
343387
{
344388
plhs[1] = mxCreateCellMatrix(2,1);

0 commit comments

Comments
 (0)