Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SixTrackLib v0.6.0 #132

Merged
merged 503 commits into from
Nov 5, 2020

Conversation

martinschwinzerl
Copy link
Contributor

@martinschwinzerl martinschwinzerl commented Jul 1, 2020

Main Features:

  • Complete overhaul of the NS(SpaceCharge*) implementation, adds NS(SpaceChargeQGaussianProfile) and NS(SpaceChargeInterpolatedProfile) beam-elements
  • The latter uses the NS(LineDensityProfileData) element to store a 1D array of values and derivatives and allows to evaluate these values either using linear or cubic spline interpolated.
  • Multiple NS(SpaceChargeInterpolatedProfile) elements can share a single NS(LineDensityProfileData) instance → cf examples/python/spacecharge/ line_density_profile.py for an example demonstrating the usage
  • The NS(SpaceChargeInterpolatedProfile)/ NS(LineDensityProfileData) implementation uses the same API as the NS(TriCub) element from Enable/disable features, adds TriCub element (disabled by default), string handling in python #123. Consequently, this PR should be a superset of Enable/disable features, adds TriCub element (disabled by default), string handling in python #123 and will replace it
  • The API conventions for C/C++ of all beam-elements have been updated to bring them in-line with developments in a different branch. The new API conventions allow a consistent generation of all beam-element accessor and manipulation functions using only the beam-elements name and the name of the individual fields. Also, they tend to be shorter and more aggressivly using
    SIXTRL_NOEXCEPT and SIXTRL_RESTRICT, hopefully improving the performance especially under C++

Required Testing:
In order to test this release, please create a new Settings.cmake from Settings.cmake.default as the changes introduced for PR #123 are also required here and mandate a new Settings format.

Any feedback concerning the performance and correctness of this PR would be highly appreciated. In particular, it would be extremly important to verify, that

  • NS(TriCub) and NS(TriCubData) continue to work as expected. Any changes not already present in the current iterationof PR Enable/disable features, adds TriCub element (disabled by default), string handling in python #123 should be incorporated in this pull-request
  • The tracking functions for the new NS(SpaceCharge*) elements have been ported directly from the pysixtrack implementation (cf. Feature/sc linedensity interpolation pysixtrack#50). It is very likely that they still contain bugs since we do not currently have any tests verifiying the correctness of the space-charge implementations
  • Performance with/without NS(TriCub) elements should remain roughly where it is with respect to the current main branch.
  • The names and API conventions especially concerning the NS(SpaceCharge*) elements is not set in stone - any feedback would be highly appreciated

Regressions and Bugs:
All tests seem to pass at least on my development machine. However, there is an issue with the OpenCL implementation provided by a recent version of the Intel OneAPI (cf. issue #131) which is also effecting the currently release version and which should be investigated

TODOs before merging:
In addition to testing and benchmarking (cf. above, thank you again), the remaining tasks are to

  • verify that the interpolated NS(SpaceChargeInterpolatedProfile) does work also using a Cuda TrackJob
  • Finalize the naming of elements and fields
  • Backport the naming of the elements and fields to the pending pysixtrack PR Feature/sc linedensity interpolation pysixtrack#50

In Closing, Additional Remarks, and Minor Changes Not Highlighted So Far:
This is a massive change, touching and potentially breaking a lot of differnt parts of the implementation. I am sorry for the sheer volume but I was not very successful in landing these changes in a more digestible fashion. In addition to the changes outlined above (And to what is presented / described in #123), the following additional changes are part of this PR:

  • All beam-elements with dataptr members (NS(Multipole), NS(RFMultipole), NS(BeamBeam4D), NS(BeamBeam6D)) now use a 64Bit integer to store the address rather than having the pointer directly as a datamember. This ensures that storing elements into a CBuffer() on architectures with 32bit pointers produces a binary representation also usable on 64 Bit systems. It also gives additional flexibility concerning the memory region of the
  • Changes the spelling of the NS(Multipole) and NS(RFMultipole) elements to be consistent with their counterparts in the python bindings of SixTrackLib and pysixtrack
  • Introduces sixtracklib/common/internal/math_constants.h, sixtracklib/common/internal/physics_constants.h which provide a templated C++ and a default C implementation for commonly used constants. This is a stepping stone to a type-traits driven version of these files used in a more recent developent version of SixTrackLib, allowing the use of types other than double
  • Provides templated and C99 versions of 1D interpolation functions, functions used in kernels and physics calculations, calculations of the factorial, etc. to be shared across all beam-elements. Again, this API prepares the introduction of a concurrently developed version of the API which can use types different than double for floating-point valued quantities
  • Introduces SIXTRL_UNUSED() macro to properly handle unused / optional method parameters, avoiding warnings and casts using (void) in the method body
  • Introduces common, abstract implementations for comparisons of floating-point type values and ranges, again providing a segway towards a utilising types other than double via C++ templates
  • The type-ids of Python beam-elements are now set via methods exposed from the C API. This ensures, that both the python version of SixTRackLib and the C/C++ implementation stay consistent in this regard. The currently choosen method to achieve this is rather clunky and will be replaced by a better implementation down the road
  • The names of tests and test-fixtures throughout SixTrackLib is currently in violation of a naming convention mandated by googletest (cf. issue remove underscores from googletest testcase names #124). This PR continues with the attempts to fix all remaining tests which are affected

NOTES:

kparasch and others added 30 commits January 20, 2020 17:30
-- Note: changed to use black -l 79 instead of autopep8 to be compatible with
   the linter script in pysixtrack
python/sixtracklib: fixes wrong calculated offset to TriCubData element
…thon

- adds two helper functions to stcommon which encode and decode
  python (unicode) strings to bytes strings compatible with ctypes.c_char_p

- Avoid explicit encoding / decoding in all parts of python/sixtracklib
  and use the helper functions instead

- re-apply the linter after reformating and simplyfing the source code
python/sixtracklib: fixes access to OpenCL related C99 symbols if Ope…
…rectly with the ClContext (does not occur in a track-job example)
This attempts to addess comment SixTrack#125 which fails on cc60
There seems to be an issue of typedef conflicts between host code and device
code on CUDA (most likely due to the use of uint64_t in common/definitions.h)

This is a work-around which should work. The better fix is to transit
the SIXTRL_(U)INT(xy) macros to use the proper native types and not to rely
on uint64_t etc. being consistent on the device side
- makes the path prefix to the kernel/program directory
  a runtime modifiable attribute of the base controller -
  this should allow to make the sixtracklib .so / .dll
  relocatable and address problems with blanks / special
  chars in the path

- adds api to fetch particle addresses on the device
- The flag CUDA_RESOLVE_DEVICE_SYMBOLS should be enabled by default on
  shared libraries like SixTrackLib. The property does not work on
  OBJECT libraries like sixtrack_cuda_device. It seems that starting
  with cmake 3.15, cmake did not pick up the property for the resulting
  compound SHARED library just by inferring the dependency on the CUDA
  device part.

  This fix attempts to rectify this by adding the property explicitly
  to the SHARED sixtracklib library if the sixtrack_cuda_device
  target is present.

  Tested on CMake 3.14, 3.16 und 3.18 -> seems to work

- Note: this would fix issue SixTrack#109 but more investigation is required whether
  this solves all problems encountered therein
Backported from #PR130

- The flag CUDA_RESOLVE_DEVICE_SYMBOLS should be enabled by default on
  shared libraries like SixTrackLib. The property does not work on
  OBJECT libraries like sixtrack_cuda_device. It seems that starting
  with cmake 3.15, cmake did not pick up the property for the resulting
  compound SHARED library just by inferring the dependency on the CUDA
  device part.

  This fix attempts to rectify this by adding the property explicitly
  to the SHARED sixtracklib library if the sixtrack_cuda_device
  target is present.

  Tested on CMake 3.14, 3.16 und 3.18 -> seems to work

- Note: this would fix issue SixTrack#109 but more investigation is required whether
  this solves all problems encountered therein
By request of users, the map now checks whether the abscissa value for
which an interpolation should be calculated is within bounds (as expected)
or outside of the range sampled in the abscissa values

If the range is exceeded, 0 is returned rather than an assertion or error
being propagated. This is a deviation from the previous assumption, that
the values *always* have to be within bounds.

The performance impact for conforming values should be minimal (
one floating point multiplication, one addition, two comparisons,
one bitwise AND) and branch divergence should only occur in very exceptionally
few cases. Given the asymptotic behaviour of real-world profiles, this
should be a pretty sensible fall-back and avoids hard to debug / trace
errors if evaluation very close to the boundaries is required and
particles could stray outside of the bounds for example by rounding errors.

NOTE: we reserve the right to revert this change in case performance
is, unexpectedly, serverly affected. Please report if any unexpected
side-effects are associated with this change
Thanks to @kparasch for providing the dataset and the methodology for the testdata!
Thanks to @kparasch for providing the testcase and for the preparation of
this test!
- fixes wrong file format qualifier when loading the dumped pickle
- casts loaded prng_seed to int as numpy does not accept floating point seeds
- disables the test if the TriCub element is not enabled.
- relaxes the error tolerances to rel=1e-12, abs=1e-13

NOTE: Investigate why there is a discrepancy with the dump above the
EPS of the machine precision for double?
…ing construction and assignment

NOTE: apparently, m_stored_buffers and m_assign_item_keys are not handled during copy-assignment
      operations -> this is not good and should be fixed!
@martinschwinzerl
Copy link
Contributor Author

Merged PR #130 and PR #110 into this PR -> will remove the other two to simplify final testing and coordination with pysixtrack

@martinschwinzerl martinschwinzerl changed the title Provide Space-Charges with interpolated line profile SixTrackLib v0.6.0 Oct 28, 2020
@martinschwinzerl martinschwinzerl merged commit 6893b94 into SixTrack:master Nov 5, 2020
@martinschwinzerl martinschwinzerl deleted the feature/sc_interpol branch November 5, 2020 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants