fix: #886 - [E2-F2-P3] Create EquilibriaFactory#894
Merged
Gorkowski merged 2 commits intouncscode:mainfrom Jan 20, 2026
Merged
Conversation
Introduce EquilibriaFactory to select equilibria strategies by name using the existing builder pattern. The factory normalizes strategy keys, delegates parameter validation to builders, and raises clear errors on unknown types. Add comprehensive tests covering mapping, parameter flow, case-insensitive lookup, default handling, and error paths. Export the factory through the equilibria package for public use. Closes uncscode#886 ADW-ID: 1d906f5f
Successfully fixed: - Exposed EquilibriaFactory through `particula.equilibria` and cleaned up the factory implementation to normalize strategy names. - Added focused tests that assert builder mapping, case-insensitive lookups, and parameter propagation for liquid vapor strategies. - Hardened parameter handling by defaulting to builder values and rejecting invalid non-dict inputs before building. Still failing (if any): - None. Closes uncscode#886 ADW-ID: 1d906f5f
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements EquilibriaFactory to provide string-based strategy selection for equilibria solvers, completing phase P3 of the E2-F2 Equilibria Runnable Refactor. The factory follows the established StrategyFactoryABC pattern used throughout particula, enabling configuration-file-driven strategy instantiation.
Changes:
- Added
EquilibriaFactorywith registry-based builder management and case-insensitive strategy lookup - Implemented comprehensive test suite covering builder isolation, parameter propagation, and error handling
- Exported factory from equilibria package for external consumption
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
particula/equilibria/equilibria_factories.py |
Implements EquilibriaFactory with get_builders() and get_strategy() methods, providing case-insensitive lookup, parameter copying, and enhanced error messages listing valid strategy types |
particula/equilibria/tests/equilibria_factories_test.py |
Comprehensive test suite validating builder freshness, parameter forwarding, case-insensitive lookup, default handling, and error paths for invalid strategy names and parameter values |
particula/equilibria/__init__.py |
Exports EquilibriaFactory to make it accessible from the equilibria package |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Target Branch:
mainFixes #886 | Workflow:
1d906f5fSummary
Adds the
EquilibriaFactoryso callers can obtain equilibria strategies by name, mirroring the factory pattern used elsewhere in particula. The factory manages a case-insensitive registry of builders, forwards parameter maps after making a local copy, and raises a helpfulValueErrorwhen an unknown strategy name is requested. Co-located tests cover builder registration, parameter propagation, case-insensitive lookup, and the expected error handling.What Changed
New Components
particula/equilibria/equilibria_factories.py- IntroducesEquilibriaFactory, implementsget_builders()returning fresh builders, andget_strategy()that normalizes strategy names, copies parameter maps, delegates validation to builders, and reports valid choices when an unknown name is supplied.particula/equilibria/tests/equilibria_factories_test.py- Adds tests covering builder map contents, fresh builder instances, parameter forwarding, case-insensitive lookup, handling of empty/Noneparameters, and expected exceptions for invalid names or parameter values.Modified Components
particula/equilibria/__init__.py- Re-exportsEquilibriaFactoryso the new entry point is available from the equilibria package.Tests Added/Updated
particula/equilibria/tests/equilibria_factories_test.py- Validates strategy creation defaults, parameterized builds, case-insensitive lookups, and error paths to achieve full coverage of the factory logic.How It Works
Every call to
get_builders()returns a fresh mapping keyed by lowercased names so factories cannot share builder instances inadvertently.get_strategy()lowercases the requested name, looks it up in the builder map, copies the provided parameter dict (if any) before passing it to the builder, and finally builds the strategy. AValueErrorlists available strategy names when a caller requests something unknown, keeping the factory behavior predictable and transparent.Implementation Notes
WallLossFactoryand friends, making it easy to add future strategies.Testing