use dll wrappers on windows#3241
Merged
Merged
Conversation
sunqm
reviewed
Jun 6, 2026
| #Fixme, the standard resource module gives wrong number when objects are released | ||
| # http://fa.bianp.net/blog/2013/different-ways-to-get-memory-consumption-or-lessons-learned-from-memory_profiler/#fn:1 | ||
| #or use slow functions as memory_profiler._get_memory did | ||
| CLOCK_TICKS = os.sysconf("SC_CLK_TCK") |
Collaborator
There was a problem hiding this comment.
create the two variables in the module space. In the case windows, set them to None
Collaborator
Author
There was a problem hiding this comment.
ok, but is CLOCK_TICKS used anywhere?
Collaborator
There was a problem hiding this comment.
Not in the PySCF package. No harm to keep it there in case it's used by other code built on top of PySCF for now. In the future, it can be cleaned up when an explicit __all__ or explicit documentation for these parameters are introduced.
Collaborator
|
please also update pyproject.toml, to include the dependency |
sunqm
approved these changes
Jun 7, 2026
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.
corresponds to patch 1, 2 and 4 of conda-forge/pyscf-feedstock#63, and passes the win-64 tests there.
On Unix, ctypes' getattr(dll, name) searches a flat process-wide symbol namespace, which means a function compiled into libcint.so is visible when accessing libcgto.so. On Windows, it is not visible. The fix: whenever a library like libcgto is loaded on Windows, it's wrapped via make_dll_wrapper() with its dependency libraries as fallbacks for symbol lookup. For example, pyscf/gto/moleintor.py now wraps libcgto with libcint as fallback, and pyscf/dft/numint.py wraps libdft with libcvhf, libcgto, libcint as fallbacks.
UPDATE: the wrap is now automatically considered in load_library.
_ctypes.dlsymreplaced withctypes.cast(getattr(...))_ctypes.dlsym(handle, name)is a CPython internal that resolves symbols by name from a raw dlopen handle. It exists on Linux/macOS but Windows has no equivalent.The fix:
ctypes.cast(getattr(lib, name), ctypes.c_void_p)achieves the same result by accessing the function via the wrapper's__getattr__, then casting the returned function pointer to c_void_p.3. Reusing wrapped library objects instead of reloadingSome modules were calling lib.load_library() again on their own, creating a separate unwrapped copy. Fixed by importing the already-wrapped object from the canonical module, e.g., pyscf/ao2mo/nrr_outcore.py now imports libao2mo from _ao2mo instead of reloading.
4. Tests fixed to use wrapped librariesFive test files were calling lib.load_library() directly. Fixed by importing from the module that already provides the wrapped library.
current_memory()used Linux-only/proc. Fixed by adding a psutil fallback. Also added conda-typical library search paths to load_library() for Windows.