Skip to content

feat(palace): expose adaptive mesh refinement controls - #285

Merged
vvahidd merged 1 commit into
gdsfactory:mainfrom
Alisama20:feat/expose-amr-refinement
Sep 30, 2026
Merged

vvahidd merged 1 commit into
gdsfactory:mainfrom
Alisama20:feat/expose-amr-refinement

Conversation

@Alisama20

Copy link
Copy Markdown
Collaborator

Summary

The generated config always carried a fixed Model.Refinement block with MaxIts = 0, so Palace's adaptive mesh refinement (AMR) could not be switched on from gsim. This adds RefinementConfig, which maps onto that block, and set_refinement() on every Palace simulation:

sim.set_refinement(max_its=5, tol=1e-3, max_dofs=2_000_000)

Palace's MaxSize is exposed as max_dofs, since it is a limit on the degrees of freedom and add_wave_port(max_size=...) already means something else.

Nothing changes by default. The block keeps the same three keys and values (UniformLevels: 0, Tol: 0.01, MaxIts: 0), which are also Palace's defaults, and keys left unset are not written, so Palace applies its own. uniform_levels is exposed too: it lets a coarse mesh file stand in for a finer mesh that Palace refines uniformly after loading.

In a frequency sweep, Palace refines on the error indicator averaged over the sampled frequencies (palace/fem/errorindicator.cpp), so a narrow resonance can end up under-refined. The docstring says so.

Part of #265.

Test Plan

New tests/palace/test_refinement_controls.py, following the pattern of #253. The key names and bounds are checked against Palace's own schema (scripts/schema/config-schema.json), which rejects unknown keys:

  • the default block is unchanged, with and without a default RefinementConfig;
  • every control reaches the config under Palace's key name, and only keys the schema knows are written;
  • unset controls are left out;
  • values outside the schema's bounds are rejected (Tol > 0, 0 < UpdateFraction < 1, non-negative integers);
  • set_refinement() replaces the sim's config;
  • write_config() forwards it, and the sim's write_config() passes it on. Removing either forwarding line makes exactly the matching test fail.

Also generated the full config.json of the simulation in nbs/palace_cpw_lumped.ipynb and validated it against the same schema with jsonschema: no errors by default, and none with every control set. The default file is byte-identical to the one main writes. As a control, the validator does reject a misspelled key, a negative MaxIts, UpdateFraction = 1 and Tol = 0.

Full suite: 1376 passed, 6 skipped (the 1363 that pass on main plus the 13 new tests). pre-commit: all hooks pass.

The generated config always carried a fixed Model.Refinement block with
MaxIts = 0, so Palace's adaptive mesh refinement could not be switched on
from gsim. Add RefinementConfig, which maps onto that block, and
set_refinement() on every Palace simulation, forwarded through
write_config(). The defaults write the same three keys as before; keys
left unset are not written, so Palace applies its own defaults.

Part of gdsfactory#265.
@codecov

codecov Bot commented Sep 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.73%. Comparing base (5b52244) to head (511242c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #285      +/-   ##
==========================================
+ Coverage   64.67%   64.73%   +0.06%     
==========================================
  Files         107      107              
  Lines       16528    16554      +26     
  Branches     3271     3272       +1     
==========================================
+ Hits        10689    10716      +27     
+ Misses       4812     4810       -2     
- Partials     1027     1028       +1     

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

@vvahidd
vvahidd merged commit ae25c03 into gdsfactory:main Sep 30, 2026
17 checks passed
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.

2 participants