setupEM 0.17.0__tar.gz → 0.18.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. setupem-0.18.1/PKG-INFO +109 -0
  2. {setupem-0.17.0 → setupem-0.18.1}/README.md +7 -2
  3. setupem-0.18.1/README_pypi.md +80 -0
  4. {setupem-0.17.0 → setupem-0.18.1}/pyproject.toml +1 -1
  5. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/__init__.py +9 -2
  6. setupem-0.18.1/src/setupEM/cli_common.py +86 -0
  7. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/config_update.py +103 -1
  8. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/data/SG13CMOS5L_200um.xml +5 -0
  9. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_FEM_200um.xml +5 -0
  10. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_FEM_200um_passi3D.xml +5 -0
  11. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/field_viewer.py +41 -23
  12. setupem-0.18.1/src/setupEM/join_pieces.py +208 -0
  13. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/layout_preview.py +388 -1
  14. setupem-0.18.1/src/setupEM/piece_set.py +598 -0
  15. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/result_viewer.py +72 -9
  16. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/run_with_overrides.py +10 -1
  17. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/setupEM.py +962 -148
  18. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/setupThermal.py +72 -29
  19. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/setup_common.py +689 -56
  20. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/stackupEditor.py +8 -4
  21. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/thermal_results.py +15 -8
  22. setupem-0.18.1/src/setupEM.egg-info/PKG-INFO +109 -0
  23. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM.egg-info/SOURCES.txt +10 -0
  24. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM.egg-info/requires.txt +1 -1
  25. setupem-0.18.1/tests/test_cli_startup.py +289 -0
  26. {setupem-0.17.0 → setupem-0.18.1}/tests/test_config_update.py +66 -0
  27. setupem-0.18.1/tests/test_config_update_gui.py +334 -0
  28. setupem-0.18.1/tests/test_deembedded_view.py +71 -0
  29. setupem-0.18.1/tests/test_join_pieces.py +132 -0
  30. setupem-0.18.1/tests/test_margin_per_side.py +346 -0
  31. setupem-0.18.1/tests/test_piece_set.py +483 -0
  32. setupem-0.18.1/tests/test_port_walls.py +440 -0
  33. setupem-0.18.1/tests/test_qt_platform_noise.py +23 -0
  34. {setupem-0.17.0 → setupem-0.18.1}/tests/test_run_with_overrides.py +52 -0
  35. {setupem-0.17.0 → setupem-0.18.1}/tests/test_thermal_results.py +7 -1
  36. setupem-0.17.0/PKG-INFO +0 -106
  37. setupem-0.17.0/README_pypi.md +0 -77
  38. setupem-0.17.0/src/setupEM.egg-info/PKG-INFO +0 -106
  39. setupem-0.17.0/tests/test_config_update_gui.py +0 -185
  40. {setupem-0.17.0 → setupem-0.18.1}/LICENSE +0 -0
  41. {setupem-0.17.0 → setupem-0.18.1}/setup.cfg +0 -0
  42. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/__main__.py +0 -0
  43. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_100um.xml +0 -0
  44. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_200um.xml +0 -0
  45. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_nosub.xml +0 -0
  46. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/gds_hierarchy_scan.py +0 -0
  47. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/momentum_import.py +0 -0
  48. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/palace_results.py +0 -0
  49. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/script_model.py +0 -0
  50. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/script_probe.py +0 -0
  51. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/simplify_gds.py +0 -0
  52. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM/stackup_writer.py +0 -0
  53. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM.egg-info/dependency_links.txt +0 -0
  54. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM.egg-info/entry_points.txt +0 -0
  55. {setupem-0.17.0 → setupem-0.18.1}/src/setupEM.egg-info/top_level.txt +0 -0
  56. {setupem-0.17.0 → setupem-0.18.1}/tests/test_script_model.py +0 -0
  57. {setupem-0.17.0 → setupem-0.18.1}/tests/test_script_probe.py +0 -0
  58. {setupem-0.17.0 → setupem-0.18.1}/tests/test_table_rows.py +0 -0
  59. {setupem-0.17.0 → setupem-0.18.1}/tests/test_thermal_powers.py +0 -0
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.4
2
+ Name: setupEM
3
+ Version: 0.18.1
4
+ Summary: Python tool for configuration of gds2palace workflow with GUI.
5
+ Author-email: Volker Muehlhaus <volker@muehlhaus.com>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/VolkerMuehlhaus/setupEM
8
+ Project-URL: Repository, https://github.com/VolkerMuehlhaus/setupEM
9
+ Project-URL: Changelog, https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: gds2palace>=0.10.1
14
+ Requires-Dist: gds_prepare_for_EM>=1.6.0
15
+ Requires-Dist: PySide6
16
+ Requires-Dist: shiboken6
17
+ Requires-Dist: scipy
18
+ Requires-Dist: requests
19
+ Requires-Dist: scikit-rf
20
+ Requires-Dist: matplotlib
21
+ Requires-Dist: numpy
22
+ Requires-Dist: gdspy
23
+ Requires-Dist: meshio
24
+ Requires-Dist: pyvista
25
+ Requires-Dist: pyvistaqt
26
+ Provides-Extra: test
27
+ Requires-Dist: pytest; extra == "test"
28
+ Dynamic: license-file
29
+
30
+ # Python GUI for gds2palace
31
+
32
+ ![Intro](https://raw.githubusercontent.com/VolkerMuehlhaus/setupEM/main/doc/png/setupEM_banner.png)
33
+
34
+ ## Install
35
+
36
+ pip install setupEM
37
+
38
+ **Full documentation, installation guide, and usage walkthrough:**
39
+ https://github.com/VolkerMuehlhaus/setupEM
40
+
41
+ ## Recent changes
42
+
43
+ # What's New - November 11, 2026 (setupEM 0.18.1)
44
+
45
+ **Command line fixes** (from issue #52, use without a display):
46
+ - `--help`, `--version` and a wrong argument of `setupEM`, `setupThermal`, `stackupEditor`, `resultViewer` and `fieldViewer` no longer need a display: the arguments are read before Qt starts. All five have `--version` now.
47
+ - `setupEM -simcfg <file>` opens a settings file of an Elmer model in Elmer mode. It opened in Palace mode unless `--elmer` was given, also when started from the KLayout plug-in.
48
+ - A `-simcfg`, `-gdsfile` or `-xmlfile` that does not exist, or a settings file of the other application, ends `setupEM` / `setupThermal` with a message on stderr and exit code 2 instead of an empty window. In the GUI, a settings file that is gone is reported as "File not found", not as "Unknown data format".
49
+ - Loading a settings file no longer shows a "Loaded" box: the log says "Config loaded from ...", with a GDS or stackup file that was not found at its saved path and was taken from the settings file's folder instead.
50
+ - Opening a `.simcfg` continues with the model script only when the file is linked to it, and asks only when the two have other settings (the question lists them). Create Model links: besides `<model>.simcfg` it writes the script's name (`"model_script"`) into the `.simcfg` the model was opened from, e.g. the KLayout plug-in's export, which keeps it on the next export. A script that only reads the same GDSII file is no longer taken for the model; the log names it. New options `--continue-with-script` and `--start-from-config` answer the question on the command line.
51
+ - `fieldViewer --screenshot` needs no display and no `QT_QPA_PLATFORM=offscreen`.
52
+ - `python -m setupEM.join_pieces` and `python -m setupEM.thermal_results` have `--help` and `--version`, write their errors to stderr, and a missing file is a message, not a traceback.
53
+ - The modules without a GUI (`join_pieces`, `thermal_results`, `script_model`, ...) can be imported without loading Qt.
54
+ - User guide: Model Fit starts snp2le with the result file loaded (the text said it has to be loaded by hand).
55
+
56
+ **Split regions, fix:**a side of the region made a port wall in setupEM after the export (e.g. with via ports of the layout on the region's edge) was a plain PEC wall in every piece and in the full check model: the wall shorted those ports, and the joined result and the full model were both wrong, in the same way. The pieces' port walls on the region's edge are now found from the ports on the edge of each piece's layout; the full model has all of the region's port walls. Where the region has a port wall but a piece none of its ports, that stretch stays PEC and now moves outward with the region's port wall extension (a length; written as `settings['wall_extension']`, needs gds2palace 0.10.1), so that all pieces and the full model have the same box.
57
+
58
+ # What's New - November 10, 2026 (setupEM 0.18.0)
59
+
60
+ **De-embedded results shown**: View S-Parameters lists the `_deembedded` files from the start and opens with the raw result and its `_deembedded` result together. Model Fit fits the calibrated result (`_dc_deembedded`, else `_deembedded`) of a model with port walls or a moved reference plane; the raw result still holds the uncalibrated gap ports.
61
+
62
+ **Port wall fixes:** a model script edited in place now gives back its port wall extension, reference plane shift and de-embedding length (they were written but not read, so the next session started with 0). Two port walls no longer make 0 the default oversize and air (the other sides became overrides and the default fields changed nothing); a default field that sets no side any more is greyed out. The status line under the log names the solve of a port wall run (calibration standard k/n, reused, or the model). The Port walls status says OK or the warnings only; the layout preview draws an extended feed and its length, a symbol per box side, and labels without the side names.
63
+
64
+ **Split regions**: a `.simcfg` from the KLayout plug-in's Export All of a split region (several EM region boxes) opens as a set of pieces. The Models list shows the pieces (and an unticked full check model). The settings (frequencies, mesh, solver, boundaries) are those of the whole region, shared by all pieces; a piece's box sides follow from the region's (a cut is a port wall, a stretch of a port wall without the piece's ports is PEC at the layout edge) and are locked; a piece can have its own mesh settings (Mesh tab, "Own mesh settings for p2"). Start Simulation runs the pieces without a gmsh window and does not mesh a piece again whose mesh is current; View S-Parameters shows the joined result first, and Model Fit fits it. The port wall extension and reference plane shift are the region's, on its outer sides only (none on a cut). An export written on another machine opens with its model folders, layouts and stackup found here. Start Simulation creates and runs the ticked pieces one after another and joins their results at the cuts (`join_pieces.py`, also `python -m setupEM.join_pieces <name>.simcfg`) into `<name>_deembedded.sNp` of the whole region. A piece whose layout fingerprint, settings and gds2palace version are unchanged since its last run is reused (`piece.key` in its model folder); **Run unchanged pieces too** overrides. Create Model keeps a settings file's own keys of the layout tool (piece name, fingerprint) when it rewrites the file.
65
+
66
+ The calibration standards of a port wall are no longer listed as models of their own in **Models** on the Create Model tab (they share the model's `_data` folder and its `run_sim` solves them before the model); Start Simulation ran `run_sim` once per listed row, and **Preview** stopped after the first standard with the model itself unbuilt. For a script that creates several models, the question about results of a previous simulation is now asked once before the first model starts, not between two models.
67
+
68
+ **Port walls**: calibrated ports at the layout edge (needs gds2palace 0.10.0). **Mesh and Boundaries > Advanced...** offers **Port wall** for xmin, xmax, ymin and ymax: PEC at the layout edge, oversize and air 0 and locked, written as `'PORTWALL'` in `settings['boundary']`. The Ports tab gets a **De-embedding** column (calibrated at a port wall, or the estimated port inductance), locks the direction of ports on a port wall, and a **Port walls** group with **Check port walls** (reads the layout, no meshing): per port wall its ports, ground at the cut, D, the standards' lengths, the valid frequency range, warnings or the error, and the **Reference plane shift** (`settings['reference_plane_shift']`). A port on an edge that is not a port wall gets the question whether to make that side one. Create Model runs the check when a port wall is set and stops on an error. An **Extension (µm)** per port wall (`auto` or a length, `settings['port_wall_extension']`) moves the port wall outward. The Ports tab runs the check by itself when a port wall has no result yet; the panel splits with the port list by a divider; warnings show with an icon and the start of their text. The layout preview shows the reference plane, where the uniform feed ends, and an extension, and fits the view to the layout and its box. setupEM and setupThermal keep the window's size and position (and the Ports tab's divider) from one session to the next. A via port on a port wall is listed as "via port used as a gap port on <line metal>" (gds2palace converts it when writing the model). The layout preview draws the simulation box: one frame, not to scale, with a label per side (a click opens the box sides dialog), a port wall as a white line. `combine_extend_snp.py` in `src/scripts` is synced with gds2palace.
69
+
70
+ The dielectric oversize can be set per side (xmin, xmax, ymin, ymax): in setupEM with **Advanced...** next to **Boundary conditions**, in setupThermal with **Advanced...** next to the oversize. It is written to the model script as a list `settings['margin'] = [xmin, xmax, ymin, ymax]`, and read from there and from settings files. Needs gds2palace 0.10.0. A negative oversize is no longer accepted.
71
+
72
+ Bundled IHP stackups (from gds2palace 0.10.0): heat source target layers `HEAT_TRANSISTOR` and `HEAT_RESISTOR`, for thermal models. Nothing is drawn on them, so EM models are unchanged.
73
+
74
+ # What's New - November 5, 2026 (setupEM 0.17.0)
75
+
76
+ setupThermal works with the thermal export of the KLayout plug-in klayout_em_export (one heat source per transistor and resistor, with the schematic instance names from LVS in `<layout>_thermalmap.json`):
77
+ - **Load powers...** below the Thermal Sources + Boundaries list sets the powers from a file of your circuit simulation, by instance name. Needs gds2palace with `util_thermal_map`.
78
+ - The list names the device of each heat source (instance and pcell) and the region outline. Heat source layers above 299 count as present in the layout.
79
+ - The export's placeholder boundary (constant temperature on the region outline, no target layer) is listed as "region outline: choose the target layer"; Create Model refuses a boundary without a target layer.
80
+ - **Temperature per device**: after a run, the log lists the average and peak temperature of each heat source and their rise above the fixed temperature, and `<model>_temperatures.csv` next to the model script has the same per instance. Command line: `python -m setupEM.thermal_results <model>.tsimcfg`.
81
+
82
+ **Changes:**
83
+ - **Create Model also writes the settings file**, `<model>.simcfg` / `<model>.tsimcfg` next to the model script (as Save Config would), so that a layout tool's next export keeps your settings and the KLayout plug-in finds the layout's stackup, datatypes and thermal objects. It overwrites only a settings file of the same application. Opening a `.simcfg` that Create Model wrote with a script continues that script without asking.
84
+ - The Mesh tab's "Mesh refinement at metal edges" is now **"Mesh size at heat sources"**, which is what it sets in a thermal model (metal edges are not refined there).
85
+
86
+ **Fixes:**
87
+ - ElmerSolver no longer hangs at start on a Linux desktop where an X display does not accept connections ("Authorization required, but no authorization protocol specified"): setupThermal starts it with hwloc's OpenGL plug-in off (`HWLOC_COMPONENTS=-gl`, unless you set that variable).
88
+
89
+ Full history: [CHANGES.md](https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md)
90
+
91
+ ---
92
+
93
+ **Note:** the `setupEM` PyPI package itself requires:
94
+
95
+ - gds2palace>=0.10.1
96
+ - gds_prepare_for_EM>=1.6.0
97
+ - PySide6
98
+ - shiboken6
99
+ - scipy
100
+ - requests
101
+ - scikit-rf
102
+ - matplotlib
103
+ - numpy
104
+ - gdspy
105
+ - meshio
106
+ - pyvista
107
+ - pyvistaqt
108
+
109
+ (Other Python modules mentioned above are only needed to run standalone helper scripts in this repository, not to use the installed package.)
@@ -4,7 +4,12 @@
4
4
 
5
5
  ## What's New
6
6
 
7
- Reserved PEC/AIR stackup materials, Layout Preview, Results viewer, Model Fit, built-in 3D field viewer, GDSII Layout Simplification, XML Stackup Editor, setupThermal for Elmer thermal simulation.
7
+ - **Port walls**: calibrated ports at the layout edge, de-embedded results
8
+ - **Split regions** from the [KLayout plug-in](https://github.com/VolkerMuehlhaus/klayout_em_export): pieces simulated and joined
9
+ - **Edit \*.py model in place**, also with parameter sweeps
10
+ - **Conductor model** with skin layers, **boundary conditions per side**
11
+ - **setupThermal**: powers and temperatures per device
12
+ - Layout Preview, Results viewer, Model Fit, 3D field viewer, GDSII simplification
8
13
 
9
14
  See [CHANGES.md](doc/CHANGES.md) for details.
10
15
 
@@ -245,7 +250,7 @@ If snp2le isn't installed, setupEM offers to install it for you via pip:
245
250
 
246
251
  Choosing **Install** runs `pip install snp2le` in the Log panel and, once it succeeds, continues automatically - no need to click Model Fit a second time. Choosing **Cancel** logs the manual install command and the project link instead.
247
252
 
248
- Once snp2le is available, Model Fit locates the raw (not `_dc`, not `_deembedded`) Touchstone result file for the current run and launches the snp2le GUI in that file's directory. snp2le's GUI has no command-line option to preload a file, so the exact path is printed to the Log panel - load it via snp2le's own file picker:
253
+ Once snp2le is available, Model Fit locates the raw (not `_dc`, not `_deembedded`) Touchstone result file for the current run and starts the snp2le GUI with that file loaded, in that file's directory. The Log panel names the file:
249
254
 
250
255
  <img src="./doc/png/modelfit2.png" alt="snp2le starting" width="700">
251
256
 
@@ -0,0 +1,80 @@
1
+ # Python GUI for gds2palace
2
+
3
+ ![Intro](https://raw.githubusercontent.com/VolkerMuehlhaus/setupEM/main/doc/png/setupEM_banner.png)
4
+
5
+ ## Install
6
+
7
+ pip install setupEM
8
+
9
+ **Full documentation, installation guide, and usage walkthrough:**
10
+ https://github.com/VolkerMuehlhaus/setupEM
11
+
12
+ ## Recent changes
13
+
14
+ # What's New - November 11, 2026 (setupEM 0.18.1)
15
+
16
+ **Command line fixes** (from issue #52, use without a display):
17
+ - `--help`, `--version` and a wrong argument of `setupEM`, `setupThermal`, `stackupEditor`, `resultViewer` and `fieldViewer` no longer need a display: the arguments are read before Qt starts. All five have `--version` now.
18
+ - `setupEM -simcfg <file>` opens a settings file of an Elmer model in Elmer mode. It opened in Palace mode unless `--elmer` was given, also when started from the KLayout plug-in.
19
+ - A `-simcfg`, `-gdsfile` or `-xmlfile` that does not exist, or a settings file of the other application, ends `setupEM` / `setupThermal` with a message on stderr and exit code 2 instead of an empty window. In the GUI, a settings file that is gone is reported as "File not found", not as "Unknown data format".
20
+ - Loading a settings file no longer shows a "Loaded" box: the log says "Config loaded from ...", with a GDS or stackup file that was not found at its saved path and was taken from the settings file's folder instead.
21
+ - Opening a `.simcfg` continues with the model script only when the file is linked to it, and asks only when the two have other settings (the question lists them). Create Model links: besides `<model>.simcfg` it writes the script's name (`"model_script"`) into the `.simcfg` the model was opened from, e.g. the KLayout plug-in's export, which keeps it on the next export. A script that only reads the same GDSII file is no longer taken for the model; the log names it. New options `--continue-with-script` and `--start-from-config` answer the question on the command line.
22
+ - `fieldViewer --screenshot` needs no display and no `QT_QPA_PLATFORM=offscreen`.
23
+ - `python -m setupEM.join_pieces` and `python -m setupEM.thermal_results` have `--help` and `--version`, write their errors to stderr, and a missing file is a message, not a traceback.
24
+ - The modules without a GUI (`join_pieces`, `thermal_results`, `script_model`, ...) can be imported without loading Qt.
25
+ - User guide: Model Fit starts snp2le with the result file loaded (the text said it has to be loaded by hand).
26
+
27
+ **Split regions, fix:**a side of the region made a port wall in setupEM after the export (e.g. with via ports of the layout on the region's edge) was a plain PEC wall in every piece and in the full check model: the wall shorted those ports, and the joined result and the full model were both wrong, in the same way. The pieces' port walls on the region's edge are now found from the ports on the edge of each piece's layout; the full model has all of the region's port walls. Where the region has a port wall but a piece none of its ports, that stretch stays PEC and now moves outward with the region's port wall extension (a length; written as `settings['wall_extension']`, needs gds2palace 0.10.1), so that all pieces and the full model have the same box.
28
+
29
+ # What's New - November 10, 2026 (setupEM 0.18.0)
30
+
31
+ **De-embedded results shown**: View S-Parameters lists the `_deembedded` files from the start and opens with the raw result and its `_deembedded` result together. Model Fit fits the calibrated result (`_dc_deembedded`, else `_deembedded`) of a model with port walls or a moved reference plane; the raw result still holds the uncalibrated gap ports.
32
+
33
+ **Port wall fixes:** a model script edited in place now gives back its port wall extension, reference plane shift and de-embedding length (they were written but not read, so the next session started with 0). Two port walls no longer make 0 the default oversize and air (the other sides became overrides and the default fields changed nothing); a default field that sets no side any more is greyed out. The status line under the log names the solve of a port wall run (calibration standard k/n, reused, or the model). The Port walls status says OK or the warnings only; the layout preview draws an extended feed and its length, a symbol per box side, and labels without the side names.
34
+
35
+ **Split regions**: a `.simcfg` from the KLayout plug-in's Export All of a split region (several EM region boxes) opens as a set of pieces. The Models list shows the pieces (and an unticked full check model). The settings (frequencies, mesh, solver, boundaries) are those of the whole region, shared by all pieces; a piece's box sides follow from the region's (a cut is a port wall, a stretch of a port wall without the piece's ports is PEC at the layout edge) and are locked; a piece can have its own mesh settings (Mesh tab, "Own mesh settings for p2"). Start Simulation runs the pieces without a gmsh window and does not mesh a piece again whose mesh is current; View S-Parameters shows the joined result first, and Model Fit fits it. The port wall extension and reference plane shift are the region's, on its outer sides only (none on a cut). An export written on another machine opens with its model folders, layouts and stackup found here. Start Simulation creates and runs the ticked pieces one after another and joins their results at the cuts (`join_pieces.py`, also `python -m setupEM.join_pieces <name>.simcfg`) into `<name>_deembedded.sNp` of the whole region. A piece whose layout fingerprint, settings and gds2palace version are unchanged since its last run is reused (`piece.key` in its model folder); **Run unchanged pieces too** overrides. Create Model keeps a settings file's own keys of the layout tool (piece name, fingerprint) when it rewrites the file.
36
+
37
+ The calibration standards of a port wall are no longer listed as models of their own in **Models** on the Create Model tab (they share the model's `_data` folder and its `run_sim` solves them before the model); Start Simulation ran `run_sim` once per listed row, and **Preview** stopped after the first standard with the model itself unbuilt. For a script that creates several models, the question about results of a previous simulation is now asked once before the first model starts, not between two models.
38
+
39
+ **Port walls**: calibrated ports at the layout edge (needs gds2palace 0.10.0). **Mesh and Boundaries > Advanced...** offers **Port wall** for xmin, xmax, ymin and ymax: PEC at the layout edge, oversize and air 0 and locked, written as `'PORTWALL'` in `settings['boundary']`. The Ports tab gets a **De-embedding** column (calibrated at a port wall, or the estimated port inductance), locks the direction of ports on a port wall, and a **Port walls** group with **Check port walls** (reads the layout, no meshing): per port wall its ports, ground at the cut, D, the standards' lengths, the valid frequency range, warnings or the error, and the **Reference plane shift** (`settings['reference_plane_shift']`). A port on an edge that is not a port wall gets the question whether to make that side one. Create Model runs the check when a port wall is set and stops on an error. An **Extension (µm)** per port wall (`auto` or a length, `settings['port_wall_extension']`) moves the port wall outward. The Ports tab runs the check by itself when a port wall has no result yet; the panel splits with the port list by a divider; warnings show with an icon and the start of their text. The layout preview shows the reference plane, where the uniform feed ends, and an extension, and fits the view to the layout and its box. setupEM and setupThermal keep the window's size and position (and the Ports tab's divider) from one session to the next. A via port on a port wall is listed as "via port used as a gap port on <line metal>" (gds2palace converts it when writing the model). The layout preview draws the simulation box: one frame, not to scale, with a label per side (a click opens the box sides dialog), a port wall as a white line. `combine_extend_snp.py` in `src/scripts` is synced with gds2palace.
40
+
41
+ The dielectric oversize can be set per side (xmin, xmax, ymin, ymax): in setupEM with **Advanced...** next to **Boundary conditions**, in setupThermal with **Advanced...** next to the oversize. It is written to the model script as a list `settings['margin'] = [xmin, xmax, ymin, ymax]`, and read from there and from settings files. Needs gds2palace 0.10.0. A negative oversize is no longer accepted.
42
+
43
+ Bundled IHP stackups (from gds2palace 0.10.0): heat source target layers `HEAT_TRANSISTOR` and `HEAT_RESISTOR`, for thermal models. Nothing is drawn on them, so EM models are unchanged.
44
+
45
+ # What's New - November 5, 2026 (setupEM 0.17.0)
46
+
47
+ setupThermal works with the thermal export of the KLayout plug-in klayout_em_export (one heat source per transistor and resistor, with the schematic instance names from LVS in `<layout>_thermalmap.json`):
48
+ - **Load powers...** below the Thermal Sources + Boundaries list sets the powers from a file of your circuit simulation, by instance name. Needs gds2palace with `util_thermal_map`.
49
+ - The list names the device of each heat source (instance and pcell) and the region outline. Heat source layers above 299 count as present in the layout.
50
+ - The export's placeholder boundary (constant temperature on the region outline, no target layer) is listed as "region outline: choose the target layer"; Create Model refuses a boundary without a target layer.
51
+ - **Temperature per device**: after a run, the log lists the average and peak temperature of each heat source and their rise above the fixed temperature, and `<model>_temperatures.csv` next to the model script has the same per instance. Command line: `python -m setupEM.thermal_results <model>.tsimcfg`.
52
+
53
+ **Changes:**
54
+ - **Create Model also writes the settings file**, `<model>.simcfg` / `<model>.tsimcfg` next to the model script (as Save Config would), so that a layout tool's next export keeps your settings and the KLayout plug-in finds the layout's stackup, datatypes and thermal objects. It overwrites only a settings file of the same application. Opening a `.simcfg` that Create Model wrote with a script continues that script without asking.
55
+ - The Mesh tab's "Mesh refinement at metal edges" is now **"Mesh size at heat sources"**, which is what it sets in a thermal model (metal edges are not refined there).
56
+
57
+ **Fixes:**
58
+ - ElmerSolver no longer hangs at start on a Linux desktop where an X display does not accept connections ("Authorization required, but no authorization protocol specified"): setupThermal starts it with hwloc's OpenGL plug-in off (`HWLOC_COMPONENTS=-gl`, unless you set that variable).
59
+
60
+ Full history: [CHANGES.md](https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md)
61
+
62
+ ---
63
+
64
+ **Note:** the `setupEM` PyPI package itself requires:
65
+
66
+ - gds2palace>=0.10.1
67
+ - gds_prepare_for_EM>=1.6.0
68
+ - PySide6
69
+ - shiboken6
70
+ - scipy
71
+ - requests
72
+ - scikit-rf
73
+ - matplotlib
74
+ - numpy
75
+ - gdspy
76
+ - meshio
77
+ - pyvista
78
+ - pyvistaqt
79
+
80
+ (Other Python modules mentioned above are only needed to run standalone helper scripts in this repository, not to use the installed package.)
@@ -12,7 +12,7 @@ authors = [
12
12
  { name = "Volker Muehlhaus", email = "volker@muehlhaus.com" }
13
13
  ]
14
14
  dependencies = [
15
- "gds2palace>=0.9.4",
15
+ "gds2palace>=0.10.1",
16
16
  "gds_prepare_for_EM>=1.6.0",
17
17
  "PySide6",
18
18
  "shiboken6",
@@ -21,7 +21,14 @@ setupEM package
21
21
  A Python tool for EM setup using gds2palace.
22
22
  """
23
23
 
24
- from .setupEM import main
24
+
25
+
26
+ def main():
27
+ """Start the setupEM GUI. Imported here only when called, so that the modules without Qt (join_pieces,
28
+ thermal_results, script_model, ...) can be imported without loading it."""
29
+ from .setupEM import main as _main
30
+ return _main()
31
+
25
32
 
26
33
  __all__ = ["main"]
27
- __version__ = "0.17.0"
34
+ __version__ = "0.18.1"
@@ -0,0 +1,86 @@
1
+ ########################################################################
2
+ #
3
+ # Copyright 2025 Volker Muehlhaus and IHP PDK Authors
4
+ #
5
+ # Licensed under the GNU General Public License, Version 3.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.gnu.org/licenses/gpl-3.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ ########################################################################
18
+
19
+ """
20
+ Command line helpers shared by setupEM, setupThermal, stackupEditor, resultViewer and fieldViewer.
21
+
22
+ No Qt in here: the commands read their arguments with these before they create the QApplication, so that
23
+ --help, --version and a wrong argument need no display.
24
+ """
25
+
26
+ import json
27
+ import os
28
+ import re
29
+
30
+ # file suffix of a settings file -> the application it belongs to
31
+ CONFIG_APPS = {"simcfg": "setupEM", "tsimcfg": "setupThermal"}
32
+
33
+
34
+ def package_version():
35
+ """__version__ of the setupEM package, also when a module is run as a plain script."""
36
+ try:
37
+ from . import __version__
38
+ return __version__
39
+ except ImportError:
40
+ init = os.path.join(os.path.dirname(os.path.abspath(__file__)), "__init__.py")
41
+ with open(init, encoding="utf-8") as f:
42
+ m = re.search(r'^__version__\s*=\s*"([^"]+)"', f.read(), re.M)
43
+ return m.group(1) if m else "unknown"
44
+
45
+
46
+ def add_version_argument(parser):
47
+ parser.add_argument("--version", action="version", version=f"%(prog)s {package_version()}")
48
+
49
+
50
+ def config_file_error(path, app_name):
51
+ """Why the settings file or model script given at start cannot be opened by app_name; None if it can."""
52
+ if not os.path.isfile(path):
53
+ return f"file not found: {path}"
54
+ suffix = os.path.splitext(path)[1].lower().lstrip(".")
55
+ if suffix == "py":
56
+ return None
57
+ own_suffix = next(s for s, app in CONFIG_APPS.items() if app == app_name)
58
+ owner = CONFIG_APPS.get(suffix)
59
+ if owner is not None and owner != app_name:
60
+ return f"{path} is a {owner} settings file, open it with {owner}"
61
+ if suffix != own_suffix:
62
+ return f"{path} is not a {app_name} settings file (*.{own_suffix}) or a model script (*.py)"
63
+ try:
64
+ with open(path, "r") as f:
65
+ data = json.load(f)
66
+ except (OSError, ValueError) as e:
67
+ return f"{path} cannot be read: {e}"
68
+ application = data.get("application", "") if isinstance(data, dict) else ""
69
+ if application == app_name:
70
+ return None
71
+ if application in CONFIG_APPS.values():
72
+ return f"{path} is a {application} settings file, open it with {application}"
73
+ return f"{path} is not a {app_name} settings file (no \"application\": \"{app_name}\" in it)"
74
+
75
+
76
+ def start_file_errors(app_name, simcfg="", gdsfile="", xmlfile=""):
77
+ """The messages for the files given at start that cannot be opened ('' = not given)."""
78
+ errors = []
79
+ if simcfg:
80
+ error = config_file_error(simcfg, app_name)
81
+ if error:
82
+ errors.append(error)
83
+ for path in (gdsfile, xmlfile):
84
+ if path and not os.path.isfile(path):
85
+ errors.append(f"file not found: {path}")
86
+ return errors
@@ -30,9 +30,11 @@ No Qt in here, so the module can be tested on its own.
30
30
  import ast
31
31
  import glob
32
32
  import json
33
+ import math
33
34
  import os
34
35
 
35
- __all__ = ["LAYOUT_KEYS", "port_differences", "layout_differences", "newer_configs", "model_scripts"]
36
+ __all__ = ["LAYOUT_KEYS", "port_differences", "layout_differences", "newer_configs", "model_scripts",
37
+ "same_path", "linked_scripts", "model_settings_snapshot", "settings_differences"]
36
38
 
37
39
  # saved_values that belong to the layout export, besides the ports
38
40
  LAYOUT_KEYS = ("GdsFile", "SubstrateFile", "cellname", "purpose")
@@ -82,6 +84,11 @@ def port_differences(old_ports, new_ports):
82
84
  return out
83
85
 
84
86
 
87
+ def same_path(a, b, base_dir=""):
88
+ """True if the paths a and b name the same file; relative paths are taken from base_dir."""
89
+ return _same_path(a, b, base_dir)
90
+
91
+
85
92
  def _same_path(a, b, base_dir=""):
86
93
  if not a or not b:
87
94
  return a == b
@@ -177,3 +184,98 @@ def model_scripts(gds_path, folders):
177
184
  out.append(path)
178
185
  out.sort(key=os.path.getmtime, reverse=True)
179
186
  return out
187
+
188
+
189
+ # ---------- Which model script a settings file belongs to ----------
190
+ #
191
+ # A layout tool's export (e.g. <layout>.simcfg of the KLayout plug-in) and the model script made from it in setupEM
192
+ # are linked in the settings file:
193
+ # "written_with": "<model>.py" Create Model wrote this settings file together with the script (same folder)
194
+ # "model_script": "<path>.py" Create Model wrote the script for a model opened from this settings file under
195
+ # another name; the path is relative to the settings file's folder
196
+ # The layout tool keeps both keys when it writes the file again. A script that only reads the same GDS file is not
197
+ # linked: it can be any script (an older copy, a hand-written one).
198
+
199
+ # settings that are not part of the model's setup, or that the GUI takes from the preferences either way
200
+ SETTINGS_NOT_COMPARED = ("unit", "model_basename", "sim_path", "preview_only", "no_preview",
201
+ "solver_maxits", "solver_tol", "fdump_enabled")
202
+
203
+
204
+ def linked_scripts(config_path, data):
205
+ """[(script path, written_with)] of the existing model scripts the settings file names, written_with first."""
206
+ folder = os.path.dirname(os.path.abspath(config_path))
207
+ out = []
208
+ for key in ("written_with", "model_script"):
209
+ name = data.get(key) if isinstance(data, dict) else None
210
+ if not isinstance(name, str) or not name.lower().endswith(".py"):
211
+ continue
212
+ if key == "written_with" and os.path.basename(name) != name:
213
+ continue # written_with is a file name in the same folder
214
+ path = os.path.normpath(os.path.join(folder, name))
215
+ if os.path.isfile(path) and not any(_same_path(path, p) for p, _ in out):
216
+ out.append((path, key == "written_with"))
217
+ return out
218
+
219
+
220
+ def model_settings_snapshot(script_path, suffix=".simcfg", application="setupEM"):
221
+ """The settings Create Model wrote with the script (<model>.simcfg, "written_with" the script), if the script was
222
+ not changed after it; else None (then they say nothing about the script)."""
223
+ path = os.path.splitext(script_path)[0] + suffix
224
+ try:
225
+ if os.path.getmtime(path) < os.path.getmtime(script_path):
226
+ return None
227
+ with open(path, encoding="utf-8") as f:
228
+ data = json.load(f)
229
+ except (OSError, ValueError):
230
+ return None
231
+ if not isinstance(data, dict) or data.get("application") != application or \
232
+ data.get("written_with") != os.path.basename(script_path):
233
+ return None
234
+ return data
235
+
236
+
237
+ def _is_number(value):
238
+ return isinstance(value, (int, float)) and not isinstance(value, bool)
239
+
240
+
241
+ def _same_setting(a, b):
242
+ """Two values of a setting as saved in settings files: numbers to rounding, a list and a scalar alike if every
243
+ element is the scalar (the oversize, one value or one per side), lists and dicts element by element."""
244
+ if _is_number(a) and _is_number(b):
245
+ return math.isclose(a, b, rel_tol=1e-9, abs_tol=1e-15)
246
+ if isinstance(a, (list, tuple)) and isinstance(b, (list, tuple)):
247
+ return len(a) == len(b) and all(_same_setting(x, y) for x, y in zip(a, b))
248
+ if isinstance(a, (list, tuple)) and _is_number(b):
249
+ return len(a) > 0 and all(_same_setting(x, b) for x in a)
250
+ if _is_number(a) and isinstance(b, (list, tuple)):
251
+ return _same_setting(b, a)
252
+ if isinstance(a, dict) and isinstance(b, dict):
253
+ return a.keys() == b.keys() and all(_same_setting(a[k], b[k]) for k in a)
254
+ return a == b
255
+
256
+
257
+ def _show(value):
258
+ if isinstance(value, float) and value.is_integer():
259
+ return str(int(value)) if abs(value) < 1e15 else str(value)
260
+ return str(value)
261
+
262
+
263
+ def settings_differences(script_data, config_data):
264
+ """Readable differences between the settings of a model script (script_data: the settings file Create Model
265
+ wrote with it) and a settings file of the same layout (config_data), [] if none. Compared: the settings both
266
+ files have, except the layout settings and ports (they come from the settings file either way) and
267
+ SETTINGS_NOT_COMPARED; and the solver (Palace or Elmer)."""
268
+ script_values = script_data.get("saved_values") or {}
269
+ config_values = config_data.get("saved_values") or {}
270
+ out = []
271
+ if "elmer_mode" in config_data and \
272
+ bool(script_data.get("elmer_mode", False)) != bool(config_data.get("elmer_mode", False)):
273
+ solver = lambda data: "Elmer" if data.get("elmer_mode") else "Palace"
274
+ out.append(f"solver: {solver(script_data)} in the script, {solver(config_data)} in the config")
275
+ for key in sorted(config_values):
276
+ if key in LAYOUT_KEYS or key in SETTINGS_NOT_COMPARED or key not in script_values:
277
+ continue
278
+ if not _same_setting(script_values[key], config_values[key]):
279
+ out.append(f"{key}: {_show(script_values[key])} in the script, {_show(config_values[key])} in the config")
280
+ return out
281
+
@@ -30,6 +30,7 @@
30
30
  <Material Name="RSIL" Type="Resistor" Rs="7" Color="d0d0d0" />
31
31
  <Material Name="RPPD" Type="Resistor" Rs="260" Color="d0d0d0" />
32
32
  <Material Name="RHIGH" Type="Resistor" Rs="1360" Color="d0d0d0" />
33
+ <Material Name="PolyRes" Type="Conductor" ThermalConductivity="20" Color="c08040" />
33
34
  </Materials>
34
35
  <ELayers LengthUnit="um">
35
36
  <Dielectrics>
@@ -57,6 +58,10 @@
57
58
  <Layer Name="RSIL" Type="sheet" Reference="Activ" ReferenceEdge="Top" Material="RSIL" Layer="314" Zmin="0.0000" Zmax="0.0000" />
58
59
  <Layer Name="REF_FOR_TRANSISTOR" Type="sheet" Reference="SiO2" ReferenceEdge="Bottom" Material="PEC" Layer="300" Zmin="0.4" Zmax="0.4" />
59
60
  <Layer Name="Activ" Type="conductor" Reference="SiO2" ReferenceEdge="Bottom" Material="Activ" Layer="1" Zmin="0.0000" Zmax="0.4000" />
61
+ <!-- Heat source targets for thermal models: z range and material of a heat source. Nothing is drawn on
62
+ these GDS layers, so they add no geometry to EM models. -->
63
+ <Layer Name="HEAT_TRANSISTOR" Type="conductor" Reference="Activ" ReferenceEdge="Top" Material="Activ" Layer="320" Zmin="-0.0400" Zmax="0.0000" />
64
+ <Layer Name="HEAT_RESISTOR" Type="conductor" Reference="Activ" ReferenceEdge="Top" Material="PolyRes" Layer="321" Zmin="0.0000" Zmax="0.1600" />
60
65
  <Layer Name="SUBGND" Type="sheet" Reference="EPI" ReferenceEdge="Top" Material="PEC" Layer="250" Zmin="0.0000" Zmax="0" />
61
66
  <Layer Name="LBE" Type="dielectric" Reference="Substrate" ReferenceEdge="Bottom" Material="AIR" Layer="157" Zmin="0.0000" Zmax="=bulk_thickness + 3.7500" />
62
67
  <Layer Name="BACKSIDEGND" Type="sheet" Reference="Substrate" ReferenceEdge="Bottom" Material="PEC" Layer="251" Zmin="0" Zmax="0" />
@@ -37,6 +37,7 @@
37
37
  <Material Name="RSIL" Type="Resistor" Rs="7" Color="d0d0d0" />
38
38
  <Material Name="RPPD" Type="Resistor" Rs="260" Color="d0d0d0" />
39
39
  <Material Name="RHIGH" Type="Resistor" Rs="1360" Color="d0d0d0" />
40
+ <Material Name="PolyRes" Type="Conductor" ThermalConductivity="20" Color="c08040" />
40
41
  </Materials>
41
42
  <ELayers LengthUnit="um">
42
43
  <Dielectrics>
@@ -71,6 +72,10 @@
71
72
  <Layer Name="RSIL" Type="sheet" Reference="Activ" ReferenceEdge="Top" Material="RSIL" Layer="314" Zmin="0.0000" Zmax="0.0000" />
72
73
  <Layer Name="REF_FOR_TRANSISTOR" Type="sheet" Reference="SiO2" ReferenceEdge="Bottom" Material="PEC" Layer="300" Zmin="0.4" Zmax="0.4" />
73
74
  <Layer Name="Activ" Type="conductor" Reference="SiO2" ReferenceEdge="Bottom" Material="Activ" Layer="1" Zmin="0.0000" Zmax="0.4000" />
75
+ <!-- Heat source targets for thermal models: z range and material of a heat source. Nothing is drawn on
76
+ these GDS layers, so they add no geometry to EM models. -->
77
+ <Layer Name="HEAT_TRANSISTOR" Type="conductor" Reference="Activ" ReferenceEdge="Top" Material="Activ" Layer="320" Zmin="-0.0400" Zmax="0.0000" />
78
+ <Layer Name="HEAT_RESISTOR" Type="conductor" Reference="Activ" ReferenceEdge="Top" Material="PolyRes" Layer="321" Zmin="0.0000" Zmax="0.1600" />
74
79
  <Layer Name="SUBGND" Type="sheet" Reference="EPI" ReferenceEdge="Top" Material="PEC" Layer="250" Zmin="0.0000" Zmax="0" />
75
80
  <Layer Name="LBE" Type="dielectric" Reference="Substrate" ReferenceEdge="Bottom" Material="AIR" Layer="157" Zmin="0.0000" Zmax="=bulk_thickness + 3.7500" />
76
81
  <Layer Name="BACKSIDEGND" Type="sheet" Reference="Substrate" ReferenceEdge="Bottom" Material="PEC" Layer="251" Zmin="0" Zmax="0.0000" />
@@ -36,6 +36,7 @@
36
36
  <Material Name="RSIL" Type="Resistor" Rs="7" Color="d0d0d0" />
37
37
  <Material Name="RPPD" Type="Resistor" Rs="260" Color="d0d0d0" />
38
38
  <Material Name="RHIGH" Type="Resistor" Rs="1360" Color="d0d0d0" />
39
+ <Material Name="PolyRes" Type="Conductor" ThermalConductivity="20" Color="c08040" />
39
40
  </Materials>
40
41
  <ELayers LengthUnit="um">
41
42
  <Dielectrics>
@@ -71,6 +72,10 @@
71
72
  <Layer Name="RSIL" Type="sheet" Reference="Activ" ReferenceEdge="Top" Material="RSIL" Layer="314" Zmin="0" Zmax="0" />
72
73
  <Layer Name="REF_FOR_TRANSISTOR" Type="sheet" Reference="SiO2" ReferenceEdge="Bottom" Material="PEC" Layer="300" Zmin="0.4" Zmax="0.4" />
73
74
  <Layer Name="Activ" Type="conductor" Reference="SiO2" ReferenceEdge="Bottom" Material="Activ" Layer="1" Zmin="0" Zmax="0.4" />
75
+ <!-- Heat source targets for thermal models: z range and material of a heat source. Nothing is drawn on
76
+ these GDS layers, so they add no geometry to EM models. -->
77
+ <Layer Name="HEAT_TRANSISTOR" Type="conductor" Reference="Activ" ReferenceEdge="Top" Material="Activ" Layer="320" Zmin="-0.04" Zmax="0" />
78
+ <Layer Name="HEAT_RESISTOR" Type="conductor" Reference="Activ" ReferenceEdge="Top" Material="PolyRes" Layer="321" Zmin="0" Zmax="0.16" />
74
79
  <Layer Name="SUBGND" Type="sheet" Reference="EPI" ReferenceEdge="Top" Material="PEC" Layer="250" Zmin="0" Zmax="0" />
75
80
  <Layer Name="LBE" Type="dielectric" Reference="Substrate" ReferenceEdge="Bottom" Material="AIR" Layer="157" Zmin="0" Zmax="=bulk_thickness + 3.7500" />
76
81
  <Layer Name="BACKSIDEGND" Type="sheet" Reference="Substrate" ReferenceEdge="Bottom" Material="PEC" Layer="251" Zmin="0" Zmax="0" />
@@ -96,9 +96,11 @@ from pyvistaqt import QtInteractor
96
96
  if __package__ in (None, ""):
97
97
  from palace_results import find_paraview_files, is_amr_iteration_path
98
98
  from thermal_results import find_thermal_paraview_file
99
+ from cli_common import add_version_argument
99
100
  else:
100
101
  from .palace_results import find_paraview_files, is_amr_iteration_path
101
102
  from .thermal_results import find_thermal_paraview_file
103
+ from .cli_common import add_version_argument
102
104
 
103
105
 
104
106
  # Axis name -> unit normal vector, for both the clip plane and the slider's bounds lookup.
@@ -2635,24 +2637,8 @@ class _StandaloneMainWindow:
2635
2637
 
2636
2638
 
2637
2639
  def main():
2638
- app = QApplication(sys.argv)
2639
-
2640
- # Pin a light color scheme so the explicit light backgrounds set on
2641
- # QLineEdit/QComboBox fields elsewhere aren't fighting an inherited dark
2642
- # auto-palette on accounts where Windows' per-user dark-mode setting is
2643
- # on (PySide6 6.5+ only; older versions just skip this and rely on the
2644
- # explicit "color:" rules already set on those field stylesheets).
2645
- try:
2646
- app.styleHints().setColorScheme(Qt.ColorScheme.Light)
2647
- except AttributeError:
2648
- pass
2649
-
2650
- if sys.platform.startswith("win"):
2651
- # matches setupEM.py's/setupThermal.py's/result_viewer.py's main() - without
2652
- # this, Qt's default style on Windows looks visibly different from the full app
2653
- app.setStyle(QStyleFactory.create("Windows"))
2654
-
2655
- parser = argparse.ArgumentParser(description="Standalone 3D field result viewer")
2640
+ # arguments first: --help, --version and a wrong argument need no display
2641
+ parser = argparse.ArgumentParser(prog="fieldViewer", description="Standalone 3D field result viewer")
2656
2642
  parser.add_argument("file_path", nargs="?",
2657
2643
  help="path to a .pvd/.pvtu/.vtu field-result file. If omitted, "
2658
2644
  "use --run-path with --source to resolve one automatically.")
@@ -2718,6 +2704,7 @@ def main():
2718
2704
  parser.add_argument("--screenshot",
2719
2705
  help="render off-screen and save a PNG here instead of opening an "
2720
2706
  "interactive window, then exit - works with no display")
2707
+ add_version_argument(parser)
2721
2708
  args = parser.parse_args()
2722
2709
 
2723
2710
  if (args.clip_position is not None or args.clip_max) and not args.clip_axis:
@@ -2758,12 +2745,44 @@ def main():
2758
2745
  if not file_paths:
2759
2746
  parser.error("no file_path given, and none could be resolved from --run-path")
2760
2747
 
2761
- def die(message):
2762
- print(f"Error: {message}", file=sys.stderr)
2763
- sys.exit(1)
2748
+ if args.screenshot:
2749
+ # rendered off-screen (see FieldViewerWindow's off_screen): no display needed, so don't let Qt look for one
2750
+ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
2751
+
2752
+ app = QApplication(sys.argv)
2753
+
2754
+ # Pin a light color scheme so the explicit light backgrounds set on
2755
+ # QLineEdit/QComboBox fields elsewhere aren't fighting an inherited dark
2756
+ # auto-palette on accounts where Windows' per-user dark-mode setting is
2757
+ # on (PySide6 6.5+ only; older versions just skip this and rely on the
2758
+ # explicit "color:" rules already set on those field stylesheets).
2759
+ try:
2760
+ app.styleHints().setColorScheme(Qt.ColorScheme.Light)
2761
+ except AttributeError:
2762
+ pass
2763
+
2764
+ if sys.platform.startswith("win"):
2765
+ # matches setupEM.py's/setupThermal.py's/result_viewer.py's main() - without
2766
+ # this, Qt's default style on Windows looks visibly different from the full app
2767
+ app.setStyle(QStyleFactory.create("Windows"))
2764
2768
 
2765
2769
  window = FieldViewerWindow(_StandaloneMainWindow(), file_paths, args.source,
2766
2770
  off_screen=bool(args.screenshot))
2771
+
2772
+ def close_and_exit(code):
2773
+ # The window is deleted here, before the application: left to Qt's own cleanup at exit, a finished
2774
+ # --screenshot run crashed there with no display (Linux, PySide6 6.12: PNG written, then exit code 139).
2775
+ nonlocal window
2776
+ window.close()
2777
+ window.deleteLater()
2778
+ window = None
2779
+ app.processEvents()
2780
+ sys.exit(code)
2781
+
2782
+ def die(message):
2783
+ print(f"Error: {message}", file=sys.stderr)
2784
+ close_and_exit(1)
2785
+
2767
2786
  if window._full_mesh is None:
2768
2787
  die(window._load_error or "failed to load the field-result file")
2769
2788
 
@@ -2873,8 +2892,7 @@ def main():
2873
2892
  break
2874
2893
  window.plotter.screenshot(args.screenshot)
2875
2894
  print(f"Saved screenshot to {args.screenshot}")
2876
- window.close()
2877
- sys.exit(0)
2895
+ close_and_exit(0)
2878
2896
 
2879
2897
  window.show()
2880
2898
  sys.exit(app.exec())