Repository navigation
Add COMSOL (MPh) simulation plugin - #786
Conversation
Generic COMSOL Multiphysics helpers ported from the Quantum RF PDK: layout extraction on any metal layer with optional crop to feed ports, sheet and extruded-metal model builders, driven CPW RF study, electrostatic capacitance study, mesh helpers, plotting and result utilities. Mocked tests, docs notebook, CI matrix entry, and the gplugins[comsol] extra. Refs gdsfactory#785 Co-authored-by: Niko Savola <niko@gdsfactory.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Sorry @jackgdsf, your pull request is larger than the review limit of 150,000 diff characters |
Co-authored-by: Niko Savola <niko@gdsfactory.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs gdsfactory#785 Co-authored-by: Niko Savola <niko@gdsfactory.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Core geometry and solver behavior has only mocked coverage and has not been exercised against a live COMSOL installation.
2 open findings
What changed in this PR
Adds a COMSOL Multiphysics plugin using MPh for layout extraction, model construction, RF and capacitance studies, meshing, plotting, and results handling.
Changes:
- Adds COMSOL geometry, study, mesh, model, plotting, and result APIs.
- Adds mocked test coverage and a CPW tutorial notebook.
- Adds packaging, CI, documentation, linting, and changelog integration.
| File | Description |
|---|---|
README.md |
Documents COMSOL support and installation. |
pyproject.toml |
Adds the comsol optional dependency. |
notebooks/comsol_01_cpw.ipynb |
Demonstrates CPW and capacitance workflows. |
gplugins/comsol/__init__.py |
Defines public and lazy exports. |
gplugins/comsol/_util.py |
Adds shared Java API helpers. |
gplugins/comsol/layout.py |
Extracts and crops layout geometry. |
gplugins/comsol/metal.py |
Builds extruded metal geometry. |
gplugins/comsol/sheet.py |
Builds sheet-metal dielectric models. |
gplugins/comsol/rf.py |
Adds driven CPW RF studies. |
gplugins/comsol/capacitance.py |
Adds electrostatic capacitance studies. |
gplugins/comsol/mesh.py |
Adds mesh refinement and sizing helpers. |
gplugins/comsol/model.py |
Adds the chainable MPh model wrapper. |
gplugins/comsol/results.py |
Adds exported-result utilities. |
gplugins/comsol/plotting.py |
Adds layout and field plotting helpers. |
gplugins/comsol/tests/__init__.py |
Initializes the test package. |
gplugins/comsol/tests/test_comsol.py |
Tests exports and metal building. |
gplugins/comsol/tests/test_comsol_layout.py |
Tests layout extraction and cropping. |
gplugins/comsol/tests/test_comsol_sheet.py |
Tests sheet geometry and materials. |
gplugins/comsol/tests/test_comsol_rf.py |
Tests RF study construction. |
gplugins/comsol/tests/test_comsol_capacitance.py |
Tests capacitance studies. |
gplugins/comsol/tests/test_comsol_mesh.py |
Tests mesh helpers. |
gplugins/comsol/tests/test_comsol_model.py |
Tests the model wrapper. |
gplugins/comsol/tests/test_comsol_results.py |
Tests result utilities. |
gplugins/comsol/tests/test_comsol_plotting.py |
Tests plotting helpers. |
docs/zensical.yml |
Adds the notebook to documentation navigation. |
.pre-commit-config.yaml |
Includes COMSOL code in Ruff hooks. |
.github/workflows/test_code.yml |
Adds COMSOL to the CI matrix. |
.changelog.d/786.added |
Records the new plugin. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| Returns: | ||
| The ``range`` expression, and the ``points``-long grid it should return. | ||
| """ | ||
| step_ghz = (high_ghz - low_ghz) / (points - 1) |
| file = "LICENSE" | ||
|
|
||
| [project.optional-dependencies] | ||
| comsol = ["MPh>=1.4,<2", "shapely"] |
|
Critical review (automated, Fable model) Scope: head HighH1 — MediumM1 — M2 — M3 — M4 — Tests verify the author's own API guesses, not COMSOL. LowL1 — L2 — L3 — Dead L4 — Verified OK
Verdict: Request changes — H1 breaks the only runnable demo, M1/M2 are latent runtime failures on documented parameters, and the solver-facing code remains unverified by any live run. |
- Notebook: start one MPh client in the setup cell and reuse it in both solve cells; COMSOL and numpy are imported unconditionally, so no cell relies on names imported inside another cell's if. - rf: port-face boxes are bounded only along the port axis; a plane with no face (sheet built with lateral_margin_um > 0) raises an explicit error, and the coupling is documented on the sheet builders. - rf: CPW cross sections are checked and the port planes probed before any other selection is created. - mesh: pin_absolute_mesh_sizes sweeps extra generated size* features, like the edge variant. - results: requested_frequency_grid rejects points < 2 and degenerate windows; exported_frequency_ghz no longer assumes a unit-less "@ freq=" value is GHz (new bare_unit keyword); explain_missing_results no longer names notebook globals. - plotting: draw_cut_plane_field takes log colour limits from positive nodes only, so exports with many zero-field nodes no longer crash. - capacitance/rf: refuse conductor tags that are not COMSOL tags or that clash with existing comp1 selections, and refuse a model that already holds mesh1/std1. - Drop the ruff: ignore pseudo-directives (not ruff syntax; the named rules are not selected) and test_historical_cpw_alias_is_gone. Co-authored-by: Niko Savola <niko@gdsfactory.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reply to the critical review, addressed in 53e488b. H1 Fixed. The setup cell starts one MPh client (only when M1 Fixed with an explicit error and docs. The port-face box is now bounded only along the port axis. A plane that selects no face raises an error naming M2 Fixed. M3 Fixed in place rather than dropped, because a downstream wrapper re-exports
Tests were added for each of these. M4 Not changed. The fake-Java tests only check the call sequence. Until one live run is recorded, the RF/ES solver path is UNVERIFIED. L1 Fixed. L2 Fixed by validating rather than renaming, so the tags users pass to
L3 Fixed. The L4 Fixed. The test was removed. Pre-commit is green apart from lychee. It failed on one external link in |

Part 1 of #785: adds
gplugins.comsol, generic COMSOL Multiphysics helpers built on MPh.prepare_comsol_layout(component, layer, feed_ports, crop_to_feed_ports=...)extracts merged metal polygons on any layer, with an optional crop between two feed ports. Also addscrop_planes,feed_port,validate_crop_containment. Usesbegin_shapes_rec, so it works on locked/cached cells.COMSOL(mph.Model)wrapper. MPh is imported lazily.gplugins[comsol]extra, CI matrix entry, ruff pre-commit scope.notebooks/comsol_01_cpw.ipynbdoes a CPW extraction and plot. The solver cells sit behindRUN_COMSOL, and the notebook links to the Quantum RF PDK's solved notebooks.mph).Not verified on a live COMSOL install. The solver code was ported from the PDK implementation and checked against the MPh/COMSOL API docs only. A human must review the code before merge.
Requested by @nikosavola
🤖 Generated with Claude Code