Conversation
Closed
Contributor
|
📄 Documentation for this branch is available at: https://ncar.github.io/musica/branch/370-python-files/ |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #406 +/- ##
=======================================
Coverage 87.15% 87.15%
=======================================
Files 43 43
Lines 3870 3870
=======================================
Hits 3373 3373
Misses 497 497 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the conditional import logic to eliminate a circular dependency at package initialization by centralizing backend selection and dynamically loading core symbols.
- Introduce
musica/backend.pyfor runtime CPU/GPU backend selection. - Update
types.py,__init__.py, andcuda.pyto usebackend.get_backend()instead of direct imports. - Refactor all
musica/mechanism_configuration/*.pymodules and tests to load C++ symbols from the chosen backend.
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| musica/backend.py | New module that detects GPU dependencies and selects the backend |
| musica/types.py | Replace direct C++ imports with dynamic backend.get_backend() |
| musica/init.py | Simplify package exports and remove inline backend logic |
| musica/cuda.py | Updated to use new backend module |
| musica/test/test_util_full_mechanism.py | Tests updated to reference mc.* instead of direct imports |
| musica/mechanism_configuration/*.py | All config classes now import C++ symbols via the dynamic backend |
Comments suppressed due to low confidence (3)
musica/init.py:9
- The module-level all omits 'version', so version won't be exposed on wildcard imports. Consider adding 'version' to all for consistency with previous exports.
__all__ = [
musica/backend.py:7
- Add unit tests for
_safe_find_spec,_gpu_deps_installed, andget_backend()to verify that CPU vs GPU backends are selected correctly under different environment conditions.
def _safe_find_spec(name):
musica/types.py:26
- [nitpick] The alias
mcfor the mechanism configuration backend may be ambiguous to readers; consider a more descriptive name likemechanism_configto improve readability.
mc = _backend._mechanism_configuration
This was referenced Jul 8, 2025
Merged
Merged
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.
The
__init__.pyfile would get a circular import if the imports in__init__.pywere re-ordered. This is because of the conditional import logic we need to do of the pybind11 musica targets for cpu vs gpu. This, I think, should fix that circular import and allow our python format actions to be turned on againCloses #370