Skip to content

fix: #886 - [E2-F2-P3] Create EquilibriaFactory#894

Merged
Gorkowski merged 2 commits intouncscode:mainfrom
Gorkowski:issue-886-adw-1d906f5f
Jan 20, 2026
Merged

fix: #886 - [E2-F2-P3] Create EquilibriaFactory#894
Gorkowski merged 2 commits intouncscode:mainfrom
Gorkowski:issue-886-adw-1d906f5f

Conversation

@Gorkowski
Copy link
Collaborator

Target Branch: main

Fixes #886 | Workflow: 1d906f5f

Summary

Adds the EquilibriaFactory so 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 helpful ValueError when 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 - Introduces EquilibriaFactory, implements get_builders() returning fresh builders, and get_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/None parameters, and expected exceptions for invalid names or parameter values.

Modified Components

  • particula/equilibria/__init__.py - Re-exports EquilibriaFactory so 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. A ValueError lists available strategy names when a caller requests something unknown, keeping the factory behavior predictable and transparent.

Implementation Notes

  • Why this approach: Matching the existing factory infrastructure keeps equilibria code consistent with WallLossFactory and friends, making it easy to add future strategies.
  • Error messaging: Unknown strategy names echo the valid options so callers can correct typos without inspecting code.
  • Builder isolation: Fresh builder instances guard against shared mutable state between successive factory calls.

Testing

  • Not run (not requested)

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
Copilot AI review requested due to automatic review settings January 20, 2026 02:53
@Gorkowski Gorkowski added agent Created or managed by ADW automation blocked Blocked - review required before ADW can process labels Jan 20, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EquilibriaFactory with 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.

@Gorkowski Gorkowski merged commit 20cc20f into uncscode:main Jan 20, 2026
13 checks passed
@Gorkowski Gorkowski deleted the issue-886-adw-1d906f5f branch January 20, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Created or managed by ADW automation blocked Blocked - review required before ADW can process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[E2-F2-P3] Create EquilibriaFactory

1 participant