xobjects 0.5.0__tar.gz → 0.5.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {xobjects-0.5.0/xobjects.egg-info → xobjects-0.5.2}/PKG-INFO +1 -1
  2. xobjects-0.5.2/xobjects/_version.py +1 -0
  3. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/context.py +21 -1
  4. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/context_cpu.py +5 -6
  5. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/context_cupy.py +4 -1
  6. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/context_pyopencl.py +4 -0
  7. xobjects-0.5.2/xobjects/general.py +52 -0
  8. {xobjects-0.5.0 → xobjects-0.5.2/xobjects.egg-info}/PKG-INFO +1 -1
  9. xobjects-0.5.0/xobjects/_version.py +0 -1
  10. xobjects-0.5.0/xobjects/general.py +0 -33
  11. {xobjects-0.5.0 → xobjects-0.5.2}/LICENSE +0 -0
  12. {xobjects-0.5.0 → xobjects-0.5.2}/pyproject.toml +0 -0
  13. {xobjects-0.5.0 → xobjects-0.5.2}/setup.cfg +0 -0
  14. {xobjects-0.5.0 → xobjects-0.5.2}/setup.py +0 -0
  15. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_align.py +0 -0
  16. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_array.py +0 -0
  17. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_buffer.py +0 -0
  18. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_capi.py +0 -0
  19. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_chunk.py +0 -0
  20. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_context_opencl.py +0 -0
  21. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_hybrid_class.py +0 -0
  22. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_kernel.py +0 -0
  23. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_linked_array.py +0 -0
  24. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_nplike_arrays.py +0 -0
  25. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_ref.py +0 -0
  26. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_scalars.py +0 -0
  27. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_shared_memory.py +0 -0
  28. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_strides.py +0 -0
  29. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_string.py +0 -0
  30. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_struct.py +0 -0
  31. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_to_json.py +0 -0
  32. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_typeutils.py +0 -0
  33. {xobjects-0.5.0 → xobjects-0.5.2}/tests/test_unionref.py +0 -0
  34. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/__init__.py +0 -0
  35. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/_patch_pyopencl_array.py +0 -0
  36. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/array.py +0 -0
  37. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/capi.py +0 -0
  38. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/hybrid_class.py +0 -0
  39. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/linkedarray.py +0 -0
  40. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/ref.py +0 -0
  41. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/scalar.py +0 -0
  42. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/specialize_source.py +0 -0
  43. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/string.py +0 -0
  44. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/struct.py +0 -0
  45. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/test_helpers.py +0 -0
  46. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/typeutils.py +0 -0
  47. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects/union.py +0 -0
  48. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects.egg-info/SOURCES.txt +0 -0
  49. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects.egg-info/dependency_links.txt +0 -0
  50. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects.egg-info/requires.txt +0 -0
  51. {xobjects-0.5.0 → xobjects-0.5.2}/xobjects.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xobjects
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: In-memory serialization and code generator for CPU and GPU
5
5
  Home-page: https://xsuite.readthedocs.io/
6
6
  Download-URL: https://pypi.python.org/pypi/xobjects
@@ -0,0 +1 @@
1
+ __version__ = "0.5.2"
@@ -6,9 +6,9 @@
6
6
  import logging
7
7
  import os
8
8
  import weakref
9
- import xobjects as xo
10
9
  from abc import ABC, abstractmethod
11
10
  from collections import defaultdict
11
+ from importlib.metadata import entry_points
12
12
  from pathlib import Path
13
13
  from typing import (
14
14
  Dict,
@@ -354,6 +354,26 @@ class XContext(ABC):
354
354
  ) -> Dict[Tuple[str, tuple], KernelType]:
355
355
  pass
356
356
 
357
+ def get_installed_c_source_paths(self) -> List[str]:
358
+ """Returns a list of include paths registered in dependent packages.
359
+
360
+ In a package that depends on xobjects, you can register C source paths
361
+ using the entry point `xobjects.c_sources`. A path to the directory
362
+ containing the specified module will be added to the include path when
363
+ building kernels. For example, the following will allow to write
364
+ ``#include <xtrack/path/to/some/header.h>`` in kernel sources:
365
+
366
+ .. code-block:: toml
367
+ [project.entry-points.xobjects]
368
+ include = "xtrack"
369
+ """
370
+ sources = []
371
+ for ep in entry_points(group="xobjects", name="include"):
372
+ module = ep.load()
373
+ path = Path(module.__file__).parents[1]
374
+ sources.append(str(path))
375
+ return sources
376
+
357
377
  @abstractmethod
358
378
  def nparray_to_context_array(self, arr):
359
379
  return arr
@@ -422,16 +422,15 @@ class ContextCpu(XContext):
422
422
  xtr_link_args.append("-fopenmp")
423
423
  xtr_compile_args.append("-DXO_CONTEXT_CPU_OPENMP")
424
424
  xtr_link_args.append("-DXO_CONTEXT_CPU_OPENMP")
425
-
426
- # https://mac.r-project.org/openmp/
427
- # on macos comment the above and uncomment the below flags to compile OpenMP with Xcode clang:
428
- # xtr_compile_args.append("-Xclang")
429
- # xtr_compile_args.append("-fopenmp")
430
- # xtr_link_args.append("-lomp")
431
425
  else:
432
426
  xtr_compile_args.append("-DXO_CONTEXT_CPU_SERIAL")
433
427
  xtr_link_args.append("-DXO_CONTEXT_CPU_SERIAL")
434
428
 
429
+ extra_include_paths = self.get_installed_c_source_paths()
430
+ include_flags = [f"-I{path}" for path in extra_include_paths]
431
+ xtr_compile_args.extend(include_flags)
432
+ xtr_link_args.extend(include_flags)
433
+
435
434
  if os.name == "nt": # windows
436
435
  # TODO: to be handled properly
437
436
  xtr_compile_args = []
@@ -455,7 +455,10 @@ class ContextCupy(XContext):
455
455
  with open(save_source_as, "w") as fid:
456
456
  fid.write(specialized_source)
457
457
 
458
- extra_compile_args = (*extra_compile_args, "-DXO_CONTEXT_CUDA")
458
+ extra_include_paths = self.get_installed_c_source_paths()
459
+ include_flags = [f"-I{path}" for path in extra_include_paths]
460
+ extra_compile_args = (*extra_compile_args, *include_flags, "-DXO_CONTEXT_CUDA")
461
+
459
462
  module = cupy.RawModule(
460
463
  code=specialized_source, options=extra_compile_args
461
464
  )
@@ -219,8 +219,12 @@ class ContextPyopencl(XContext):
219
219
  with open(save_source_as, "w") as fid:
220
220
  fid.write(specialized_source)
221
221
 
222
+ extra_include_paths = self.get_installed_c_source_paths()
223
+ include_flags = [f"-I{path}" for path in extra_include_paths]
224
+
222
225
  extra_compile_args = (
223
226
  *extra_compile_args,
227
+ *include_flags,
224
228
  "-cl-std=CL2.0",
225
229
  "-DXO_CONTEXT_CL",
226
230
  )
@@ -0,0 +1,52 @@
1
+ # copyright ################################# #
2
+ # This file is part of the Xobjects Package. #
3
+ # Copyright (c) CERN, 2024. #
4
+ # ########################################### #
5
+ from numpy.testing import assert_allclose as np_assert_allclose
6
+ import numpy as np
7
+
8
+
9
+ class Print:
10
+ suppress = False
11
+
12
+ def __call__(self, *args, **kwargs):
13
+ if not self.suppress:
14
+ print(*args, **kwargs)
15
+
16
+
17
+ _print = Print()
18
+
19
+
20
+ def assert_allclose(a, b, rtol=0, atol=0, max_outliers=0):
21
+ if hasattr(a, "get"):
22
+ a = a.get()
23
+ if hasattr(b, "get"):
24
+ b = b.get()
25
+ try:
26
+ a = np.squeeze(a)
27
+ except:
28
+ pass
29
+ try:
30
+ b = np.squeeze(b)
31
+ except:
32
+ pass
33
+
34
+ try:
35
+ np_assert_allclose(a, b, rtol=rtol, atol=atol)
36
+ except AssertionError as e:
37
+ if max_outliers == 0:
38
+ raise e
39
+ if not allclose_with_outliers(a, b, rtol, atol, max_outliers):
40
+ raise AssertionError(
41
+ "Arrays are not close enough, even with outliers allowed."
42
+ ) from e
43
+
44
+
45
+ def allclose_with_outliers(a, b, rtol=1e-7, atol=0, max_outliers=0):
46
+ a = np.asanyarray(a)
47
+ b = np.asanyarray(b)
48
+ diff = np.abs(a - b)
49
+ allowed = atol + rtol * np.abs(b)
50
+ mask = diff > allowed
51
+ num_outliers = np.count_nonzero(mask)
52
+ return num_outliers <= max_outliers
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xobjects
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: In-memory serialization and code generator for CPU and GPU
5
5
  Home-page: https://xsuite.readthedocs.io/
6
6
  Download-URL: https://pypi.python.org/pypi/xobjects
@@ -1 +0,0 @@
1
- __version__ = "0.5.0"
@@ -1,33 +0,0 @@
1
- # copyright ################################# #
2
- # This file is part of the Xobjects Package. #
3
- # Copyright (c) CERN, 2024. #
4
- # ########################################### #
5
- from numpy.testing import assert_allclose as np_assert_allclose
6
- import numpy as np
7
-
8
-
9
- class Print:
10
- suppress = False
11
-
12
- def __call__(self, *args, **kwargs):
13
- if not self.suppress:
14
- print(*args, **kwargs)
15
-
16
-
17
- _print = Print()
18
-
19
-
20
- def assert_allclose(a, b, rtol=1e-7, atol=1e-7):
21
- if hasattr(a, "get"):
22
- a = a.get()
23
- if hasattr(b, "get"):
24
- b = b.get()
25
- try:
26
- a = np.squeeze(a)
27
- except:
28
- pass
29
- try:
30
- b = np.squeeze(b)
31
- except:
32
- pass
33
- np_assert_allclose(a, b, rtol=rtol, atol=atol)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes