gpflash 0.3.0__tar.gz → 0.3.1__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 (152) hide show
  1. {gpflash-0.3.0 → gpflash-0.3.1}/.github/workflows/wheels.yml +2 -2
  2. {gpflash-0.3.0 → gpflash-0.3.1}/CHANGELOG.md +19 -0
  3. {gpflash-0.3.0 → gpflash-0.3.1}/PKG-INFO +8 -4
  4. {gpflash-0.3.0 → gpflash-0.3.1}/README.md +4 -3
  5. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/Version.hpp +1 -1
  6. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/core/Platform.hpp +2 -1
  7. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_cache/Hdf5Store.hpp +12 -2
  8. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_cache/PosteriorCache.hpp +12 -2
  9. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_cache/README.md +3 -1
  10. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_eval/PosteriorOptions.hpp +4 -4
  11. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_eval/PosteriorQuery.hpp +9 -6
  12. {gpflash-0.3.0 → gpflash-0.3.1}/pyproject.toml +1 -1
  13. gpflash-0.3.1/python/CMakeLists.txt +44 -0
  14. {gpflash-0.3.0 → gpflash-0.3.1}/python/README.md +7 -3
  15. {gpflash-0.3.0 → gpflash-0.3.1}/python/ci/install_deps_unix.sh +2 -1
  16. {gpflash-0.3.0 → gpflash-0.3.1}/python/gpflash/__init__.py +5 -0
  17. {gpflash-0.3.0 → gpflash-0.3.1}/python/gpflash/_gp.py +3 -1
  18. {gpflash-0.3.0 → gpflash-0.3.1}/python/src/bindings.cpp +2 -1
  19. {gpflash-0.3.0 → gpflash-0.3.1}/python/tests/test_gaussian_process.py +60 -0
  20. gpflash-0.3.1/python/tests/test_openmp_isolation.py +66 -0
  21. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_cache.cpp +99 -8
  22. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_input_validation.cpp +20 -5
  23. gpflash-0.3.0/python/CMakeLists.txt +0 -19
  24. {gpflash-0.3.0 → gpflash-0.3.1}/.clang-format +0 -0
  25. {gpflash-0.3.0 → gpflash-0.3.1}/.github/workflows/ci.yml +0 -0
  26. {gpflash-0.3.0 → gpflash-0.3.1}/.github/workflows/weekly.yml +0 -0
  27. {gpflash-0.3.0 → gpflash-0.3.1}/.gitignore +0 -0
  28. {gpflash-0.3.0 → gpflash-0.3.1}/CITATION.cff +0 -0
  29. {gpflash-0.3.0 → gpflash-0.3.1}/CMakeLists.txt +0 -0
  30. {gpflash-0.3.0 → gpflash-0.3.1}/LICENSE +0 -0
  31. {gpflash-0.3.0 → gpflash-0.3.1}/NOTICE +0 -0
  32. {gpflash-0.3.0 → gpflash-0.3.1}/THIRD-PARTY-NOTICES +0 -0
  33. {gpflash-0.3.0 → gpflash-0.3.1}/cmake/GpFlashConfig.cmake.in +0 -0
  34. {gpflash-0.3.0 → gpflash-0.3.1}/cmake/GpFlashDependencies.cmake +0 -0
  35. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/CholTerms.hpp +0 -0
  36. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/EtaTermHpGrad.hpp +0 -0
  37. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/KernTermHpGrad.hpp +0 -0
  38. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/KernelAssembly.hpp +0 -0
  39. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/KernelMatrix.hpp +0 -0
  40. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/KernelMatrixGrad.hpp +0 -0
  41. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/KmatNuggetGrad.hpp +0 -0
  42. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/PosteriorCovariance.hpp +0 -0
  43. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/SigmaGrad.hpp +0 -0
  44. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/SigmaMatrix.hpp +0 -0
  45. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/assembly/SymmetryMatrix.hpp +0 -0
  46. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/core/Errors.hpp +0 -0
  47. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/core/NoiseModel.hpp +0 -0
  48. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/core/ParallelContext.hpp +0 -0
  49. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/core/StringFormat.hpp +0 -0
  50. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/inputs/EigMaxUbMethod.hpp +0 -0
  51. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/inputs/HpVal.hpp +0 -0
  52. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/inputs/KernelId.hpp +0 -0
  53. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/inputs/ModelOptions.hpp +0 -0
  54. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/inputs/SymmetrySpec.hpp +0 -0
  55. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/inputs/TrainingData.hpp +0 -0
  56. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/HpGradInputs.hpp +0 -0
  57. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/KernelBase.hpp +0 -0
  58. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/KernelDispatch.hpp +0 -0
  59. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/KernelStationary.hpp +0 -0
  60. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/OptzSeeding.hpp +0 -0
  61. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/inner_product/KernelInnerProduct.hpp +0 -0
  62. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/inner_product/Linear.hpp +0 -0
  63. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/inner_product/Quadratic.hpp +0 -0
  64. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/radial/KernelRadial.hpp +0 -0
  65. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/radial/Matern32.hpp +0 -0
  66. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/radial/Matern52.hpp +0 -0
  67. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/radial/RatQuad.hpp +0 -0
  68. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/radial/SqExp.hpp +0 -0
  69. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/kernels/stationary/Periodic.hpp +0 -0
  70. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/linear_algebra/BlasLapack.hpp +0 -0
  71. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/linear_algebra/Cholesky.hpp +0 -0
  72. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/linear_algebra/InnerProducts.hpp +0 -0
  73. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/linear_algebra/RecursiveInv.hpp +0 -0
  74. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/mean/MeanModel.hpp +0 -0
  75. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/mean/MeanModelWeights.hpp +0 -0
  76. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/HpOptimizer.hpp +0 -0
  77. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/MllOptzObjective.hpp +0 -0
  78. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/MllOptzResult.hpp +0 -0
  79. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/MultistartReport.hpp +0 -0
  80. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/README.md +0 -0
  81. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/local_optz/LocalOptzResult.hpp +0 -0
  82. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/local_optz/OptimizerNlopt.hpp +0 -0
  83. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/multistart/LatinHypercube.hpp +0 -0
  84. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/multistart/MultistartResult.hpp +0 -0
  85. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/multistart/OptimumClusters.hpp +0 -0
  86. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/multistart/RunMultistart.hpp +0 -0
  87. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/search_space/ActiveBounds.hpp +0 -0
  88. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/search_space/HpAtBound.hpp +0 -0
  89. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/search_space/HpOptzLayout.hpp +0 -0
  90. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/search_space/OptzOptions.hpp +0 -0
  91. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/optimization/search_space/OptzRegion.hpp +0 -0
  92. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_build/PosteriorBuild.hpp +0 -0
  93. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_cache/CacheInfo.hpp +0 -0
  94. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_cache/CacheInputHash.hpp +0 -0
  95. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_cache/CacheLayout.hpp +0 -0
  96. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_cache/PosteriorContents.hpp +0 -0
  97. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_cache/PosteriorModelInfo.hpp +0 -0
  98. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_cache/PosteriorPrecompute.hpp +0 -0
  99. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_eval/GpPosterior.hpp +0 -0
  100. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_eval/PosteriorEval.hpp +0 -0
  101. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_eval/PosteriorGrad.hpp +0 -0
  102. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/posterior_eval/PosteriorResult.hpp +0 -0
  103. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/preconditioning/ConditionedCholesky.hpp +0 -0
  104. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/preconditioning/EtaTerms.hpp +0 -0
  105. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/preconditioning/PreconScales.hpp +0 -0
  106. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/training/EvalMll.hpp +0 -0
  107. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/training/EvalMllDispatch.hpp +0 -0
  108. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/training/EvalMllGrad.hpp +0 -0
  109. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/training/EvalVariances.hpp +0 -0
  110. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/training/MllHpGrad.hpp +0 -0
  111. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/training/MllResult.hpp +0 -0
  112. {gpflash-0.3.0 → gpflash-0.3.1}/include/gpflash/training/StageTiming.hpp +0 -0
  113. {gpflash-0.3.0 → gpflash-0.3.1}/python/LICENSES_bundled.txt +0 -0
  114. {gpflash-0.3.0 → gpflash-0.3.1}/python/ci/install_deps_windows.ps1 +0 -0
  115. {gpflash-0.3.0 → gpflash-0.3.1}/python/gpflash/_core.pyi +0 -0
  116. {gpflash-0.3.0 → gpflash-0.3.1}/python/gpflash/py.typed +0 -0
  117. {gpflash-0.3.0 → gpflash-0.3.1}/python/tests/test_core.py +0 -0
  118. {gpflash-0.3.0 → gpflash-0.3.1}/python/tests/test_diagnostics.py +0 -0
  119. {gpflash-0.3.0 → gpflash-0.3.1}/python/tests/test_numerics.py +0 -0
  120. {gpflash-0.3.0 → gpflash-0.3.1}/tst/CMakeLists.txt +0 -0
  121. {gpflash-0.3.0 → gpflash-0.3.1}/tst/GpFlashTestSupport.hpp +0 -0
  122. {gpflash-0.3.0 → gpflash-0.3.1}/tst/check_formatting.cmake +0 -0
  123. {gpflash-0.3.0 → gpflash-0.3.1}/tst/check_prediction_only_includes.cmake +0 -0
  124. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_chol_solves.cpp +0 -0
  125. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_inner_product_gradient.cpp +0 -0
  126. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_kernel_assembly.cpp +0 -0
  127. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_kernel_center.cpp +0 -0
  128. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_kernel_contract.cpp +0 -0
  129. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_kernel_finite_difference.cpp +0 -0
  130. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_kernel_matrix_grad.cpp +0 -0
  131. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_kernel_posterior_assembly.cpp +0 -0
  132. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_kmat_nugget.cpp +0 -0
  133. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_kmat_nugget_grad.cpp +0 -0
  134. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_linear.cpp +0 -0
  135. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_local_optz.cpp +0 -0
  136. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_multistart.cpp +0 -0
  137. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_multistart_report.cpp +0 -0
  138. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_optimizer.cpp +0 -0
  139. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_optimizer_mpi.cpp +0 -0
  140. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_optimizer_periodic.cpp +0 -0
  141. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_periodic.cpp +0 -0
  142. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_posterior.cpp +0 -0
  143. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_posterior_nonradial.cpp +0 -0
  144. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_recursive_inv.cpp +0 -0
  145. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_search_space.cpp +0 -0
  146. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_sigma_matrix.cpp +0 -0
  147. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_stage_timing.cpp +0 -0
  148. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_string_format.cpp +0 -0
  149. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_struct_checks.cpp +0 -0
  150. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_symmetry.cpp +0 -0
  151. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_training.cpp +0 -0
  152. {gpflash-0.3.0 → gpflash-0.3.1}/tst/test_gpflash_version.cpp +0 -0
@@ -72,8 +72,8 @@ jobs:
72
72
  key: windows-deps-${{ hashFiles('python/ci/install_deps_windows.ps1') }}
73
73
  - uses: pypa/cibuildwheel@v4.2.1
74
74
  env:
75
- # The oldest macOS the wheel runs on. It must not be older than the Homebrew libraries delocate bundles,
76
- # which are built for the runner's own macOS.
75
+ # The oldest macOS the wheel runs on. It must not be older than Homebrew's libomp, which the module links
76
+ # statically and which is built for the runner's own macOS.
77
77
  MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macos_deployment_target }}
78
78
  - name: Check Windows libraries
79
79
  id: windows_deps_check
@@ -3,6 +3,25 @@
3
3
  Every release of GpFlash and what it changed. Version numbers follow
4
4
  [semantic versioning](https://semver.org); before 1.0, a minor release may change the interface.
5
5
 
6
+ ## 0.3.1 (2026-11-05)
7
+
8
+ ### Fixed
9
+
10
+ - The cache calls (`peek_info`, `peek_kernel_id`, `save_precompute`, `load_posterior`, `load_posterior_verified` and
11
+ the `load_precompute` functions) may run on several threads at once: they hold one process-wide lock, so a second
12
+ call waits for the first, even on another file. HDF5 is not built thread-safe, and two calls that overlapped,
13
+ as Python threads could since the bindings release the GIL, could crash or corrupt its state.
14
+ - A query checks its points' row count even with `PosteriorOptions::check_query_points` cleared, which now skips only
15
+ the finiteness check. Before, clearing it let a point of the wrong dimension read out of bounds. A query that asks
16
+ for nothing now raises on a wrong row count too, rather than returning an empty result.
17
+ - **Python:** the macOS wheel links the OpenMP runtime statically and exports only the module's entry point, so it
18
+ runs in a process that has imported PyTorch, which loads its own copy of the runtime.
19
+
20
+ ### Changed
21
+
22
+ - The README and `core/Platform.hpp` say that GpFlash's declarations of glibc's vector `exp`, `log`, `pow`, `sin` and
23
+ `cos` apply to every call to them in a file that includes a GpFlash header, the caller's own included.
24
+
6
25
  ## 0.3.0 (2026-10-18)
7
26
 
8
27
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gpflash
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Fast, exact Gaussian process regression: marginal log-likelihood with analytic gradients, hyperparameter fitting and posterior evaluation.
5
5
  Keywords: gaussian-process,kriging,surrogate-model,bayesian-optimization,machine-learning
6
6
  Author: André Marchildon
@@ -164,9 +164,13 @@ cores through OpenMP.
164
164
  ## Threads
165
165
 
166
166
  Fits and queries run in parallel with OpenMP and release the GIL, so other Python threads run
167
- meanwhile. `OMP_NUM_THREADS` sets the thread count. Loading two different OpenMP runtimes into
168
- one process, for example GpFlash's alongside another library's, can slow both down; if that
169
- happens, set `OMP_NUM_THREADS` or import one library at a time.
167
+ meanwhile. The cache calls (`peek_info`, `peek_kernel_id`, `load_posterior`, `load_posterior_verified`,
168
+ `GpPosterior.save_precompute` and the `GaussianProcess` methods that call them) read and write HDF5,
169
+ which is not built thread-safe, so GpFlash runs them one at a time: a second cache call waits for the
170
+ first, even on another file. `OMP_NUM_THREADS` sets the thread count. On macOS the module carries its
171
+ own OpenMP runtime, linked in and hidden, so it loads beside another library's, such as PyTorch's.
172
+ Two runtimes in one process can still slow each other down when both run threads at once; if that
173
+ happens, set `OMP_NUM_THREADS`.
170
174
 
171
175
  ## Building from source
172
176
 
@@ -340,9 +340,10 @@ the first three rows, or an Armadillo configured otherwise, at compile time (`li
340
340
  Compile as C++14 or later with OpenMP enabled, and add:
341
341
 
342
342
  - `-funroll-loops`: faster batch posterior evaluation.
343
- - `-fno-math-errno`: with GCC on x86-64 Linux, lets the kernels' `exp`, `log`, `pow`, `sin` and `cos` vectorize. The
344
- vectorized functions can differ from the scalar ones in the last bits; define `GPFLASH_NO_VECTOR_MATH` to keep the
345
- scalar ones.
343
+ - `-fno-math-errno`: with GCC on x86-64 Linux, lets the kernels' `exp`, `log`, `pow`, `sin` and `cos` vectorize.
344
+ GpFlash declares glibc's vector versions of these five functions, so they also apply to your own calls to them in
345
+ any file that includes a GpFlash header. The vectorized functions can differ from the scalar ones in the last bits;
346
+ define `GPFLASH_NO_VECTOR_MATH` to keep the scalar ones everywhere.
346
347
 
347
348
  Do not use `-ffast-math` or `-Ofast`: they fold `std::isfinite` to true, which disables the input validation, and
348
349
  `core/Platform.hpp` rejects them.
@@ -11,7 +11,7 @@
11
11
 
12
12
  #define GPFLASH_VERSION_MAJOR 0
13
13
  #define GPFLASH_VERSION_MINOR 3
14
- #define GPFLASH_VERSION_PATCH 0
14
+ #define GPFLASH_VERSION_PATCH 1
15
15
 
16
16
  namespace gpflash {
17
17
 
@@ -21,7 +21,8 @@
21
21
 
22
22
  // ── Vector math (GCC, glibc, x86-64) ─────────────────────────────────────────
23
23
  // glibc declares its SIMD exp, log, pow, sin and cos only under __FAST_MATH__; without them GCC cannot vectorize the
24
- // kernel loops. Needs -fno-math-errno. GPFLASH_NO_VECTOR_MATH keeps the scalar versions.
24
+ // kernel loops. Needs -fno-math-errno. The declarations are global, so they cover every call to these five functions
25
+ // in a file that includes a GpFlash header, the caller's own included. GPFLASH_NO_VECTOR_MATH keeps the scalar ones.
25
26
  #include <cmath>
26
27
  #if defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__) && defined(__GLIBC__) && !defined(__FAST_MATH__) \
27
28
  && !defined(GPFLASH_NO_VECTOR_MATH)
@@ -6,8 +6,9 @@
6
6
  * HDF5 error dump. Added on top: exceptions naming the array and file, an existence probe, a read straight into
7
7
  * caller memory, an atomic replace, and strings as byte arrays.
8
8
  *
9
- * Not safe to call concurrently: HDF5 is linked without --enable-threadsafe, so its global state makes two
10
- * simultaneous calls unsafe even to different files.
9
+ * HDF5 is linked without --enable-threadsafe, so its global state makes two simultaneous calls unsafe even to
10
+ * different files. The cache's entry points (PosteriorCache.hpp) therefore each hold cache_mutex for their whole call;
11
+ * these primitives take no lock of their own.
11
12
  */
12
13
  #pragma once
13
14
 
@@ -21,6 +22,7 @@
21
22
  #include <algorithm> // std::find
22
23
  #include <cstdio> // std::rename, std::remove
23
24
  #include <fstream> // has_file
25
+ #include <mutex> // cache_mutex
24
26
  #include <string>
25
27
  #include <vector> // list_open_files
26
28
 
@@ -43,6 +45,14 @@ inline bool has_file(const std::string& path) { return std::ifstream(path.c_str(
43
45
 
44
46
  namespace detail {
45
47
 
48
+ // The one lock every cache entry point holds, so that two threads' cache calls run one after the other. One whole call,
49
+ // not each array: a failed save closes every file opened since its start, which must not include another thread's. A
50
+ // function-local static, so one lock per program, or per shared library on platforms that keep their symbols apart.
51
+ inline std::mutex& cache_mutex() {
52
+ static std::mutex mutex;
53
+ return mutex;
54
+ }
55
+
46
56
  // Every failure in the cache, named for the function that raised it. One type for all of them, so a caller can
47
57
  // tell a rejected file from an unrelated exception such as a failed allocation.
48
58
  inline ErrorInvalidInput cache_error(const char* caller, const std::string& what_failed) {
@@ -5,12 +5,15 @@
5
5
  * Reading never creates, modifies, or removes a file -- every failure is a throw. Only save_precompute writes,
6
6
  * and it writes one file, removing nothing but its own scratch file.
7
7
  *
8
- * Not safe to call concurrently, reads included, even on different files; see Hdf5Store.hpp.
8
+ * Safe to call from several threads: each entry point holds detail::cache_mutex for its whole call, since HDF5 is not
9
+ * built thread-safe (Hdf5Store.hpp). A second call waits for the first, even on another file. The caller's own HDF5
10
+ * calls take no part in the lock and must not overlap these.
9
11
  */
10
12
  #pragma once
11
13
 
12
14
  #include <armadillo>
13
15
  #include <cstdio> // std::remove
16
+ #include <mutex> // std::lock_guard
14
17
  #include <string>
15
18
  #include <utility> // std::move
16
19
 
@@ -27,7 +30,10 @@ namespace cache {
27
30
 
28
31
  // What the file says about itself, without loading the arrays. Raises on an unreadable file, one another format
29
32
  // version wrote, or an impossible stored value; the kernel and hash checks need what only the load path is given.
30
- inline CacheInfo peek_info(const std::string& path) { return detail::load_cache_info(path, "peek_info"); }
33
+ inline CacheInfo peek_info(const std::string& path) {
34
+ const std::lock_guard<std::mutex> cache_lock(detail::cache_mutex());
35
+ return detail::load_cache_info(path, "peek_info");
36
+ }
31
37
 
32
38
  // The kernel a file was written with, so it can be loaded without naming that kernel in advance.
33
39
  inline kernel::KernelId peek_kernel_id(const std::string& path) { return peek_info(path).post_model_info.kernel_id; }
@@ -93,6 +99,7 @@ inline void save_precompute(
93
99
  const gpflash::detail::PosteriorPrecompute& post_precompute,
94
100
  const std::string& note = "",
95
101
  const bool include_variance_data = true) {
102
+ const std::lock_guard<std::mutex> cache_lock(detail::cache_mutex());
96
103
  detail::write_precompute_file(
97
104
  path,
98
105
  post_model_info,
@@ -167,6 +174,7 @@ inline PosteriorContents load_precompute(
167
174
  const std::string& path,
168
175
  const kernel::KernelId expected_kernel_id,
169
176
  const arma::u64* expected_input_hash_ptr = nullptr) {
177
+ const std::lock_guard<std::mutex> cache_lock(detail::cache_mutex());
170
178
  // The same validated header read peek_info uses, so neither can accept a file the other rejects. A NaN
171
179
  // mll or a negative hp_sig2_k throws here, in release as well as debug.
172
180
  const CacheInfo cache_info = detail::load_cache_info(path, "load_precompute");
@@ -183,6 +191,7 @@ inline PosteriorContents load_precompute_for_kernel(
183
191
  const std::string& path,
184
192
  const char* caller,
185
193
  const arma::u64* expected_input_hash_ptr = nullptr) {
194
+ const std::lock_guard<std::mutex> cache_lock(detail::cache_mutex());
186
195
  const CacheInfo cache_info = detail::load_cache_info(path, caller);
187
196
  PosteriorContents post_contents = detail::load_precompute_after_header(
188
197
  path, cache_info, kern_fun.kernel_id(), expected_input_hash_ptr, caller);
@@ -195,6 +204,7 @@ namespace detail {
195
204
 
196
205
  // load_precompute_for_kernel at the kernel the file names, its header read once.
197
206
  inline PosteriorContents load_precompute_for_file_kernel(const std::string& path, const char* caller) {
207
+ const std::lock_guard<std::mutex> cache_lock(cache_mutex());
198
208
  const CacheInfo cache_info = load_cache_info(path, caller);
199
209
  const kernel::KernelBase& kern_fun = kernel::kernel_by_id(cache_info.post_model_info.kernel_id);
200
210
  PosteriorContents post_contents = load_precompute_after_header(
@@ -38,7 +38,9 @@ The package `README.md` shows the calls. `load_posterior(path)` checks the file
38
38
  it whenever they are in hand. A prediction-only build has `load_posterior` alone. To replace a file, save over it.
39
39
  The format layer itself is `save_precompute` and `load_precompute` in `PosteriorCache.hpp`.
40
40
 
41
- No two cache calls, reads or saves, may run at once, even on different files: HDF5 is linked without thread safety.
41
+ HDF5 is linked without thread safety, so the cache calls hold one process-wide lock for their whole run: two threads
42
+ may call them at once, and the second waits for the first, even on another file. The lock covers GpFlash's calls only;
43
+ the caller's own HDF5 use must not overlap them.
42
44
 
43
45
  ## When errors are raised
44
46
 
@@ -16,15 +16,15 @@ struct PosteriorOptions {
16
16
  bool return_mean_gradient = false;
17
17
  bool return_var_gradient = false;
18
18
 
19
- // Whether to check the query points' row count and finiteness, on by default. Clearing it saves a scan of
20
- // n_dim values per point.
19
+ // Whether to check that every query coordinate is finite, on by default. Clearing it saves a scan of n_dim values
20
+ // per point. The row count is always checked, since a wrong one would read out of bounds.
21
21
  bool check_query_points = true;
22
22
  };
23
23
 
24
24
  namespace detail {
25
25
 
26
- // Whether no quantity was asked for, whatever check_query_points says. Not an error: a query then returns an empty
27
- // PosteriorResult, which is what every field already means when its flag is clear.
26
+ // Whether no quantity was asked for. Not an error: a query then returns an empty PosteriorResult, which is what every
27
+ // field already means when its flag is clear. Asked after the query points' checks, so a wrong row count still raises.
28
28
  inline bool is_empty_request(const PosteriorOptions& post_opts) {
29
29
  return !post_opts.return_mean && !post_opts.return_var && !post_opts.return_mean_gradient
30
30
  && !post_opts.return_var_gradient;
@@ -39,9 +39,13 @@ namespace detail {
39
39
  // ── Validation ───────────────────────────────────────────────────────────────
40
40
 
41
41
  // The query points, before any of them reaches the kernel. A point of another dimension would read past the training
42
- // features, and a non-finite one has no distance to them, so a stationary kernel would return its far-field answer.
42
+ // features, so its row count is always checked; a non-finite one has no distance to them, so a stationary kernel would
43
+ // return its far-field answer, and that scan is skipped when the caller clears check_query_points.
43
44
  inline void check_post_points(
44
- const arma::mat& X_ndim_npost_mat, const PosteriorPrecompute& post_precompute, const char* field_name) {
45
+ const arma::mat& X_ndim_npost_mat,
46
+ const PosteriorPrecompute& post_precompute,
47
+ const PosteriorOptions& post_opts,
48
+ const char* field_name) {
45
49
  const char* caller = "GpPosterior::eval";
46
50
  check_mat_n_rows(
47
51
  X_ndim_npost_mat,
@@ -49,7 +53,7 @@ inline void check_post_points(
49
53
  field_name,
50
54
  caller,
51
55
  "One row per input dimension the posterior was built with.");
52
- check_all_finite_vals(X_ndim_npost_mat, field_name, caller);
56
+ if (post_opts.check_query_points) check_all_finite_vals(X_ndim_npost_mat, field_name, caller);
53
57
  }
54
58
 
55
59
  // What the options alone cannot say: whether this precompute can serve them.
@@ -69,8 +73,7 @@ inline PosteriorResult eval_precompute(
69
73
  const PosteriorPrecompute& post_precompute,
70
74
  const arma::vec& x_post_vec,
71
75
  const PosteriorOptions& post_opts) {
72
- // Skipped only when the caller vouches for the points; see PosteriorOptions::check_query_points.
73
- if (post_opts.check_query_points) check_post_points(x_post_vec, post_precompute, "x_post_vec");
76
+ check_post_points(x_post_vec, post_precompute, post_opts, "x_post_vec");
74
77
  // Nothing asked for, nothing to build.
75
78
  if (is_empty_request(post_opts)) return PosteriorResult{};
76
79
  check_posterior_request(post_opts, post_precompute);
@@ -165,7 +168,7 @@ inline PosteriorResult eval_precompute(
165
168
  const PosteriorPrecompute& post_precompute,
166
169
  const arma::mat& X_ndim_npost_mat,
167
170
  const PosteriorOptions& post_opts) {
168
- if (post_opts.check_query_points) check_post_points(X_ndim_npost_mat, post_precompute, "X_ndim_npost_mat");
171
+ check_post_points(X_ndim_npost_mat, post_precompute, post_opts, "X_ndim_npost_mat");
169
172
  // Nothing asked for, nothing to build.
170
173
  if (is_empty_request(post_opts)) return PosteriorResult{};
171
174
  check_posterior_request(post_opts, post_precompute);
@@ -96,7 +96,7 @@ environment = { CMAKE_PREFIX_PATH = "/opt/gpflash_deps", BLA_VENDOR = "OpenBLAS"
96
96
 
97
97
  [tool.cibuildwheel.macos]
98
98
  before-all = "bash {project}/python/ci/install_deps_unix.sh"
99
- # MACOSX_DEPLOYMENT_TARGET is set per runner by the workflow, to match the Homebrew libraries delocate bundles.
99
+ # MACOSX_DEPLOYMENT_TARGET is set per runner by the workflow, to match Homebrew's libomp, which the module links in.
100
100
  environment = { CMAKE_PREFIX_PATH = "/tmp/gpflash_deps", CMAKE_ARGS = "-DOpenMP_ROOT=$(brew --prefix libomp)" }
101
101
 
102
102
  [tool.cibuildwheel.windows]
@@ -0,0 +1,44 @@
1
+ # The Python module gpflash._core: pybind11 bindings over the header-only library, compiled as ISO C++14 like the rest
2
+ # of the package. pyproject.toml drives this through scikit-build-core; only its install component, python, goes into
3
+ # the wheel, so the headers and CMake package files the root installs stay out of it.
4
+
5
+ find_package(Python 3.11 REQUIRED COMPONENTS Interpreter Development.Module)
6
+ find_package(pybind11 3.0 CONFIG REQUIRED) # 3.0 for py::native_enum; pyproject.toml requires the same
7
+
8
+ pybind11_add_module(gpflash_python MODULE src/bindings.cpp)
9
+ set_target_properties(gpflash_python PROPERTIES OUTPUT_NAME _core)
10
+
11
+ # GpFlash::GpFlash carries every define, flag and library the headers need.
12
+ target_link_libraries(gpflash_python PRIVATE GpFlash::GpFlash)
13
+
14
+ # The README's "Compiling the headers" flags: -funroll-loops for batch posterior evaluation, -fno-math-errno so the
15
+ # kernels' math functions vectorize. Never -ffast-math, which core/Platform.hpp rejects.
16
+ target_compile_options(gpflash_python PRIVATE
17
+ $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-funroll-loops -fno-math-errno>)
18
+
19
+ # macOS: link libomp statically and export only the module's entry point. Two copies of libomp.dylib in one process,
20
+ # this module's and another library's such as torch's, abort (OMP: Error #15) or crash; a static, hidden copy does
21
+ # neither. Only this module is affected; GpFlash::GpFlash's consumers keep the dylib.
22
+ if(APPLE)
23
+ get_target_property(gpflash_omp_link_libs OpenMP::OpenMP_CXX INTERFACE_LINK_LIBRARIES)
24
+ set(gpflash_omp_static_link_libs "")
25
+ foreach(gpflash_omp_lib IN LISTS gpflash_omp_link_libs)
26
+ if(gpflash_omp_lib MATCHES "libomp\\.dylib$")
27
+ string(REGEX REPLACE "\\.dylib$" ".a" gpflash_omp_static_lib "${gpflash_omp_lib}")
28
+ # A source build against an OpenMP without the static library still builds; the wheels' tests
29
+ # (test_openmp_isolation.py) refuse a module that links the dylib, so a release cannot ship one.
30
+ if(EXISTS "${gpflash_omp_static_lib}")
31
+ set(gpflash_omp_lib "${gpflash_omp_static_lib}")
32
+ else()
33
+ message(WARNING "No ${gpflash_omp_static_lib} beside the libomp.dylib FindOpenMP found, so the "
34
+ "module links the dylib and cannot share a process with another copy of libomp, such as "
35
+ "torch's. Homebrew's libomp provides both.")
36
+ endif()
37
+ endif()
38
+ list(APPEND gpflash_omp_static_link_libs "${gpflash_omp_lib}")
39
+ endforeach()
40
+ set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_LINK_LIBRARIES "${gpflash_omp_static_link_libs}")
41
+ target_link_options(gpflash_python PRIVATE "LINKER:-exported_symbol,_PyInit__core")
42
+ endif()
43
+
44
+ install(TARGETS gpflash_python LIBRARY DESTINATION gpflash COMPONENT python)
@@ -130,9 +130,13 @@ cores through OpenMP.
130
130
  ## Threads
131
131
 
132
132
  Fits and queries run in parallel with OpenMP and release the GIL, so other Python threads run
133
- meanwhile. `OMP_NUM_THREADS` sets the thread count. Loading two different OpenMP runtimes into
134
- one process, for example GpFlash's alongside another library's, can slow both down; if that
135
- happens, set `OMP_NUM_THREADS` or import one library at a time.
133
+ meanwhile. The cache calls (`peek_info`, `peek_kernel_id`, `load_posterior`, `load_posterior_verified`,
134
+ `GpPosterior.save_precompute` and the `GaussianProcess` methods that call them) read and write HDF5,
135
+ which is not built thread-safe, so GpFlash runs them one at a time: a second cache call waits for the
136
+ first, even on another file. `OMP_NUM_THREADS` sets the thread count. On macOS the module carries its
137
+ own OpenMP runtime, linked in and hidden, so it loads beside another library's, such as PyTorch's.
138
+ Two runtimes in one process can still slow each other down when both run threads at once; if that
139
+ happens, set `OMP_NUM_THREADS`.
136
140
 
137
141
  ## Building from source
138
142
 
@@ -6,7 +6,8 @@
6
6
  #
7
7
  # Linux: OpenBLAS (LAPACK in C, so no libgfortran), HDF5 and Armadillo, built into the prefix.
8
8
  # macOS: Accelerate for BLAS/LAPACK; HDF5 and Armadillo built into the prefix, as on Linux; Homebrew's libomp, the
9
- # one library taken as installed. delocate bundles HDF5 and libomp.
9
+ # one library taken as installed, whose libomp.a the module links statically (python/CMakeLists.txt).
10
+ # delocate bundles HDF5.
10
11
  #
11
12
  # Usage: GPFLASH_DEPS_PREFIX=<dir> bash install_deps_unix.sh. The prefix goes on CMAKE_PREFIX_PATH for the wheel build.
12
13
  set -euo pipefail
@@ -6,6 +6,11 @@ Two layers:
6
6
  - The C++ interface, re-exported from ``gpflash._core`` under its C++ names and shapes
7
7
  (``TrainingData``, ``select_hp_with_max_mll``, ``GpPosterior``, ...), where points are
8
8
  columns: ``X_ndim_ntrain_mat`` is (n_dim, n_train).
9
+
10
+ Fits and queries release the GIL. The cache calls (``peek_info``, ``peek_kernel_id``, ``load_posterior``,
11
+ ``load_posterior_verified``, ``GpPosterior.save_precompute`` and the ``GaussianProcess`` methods that call them) read
12
+ and write HDF5, which is not built thread-safe, so GpFlash runs them one at a time: a second cache call waits for the
13
+ first, even on another file.
9
14
  """
10
15
 
11
16
  from ._core import (
@@ -161,11 +161,13 @@ class GaussianProcess:
161
161
  The flags and their defaults are C++'s PosteriorOptions; a quantity not asked for is None in the
162
162
  result. The variance costs O(n_train^2) per point against O(n_train) for the mean, so pass
163
163
  return_var=False when only the mean is needed, and for a posterior saved without variance data.
164
- check_query_points=False skips the check of the points' dimension and finiteness, for speed.
164
+ check_query_points=False skips the check that the points are finite, for speed; their dimension is
165
+ always checked.
165
166
  """
166
167
  posterior = self._fitted_posterior()
167
168
  X_post_points_mat = _as_points_mat(X_post_mat, "X_post_mat")
168
169
  n_dim = X_post_points_mat.shape[1]
170
+ # C++ checks this too, whatever check_query_points says; here for a message in this (n_post, n_dim) layout.
169
171
  if n_dim != posterior.n_dim():
170
172
  raise _core.InvalidInputError(
171
173
  f"X_post_mat has {n_dim} columns; the model was fitted in {posterior.n_dim()} dimensions."
@@ -7,7 +7,8 @@
7
7
  *
8
8
  * Array fields are converted on every get and set, so they are values, not views: assign a whole array to change
9
9
  * one. A query's points are read in place when they are already float64 and column-major, which the transpose of a
10
- * C-ordered (n_points, n_dim) array is. Every computation releases the GIL so other Python threads run meanwhile.
10
+ * C-ordered (n_points, n_dim) array is. Every computation releases the GIL so other Python threads run meanwhile;
11
+ * cache saves and loads still run one at a time, on the C++ cache's lock, since HDF5 is not built thread-safe.
11
12
  *
12
13
  * Serial only: the module is built without GPFLASH_HAVE_MPI, so a fit runs on the calling process. MPI stays with
13
14
  * the C++ library.
@@ -127,6 +127,20 @@ def test_unchecked_query_matches_checked(gp, data):
127
127
  )
128
128
 
129
129
 
130
+ def test_unchecked_query_still_checks_dimension(gp, data):
131
+ # Cleared, the flag skips only the finiteness scan: the C++ query, which the wrapper's own check does not guard,
132
+ # still refuses points of another dimension rather than reading past the training features.
133
+ _, _, X_post_mat = data
134
+ post_opts = gpflash.PosteriorOptions()
135
+ post_opts.check_query_points = False
136
+ X_wrong_mat = np.asfortranarray(np.hstack([X_post_mat, X_post_mat]).T)
137
+ with pytest.raises(gpflash.InvalidInputError, match="X_ndim_npost_mat"):
138
+ gp.posterior().eval(X_wrong_mat, post_opts)
139
+ post_opts.return_mean = post_opts.return_var = False
140
+ with pytest.raises(gpflash.InvalidInputError, match="X_ndim_npost_mat"):
141
+ gp.posterior().eval(X_wrong_mat, post_opts)
142
+
143
+
130
144
  def test_hyperparameters_and_fit(gp):
131
145
  hp_val_struct = gp.hp_val_struct()
132
146
  assert hp_val_struct.hp_sig2_k > 0.0
@@ -315,3 +329,49 @@ def test_concurrent_predictions_agree(gp, data):
315
329
  thread.join()
316
330
  for result in results:
317
331
  np.testing.assert_array_equal(result, expected)
332
+
333
+
334
+ def test_concurrent_cache_calls_agree(data, tmp_path):
335
+ # The GIL is released during cache calls too, which HDF5, not built thread-safe, only survives because GpFlash runs
336
+ # them one at a time. Without that lock this fails or crashes, how often depending on the timing.
337
+ X_train_mat, f_train_vec, X_post_mat = data
338
+ optz_opts = make_optz_opts(gpflash.KernelId.SqExp)
339
+ paths = [tmp_path / f"gp_{i_file}.h5" for i_file in range(4)]
340
+ for i_file, path in enumerate(paths):
341
+ gpflash.GaussianProcess(optz_opts).fit(X_train_mat, (1.0 + i_file) * f_train_vec).save_precompute(path)
342
+ expected = [predict_mean(gpflash.GaussianProcess.load_posterior(path), X_post_mat) for path in paths]
343
+ saved_gp = gpflash.GaussianProcess.load_posterior(paths[0])
344
+ results = [[] for _ in paths]
345
+ errors = []
346
+
347
+ def load(i_file):
348
+ for _ in range(10):
349
+ results[i_file].append(predict_mean(gpflash.GaussianProcess.load_posterior(paths[i_file]), X_post_mat))
350
+
351
+ def peek():
352
+ for _ in range(10):
353
+ for path in paths:
354
+ assert gpflash.peek_info(str(path)).n_train == X_train_mat.shape[0]
355
+
356
+ def save():
357
+ for _ in range(10):
358
+ saved_gp.save_precompute(tmp_path / "gp_saved.h5")
359
+
360
+ def run(task, *args):
361
+ try:
362
+ task(*args)
363
+ except Exception as error:
364
+ errors.append(error)
365
+
366
+ threads = [threading.Thread(target=run, args=(load, i_file)) for i_file in range(len(paths))]
367
+ threads += [threading.Thread(target=run, args=(peek,)), threading.Thread(target=run, args=(save,))]
368
+ for thread in threads:
369
+ thread.start()
370
+ for thread in threads:
371
+ thread.join()
372
+ assert errors == []
373
+ for result_list, expected_mean in zip(results, expected, strict=True):
374
+ assert len(result_list) == 10
375
+ for result in result_list:
376
+ np.testing.assert_array_equal(result, expected_mean)
377
+ gpflash.load_posterior(str(tmp_path / "gp_saved.h5"))
@@ -0,0 +1,66 @@
1
+ """The module's OpenMP runtime shares a process with another library's: on macOS it is linked in and hidden."""
2
+
3
+ import os
4
+ import subprocess
5
+ import sys
6
+ import textwrap
7
+
8
+ import pytest
9
+
10
+ from gpflash import _core
11
+
12
+ # A fit large enough to enter the OpenMP regions (n_train >= PERF_OMP_MIN_N_POINT, core/Platform.hpp), printing its
13
+ # MLL. A module named as the script's argument is imported before gpflash, so its OpenMP runtime starts first.
14
+ _FIT_SCRIPT = textwrap.dedent(
15
+ """
16
+ import importlib
17
+ import sys
18
+
19
+ import numpy as np
20
+
21
+ if len(sys.argv) > 1:
22
+ importlib.import_module(sys.argv[1])
23
+ import gpflash
24
+
25
+ rng = np.random.default_rng(0)
26
+ X_train_mat = rng.random((300, 4))
27
+ f_train_vec = np.sin(3 * X_train_mat).sum(axis=1)
28
+ print(gpflash.GaussianProcess().fit(X_train_mat, f_train_vec, sig2_f_val=-1.0).mll())
29
+ """
30
+ )
31
+
32
+ macos_only = pytest.mark.skipif(sys.platform != "darwin", reason="the macOS wheel links its OpenMP runtime statically")
33
+
34
+
35
+ def _run_fit(first_import: str | None = None) -> subprocess.CompletedProcess[str]:
36
+ env = {**os.environ, "OMP_NUM_THREADS": "2"}
37
+ env.pop("KMP_DUPLICATE_LIB_OK", None) # the runtime must not need it
38
+ script_args = [] if first_import is None else [first_import]
39
+ return subprocess.run(
40
+ [sys.executable, "-c", _FIT_SCRIPT, *script_args], env=env, capture_output=True, text=True, timeout=300
41
+ )
42
+
43
+
44
+ @macos_only
45
+ def test_module_links_no_openmp_dylib():
46
+ linked = subprocess.run(["otool", "-L", _core.__file__], capture_output=True, text=True, check=True).stdout
47
+ assert "libomp" not in linked
48
+
49
+
50
+ @macos_only
51
+ def test_module_exports_only_its_entry_point():
52
+ exported = subprocess.run(["nm", "-gU", _core.__file__], capture_output=True, text=True, check=True).stdout
53
+ assert [line.split()[-1] for line in exported.splitlines()] == ["_PyInit__core"]
54
+
55
+
56
+ def test_fit_runs_in_a_fresh_process():
57
+ result = _run_fit()
58
+ assert result.returncode == 0, result.stderr
59
+
60
+
61
+ @pytest.mark.parametrize("first_import", ["torch", "sklearn"])
62
+ def test_fit_runs_beside_another_openmp_runtime(first_import):
63
+ pytest.importorskip(first_import)
64
+ result = _run_fit(first_import)
65
+ assert result.returncode == 0, result.stderr
66
+ assert float(result.stdout) == pytest.approx(float(_run_fit().stdout), rel=1e-8)