Implementing buildDescriptor from vlsvvtkreader as a C function#426
Open
lassejsc wants to merge 20 commits intofmihpc:devfrom
Open
Implementing buildDescriptor from vlsvvtkreader as a C function#426lassejsc wants to merge 20 commits intofmihpc:devfrom
lassejsc wants to merge 20 commits intofmihpc:devfrom
Conversation
where the package got compiled with older version of numpy C api.
…on hile" This reverts commit 89676f5.
lassejsc
commented
Feb 18, 2026
analysator/cpphelpers/setup.py
Outdated
| name="cpphelpers", | ||
| version="1.0", | ||
| ext_modules=[Extension("cpphelpers", sources=["cpphelpers.cpp"])], | ||
| include_dirs=[numpy.get_include()] |
Contributor
Author
There was a problem hiding this comment.
Numpy is not currently needed i think but keeping this still here if new stuff gets added to cpphelpers
additionally shortened the test.py which may or may not be removed entirely in the end
should match one in dev and removed -p from uv python install in workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UPDATE: the cpphelpers is going into the back end but this adds import and call of it into the buildDescriptor() function, the pure python version is still kept as
buildDescriptorPython()Pure python
buildDescriptor()is very slow, for larger files I tested from FID run this was ~60(maybe +) seconds, in contrast with the new cpphelperbuildDescriptorthis time is closer to under ~10 seconds (tested on turso-carrington). For smaller files the difference isn't as big, but testing with some files I found that the speed up is somewhere around 3-9x overall for files where the time was already in tens of seconds, for smaller files the difference is probably closer to 20% since at that point the overhead starts to be a more of a thing. I tested random files (8 for each) across runs FID,FIJ,ABC,BED,FHA and the overall average speedup was at slowest 1.30x for smaller files and for larger files it was around 9x.What is happening here is extension of Python with C, see https://docs.python.org/3/extending/extending.html
With the Python C API we first convert all the python objects to C objects, we do the descriptor building for loops etc that were slow in pure python and we convert back to the python objects and these get passed directly back into Python seamlessly.
Inside python this is just a regular function call, only caveat is that the new modules needs to get built and imported first.
(Note that all this can also be done with pybind11/nano apparently but this also works fine, still testing if this is fragile in different platforms, so far it has behaved nicely on local machine,turso-carrington frontend, hile, my phone )
The compilation uses setuptools (also no it is not deprecated, only the command
python setup.py installandbuildare, see https://packaging.python.org/en/latest/discussions/setup-py-deprecated/). Setuptools should also accept the env variables CC, CXX, etc for setting which compiler to use.EDIT:
So far tested on HILE and turso-carrington, both work and compile fine, though on HILE you need toSeems like this is not necessary if you set the env flags tomodule load gcc-nativeit seems.CC=cc,CXX=CC, however you may need to recompile matplotlib as that had some issue where if you imported this module first and then matplotlib it would segfault at some compiled matplotlib binary.Recompiling matplotlib can be done with
pip install --no-cache-dir --no-binary :all: matplotlibafter setting env variablesCC,CXXcorrectly as above.