Skip to content

rework factories, enclosure, and cross section registration#987

Merged
sebastian-goeldi merged 2 commits into
mainfrom
gf-cross-section-compatibility
Jun 14, 2026
Merged

rework factories, enclosure, and cross section registration#987
sebastian-goeldi merged 2 commits into
mainfrom
gf-cross-section-compatibility

Conversation

@sebastian-goeldi

@sebastian-goeldi sebastian-goeldi commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

1. generic_factories — register arbitrary functions as factories

  • layout.py: new KCLayout.generic_factories: dict[str, Callable[..., ProtoTKCell[Any]] | Callable[..., VKCell]], plus a @kcl.generic_factory decorator (usable bare, with name=, or as a direct call) that registers a cell-producing function and wraps it with a
    guardrail raising if the returned cell's .kcl isn't this layout.
  • tests/test_generic_factories.py: registration/delegation, the foreign-kcl guardrail, custom name, and independence from factories / virtual_factories.

2. Cross-section / enclosure rework (the bulk)

  • Single registry: CrossSectionModel now holds one cross_sections: dict[str, SymmetricalCrossSection | AsymmetricalCrossSection] (dropped the separate asymmetrical_cross_sections dict). One unified _register; cross-kind name uniqueness is automatic.
  • Canonical naming: every entry is keyed by its geometry-derived auto_name() and, when named, its explicit name. Existence is a single get(auto_name()). Unnamed entries resolve to a structurally-identical named one; registering a name promotes an unnamed
    canonical; a second name for one signature raises.
  • bbox → enclosure: bbox_sections removed as a SymmetricalCrossSection field; now a read-only property delegating to the enclosure. The enclosure's structural hash now folds in bbox_sections, so auto_name() is a complete key. Asymmetric auto_name() is now a
    SHA1 over its geometry.
  • radius as metadata: excluded from auto_name(), __eq__, and __hash__. Re-registering the same profile with a different radius raises (override radius at routing time instead).
  • __eq__: cross-kind comparisons return False; wrapper (CrossSection/DCrossSection/asymmetric) comparisons compare bases.
  • New error: CrossSectionNamingConflictError in exceptions.py.
  • symmetrical kwarg: get_cross_section / get_icross_section / get_dcross_section gained symmetrical: bool | None = None (replacing the old kind literal) — None = either kind, True = symmetric (raise otherwise), False = asymmetric (raise otherwise),
    via overloads.
  • Consumers updated for the single registry: serialization in layout.py (one loop, de-aliased via set()), session_cache.py (split into two pkls on dump, load both back), utils/difftest.py, schematic.py (iterates all kinds; map type widened), kcell.py.

3. Type / lint hygiene

  • decorators.py: @final on WrappedKCellFunc / WrappedVKCellFunc so isinstance narrowing is clean (fixed the schematic_driven diagnostics, removed redundant # ty: ignores).
  • Factories.get: key widened to object to satisfy Mapping.get's LSP contract.
  • Test/conftest updates (sym_enc factory fixture, etc.).
    • decorators.py: @Final on WrappedKCellFunc/WrappedVKCellFunc so isinstance narrowing is clean (fixed the schematic_driven diagnostics, removed redundant # ty: ignores).
    • Factories.get: key widened to object to satisfy Mapping.get's LSP contract.
    • Test/conftest updates (sym_enc factory fixture, etc.).

@sebastian-goeldi sebastian-goeldi added the enhancement New feature or request label Jun 13, 2026
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.17582% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.00%. Comparing base (b842d75) to head (439c6b3).

Files with missing lines Patch % Lines
src/kfactory/cross_section.py 80.55% 8 Missing and 6 partials ⚠️
src/kfactory/kcell.py 21.42% 11 Missing ⚠️
src/kfactory/layout.py 73.17% 6 Missing and 5 partials ⚠️
src/kfactory/enclosure.py 90.00% 2 Missing and 2 partials ⚠️
src/kfactory/session_cache.py 42.85% 2 Missing and 2 partials ⚠️
src/kfactory/utils/difftest.py 0.00% 1 Missing and 1 partial ⚠️
src/kfactory/schematic.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #987      +/-   ##
==========================================
+ Coverage   70.96%   71.00%   +0.03%     
==========================================
  Files          72       72              
  Lines       14423    14526     +103     
  Branches     2795     2817      +22     
==========================================
+ Hits        10236    10314      +78     
- Misses       3337     3347      +10     
- Partials      850      865      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sebastian-goeldi sebastian-goeldi marked this pull request as ready for review June 14, 2026 10:12
@sebastian-goeldi sebastian-goeldi merged commit bf8037e into main Jun 14, 2026
22 checks passed
@sebastian-goeldi sebastian-goeldi deleted the gf-cross-section-compatibility branch June 14, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant