Replies: 1 comment 1 reply
-
|
Why is this a new discussion? Wasn't all this already discussed in #160 ? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Separate Calculator Factory from Collection Base Classes
Status
Proposed
Context
The legacy
InterfaceFactoryTemplateclass served as both a calculator factory and a state manager, tightly coupling calculator creation with calculator lifecycle management. This design has several issues:InterfaceFactoryTemplatemaintains state about the "current" calculator, mixing factory responsibilities with state managementNewCollectionBase, making it difficult to use calculators independently of collection classesThe need for a cleaner calculator architecture was discussed in Discussion #160, leading to the proposal to separate calculator concerns from collection management.
Decision
We will introduce a new calculator architecture with the following components:
1. CalculatorBase
An abstract base class for all physics calculators:
calculate(x): Abstract method for performing calculationsmodelproperty: Get/set the physical modelinstrumental_parametersproperty: Get/set instrumental parametersupdate_model()andupdate_instrumental_parameters(): Explicit update methodsModelBaseto integrate with EasyScience's object graph2. CalculatorFactoryBase
An abstract factory for creating calculator instances:
_try_register_calculator(): Dynamic discovery of available calculators based on installed dependenciesavailable_calculatorsproperty: List calculators that can be createdcreate(): Abstract method to instantiate a calculator3. SimpleCalculatorFactory
A concrete factory implementation:
register(): Dynamically add calculators to the factoryunregister(): Remove calculators from the factory4. Deprecation of InterfaceFactoryTemplate
InterfaceFactoryTemplateas deprecated with aDeprecationWarning5. Encapsulation Improvements
Map._storeprivate (__store) to enforce encapsulation_storedirectly to use public APIs (vertices(),get_item_by_key())Consequences
Positive
__storeenforces proper API usage in the Map classNegative
InterfaceFactoryTemplatewill need to be updatedInterfaceFactoryTemplateduring a transition periodNeutral
Implementation
The implementation is provided in draft PR #181:
src/easyscience/fitting/calculators/calculator_base.py- New CalculatorBase classsrc/easyscience/fitting/calculators/calculator_factory.py- New factory classessrc/easyscience/fitting/calculators/interface_factory.py- Deprecation warning addedsrc/easyscience/global_object/map.py- Encapsulation improvement (_store→__store)src/easyscience/variable/parameter.py- Updated to use public Map APIMigration Path
For product libraries currently using
InterfaceFactoryTemplate:Before (Legacy Pattern)
After (New Pattern)
References
Notes
easyscience.fitting.calculatorsmodule, matching the location of the legacyInterfaceFactoryTemplate_try_register_calculatormethod enables graceful handling of optional dependencies, improving user experience when not all calculator backends are installedBeta Was this translation helpful? Give feedback.
All reactions