Skip to content

Add hierarchical subcircuit composition support - #39

Merged
cdaunt merged 4 commits into
mainfrom
feat/subcircuit-hierarchy
Jul 28, 2026
Merged

Add hierarchical subcircuit composition support#39
cdaunt merged 4 commits into
mainfrom
feat/subcircuit-hierarchy

Conversation

@cdaunt

@cdaunt cdaunt commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds support for hierarchical subcircuit composition to circulax, enabling the equivalent of SPICE's .subckt directive. This allows recursive netlist flattening before compilation, enabling arbitrary nesting depth — an advantage over SAX's bottom-up composition which fails under JAX tracing at deep nesting levels.

Changes

  • feat(hierarchy): add recursive netlist flattening and subcircuit composition

    • Implement flatten_recursive_netlist() to flatten dict-of-Netlists to SAX format
    • Extend compile_circuit() to accept RecursiveNetlist input and Circuit objects
    • Store source netlist/models metadata on compiled Circuit objects
    • Add 20 comprehensive tests covering flattening, composition, and edge cases
    • Handle circulax connection extensions (tuple targets, nets lists)
    • GND instances are never prefixed during flattening
  • test(subcircuit): add 6-level deep nesting tests for flattening and DC solve

    • test_6_level_deep_nesting: verifies correct instance naming and component type after flattening 6 nested levels
    • test_6_level_deep_nesting_dc_solve: end-to-end test compiling and DC-solving a 6-level deep circuit

Testing

All 243 existing tests pass plus 20 new tests with zero regressions.

cdaunt added 2 commits July 28, 2026 13:36
…osition

Add support for hierarchical subcircuit composition via RecursiveNetlist:
- Implement flatten_recursive_netlist() to flatten dict-of-Netlists to SAX format
- Extend compile_circuit() to accept RecursiveNetlist input and Circuit objects
- Store source netlist/models metadata on compiled Circuit objects via properties
- Add 20 comprehensive tests covering flattening, composition, and edge cases
- Document hierarchy specification and roadmap in references/

Handles circulax connection extensions (tuple targets, nets lists). GND
instances are never prefixed during flattening. All 243 existing tests pass
plus 20 new tests with zero regressions.
…C solve

Adds two tests demonstrating circulax's pre-compilation flattening works at
arbitrary depth:
- test_6_level_deep_nesting: verifies correct instance naming (a~x~x~x~x~x~x)
  and component type after flattening 6 nested levels
- test_6_level_deep_nesting_dc_solve: end-to-end test compiling and DC-solving
  a 6-level deep circuit, verifying correct voltage at deepest node

These tests demonstrate an advantage over SAX's bottom-up circuit composition,
which fails under JAX tracing at similar depth due to concrete boolean indexing.
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

cdaunt added 2 commits July 28, 2026 13:49
Update references/hierarchy.md to document the actual implementation
landed in PR #39:
- Status: V1 now implemented (was: specified, not yet implemented)
- Implementation Files: document all actual functions and helpers added
- Circuit additions: list public properties (ports, source_netlist, source_models)
- Test matrix: expand from 8 planned to 22 actual tests across 4 test classes
- Verification: document 265 total tests (243 existing + 22 new), all passing
- V2 notes: update to reflect V1 has landed
…specs/

Scaffold specs/ directory structure with overview index and move hierarchy
specification from references/ to specs/ to co-locate with other design docs.
Remove references/README.md now that its content is superseded.
@cdaunt
cdaunt marked this pull request as ready for review July 28, 2026 15:58
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@cdaunt
cdaunt merged commit 4958832 into main Jul 28, 2026
6 checks passed
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