Skip to content

Commit

Permalink
Merge pull request #33 from rdemaria/master
Browse files Browse the repository at this point in the history
From Riccardo (looks heavy)
  • Loading branch information
giadarol authored Dec 9, 2019
2 parents b3881a4 + 229b809 commit ddfb693
Show file tree
Hide file tree
Showing 51 changed files with 6,449 additions and 390 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203,

34 changes: 34 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7]

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pytest
26 changes: 26 additions & 0 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
33 changes: 16 additions & 17 deletions examples/aperture/000_test_aperture.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import numpy as np
from numpy.random import uniform
import matplotlib.pyplot as plt

import pysixtrack

p = pysixtrack.Particles()

rect_aperture = pysixtrack.elements.LimitRect( min_x=-1e-2, max_x=2e-2,
min_y=-0.5e-2, max_y=2.5e-2)
rect_aperture = pysixtrack.elements.LimitRect(
min_x=-1e-2, max_x=2e-2, min_y=-0.5e-2, max_y=2.5e-2
)

ellip_aperture = pysixtrack.elements.LimitEllipse(a=1.5e-2, b=.3e-2)
ellip_aperture = pysixtrack.elements.LimitEllipse(a=1.5e-2, b=0.3e-2)

# Test scalar
assert(rect_aperture.track(p) is None)
assert(ellip_aperture.track(p) is None)
assert rect_aperture.track(p) is None
assert ellip_aperture.track(p) is None

p.x= 100.
assert(rect_aperture.track(p)==0)
assert(ellip_aperture.track(p)==0)
p.x = 100.0
assert rect_aperture.track(p) == 0
assert ellip_aperture.track(p) == 0

# Test vector
from numpy.random import uniform

N_part = 10000

Expand All @@ -29,14 +32,10 @@
rect_aperture.track(p)
ellip_aperture.track(p)

import matplotlib.pyplot as plt

plt.close('all')
plt.close("all")
fig1 = plt.figure(1)
ax = fig1.add_subplot(111)

ax.plot(p.x, p.y, '.b')
ax.plot(p.lost_particles[0].x, p.lost_particles[0].y, 'r.')
ax.plot(p.lost_particles[1].x, p.lost_particles[1].y, 'g.')

plt.show()
ax.plot(p.x, p.y, ".b")
ax.plot(p.lost_particles[0].x, p.lost_particles[0].y, "r.")
ax.plot(p.lost_particles[1].x, p.lost_particles[1].y, "g.")
11 changes: 8 additions & 3 deletions examples/bbsimple/testbb6d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
line, other_data = pysixtrack.Line.from_sixinput(sixinput)

# Info on sixtrack->pyblep conversion
iconv = other_data["iconv"]
iconv = line.other_data["iconv"]

########################################################
# Search closed orbit #
Expand Down Expand Up @@ -125,10 +125,15 @@ def compare(prun, pbench, pbench_prev):
vbench = getattr(pbench, att)
vbench_prev = getattr(pbench_prev, att)
diff = vrun - vbench
diffrel = abs(1.0 - abs(vrun - vbench_prev) / abs(vbench - vbench_prev))
diffrel = abs(
1.0 - abs(vrun - vbench_prev) / abs(vbench - vbench_prev)
)
out.append(abs(diff))
out_rel.append(diffrel)
print(f"{att:<5} {vrun:22.13e} {vbench:22.13e} {diff:22.13g} {diffrel:22.13g}")
print(
f"{att:<5} {vrun:22.13e} {vbench:22.13e}"
"{diff:22.13g} {diffrel:22.13g}"
)
if diffrel > 1e-5 or np.isnan(diffrel):
if np.abs(diff) > 9e-10:
print("Too large discrepancy!")
Expand Down
13 changes: 9 additions & 4 deletions examples/beambeam/testbb6d.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
p0c_eV = sixinput.initialconditions[-3] * 1e6

# Build pysixtrack line from sixtrack input
line, other_data = pysixtrack.Line.from_sixinput(sixinput)
line = pysixtrack.Line.from_sixinput(sixinput)

# Info on sixtrack->pyblep conversion
iconv = other_data["iconv"]
iconv = line.other_data["iconv"]

########################################################
# Search closed orbit #
Expand Down Expand Up @@ -125,10 +125,15 @@ def compare(prun, pbench, pbench_prev):
vbench = getattr(pbench, att)
vbench_prev = getattr(pbench_prev, att)
diff = vrun - vbench
diffrel = abs(1.0 - abs(vrun - vbench_prev) / abs(vbench - vbench_prev))
diffrel = abs(
1.0 - abs(vrun - vbench_prev) / abs(vbench - vbench_prev)
)
out.append(abs(diff))
out_rel.append(diffrel)
print(f"{att:<5} {vrun:22.13e} {vbench:22.13e} {diff:22.13g} {diffrel:22.13g}")
print(
f"{att:<5} {vrun:22.13e} {vbench:22.13e}"
"{diff:22.13g} {diffrel:22.13g}"
)
if diffrel > 1e-8 or np.isnan(diffrel):
if np.abs(diff) > 1e-11:
print("Too large discrepancy!")
Expand Down
4 changes: 2 additions & 2 deletions examples/fodo/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pysixtrack

six = sixtracktools.SixInput(".")
line, other = pysixtrack.Line.from_sixinput(six)
iconv = other["iconv"]
line = pysixtrack.Line.from_sixinput(six)
iconv = line.other_data["iconv"]

sixdump = sixtracktools.SixDump101("res/dump.dat")[1::2]

Expand Down
4 changes: 2 additions & 2 deletions examples/lhc/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pysixtrack

six = sixtracktools.SixInput(".")
line, other = pysixtrack.Line.from_sixinput(six)
iconv = other["iconv"]
line = pysixtrack.Line.from_sixinput(six)
iconv = line.other_info["iconv"]

sixdump = sixtracktools.SixDump101("res/dump3.dat")[1::2]

Expand Down
2 changes: 1 addition & 1 deletion examples/load_from_mad/000_from_madx_disabled_bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

mad.call("mad/lhcwbb.seq")

line, other = pysixtrack.Line.from_madx_sequence(mad.sequence.lhcb1)
line = pysixtrack.Line.from_madx_sequence(mad.sequence.lhcb1)

print(line)
19 changes: 13 additions & 6 deletions examples/load_from_mad/001_line_with_bb_from_madx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from cpymad.madx import Madx
import pysixtrack

from pysixtrack.be_beamfields.tools import norm, find_alpha_and_phi
from pysixtrack.be_beamfields.tools import get_bb_names_madpoints_sigmas
from pysixtrack.be_beamfields.tools import shift_strong_beam_based_on_close_ip
from pysixtrack.be_beamfields.tools import setup_beam_beam_in_line
Expand Down Expand Up @@ -64,7 +63,8 @@

# Check number of slices
assert (
len([nn for nn in bb_names_b1 if nn.startswith("bb_ho.l1")]) == (n_slices - 1) / 2
len([nn for nn in bb_names_b1 if nn.startswith("bb_ho.l1")])
== (n_slices - 1) / 2
)

# Correct for small shifts between surveys of the two beams
Expand All @@ -85,7 +85,9 @@
mad_ft.use("lhcb1") # without this the sequence does not work properly

# Build pysixtrack line
line_for_tracking, _ = pysixtrack.Line.from_madx_sequence(mad_ft.sequence["lhcb1"])
line_for_tracking = pysixtrack.Line.from_madx_sequence(
mad_ft.sequence["lhcb1"]
)

# Setup 4D and 6D beam beam lenses
setup_beam_beam_in_line(
Expand All @@ -101,18 +103,23 @@
)

# A check
assert np.abs(line_for_tracking.get_length() - mad.sequence.lhcb1.beam.circ) < 1e-6
assert (
np.abs(line_for_tracking.get_length() - mad.sequence.lhcb1.beam.circ)
< 1e-6
)

# There is a problem in the mask
# (the RF frequancy is wrong in the machine for tracking
# I patch it here -> to be fixed properly!!!!
line_temp, _ = pysixtrack.Line.from_madx_sequence(mad.sequence.lhcb1)
line_temp = pysixtrack.Line.from_madx_sequence(mad.sequence.lhcb1)
dct_correct_cavities = dict(
zip(*line_temp.get_elements_of_type(pysixtrack.elements.Cavity)[::-1])
)
for ii, nn in enumerate(line_for_tracking.element_names):
if nn in dct_correct_cavities.keys():
line_for_tracking.elements[ii].frequency = dct_correct_cavities[nn].frequency
line_for_tracking.elements[ii].frequency = dct_correct_cavities[
nn
].frequency

# Save line
with open("line_from_mad.pkl", "wb") as fid:
Expand Down
4 changes: 3 additions & 1 deletion examples/load_from_mad/002_compare_against_sixinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def norm(x):

# Check if the relative error is small
try:
diff_rel = norm(np.array(dmad[kk]) - np.array(dsix[kk])) / norm(dmad[kk])
diff_rel = norm(np.array(dmad[kk]) - np.array(dsix[kk])) / norm(
dmad[kk]
)
except ZeroDivisionError:
diff_rel = 100.0
if diff_rel < 3e-5:
Expand Down
9 changes: 5 additions & 4 deletions examples/load_from_sixtrack_input/000_basics.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Read sixtrack input using sixtracktools
import sixtracktools
import pysixtrack
import pysixtracklib

# Read sixtrack input using sixtracktools

sixinput = sixtracktools.SixInput("sixtrack_input")

# Build a pysixtrack line from pyblep line
import pysixtrack

ps_line, other = pysixtrack.Line.from_sixinput(sixinput)
ps_line = pysixtrack.Line.from_sixinput(sixinput)

# Build a pysixtracklib line from pyblep line
import pysixtracklib

pslib_line = pysixtracklib.Elements()
pslib_line.append_line(ps_line)
Expand Down
Loading

0 comments on commit ddfb693

Please sign in to comment.