Skip to content

Commit

Permalink
Merge pull request #23 from giadarol/master
Browse files Browse the repository at this point in the history
Remove pyblep dependence in footprint example
  • Loading branch information
rdemaria authored Jun 18, 2019
2 parents 8c42233 + 62f8891 commit 5f2f5b2
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sixtracktools
import pyblep
import pysixtrack
import pickle
import os
Expand All @@ -16,14 +15,12 @@
sixinput = sixtracktools.SixInput('.')
p0c_eV = sixinput.initialconditions[-3]*1e6

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

# Info on sixtrack->pyblep conversion
iconv = other_data['iconv']

# Build pysixtrack line
line = pysixtrack.Line.fromline(pbline)

########################################################
# Search closed orbit #
Expand Down Expand Up @@ -64,7 +61,7 @@
#################################

with open('line.pkl', 'wb') as fid:
pickle.dump(line.to_pyblep_line(), fid)
pickle.dump(line.to_dict(keepextra=True), fid)

#########################################
# Save particle on closed orbit as dict #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

# Load machine
with open('line.pkl', 'rb') as fid:
pbline = pickle.load(fid)

line = pysixtrack.Line.fromline(pbline)
line = pysixtrack.Line.from_dict(pickle.load(fid))

# Load particle on CO
with open('particle_on_CO.pkl', 'rb') as fid:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
n_turns = 100

with open('line.pkl', 'rb') as fid:
line = pickle.load(fid)
line = pysixtrack.Line.from_dict(pickle.load(fid))

with open('particle_on_CO.pkl', 'rb') as fid:
partCO = pickle.load(fid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


with open('line.pkl', 'rb') as fid:
line = pickle.load(fid)
line = pysixtrack.Line.from_dict(pickle.load(fid))

with open('particle_on_CO.pkl', 'rb') as fid:
partCO = pickle.load(fid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
n_turns = 100

with open('line.pkl', 'rb') as fid:
line = pickle.load(fid)
line = pysixtrack.Line.from_dict(pickle.load(fid))

with open('particle_on_CO.pkl', 'rb') as fid:
partCO = pickle.load(fid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ def track_particle_pysixtrack(line, part, Dx_wrt_CO_m, Dpx_wrt_CO_rad,
Dy_wrt_CO_m, Dpy_wrt_CO_rad,
Dsigma_wrt_CO_m, Ddelta_wrt_CO, n_turns, verbose=False):

line = pysixtrack.Line.fromline(line)

Dx_wrt_CO_m, Dpx_wrt_CO_rad,\
Dy_wrt_CO_m, Dpy_wrt_CO_rad,\
Dsigma_wrt_CO_m, Ddelta_wrt_CO = vectorize_all_coords(
Expand Down
13 changes: 9 additions & 4 deletions examples/python/test_sis18/test_timings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cpymad.madx import Madx
import pysixtracklib as pyst
import pysixtracklib as pystlib
import pysixtrack

import time
from scipy.constants import e, m_p, c
Expand All @@ -26,13 +27,17 @@
sis18 = mad.sequence.FODO

nturns = 1
elements = pyst.Elements.from_mad(sis18)
ps_line, _ = pysixtrack.Line.from_madx_sequence(sis18)
elements=pystlib.Elements()
elements.append_line(ps_line)



def prepare(npart=int(1e6), p0c=p0c, elements=elements, device='cpu'):
particles = pyst.Particles.from_ref(npart, p0c=p0c)
particles = pystlib.Particles.from_ref(npart, p0c=p0c)
particles.x += np.linspace(0, 1e-6, npart)

job = pyst.TrackJob(elements, particles, device=device)
job = pystlib.TrackJob(elements, particles, device=device)
return job

class Timer(object):
Expand Down
23 changes: 14 additions & 9 deletions examples/python/test_sps_mad/test_sps_mad.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import matplotlib.pyplot as pl
from cpymad.madx import Madx
import pysixtracklib as pyst

import pysixtracklib as pystlib
import pysixtrack

# prepare madx
mad = Madx()
Expand All @@ -15,23 +15,28 @@
print(q1mad, q2mad)

# Build elements for SixTrackLib
elements = pyst.Elements.from_mad(mad.sequence.sps)
elements = pystlib.Elements.from_line(
pysixtrack.Line.from_madx_sequence(mad.sequence.sps)[0])
nturns = 2**14

ps_line, _ = pysixtrack.Line.from_madx_sequence(mad.sequence.sps)
elements=pystlib.Elements()
elements.append_line(ps_line)
bpm = elements.BeamMonitor(num_stores=nturns)

# Track one turn
npart = 10
particles = pyst.Particles.from_ref(npart, p0c=26e6)
particles = pystlib.Particles.from_ref(npart, p0c=26e6)
particles.x += np.linspace(0, 1e-6, npart)
job = pyst.TrackJob(elements, particles, until_turn_elem_by_elem=1)
job = pystlib.TrackJob(elements, particles, until_turn_elem_by_elem=1)
job.track_elem_by_elem(1)
pl.plot(job.output.particles[0].x[1::10])

# Track many turns CPU
npart = 10
particles = pyst.Particles.from_ref(npart, p0c=26e6)
particles = pystlib.Particles.from_ref(npart, p0c=26e6)
particles.x += np.linspace(0, 1e-6, npart)
job = pyst.TrackJob(elements, particles)
job = pystlib.TrackJob(elements, particles)
job.track(nturns)

# Find tunes
Expand All @@ -46,9 +51,9 @@
npart = 5000
nturns = 256
bpm.num_stores = nturns
particles = pyst.Particles.from_ref(npart, p0c=26e6)
particles = pystlib.Particles.from_ref(npart, p0c=26e6)
particles.x += np.linspace(0, 1e-1, npart)
job = pyst.TrackJob(elements, particles, device="opencl:0.0")
job = pystlib.TrackJob(elements, particles)#, device="opencl:0.0")
job.track(nturns)
job.collect()

Expand Down

0 comments on commit 5f2f5b2

Please sign in to comment.