fix: ensure deterministic unnamed subcircuit connectivity keys#2332
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR aims to make subcircuit_connectivity_map_key deterministic for unnamed subcircuits by removing the use of the runtime-derived group._renderId, improving SVG/snapshot stability across renders.
Changes:
- Replaces
_renderId-based fallback connectivity key generation with a deterministic identifier based ongroup.subcircuit_id/group.source_group_id. - Applies the new deterministic fallback consistently for traces, ports, and nets in subcircuits.
Comments suppressed due to low confidence (2)
lib/components/primitive-components/Group/Group_doInitialSourceAddConnectivityMapKey.ts:71
- Same issue here:
?? ""can produce an empty unnamed-subcircuit suffix, leading to ambiguous/colliding connectivity keys. Prefer requiring a stable identifier (e.g.,subcircuit_idorsource_group_id) instead of falling back to an empty string.
const connectivityMapKey = `${subcircuitName ?? `unnamedsubcircuit${group.subcircuit_id ?? group.source_group_id ?? ""}`}_${connNetId}`
lib/components/primitive-components/Group/Group_doInitialSourceAddConnectivityMapKey.ts:99
- Same issue here: falling back to an empty string for the unnamed subcircuit identifier can create duplicate keys across subcircuits. It’s safer to require
subcircuit_id/source_group_idto be present than to emit a potentially-colliding key.
const connectivityMapKey = `${subcircuitName ?? `unnamedsubcircuit${group.subcircuit_id ?? group.source_group_id ?? ""}`}_${connNetId}`
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
seveibar
left a comment
There was a problem hiding this comment.
This would be much better if you didn't use ids. Also you should have a test that uses toMatchInlineSnapshot so that we can see the id that's generated
…unnamed subcircuits
|
I think it's ok to use ids in this case, but ideally we find a better key using something like |
|
currently this return something like |
…onents and keys for improved determinism
|
This PR has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs. |
…unnamed subcircuits
…onents and keys for improved determinism
93e2f90 to
3d789ec
Compare
… of https://github.com/rushabhcodes/core into fix/deterministic-unnamed-subcircuit-connectivity-keys
…eterminism and clarity
…larity and determinism
|
Thank you for your contribution! 🎉 PR Rating: ⭐⭐⭐ Track your contributions and see the leaderboard at: tscircuit Contribution Tracker |
This pull request improves the determinism and correctness of how unnamed subcircuit connectivity map keys are generated for groups, traces, ports, and nets. The logic now consistently uses a combination of
subcircuit_id,source_group_id, or a fallback render ID to ensure that keys are stable and unique across renders. Existing test fixtures and outputs are updated to match the new key format, and a new test verifies that the generated keys remain deterministic.Key changes include:
Connectivity Map Key Generation Improvements:
Group_doInitialSourceAddConnectivityMapKeyto generatesubcircuit_connectivity_map_keyusingsubcircuitName ?? unnamedsubcircuit${group.subcircuit_id ?? group.source_group_id ?? group._renderId}instead of relying solely on_renderId. This ensures keys are more stable and meaningful, especially for unnamed subcircuits. [1] [2] [3]Testing and Validation:
group-unnamed-subcircuit-connectivity-map-key.test.tsx) that renders circuits with unnamed subcircuits multiple times and asserts that the generated connectivity map keys are deterministic and consistent across renders.Fixture and Test Data Updates:
simple-circuit.json) to use the new, deterministicsubcircuit_connectivity_map_keyformat, replacing previous keys that used only the render ID. [1] [2] [3] [4]These changes make subcircuit connectivity mapping more robust and predictable, reducing the likelihood of key collisions or inconsistencies between renders.