gsim.palace
Types¶
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
GroundPlane
dataclass
¶
Ground plane configuration for microstrip structures.
Classes¶
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 |
|---|---|
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. |
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
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 210 211 212 213 214 215 216 217 | |
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.
MaterialProperties
¶
Bases: BaseModel
EM properties for a material.
Methods:
| Name | Description |
|---|---|
conductor |
Create a conductor material. |
dielectric |
Create a dielectric material. |
to_dict |
Convert to dictionary for YAML output. |
dielectric
classmethod
¶
Create a dielectric material.
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
ValidationResult
¶
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,
excited: bool = True,
)
MeshConfig
dataclass
¶
MeshConfig(
refined_mesh_size: float = 5.0,
max_mesh_size: float = 300.0,
cells_per_wavelength: int = 10,
margin: float = 50.0,
air_above: float = 100.0,
ground_plane: GroundPlane | None = None,
fmax: float = 100000000000.0,
boundary_conditions: list[str] | None = None,
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.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). |
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
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.
Functions¶
get_stack
¶
get_stack(yaml_path: str | Path | None = None, **kwargs) -> LayerStack
Get layer stack from active PDK or YAML file.
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 extract_layer_stack: - 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
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
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 | |
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
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
material_is_conductor
¶
material_is_dielectric
¶
Check if a material is a dielectric.
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
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 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 | |
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
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 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 | |
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
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
configure_cpw_port
¶
configure_cpw_port(
port_upper,
port_lower,
layer: str,
length: float,
impedance: float = 50.0,
excited: bool = True,
cpw_name: str | None = None,
)
Configure two gdsfactory ports as a CPW (multi-element) lumped port.
In CPW (Ground-Signal-Ground), E-fields are opposite in the two gaps. This function links two ports to form one multi-element lumped port that Palace will excite with proper CPW mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port_upper
|
gdsfactory Port for upper gap (signal-to-ground2) |
required | |
port_lower
|
gdsfactory Port for lower gap (ground1-to-signal) |
required | |
layer
|
str
|
Target conductor layer name (e.g., 'topmetal2') |
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
|
cpw_name
|
str | None
|
Optional name for the CPW port (default: uses port_lower.name) |
None
|
Examples:
configure_cpw_port(
port_upper=c.ports["gap_upper"],
port_lower=c.ports["gap_lower"],
layer="topmetal2",
length=5.0,
)
Source code in src/gsim/palace/ports/config.py
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). CPW ports are automatically grouped by their cpw_group ID.
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
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 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 | |
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
Constants¶
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),
"passive": MaterialProperties(
type="dielectric", permittivity=6.6, loss_tangent=0.0
),
"Si3N4": MaterialProperties(
type="dielectric", permittivity=7.5, loss_tangent=0.001
),
"polyimide": MaterialProperties(
type="dielectric", permittivity=3.4, loss_tangent=0.002
),
"air": MaterialProperties(type="dielectric", permittivity=1.0, loss_tangent=0.0),
"vacuum": MaterialProperties(type="dielectric", permittivity=1.0, loss_tangent=0.0),
"silicon": MaterialProperties(
type="semiconductor", permittivity=11.9, conductivity=2.0
),
"si": MaterialProperties(type="semiconductor", permittivity=11.9, conductivity=2.0),
}