Refactor CondensedPhaseArrhenius to use composition instead of inheritance#461
Refactor CondensedPhaseArrhenius to use composition instead of inheritance#461
Conversation
…tance Co-authored-by: K20shores <[email protected]>
CondensedPhaseArrhenius|
@copilot it looks like there's an issue with one of the attributes |
…sed CondensedPhaseArrhenius Co-authored-by: K20shores <[email protected]>
... Fixed the missing |
| Returns: | ||
| Dict: A dictionary representation of the condensed phase Arrhenius rate constant. | ||
| """ | ||
| return instance.serialize() |
There was a problem hiding this comment.
This will only work if the type is a python type. This serialize_static method is only called with the c++ wrapper types, an _CondensedPhaseArrhenius
There was a problem hiding this comment.
Fixed the serialize_static method to handle both Python wrapper and C++ types. The method now checks if the instance has an _instance attribute (composition-based Python wrapper) and delegates to instance.serialize(), otherwise it uses direct attribute access for C++ wrapper types like the original implementation. Commit 3cdba82.
Co-authored-by: K20shores <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #461 +/- ##
=======================================
Coverage 83.63% 83.63%
=======================================
Files 48 48
Lines 4093 4093
=======================================
Hits 3423 3423
Misses 670 670 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
musica/_version.py
Outdated
There was a problem hiding this comment.
Removed the accidentally added _version.py file and fixed the import to handle the missing file gracefully. Commit 759832e.
There was a problem hiding this comment.
What is the purpose of the changes here? Will these changes only be needed while we transition away from the inheritance?
There was a problem hiding this comment.
The changes to Reactions.init are permanent architectural changes needed to support the composition pattern. The Reactions class needs to handle both inheritance-based reactions (pass through as-is) and composition-based reactions (extract the _instance for the C++ backend). This ensures the C++ backend receives the correct object types while maintaining compatibility with both patterns. This is not transitional - it's the bridge that allows the composition pattern to work with the existing C++ infrastructure.
Co-authored-by: K20shores <[email protected]>
musica/__init__.py
Outdated
| try: | ||
| from ._version import version as __version__ | ||
| except ImportError: | ||
| __version__ = "0.12.0" |
There was a problem hiding this comment.
| try: | |
| from ._version import version as __version__ | |
| except ImportError: | |
| __version__ = "0.12.0" | |
| try: | |
| from ._version import version as __version__ | |
| except ImportError: | |
| __version__ = "0.12.0" |
Revert this change. This already works
There was a problem hiding this comment.
Reverted the init.py file back to the original import statement. The _version.py file is automatically generated at build time via scikit-build-core configuration. Commit 540ea12.
Co-authored-by: K20shores <[email protected]>
This PR refactors the
CondensedPhaseArrheniusclass inmusica.mechanism_configurationto use composition instead of inheritance from_CondensedPhaseArrhenius, following the wrapper pattern established intuvx.py.Changes Made
Core Refactor
class CondensedPhaseArrhenius(_CondensedPhaseArrhenius)→class CondensedPhaseArrheniusself._instance = _CondensedPhaseArrhenius()to hold the underlying C++ objectSpeciesandPhaseobjects separately for the public interfaceProperty Delegation
@propertydecorators for all attributes (A,B,C,D,E,name)self._instancefor seamless operationPublic Interface Improvements
reactants,products,aerosol_phase, andaerosol_phase_waternow return Python objectsSerialization Updates
serialize()is now an instance method instead of staticserialize_static()for existing code that calls it staticallyserialize_static()to maintain compatibilityExample Usage
Benefits
Fixes #443.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.