Skip to content

refactor(): Draft context manager#1634

Merged
benflexcompute merged 10 commits intomainfrom
BenY/DraftContextManager
Dec 11, 2025
Merged

refactor(): Draft context manager#1634
benflexcompute merged 10 commits intomainfrom
BenY/DraftContextManager

Conversation

@benflexcompute
Copy link
Collaborator

No description provided.

… API

Completes Stage 1 of entity management refactoring plan:
- Remove entity_bucket from EntityBase and all entity classes
- Refactor EntityRegistry to use type-based storage (Dict[type[EntityBase], List])
- Add EntityRegistryView class with glob pattern support
- Add registry.view(entity_type) method for filtered access
- Add registry.view_subclasses(parent_type) for subclass iteration
- Update all tests to use new view() API instead of get_bucket()

Key changes:
- EntityRegistry.internal_registry now keyed by type instead of string bucket
- EntityRegistryView supports glob patterns: registry.view(Surface)['wing*']
- Replace get_bucket() calls with view() throughout codebase
- Add DraftContext with entity isolation support

This establishes foundation for making entity_info single source of truth.
Adds factory method for building EntityRegistry from entity_info:
- Add EntityRegistry.from_entity_info(entity_info) classmethod
- Add _register_from_entity_info() internal method
- Handle all entity_info types: GeometryEntityInfo, VolumeMeshEntityInfo, SurfaceMeshEntityInfo
- Register draft_entities and ghost_entities (common to all types)
- Use fast_register() for performance with hash deduplication
- Use type_name string check instead of isinstance to avoid circular imports

Key design decisions:
- Completely isolated from legacy get_persistent_entity_registry() path
- Stores references to same entity objects (not copies)
- Designed for DraftContext workflow only
…ew()

- create_draft() now deep copies entity_info via model_dump/model_validate
  ensuring draft modifications don't affect the original asset
- Remove _SingleTypeEntityRegistry class, use EntityRegistry.view() directly
- DraftContext now uses EntityRegistry.from_entity_info() for registry building
- Add 6 new tests verifying draft entity isolation behavior
- Update REFACTOR_PLAN.md to mark Stage 3 complete
Add draft_entity_info parameter to set_up_params_for_uploading() to use
DraftContext's entity_info as source of truth during upload. Implement
_merge_draft_entities_from_params() to collect draft entities from params
and merge into entity_info without duplicates.
@benflexcompute benflexcompute force-pushed the BenY/DraftContextManager branch from 2cb155b to c64b678 Compare December 8, 2025 02:00
  This stage completes the transition from dictionary-based entity lookup to EntityRegistry-based
  entity selection and materialization. The EntityRegistry now provides proper entity reference
  management with grouping selection support.

  Key Changes:

  1. EntityRegistry Enhancements:
     - Added find_by_name(name) for exact name lookups
     - Added find_by_type(entity_class) for type-based queries with subclass support
     - Added find_by_type_name(type_name) for serialized type name matching
     - Fixed _register_from_entity_info() to respect user grouping selection
       * Only registers entities from selected grouping (face_group_tag, edge_group_tag, body_group_tag)
       * Previously registered ALL entities from ALL groupings (incorrect)
     - DRY refactoring: extracted _register_selected_grouping() helper to eliminate duplication
     - Removed SimpleNamespace support (entity_info must be deserialized objects)

  2. Entity Expansion Refactoring (entity_expansion_utils.py):
     - Replaced SelectorEntityPool-building functions with EntityRegistry-based approach
     - Added get_registry_from_dict() - deserializes entity_info and builds EntityRegistry
     - Added get_registry_from_params() - builds EntityRegistry from SimulationParams
     - Strips legacy fields (private_attribute_registry_bucket_name, private_attribute_potential_issues)
       for backward compatibility with older JSON files
     - Removed _build_selector_pool_from_entity_info() and related helpers

  3. Entity Selector Integration (entity_selector.py):
     - Updated _process_selectors() to accept EntityRegistry instead of SelectorEntityPool
     - Changed _get_entity_pool() to use registry.find_by_type_name()
     - Updated _expand_node_selectors() to work with EntityRegistry
     - Selector expansion now uses proper entity references from registry

  4. Testing:
     - Added test_entity_registry_respects_grouping_selection() to verify grouping logic
       * Ensures only entities from selected grouping are registered
       * Tests face, edge, and body grouping selections
     - Updated _DummyParams test fixture to deserialize entity_info (no SimpleNamespace)
     - Added required private_attribute_is_interface field to test data
     - All 8 entity_dict_database tests pass
     - All 672 simulation tests pass

  5. Documentation:
     - Updated REFACTOR_PLAN.md to mark Stage 5 complete
     - Added Stage 5 completion summary with usage examples
     - Documented EntityRegistry API additions

  Architecture Impact:
  - EntityRegistry is now the single source of truth for entity lookup
  - Proper separation: EntityRegistry provides references, doesn't create entities
  - Entity creation happens during deserialization (get_registry_from_dict)
  - Grouping selection properly enforced (user's selected grouping only)
  - Legacy field handling centralized in deserialization layer
…stry and optimize performance

  Replace the entity_pool dict-based approach with EntityRegistry for entity
  materialization, implementing two distinct operation modes with significant
  performance optimizations.
@benflexcompute benflexcompute merged commit 25a6e37 into main Dec 11, 2025
20 checks passed
@benflexcompute benflexcompute deleted the BenY/DraftContextManager branch December 11, 2025 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant