Skip to content

fix(palace): mesh boolean stack levels from their evaluated region - #560

Open
Alisama20 wants to merge 1 commit into
gdsfactory:mainfrom
Alisama20:ali/palace-derived-layers
Open

Alisama20 wants to merge 1 commit into
gdsfactory:mainfrom
Alisama20:ali/palace-derived-layers

Conversation

@Alisama20

Copy link
Copy Markdown
Collaborator

Palace/FEM meshing now uses the evaluated region of boolean stack levels, as the FDTD route already does.

With the generic PDK, core is (WG - DEEP_ETCH) - SHALLOW_ETCH and shallow_etch is SHALLOW_ETCH & WG. The FDTD route evaluates these. The Palace route kept one GDS layer per level and read its raw polygons. So an etched component was meshed with the unetched core and shallow_etch was empty.

component level FDTD Palace before Palace after
grating_coupler_elliptical_trenches core 300.4 453.4 300.4
shallow_etch 153.0 – 153.0
strip with shallow-etch bar core 4.0 5.0 4.0
straight(cross_section="rib") core / slab90 5 / 65 5 / 65 5 / 65

Areas in µm² of the polygons handed to the mesher per stack level.

What changed:

  • A stack Layer records its PDK level when its layer is a boolean expression (private, not serialized). extract_geometry takes the region from the same function the FDTD route uses.
  • Polygons are filed under one key per level: the level name for boolean levels, (layer, datatype) for plain levels that share a GDS layer number with another datatype, and the layer number otherwise, as before. This also removes a collision where gpdk deep_etch and slab90 (both on layer 3) got each other's polygons.
  • The layout bbox still includes the drawn layer, so the domain size does not change.
  • The mesh fingerprint includes the expression for boolean levels.

Tests: tests/palace/test_derived_layers.py compares the area per stack level with the FDTD route on two synthetic strips, the grating coupler and a rib control, plus keys, symmetry planes, fingerprint and a Gmsh extrusion. tests/palace tests/common tests/fdtd: 5003 passed, 20 skipped. pre-commit clean on the changed files.

Behaviour change: Palace meshes of components that draw on boolean-level layers change (etched core, meshed shallow_etch volume), so their results change. Stacks loaded from YAML hold plain layers and are unaffected. I have not checked IHP or other PDK notebooks, and I have not run a Palace solve on an etched component.

@github-actions github-actions Bot added the bug Something isn't working label Nov 26, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T20:17:24.748980Z f85130d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da3a8c6a37

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

# ``WG - DEEP_ETCH``); ``gds_layer`` then holds only one leaf of it. Kept
# out of the serialized stack (YAML, ``model_dump``): a stack read back
# from YAML has plain layers.
_derived_source: Any = PrivateAttr(default=None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Serialize derived layer semantics in stack exports

When a PDK stack with a boolean level (for example gpdk core) is exported through the documented stack.to_yaml(...) workflow and later loaded with get_stack(yaml_path=...), this private attribute is omitted and the loader has no way to restore it. The reloaded layer consequently takes the plain-GDS branch in extract_geometry() and meshes the unetched leaf rather than the evaluated expression, so a saved stack no longer reproduces the simulation that created it; serialize a reconstructable expression or fail the export clearly instead of silently flattening it.

AGENTS.md reference: AGENTS.md:L50-L52

Useful? React with 👍 / 👎.

entry = layer.model_dump(mode="json", exclude={"mesh_resolution"})
if layer.derived_source is not None:
# the mesher meshes the evaluated expression, not the GDS tuple
entry["derived_layer"] = str(layer.derived_source.layer)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Hash background semantics for derived levels

When a boolean LayerLevel is also configured with background=True (and possibly background_exclude_layers), layer_level_region() meshes the component bounding box minus those exclusions rather than the region represented by .layer, but this cache entry hashes only .layer. Reusing a mesh after toggling the background flag or changing its exclusions therefore reports no stack change and can run against stale geometry; include every source field consulted by the evaluator in this fingerprint entry.

AGENTS.md reference: AGENTS.md:L50-L55

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.25000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.67%. Comparing base (55aad85) to head (f85130d).

Files with missing lines Patch % Lines
src/gsim/palace/mesh/geometry.py 95.16% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #560   +/-   ##
=======================================
  Coverage   91.66%   91.67%           
=======================================
  Files         216      216           
  Lines       30533    30590   +57     
  Branches     5672     5685   +13     
=======================================
+ Hits        27989    28042   +53     
- Misses       1458     1462    +4     
  Partials     1086     1086           

☔ 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.

@Alisama20

Copy link
Copy Markdown
Collaborator Author

Before and after, on grating_coupler_elliptical_trenches with the generic PDK.

Polygons the Palace mesher receives per stack level (top view). Before the fix the core is the raw WG layer (453.4 µm²) and shallow_etch is empty. After, both match what the FDTD route resolves (dashed outline): core 300.4 µm², shallow_etch 153.0 µm².

polygons before and after

Mesh, x-z slice through the trenches, coarse preset. Before: 634 tetrahedra and a flat unetched core. After: 69,843 tetrahedra with the trenches meshed as shallow_etch.

mesh before and after

@Alisama20

Copy link
Copy Markdown
Collaborator Author

@nikosavola could you review this one? Palace meshed etched levels with the unetched core, so any FEM run of a grating or a rib with shallow-etch bars simulated a different device. The before/after images are in the comment above.

@vvahidd
vvahidd force-pushed the ali/palace-derived-layers branch from da3a8c6 to f85130d Compare December 1, 2026 20:10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f85130d7fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

elif gds_tuple in boolean_tuples:
sources.append((None, gds_tuple, polys, False))
for name, level in boolean_levels.items():
polys = _boolean_level_polygons(component, level)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Evaluate derived conductors during auto-sizing

When a derived conductor's boolean operation creates a narrower feature than its first GDS leaf and auto_size=True (or the default resolution warning runs), this branch gives the evaluated region to the mesher, but auto_size._conductor_regions() still reads only layer.gds_layer. The advertised minimum-feature calculation therefore sizes against the unetched mask and can leave the newly corrected conductor under-resolved without a warning; evaluate derived_source in that path as well.

AGENTS.md reference: AGENTS.md:L53-L55

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant