setupEM 0.18.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 (56) hide show
  1. {setupem-0.18.0/src/setupEM.egg-info → setupem-0.18.1}/PKG-INFO +18 -21
  2. {setupem-0.18.0 → setupem-0.18.1}/README.md +7 -2
  3. {setupem-0.18.0 → setupem-0.18.1}/README_pypi.md +16 -19
  4. {setupem-0.18.0 → setupem-0.18.1}/pyproject.toml +1 -1
  5. {setupem-0.18.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.18.0 → setupem-0.18.1}/src/setupEM/config_update.py +103 -1
  8. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/field_viewer.py +41 -23
  9. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/join_pieces.py +17 -6
  10. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/piece_set.py +97 -8
  11. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/result_viewer.py +10 -6
  12. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/setupEM.py +61 -35
  13. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/setupThermal.py +39 -25
  14. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/setup_common.py +132 -36
  15. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/stackupEditor.py +8 -4
  16. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/thermal_results.py +15 -8
  17. {setupem-0.18.0 → setupem-0.18.1/src/setupEM.egg-info}/PKG-INFO +18 -21
  18. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM.egg-info/SOURCES.txt +2 -0
  19. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM.egg-info/requires.txt +1 -1
  20. setupem-0.18.1/tests/test_cli_startup.py +289 -0
  21. {setupem-0.18.0 → setupem-0.18.1}/tests/test_config_update.py +66 -0
  22. setupem-0.18.1/tests/test_config_update_gui.py +334 -0
  23. {setupem-0.18.0 → setupem-0.18.1}/tests/test_piece_set.py +70 -7
  24. {setupem-0.18.0 → setupem-0.18.1}/tests/test_thermal_results.py +7 -1
  25. setupem-0.18.0/tests/test_config_update_gui.py +0 -185
  26. {setupem-0.18.0 → setupem-0.18.1}/LICENSE +0 -0
  27. {setupem-0.18.0 → setupem-0.18.1}/setup.cfg +0 -0
  28. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/__main__.py +0 -0
  29. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/data/SG13CMOS5L_200um.xml +0 -0
  30. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_100um.xml +0 -0
  31. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_200um.xml +0 -0
  32. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_FEM_200um.xml +0 -0
  33. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_FEM_200um_passi3D.xml +0 -0
  34. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/data/SG13G2_nosub.xml +0 -0
  35. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/gds_hierarchy_scan.py +0 -0
  36. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/layout_preview.py +0 -0
  37. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/momentum_import.py +0 -0
  38. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/palace_results.py +0 -0
  39. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/run_with_overrides.py +0 -0
  40. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/script_model.py +0 -0
  41. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/script_probe.py +0 -0
  42. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/simplify_gds.py +0 -0
  43. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM/stackup_writer.py +0 -0
  44. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM.egg-info/dependency_links.txt +0 -0
  45. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM.egg-info/entry_points.txt +0 -0
  46. {setupem-0.18.0 → setupem-0.18.1}/src/setupEM.egg-info/top_level.txt +0 -0
  47. {setupem-0.18.0 → setupem-0.18.1}/tests/test_deembedded_view.py +0 -0
  48. {setupem-0.18.0 → setupem-0.18.1}/tests/test_join_pieces.py +0 -0
  49. {setupem-0.18.0 → setupem-0.18.1}/tests/test_margin_per_side.py +0 -0
  50. {setupem-0.18.0 → setupem-0.18.1}/tests/test_port_walls.py +0 -0
  51. {setupem-0.18.0 → setupem-0.18.1}/tests/test_qt_platform_noise.py +0 -0
  52. {setupem-0.18.0 → setupem-0.18.1}/tests/test_run_with_overrides.py +0 -0
  53. {setupem-0.18.0 → setupem-0.18.1}/tests/test_script_model.py +0 -0
  54. {setupem-0.18.0 → setupem-0.18.1}/tests/test_script_probe.py +0 -0
  55. {setupem-0.18.0 → setupem-0.18.1}/tests/test_table_rows.py +0 -0
  56. {setupem-0.18.0 → setupem-0.18.1}/tests/test_thermal_powers.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: setupEM
3
- Version: 0.18.0
3
+ Version: 0.18.1
4
4
  Summary: Python tool for configuration of gds2palace workflow with GUI.
5
5
  Author-email: Volker Muehlhaus <volker@muehlhaus.com>
6
6
  License-Expression: GPL-3.0-or-later
@@ -10,7 +10,7 @@ Project-URL: Changelog, https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc
10
10
  Requires-Python: >=3.9
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE
13
- Requires-Dist: gds2palace>=0.10.0
13
+ Requires-Dist: gds2palace>=0.10.1
14
14
  Requires-Dist: gds_prepare_for_EM>=1.6.0
15
15
  Requires-Dist: PySide6
16
16
  Requires-Dist: shiboken6
@@ -40,6 +40,21 @@ https://github.com/VolkerMuehlhaus/setupEM
40
40
 
41
41
  ## Recent changes
42
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
+
43
58
  # What's New - November 10, 2026 (setupEM 0.18.0)
44
59
 
45
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.
@@ -71,31 +86,13 @@ setupThermal works with the thermal export of the KLayout plug-in klayout_em_exp
71
86
  **Fixes:**
72
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).
73
88
 
74
- # What's New - October 31, 2026 (setupEM 0.16.0)
75
-
76
- **After a new export from the layout tool** (setupEM): a layout tool such as the KLayout plug-in klayout_em_export writes the GDSII file and a `.simcfg`, and writes both again when the layout changes. The settings you made in setupEM since are only in your model script, because Create Model writes the script, not the `.simcfg`. setupEM now takes from such a `.simcfg` only the ports, GDSII file, stackup, cell and purpose, and keeps everything else as in the script:
77
- - Opening a `.simcfg` when a model script for the same GDSII file exists next to it asks whether to **Continue with the script** (edit it in place, ports and layout settings from the `.simcfg`) or **Start from the config**.
78
- - Loading a `.simcfg` while editing a script in place lists the ports and layout settings that differ and asks whether to **Update the script from it** or **Open it as a new model**. Before, loading it ended editing in place and replaced all settings.
79
- - While editing a script in place, the bar below the menu points out a newer `.simcfg` of the same GDSII file with other ports or layout settings, with **Update from it**.
80
-
81
- **Load Config, Import from \*.py model and Edit \*.py model in place** start in the folder of the model you are working on (the config or script loaded last, else the GDSII file). Before, they started in the folder setupEM was launched from, e.g. KLayout's when the KLayout plug-in opened setupEM.
82
-
83
- setupEM 0.16.0 needs gds2palace 0.9.3 or later: a layout with several shapes on one port layer (e.g. a transistor terminal on several fingers, from the KLayout plug-in) makes one port with several elements there; older gds2palace versions used only the last shape.
84
-
85
- **Fixes:**
86
- - `scripts/combine_extend_snp.py` is the same as gds2palace's again. It had missed three fixes made there in September: the port impedance lookup for AMR iterations, the missing `.sNp` extension for a model name that contains a dot, and Touchstone output after an interrupted Palace run.
87
- - On Linux with GNOME (Wayland), the mouse cursor no longer keeps spinning for about 10 seconds after setupEM starts. setupEM briefly opened three invisible windows while building the Input Files tab, and GNOME waited for them to finish starting.
88
- - Via ports with direction `-Z` keep their from and to layers. Before, loading a `.simcfg` dropped them, and Create Model wrote such a port as an in-plane port.
89
- - An incomplete port (direction and layers that don't fit, e.g. from a `.simcfg` written by another tool) gives a warning in the Ports tab. Before, gds2palace exited and setupEM closed. A lowercase `z` counts as a via port too.
90
- - `combine_extend_snp` (Touchstone output after a Palace run) handles ports with several elements (several shapes on one port layer, gds2palace 0.9.3): one Z0 per port in the option line, and the elements' port inductances combined in parallel for de-embedding. Before, the last element overwrote the others.
91
-
92
89
  Full history: [CHANGES.md](https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md)
93
90
 
94
91
  ---
95
92
 
96
93
  **Note:** the `setupEM` PyPI package itself requires:
97
94
 
98
- - gds2palace>=0.10.0
95
+ - gds2palace>=0.10.1
99
96
  - gds_prepare_for_EM>=1.6.0
100
97
  - PySide6
101
98
  - shiboken6
@@ -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
 
@@ -11,6 +11,21 @@ https://github.com/VolkerMuehlhaus/setupEM
11
11
 
12
12
  ## Recent changes
13
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
+
14
29
  # What's New - November 10, 2026 (setupEM 0.18.0)
15
30
 
16
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.
@@ -42,31 +57,13 @@ setupThermal works with the thermal export of the KLayout plug-in klayout_em_exp
42
57
  **Fixes:**
43
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).
44
59
 
45
- # What's New - October 31, 2026 (setupEM 0.16.0)
46
-
47
- **After a new export from the layout tool** (setupEM): a layout tool such as the KLayout plug-in klayout_em_export writes the GDSII file and a `.simcfg`, and writes both again when the layout changes. The settings you made in setupEM since are only in your model script, because Create Model writes the script, not the `.simcfg`. setupEM now takes from such a `.simcfg` only the ports, GDSII file, stackup, cell and purpose, and keeps everything else as in the script:
48
- - Opening a `.simcfg` when a model script for the same GDSII file exists next to it asks whether to **Continue with the script** (edit it in place, ports and layout settings from the `.simcfg`) or **Start from the config**.
49
- - Loading a `.simcfg` while editing a script in place lists the ports and layout settings that differ and asks whether to **Update the script from it** or **Open it as a new model**. Before, loading it ended editing in place and replaced all settings.
50
- - While editing a script in place, the bar below the menu points out a newer `.simcfg` of the same GDSII file with other ports or layout settings, with **Update from it**.
51
-
52
- **Load Config, Import from \*.py model and Edit \*.py model in place** start in the folder of the model you are working on (the config or script loaded last, else the GDSII file). Before, they started in the folder setupEM was launched from, e.g. KLayout's when the KLayout plug-in opened setupEM.
53
-
54
- setupEM 0.16.0 needs gds2palace 0.9.3 or later: a layout with several shapes on one port layer (e.g. a transistor terminal on several fingers, from the KLayout plug-in) makes one port with several elements there; older gds2palace versions used only the last shape.
55
-
56
- **Fixes:**
57
- - `scripts/combine_extend_snp.py` is the same as gds2palace's again. It had missed three fixes made there in September: the port impedance lookup for AMR iterations, the missing `.sNp` extension for a model name that contains a dot, and Touchstone output after an interrupted Palace run.
58
- - On Linux with GNOME (Wayland), the mouse cursor no longer keeps spinning for about 10 seconds after setupEM starts. setupEM briefly opened three invisible windows while building the Input Files tab, and GNOME waited for them to finish starting.
59
- - Via ports with direction `-Z` keep their from and to layers. Before, loading a `.simcfg` dropped them, and Create Model wrote such a port as an in-plane port.
60
- - An incomplete port (direction and layers that don't fit, e.g. from a `.simcfg` written by another tool) gives a warning in the Ports tab. Before, gds2palace exited and setupEM closed. A lowercase `z` counts as a via port too.
61
- - `combine_extend_snp` (Touchstone output after a Palace run) handles ports with several elements (several shapes on one port layer, gds2palace 0.9.3): one Z0 per port in the option line, and the elements' port inductances combined in parallel for de-embedding. Before, the last element overwrote the others.
62
-
63
60
  Full history: [CHANGES.md](https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md)
64
61
 
65
62
  ---
66
63
 
67
64
  **Note:** the `setupEM` PyPI package itself requires:
68
65
 
69
- - gds2palace>=0.10.0
66
+ - gds2palace>=0.10.1
70
67
  - gds_prepare_for_EM>=1.6.0
71
68
  - PySide6
72
69
  - shiboken6
@@ -12,7 +12,7 @@ authors = [
12
12
  { name = "Volker Muehlhaus", email = "volker@muehlhaus.com" }
13
13
  ]
14
14
  dependencies = [
15
- "gds2palace>=0.10.0",
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.18.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
+
@@ -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())
@@ -180,15 +180,26 @@ def join_all(set_path):
180
180
 
181
181
 
182
182
  def main(argv=None):
183
- argv = sys.argv[1:] if argv is None else argv
184
- if len(argv) != 1:
185
- print(__doc__)
186
- return 2
183
+ """python -m setupEM.join_pieces <export>.simcfg: 0 joined, 1 not joined (the reason on stderr), 2 wrong
184
+ arguments."""
185
+ import argparse
186
+ if __package__ in (None, ""):
187
+ from cli_common import add_version_argument
188
+ else:
189
+ from .cli_common import add_version_argument
190
+ parser = argparse.ArgumentParser(prog="python -m setupEM.join_pieces", description=__doc__,
191
+ formatter_class=argparse.RawDescriptionHelpFormatter)
192
+ parser.add_argument("simcfg", help="<export>.simcfg of a split region (with a pieces section)")
193
+ add_version_argument(parser)
194
+ args = parser.parse_args(argv)
187
195
  try:
188
- for message in join_all(argv[0]):
196
+ for message in join_all(args.simcfg):
189
197
  print(message)
190
198
  except JoinError as e:
191
- print(f"not joined: {e}")
199
+ print(f"not joined: {e}", file=sys.stderr)
200
+ return 1
201
+ except (OSError, json.JSONDecodeError) as e:
202
+ print(f"not joined: {args.simcfg} cannot be read: {e}", file=sys.stderr)
192
203
  return 1
193
204
  return 0
194
205