Skip to content

Commit

Permalink
Merge pull request #112 from PyCOMPLETE/release/v1.14.0
Browse files Browse the repository at this point in the history
Release/v1.14.0
  • Loading branch information
lmether authored Jan 27, 2020
2 parents 85242b0 + d8598e3 commit a85d0ea
Show file tree
Hide file tree
Showing 172 changed files with 29,239 additions and 1,162 deletions.
4 changes: 1 addition & 3 deletions PyHEADTAIL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
from ._version import __version__
dirty = False

print ('PyHEADTAIL v' + __version__)
print(('PyHEADTAIL v' + __version__))
if dirty:
print ('(dirty git work tree)')
print ('\n')

from .general.element import Element, Printing
from .general import utils
# print ' '
# print ' ;Cfttttt11111111tttt1f0f. '
# print ' ,GttttfG0GGG00000GGG0G0G0G0G0G0Ct1t1fG: '
Expand Down
2 changes: 1 addition & 1 deletion PyHEADTAIL/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.13.5'
__version__ = '1.14.0'
3 changes: 0 additions & 3 deletions PyHEADTAIL/aperture/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
from .. import Element
from ..particles.slicing import clean_slices
from .. import __version__

13 changes: 6 additions & 7 deletions PyHEADTAIL/aperture/aperture.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division
'''
Aperture module to manage particle losses. An aperture is
defined as a condition on the phase space coordinates. Particles
Expand All @@ -11,26 +10,26 @@
Michael Schenk
'''

from . import Element, clean_slices

from abc import ABCMeta, abstractmethod

from ..general import pmath as pm
import numpy as np
from abc import ABCMeta, abstractmethod

from PyHEADTAIL.general.element import Element, Printing
from PyHEADTAIL.general import pmath as pm
from PyHEADTAIL.particles.slicing import clean_slices

def make_int32(array):
return array.astype(np.int32)


class Aperture(Element):
class Aperture(Element, metaclass=ABCMeta):
'''Abstract base class for Aperture elements. An aperture is
generally defined as a condition on the phase space coordinates.
Particles not fulfilling this condition are tagged as lost and
are removed from the beam directly after.
'''

__metaclass__ = ABCMeta

@clean_slices
def track(self, beam):
'''Tag particles not passing through the aperture as lost. If
Expand Down
2 changes: 1 addition & 1 deletion PyHEADTAIL/aperture/aperture_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cimport cython
import numpy as np
cimport numpy as np

import aperture
import PyHEADTAIL.aperture.aperture as aperture

class Aperture(aperture.Aperture):
'''Pendant to aperture.Aperture with the relocate algorithm
Expand Down
1 change: 0 additions & 1 deletion PyHEADTAIL/cobra_functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .. import __version__
4 changes: 2 additions & 2 deletions PyHEADTAIL/cobra_functions/curve_tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import division


import numpy as np
from scipy.optimize import brentq
Expand All @@ -20,4 +20,4 @@ def extrema(x, y=None):
zix = np.where(np.abs(np.diff(np.sign(np.diff(x)))) == 2)[0]
return zix
if not y:
print zix
print(zix)
2 changes: 1 addition & 1 deletion PyHEADTAIL/cobra_functions/pdf_integrators_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
@date 21.06.2017
@brief 2D distribution integration methods for y(x) parametrised domains
'''
from scipy.integrate import quad, dblquad, cumtrapz, romb

import numpy as np
from scipy.integrate import quad, dblquad, cumtrapz, romb


def quad2d(f, ylimits, xmin, xmax):
Expand Down
1 change: 1 addition & 0 deletions PyHEADTAIL/cobra_functions/stats.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
of bunch and slice_set data.
@copyright CERN
"""

import numpy as np
cimport numpy as np
cimport libc.math as cmath
Expand Down
2 changes: 0 additions & 2 deletions PyHEADTAIL/feedback/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
from .. import __version__
from .. import Element
4 changes: 2 additions & 2 deletions PyHEADTAIL/feedback/transverse_damper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
@date 20/06/2014
@copyright CERN
'''
from __future__ import division



import numpy as np
from scipy.special import k0
from scipy.constants import c, e

from . import Element
from PyHEADTAIL.general.element import Element

class TransverseDamper(Element):

Expand Down
2 changes: 1 addition & 1 deletion PyHEADTAIL/feedback/widebandfeedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@date 20/06/2014
@copyright CERN
'''
from __future__ import division



import numpy as np
Expand Down
10 changes: 5 additions & 5 deletions PyHEADTAIL/field_maps/Transverse_Efield_map.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import numpy as np
from scipy.constants import c

from PyHEADTAIL.general.element import Element
from PyHEADTAIL.particles.slicing import UniformBinSlicer
from PyPIC.PyPIC_Scatter_Gather import PyPIC_Scatter_Gather

from . import Element

class Transverse_Efield_map(Element):
def __init__(self, xg, yg, Ex, Ey, L_interaction, slicer,
flag_clean_slices=False, wrt_slice_centroid=False,
x_beam_offset=0., y_beam_offset=0., verbose=False,
*args, **kwargs):
flag_clean_slices=False, wrt_slice_centroid=False,
x_beam_offset=0., y_beam_offset=0., verbose=False,
*args, **kwargs):

self.slicer = slicer
self.L_interaction = L_interaction
Expand All @@ -36,7 +36,7 @@ def track(self, beam):

slices = beam.get_slices(self.slicer)

for sid in xrange(slices.n_slices-1, -1, -1):
for sid in range(slices.n_slices-1, -1, -1):

# select particles in the slice
pid = slices.particle_indices_of_slice(sid)
Expand Down
1 change: 0 additions & 1 deletion PyHEADTAIL/field_maps/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .. import Element
17 changes: 8 additions & 9 deletions PyHEADTAIL/field_maps/field_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
@date: 13.06.2017
'''

from __future__ import division, print_function

from scipy.constants import c

from . import Element
from scipy.constants import c

from ..general import pmath as pm
from ..gpu.pypic import make_PyPIC
from PyHEADTAIL.general.element import Element
from PyHEADTAIL.general import pmath as pm
from PyHEADTAIL.gpu.pypic import make_PyPIC

class FieldMap(Element):
'''This static field in the lab frame applies kicks to the beam
Expand Down Expand Up @@ -83,7 +82,7 @@ def __init__(self, length, mesh, fields, wrt_beam_centroid=False,
poissonsolver=None,
gradient=lambda *args, **kwargs: None,
mesh=mesh)
self.fields = map(pm.ensure_same_device, fields)
self.fields = list(map(pm.ensure_same_device, fields))
self.wrt_beam_centroid = wrt_beam_centroid

def track(self, beam):
Expand All @@ -95,7 +94,7 @@ def track(self, beam):
beam.y - my,
beam.z - mz] # zip will cut to #fields

mesh_fields_and_mp_coords = zip(self.fields, mp_coords)
mesh_fields_and_mp_coords = list(zip(self.fields, mp_coords))

# electric fields at each particle position in lab frame [V/m]
part_fields = self.pypic.field_to_particles(*mesh_fields_and_mp_coords)
Expand Down Expand Up @@ -150,7 +149,7 @@ def __init__(self, slicer, *args, **kwargs):
# require 2D!
assert self.pypic.mesh.dimension == 2, \
'mesh needs to be two-dimensional!'
assert all(map(lambda f: f.ndim == 2, self.fields)), \
assert all([f.ndim == 2 for f in self.fields]), \
'transverse field components need to be two-dimensional arrays!'
#

Expand All @@ -168,7 +167,7 @@ def track(self, beam):
mp_coords = [beam.x - mx,
beam.y - my,
beam.z] # zip will cut to #fields
mesh_fields_and_mp_coords = zip(self.fields, mp_coords)
mesh_fields_and_mp_coords = list(zip(self.fields, mp_coords))

# electric fields at each particle position in lab frame [V/m]
part_fields = self.pypic.field_to_particles(*mesh_fields_and_mp_coords)
Expand Down
1 change: 0 additions & 1 deletion PyHEADTAIL/general/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .. import __version__
13 changes: 4 additions & 9 deletions PyHEADTAIL/general/contextmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
@author Stefan Hegglin
@data 30.09.2015
'''

import numpy as np

class UnknownContextManagerError(Exception):
'''Raise if context manager is not found, e.g. cannot determine
whether on CPU or on GPU.
'''
def __init__(self, message='Failed to determine current context, e.g. '
'whether pmath.device is "CPU" or "GPU".'):
self.message = message
import PyHEADTAIL.general.pmath as pm
from PyHEADTAIL.gpu import gpu_utils

import pmath as pm
from ..gpu import gpu_utils
try:
import pycuda.gpuarray as gpuarray
import pycuda
Expand All @@ -25,6 +19,7 @@ def __init__(self, message='Failed to determine current context, e.g. '
# print ('pycuda not found, GPU context unavailable')
has_pycuda = False


if has_pycuda:
def create_kernel(operator):
'''Return a elementwisekernel with the operator being one of
Expand Down
7 changes: 4 additions & 3 deletions PyHEADTAIL/general/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import warnings
from functools import wraps
from ..gpu import gpu_utils

from PyHEADTAIL.gpu import gpu_utils


def deprecated(message):
Expand All @@ -25,7 +26,7 @@ def deprecated_wrapper(*args, **kwargs):
'PyHEADTAIL release!'.format(name),
category=DeprecationWarning, stacklevel=2)
warnings.simplefilter('default', DeprecationWarning)
print message
print(message)
return func(*args, **kwargs)
return deprecated_wrapper
return deprecated_decorator
Expand All @@ -40,7 +41,7 @@ def memoize(function):
@wraps(function)
def evaluate(*args):
signature = (args)
if not store.has_key(signature):
if signature not in store:
store[signature] = function(*args)
return store[signature]
return evaluate
Expand Down
10 changes: 7 additions & 3 deletions PyHEADTAIL/general/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
Can be used for implementing general features that every derived element
in PyHEADTAIL should have.
'''
from .printers import ConsolePrinter

from abc import ABCMeta, abstractmethod

from PyHEADTAIL.general.printers import ConsolePrinter


class Printing(object):
'''Provides prints(output) method in order to communicate any output
Expand All @@ -24,6 +26,9 @@ class Printing(object):
in order to obtain full flexibility over output channels.
'''

def __init__(self, *args, **kwargs):
pass

def __new__(cls, *args, **kwargs):
'''
Factory method makes sure that inheriting elements always
Expand Down Expand Up @@ -66,12 +71,11 @@ def warns(self, output):
self._warningprinter.prints("*** PyHEADTAIL WARNING! " + output)


class Element(Printing):
class Element(Printing, metaclass=ABCMeta):
'''
Abstract element as part of the tracking layout. Guarantees
to fulfil its tracking contract via the method track(beam).
'''
__metaclass__ = ABCMeta

@abstractmethod
def track(self, beam):
Expand Down
38 changes: 26 additions & 12 deletions PyHEADTAIL/general/pmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,53 @@
@author Stefan Hegglin
@date 05.10.2015
'''

import numpy as np
from ..cobra_functions import stats as cp
from functools import wraps
from scipy.special import erfc as _erfc
from scipy.special import wofz as _scipy_wofz

from PyHEADTAIL.cobra_functions import stats as cp

try:
import pycuda.cumath
import pycuda.gpuarray
import pycuda.tools
from ..gpu import gpu_utils
from ..gpu import gpu_wrap

from PyHEADTAIL.gpu import gpu_utils
from PyHEADTAIL.gpu import gpu_wrap
has_pycuda = gpu_wrap.has_pycuda
except (ImportError, OSError):
# print ('No Pycuda in pmath.py import statement found')
has_pycuda = False

try:
import skcuda.misc
except ImportError:
# print ('Skcuda not found. (Scikit-cuda)')
pass

from functools import wraps

from contextmanager import UnknownContextManagerError

# FADDEEVA error function (wofz) business (used a.o. in spacecharge module)
try:
from errfff import errf as _errf_f
from PyHEADTAIL.general.errfff import errf as _errf_f
_errf = np.vectorize(_errf_f)
except ImportError:
_errf = None
from scipy.special import erfc as _erfc
from scipy.special import wofz as _scipy_wofz


class UnknownContextManagerError(Exception):
'''Raise if context manager is not found, e.g. cannot determine
whether on CPU or on GPU.
'''
def __init__(self, message='Failed to determine current context, e.g. '
'whether pmath.device is "CPU" or "GPU".'):
self.message = message


def _wofz(x, y):
res = _scipy_wofz(x + 1j*y)
return res.real, res.imag

def _errfadd(z):
return np.exp(-z**2) * _erfc(z * -1j)

Expand Down Expand Up @@ -317,8 +331,8 @@ def update_active_dict(new_dict):
if not hasattr(update_active_dict, 'active_dict'):
update_active_dict.active_dict = new_dict
# delete all old implementations/references from globals()
for key in globals().keys():
if key in update_active_dict.active_dict.keys():
for key in list(globals().keys()):
if key in list(update_active_dict.active_dict.keys()):
del globals()[key]
# add the new active dict to the globals()
globals().update(new_dict)
Expand Down
Loading

0 comments on commit a85d0ea

Please sign in to comment.