feat(palace): expose adaptive mesh refinement controls - #285
Merged
Merged
Conversation
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.
Alisama20
requested review from
cdaunt,
flaport,
joamatab,
nikosavola and
vvahidd
as code owners
September 29, 2026 11:37
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This was referenced Sep 29, 2026
vvahidd
approved these changes
Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The generated config always carried a fixed
Model.Refinementblock withMaxIts = 0, so Palace's adaptive mesh refinement (AMR) could not be switched on from gsim. This addsRefinementConfig, which maps onto that block, andset_refinement()on every Palace simulation:Palace's
MaxSizeis exposed asmax_dofs, since it is a limit on the degrees of freedom andadd_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_levelsis 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:RefinementConfig;Tol > 0,0 < UpdateFraction < 1, non-negative integers);set_refinement()replaces the sim's config;write_config()forwards it, and the sim'swrite_config()passes it on. Removing either forwarding line makes exactly the matching test fail.Also generated the full
config.jsonof the simulation innbs/palace_cpw_lumped.ipynband validated it against the same schema withjsonschema: no errors by default, and none with every control set. The default file is byte-identical to the onemainwrites. As a control, the validator does reject a misspelled key, a negativeMaxIts,UpdateFraction = 1andTol = 0.Full suite: 1376 passed, 6 skipped (the 1363 that pass on
mainplus the 13 new tests). pre-commit: all hooks pass.