setupEM 0.18.3__tar.gz → 0.19.0__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 (64) hide show
  1. setupem-0.19.0/PKG-INFO +91 -0
  2. {setupem-0.18.3 → setupem-0.19.0}/README.md +5 -1
  3. setupem-0.19.0/README_pypi.md +62 -0
  4. {setupem-0.18.3 → setupem-0.19.0}/pyproject.toml +3 -3
  5. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/__init__.py +1 -1
  6. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/gds_hierarchy_scan.py +13 -15
  7. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/piece_set.py +6 -4
  8. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/setupEM.py +0 -1
  9. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/setupThermal.py +0 -1
  10. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/setup_common.py +149 -29
  11. setupem-0.19.0/src/setupEM.egg-info/PKG-INFO +91 -0
  12. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM.egg-info/SOURCES.txt +2 -0
  13. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM.egg-info/requires.txt +3 -3
  14. setupem-0.19.0/tests/test_cellname_default.py +48 -0
  15. {setupem-0.18.3 → setupem-0.19.0}/tests/test_cli_startup.py +1 -0
  16. {setupem-0.18.3 → setupem-0.19.0}/tests/test_config_update_gui.py +3 -0
  17. {setupem-0.18.3 → setupem-0.19.0}/tests/test_deembedded_view.py +2 -0
  18. {setupem-0.18.3 → setupem-0.19.0}/tests/test_export_no_gui.py +1 -0
  19. {setupem-0.18.3 → setupem-0.19.0}/tests/test_margin_per_side.py +1 -0
  20. {setupem-0.18.3 → setupem-0.19.0}/tests/test_piece_set.py +12 -7
  21. {setupem-0.18.3 → setupem-0.19.0}/tests/test_port_walls.py +26 -25
  22. {setupem-0.18.3 → setupem-0.19.0}/tests/test_return_applies.py +1 -0
  23. setupem-0.19.0/tests/test_save_current_file.py +119 -0
  24. {setupem-0.18.3 → setupem-0.19.0}/tests/test_script_writer.py +1 -0
  25. {setupem-0.18.3 → setupem-0.19.0}/tests/test_table_rows.py +1 -0
  26. {setupem-0.18.3 → setupem-0.19.0}/tests/test_thermal_powers.py +11 -5
  27. {setupem-0.18.3 → setupem-0.19.0}/tests/test_thermal_results.py +1 -0
  28. setupem-0.18.3/PKG-INFO +0 -104
  29. setupem-0.18.3/README_pypi.md +0 -75
  30. setupem-0.18.3/src/setupEM.egg-info/PKG-INFO +0 -104
  31. {setupem-0.18.3 → setupem-0.19.0}/LICENSE +0 -0
  32. {setupem-0.18.3 → setupem-0.19.0}/setup.cfg +0 -0
  33. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/__main__.py +0 -0
  34. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/cli_common.py +0 -0
  35. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/config_update.py +0 -0
  36. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/data/SG13CMOS5L_200um.xml +0 -0
  37. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/data/SG13G2_100um.xml +0 -0
  38. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/data/SG13G2_200um.xml +0 -0
  39. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/data/SG13G2_FEM_200um.xml +0 -0
  40. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/data/SG13G2_FEM_200um_passi3D.xml +0 -0
  41. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/data/SG13G2_nosub.xml +0 -0
  42. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/field_viewer.py +0 -0
  43. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/join_pieces.py +0 -0
  44. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/layout_preview.py +0 -0
  45. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/momentum_import.py +0 -0
  46. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/palace_results.py +0 -0
  47. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/result_viewer.py +0 -0
  48. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/run_with_overrides.py +0 -0
  49. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/script_model.py +0 -0
  50. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/script_probe.py +0 -0
  51. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/script_writer.py +0 -0
  52. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/simplify_gds.py +0 -0
  53. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/stackupEditor.py +0 -0
  54. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/stackup_writer.py +0 -0
  55. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM/thermal_results.py +0 -0
  56. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM.egg-info/dependency_links.txt +0 -0
  57. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM.egg-info/entry_points.txt +0 -0
  58. {setupem-0.18.3 → setupem-0.19.0}/src/setupEM.egg-info/top_level.txt +0 -0
  59. {setupem-0.18.3 → setupem-0.19.0}/tests/test_config_update.py +0 -0
  60. {setupem-0.18.3 → setupem-0.19.0}/tests/test_join_pieces.py +0 -0
  61. {setupem-0.18.3 → setupem-0.19.0}/tests/test_qt_platform_noise.py +0 -0
  62. {setupem-0.18.3 → setupem-0.19.0}/tests/test_run_with_overrides.py +0 -0
  63. {setupem-0.18.3 → setupem-0.19.0}/tests/test_script_model.py +0 -0
  64. {setupem-0.18.3 → setupem-0.19.0}/tests/test_script_probe.py +0 -0
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.4
2
+ Name: setupEM
3
+ Version: 0.19.0
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.11.0
14
+ Requires-Dist: gds_prepare_for_EM>=1.8.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: gdstk
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 19, 2026 (setupEM 0.19.0)
44
+
45
+ Needs gds2palace 0.11 and gds_prepare_for_EM 1.8 or newer (`pip install` updates them). setupEM, gds2palace and gds_prepare_for_EM read layouts with gdstk now instead of gdspy, which is no longer maintained (its polygon fracturing could hang); gdspy is no longer installed with setupEM.
46
+
47
+ **The cell read when the Cellname box says "(default)".** gds2palace 0.11 reads the design cell then: the top-level cell with the largest bounding box, never KLayout's `$$$CONTEXT_INFO$$$`. Before, it read the first top-level cell, which depends on the order in the file (for some KLayout files `$$$CONTEXT_INFO$$$`). The box now names that cell, e.g. "(default: T582_BEOL_D1_300u)", so you see which cell the model and the layout preview use; it is still saved as an empty cell name. Tools > Simplify GDS takes the same cell (gds_prepare_for_EM 1.8).
48
+
49
+ **Tools > Simplify GDS** gets gds_prepare_for_EM 1.8: merged vias are complete (before, rings of vias came out cut open and large via fields lost strips along their fracture lines), circuit blocks whose wiring is drawn as paths are no longer deleted as seal rings, and large layouts are much faster.
50
+
51
+ # What's New - November 16, 2026 (setupEM 0.18.4)
52
+
53
+ **File > Save (Ctrl+S) saves the settings file you opened.** Opened from a `.simcfg` (e.g. the KLayout plug-in's export, with Open in setupEM), Ctrl+S did nothing: the action existed only for a script edited in place, and changes such as a port wall extension were lost without a question when setupEM was closed. Now:
54
+ - Ctrl+S saves into the `.simcfg` / `.tsimcfg` the model was opened from (the menu names it). Its other entries, e.g. the plug-in's link to the model script, are kept. A script edited in place and a piece of a split region are saved as before; a new model asks for a file name.
55
+ - Closing setupEM, opening another file or File > New asks "Save the changes to ...?" when the settings changed since the file was opened or saved.
56
+
57
+ # What's New - November 15, 2026 (setupEM 0.18.3)
58
+
59
+ Needs gds2palace 0.10.7 or newer (`pip install` updates it).
60
+
61
+ **`combine_extend_snp.py` 1.5** (`combine_snp`, in `scripts/`), the same file as in gds2palace 0.10.7:
62
+ - The `_dc` Touchstone file keeps all simulated frequency points and adds only the 0 Hz point in front. Before, a result with the two low frequency points of a sweep from 0 Hz was resampled to a uniform frequency grid, so the simulated points, among them the two low ones, were replaced by interpolated values. The 0 Hz value itself is unchanged.
63
+ - Port walls (from gds2palace 0.10.6): the line resistance of the standards is taken from the model's lowest frequency, so R and Q of models with port walls are right also below fstop/20.
64
+
65
+ **Sweep from 0 Hz, the frequencies that replace DC** (a gds2palace 0.10.7 change, nothing to set in setupEM): with start frequency 0, gds2palace simulates two low frequency points instead of 0 Hz. These were always 10 MHz and 20 MHz. With a mesh finer than 0.5 µm (refined cellsize or a per-layer override), gds2palace 0.10.7 moves them up, to 5 MHz·µm divided by the smallest cell size and twice that (e.g. 25 and 50 MHz at 0.2 µm), because on such a fine mesh Palace could stop with "SuperLUSolver: Found a singular matrix" at 10 MHz. Models with cell sizes of 0.5 µm and more keep 10 and 20 MHz. The user's guide section on DC handling says this now.
66
+
67
+ **Citation:** `CITATION.cff` and a "How to cite" section in the README; GitHub's **Cite this repository** button gives APA and BibTeX entries.
68
+
69
+ **Internal:** the model script writer of setupEM and setupThermal is now a module without Qt (`script_writer.py`, issue #52). The written scripts are unchanged; `tests/test_script_writer.py` checks 8 recorded scripts against both the GUI and the writer.
70
+
71
+ Full history: [CHANGES.md](https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md)
72
+
73
+ ---
74
+
75
+ **Note:** the `setupEM` PyPI package itself requires:
76
+
77
+ - gds2palace>=0.11.0
78
+ - gds_prepare_for_EM>=1.8.0
79
+ - PySide6
80
+ - shiboken6
81
+ - scipy
82
+ - requests
83
+ - scikit-rf
84
+ - matplotlib
85
+ - numpy
86
+ - gdstk
87
+ - meshio
88
+ - pyvista
89
+ - pyvistaqt
90
+
91
+ (Other Python modules mentioned above are only needed to run standalone helper scripts in this repository, not to use the installed package.)
@@ -95,7 +95,7 @@ The setupEM module also installs these dependencies:
95
95
  - scikit-rf
96
96
  - matplotlib
97
97
  - numpy
98
- - gdspy
98
+ - gdstk
99
99
  - meshio
100
100
  - pyvista
101
101
  - pyvistaqt
@@ -343,6 +343,10 @@ If you then start KLayout using this script, a new menu item is available: Tools
343
343
 
344
344
  If you use setupEM in a publication, please cite it. The **Cite this repository** button on the GitHub repository page gives APA and BibTeX entries, generated from [CITATION.cff](./CITATION.cff).
345
345
 
346
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23766714.svg)](https://doi.org/10.5281/zenodo.23766714)
347
+
348
+ Each release of setupEM is archived on Zenodo with its own DOI. The DOI above, 10.5281/zenodo.23766714, always resolves to the latest version; the record lists the DOIs of all versions, so you can cite the version you used.
349
+
346
350
  Please also cite [gds2palace](https://github.com/VolkerMuehlhaus/gds2palace_ihp_sg13g2), which builds the model, and the [Palace](https://github.com/awslabs/palace) solver that computed your results.
347
351
 
348
352
  # License
@@ -0,0 +1,62 @@
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 19, 2026 (setupEM 0.19.0)
15
+
16
+ Needs gds2palace 0.11 and gds_prepare_for_EM 1.8 or newer (`pip install` updates them). setupEM, gds2palace and gds_prepare_for_EM read layouts with gdstk now instead of gdspy, which is no longer maintained (its polygon fracturing could hang); gdspy is no longer installed with setupEM.
17
+
18
+ **The cell read when the Cellname box says "(default)".** gds2palace 0.11 reads the design cell then: the top-level cell with the largest bounding box, never KLayout's `$$$CONTEXT_INFO$$$`. Before, it read the first top-level cell, which depends on the order in the file (for some KLayout files `$$$CONTEXT_INFO$$$`). The box now names that cell, e.g. "(default: T582_BEOL_D1_300u)", so you see which cell the model and the layout preview use; it is still saved as an empty cell name. Tools > Simplify GDS takes the same cell (gds_prepare_for_EM 1.8).
19
+
20
+ **Tools > Simplify GDS** gets gds_prepare_for_EM 1.8: merged vias are complete (before, rings of vias came out cut open and large via fields lost strips along their fracture lines), circuit blocks whose wiring is drawn as paths are no longer deleted as seal rings, and large layouts are much faster.
21
+
22
+ # What's New - November 16, 2026 (setupEM 0.18.4)
23
+
24
+ **File > Save (Ctrl+S) saves the settings file you opened.** Opened from a `.simcfg` (e.g. the KLayout plug-in's export, with Open in setupEM), Ctrl+S did nothing: the action existed only for a script edited in place, and changes such as a port wall extension were lost without a question when setupEM was closed. Now:
25
+ - Ctrl+S saves into the `.simcfg` / `.tsimcfg` the model was opened from (the menu names it). Its other entries, e.g. the plug-in's link to the model script, are kept. A script edited in place and a piece of a split region are saved as before; a new model asks for a file name.
26
+ - Closing setupEM, opening another file or File > New asks "Save the changes to ...?" when the settings changed since the file was opened or saved.
27
+
28
+ # What's New - November 15, 2026 (setupEM 0.18.3)
29
+
30
+ Needs gds2palace 0.10.7 or newer (`pip install` updates it).
31
+
32
+ **`combine_extend_snp.py` 1.5** (`combine_snp`, in `scripts/`), the same file as in gds2palace 0.10.7:
33
+ - The `_dc` Touchstone file keeps all simulated frequency points and adds only the 0 Hz point in front. Before, a result with the two low frequency points of a sweep from 0 Hz was resampled to a uniform frequency grid, so the simulated points, among them the two low ones, were replaced by interpolated values. The 0 Hz value itself is unchanged.
34
+ - Port walls (from gds2palace 0.10.6): the line resistance of the standards is taken from the model's lowest frequency, so R and Q of models with port walls are right also below fstop/20.
35
+
36
+ **Sweep from 0 Hz, the frequencies that replace DC** (a gds2palace 0.10.7 change, nothing to set in setupEM): with start frequency 0, gds2palace simulates two low frequency points instead of 0 Hz. These were always 10 MHz and 20 MHz. With a mesh finer than 0.5 µm (refined cellsize or a per-layer override), gds2palace 0.10.7 moves them up, to 5 MHz·µm divided by the smallest cell size and twice that (e.g. 25 and 50 MHz at 0.2 µm), because on such a fine mesh Palace could stop with "SuperLUSolver: Found a singular matrix" at 10 MHz. Models with cell sizes of 0.5 µm and more keep 10 and 20 MHz. The user's guide section on DC handling says this now.
37
+
38
+ **Citation:** `CITATION.cff` and a "How to cite" section in the README; GitHub's **Cite this repository** button gives APA and BibTeX entries.
39
+
40
+ **Internal:** the model script writer of setupEM and setupThermal is now a module without Qt (`script_writer.py`, issue #52). The written scripts are unchanged; `tests/test_script_writer.py` checks 8 recorded scripts against both the GUI and the writer.
41
+
42
+ Full history: [CHANGES.md](https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md)
43
+
44
+ ---
45
+
46
+ **Note:** the `setupEM` PyPI package itself requires:
47
+
48
+ - gds2palace>=0.11.0
49
+ - gds_prepare_for_EM>=1.8.0
50
+ - PySide6
51
+ - shiboken6
52
+ - scipy
53
+ - requests
54
+ - scikit-rf
55
+ - matplotlib
56
+ - numpy
57
+ - gdstk
58
+ - meshio
59
+ - pyvista
60
+ - pyvistaqt
61
+
62
+ (Other Python modules mentioned above are only needed to run standalone helper scripts in this repository, not to use the installed package.)
@@ -12,8 +12,8 @@ authors = [
12
12
  { name = "Volker Muehlhaus", email = "volker@muehlhaus.com" }
13
13
  ]
14
14
  dependencies = [
15
- "gds2palace>=0.10.7",
16
- "gds_prepare_for_EM>=1.6.0",
15
+ "gds2palace>=0.11.0",
16
+ "gds_prepare_for_EM>=1.8.0",
17
17
  "PySide6",
18
18
  "shiboken6",
19
19
  "scipy",
@@ -21,7 +21,7 @@ dependencies = [
21
21
  "scikit-rf",
22
22
  "matplotlib",
23
23
  "numpy",
24
- "gdspy",
24
+ "gdstk",
25
25
  "meshio",
26
26
  "pyvista",
27
27
  "pyvistaqt"
@@ -31,4 +31,4 @@ def main():
31
31
 
32
32
 
33
33
  __all__ = ["main"]
34
- __version__ = "0.18.3"
34
+ __version__ = "0.19.0"
@@ -19,7 +19,7 @@
19
19
  """
20
20
  gds_hierarchy_scan.py
21
21
 
22
- Cheap, pure-gdspy GDS cell-hierarchy walkers that never call cell.flatten().
22
+ Cheap GDS cell-hierarchy walkers (gdstk objects) that never call cell.flatten().
23
23
  gds2palace's own gds_reader.read_gds() flattens the whole chosen cell (every
24
24
  array/reference expanded into real, individual polygon objects) before doing
25
25
  anything else - fine for actually building a model, but for a densely-arrayed
@@ -47,11 +47,14 @@ def layers_present_in_range(gds_path, cellname, layer_min, layer_max, purposelis
47
47
  polygon whose datatype is in purposelist (any datatype if purposelist is
48
48
  falsy), anywhere in the cell hierarchy - without flattening. Recursive,
49
49
  memoized-per-cell-name, set-union based: unlike estimate_polygon_count,
50
- presence needs no CellArray columns*rows multiplication (N copies of a
51
- present layer is still just "present"), so CellReference and CellArray
50
+ presence needs no array columns*rows multiplication (N copies of a
51
+ present layer is still just "present"), so plain and array references
52
52
  are treated identically here. Raises on open/resolve failure, same as
53
- open_gds_cell(); callers wrap in their own try/except.
53
+ open_gds_cell() (gds_prepare_for_EM >= 1.8: gdstk library and cell);
54
+ callers wrap in their own try/except.
54
55
  """
56
+ import gdstk
57
+
55
58
  library, cell = open_gds_cell(gds_path, cellname)
56
59
  wanted = set(range(layer_min, layer_max + 1))
57
60
  purposeset = set(int(p) for p in purposelist) if purposelist else None
@@ -62,20 +65,15 @@ def layers_present_in_range(gds_path, cellname, layer_min, layer_max, purposelis
62
65
  if c.name in memo:
63
66
  return memo[c.name]
64
67
  found = set()
65
- for polygonset in c.polygons:
66
- for layer, datatype in zip(polygonset.layers, polygonset.datatypes):
67
- layer = int(layer)
68
- if layer in wanted and (purposeset is None or int(datatype) in purposeset):
69
- found.add(layer)
68
+ for polygon in c.polygons:
69
+ if polygon.layer in wanted and (purposeset is None or polygon.datatype in purposeset):
70
+ found.add(polygon.layer)
70
71
  for ref in c.references:
71
72
  if found >= wanted:
72
73
  break # already covers every requested layer - nothing left to gain
73
- ref_cell = ref.ref_cell
74
- if isinstance(ref_cell, str):
75
- ref_cell = library.cells.get(ref_cell)
76
- if ref_cell is None:
77
- continue
78
- found |= scan(ref_cell)
74
+ if not isinstance(ref.cell, gdstk.Cell):
75
+ continue # cell missing from the file
76
+ found |= scan(ref.cell)
79
77
  memo[c.name] = found
80
78
  return found
81
79
 
@@ -103,10 +103,12 @@ def ports_on_edge(gds, cellname, port_layers):
103
103
  if stamp in _edge_cache:
104
104
  return _edge_cache[stamp]
105
105
  try:
106
- import gdspy
107
- lib = gdspy.GdsLibrary(infile=gds)
108
- cell = lib.cells.get(cellname) or (lib.top_level() or [None])[0]
109
- by_spec = cell.get_polygons(by_spec=True)
106
+ import gdstk
107
+ from gds2palace.util_gds_reader import select_design_cell
108
+ cell = select_design_cell(gdstk.read_gds(gds), cellname) # the cell read_gds() reads
109
+ by_spec = {}
110
+ for polygon in cell.get_polygons(include_paths=True):
111
+ by_spec.setdefault((polygon.layer, polygon.datatype), []).append(polygon.points)
110
112
  except Exception: # noqa: BLE001 - an unreadable layout: the caller falls back to the export's record
111
113
  return None
112
114
  points = [p for polys in by_spec.values() for p in polys if len(p)]
@@ -22,7 +22,6 @@ import numpy as np
22
22
  import importlib.metadata
23
23
  import importlib.util
24
24
  import requests
25
- import gdspy
26
25
  from scipy.interpolate import interp1d
27
26
  from PySide6.QtWidgets import (
28
27
  QApplication, QMainWindow, QWidget, QHBoxLayout, QVBoxLayout,
@@ -21,7 +21,6 @@ import sys, json, os, pathlib, ast, webbrowser, argparse, math
21
21
  import numpy as np
22
22
  import importlib.metadata
23
23
  import requests
24
- import gdspy
25
24
  from scipy.interpolate import interp1d
26
25
  from PySide6.QtWidgets import (
27
26
  QApplication, QMainWindow, QWidget, QHBoxLayout, QVBoxLayout,
@@ -37,7 +37,6 @@ import importlib.metadata
37
37
  import xml.etree.ElementTree as ET
38
38
  import numpy as np
39
39
  import requests
40
- import gdspy
41
40
  import shiboken6
42
41
  from scipy.interpolate import interp1d
43
42
  from PySide6.QtWidgets import (
@@ -302,7 +301,10 @@ def get_saved_value(saved_values, key, default):
302
301
  # (saved_values["cellname"], gds_reader.read_gds()'s cellname= argument, the
303
302
  # generated Python model's settings['cellname']), only the combo box display
304
303
  # uses this label. Translate at the two boundaries with cellname_for_display()/
305
- # cellname_from_display() rather than special-casing "" throughout.
304
+ # cellname_from_display() rather than special-casing "" throughout. Once the GDS
305
+ # file is read, the entry names the cell that "" means: "(default: <cell>)", the
306
+ # design cell gds2palace's read_gds() takes (select_design_cell: the largest
307
+ # top-level cell, never KLayout's $$$CONTEXT_INFO$$$).
306
308
  CELLNAME_DEFAULT_LABEL = "(default)"
307
309
 
308
310
 
@@ -310,8 +312,12 @@ def cellname_for_display(cellname):
310
312
  return cellname if cellname else CELLNAME_DEFAULT_LABEL
311
313
 
312
314
 
315
+ def cellname_default_label(design_cell_name):
316
+ return f"{CELLNAME_DEFAULT_LABEL[:-1]}: {design_cell_name})" if design_cell_name else CELLNAME_DEFAULT_LABEL
317
+
318
+
313
319
  def cellname_from_display(text):
314
- return "" if text == CELLNAME_DEFAULT_LABEL else text
320
+ return "" if text == CELLNAME_DEFAULT_LABEL or text.startswith(CELLNAME_DEFAULT_LABEL[:-1] + ": ") else text
315
321
 
316
322
 
317
323
  def is_setupem_generated(path):
@@ -908,17 +914,19 @@ class FileInputTab(QWidget):
908
914
 
909
915
  def update_cellnames_from_gds(self, filename):
910
916
  if filename:
911
- # get top level cellnames now
917
+ # get the cellnames now, and the design cell that "(default)" stands for
912
918
  try:
913
- lib = gdspy.GdsLibrary()
914
- lib.read_gds(filename)
915
- cellnames = list(lib.cells.keys())
919
+ import gdstk
920
+ from gds2palace.util_gds_reader import select_design_cell
921
+ lib = gdstk.read_gds(filename)
922
+ cellnames = [c.name for c in lib.cells]
923
+ default_name = select_design_cell(lib).name if lib.top_level() else ""
916
924
  except Exception:
917
925
  # called on a just-resolved path during load_values() now, not only after
918
926
  # the user explicitly picked a file via the Browse dialog - be defensive
919
927
  return False
920
928
  self.cellname_box.clear()
921
- self.cellname_box.addItem(CELLNAME_DEFAULT_LABEL)
929
+ self.cellname_box.addItem(cellname_default_label(default_name))
922
930
  for cellname in cellnames:
923
931
  self.cellname_box.addItem(cellname)
924
932
  return True
@@ -1146,7 +1154,8 @@ class FileInputTab(QWidget):
1146
1154
  # was set) with no way to pick a different one without re-browsing for the file.
1147
1155
  saved_cellname = get_saved_value(saved_values, "cellname", "")
1148
1156
  if os.path.isfile(gdsfile) and self.update_cellnames_from_gds(gdsfile):
1149
- index = self.cellname_box.findText(cellname_for_display(saved_cellname))
1157
+ # the "(default: ...)" entry is always the first one
1158
+ index = self.cellname_box.findText(saved_cellname) if saved_cellname else 0
1150
1159
  self.cellname_box.setCurrentIndex(index if index >= 0 else 0)
1151
1160
  else:
1152
1161
  self.cellname_box.clear()
@@ -4822,7 +4831,7 @@ class MainWindowBase(QMainWindow):
4822
4831
 
4823
4832
  self.import_model_action.triggered.connect(lambda: self.import_py_model())
4824
4833
  self.edit_model_action.triggered.connect(lambda: self.edit_py_model())
4825
- self.save_script_action.triggered.connect(lambda: self.save_script_in_place())
4834
+ self.save_script_action.triggered.connect(lambda: self.save_current_file())
4826
4835
  self.revert_script_action.triggered.connect(lambda: self.revert_script_in_place())
4827
4836
  self.export_model_action.triggered.connect(lambda: self.export_to_python())
4828
4837
  self.preferences_action.triggered.connect(lambda: self.open_preferences_dialog())
@@ -5051,6 +5060,8 @@ class MainWindowBase(QMainWindow):
5051
5060
  self._stop_preserve_mode()
5052
5061
  self.protected_source_model_path = None
5053
5062
  self.backup_before_overwrite = None
5063
+ self.config_file = None # a new model: no settings file yet (Ctrl+S asks for one)
5064
+ self._config_baseline = None
5054
5065
  self.saved_values.clear()
5055
5066
  self.materials_list = None
5056
5067
  self.dielectrics_list = None
@@ -5060,6 +5071,7 @@ class MainWindowBase(QMainWindow):
5060
5071
  self.load_all_tabs()
5061
5072
  self.create_model_tab.log_area.clear()
5062
5073
  self.create_model_tab._reset_live_status()
5074
+ self._update_in_place_menu()
5063
5075
 
5064
5076
  def load_user_inputs(self, filename):
5065
5077
  # load of native configuration file
@@ -5207,6 +5219,8 @@ class MainWindowBase(QMainWindow):
5207
5219
  self.apply_native_config_data(data)
5208
5220
  self.load_all_tabs()
5209
5221
  self._add_recent_file(RECENT_SETTINGS_KEY, file_path)
5222
+ self.config_file = file_path # Ctrl+S saves to this file
5223
+ self._mark_config_saved() # the baseline for unsaved changes
5210
5224
  if not quiet:
5211
5225
  # in the log, not a message box: nothing to decide, and a box blocks a start with no display
5212
5226
  log_area = self.create_model_tab.log_area
@@ -5241,6 +5255,9 @@ class MainWindowBase(QMainWindow):
5241
5255
  if answer != QMessageBox.Yes:
5242
5256
  return
5243
5257
  leave_current_script()
5258
+ self.config_file = None # a model from a script: no settings file for Ctrl+S to write
5259
+ self._config_baseline = None
5260
+ self._update_in_place_menu()
5244
5261
  if not quiet and self.piece_set is not None:
5245
5262
  self.piece_set = None # another model: the split region is closed
5246
5263
  self.current_piece = None
@@ -6076,16 +6093,21 @@ class MainWindowBase(QMainWindow):
6076
6093
  action()
6077
6094
 
6078
6095
  def _update_in_place_menu(self):
6079
- # Save script / Revert only in edit-in-place mode; Save Config (*.simcfg)
6080
- # is hidden there, a config file next to the script would be a second,
6081
- # diverging copy of its settings
6096
+ # Save (Ctrl+S) always: the script edited in place, the piece of a split region or the settings file the
6097
+ # model was opened from (save_current_file), named after it. Revert only in edit-in-place mode; Save Config
6098
+ # (*.simcfg) is hidden there, a config file next to the script would be a second, diverging copy of its
6099
+ # settings
6082
6100
  in_place = getattr(self, "script_model", None) is not None
6083
- self.save_script_action.setVisible(in_place)
6084
6101
  self.revert_script_action.setVisible(in_place)
6085
6102
  if in_place:
6086
6103
  name = os.path.basename(self.script_model.path)
6087
6104
  self.save_script_action.setText(f"Save {name}")
6088
6105
  self.revert_script_action.setText(f"Revert {name}")
6106
+ elif getattr(self, "piece_set", None) is not None and getattr(self, "current_piece", None) is not None:
6107
+ self.save_script_action.setText(f"Save {self.current_piece['piece']}")
6108
+ else:
6109
+ config = self._current_config_file()
6110
+ self.save_script_action.setText(f"Save {os.path.basename(config)}" if config else "Save ...")
6089
6111
  self.save_action.setVisible(not in_place)
6090
6112
 
6091
6113
  # saved_values key -> (tab attribute, [widget attributes]) of the fields that
@@ -6293,7 +6315,7 @@ class MainWindowBase(QMainWindow):
6293
6315
 
6294
6316
  def _set_script_dirty(self, dirty):
6295
6317
  self._script_dirty = dirty
6296
- self.save_script_action.setEnabled(self.script_model is not None)
6318
+ self._update_in_place_menu() # Save is always there (save_current_file), named after the file
6297
6319
  self._refresh_title()
6298
6320
 
6299
6321
  def script_has_unsaved_changes(self):
@@ -6385,11 +6407,115 @@ class MainWindowBase(QMainWindow):
6385
6407
  return
6386
6408
  self.load_configuration_from_file(self.script_model.path, in_place=True, ask_unsaved=False)
6387
6409
 
6410
+ # ---------- the settings file opened: Save (Ctrl+S) and its unsaved changes ----------
6411
+
6412
+ def _current_config_file(self):
6413
+ """The settings file (*.simcfg / *.tsimcfg) the tabs were loaded from or last saved to, if it still exists;
6414
+ None for a script edited in place, a split region (its pieces save themselves), or a model from a script or
6415
+ File > New. (Not user_inputs_file: that stays set while a script is edited in place, for Create Model's link
6416
+ from a layout tool's settings file to the script.)"""
6417
+ if getattr(self, "script_model", None) is not None or getattr(self, "piece_set", None) is not None:
6418
+ return None
6419
+ path = getattr(self, "config_file", None)
6420
+ if path and path.lower().endswith("." + self.CONFIG_SUFFIX.lower()) and os.path.isfile(path):
6421
+ return path
6422
+ return None
6423
+
6424
+ def _config_struct(self):
6425
+ """The settings as a settings file holds them (Save Config)."""
6426
+ struct = {"application": self.APP_NAME, "data_format": "1.0"}
6427
+ struct["saved_values"] = self.saved_values
6428
+ struct.update(self.native_config_extra_struct())
6429
+ return struct
6430
+
6431
+ def _config_fingerprint(self):
6432
+ """The tabs' settings as text, for comparing: saved from the tabs without the tabs' warnings (an invalid field
6433
+ is the user's to find when saving, not when opening or closing)."""
6434
+ shown = {kind: getattr(QMessageBox, kind) for kind in ("warning", "critical", "information")}
6435
+ try:
6436
+ for kind in shown:
6437
+ setattr(QMessageBox, kind, staticmethod(lambda *args, **kwargs: QMessageBox.Ok))
6438
+ self.save_all_tabs()
6439
+ finally:
6440
+ for kind, function in shown.items():
6441
+ setattr(QMessageBox, kind, function)
6442
+ return json.dumps(self._config_struct(), sort_keys=True, default=str)
6443
+
6444
+ def _mark_config_saved(self):
6445
+ """The tabs hold what the settings file holds (just loaded or saved): the baseline for unsaved changes."""
6446
+ self._config_baseline = self._config_fingerprint() if self._current_config_file() else None
6447
+ self._update_in_place_menu()
6448
+
6449
+ def config_has_unsaved_changes(self):
6450
+ if self._current_config_file() is None or getattr(self, "_config_baseline", None) is None:
6451
+ return False
6452
+ return self._config_fingerprint() != self._config_baseline
6453
+
6454
+ def _write_config(self, filename, keep_other_keys):
6455
+ """Write the settings file; keep_other_keys: keep the file's other top-level keys (e.g. a layout tool's
6456
+ model_script link or pieces). Returns True when written. A tab with invalid input says so (its warning) and
6457
+ keeps its last valid values, as Save Config always did."""
6458
+ self.save_all_tabs()
6459
+ data = {}
6460
+ if keep_other_keys and os.path.isfile(filename):
6461
+ try:
6462
+ with open(filename, encoding="utf-8") as f:
6463
+ data = json.load(f)
6464
+ except (OSError, ValueError):
6465
+ data = {}
6466
+ if not isinstance(data, dict):
6467
+ data = {}
6468
+ data.update(self._config_struct())
6469
+ try:
6470
+ with open(filename, "w", encoding="utf-8") as f:
6471
+ json.dump(data, f, indent=4)
6472
+ except OSError as e:
6473
+ QMessageBox.warning(self, "Error", f"Failed to save config to {filename}: {e}")
6474
+ return False
6475
+ self._add_recent_file(RECENT_SETTINGS_KEY, filename)
6476
+ self.config_file = filename
6477
+ self._mark_config_saved()
6478
+ return True
6479
+
6480
+ def save_current_file(self):
6481
+ """File > Save (Ctrl+S): the script edited in place, the current piece of a split region, or the settings
6482
+ file the model was opened from (an export of a layout tool too); with none of them, Save Config's dialog.
6483
+ Returns True when saved."""
6484
+ if self.script_model is not None:
6485
+ return self.save_script_in_place()
6486
+ if getattr(self, "piece_set", None) is not None and getattr(self, "current_piece", None) is not None:
6487
+ self.leave_piece(self.current_piece)
6488
+ self.create_model_tab.log_area.appendPlainText(f"Saved {self.current_piece['piece']}.\n")
6489
+ return True
6490
+ path = self._current_config_file()
6491
+ if path is None:
6492
+ self.save_ask_filenamefile()
6493
+ return self._current_config_file() is not None
6494
+ if self._write_config(path, keep_other_keys=True):
6495
+ self.create_model_tab.log_area.appendPlainText(f"Config saved to {shorten_path_for_display(path)}\n")
6496
+ return True
6497
+ return False
6498
+
6499
+ def confirm_unsaved_config(self):
6500
+ """Before New, Load, Import, Open or Exit: offer to save changes to the settings file the model was opened
6501
+ from. Returns False to stay."""
6502
+ if not self.config_has_unsaved_changes():
6503
+ return True
6504
+ path = self._current_config_file()
6505
+ answer = QMessageBox.question(
6506
+ self, "Unsaved changes",
6507
+ f"Save the changes to {os.path.basename(path)}?",
6508
+ QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel, QMessageBox.Save)
6509
+ if answer == QMessageBox.Save:
6510
+ return self._write_config(path, keep_other_keys=True)
6511
+ return answer == QMessageBox.Discard
6512
+
6388
6513
  def confirm_unsaved_script(self):
6389
6514
  """Before leaving edit-in-place mode (New, Load, Import, Open, Exit): offer
6390
- to save unsaved changes. Returns False to stay."""
6515
+ to save unsaved changes. Returns False to stay. Without a script edited in place: the same for the settings
6516
+ file the model was opened from (confirm_unsaved_config)."""
6391
6517
  if not self.script_has_unsaved_changes():
6392
- return True
6518
+ return self.confirm_unsaved_config()
6393
6519
  answer = QMessageBox.question(
6394
6520
  self, "Unsaved changes",
6395
6521
  f"Save the changes to {os.path.basename(self.script_model.path)}?",
@@ -6531,19 +6657,13 @@ class MainWindowBase(QMainWindow):
6531
6657
  raise NotImplementedError
6532
6658
 
6533
6659
  def save_user_inputs_to_file(self, filename):
6534
- # make sure all tabs save their values
6535
- self.save_all_tabs()
6536
-
6660
+ # Save Config: the file becomes the one File > Save (Ctrl+S) writes; saved over the file the model was
6661
+ # opened from, that file's other keys (e.g. a layout tool's) are kept
6662
+ current = self._current_config_file()
6663
+ keep = bool(current) and same_path(filename, current)
6537
6664
  try:
6538
- struct = {"application": self.APP_NAME,
6539
- "data_format": "1.0"}
6540
- struct["saved_values"] = self.saved_values
6541
- struct.update(self.native_config_extra_struct())
6542
-
6543
- with open(filename, "w") as f:
6544
- json.dump(struct, f, indent=4)
6545
- self._add_recent_file(RECENT_SETTINGS_KEY, filename)
6546
- QMessageBox.information(self, "Saved", f"Config saved to {filename}")
6665
+ if self._write_config(filename, keep_other_keys=keep):
6666
+ QMessageBox.information(self, "Saved", f"Config saved to {filename}")
6547
6667
  except Exception as e:
6548
6668
  QMessageBox.warning(self, "Error", f"Failed to save config to {filename}: {e}")
6549
6669