xcoll 0.3.6__py3-none-any.whl → 0.5.0__py3-none-any.whl

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.

Potentially problematic release.


This version of xcoll might be problematic. Click here for more details.

Files changed (350) hide show
  1. xcoll/__init__.py +13 -4
  2. xcoll/beam_elements/__init__.py +14 -6
  3. xcoll/beam_elements/absorber.py +41 -7
  4. xcoll/beam_elements/base.py +1202 -247
  5. xcoll/beam_elements/blowup.py +198 -0
  6. xcoll/beam_elements/elements_src/black_absorber.h +136 -0
  7. xcoll/beam_elements/elements_src/black_crystal.h +129 -0
  8. xcoll/beam_elements/elements_src/blowup.h +42 -0
  9. xcoll/beam_elements/elements_src/emittance_monitor.h +109 -0
  10. xcoll/beam_elements/{collimators_src → elements_src}/everest_block.h +59 -30
  11. xcoll/beam_elements/elements_src/everest_collimator.h +237 -0
  12. xcoll/beam_elements/elements_src/everest_crystal.h +280 -0
  13. xcoll/beam_elements/everest.py +65 -119
  14. xcoll/beam_elements/monitor.py +428 -0
  15. xcoll/colldb.py +276 -747
  16. xcoll/general.py +5 -5
  17. xcoll/headers/checks.h +1 -1
  18. xcoll/headers/particle_states.h +2 -2
  19. xcoll/initial_distribution.py +207 -0
  20. xcoll/install.py +179 -0
  21. xcoll/interaction_record/__init__.py +1 -0
  22. xcoll/interaction_record/interaction_record.py +298 -0
  23. xcoll/interaction_record/interaction_record_src/interaction_record.h +98 -0
  24. xcoll/{impacts → interaction_record}/interaction_types.py +11 -4
  25. xcoll/line_tools.py +82 -0
  26. xcoll/lossmap.py +219 -0
  27. xcoll/manager.py +2 -937
  28. xcoll/rf_sweep.py +1 -1
  29. xcoll/scattering_routines/everest/amorphous.h +232 -0
  30. xcoll/scattering_routines/everest/channeling.h +240 -0
  31. xcoll/scattering_routines/everest/crystal_parameters.h +137 -0
  32. xcoll/scattering_routines/everest/everest.h +11 -30
  33. xcoll/scattering_routines/everest/everest.py +13 -10
  34. xcoll/scattering_routines/everest/jaw.h +28 -197
  35. xcoll/scattering_routines/everest/materials.py +37 -15
  36. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +31 -10
  37. xcoll/scattering_routines/everest/nuclear_interaction.h +86 -0
  38. xcoll/scattering_routines/everest/properties.h +6 -1
  39. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  40. xcoll/scattering_routines/geant4/collimasim/.git +1 -0
  41. xcoll/scattering_routines/geant4/collimasim/.gitignore +12 -0
  42. xcoll/scattering_routines/geant4/collimasim/.gitmodules +3 -0
  43. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +26 -0
  44. xcoll/scattering_routines/geant4/collimasim/README.md +21 -0
  45. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +20 -0
  46. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +35 -0
  47. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +10 -0
  48. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +59 -0
  49. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +26 -0
  50. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +37 -0
  51. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +19 -0
  52. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +65 -0
  53. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +73 -0
  54. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +1 -0
  55. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +9 -0
  56. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +386 -0
  57. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +45 -0
  58. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +8 -0
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +16 -0
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +8 -0
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +3 -0
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +19 -0
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +969 -0
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +84 -0
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +48 -0
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +16 -0
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +103 -0
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +45 -0
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +151 -0
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +3 -0
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +297 -0
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +29 -0
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +6 -0
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +180 -0
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +23 -0
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +192 -0
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +11 -0
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +81 -0
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +93 -0
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +310 -0
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +109 -0
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +43 -0
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +171 -0
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +251 -0
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +305 -0
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +1297 -0
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +262 -0
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +396 -0
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +568 -0
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +337 -0
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +13 -0
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +463 -0
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +286 -0
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +155 -0
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +174 -0
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +308 -0
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +91 -0
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +95 -0
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +2050 -0
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +542 -0
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +8 -0
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +648 -0
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +381 -0
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +343 -0
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +48 -0
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +105 -0
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +72 -0
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +427 -0
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +427 -0
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +130 -0
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +96 -0
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +8 -0
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +548 -0
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +605 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +144 -0
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +1432 -0
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +213 -0
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +2 -0
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +65 -0
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +709 -0
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +1021 -0
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +104 -0
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +346 -0
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +467 -0
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +978 -0
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +55 -0
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +606 -0
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +284 -0
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +163 -0
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +121 -0
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +193 -0
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +275 -0
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +1741 -0
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +163 -0
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +65 -0
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +2497 -0
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +1879 -0
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +103 -0
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +375 -0
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +747 -0
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +88 -0
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +11 -0
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +52 -0
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +12 -0
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +6 -0
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +21 -0
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +482 -0
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +63 -0
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +41 -0
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +56 -0
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +155 -0
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +503 -0
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +208 -0
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +275 -0
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +73 -0
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +33 -0
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +279 -0
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +143 -0
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +85 -0
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +179 -0
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +151 -0
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +91 -0
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +85 -0
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +19 -0
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +12 -0
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +26 -0
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +25 -0
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +216 -0
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +163 -0
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +286 -0
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +536 -0
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +107 -0
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +248 -0
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +227 -0
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +202 -0
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +84 -0
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +210 -0
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +550 -0
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +473 -0
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +84 -0
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +21 -0
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +28 -0
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +39 -0
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +46 -0
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +6 -0
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +41 -0
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +35 -0
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +41 -0
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +10 -0
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +165 -0
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +53 -0
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +238 -0
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +126 -0
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +141 -0
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +117 -0
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +41 -0
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +50 -0
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +69 -0
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +42 -0
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +348 -0
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +771 -0
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +47 -0
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +22 -0
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +23 -0
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +326 -0
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +15 -0
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +148 -0
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +272 -0
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +119 -0
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +51 -0
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +5 -0
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +285 -0
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +12 -0
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +265 -0
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +397 -0
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +520 -0
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +49 -0
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +94 -0
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +125 -0
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +331 -0
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +153 -0
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +284 -0
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +107 -0
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +257 -0
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +412 -0
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +517 -0
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +102 -0
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +92 -0
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +233 -0
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +360 -0
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +472 -0
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +593 -0
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +524 -0
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +441 -0
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +103 -0
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +267 -0
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +73 -0
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +59 -0
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +235 -0
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +146 -0
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +189 -0
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +82 -0
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +560 -0
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +651 -0
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +500 -0
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +253 -0
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +452 -0
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +318 -0
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +342 -0
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +291 -0
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +131 -0
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +318 -0
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +144 -0
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +29 -0
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +66 -0
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +44 -0
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +22 -0
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +9 -0
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +510 -0
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +408 -0
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +140 -0
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +117 -0
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +70 -0
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +86 -0
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +257 -0
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +44 -0
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +23 -0
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +39 -0
  275. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +64 -0
  276. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +402 -0
  277. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +233 -0
  278. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +276 -0
  279. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +214 -0
  280. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +3 -0
  281. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +65 -0
  282. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +41 -0
  283. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +8 -0
  284. xcoll/scattering_routines/geant4/collimasim/setup.py +144 -0
  285. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +403 -0
  286. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +100 -0
  287. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +763 -0
  288. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +118 -0
  289. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +8 -0
  290. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +63 -0
  291. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +142 -0
  292. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +556 -0
  293. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +6 -0
  294. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +24 -0
  295. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +1 -0
  296. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +1 -0
  297. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +1 -0
  298. xcoll/scattering_routines/geant4/collimasim/tests/README.md +25 -0
  299. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +25 -0
  300. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +18 -0
  301. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +68 -0
  302. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +15 -0
  303. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +110 -0
  304. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +7 -0
  305. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +3 -0
  306. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +54 -0
  307. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +3 -0
  308. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +3 -0
  309. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +5 -0
  310. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +51 -0
  311. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +65 -0
  312. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +59 -0
  313. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +102 -0
  314. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +75 -0
  315. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +74 -0
  316. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +84 -0
  317. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +159 -0
  318. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +99 -0
  319. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +78 -0
  320. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +88 -0
  321. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +80 -0
  322. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +97 -0
  323. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +96 -0
  324. xcoll/scattering_routines/geometry/__init__.py +6 -0
  325. xcoll/scattering_routines/geometry/collimator_geometry.h +218 -0
  326. xcoll/scattering_routines/geometry/crystal_geometry.h +153 -0
  327. xcoll/scattering_routines/geometry/geometry.py +26 -0
  328. xcoll/scattering_routines/geometry/get_s.h +92 -0
  329. xcoll/scattering_routines/geometry/methods.h +111 -0
  330. xcoll/scattering_routines/geometry/objects.h +154 -0
  331. xcoll/scattering_routines/geometry/rotation.h +23 -0
  332. xcoll/scattering_routines/geometry/segments.h +226 -0
  333. xcoll/scattering_routines/geometry/sort.h +184 -0
  334. {xcoll-0.3.6.dist-info → xcoll-0.5.0.dist-info}/METADATA +1 -1
  335. xcoll-0.5.0.dist-info/RECORD +413 -0
  336. xcoll/beam_elements/collimators_src/absorber.h +0 -141
  337. xcoll/beam_elements/collimators_src/everest_collimator.h +0 -142
  338. xcoll/beam_elements/collimators_src/everest_crystal.h +0 -115
  339. xcoll/collimator_settings.py +0 -457
  340. xcoll/impacts/__init__.py +0 -1
  341. xcoll/impacts/impacts.py +0 -102
  342. xcoll/impacts/impacts_src/impacts.h +0 -99
  343. xcoll/scattering_routines/everest/crystal.h +0 -1302
  344. xcoll/scattering_routines/everest/scatter.h +0 -169
  345. xcoll/scattering_routines/everest/scatter_crystal.h +0 -260
  346. xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
  347. xcoll-0.3.6.dist-info/RECORD +0 -111
  348. {xcoll-0.3.6.dist-info → xcoll-0.5.0.dist-info}/LICENSE +0 -0
  349. {xcoll-0.3.6.dist-info → xcoll-0.5.0.dist-info}/NOTICE +0 -0
  350. {xcoll-0.3.6.dist-info → xcoll-0.5.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,520 @@
1
+ # -*- coding: utf-8 -*-
2
+ import re
3
+
4
+ import pytest
5
+
6
+ import env # noqa: F401
7
+ from pybind11_tests import ConstructorStats
8
+ from pybind11_tests import factory_constructors as m
9
+ from pybind11_tests.factory_constructors import tag
10
+
11
+
12
+ def test_init_factory_basic():
13
+ """Tests py::init_factory() wrapper around various ways of returning the object"""
14
+
15
+ cstats = [
16
+ ConstructorStats.get(c)
17
+ for c in [m.TestFactory1, m.TestFactory2, m.TestFactory3]
18
+ ]
19
+ cstats[0].alive() # force gc
20
+ n_inst = ConstructorStats.detail_reg_inst()
21
+
22
+ x1 = m.TestFactory1(tag.unique_ptr, 3)
23
+ assert x1.value == "3"
24
+ y1 = m.TestFactory1(tag.pointer)
25
+ assert y1.value == "(empty)"
26
+ z1 = m.TestFactory1("hi!")
27
+ assert z1.value == "hi!"
28
+
29
+ assert ConstructorStats.detail_reg_inst() == n_inst + 3
30
+
31
+ x2 = m.TestFactory2(tag.move)
32
+ assert x2.value == "(empty2)"
33
+ y2 = m.TestFactory2(tag.pointer, 7)
34
+ assert y2.value == "7"
35
+ z2 = m.TestFactory2(tag.unique_ptr, "hi again")
36
+ assert z2.value == "hi again"
37
+
38
+ assert ConstructorStats.detail_reg_inst() == n_inst + 6
39
+
40
+ x3 = m.TestFactory3(tag.shared_ptr)
41
+ assert x3.value == "(empty3)"
42
+ y3 = m.TestFactory3(tag.pointer, 42)
43
+ assert y3.value == "42"
44
+ z3 = m.TestFactory3("bye")
45
+ assert z3.value == "bye"
46
+
47
+ for null_ptr_kind in [tag.null_ptr, tag.null_unique_ptr, tag.null_shared_ptr]:
48
+ with pytest.raises(TypeError) as excinfo:
49
+ m.TestFactory3(null_ptr_kind)
50
+ assert (
51
+ str(excinfo.value) == "pybind11::init(): factory function returned nullptr"
52
+ )
53
+
54
+ assert [i.alive() for i in cstats] == [3, 3, 3]
55
+ assert ConstructorStats.detail_reg_inst() == n_inst + 9
56
+
57
+ del x1, y2, y3, z3
58
+ assert [i.alive() for i in cstats] == [2, 2, 1]
59
+ assert ConstructorStats.detail_reg_inst() == n_inst + 5
60
+ del x2, x3, y1, z1, z2
61
+ assert [i.alive() for i in cstats] == [0, 0, 0]
62
+ assert ConstructorStats.detail_reg_inst() == n_inst
63
+
64
+ assert [i.values() for i in cstats] == [
65
+ ["3", "hi!"],
66
+ ["7", "hi again"],
67
+ ["42", "bye"],
68
+ ]
69
+ assert [i.default_constructions for i in cstats] == [1, 1, 1]
70
+
71
+
72
+ def test_init_factory_signature(msg):
73
+ with pytest.raises(TypeError) as excinfo:
74
+ m.TestFactory1("invalid", "constructor", "arguments")
75
+ assert (
76
+ msg(excinfo.value)
77
+ == """
78
+ __init__(): incompatible constructor arguments. The following argument types are supported:
79
+ 1. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int)
80
+ 2. m.factory_constructors.TestFactory1(arg0: str)
81
+ 3. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.pointer_tag)
82
+ 4. m.factory_constructors.TestFactory1(arg0: handle, arg1: int, arg2: handle)
83
+
84
+ Invoked with: 'invalid', 'constructor', 'arguments'
85
+ """ # noqa: E501 line too long
86
+ )
87
+
88
+ assert (
89
+ msg(m.TestFactory1.__init__.__doc__)
90
+ == """
91
+ __init__(*args, **kwargs)
92
+ Overloaded function.
93
+
94
+ 1. __init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int) -> None
95
+
96
+ 2. __init__(self: m.factory_constructors.TestFactory1, arg0: str) -> None
97
+
98
+ 3. __init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.pointer_tag) -> None
99
+
100
+ 4. __init__(self: m.factory_constructors.TestFactory1, arg0: handle, arg1: int, arg2: handle) -> None
101
+ """ # noqa: E501 line too long
102
+ )
103
+
104
+
105
+ def test_init_factory_casting():
106
+ """Tests py::init_factory() wrapper with various upcasting and downcasting returns"""
107
+
108
+ cstats = [
109
+ ConstructorStats.get(c)
110
+ for c in [m.TestFactory3, m.TestFactory4, m.TestFactory5]
111
+ ]
112
+ cstats[0].alive() # force gc
113
+ n_inst = ConstructorStats.detail_reg_inst()
114
+
115
+ # Construction from derived references:
116
+ a = m.TestFactory3(tag.pointer, tag.TF4, 4)
117
+ assert a.value == "4"
118
+ b = m.TestFactory3(tag.shared_ptr, tag.TF4, 5)
119
+ assert b.value == "5"
120
+ c = m.TestFactory3(tag.pointer, tag.TF5, 6)
121
+ assert c.value == "6"
122
+ d = m.TestFactory3(tag.shared_ptr, tag.TF5, 7)
123
+ assert d.value == "7"
124
+
125
+ assert ConstructorStats.detail_reg_inst() == n_inst + 4
126
+
127
+ # Shared a lambda with TF3:
128
+ e = m.TestFactory4(tag.pointer, tag.TF4, 8)
129
+ assert e.value == "8"
130
+
131
+ assert ConstructorStats.detail_reg_inst() == n_inst + 5
132
+ assert [i.alive() for i in cstats] == [5, 3, 2]
133
+
134
+ del a
135
+ assert [i.alive() for i in cstats] == [4, 2, 2]
136
+ assert ConstructorStats.detail_reg_inst() == n_inst + 4
137
+
138
+ del b, c, e
139
+ assert [i.alive() for i in cstats] == [1, 0, 1]
140
+ assert ConstructorStats.detail_reg_inst() == n_inst + 1
141
+
142
+ del d
143
+ assert [i.alive() for i in cstats] == [0, 0, 0]
144
+ assert ConstructorStats.detail_reg_inst() == n_inst
145
+
146
+ assert [i.values() for i in cstats] == [
147
+ ["4", "5", "6", "7", "8"],
148
+ ["4", "5", "8"],
149
+ ["6", "7"],
150
+ ]
151
+
152
+
153
+ def test_init_factory_alias():
154
+ """Tests py::init_factory() wrapper with value conversions and alias types"""
155
+
156
+ cstats = [m.TestFactory6.get_cstats(), m.TestFactory6.get_alias_cstats()]
157
+ cstats[0].alive() # force gc
158
+ n_inst = ConstructorStats.detail_reg_inst()
159
+
160
+ a = m.TestFactory6(tag.base, 1)
161
+ assert a.get() == 1
162
+ assert not a.has_alias()
163
+ b = m.TestFactory6(tag.alias, "hi there")
164
+ assert b.get() == 8
165
+ assert b.has_alias()
166
+ c = m.TestFactory6(tag.alias, 3)
167
+ assert c.get() == 3
168
+ assert c.has_alias()
169
+ d = m.TestFactory6(tag.alias, tag.pointer, 4)
170
+ assert d.get() == 4
171
+ assert d.has_alias()
172
+ e = m.TestFactory6(tag.base, tag.pointer, 5)
173
+ assert e.get() == 5
174
+ assert not e.has_alias()
175
+ f = m.TestFactory6(tag.base, tag.alias, tag.pointer, 6)
176
+ assert f.get() == 6
177
+ assert f.has_alias()
178
+
179
+ assert ConstructorStats.detail_reg_inst() == n_inst + 6
180
+ assert [i.alive() for i in cstats] == [6, 4]
181
+
182
+ del a, b, e
183
+ assert [i.alive() for i in cstats] == [3, 3]
184
+ assert ConstructorStats.detail_reg_inst() == n_inst + 3
185
+ del f, c, d
186
+ assert [i.alive() for i in cstats] == [0, 0]
187
+ assert ConstructorStats.detail_reg_inst() == n_inst
188
+
189
+ class MyTest(m.TestFactory6):
190
+ def __init__(self, *args):
191
+ m.TestFactory6.__init__(self, *args)
192
+
193
+ def get(self):
194
+ return -5 + m.TestFactory6.get(self)
195
+
196
+ # Return Class by value, moved into new alias:
197
+ z = MyTest(tag.base, 123)
198
+ assert z.get() == 118
199
+ assert z.has_alias()
200
+
201
+ # Return alias by value, moved into new alias:
202
+ y = MyTest(tag.alias, "why hello!")
203
+ assert y.get() == 5
204
+ assert y.has_alias()
205
+
206
+ # Return Class by pointer, moved into new alias then original destroyed:
207
+ x = MyTest(tag.base, tag.pointer, 47)
208
+ assert x.get() == 42
209
+ assert x.has_alias()
210
+
211
+ assert ConstructorStats.detail_reg_inst() == n_inst + 3
212
+ assert [i.alive() for i in cstats] == [3, 3]
213
+ del x, y, z
214
+ assert [i.alive() for i in cstats] == [0, 0]
215
+ assert ConstructorStats.detail_reg_inst() == n_inst
216
+
217
+ assert [i.values() for i in cstats] == [
218
+ ["1", "8", "3", "4", "5", "6", "123", "10", "47"],
219
+ ["hi there", "3", "4", "6", "move", "123", "why hello!", "move", "47"],
220
+ ]
221
+
222
+
223
+ def test_init_factory_dual():
224
+ """Tests init factory functions with dual main/alias factory functions"""
225
+ from pybind11_tests.factory_constructors import TestFactory7
226
+
227
+ cstats = [TestFactory7.get_cstats(), TestFactory7.get_alias_cstats()]
228
+ cstats[0].alive() # force gc
229
+ n_inst = ConstructorStats.detail_reg_inst()
230
+
231
+ class PythFactory7(TestFactory7):
232
+ def get(self):
233
+ return 100 + TestFactory7.get(self)
234
+
235
+ a1 = TestFactory7(1)
236
+ a2 = PythFactory7(2)
237
+ assert a1.get() == 1
238
+ assert a2.get() == 102
239
+ assert not a1.has_alias()
240
+ assert a2.has_alias()
241
+
242
+ b1 = TestFactory7(tag.pointer, 3)
243
+ b2 = PythFactory7(tag.pointer, 4)
244
+ assert b1.get() == 3
245
+ assert b2.get() == 104
246
+ assert not b1.has_alias()
247
+ assert b2.has_alias()
248
+
249
+ c1 = TestFactory7(tag.mixed, 5)
250
+ c2 = PythFactory7(tag.mixed, 6)
251
+ assert c1.get() == 5
252
+ assert c2.get() == 106
253
+ assert not c1.has_alias()
254
+ assert c2.has_alias()
255
+
256
+ d1 = TestFactory7(tag.base, tag.pointer, 7)
257
+ d2 = PythFactory7(tag.base, tag.pointer, 8)
258
+ assert d1.get() == 7
259
+ assert d2.get() == 108
260
+ assert not d1.has_alias()
261
+ assert d2.has_alias()
262
+
263
+ # Both return an alias; the second multiplies the value by 10:
264
+ e1 = TestFactory7(tag.alias, tag.pointer, 9)
265
+ e2 = PythFactory7(tag.alias, tag.pointer, 10)
266
+ assert e1.get() == 9
267
+ assert e2.get() == 200
268
+ assert e1.has_alias()
269
+ assert e2.has_alias()
270
+
271
+ f1 = TestFactory7(tag.shared_ptr, tag.base, 11)
272
+ f2 = PythFactory7(tag.shared_ptr, tag.base, 12)
273
+ assert f1.get() == 11
274
+ assert f2.get() == 112
275
+ assert not f1.has_alias()
276
+ assert f2.has_alias()
277
+
278
+ g1 = TestFactory7(tag.shared_ptr, tag.invalid_base, 13)
279
+ assert g1.get() == 13
280
+ assert not g1.has_alias()
281
+ with pytest.raises(TypeError) as excinfo:
282
+ PythFactory7(tag.shared_ptr, tag.invalid_base, 14)
283
+ assert (
284
+ str(excinfo.value)
285
+ == "pybind11::init(): construction failed: returned holder-wrapped instance is not an "
286
+ "alias instance"
287
+ )
288
+
289
+ assert [i.alive() for i in cstats] == [13, 7]
290
+ assert ConstructorStats.detail_reg_inst() == n_inst + 13
291
+
292
+ del a1, a2, b1, d1, e1, e2
293
+ assert [i.alive() for i in cstats] == [7, 4]
294
+ assert ConstructorStats.detail_reg_inst() == n_inst + 7
295
+ del b2, c1, c2, d2, f1, f2, g1
296
+ assert [i.alive() for i in cstats] == [0, 0]
297
+ assert ConstructorStats.detail_reg_inst() == n_inst
298
+
299
+ assert [i.values() for i in cstats] == [
300
+ ["1", "2", "3", "4", "5", "6", "7", "8", "9", "100", "11", "12", "13", "14"],
301
+ ["2", "4", "6", "8", "9", "100", "12"],
302
+ ]
303
+
304
+
305
+ def test_no_placement_new(capture):
306
+ """Prior to 2.2, `py::init<...>` relied on the type supporting placement
307
+ new; this tests a class without placement new support."""
308
+ with capture:
309
+ a = m.NoPlacementNew(123)
310
+
311
+ found = re.search(r"^operator new called, returning (\d+)\n$", str(capture))
312
+ assert found
313
+ assert a.i == 123
314
+ with capture:
315
+ del a
316
+ pytest.gc_collect()
317
+ assert capture == "operator delete called on " + found.group(1)
318
+
319
+ with capture:
320
+ b = m.NoPlacementNew()
321
+
322
+ found = re.search(r"^operator new called, returning (\d+)\n$", str(capture))
323
+ assert found
324
+ assert b.i == 100
325
+ with capture:
326
+ del b
327
+ pytest.gc_collect()
328
+ assert capture == "operator delete called on " + found.group(1)
329
+
330
+
331
+ def test_multiple_inheritance():
332
+ class MITest(m.TestFactory1, m.TestFactory2):
333
+ def __init__(self):
334
+ m.TestFactory1.__init__(self, tag.unique_ptr, 33)
335
+ m.TestFactory2.__init__(self, tag.move)
336
+
337
+ a = MITest()
338
+ assert m.TestFactory1.value.fget(a) == "33"
339
+ assert m.TestFactory2.value.fget(a) == "(empty2)"
340
+
341
+
342
+ def create_and_destroy(*args):
343
+ a = m.NoisyAlloc(*args)
344
+ print("---")
345
+ del a
346
+ pytest.gc_collect()
347
+
348
+
349
+ def strip_comments(s):
350
+ return re.sub(r"\s+#.*", "", s)
351
+
352
+
353
+ def test_reallocation_a(capture, msg):
354
+ """When the constructor is overloaded, previous overloads can require a preallocated value.
355
+ This test makes sure that such preallocated values only happen when they might be necessary,
356
+ and that they are deallocated properly."""
357
+
358
+ pytest.gc_collect()
359
+
360
+ with capture:
361
+ create_and_destroy(1)
362
+ assert (
363
+ msg(capture)
364
+ == """
365
+ noisy new
366
+ noisy placement new
367
+ NoisyAlloc(int 1)
368
+ ---
369
+ ~NoisyAlloc()
370
+ noisy delete
371
+ """
372
+ )
373
+
374
+
375
+ def test_reallocation_b(capture, msg):
376
+ with capture:
377
+ create_and_destroy(1.5)
378
+ assert msg(capture) == strip_comments(
379
+ """
380
+ noisy new # allocation required to attempt first overload
381
+ noisy delete # have to dealloc before considering factory init overload
382
+ noisy new # pointer factory calling "new", part 1: allocation
383
+ NoisyAlloc(double 1.5) # ... part two, invoking constructor
384
+ ---
385
+ ~NoisyAlloc() # Destructor
386
+ noisy delete # operator delete
387
+ """
388
+ )
389
+
390
+
391
+ def test_reallocation_c(capture, msg):
392
+ with capture:
393
+ create_and_destroy(2, 3)
394
+ assert msg(capture) == strip_comments(
395
+ """
396
+ noisy new # pointer factory calling "new", allocation
397
+ NoisyAlloc(int 2) # constructor
398
+ ---
399
+ ~NoisyAlloc() # Destructor
400
+ noisy delete # operator delete
401
+ """
402
+ )
403
+
404
+
405
+ def test_reallocation_d(capture, msg):
406
+ with capture:
407
+ create_and_destroy(2.5, 3)
408
+ assert msg(capture) == strip_comments(
409
+ """
410
+ NoisyAlloc(double 2.5) # construction (local func variable: operator_new not called)
411
+ noisy new # return-by-value "new" part 1: allocation
412
+ ~NoisyAlloc() # moved-away local func variable destruction
413
+ ---
414
+ ~NoisyAlloc() # Destructor
415
+ noisy delete # operator delete
416
+ """
417
+ )
418
+
419
+
420
+ def test_reallocation_e(capture, msg):
421
+ with capture:
422
+ create_and_destroy(3.5, 4.5)
423
+ assert msg(capture) == strip_comments(
424
+ """
425
+ noisy new # preallocation needed before invoking placement-new overload
426
+ noisy placement new # Placement new
427
+ NoisyAlloc(double 3.5) # construction
428
+ ---
429
+ ~NoisyAlloc() # Destructor
430
+ noisy delete # operator delete
431
+ """
432
+ )
433
+
434
+
435
+ def test_reallocation_f(capture, msg):
436
+ with capture:
437
+ create_and_destroy(4, 0.5)
438
+ assert msg(capture) == strip_comments(
439
+ """
440
+ noisy new # preallocation needed before invoking placement-new overload
441
+ noisy delete # deallocation of preallocated storage
442
+ noisy new # Factory pointer allocation
443
+ NoisyAlloc(int 4) # factory pointer construction
444
+ ---
445
+ ~NoisyAlloc() # Destructor
446
+ noisy delete # operator delete
447
+ """
448
+ )
449
+
450
+
451
+ def test_reallocation_g(capture, msg):
452
+ with capture:
453
+ create_and_destroy(5, "hi")
454
+ assert msg(capture) == strip_comments(
455
+ """
456
+ noisy new # preallocation needed before invoking first placement new
457
+ noisy delete # delete before considering new-style constructor
458
+ noisy new # preallocation for second placement new
459
+ noisy placement new # Placement new in the second placement new overload
460
+ NoisyAlloc(int 5) # construction
461
+ ---
462
+ ~NoisyAlloc() # Destructor
463
+ noisy delete # operator delete
464
+ """
465
+ )
466
+
467
+
468
+ @pytest.mark.skipif("env.PY2")
469
+ def test_invalid_self():
470
+ """Tests invocation of the pybind-registered base class with an invalid `self` argument. You
471
+ can only actually do this on Python 3: Python 2 raises an exception itself if you try."""
472
+
473
+ class NotPybindDerived(object):
474
+ pass
475
+
476
+ # Attempts to initialize with an invalid type passed as `self`:
477
+ class BrokenTF1(m.TestFactory1):
478
+ def __init__(self, bad):
479
+ if bad == 1:
480
+ a = m.TestFactory2(tag.pointer, 1)
481
+ m.TestFactory1.__init__(a, tag.pointer)
482
+ elif bad == 2:
483
+ a = NotPybindDerived()
484
+ m.TestFactory1.__init__(a, tag.pointer)
485
+
486
+ # Same as above, but for a class with an alias:
487
+ class BrokenTF6(m.TestFactory6):
488
+ def __init__(self, bad):
489
+ if bad == 0:
490
+ m.TestFactory6.__init__()
491
+ elif bad == 1:
492
+ a = m.TestFactory2(tag.pointer, 1)
493
+ m.TestFactory6.__init__(a, tag.base, 1)
494
+ elif bad == 2:
495
+ a = m.TestFactory2(tag.pointer, 1)
496
+ m.TestFactory6.__init__(a, tag.alias, 1)
497
+ elif bad == 3:
498
+ m.TestFactory6.__init__(
499
+ NotPybindDerived.__new__(NotPybindDerived), tag.base, 1
500
+ )
501
+ elif bad == 4:
502
+ m.TestFactory6.__init__(
503
+ NotPybindDerived.__new__(NotPybindDerived), tag.alias, 1
504
+ )
505
+
506
+ for arg in (1, 2):
507
+ with pytest.raises(TypeError) as excinfo:
508
+ BrokenTF1(arg)
509
+ assert (
510
+ str(excinfo.value)
511
+ == "__init__(self, ...) called with invalid or missing `self` argument"
512
+ )
513
+
514
+ for arg in (0, 1, 2, 3, 4):
515
+ with pytest.raises(TypeError) as excinfo:
516
+ BrokenTF6(arg)
517
+ assert (
518
+ str(excinfo.value)
519
+ == "__init__(self, ...) called with invalid or missing `self` argument"
520
+ )
@@ -0,0 +1,49 @@
1
+ /*
2
+ tests/test_gil_scoped.cpp -- acquire and release gil
3
+
4
+ Copyright (c) 2017 Borja Zarco (Google LLC) <bzarco@google.com>
5
+
6
+ All rights reserved. Use of this source code is governed by a
7
+ BSD-style license that can be found in the LICENSE file.
8
+ */
9
+
10
+ #include "pybind11_tests.h"
11
+ #include <pybind11/functional.h>
12
+
13
+
14
+ class VirtClass {
15
+ public:
16
+ virtual ~VirtClass() = default;
17
+ VirtClass() = default;
18
+ VirtClass(const VirtClass&) = delete;
19
+ virtual void virtual_func() {}
20
+ virtual void pure_virtual_func() = 0;
21
+ };
22
+
23
+ class PyVirtClass : public VirtClass {
24
+ void virtual_func() override {
25
+ PYBIND11_OVERRIDE(void, VirtClass, virtual_func,);
26
+ }
27
+ void pure_virtual_func() override {
28
+ PYBIND11_OVERRIDE_PURE(void, VirtClass, pure_virtual_func,);
29
+ }
30
+ };
31
+
32
+ TEST_SUBMODULE(gil_scoped, m) {
33
+ py::class_<VirtClass, PyVirtClass>(m, "VirtClass")
34
+ .def(py::init<>())
35
+ .def("virtual_func", &VirtClass::virtual_func)
36
+ .def("pure_virtual_func", &VirtClass::pure_virtual_func);
37
+
38
+ m.def("test_callback_py_obj", [](py::object &func) { func(); });
39
+ m.def("test_callback_std_func", [](const std::function<void()> &func) { func(); });
40
+ m.def("test_callback_virtual_func", [](VirtClass &virt) { virt.virtual_func(); });
41
+ m.def("test_callback_pure_virtual_func", [](VirtClass &virt) { virt.pure_virtual_func(); });
42
+ m.def("test_cross_module_gil", []() {
43
+ auto cm = py::module_::import("cross_module_gil_utils");
44
+ auto gil_acquire
45
+ = reinterpret_cast<void (*)()>(PyLong_AsVoidPtr(cm.attr("gil_acquire_funcaddr").ptr()));
46
+ py::gil_scoped_release gil_release;
47
+ gil_acquire();
48
+ });
49
+ }
@@ -0,0 +1,94 @@
1
+ # -*- coding: utf-8 -*-
2
+ import multiprocessing
3
+ import threading
4
+
5
+ from pybind11_tests import gil_scoped as m
6
+
7
+
8
+ def _run_in_process(target, *args, **kwargs):
9
+ """Runs target in process and returns its exitcode after 10s (None if still alive)."""
10
+ process = multiprocessing.Process(target=target, args=args, kwargs=kwargs)
11
+ process.daemon = True
12
+ try:
13
+ process.start()
14
+ # Do not need to wait much, 10s should be more than enough.
15
+ process.join(timeout=10)
16
+ return process.exitcode
17
+ finally:
18
+ if process.is_alive():
19
+ process.terminate()
20
+
21
+
22
+ def _python_to_cpp_to_python():
23
+ """Calls different C++ functions that come back to Python."""
24
+
25
+ class ExtendedVirtClass(m.VirtClass):
26
+ def virtual_func(self):
27
+ pass
28
+
29
+ def pure_virtual_func(self):
30
+ pass
31
+
32
+ extended = ExtendedVirtClass()
33
+ m.test_callback_py_obj(lambda: None)
34
+ m.test_callback_std_func(lambda: None)
35
+ m.test_callback_virtual_func(extended)
36
+ m.test_callback_pure_virtual_func(extended)
37
+
38
+
39
+ def _python_to_cpp_to_python_from_threads(num_threads, parallel=False):
40
+ """Calls different C++ functions that come back to Python, from Python threads."""
41
+ threads = []
42
+ for _ in range(num_threads):
43
+ thread = threading.Thread(target=_python_to_cpp_to_python)
44
+ thread.daemon = True
45
+ thread.start()
46
+ if parallel:
47
+ threads.append(thread)
48
+ else:
49
+ thread.join()
50
+ for thread in threads:
51
+ thread.join()
52
+
53
+
54
+ # TODO: FIXME, sometimes returns -11 (segfault) instead of 0 on macOS Python 3.9
55
+ def test_python_to_cpp_to_python_from_thread():
56
+ """Makes sure there is no GIL deadlock when running in a thread.
57
+
58
+ It runs in a separate process to be able to stop and assert if it deadlocks.
59
+ """
60
+ assert _run_in_process(_python_to_cpp_to_python_from_threads, 1) == 0
61
+
62
+
63
+ # TODO: FIXME on macOS Python 3.9
64
+ def test_python_to_cpp_to_python_from_thread_multiple_parallel():
65
+ """Makes sure there is no GIL deadlock when running in a thread multiple times in parallel.
66
+
67
+ It runs in a separate process to be able to stop and assert if it deadlocks.
68
+ """
69
+ assert _run_in_process(_python_to_cpp_to_python_from_threads, 8, parallel=True) == 0
70
+
71
+
72
+ # TODO: FIXME on macOS Python 3.9
73
+ def test_python_to_cpp_to_python_from_thread_multiple_sequential():
74
+ """Makes sure there is no GIL deadlock when running in a thread multiple times sequentially.
75
+
76
+ It runs in a separate process to be able to stop and assert if it deadlocks.
77
+ """
78
+ assert (
79
+ _run_in_process(_python_to_cpp_to_python_from_threads, 8, parallel=False) == 0
80
+ )
81
+
82
+
83
+ # TODO: FIXME on macOS Python 3.9
84
+ def test_python_to_cpp_to_python_from_process():
85
+ """Makes sure there is no GIL deadlock when using processes.
86
+
87
+ This test is for completion, but it was never an issue.
88
+ """
89
+ assert _run_in_process(_python_to_cpp_to_python) == 0
90
+
91
+
92
+ def test_cross_module_gil():
93
+ """Makes sure that the GIL can be acquired by another module from a GIL-released state."""
94
+ m.test_cross_module_gil() # Should not raise a SIGSEGV