Skip to content

Migrate Python modules to sbldpy (simplebuild/dgcode 2.0) and make LOKI tests platform independent - #6

Merged
MilanKlausz merged 3 commits into
ess-dg:mainfrom
tkittel:simplebuild200
Oct 27, 2026
Merged

MilanKlausz merged 3 commits into
ess-dg:mainfrom
tkittel:simplebuild200

Conversation

@tkittel

@tkittel tkittel commented Oct 27, 2026

Copy link
Copy Markdown
Member

Yo @MilanKlausz we are finally getting to the dgcode_projects in this housekeeping + updating of simplebuild and dgcode.

It is mostly follow up fixes for the migration away from pybind11 to a new small custom python-c++ hooking I designed (it has less features but compiles a lot faster and will eventually allow me to drop the pybind11 support). There are also some fixes for one of your tests which was a bit flaky.

Claude will say the rest:

Converts all compiled Python modules from pybind11 (pycpp_* directories) to sbldpy (pymod_* directories), as introduced in simplebuild 2.0.0 and simplebuild-dgcode 2.0.0, and makes the output of the LOKI tests independent of the platform.

Python modules (the Python APIs are unchanged):

  • The geometry modules GeoBCS, GeoBCSBanks, GeoLarmor2020, GeoLarmor2022 and GeoPlane are migrated following the recipe in the simplebuild-dgcode documentation.
  • LokiAimHelper, Larmor2022Bank and G4GeoLokiTests.TestUtils: the compiled code is now in private modules, and Python modules with the same names add the default values of constructor arguments, the module constants, and the conversion of results to lists. G4GeoLokiTests now depends on numpy.

Test robustness:

  • Many positions in the LOKI geometry (e.g. pixel centres along the straws, like 7.8125 mm) are exactly halfway between two printed values, so tiny floating point differences between platforms decided the rounding, and test_geo_navigation failed on macOS. The fmt helper of the tests now removes such differences before rounding, and always rounds ties away from zero. The reference logs change only in the last digit of such values (and in the hashes of formatted pixel centres in test_larmor2022_bank).

All 44 tests pass on Linux (release and debug builds) and macOS. The cppcheck step requires simplebuild-dgcode 2.0.1, which fixes an error reported in its MCPLExtra package.

assisted-by: claude

Migrate the GeoBCS, GeoBCSBanks, GeoLarmor2020, GeoLarmor2022 and GeoPlane
geometry modules from pybind11 (pycpp_*) to sbldpy (pymod__*), following the
migration recipe in the simplebuild-dgcode documentation. The Python API
(e.g. G4GeoLoki.GeoBCSBanks.create()) is unchanged.

Assisted-by: Claude
The compiled code is in private modules (_LokiAimHelper, _Larmor2022Bank,
_TestUtils), and Python modules with the same names and APIs as before add
the default values of constructor arguments, the module constants, and the
conversion of results to lists (passed from C++ through callbacks).
G4GeoLokiTests now depends on numpy.

Assisted-by: Claude
Many positions in the geometry (e.g. pixel centres along the straws, like
7.8125 mm) are exactly halfway between two printed values, so tiny floating
point differences between platforms decided the rounding, and
test_geo_navigation failed on macOS even with fewer decimals. The fmt helper
now first rounds to prec+6 decimals (removing such differences) and then
rounds half away from zero. The reference logs change only in the last digit
of such values (and in the hashes of the formatted pixel centres in
test_larmor2022_bank).

Assisted-by: Claude
@MilanKlausz
MilanKlausz merged commit 764f2a5 into ess-dg:main Oct 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants