API Reference
gsim¶
Functions¶
get_status
¶
wait_for_results
¶
wait_for_results(
*job_ids: str,
verbose: bool = True,
parent_dir: str | Path | None = None,
poll_interval: float = 5.0,
) -> Any
Wait for one or more jobs to finish, then download and parse results.
Accepts job IDs as positional args or a single list/tuple::
wait_for_results(id1, id2)
wait_for_results([id1, id2])
For a single job, returns the parsed result directly. For multiple jobs, returns a list of results (same order as input).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*job_ids
|
str
|
One or more job ID strings, or a single list/tuple of IDs. |
()
|
verbose
|
bool
|
Print progress messages. |
True
|
parent_dir
|
str | Path | None
|
Where to create sim-data directories (default: cwd). |
None
|
poll_interval
|
float
|
Seconds between status polls (default 5.0). |
5.0
|
Returns:
| Type | Description |
|---|---|
Any
|
Parsed result (single job) or list of parsed results (multiple jobs). |
Source code in src/gsim/gcloud.py
gsim.common¶
Classes¶
Geometry
¶
Bases: BaseModel
Shared geometry wrapper for gdsfactory Component.
This class wraps a gdsfactory Component and provides computed properties that are useful for simulation setup (bounds, ports, etc.).
Attributes:
| Name | Type | Description |
|---|---|---|
component |
Any
|
The wrapped gdsfactory Component |
Example
from gdsfactory.components import straight c = straight(length=100) geom = Geometry(component=c) print(geom.bounds) (0.0, -0.25, 100.0, 0.25)
Methods:
| Name | Description |
|---|---|
get_port |
Get a port by name. |
GeometryModel
dataclass
¶
GeometryModel(
prisms: dict[str, list[Prism]],
bbox: tuple[tuple[float, float, float], tuple[float, float, float]],
layer_bboxes: dict[
str, tuple[tuple[float, float, float], tuple[float, float, float]]
] = dict(),
layer_mesh_orders: dict[str, int] = dict(),
)
Complete 3D geometry: layers of prisms, ready for visualization.
Attributes:
| Name | Type | Description |
|---|---|---|
prisms |
dict[str, list[Prism]]
|
Mapping from layer name to list of Prism objects. |
bbox |
tuple[tuple[float, float, float], tuple[float, float, float]]
|
Axis-aligned 3D bounding box as ((xmin, ymin, zmin), (xmax, ymax, zmax)). |
layer_bboxes |
dict[str, tuple[tuple[float, float, float], tuple[float, float, float]]]
|
Optional per-layer bounding boxes for 2D slice logic. |
layer_mesh_orders |
dict[str, int]
|
Optional mapping of layer_name -> mesh_order for z-ordering in 2D plots. |
Methods:
| Name | Description |
|---|---|
get_layer_bbox |
Return the bounding box for a specific layer. |
get_layer_center |
Return the center of a layer's bounding box. |
get_layer_bbox
¶
Return the bounding box for a specific layer.
Falls back to the geometry-wide bbox if no per-layer bbox is stored.
Source code in src/gsim/common/geometry_model.py
get_layer_center
¶
Return the center of a layer's bounding box.
Falls back to the geometry-wide center if no per-layer bbox is stored.
Source code in src/gsim/common/geometry_model.py
Layer
¶
Bases: BaseModel
Layer information for Palace simulation.
Methods:
| Name | Description |
|---|---|
get_mesh_size |
Get mesh size in um for this layer. |
to_dict |
Convert to dictionary for YAML output. |
get_mesh_size
¶
Get mesh size in um for this layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_size
|
float
|
Base mesh size for "medium" resolution |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
Mesh size in um |
Source code in src/gsim/common/stack/extractor.py
to_dict
¶
to_dict() -> dict
Convert to dictionary for YAML output.
Source code in src/gsim/common/stack/extractor.py
LayerStack
¶
Bases: BaseModel
Complete layer stack for Palace simulation.
Methods:
| Name | Description |
|---|---|
from_layer_list |
Build a LayerStack from a list of Layer objects. |
get_conductor_layers |
Get all conductor layers. |
get_via_layers |
Get all via layers. |
get_z_range |
Get the full z-range of the stack (substrate bottom to air top). |
to_dict |
Convert to dictionary for YAML output. |
to_yaml |
Convert to YAML string and optionally write to file. |
validate_stack |
Validate the layer stack for simulation readiness. |
from_layer_list
classmethod
¶
from_layer_list(layerList: list[Layer]) -> LayerStack
Build a LayerStack from a list of Layer objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layerList
|
list[Layer]
|
List of Layer definitions to include in the stack. |
required |
Returns:
| Type | Description |
|---|---|
LayerStack
|
A LayerStack with layers/materials/dielectrics assembled from |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/gsim/common/stack/extractor.py
get_conductor_layers
¶
get_via_layers
¶
get_z_range
¶
Get the full z-range of the stack (substrate bottom to air top).
Source code in src/gsim/common/stack/extractor.py
to_dict
¶
to_dict() -> dict
Convert to dictionary for YAML output.
Source code in src/gsim/common/stack/extractor.py
to_yaml
¶
Convert to YAML string and optionally write to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | None
|
Optional path to write YAML file |
None
|
Returns:
| Type | Description |
|---|---|
str
|
YAML string |
Source code in src/gsim/common/stack/extractor.py
validate_stack
¶
validate_stack(tolerance: float = 0.001) -> ValidationResult
Validate the layer stack for simulation readiness.
Checks: 1. Z-axis continuity: no gaps in dielectric regions 2. Material coverage: all materials have properties defined 3. Layer coverage: all conductor/via layers are within dielectric envelope 4. No negative thicknesses
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Tolerance for z-coordinate comparisons (um) |
0.001
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with valid flag, errors, and warnings |
Source code in src/gsim/common/stack/extractor.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
Prism
dataclass
¶
Prism(
vertices: ndarray,
z_base: float,
z_top: float,
layer_name: str = "",
material: str = "",
sidewall_angle: float = 0.0,
original_polygon: Any = None,
)
A 2D polygon extruded in z. No solver dependency.
Attributes:
| Name | Type | Description |
|---|---|---|
vertices |
ndarray
|
(N, 2) numpy array of xy coordinates defining the polygon. |
z_base |
float
|
Bottom z coordinate of the extrusion. |
z_top |
float
|
Top z coordinate of the extrusion. |
layer_name |
str
|
Name of the layer this prism belongs to. |
material |
str
|
Name of the material assigned to this prism. |
sidewall_angle |
float
|
Sidewall taper angle in degrees (gdsfactory convention). |
original_polygon |
Any
|
Optional reference to the source Shapely polygon. |
ValidationResult
¶
Bases: BaseModel
Result of stack validation.
Functions¶
decimate
¶
decimate(
polygons: list[Polygon], relative_tolerance: float = 0.001, *, verbose: bool = False
) -> list[Polygon]
Reduce vertex count of a list of KLayout polygons.
Only polygons with more than 20 hull vertices are simplified; simpler shapes are kept as-is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygons
|
list[Polygon]
|
Input polygon list. |
required |
relative_tolerance
|
float
|
Fraction of polygon size used as tolerance. |
0.001
|
verbose
|
bool
|
Print per-polygon reduction statistics. |
False
|
Returns:
| Type | Description |
|---|---|
list[Polygon]
|
List of (possibly simplified) polygons. |
Source code in src/gsim/common/polygon_utils.py
extract_geometry_model
¶
extract_geometry_model(layered_component: LayeredComponentBase) -> GeometryModel
Convert a LayeredComponentBase into a GeometryModel with generic Prisms.
For each geometry layer (sorted by mesh_order): 1. Retrieve the merged Shapely polygon from layered_component.polygons. 2. Compute z_base / z_top from get_layer_bbox. 3. Iterate sub-polygons for MultiPolygon geometries. 4. Handle polygons with holes via Delaunay triangulation. 5. Produce Prism objects with (N, 2) numpy vertex arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layered_component
|
LayeredComponentBase
|
A LayeredComponentBase (or subclass) instance that provides polygons, geometry_layers, and get_layer_bbox. |
required |
Returns:
| Type | Description |
|---|---|
GeometryModel
|
A GeometryModel containing all extracted prisms and the overall |
GeometryModel
|
3D bounding box. |
Source code in src/gsim/common/geometry_model.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
klayout_to_shapely
¶
Convert a KLayout polygon (with optional holes) to a Shapely Polygon.
Source code in src/gsim/common/polygon_utils.py
shapely_to_klayout
¶
Convert a Shapely Polygon back to a KLayout polygon.
Returns None if the polygon is empty, invalid, or has fewer than
3 exterior vertices.
Source code in src/gsim/common/polygon_utils.py
gsim.common.viz¶
Functions¶
create_web_export
¶
create_web_export(
geometry_model: GeometryModel,
filename: str = "geometry_3d.html",
title: str = "3D Geometry Visualization",
) -> str
Export 3D visualisation as standalone HTML (via PyVista).
Source code in src/gsim/common/viz/render3d_pyvista.py
export_3d_mesh
¶
export_3d_mesh(geometry_model: GeometryModel, filename: str, fmt: str = 'auto') -> None
Export 3D geometry to mesh file (STL, PLY, OBJ, VTK, glTF).
Source code in src/gsim/common/viz/render3d_pyvista.py
plot_prism_slices
¶
plot_prism_slices(
geometry_model: GeometryModel,
x: float | str | None = None,
y: float | str | None = None,
z: float | str = "core",
ax: Axes | None = None,
legend: bool = True,
slices: str = "z",
*,
overlay: Any | None = None,
) -> Axes | None
Plot cross sections of a GeometryModel with multi-view support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry_model
|
GeometryModel
|
GeometryModel with prisms and bbox. |
required |
x
|
float | str | None
|
X-coordinate (or layer name) for the slice plane. |
None
|
y
|
float | str | None
|
Y-coordinate (or layer name) for the slice plane. |
None
|
z
|
float | str
|
Z-coordinate (or layer name) for the slice plane. |
'core'
|
ax
|
Axes | None
|
Axes to draw on. If |
None
|
legend
|
bool
|
Whether to show the legend. |
True
|
slices
|
str
|
Which slice(s) to plot -- "x", "y", "z", or combinations like "xy", "xz", "yz", "xyz". |
'z'
|
overlay
|
Any | None
|
Optional SimOverlay with sim cell / PML / port metadata. |
None
|
Returns:
| Type | Description |
|---|---|
Axes | None
|
|
Axes | None
|
(the figure is shown directly). |
Source code in src/gsim/common/viz/render2d.py
plot_prisms_3d
¶
plot_prisms_3d(
geometry_model: GeometryModel,
*,
show_edges: bool = True,
opacity: float = 0.8,
color_by_layer: bool = True,
show_simulation_box: bool = True,
camera_position: str | None = "isometric",
notebook: bool = True,
theme: str = "default",
**kwargs: Any,
) -> Any | None
Create interactive 3D visualisation of prisms using PyVista.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry_model
|
GeometryModel
|
A GeometryModel with prisms and bbox. |
required |
show_edges
|
bool
|
Whether to show edges of the prisms. |
True
|
opacity
|
float
|
Base opacity (0.0-1.0). Core layer forced opaque. |
0.8
|
color_by_layer
|
bool
|
Colour by layer name. |
True
|
show_simulation_box
|
bool
|
Draw the simulation bounding box. |
True
|
camera_position
|
str | None
|
"isometric", "xy", "xz", "yz", or custom tuple. |
'isometric'
|
notebook
|
bool
|
Whether running inside Jupyter. |
True
|
theme
|
str
|
PyVista theme ("default", "dark", "document"). |
'default'
|
**kwargs
|
Any
|
Extra args forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Any | None
|
PyVista plotter object for further customisation. |
Source code in src/gsim/common/viz/render3d_pyvista.py
plot_prisms_3d_open3d
¶
plot_prisms_3d_open3d(
geometry_model: GeometryModel,
*,
show_edges: bool = False,
color_by_layer: bool = True,
show_simulation_box: bool = True,
notebook: bool = True,
layer_opacity: dict[str, float] | None = None,
**kwargs: Any,
) -> None
Create interactive 3D visualisation using Open3D + Plotly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry_model
|
GeometryModel
|
GeometryModel containing prisms and bbox. |
required |
show_edges
|
bool
|
Show wireframe edges. |
False
|
color_by_layer
|
bool
|
Colour each layer differently. |
True
|
show_simulation_box
|
bool
|
Draw the simulation box. |
True
|
notebook
|
bool
|
Display inside Jupyter notebook. |
True
|
layer_opacity
|
dict[str, float] | None
|
Per-layer opacity override (default: core=1.0, else 0.2). |
None
|
**kwargs
|
Any
|
Extra Plotly figure options. |
{}
|
Source code in src/gsim/common/viz/render3d_open3d.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
gsim.palace¶
Classes¶
CPWPortConfig
¶
Bases: BaseModel
Configuration for a coplanar waveguide (CPW) port.
CPW ports consist of two elements (upper and lower gaps) that are excited with opposite E-field directions to create the CPW mode.
The port is placed at the center of the signal conductor. The two gap element surfaces are computed from s_width and gap_width.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Port name (must match a single component port at the signal center) |
layer |
str
|
Target conductor layer |
s_width |
float
|
Width of the signal (center) conductor (um) |
gap_width |
float
|
Width of each gap between signal and ground (um) |
length |
float
|
Port extent along direction (um) |
offset |
float
|
Shift the port along the waveguide direction (um). Positive moves in the port orientation direction. |
impedance |
float
|
Port impedance (Ohms) |
excited |
bool
|
Whether this port is excited |
DrivenConfig
¶
Bases: BaseModel
Configuration for driven (frequency sweep) simulation.
This is used for S-parameter extraction and frequency response analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
fmin |
float
|
Minimum frequency in Hz |
fmax |
float
|
Maximum frequency in Hz |
num_points |
int
|
Number of frequency points |
scale |
Literal['linear', 'log']
|
Frequency spacing ("linear" or "log") |
adaptive_tol |
float
|
Adaptive tolerance (0 disables adaptive) |
adaptive_max_samples |
int
|
Maximum samples for adaptive refinement |
compute_s_params |
bool
|
Whether to compute S-parameters |
reference_impedance |
float
|
Reference impedance for S-params (Ohms) |
excitation_port |
str | None
|
Name of port to excite (None = first port) |
Methods:
| Name | Description |
|---|---|
to_palace_config |
Convert to Palace JSON config format. |
validate_frequency_range |
Validate that fmin < fmax. |
to_palace_config
¶
to_palace_config() -> dict
Convert to Palace JSON config format.
Source code in src/gsim/palace/models/problems.py
DrivenSim
¶
Bases: PalaceSimMixin, BaseModel
Frequency-domain driven simulation for S-parameter extraction.
This class configures and runs driven simulations that sweep through frequencies to compute S-parameters. Uses composition (no inheritance) with shared Geometry and Stack components from gsim.common.
Example
from gsim.palace import DrivenSim
sim = DrivenSim() sim.set_geometry(component) sim.set_stack(air_above=300.0) sim.add_cpw_port("o1", layer="topmetal2", s_width=10, gap_width=6, length=5) sim.add_cpw_port("o2", layer="topmetal2", s_width=10, gap_width=6, length=5) sim.set_driven(fmin=1e9, fmax=100e9, num_points=40) sim.set_output_dir("./sim") sim.mesh(preset="default") results = sim.run()
Attributes:
| Name | Type | Description |
|---|---|---|
geometry |
Geometry | None
|
Wrapped gdsfactory Component (from common) |
stack |
LayerStack | None
|
Layer stack configuration (from common) |
ports |
list[PortConfig]
|
List of single-element port configurations |
cpw_ports |
list[CPWPortConfig]
|
List of CPW (two-element) port configurations |
driven |
DrivenConfig
|
Driven simulation configuration (frequencies, etc.) |
mesh |
SimulationResult
|
Mesh configuration |
materials |
dict[str, MaterialConfig]
|
Material property overrides |
numerical |
NumericalConfig
|
Numerical solver configuration |
Methods:
| Name | Description |
|---|---|
add_cpw_port |
Add a coplanar waveguide (CPW) port. |
add_port |
Add a single-element lumped port. |
get_status |
Get the current status of this sim's cloud job. |
mesh |
Generate the mesh for Palace simulation. |
plot_mesh |
Plot the mesh using PyVista. |
plot_stack |
Plot the layer stack visualization. |
preview |
Preview the mesh without running simulation. |
run |
Run simulation on GDSFactory+ cloud. |
run_local |
Run simulation locally using Palace via Apptainer. |
set_driven |
Configure driven (frequency sweep) simulation. |
set_geometry |
Set the gdsfactory component for simulation. |
set_material |
Override or add material properties. |
set_numerical |
Configure numerical solver parameters. |
set_output_dir |
Set the output directory for mesh and config files. |
set_stack |
Configure the layer stack. |
show_stack |
Print the layer stack table. |
start |
Start cloud execution for this sim's uploaded job. |
upload |
Prepare config, upload to the cloud. Does NOT start execution. |
validate_config |
Validate the simulation configuration. |
validate_mesh |
Validate the generated mesh and config before cloud submission. |
wait_for_results |
Wait for this sim's cloud job, download and parse results. |
write_config |
Write Palace config.json after mesh generation. |
component
property
¶
Get the current component (for backward compatibility).
add_cpw_port
¶
add_cpw_port(
name: str,
*,
layer: str,
s_width: float,
gap_width: float,
length: float,
offset: float = 0.0,
impedance: float = 50.0,
excited: bool = True,
) -> None
Add a coplanar waveguide (CPW) port.
CPW ports consist of two elements (upper and lower gaps) that are excited with opposite E-field directions to create the CPW mode.
Place a single gdsfactory port at the center of the signal conductor. The two gap element surfaces are computed from s_width and gap_width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Port name (must match a component port at the signal center) |
required |
layer
|
str
|
Target conductor layer (e.g., "topmetal2") |
required |
s_width
|
float
|
Width of the signal (center) conductor (um) |
required |
gap_width
|
float
|
Width of each gap between signal and ground (um) |
required |
length
|
float
|
Port extent along direction (um) |
required |
offset
|
float
|
Shift the port inward along the waveguide (um). Positive moves away from the boundary, into the conductor. |
0.0
|
impedance
|
float
|
Port impedance (Ohms) |
50.0
|
excited
|
bool
|
Whether this port is excited |
True
|
Example
sim.add_cpw_port( ... "left", layer="topmetal2", s_width=20, gap_width=15, length=5.0 ... )
Source code in src/gsim/palace/driven.py
add_port
¶
add_port(
name: str,
*,
layer: str | None = None,
from_layer: str | None = None,
to_layer: str | None = None,
length: float | None = None,
impedance: float = 50.0,
resistance: float | None = None,
inductance: float | None = None,
capacitance: float | None = None,
excited: bool = True,
geometry: Literal["inplane", "via"] = "inplane",
) -> None
Add a single-element lumped port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Port name (must match component port name) |
required |
layer
|
str | None
|
Target layer for inplane ports |
None
|
from_layer
|
str | None
|
Bottom layer for via ports |
None
|
to_layer
|
str | None
|
Top layer for via ports |
None
|
length
|
float | None
|
Port extent along direction (um) |
None
|
impedance
|
float
|
Port impedance (Ohms) |
50.0
|
resistance
|
float | None
|
Series resistance (Ohms) |
None
|
inductance
|
float | None
|
Series inductance (H) |
None
|
capacitance
|
float | None
|
Shunt capacitance (F) |
None
|
excited
|
bool
|
Whether this port is excited |
True
|
geometry
|
Literal['inplane', 'via']
|
Port geometry type ("inplane" or "via") |
'inplane'
|
Example
sim.add_port("o1", layer="topmetal2", length=5.0) sim.add_port( ... "feed", from_layer="metal1", to_layer="topmetal2", geometry="via" ... )
Source code in src/gsim/palace/driven.py
get_status
¶
get_status() -> str
Get the current status of this sim's cloud job.
Returns:
Raises:
| Type | Description |
|---|---|
ValueError
|
If no job has been submitted yet. |
Source code in src/gsim/palace/driven.py
mesh
¶
mesh(
*,
preset: Literal["coarse", "default", "graded", "fine"] | None = None,
refined_mesh_size: float | None = None,
max_mesh_size: float | None = None,
margin: float | None = None,
airbox_margin: float | None = None,
fmax: float | None = None,
planar_conductors: bool | None = None,
show_gui: bool = False,
model_name: str = "palace",
verbose: bool = True,
) -> SimulationResult
Generate the mesh for Palace simulation.
Only generates the mesh file (palace.msh). Config is generated separately with write_config().
Requires set_output_dir() to be called first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset
|
Literal['coarse', 'default', 'graded', 'fine'] | None
|
Mesh quality preset ("coarse", "default", "graded", "fine") |
None
|
refined_mesh_size
|
float | None
|
Mesh size near conductors (um), overrides preset |
None
|
max_mesh_size
|
float | None
|
Max mesh size in air/dielectric (um), overrides preset |
None
|
margin
|
float | None
|
XY margin around design (um), overrides preset |
None
|
airbox_margin
|
float | None
|
Extra airbox around stack (um); 0 = disabled |
None
|
fmax
|
float | None
|
Max frequency for mesh sizing (Hz), overrides preset |
None
|
planar_conductors
|
bool | None
|
Treat conductors as 2D PEC surfaces |
None
|
show_gui
|
bool
|
Show gmsh GUI during meshing |
False
|
model_name
|
str
|
Base name for output files |
'palace'
|
verbose
|
bool
|
Print progress messages |
True
|
Returns:
| Type | Description |
|---|---|
SimulationResult
|
SimulationResult with mesh path |
Raises:
| Type | Description |
|---|---|
ValueError
|
If output_dir not set or configuration is invalid |
Example
sim.set_output_dir("./sim") result = sim.mesh(preset="fine", planar_conductors=True) print(f"Mesh saved to: {result.mesh_path}")
Source code in src/gsim/palace/driven.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
plot_mesh
¶
plot_mesh(
output: str | Path | None = None,
show_groups: list[str] | None = None,
interactive: bool = True,
style: Literal["wireframe", "solid"] = "wireframe",
transparent_groups: list[str] | None = None,
) -> None
Plot the mesh using PyVista.
Requires mesh() to be called first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str | Path | None
|
Output PNG path (only used if interactive=False) |
None
|
show_groups
|
list[str] | None
|
List of group name patterns to show (None = all). Example: ["metal", "P"] to show metal layers and ports. |
None
|
interactive
|
bool
|
If True, open interactive 3D viewer. If False, save static PNG to output path. |
True
|
style
|
Literal['wireframe', 'solid']
|
|
'wireframe'
|
transparent_groups
|
list[str] | None
|
Group names rendered at low opacity in solid mode. Ignored in wireframe mode. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If output_dir not set or mesh file doesn't exist |
Example
sim.mesh(preset="default") sim.plot_mesh(show_groups=["metal", "P"]) sim.plot_mesh(style="solid", transparent_groups=["Absorbing_boundary"])
Source code in src/gsim/palace/base.py
plot_stack
¶
Plot the layer stack visualization.
Example
sim.plot_stack()
Source code in src/gsim/palace/base.py
preview
¶
preview(
*,
preset: Literal["coarse", "default", "graded", "fine"] | None = None,
refined_mesh_size: float | None = None,
max_mesh_size: float | None = None,
margin: float | None = None,
airbox_margin: float | None = None,
fmax: float | None = None,
planar_conductors: bool | None = None,
show_gui: bool = True,
) -> None
Preview the mesh without running simulation.
Opens the gmsh GUI to visualize the mesh interactively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset
|
Literal['coarse', 'default', 'graded', 'fine'] | None
|
Mesh quality preset ("coarse", "default", "graded", "fine") |
None
|
refined_mesh_size
|
float | None
|
Mesh size near conductors (um) |
None
|
max_mesh_size
|
float | None
|
Max mesh size in air/dielectric (um) |
None
|
margin
|
float | None
|
XY margin around design (um) |
None
|
airbox_margin
|
float | None
|
Extra airbox around stack (um); 0 = disabled |
None
|
fmax
|
float | None
|
Max frequency for mesh sizing (Hz) |
None
|
planar_conductors
|
bool | None
|
Treat conductors as 2D PEC surfaces |
None
|
show_gui
|
bool
|
Show gmsh GUI for interactive preview |
True
|
Example
sim.preview(preset="fine", planar_conductors=True, show_gui=True)
Source code in src/gsim/palace/driven.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
run
¶
run(
parent_dir: str | Path | None = None, *, verbose: bool = True, wait: bool = True
) -> dict[str, Path] | str
Run simulation on GDSFactory+ cloud.
Requires mesh() to be called first. Automatically calls write_config() if config.json hasn't been written yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_dir
|
str | Path | None
|
Where to create the sim directory. Defaults to the current working directory. |
None
|
verbose
|
bool
|
Print progress messages. |
True
|
wait
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Path] | str
|
|
dict[str, Path] | str
|
or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If output_dir not set or mesh not generated |
RuntimeError
|
If simulation fails |
Example
results = sim.run() print(f"S-params saved to: {results['port-S.csv']}")
Source code in src/gsim/palace/driven.py
run_local
¶
run_local(
*,
palace_sif_path: str | Path | None = None,
num_processes: int | None = None,
verbose: bool = True,
) -> dict[str, Path]
Run simulation locally using Palace via Apptainer.
Requires mesh() and write_config() to be called first, and Palace to be installed locally via Apptainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
palace_sif_path
|
str | Path | None
|
Path to Palace Apptainer SIF file. If None, uses PALACE_SIF environment variable. |
None
|
num_processes
|
int | None
|
Number of MPI processes (default: CPU count - 2) |
None
|
verbose
|
bool
|
Print progress messages |
True
|
Returns:
Raises:
| Type | Description |
|---|---|
ValueError
|
If output_dir not set or PALACE_SIF not configured |
FileNotFoundError
|
If mesh, config, or Palace SIF not found |
RuntimeError
|
If simulation fails |
Example
Using environment variable¶
import os os.environ["PALACE_SIF"] = "/path/to/Palace.sif" results = sim.simulate_local()
Or specify path directly¶
results = sim.simulate_local(palace_sif_path="/path/to/Palace.sif") print(f"S-params: {results['port-S.csv']}")
Source code in src/gsim/palace/driven.py
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
set_driven
¶
set_driven(
*,
fmin: float = 1000000000.0,
fmax: float = 100000000000.0,
num_points: int = 40,
scale: Literal["linear", "log"] = "linear",
adaptive_tol: float = 0.02,
adaptive_max_samples: int = 20,
compute_s_params: bool = True,
reference_impedance: float = 50.0,
excitation_port: str | None = None,
) -> None
Configure driven (frequency sweep) simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmin
|
float
|
Minimum frequency in Hz |
1000000000.0
|
fmax
|
float
|
Maximum frequency in Hz |
100000000000.0
|
num_points
|
int
|
Number of frequency points |
40
|
scale
|
Literal['linear', 'log']
|
"linear" or "log" frequency spacing |
'linear'
|
adaptive_tol
|
float
|
Adaptive frequency tolerance (0 disables adaptive) |
0.02
|
adaptive_max_samples
|
int
|
Max samples for adaptive refinement |
20
|
compute_s_params
|
bool
|
Compute S-parameters |
True
|
reference_impedance
|
float
|
Reference impedance for S-params (Ohms) |
50.0
|
excitation_port
|
str | None
|
Port to excite (None = first port) |
None
|
Example
sim.set_driven(fmin=1e9, fmax=100e9, num_points=40)
Source code in src/gsim/palace/driven.py
set_geometry
¶
Set the gdsfactory component for simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
Component
|
gdsfactory Component to simulate |
required |
Example
sim.set_geometry(my_component)
Source code in src/gsim/palace/base.py
set_material
¶
set_material(
name: str,
*,
material_type: Literal["conductor", "dielectric", "semiconductor"] | None = None,
conductivity: float | None = None,
permittivity: float | None = None,
loss_tangent: float | None = None,
) -> None
Override or add material properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Material name |
required |
material_type
|
Literal['conductor', 'dielectric', 'semiconductor'] | None
|
Material type (conductor, dielectric, semiconductor) |
None
|
conductivity
|
float | None
|
Conductivity in S/m (for conductors) |
None
|
permittivity
|
float | None
|
Relative permittivity (for dielectrics) |
None
|
loss_tangent
|
float | None
|
Dielectric loss tangent |
None
|
Example
sim.set_material( ... "aluminum", material_type="conductor", conductivity=3.8e7 ... ) sim.set_material("sio2", material_type="dielectric", permittivity=3.9)
Source code in src/gsim/palace/base.py
set_numerical
¶
set_numerical(
*,
order: int = 1,
tolerance: float = 1e-06,
max_iterations: int = 400,
solver_type: Literal["Default", "SuperLU", "STRUMPACK", "MUMPS"] = "Default",
preconditioner: Literal["Default", "AMS", "BoomerAMG"] = "Default",
device: Literal["CPU", "GPU"] = "CPU",
num_processors: int | None = None,
) -> None
Configure numerical solver parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
Finite element order (1-4) |
1
|
tolerance
|
float
|
Linear solver tolerance |
1e-06
|
max_iterations
|
int
|
Maximum solver iterations |
400
|
solver_type
|
Literal['Default', 'SuperLU', 'STRUMPACK', 'MUMPS']
|
Linear solver type |
'Default'
|
preconditioner
|
Literal['Default', 'AMS', 'BoomerAMG']
|
Preconditioner type |
'Default'
|
device
|
Literal['CPU', 'GPU']
|
Compute device (CPU or GPU) |
'CPU'
|
num_processors
|
int | None
|
Number of processors (None = auto) |
None
|
Example
sim.set_numerical(order=3, tolerance=1e-8)
Source code in src/gsim/palace/base.py
set_output_dir
¶
Set the output directory for mesh and config files.
Parameters:
Example
sim.set_output_dir("./palace-sim")
Source code in src/gsim/palace/base.py
set_stack
¶
set_stack(
stack: LayerStack | None = None,
*,
yaml_path: str | Path | None = None,
air_above: float = 200.0,
substrate_thickness: float = 2.0,
include_substrate: bool = False,
**kwargs,
) -> None
Configure the layer stack.
Three modes of use:
-
Active PDK (default — auto-detects IHP, QPDK, etc.)::
sim.set_stack(air_above=300.0, substrate_thickness=2.0)
-
YAML file::
sim.set_stack(yaml_path="custom_stack.yaml")
-
Custom stack (advanced — pass a hand-built LayerStack)::
sim.set_stack(my_layer_stack)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stack
|
LayerStack | None
|
Custom gsim LayerStack (bypasses PDK extraction). |
None
|
yaml_path
|
str | Path | None
|
Path to custom YAML stack file. |
None
|
air_above
|
float
|
Air box height above top metal in um. |
200.0
|
substrate_thickness
|
float
|
Thickness below z=0 in um. |
2.0
|
include_substrate
|
bool
|
Include lossy silicon substrate. |
False
|
**kwargs
|
Additional args passed to extract_layer_stack. |
{}
|
Example
sim.set_stack(air_above=300.0, substrate_thickness=2.0)
Source code in src/gsim/palace/base.py
show_stack
¶
Print the layer stack table.
Example
sim.show_stack()
Source code in src/gsim/palace/base.py
start
¶
start(*, verbose: bool = True) -> None
Start cloud execution for this sim's uploaded job.
Raises:
| Type | Description |
|---|---|
ValueError
|
If :meth: |
Source code in src/gsim/palace/driven.py
upload
¶
Prepare config, upload to the cloud. Does NOT start execution.
Requires :meth:set_output_dir and :meth:mesh to have been
called first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Print progress messages. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str
|
|
|
or |
str
|
func: |
Source code in src/gsim/palace/driven.py
validate_config
¶
validate_config() -> ValidationResult
Validate the simulation configuration.
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with validation status and messages |
Source code in src/gsim/palace/driven.py
validate_mesh
¶
validate_mesh() -> ValidationResult
Validate the generated mesh and config before cloud submission.
Checks that physical groups are correctly assigned after meshing: conductor surfaces, dielectric volumes, ports, and absorbing boundary. Also verifies the generated config.json structure.
Call after mesh() and before run().
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with validation status and messages |
Example
sim.mesh(preset="coarse") result = sim.validate_mesh() print(result)
Source code in src/gsim/palace/base.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
wait_for_results
¶
Wait for this sim's cloud job, download and parse results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Print progress messages. |
True
|
parent_dir
|
str | Path | None
|
Where to create the sim-data directory. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Parsed result (typically |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no job has been submitted yet. |
Source code in src/gsim/palace/driven.py
write_config
¶
write_config() -> Path
Write Palace config.json after mesh generation.
Use this when mesh() was called with write_config=False.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the generated config.json |
Raises:
| Type | Description |
|---|---|
ValueError
|
If mesh() hasn't been called yet |
Example
result = sim.mesh("./sim", write_config=False) config_path = sim.write_config()
Source code in src/gsim/palace/driven.py
EigenmodeConfig
¶
Bases: BaseModel
Configuration for eigenmode (resonance) simulation.
This is used for finding resonant frequencies and mode shapes.
Attributes:
| Name | Type | Description |
|---|---|---|
num_modes |
int
|
Number of modes to find |
target |
float | None
|
Target frequency in Hz for mode search |
tolerance |
float
|
Eigenvalue solver tolerance |
Methods:
| Name | Description |
|---|---|
to_palace_config |
Convert to Palace JSON config format. |
EigenmodeSim
¶
Bases: PalaceSimMixin, BaseModel
Eigenmode simulation for finding resonant frequencies.
This class configures and runs eigenmode simulations to find resonant frequencies and mode shapes of structures.
Example
from gsim.palace import EigenmodeSim
sim = EigenmodeSim() sim.set_geometry(component) sim.set_stack(air_above=300.0) sim.add_port("o1", layer="topmetal2", length=5.0) sim.set_eigenmode(num_modes=10, target=50e9) sim.set_output_dir("./sim") sim.mesh(preset="default") results = sim.run()
Attributes:
| Name | Type | Description |
|---|---|---|
geometry |
Geometry | None
|
Wrapped gdsfactory Component (from common) |
stack |
LayerStack | None
|
Layer stack configuration (from common) |
ports |
list[PortConfig]
|
List of single-element port configurations |
cpw_ports |
list[CPWPortConfig]
|
List of CPW (two-element) port configurations |
eigenmode |
EigenmodeConfig
|
Eigenmode simulation configuration |
materials |
dict[str, MaterialConfig]
|
Material property overrides |
numerical |
NumericalConfig
|
Numerical solver configuration |
Methods:
| Name | Description |
|---|---|
add_cpw_port |
Add a coplanar waveguide (CPW) port. |
add_port |
Add a single-element lumped port. |
mesh |
Generate the mesh for Palace simulation. |
plot_mesh |
Plot the mesh using PyVista. |
plot_stack |
Plot the layer stack visualization. |
preview |
Preview the mesh without running simulation. |
run |
Run eigenmode simulation on GDSFactory+ cloud. |
set_eigenmode |
Configure eigenmode simulation. |
set_geometry |
Set the gdsfactory component for simulation. |
set_material |
Override or add material properties. |
set_numerical |
Configure numerical solver parameters. |
set_output_dir |
Set the output directory for mesh and config files. |
set_stack |
Configure the layer stack. |
show_stack |
Print the layer stack table. |
validate_config |
Validate the simulation configuration. |
validate_mesh |
Validate the generated mesh and config before cloud submission. |
component
property
¶
Get the current component (for backward compatibility).
add_cpw_port
¶
add_cpw_port(
name: str,
*,
layer: str,
s_width: float,
gap_width: float,
length: float,
offset: float = 0.0,
impedance: float = 50.0,
excited: bool = True,
) -> None
Add a coplanar waveguide (CPW) port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the port on the component (at signal center) |
required |
layer
|
str
|
Target conductor layer |
required |
s_width
|
float
|
Signal conductor width (um) |
required |
gap_width
|
float
|
Gap width between signal and ground (um) |
required |
length
|
float
|
Port extent along direction (um) |
required |
offset
|
float
|
Shift port inward along the waveguide (um). Positive moves away from the boundary, into the conductor. |
0.0
|
impedance
|
float
|
Port impedance (Ohms) |
50.0
|
excited
|
bool
|
Whether this port is excited |
True
|
Example
sim.add_cpw_port( ... "o1", layer="topmetal2", s_width=10, gap_width=6, length=5 ... )
Source code in src/gsim/palace/eigenmode.py
add_port
¶
add_port(
name: str,
*,
layer: str | None = None,
from_layer: str | None = None,
to_layer: str | None = None,
length: float | None = None,
impedance: float = 50.0,
resistance: float | None = None,
inductance: float | None = None,
capacitance: float | None = None,
excited: bool = True,
geometry: Literal["inplane", "via"] = "inplane",
) -> None
Add a single-element lumped port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Port name (must match component port name) |
required |
layer
|
str | None
|
Target layer for inplane ports |
None
|
from_layer
|
str | None
|
Bottom layer for via ports |
None
|
to_layer
|
str | None
|
Top layer for via ports |
None
|
length
|
float | None
|
Port extent along direction (um) |
None
|
impedance
|
float
|
Port impedance (Ohms) |
50.0
|
resistance
|
float | None
|
Series resistance (Ohms) |
None
|
inductance
|
float | None
|
Series inductance (H) |
None
|
capacitance
|
float | None
|
Shunt capacitance (F) |
None
|
excited
|
bool
|
Whether this port is excited |
True
|
geometry
|
Literal['inplane', 'via']
|
Port geometry type ("inplane" or "via") |
'inplane'
|
Example
sim.add_port("o1", layer="topmetal2", length=5.0) sim.add_port( ... "junction", layer="SUPERCONDUCTOR", length=5.0, inductance=10e-9 ... )
Source code in src/gsim/palace/eigenmode.py
mesh
¶
mesh(
*,
preset: Literal["coarse", "default", "graded", "fine"] | None = None,
refined_mesh_size: float | None = None,
max_mesh_size: float | None = None,
margin: float | None = None,
airbox_margin: float | None = None,
fmax: float | None = None,
planar_conductors: bool | None = None,
show_gui: bool = False,
model_name: str = "palace",
verbose: bool = True,
) -> SimulationResult
Generate the mesh for Palace simulation.
Requires set_output_dir() to be called first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset
|
Literal['coarse', 'default', 'graded', 'fine'] | None
|
Mesh quality preset ("coarse", "default", "graded", "fine") |
None
|
refined_mesh_size
|
float | None
|
Mesh size near conductors (um), overrides preset |
None
|
max_mesh_size
|
float | None
|
Max mesh size in air/dielectric (um), overrides preset |
None
|
margin
|
float | None
|
XY margin around design (um), overrides preset |
None
|
airbox_margin
|
float | None
|
Extra airbox around stack (um); 0 = disabled |
None
|
fmax
|
float | None
|
Max frequency for mesh sizing (Hz), overrides preset |
None
|
planar_conductors
|
bool | None
|
Treat conductors as 2D PEC surfaces |
None
|
show_gui
|
bool
|
Show gmsh GUI during meshing |
False
|
model_name
|
str
|
Base name for output files |
'palace'
|
verbose
|
bool
|
Print progress messages |
True
|
Returns:
| Type | Description |
|---|---|
SimulationResult
|
SimulationResult with mesh path |
Raises:
| Type | Description |
|---|---|
ValueError
|
If output_dir not set or configuration is invalid |
Example
sim.set_output_dir("./sim") result = sim.mesh(preset="fine", planar_conductors=True) print(f"Mesh saved to: {result.mesh_path}")
Source code in src/gsim/palace/eigenmode.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
plot_mesh
¶
plot_mesh(
output: str | Path | None = None,
show_groups: list[str] | None = None,
interactive: bool = True,
style: Literal["wireframe", "solid"] = "wireframe",
transparent_groups: list[str] | None = None,
) -> None
Plot the mesh using PyVista.
Requires mesh() to be called first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str | Path | None
|
Output PNG path (only used if interactive=False) |
None
|
show_groups
|
list[str] | None
|
List of group name patterns to show (None = all). Example: ["metal", "P"] to show metal layers and ports. |
None
|
interactive
|
bool
|
If True, open interactive 3D viewer. If False, save static PNG to output path. |
True
|
style
|
Literal['wireframe', 'solid']
|
|
'wireframe'
|
transparent_groups
|
list[str] | None
|
Group names rendered at low opacity in solid mode. Ignored in wireframe mode. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If output_dir not set or mesh file doesn't exist |
Example
sim.mesh(preset="default") sim.plot_mesh(show_groups=["metal", "P"]) sim.plot_mesh(style="solid", transparent_groups=["Absorbing_boundary"])
Source code in src/gsim/palace/base.py
plot_stack
¶
Plot the layer stack visualization.
Example
sim.plot_stack()
Source code in src/gsim/palace/base.py
preview
¶
preview(
*,
preset: Literal["coarse", "default", "graded", "fine"] | None = None,
refined_mesh_size: float | None = None,
max_mesh_size: float | None = None,
margin: float | None = None,
airbox_margin: float | None = None,
fmax: float | None = None,
planar_conductors: bool | None = None,
show_gui: bool = True,
) -> None
Preview the mesh without running simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset
|
Literal['coarse', 'default', 'graded', 'fine'] | None
|
Mesh quality preset ("coarse", "default", "graded", "fine") |
None
|
refined_mesh_size
|
float | None
|
Mesh size near conductors (um) |
None
|
max_mesh_size
|
float | None
|
Max mesh size in air/dielectric (um) |
None
|
margin
|
float | None
|
XY margin around design (um) |
None
|
airbox_margin
|
float | None
|
Extra airbox around stack (um); 0 = disabled |
None
|
fmax
|
float | None
|
Max frequency for mesh sizing (Hz) |
None
|
planar_conductors
|
bool | None
|
Treat conductors as 2D PEC surfaces |
None
|
show_gui
|
bool
|
Show gmsh GUI for interactive preview |
True
|
Example
sim.preview(preset="fine", planar_conductors=True, show_gui=True)
Source code in src/gsim/palace/eigenmode.py
run
¶
Run eigenmode simulation on GDSFactory+ cloud.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str | Path | None
|
Directory containing mesh files |
None
|
verbose
|
bool
|
Print progress messages |
True
|
Returns:
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Eigenmode is not yet fully implemented |
Source code in src/gsim/palace/eigenmode.py
set_eigenmode
¶
set_eigenmode(
*, num_modes: int = 10, target: float | None = None, tolerance: float = 1e-06
) -> None
Configure eigenmode simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_modes
|
int
|
Number of modes to find |
10
|
target
|
float | None
|
Target frequency in Hz for mode search |
None
|
tolerance
|
float
|
Eigenvalue solver tolerance |
1e-06
|
Example
sim.set_eigenmode(num_modes=10, target=50e9)
Source code in src/gsim/palace/eigenmode.py
set_geometry
¶
Set the gdsfactory component for simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
Component
|
gdsfactory Component to simulate |
required |
Example
sim.set_geometry(my_component)
Source code in src/gsim/palace/base.py
set_material
¶
set_material(
name: str,
*,
material_type: Literal["conductor", "dielectric", "semiconductor"] | None = None,
conductivity: float | None = None,
permittivity: float | None = None,
loss_tangent: float | None = None,
) -> None
Override or add material properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Material name |
required |
material_type
|
Literal['conductor', 'dielectric', 'semiconductor'] | None
|
Material type (conductor, dielectric, semiconductor) |
None
|
conductivity
|
float | None
|
Conductivity in S/m (for conductors) |
None
|
permittivity
|
float | None
|
Relative permittivity (for dielectrics) |
None
|
loss_tangent
|
float | None
|
Dielectric loss tangent |
None
|
Example
sim.set_material( ... "aluminum", material_type="conductor", conductivity=3.8e7 ... ) sim.set_material("sio2", material_type="dielectric", permittivity=3.9)
Source code in src/gsim/palace/base.py
set_numerical
¶
set_numerical(
*,
order: int = 1,
tolerance: float = 1e-06,
max_iterations: int = 400,
solver_type: Literal["Default", "SuperLU", "STRUMPACK", "MUMPS"] = "Default",
preconditioner: Literal["Default", "AMS", "BoomerAMG"] = "Default",
device: Literal["CPU", "GPU"] = "CPU",
num_processors: int | None = None,
) -> None
Configure numerical solver parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
Finite element order (1-4) |
1
|
tolerance
|
float
|
Linear solver tolerance |
1e-06
|
max_iterations
|
int
|
Maximum solver iterations |
400
|
solver_type
|
Literal['Default', 'SuperLU', 'STRUMPACK', 'MUMPS']
|
Linear solver type |
'Default'
|
preconditioner
|
Literal['Default', 'AMS', 'BoomerAMG']
|
Preconditioner type |
'Default'
|
device
|
Literal['CPU', 'GPU']
|
Compute device (CPU or GPU) |
'CPU'
|
num_processors
|
int | None
|
Number of processors (None = auto) |
None
|
Example
sim.set_numerical(order=3, tolerance=1e-8)
Source code in src/gsim/palace/base.py
set_output_dir
¶
Set the output directory for mesh and config files.
Parameters:
Example
sim.set_output_dir("./palace-sim")
Source code in src/gsim/palace/base.py
set_stack
¶
set_stack(
stack: LayerStack | None = None,
*,
yaml_path: str | Path | None = None,
air_above: float = 200.0,
substrate_thickness: float = 2.0,
include_substrate: bool = False,
**kwargs,
) -> None
Configure the layer stack.
Three modes of use:
-
Active PDK (default — auto-detects IHP, QPDK, etc.)::
sim.set_stack(air_above=300.0, substrate_thickness=2.0)
-
YAML file::
sim.set_stack(yaml_path="custom_stack.yaml")
-
Custom stack (advanced — pass a hand-built LayerStack)::
sim.set_stack(my_layer_stack)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stack
|
LayerStack | None
|
Custom gsim LayerStack (bypasses PDK extraction). |
None
|
yaml_path
|
str | Path | None
|
Path to custom YAML stack file. |
None
|
air_above
|
float
|
Air box height above top metal in um. |
200.0
|
substrate_thickness
|
float
|
Thickness below z=0 in um. |
2.0
|
include_substrate
|
bool
|
Include lossy silicon substrate. |
False
|
**kwargs
|
Additional args passed to extract_layer_stack. |
{}
|
Example
sim.set_stack(air_above=300.0, substrate_thickness=2.0)
Source code in src/gsim/palace/base.py
show_stack
¶
Print the layer stack table.
Example
sim.show_stack()
Source code in src/gsim/palace/base.py
validate_config
¶
validate_config() -> ValidationResult
Validate the simulation configuration.
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with validation status and messages |
Source code in src/gsim/palace/eigenmode.py
validate_mesh
¶
validate_mesh() -> ValidationResult
Validate the generated mesh and config before cloud submission.
Checks that physical groups are correctly assigned after meshing: conductor surfaces, dielectric volumes, ports, and absorbing boundary. Also verifies the generated config.json structure.
Call after mesh() and before run().
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with validation status and messages |
Example
sim.mesh(preset="coarse") result = sim.validate_mesh() print(result)
Source code in src/gsim/palace/base.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
ElectrostaticConfig
¶
Bases: BaseModel
Configuration for electrostatic (capacitance matrix) simulation.
Attributes:
| Name | Type | Description |
|---|---|---|
save_fields |
int
|
Number of field solutions to save |
Methods:
| Name | Description |
|---|---|
to_palace_config |
Convert to Palace JSON config format. |
ElectrostaticSim
¶
Bases: PalaceSimMixin, BaseModel
Electrostatic simulation for capacitance matrix extraction.
This class configures and runs electrostatic simulations to extract the capacitance matrix between conductor terminals. Unlike driven and eigenmode simulations, this does not use ports.
Example
from gsim.palace import ElectrostaticSim
sim = ElectrostaticSim() sim.set_geometry(component) sim.set_stack(air_above=300.0) sim.add_terminal("T1", layer="topmetal2") sim.add_terminal("T2", layer="topmetal2") sim.set_electrostatic() sim.set_output_dir("./sim") sim.mesh(preset="default") results = sim.run()
Attributes:
| Name | Type | Description |
|---|---|---|
geometry |
Geometry | None
|
Wrapped gdsfactory Component (from common) |
stack |
LayerStack | None
|
Layer stack configuration (from common) |
terminals |
list[TerminalConfig]
|
List of terminal configurations |
electrostatic |
ElectrostaticConfig
|
Electrostatic simulation configuration |
materials |
dict[str, MaterialConfig]
|
Material property overrides |
numerical |
NumericalConfig
|
Numerical solver configuration |
Methods:
| Name | Description |
|---|---|
add_terminal |
Add a terminal for capacitance extraction. |
mesh |
Generate the mesh for Palace simulation. |
plot_mesh |
Plot the mesh using PyVista. |
plot_stack |
Plot the layer stack visualization. |
preview |
Preview the mesh without running simulation. |
run |
Run electrostatic simulation on GDSFactory+ cloud. |
set_electrostatic |
Configure electrostatic simulation. |
set_geometry |
Set the gdsfactory component for simulation. |
set_material |
Override or add material properties. |
set_numerical |
Configure numerical solver parameters. |
set_output_dir |
Set the output directory for mesh and config files. |
set_stack |
Configure the layer stack. |
show_stack |
Print the layer stack table. |
validate_config |
Validate the simulation configuration. |
validate_mesh |
Validate the generated mesh and config before cloud submission. |
component
property
¶
Get the current component (for backward compatibility).
add_terminal
¶
Add a terminal for capacitance extraction.
Terminals define conductor surfaces for capacitance matrix extraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Terminal name |
required |
layer
|
str
|
Target conductor layer |
required |
Example
sim.add_terminal("T1", layer="topmetal2") sim.add_terminal("T2", layer="topmetal2")
Source code in src/gsim/palace/electrostatic.py
mesh
¶
mesh(
*,
preset: Literal["coarse", "default", "graded", "fine"] | None = None,
refined_mesh_size: float | None = None,
max_mesh_size: float | None = None,
margin: float | None = None,
airbox_margin: float | None = None,
fmax: float | None = None,
planar_conductors: bool | None = None,
show_gui: bool = False,
model_name: str = "palace",
verbose: bool = True,
) -> SimulationResult
Generate the mesh for Palace simulation.
Requires set_output_dir() to be called first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset
|
Literal['coarse', 'default', 'graded', 'fine'] | None
|
Mesh quality preset ("coarse", "default", "graded", "fine") |
None
|
refined_mesh_size
|
float | None
|
Mesh size near conductors (um), overrides preset |
None
|
max_mesh_size
|
float | None
|
Max mesh size in air/dielectric (um), overrides preset |
None
|
margin
|
float | None
|
XY margin around design (um), overrides preset |
None
|
airbox_margin
|
float | None
|
Extra airbox around stack (um); 0 = disabled |
None
|
fmax
|
float | None
|
Max frequency for mesh sizing (Hz) - less relevant for electrostatic |
None
|
planar_conductors
|
bool | None
|
Treat conductors as 2D PEC surfaces |
None
|
show_gui
|
bool
|
Show gmsh GUI during meshing |
False
|
model_name
|
str
|
Base name for output files |
'palace'
|
verbose
|
bool
|
Print progress messages |
True
|
Returns:
| Type | Description |
|---|---|
SimulationResult
|
SimulationResult with mesh path |
Raises:
| Type | Description |
|---|---|
ValueError
|
If output_dir not set or configuration is invalid |
Example
sim.set_output_dir("./sim") result = sim.mesh(preset="fine", planar_conductors=True) print(f"Mesh saved to: {result.mesh_path}")
Source code in src/gsim/palace/electrostatic.py
plot_mesh
¶
plot_mesh(
output: str | Path | None = None,
show_groups: list[str] | None = None,
interactive: bool = True,
style: Literal["wireframe", "solid"] = "wireframe",
transparent_groups: list[str] | None = None,
) -> None
Plot the mesh using PyVista.
Requires mesh() to be called first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str | Path | None
|
Output PNG path (only used if interactive=False) |
None
|
show_groups
|
list[str] | None
|
List of group name patterns to show (None = all). Example: ["metal", "P"] to show metal layers and ports. |
None
|
interactive
|
bool
|
If True, open interactive 3D viewer. If False, save static PNG to output path. |
True
|
style
|
Literal['wireframe', 'solid']
|
|
'wireframe'
|
transparent_groups
|
list[str] | None
|
Group names rendered at low opacity in solid mode. Ignored in wireframe mode. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If output_dir not set or mesh file doesn't exist |
Example
sim.mesh(preset="default") sim.plot_mesh(show_groups=["metal", "P"]) sim.plot_mesh(style="solid", transparent_groups=["Absorbing_boundary"])
Source code in src/gsim/palace/base.py
plot_stack
¶
Plot the layer stack visualization.
Example
sim.plot_stack()
Source code in src/gsim/palace/base.py
preview
¶
preview(
*,
preset: Literal["coarse", "default", "graded", "fine"] | None = None,
refined_mesh_size: float | None = None,
max_mesh_size: float | None = None,
margin: float | None = None,
airbox_margin: float | None = None,
fmax: float | None = None,
planar_conductors: bool | None = None,
show_gui: bool = True,
) -> None
Preview the mesh without running simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset
|
Literal['coarse', 'default', 'graded', 'fine'] | None
|
Mesh quality preset ("coarse", "default", "graded", "fine") |
None
|
refined_mesh_size
|
float | None
|
Mesh size near conductors (um) |
None
|
max_mesh_size
|
float | None
|
Max mesh size in air/dielectric (um) |
None
|
margin
|
float | None
|
XY margin around design (um) |
None
|
airbox_margin
|
float | None
|
Extra airbox around stack (um); 0 = disabled |
None
|
fmax
|
float | None
|
Max frequency for mesh sizing (Hz) |
None
|
planar_conductors
|
bool | None
|
Treat conductors as 2D PEC surfaces |
None
|
show_gui
|
bool
|
Show gmsh GUI for interactive preview |
True
|
Example
sim.preview(preset="fine", planar_conductors=True, show_gui=True)
Source code in src/gsim/palace/electrostatic.py
run
¶
Run electrostatic simulation on GDSFactory+ cloud.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str | Path | None
|
Directory containing mesh files |
None
|
verbose
|
bool
|
Print progress messages |
True
|
Returns:
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Electrostatic is not yet fully implemented |
Source code in src/gsim/palace/electrostatic.py
set_electrostatic
¶
set_electrostatic(*, save_fields: int = 0) -> None
Configure electrostatic simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_fields
|
int
|
Number of field solutions to save |
0
|
Example
sim.set_electrostatic(save_fields=1)
Source code in src/gsim/palace/electrostatic.py
set_geometry
¶
Set the gdsfactory component for simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
Component
|
gdsfactory Component to simulate |
required |
Example
sim.set_geometry(my_component)
Source code in src/gsim/palace/base.py
set_material
¶
set_material(
name: str,
*,
material_type: Literal["conductor", "dielectric", "semiconductor"] | None = None,
conductivity: float | None = None,
permittivity: float | None = None,
loss_tangent: float | None = None,
) -> None
Override or add material properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Material name |
required |
material_type
|
Literal['conductor', 'dielectric', 'semiconductor'] | None
|
Material type (conductor, dielectric, semiconductor) |
None
|
conductivity
|
float | None
|
Conductivity in S/m (for conductors) |
None
|
permittivity
|
float | None
|
Relative permittivity (for dielectrics) |
None
|
loss_tangent
|
float | None
|
Dielectric loss tangent |
None
|
Example
sim.set_material( ... "aluminum", material_type="conductor", conductivity=3.8e7 ... ) sim.set_material("sio2", material_type="dielectric", permittivity=3.9)
Source code in src/gsim/palace/base.py
set_numerical
¶
set_numerical(
*,
order: int = 1,
tolerance: float = 1e-06,
max_iterations: int = 400,
solver_type: Literal["Default", "SuperLU", "STRUMPACK", "MUMPS"] = "Default",
preconditioner: Literal["Default", "AMS", "BoomerAMG"] = "Default",
device: Literal["CPU", "GPU"] = "CPU",
num_processors: int | None = None,
) -> None
Configure numerical solver parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
Finite element order (1-4) |
1
|
tolerance
|
float
|
Linear solver tolerance |
1e-06
|
max_iterations
|
int
|
Maximum solver iterations |
400
|
solver_type
|
Literal['Default', 'SuperLU', 'STRUMPACK', 'MUMPS']
|
Linear solver type |
'Default'
|
preconditioner
|
Literal['Default', 'AMS', 'BoomerAMG']
|
Preconditioner type |
'Default'
|
device
|
Literal['CPU', 'GPU']
|
Compute device (CPU or GPU) |
'CPU'
|
num_processors
|
int | None
|
Number of processors (None = auto) |
None
|
Example
sim.set_numerical(order=3, tolerance=1e-8)
Source code in src/gsim/palace/base.py
set_output_dir
¶
Set the output directory for mesh and config files.
Parameters:
Example
sim.set_output_dir("./palace-sim")
Source code in src/gsim/palace/base.py
set_stack
¶
set_stack(
stack: LayerStack | None = None,
*,
yaml_path: str | Path | None = None,
air_above: float = 200.0,
substrate_thickness: float = 2.0,
include_substrate: bool = False,
**kwargs,
) -> None
Configure the layer stack.
Three modes of use:
-
Active PDK (default — auto-detects IHP, QPDK, etc.)::
sim.set_stack(air_above=300.0, substrate_thickness=2.0)
-
YAML file::
sim.set_stack(yaml_path="custom_stack.yaml")
-
Custom stack (advanced — pass a hand-built LayerStack)::
sim.set_stack(my_layer_stack)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stack
|
LayerStack | None
|
Custom gsim LayerStack (bypasses PDK extraction). |
None
|
yaml_path
|
str | Path | None
|
Path to custom YAML stack file. |
None
|
air_above
|
float
|
Air box height above top metal in um. |
200.0
|
substrate_thickness
|
float
|
Thickness below z=0 in um. |
2.0
|
include_substrate
|
bool
|
Include lossy silicon substrate. |
False
|
**kwargs
|
Additional args passed to extract_layer_stack. |
{}
|
Example
sim.set_stack(air_above=300.0, substrate_thickness=2.0)
Source code in src/gsim/palace/base.py
show_stack
¶
Print the layer stack table.
Example
sim.show_stack()
Source code in src/gsim/palace/base.py
validate_config
¶
validate_config() -> ValidationResult
Validate the simulation configuration.
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with validation status and messages |
Source code in src/gsim/palace/electrostatic.py
validate_mesh
¶
validate_mesh() -> ValidationResult
Validate the generated mesh and config before cloud submission.
Checks that physical groups are correctly assigned after meshing: conductor surfaces, dielectric volumes, ports, and absorbing boundary. Also verifies the generated config.json structure.
Call after mesh() and before run().
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with validation status and messages |
Example
sim.mesh(preset="coarse") result = sim.validate_mesh() print(result)
Source code in src/gsim/palace/base.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
Geometry
¶
Bases: BaseModel
Shared geometry wrapper for gdsfactory Component.
This class wraps a gdsfactory Component and provides computed properties that are useful for simulation setup (bounds, ports, etc.).
Attributes:
| Name | Type | Description |
|---|---|---|
component |
Any
|
The wrapped gdsfactory Component |
Example
from gdsfactory.components import straight c = straight(length=100) geom = Geometry(component=c) print(geom.bounds) (0.0, -0.25, 100.0, 0.25)
Methods:
| Name | Description |
|---|---|
get_port |
Get a port by name. |
GeometryConfig
¶
Bases: BaseModel
Configuration for geometry settings.
This model stores metadata about the component being simulated. The actual Component object is stored separately on simulation classes.
Attributes:
| Name | Type | Description |
|---|---|---|
component_name |
str | None
|
Name of the component being simulated |
bounds |
tuple[float, float, float, float] | None
|
Bounding box as (xmin, ymin, xmax, ymax) |
GroundPlane
dataclass
¶
Ground plane configuration for microstrip structures.
Layer
¶
Bases: BaseModel
Layer information for Palace simulation.
Methods:
| Name | Description |
|---|---|
get_mesh_size |
Get mesh size in um for this layer. |
to_dict |
Convert to dictionary for YAML output. |
get_mesh_size
¶
Get mesh size in um for this layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_size
|
float
|
Base mesh size for "medium" resolution |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
Mesh size in um |
Source code in src/gsim/common/stack/extractor.py
to_dict
¶
to_dict() -> dict
Convert to dictionary for YAML output.
Source code in src/gsim/common/stack/extractor.py
LayerStack
¶
Bases: BaseModel
Complete layer stack for Palace simulation.
Methods:
| Name | Description |
|---|---|
from_layer_list |
Build a LayerStack from a list of Layer objects. |
get_conductor_layers |
Get all conductor layers. |
get_via_layers |
Get all via layers. |
get_z_range |
Get the full z-range of the stack (substrate bottom to air top). |
to_dict |
Convert to dictionary for YAML output. |
to_yaml |
Convert to YAML string and optionally write to file. |
validate_stack |
Validate the layer stack for simulation readiness. |
from_layer_list
classmethod
¶
from_layer_list(layerList: list[Layer]) -> LayerStack
Build a LayerStack from a list of Layer objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layerList
|
list[Layer]
|
List of Layer definitions to include in the stack. |
required |
Returns:
| Type | Description |
|---|---|
LayerStack
|
A LayerStack with layers/materials/dielectrics assembled from |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/gsim/common/stack/extractor.py
get_conductor_layers
¶
get_via_layers
¶
get_z_range
¶
Get the full z-range of the stack (substrate bottom to air top).
Source code in src/gsim/common/stack/extractor.py
to_dict
¶
to_dict() -> dict
Convert to dictionary for YAML output.
Source code in src/gsim/common/stack/extractor.py
to_yaml
¶
Convert to YAML string and optionally write to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | None
|
Optional path to write YAML file |
None
|
Returns:
| Type | Description |
|---|---|
str
|
YAML string |
Source code in src/gsim/common/stack/extractor.py
validate_stack
¶
validate_stack(tolerance: float = 0.001) -> ValidationResult
Validate the layer stack for simulation readiness.
Checks: 1. Z-axis continuity: no gaps in dielectric regions 2. Material coverage: all materials have properties defined 3. Layer coverage: all conductor/via layers are within dielectric envelope 4. No negative thicknesses
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Tolerance for z-coordinate comparisons (um) |
0.001
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with valid flag, errors, and warnings |
Source code in src/gsim/common/stack/extractor.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
MagnetostaticConfig
¶
Bases: BaseModel
Configuration for magnetostatic (inductance matrix) simulation.
Attributes:
| Name | Type | Description |
|---|---|---|
save_fields |
int
|
Number of field solutions to save |
Methods:
| Name | Description |
|---|---|
to_palace_config |
Convert to Palace JSON config format. |
MaterialConfig
¶
Bases: BaseModel
EM properties for a material.
Used for material property overrides in simulation classes.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['conductor', 'dielectric', 'semiconductor']
|
Material type (conductor, dielectric, or semiconductor) |
conductivity |
float | None
|
Conductivity in S/m (for conductors) |
permittivity |
float | None
|
Relative permittivity (for dielectrics) |
loss_tangent |
float | None
|
Dielectric loss tangent |
Methods:
| Name | Description |
|---|---|
conductor |
Create a conductor material. |
dielectric |
Create a dielectric material. |
to_dict |
Convert to dictionary for YAML output. |
conductor
classmethod
¶
dielectric
classmethod
¶
Create a dielectric material.
to_dict
¶
Convert to dictionary for YAML output.
Source code in src/gsim/palace/models/stack.py
MaterialProperties
¶
Bases: BaseModel
EM properties for a material.
Methods:
| Name | Description |
|---|---|
conductor |
Create a conductor material. |
dielectric |
Create a dielectric material. |
optical |
Create a material with optical properties for photonic simulation. |
to_dict |
Convert to dictionary for YAML output. |
conductor
classmethod
¶
conductor(conductivity: float = 58000000.0) -> MaterialProperties
dielectric
classmethod
¶
dielectric(permittivity: float, loss_tangent: float = 0.0) -> MaterialProperties
Create a dielectric material.
Source code in src/gsim/common/stack/materials.py
optical
classmethod
¶
optical(refractive_index: float, extinction_coeff: float = 0.0) -> MaterialProperties
Create a material with optical properties for photonic simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
refractive_index
|
float
|
Refractive index (n) |
required |
extinction_coeff
|
float
|
Extinction coefficient (k), default 0 |
0.0
|
Source code in src/gsim/common/stack/materials.py
to_dict
¶
Convert to dictionary for YAML output.
Source code in src/gsim/common/stack/materials.py
MeshConfig
dataclass
¶
MeshConfig(
refined_mesh_size: float = 5.0,
max_mesh_size: float = 300.0,
cells_per_wavelength: int = 10,
margin: float = 50.0,
airbox_margin: float = 0.0,
ground_plane: GroundPlane | None = None,
fmax: float = 100000000000.0,
boundary_conditions: list[str] | None = None,
planar_conductors: bool = False,
refine_from_curves: bool = False,
show_gui: bool = False,
preview_only: bool = False,
)
Configuration for mesh generation.
Use class methods for quick presets
MeshConfig.coarse() - Fast iteration (~2.5 elem/λ) MeshConfig.default() - Balanced (COMSOL default, ~5 elem/λ) MeshConfig.graded() - Default sizes + refined near conductor edges MeshConfig.fine() - High accuracy (~10 elem/λ)
Or customize directly
MeshConfig(refined_mesh_size=3.0, max_mesh_size=200.0)
Methods:
| Name | Description |
|---|---|
coarse |
Fast mesh for quick iteration (~2.5 elements per wavelength). |
default |
Balanced mesh matching COMSOL defaults (~5 elements per wavelength). |
fine |
High accuracy mesh (~10 elements per wavelength). |
graded |
Default mesh sizes with refinement near conductor edges. |
coarse
classmethod
¶
coarse(**kwargs) -> MeshConfig
Fast mesh for quick iteration (~2.5 elements per wavelength).
Source code in src/gsim/palace/mesh/pipeline.py
default
classmethod
¶
default(**kwargs) -> MeshConfig
Balanced mesh matching COMSOL defaults (~5 elements per wavelength).
Source code in src/gsim/palace/mesh/pipeline.py
fine
classmethod
¶
fine(**kwargs) -> MeshConfig
High accuracy mesh (~10 elements per wavelength).
Source code in src/gsim/palace/mesh/pipeline.py
graded
classmethod
¶
graded(**kwargs) -> MeshConfig
Default mesh sizes with refinement near conductor edges.
Source code in src/gsim/palace/mesh/pipeline.py
MeshPreset
¶
Bases: Enum
Mesh quality presets based on COMSOL guidelines.
COMSOL uses 2nd order elements with ~5 elements per wavelength as default. Wavelength in dielectric: λ = c / (f * √εᵣ) At 100 GHz in SiO2 (εᵣ≈4): λ ≈ 1500 µm
MeshResult
dataclass
¶
MeshResult(
mesh_path: Path,
config_path: Path | None = None,
conductor_groups: dict = dict(),
dielectric_groups: dict = dict(),
port_groups: dict = dict(),
boundary_groups: dict = dict(),
port_info: list = list(),
mesh_stats: dict = dict(),
groups: dict = dict(),
output_dir: Path | None = None,
model_name: str = "palace",
fmax: float = 100000000000.0,
)
Result from mesh generation.
NumericalConfig
¶
Bases: BaseModel
Numerical solver configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
order |
int
|
Finite element order (1-4) |
tolerance |
float
|
Linear solver tolerance |
max_iterations |
int
|
Maximum solver iterations |
solver_type |
Literal['Default', 'SuperLU', 'STRUMPACK', 'MUMPS']
|
Linear solver type |
preconditioner |
Literal['Default', 'AMS', 'BoomerAMG']
|
Preconditioner type |
device |
Literal['CPU', 'GPU']
|
Compute device (CPU or GPU) |
num_processors |
int | None
|
Number of processors (None = auto) |
Methods:
| Name | Description |
|---|---|
to_palace_config |
Convert to Palace JSON config format. |
to_palace_config
¶
to_palace_config() -> dict
Convert to Palace JSON config format.
Source code in src/gsim/palace/models/numerical.py
PalacePort
dataclass
¶
PalacePort(
name: str,
port_type: PortType = LUMPED,
geometry: PortGeometry = INPLANE,
center: tuple[float, float] = (0.0, 0.0),
width: float = 0.0,
orientation: float = 0.0,
zmin: float = 0.0,
zmax: float = 0.0,
layer: str | None = None,
from_layer: str | None = None,
to_layer: str | None = None,
length: float | None = None,
multi_element: bool = False,
centers: list[tuple[float, float]] | None = None,
directions: list[str] | None = None,
impedance: float = 50.0,
resistance: float | None = None,
inductance: float | None = None,
capacitance: float | None = None,
excited: bool = True,
)
PortConfig
¶
Bases: BaseModel
Configuration for a single-element lumped port.
Lumped ports can be inplane (horizontal, on single layer) or via (vertical, between two layers).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Port name (must match component port name) |
layer |
str | None
|
Target layer for inplane ports |
from_layer |
str | None
|
Bottom layer for via ports |
to_layer |
str | None
|
Top layer for via ports |
length |
float | None
|
Port extent along direction (um) |
impedance |
float
|
Port impedance (Ohms) |
excited |
bool
|
Whether this port is excited |
geometry |
Literal['inplane', 'via']
|
Port geometry type ("inplane" or "via") |
Methods:
| Name | Description |
|---|---|
validate_layer_config |
Validate layer configuration based on geometry type. |
validate_layer_config
¶
validate_layer_config() -> Self
Validate layer configuration based on geometry type.
Source code in src/gsim/palace/models/ports.py
SimulationResult
¶
Bases: BaseModel
Result from running a Palace simulation.
Attributes:
| Name | Type | Description |
|---|---|---|
mesh_path |
Path
|
Path to the generated mesh file |
output_dir |
Path
|
Output directory path |
config_path |
Path | None
|
Path to the Palace config file |
results |
dict[str, Path]
|
Dictionary mapping result filenames to paths |
conductor_groups |
dict
|
Physical group info for conductors |
dielectric_groups |
dict
|
Physical group info for dielectrics |
port_groups |
dict
|
Physical group info for ports |
boundary_groups |
dict
|
Physical group info for boundaries |
port_info |
list
|
Port metadata |
StackLayer
dataclass
¶
StackLayer(
name: str,
zmin: float,
zmax: float,
thickness: float,
material: str | None = None,
gds_layer: int | None = None,
layer_type: str = "conductor",
)
Parsed layer info for visualization.
TerminalConfig
¶
TransientConfig
¶
Bases: BaseModel
Configuration for transient (time-domain) simulation.
Attributes:
| Name | Type | Description |
|---|---|---|
max_time |
float
|
Maximum simulation time in ns |
excitation |
Literal['sinusoidal', 'gaussian', 'ramp', 'smoothstep']
|
Excitation waveform type |
excitation_freq |
float | None
|
Excitation frequency in Hz (for sinusoidal) |
excitation_width |
float | None
|
Pulse width in ns (for gaussian) |
time_step |
float | None
|
Time step in ns (None = adaptive) |
Methods:
| Name | Description |
|---|---|
to_palace_config |
Convert to Palace JSON config format. |
to_palace_config
¶
to_palace_config() -> dict
Convert to Palace JSON config format.
Source code in src/gsim/palace/models/problems.py
ValidationResult
¶
WavePortConfig
¶
Bases: BaseModel
Configuration for a wave port (domain boundary with mode solving).
Wave ports are used for domain-boundary ports where mode solving is needed. This is an alternative to lumped ports for more accurate S-parameter extraction.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Port name (must match component port name) |
layer |
str
|
Target conductor layer |
mode |
int
|
Mode number to excite |
excited |
bool
|
Whether this port is excited |
offset |
float
|
De-embedding distance in um |
Functions¶
configure_cpw_port
¶
configure_cpw_port(
port,
layer: str,
s_width: float,
gap_width: float,
length: float,
impedance: float = 50.0,
excited: bool = True,
offset: float = 0.0,
)
Configure a gdsfactory port as a CPW (multi-element) lumped port.
In CPW (Ground-Signal-Ground), E-fields are opposite in the two gaps. The port should be placed at the signal center. The upper and lower gap centers are computed from the signal width and gap width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
gdsfactory Port at the signal center |
required | |
layer
|
str
|
Target conductor layer name (e.g., 'topmetal2') |
required |
s_width
|
float
|
Signal conductor width in um |
required |
gap_width
|
float
|
Gap width between signal and ground in um |
required |
length
|
float
|
Port extent along direction (um) |
required |
impedance
|
float
|
Port impedance in Ohms (default: 50) |
50.0
|
excited
|
bool
|
Whether port is excited (default: True) |
True
|
offset
|
float
|
Shift port inward along the waveguide (um). Positive moves away from the boundary, into the conductor. |
0.0
|
Examples:
Source code in src/gsim/palace/ports/config.py
configure_inplane_port
¶
configure_inplane_port(
ports, layer: str, length: float, impedance: float = 50.0, excited: bool = True
)
Configure gdsfactory port(s) as inplane (lumped) ports for Palace simulation.
Inplane ports are horizontal ports on a single metal layer, used for CPW gaps or similar structures where excitation occurs in the XY plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ports
|
Single gdsfactory Port or iterable of Ports (e.g., c.ports) |
required | |
layer
|
str
|
Target conductor layer name (e.g., 'topmetal2') |
required |
length
|
float
|
Port extent along direction in um (perpendicular to port width) |
required |
impedance
|
float
|
Port impedance in Ohms (default: 50) |
50.0
|
excited
|
bool
|
Whether port is excited vs just measured (default: True) |
True
|
Examples:
configure_inplane_port(c.ports["o1"], layer="topmetal2", length=5.0)
configure_inplane_port(c.ports, layer="topmetal2", length=5.0) # all ports
Source code in src/gsim/palace/ports/config.py
configure_via_port
¶
configure_via_port(
ports, from_layer: str, to_layer: str, impedance: float = 50.0, excited: bool = True
)
Configure gdsfactory port(s) as via (vertical) lumped ports.
Via ports are vertical lumped ports between two metal layers, used for microstrip feed structures where excitation occurs in the Z direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ports
|
Single gdsfactory Port or iterable of Ports (e.g., c.ports) |
required | |
from_layer
|
str
|
Bottom conductor layer name (e.g., 'metal1') |
required |
to_layer
|
str
|
Top conductor layer name (e.g., 'topmetal2') |
required |
impedance
|
float
|
Port impedance in Ohms (default: 50) |
50.0
|
excited
|
bool
|
Whether port is excited vs just measured (default: True) |
True
|
Examples:
configure_via_port(c.ports["o1"], from_layer="metal1", to_layer="topmetal2")
configure_via_port(
c.ports, from_layer="metal1", to_layer="topmetal2"
) # all ports
Source code in src/gsim/palace/ports/config.py
extract_from_pdk
¶
extract_from_pdk(pdk_module, output_path: Path | None = None, **kwargs) -> LayerStack
Extract layer stack from a PDK module or PDK object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pdk_module
|
PDK module (e.g., ihp, sky130) or gdsfactory Pdk object |
required | |
output_path
|
Path | None
|
Optional path to write YAML file |
None
|
**kwargs
|
Additional arguments passed to extract_layer_stack |
{}
|
Returns:
| Type | Description |
|---|---|
LayerStack
|
LayerStack object for Palace simulation |
Source code in src/gsim/common/stack/extractor.py
extract_layer_stack
¶
extract_layer_stack(
gf_layer_stack: LayerStack,
pdk_name: str = "unknown",
substrate_thickness: float = 2.0,
air_above: float = 200.0,
boundary_margin: float = 30.0,
include_substrate: bool = False,
) -> LayerStack
Extract layer stack from a gdsfactory LayerStack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gf_layer_stack
|
LayerStack
|
gdsfactory LayerStack object |
required |
pdk_name
|
str
|
Name of the PDK (for documentation) |
'unknown'
|
substrate_thickness
|
float
|
Thickness of substrate in um (default: 2.0) |
2.0
|
air_above
|
float
|
Height of air box above top metal in um (default: 200) |
200.0
|
boundary_margin
|
float
|
Lateral margin from GDS bbox in um (default: 30) |
30.0
|
include_substrate
|
bool
|
Whether to include lossy substrate (default: False) |
False
|
Returns:
| Type | Description |
|---|---|
LayerStack
|
LayerStack object for Palace simulation |
Source code in src/gsim/common/stack/extractor.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
extract_ports
¶
extract_ports(component, stack: LayerStack) -> list[PalacePort]
Extract Palace ports from a gdsfactory component.
Handles all port types: inplane, via, and CPW (multi-element).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
gdsfactory Component with configured ports |
required | |
stack
|
LayerStack
|
LayerStack from stack module |
required |
Returns:
| Type | Description |
|---|---|
list[PalacePort]
|
List of PalacePort objects ready for simulation |
Source code in src/gsim/palace/ports/config.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
generate_mesh
¶
generate_mesh(
component,
stack: LayerStack,
ports: list[PalacePort],
output_dir: str | Path,
config: MeshConfig | None = None,
model_name: str = "palace",
driven_config: DrivenConfig | None = None,
write_config: bool = True,
) -> MeshResult
Generate mesh for Palace EM simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
gdsfactory Component |
required | |
stack
|
LayerStack
|
LayerStack from palace-api |
required |
ports
|
list[PalacePort]
|
List of PalacePort objects (single and multi-element) |
required |
output_dir
|
str | Path
|
Directory for output files |
required |
config
|
MeshConfig | None
|
MeshConfig with mesh parameters |
None
|
model_name
|
str
|
Base name for output files (default: "mesh" -> mesh.msh) |
'palace'
|
driven_config
|
DrivenConfig | None
|
Optional DrivenConfig for frequency sweep settings |
None
|
write_config
|
bool
|
Whether to write config.json (default True) |
True
|
Returns:
| Type | Description |
|---|---|
MeshResult
|
MeshResult with mesh path and metadata |
Source code in src/gsim/palace/mesh/pipeline.py
get_material_properties
¶
get_material_properties(material_name: str) -> MaterialProperties | None
Look up material properties by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
material_name
|
str
|
Material name from PDK (e.g., "aluminum", "tungsten") |
required |
Returns:
| Type | Description |
|---|---|
MaterialProperties | None
|
MaterialProperties if found, None otherwise |
Source code in src/gsim/common/stack/materials.py
get_stack
¶
get_stack(yaml_path: str | Path | None = None, **kwargs) -> LayerStack
Get layer stack from active PDK or YAML file.
Automatically detects the active PDK and builds the appropriate stack
by extracting layers from the PDK's LAYER_STACK via
:func:extract_from_pdk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml_path
|
str | Path | None
|
Path to custom YAML stack file. If None, uses active PDK. |
None
|
**kwargs
|
Additional args passed to the stack builder: - substrate_thickness: Thickness below z=0 in um (default: 2.0) - air_above: Air box height above top metal in um (default: 200) - include_substrate: Include lossy silicon substrate (default: False). When False, matches gds2palace "nosub" behavior for RF simulation. |
{}
|
Returns:
| Type | Description |
|---|---|
LayerStack
|
LayerStack object |
Examples:
From active PDK (after PDK.activate()) - no substrate (recommended for RF)¶
stack = get_stack()
With lossy substrate (for substrate coupling studies)¶
stack = get_stack(include_substrate=True)
From YAML file¶
stack = get_stack(yaml_path="custom_stack.yaml")
With custom settings¶
stack = get_stack(air_above=300, substrate_thickness=5.0)
Source code in src/gsim/common/stack/__init__.py
load_stack_yaml
¶
load_stack_yaml(yaml_path: str | Path) -> LayerStack
Load layer stack from YAML file.
Parameters:
Returns:
| Type | Description |
|---|---|
LayerStack
|
LayerStack object |
Source code in src/gsim/common/stack/__init__.py
material_is_conductor
¶
material_is_dielectric
¶
Check if a material is a dielectric.
parse_layer_stack
¶
parse_layer_stack(layer_stack: LayerStack) -> list[StackLayer]
Parse a gdsfactory LayerStack into a list of StackLayer objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_stack
|
LayerStack
|
gdsfactory LayerStack object |
required |
Returns:
| Type | Description |
|---|---|
list[StackLayer]
|
List of StackLayer objects sorted by zmin (ascending) |
Source code in src/gsim/common/stack/visualization.py
plot_mesh
¶
plot_mesh(
msh_path: str | Path,
output: str | Path | None = None,
show_groups: list[str] | None = None,
interactive: bool = True,
style: Literal["wireframe", "solid"] = "wireframe",
transparent_groups: list[str] | None = None,
) -> None
Plot a .msh mesh using PyVista.
Two rendering styles are available:
- wireframe (default) — edges only, one colour per group when show_groups is given; black otherwise.
- solid — coloured surfaces per physical group with a legend bar. Groups listed in transparent_groups are drawn with low opacity so the interior structure remains visible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msh_path
|
str | Path
|
Path to |
required |
output
|
str | Path | None
|
Output PNG path (only used when |
None
|
show_groups
|
list[str] | None
|
Group-name patterns to display ( |
None
|
interactive
|
bool
|
If |
True
|
style
|
Literal['wireframe', 'solid']
|
|
'wireframe'
|
transparent_groups
|
list[str] | None
|
Group names rendered at low opacity in solid mode. Ignored in wireframe mode. |
None
|
Example
pa.plot_mesh("./sim/palace.msh", show_groups=["metal", "P"]) pa.plot_mesh( ... "sim.msh", style="solid", transparent_groups=["Absorbing_boundary"] ... )
Source code in src/gsim/viz.py
plot_stack
¶
Create an interactive plotly visualization of the layer stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pdk
|
A PDK module with LAYER_STACK, or a LayerStack directly |
required | |
width
|
float
|
Figure width in pixels |
600
|
height
|
float
|
Figure height in pixels |
800
|
to_scale
|
bool
|
If True, show actual z dimensions. If False (default), use fixed height for all layers for better visibility. |
False
|
Returns:
| Type | Description |
|---|---|
|
plotly Figure object (displays automatically in notebooks) |
Examples:
Source code in src/gsim/common/stack/visualization.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
print_job_summary
¶
Print a formatted summary of a simulation job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job object from gdsfactoryplus |
required |
Source code in src/gsim/gcloud.py
print_stack
¶
print_stack(pdk) -> str
Print an ASCII diagram of the layer stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pdk
|
A PDK module with LAYER_STACK, or a LayerStack directly |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted string (also prints to stdout) |
Examples:
Source code in src/gsim/common/stack/visualization.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
print_stack_table
¶
print_stack_table(pdk) -> str
Print a table of layer information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pdk
|
A PDK module with LAYER_STACK, or a LayerStack directly |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted string (also prints to stdout) |
Examples:
Source code in src/gsim/common/stack/visualization.py
Data¶
MATERIALS_DB
module-attribute
¶
MATERIALS_DB: dict[str, MaterialProperties] = {
"aluminum": MaterialProperties(type="conductor", conductivity=37700000.0),
"copper": MaterialProperties(type="conductor", conductivity=58000000.0),
"tungsten": MaterialProperties(type="conductor", conductivity=18200000.0),
"gold": MaterialProperties(type="conductor", conductivity=41000000.0),
"TiN": MaterialProperties(type="conductor", conductivity=5000000.0),
"poly_si": MaterialProperties(type="conductor", conductivity=100000.0),
"SiO2": MaterialProperties(
type="dielectric", permittivity=4.1, loss_tangent=0.0, refractive_index=1.44
),
"passive": MaterialProperties(
type="dielectric", permittivity=6.6, loss_tangent=0.0
),
"Si3N4": MaterialProperties(
type="dielectric", permittivity=7.5, loss_tangent=0.001, refractive_index=2.0
),
"polyimide": MaterialProperties(
type="dielectric", permittivity=3.4, loss_tangent=0.002
),
"air": MaterialProperties(
type="dielectric", permittivity=1.0, loss_tangent=0.0, refractive_index=1.0
),
"vacuum": MaterialProperties(
type="dielectric", permittivity=1.0, loss_tangent=0.0, refractive_index=1.0
),
"silicon": MaterialProperties(
type="semiconductor", permittivity=11.9, conductivity=2.0, refractive_index=3.47
),
"si": MaterialProperties(
type="semiconductor", permittivity=11.9, conductivity=2.0, refractive_index=3.47
),
"sapphire": MaterialProperties(
type="dielectric",
permittivity=9.3,
loss_tangent=3e-05,
refractive_index=1.77,
permittivity_diagonal=[9.3, 9.3, 11.5],
permeability=[0.99999975, 0.99999975, 0.99999979],
loss_tangent_diagonal=[3e-05, 3e-05, 8.6e-05],
material_axes=[[0.8, 0.6, 0.0], [-0.6, 0.8, 0.0], [0.0, 0.0, 1.0]],
),
"quartz": MaterialProperties(type="dielectric", permittivity=4.5),
"tfln": MaterialProperties(type="dielectric", permittivity=44.0),
}
gsim.meep¶
Classes¶
BuildResult
dataclass
¶
Domain
¶
Bases: BaseModel
Computational domain sizing: PML + margins + symmetries.
DomainConfig
¶
Bases: BaseModel
Simulation domain sizing: margins around geometry + PML thickness.
Margins control how much material (from the layer stack) is kept around
the waveguide core. set_z_crop() uses margin_z_above /
margin_z_below to determine the crop window. Along XY the margin
is the gap between the geometry bounding-box and the PML inner edge.
Cell size formula
cell_x = bbox_width + 2(margin_xy + dpml) cell_y = bbox_height + 2(margin_xy + dpml) cell_z = z_extent + 2*dpml (z-margins baked into z_extent)
FDTD
¶
Bases: BaseModel
Solver numerics: resolution, stopping, subpixel, diagnostics.
Methods:
| Name | Description |
|---|---|
stop_after_sources |
Run for a fixed sim-time after sources turn off. |
stop_after_walltime |
Set a wall-clock time limit (safety net). |
stop_when_dft_decayed |
Stop when all DFT monitors converge. |
stop_when_energy_decayed |
Stop when total field energy in the cell decays (recommended). |
stop_when_fields_decayed |
Stop when a field component decays at a point (recommended). |
stop_after_sources
¶
stop_after_walltime
¶
Set a wall-clock time limit (safety net).
This is orthogonal to the sim-time stopping mode — it caps how long the FDTD run is allowed to take in real (wall) seconds. Combine with any other stopping method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
Maximum wall-clock seconds for the FDTD run. |
required |
Returns:
| Type | Description |
|---|---|
FDTD
|
self (for fluent chaining). |
Source code in src/gsim/meep/models/api.py
stop_when_dft_decayed
¶
Stop when all DFT monitors converge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tol
|
float
|
DFT convergence tolerance. |
0.001
|
min_time
|
float
|
Minimum absolute sim time before checking convergence. |
100.0
|
Returns:
| Type | Description |
|---|---|
FDTD
|
self (for fluent chaining). |
Source code in src/gsim/meep/models/api.py
stop_when_energy_decayed
¶
Stop when total field energy in the cell decays (recommended).
Monitors total electromagnetic energy and stops when it has decayed
by decay_by from its peak value. More robust than dft_decay
for devices where DFTs can falsely converge on near-zero fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Time window between energy checks (MEEP time units). |
50.0
|
decay_by
|
float
|
Fractional energy decay threshold (e.g. 0.05 = 5%). |
0.05
|
Returns:
| Type | Description |
|---|---|
FDTD
|
self (for fluent chaining). |
Source code in src/gsim/meep/models/api.py
stop_when_fields_decayed
¶
stop_when_fields_decayed(
dt: float = 50.0,
component: str = "Ey",
decay_by: float = 0.05,
monitor_port: str | None = None,
) -> FDTD
Stop when a field component decays at a point (recommended).
Matches the standard MEEP tutorial stopping condition. Monitors
|component|² at a point and stops when it decays by decay_by
from its peak value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Decay measurement time window. |
50.0
|
component
|
str
|
Field component name (e.g. "Ey", "Hz"). |
'Ey'
|
decay_by
|
float
|
Fractional decay threshold (e.g. 0.05 = 5%). |
0.05
|
monitor_port
|
str | None
|
Port to monitor (None = first non-source port). |
None
|
Returns:
| Type | Description |
|---|---|
FDTD
|
self (for fluent chaining). |
Source code in src/gsim/meep/models/api.py
Geometry
¶
Bases: BaseModel
Physical layout: component + layer stack + optional z-crop.
Material
¶
Bases: BaseModel
Optical material properties.
ModeSource
¶
Bases: BaseModel
Mode source excitation and spectral measurement window.
ResolutionConfig
¶
Bases: BaseModel
MEEP grid resolution configuration.
Methods:
| Name | Description |
|---|---|
coarse |
Coarse resolution (16 pixels/um) for quick tests. |
default |
Default resolution (32 pixels/um). |
fine |
Fine resolution (64 pixels/um) for production runs. |
coarse
classmethod
¶
coarse() -> ResolutionConfig
default
classmethod
¶
default() -> ResolutionConfig
SParameterResult
¶
Bases: BaseModel
S-parameter results from MEEP simulation.
Parses CSV output from the cloud runner and provides visualization via matplotlib.
Methods:
| Name | Description |
|---|---|
from_csv |
Parse S-parameter results from CSV file. |
from_directory |
Load from directory — handles preview-only with no CSV. |
plot |
Plot S-parameters vs wavelength. |
show_animation |
Display field animation MP4 in Jupyter. |
show_diagnostics |
Display diagnostic images in Jupyter. |
from_csv
classmethod
¶
from_csv(path: str | Path) -> SParameterResult
Parse S-parameter results from CSV file.
Expected CSV format
wavelength,S11_mag,S11_phase,S21_mag,S21_phase,... 1.5, 0.1, -30.0, 0.9, 45.0, ...
Automatically loads meep_debug.json from the same directory
if it exists, populating the debug_info field.
Parameters:
Returns:
| Type | Description |
|---|---|
SParameterResult
|
SParameterResult instance |
Source code in src/gsim/meep/models/results.py
from_directory
classmethod
¶
from_directory(directory: str | Path) -> SParameterResult
Load from directory — handles preview-only with no CSV.
If s_parameters.csv exists, delegates to from_csv().
Otherwise loads only debug info and diagnostic images (preview mode).
Parameters:
Returns:
| Type | Description |
|---|---|
SParameterResult
|
SParameterResult instance |
Source code in src/gsim/meep/models/results.py
plot
¶
Plot S-parameters vs wavelength.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
bool
|
If True, plot in dB scale |
True
|
**kwargs
|
Any
|
Passed to matplotlib plot() |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
matplotlib Figure |
Source code in src/gsim/meep/models/results.py
show_animation
¶
Display field animation MP4 in Jupyter.
Source code in src/gsim/meep/models/results.py
show_diagnostics
¶
Display diagnostic images in Jupyter.
Source code in src/gsim/meep/models/results.py
SimConfig
¶
Bases: BaseModel
Complete serializable simulation config written as JSON.
This is the top-level config that the cloud MEEP runner reads. The geometry is NOT included here — it's in the GDS file. The layer_stack tells the runner how to extrude each GDS layer.
Methods:
| Name | Description |
|---|---|
to_json |
Write config to JSON file. |
Simulation
¶
Bases: BaseModel
Declarative MEEP FDTD simulation container.
Assigns typed physics objects, then calls write_config() to
produce the JSON + GDS + runner consumed by the cloud engine.
Example::
from gsim import meep
sim = meep.Simulation()
sim.geometry.component = ybranch
sim.geometry.stack = stack
sim.materials = {"si": 3.47, "sio2": 1.44}
sim.source.port = "o1"
sim.monitors = ["o1", "o2"]
sim.solver.stopping = "dft_decay"
sim.solver.max_time = 200
result = sim.run() # creates sim-data-{job_name}/ in CWD
Methods:
| Name | Description |
|---|---|
build_config |
Build the complete simulation config (single source of truth). |
get_status |
Get the current status of this sim's cloud job. |
plot_2d |
Plot 2D cross-sections of the geometry. |
plot_3d |
Plot 3D visualization of the geometry. |
run |
Run MEEP simulation on the cloud. |
start |
Start cloud execution for this sim's uploaded job. |
upload |
Write config and upload to the cloud. Does NOT start execution. |
validate_config |
Validate the simulation configuration. |
wait_for_results |
Wait for this sim's cloud job, download and parse results. |
write_config |
Serialize simulation config to output directory. |
build_config
¶
build_config() -> BuildResult
Build the complete simulation config (single source of truth).
All computation — validation, stack resolution, z-crop, port
extension, material resolution, MPI estimation — happens here.
Both :meth:write_config and the viz methods consume this output.
Returns:
| Type | Description |
|---|---|
BuildResult
|
BuildResult with SimConfig, extended component, and original. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If config is invalid. |
Source code in src/gsim/meep/simulation.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
get_status
¶
get_status() -> str
Get the current status of this sim's cloud job.
Returns:
Raises:
| Type | Description |
|---|---|
ValueError
|
If no job has been submitted yet. |
Source code in src/gsim/meep/simulation.py
plot_2d
¶
Plot 2D cross-sections of the geometry.
Uses :meth:build_config so the plot shows exactly what meep
processes — including extended ports and PML boundaries.
Accepts the same keyword arguments as :func:gsim.meep.viz.plot_2d.
Source code in src/gsim/meep/simulation.py
plot_3d
¶
Plot 3D visualization of the geometry.
Uses :meth:build_config so the plot shows exactly what meep
processes — including extended ports.
Accepts the same keyword arguments as :func:gsim.meep.viz.plot_3d.
Source code in src/gsim/meep/simulation.py
run
¶
Run MEEP simulation on the cloud.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_dir
|
str | Path | None
|
Where to create the sim directory. Defaults to the current working directory. |
None
|
verbose
|
bool
|
Print progress info. |
True
|
wait
|
bool
|
If |
True
|
Returns:
Source code in src/gsim/meep/simulation.py
start
¶
start(*, verbose: bool = True) -> None
Start cloud execution for this sim's uploaded job.
Raises:
| Type | Description |
|---|---|
ValueError
|
If :meth: |
Source code in src/gsim/meep/simulation.py
upload
¶
Write config and upload to the cloud. Does NOT start execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Print progress messages. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str
|
|
|
or |
str
|
func: |
Source code in src/gsim/meep/simulation.py
validate_config
¶
validate_config() -> Any
Validate the simulation configuration.
Returns:
| Type | Description |
|---|---|
Any
|
ValidationResult with errors/warnings. |
Source code in src/gsim/meep/simulation.py
wait_for_results
¶
Wait for this sim's cloud job, download and parse results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Print progress messages. |
True
|
parent_dir
|
str | Path | None
|
Where to create the sim-data directory. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Parsed result (typically |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no job has been submitted yet. |
Source code in src/gsim/meep/simulation.py
write_config
¶
Serialize simulation config to output directory.
Thin wrapper around :meth:build_config — writes GDS, JSON, and
the runner script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str | Path
|
Directory to write layout.gds, sim_config.json, run_meep.py. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the output directory. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If config is invalid. |
Source code in src/gsim/meep/simulation.py
SourceConfig
¶
Bases: BaseModel
Source excitation configuration.
Controls the Gaussian source bandwidth and which port is excited.
When bandwidth is None (auto), compute_fwidth returns a
bandwidth ~3x wider than the monitor frequency span (matching
gplugins' dfcen=0.2 convention) so edge frequencies receive
adequate spectral power.
Methods:
| Name | Description |
|---|---|
compute_fwidth |
Compute Gaussian source fwidth in frequency units. |
compute_fwidth
¶
Compute Gaussian source fwidth in frequency units.
When auto (bandwidth=None), returns max(3 * monitor_df, 0.2 * fcen)
to ensure edge frequencies have enough spectral power.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fcen
|
float
|
Center frequency (1/um). |
required |
monitor_df
|
float
|
Monitor frequency span (1/um). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Source fwidth in frequency units (1/um). |
Source code in src/gsim/meep/models/config.py
Symmetry
¶
Bases: BaseModel
Mirror symmetry plane.
WavelengthConfig
¶
Bases: BaseModel
Wavelength and frequency settings for MEEP FDTD simulation.
MEEP uses normalized units where c = 1 and lengths are in um. Frequency f = 1/wavelength (in 1/um).
Attributes:
gsim.gcloud¶
Classes¶
RunResult
dataclass
¶
Functions¶
get_status
¶
print_job_summary
¶
Print a formatted summary of a simulation job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job object from gdsfactoryplus |
required |
Source code in src/gsim/gcloud.py
register_result_parser
¶
Register a result parser for a solver type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
str
|
Solver name (e.g. |
required |
parser
|
Callable[[RunResult], Any]
|
Callable that takes a :class: |
required |
Source code in src/gsim/gcloud.py
run_simulation
¶
run_simulation(
config_dir: str | Path,
job_type: Literal["palace", "meep"] = "palace",
verbose: bool = True,
on_started: Callable | None = None,
parent_dir: str | Path | None = None,
) -> RunResult
Run a simulation on GDSFactory+ cloud (blocking).
This function handles the complete workflow:
1. Uploads simulation files from config_dir
2. Starts the simulation job
3. Creates a structured directory sim-data-{job_name}/
with input/ (config files) and output/ (results) sub-dirs
4. Waits for completion
5. Downloads results into output/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
str | Path
|
Directory containing the simulation config files. |
required |
job_type
|
Literal['palace', 'meep']
|
Type of simulation (default: "palace"). |
'palace'
|
verbose
|
bool
|
Print progress messages (default True). |
True
|
on_started
|
Callable | None
|
Optional callback called with job object when simulation starts. |
None
|
parent_dir
|
str | Path | None
|
Where to create the sim directory. Defaults to the current working directory. |
None
|
Returns:
| Type | Description |
|---|---|
RunResult
|
RunResult with sim_dir, files dict, and job_name. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If simulation fails |
Example
result = gcloud.run_simulation("./sim", job_type="palace") Uploading simulation... done Job started: palace-abc123 Waiting for completion... done (2m 34s) Downloading results... done print(result.sim_dir) sim-data-palace-abc123/
Source code in src/gsim/gcloud.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
start
¶
Start cloud execution for a previously uploaded job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Job identifier returned by :func: |
required |
verbose
|
bool
|
Print progress messages. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The |
Source code in src/gsim/gcloud.py
upload
¶
Upload simulation files to the cloud. Does NOT start execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
str | Path
|
Directory containing simulation config files. |
required |
job_type
|
str
|
Simulation type (e.g. |
required |
verbose
|
bool
|
Print progress messages. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
|
str
|
func: |
Source code in src/gsim/gcloud.py
upload_simulation_dir
¶
Upload a simulation directory for cloud execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dir
|
str | Path
|
Directory containing simulation files |
required |
job_type
|
str
|
Simulation type (e.g., "palace") |
required |
Returns:
| Type | Description |
|---|---|
|
PreJob object from gdsfactoryplus |
Source code in src/gsim/gcloud.py
wait_for_results
¶
wait_for_results(
*job_ids: str,
verbose: bool = True,
parent_dir: str | Path | None = None,
poll_interval: float = 5.0,
) -> Any
Wait for one or more jobs to finish, then download and parse results.
Accepts job IDs as positional args or a single list/tuple::
wait_for_results(id1, id2)
wait_for_results([id1, id2])
For a single job, returns the parsed result directly. For multiple jobs, returns a list of results (same order as input).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*job_ids
|
str
|
One or more job ID strings, or a single list/tuple of IDs. |
()
|
verbose
|
bool
|
Print progress messages. |
True
|
parent_dir
|
str | Path | None
|
Where to create sim-data directories (default: cwd). |
None
|
poll_interval
|
float
|
Seconds between status polls (default 5.0). |
5.0
|
Returns:
| Type | Description |
|---|---|
Any
|
Parsed result (single job) or list of parsed results (multiple jobs). |