API Reference
This page follows Tempura's importable module structure. It is a reference, not the best first read. For the full workflow, start with Triple Quantum Dot. For the shorter concept pages, see Layout, Device, Mesh, and Solve, and Theory.
from tempura import Device, Dielectric, Gate, TwoDEG, export_device_view
from tempura.electrostatics import build_problem, solve_gate_potentials
from tempura.electrostatics.solver import TFSolver, daz_to_delta
from tempura.layout import (
crop_polygons_to_aoi,
load_layout_polygons,
make_aoi_bbox_from_ranges,
polygons_to_vertices,
rasterize_gate_vertices,
)
from tempura.layout.readers import load_layout_data
from tempura.layout.layout_pipeline import prepare_layout, build_device
from tempura.plotting import PlaneSpec, plot_problem_regions_with_mesh
Examples vs core API
The worked examples also use extract_2deg_plane(...) and
extract_2deg_basis(...) from tempura.electrostatics.pescado_wrapper to
reshape solved vectors for plotting. The core electrostatics entry points
are still build_problem(...) and solve_gate_potentials(...).
Public spelling and implicit behavior
Device(grid=...)is the supported public spelling for the in-plane lattice.dxanddyare still accepted as compatibility aliases.build_problem(...)resolves per-layerresolution=[dx, dy, dz]automatically from the finalized device. TheTwoDEGsets the finest master lattice.build_device(...)may expand one layoutsource_layerinto several suffixedGateobjects when that source layer contains several non-empty masks.
Module guide
tempura: high-level layer classes plus viewer export.tempura.electrostatics: device construction, automatic meshing, and gate-basis solves.tempura.electrostatics.solver: Thomas-Fermi and lower-level linear-system helpers.tempura.layout: low-level polygon, AOI, and rasterization helpers.tempura.layout.layout_pipeline: convenience workflow from layout ROI to a finalizedDevice.tempura.plotting: mesh and region inspection helpers.tempura.viewer: export helpers for the browser viewer.
Package Root
Public package API for Tempura.
Device
Ordered device stack used to derive solver geometry.
Source code in tempura/electrostatics/device.py
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 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 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |
dx
property
Return the x lattice spacing alias for :attr:grid.
dy
property
Return the y lattice spacing alias for :attr:grid.
finalized
property
Return whether :meth:finalize has been called successfully.
grid
property
Return the square in-plane lattice spacing.
layers
property
Return the ordered layer stack as a read-only mapping.
__init__(*, length, width, grid=None, dx=None, dy=None)
Create a device with explicit dimensions and base XY lattice spacing.
Source code in tempura/electrostatics/device.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
add_layer(layer)
Add a layer in bottom-to-top stacking order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
LayerInput
|
Either one layer instance or one non-empty list of gates deposited together in the same metal batch. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the device has already been finalized. |
ValueError
|
If names collide, a gate stencil shape is invalid, or two metal batches are added without an intervening non-gate layer. |
TypeError
|
If |
Source code in tempura/electrostatics/device.py
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 | |
finalize()
Realize device geometry in explicit, named stages.
Source code in tempura/electrostatics/device.py
636 637 638 639 640 641 642 643 644 645 | |
DeviceViewExportManifest
dataclass
Paths written by :func:export_device_view.
Attributes:
| Name | Type | Description |
|---|---|---|
scene_name |
str
|
Human-readable scene name stored in |
scene_json_path |
Path
|
Path to the scene metadata file. |
asset_paths |
tuple[Path, ...]
|
Paths to binary array assets referenced by |
Source code in tempura/viewer/export.py
26 27 28 29 30 31 32 33 34 35 36 37 38 | |
Dielectric
dataclass
Bases: LayerBase
Dielectric layer covering the full XY device footprint.
Source code in tempura/electrostatics/device.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
__post_init__()
Validate and normalize the dielectric permittivity.
Source code in tempura/electrostatics/device.py
471 472 473 474 475 476 477 478 | |
Gate
dataclass
Bases: LayerBase
Metallic gate layer described by a device-aligned stencil.
Source code in tempura/electrostatics/device.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
__post_init__()
Validate the gate stencil and normalize it to a boolean mask.
Source code in tempura/electrostatics/device.py
451 452 453 454 455 456 457 458 459 460 461 462 | |
TwoDEG
dataclass
Bases: LayerBase
Two-dimensional electron gas (2DEG) layer.
Source code in tempura/electrostatics/device.py
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 | |
__post_init__()
Validate the 2DEG material parameters and boundary condition.
Source code in tempura/electrostatics/device.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
export_device_view(device, out_dir, *, scene_name='device', colors=None, overwrite=True, verbose=False)
Export a device into files consumed by the TypeScript 3D viewer.
The exporter writes one scene.json metadata file and one or more binary
array files storing layer height fields (plus gate stencils).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
Device to export. |
required |
out_dir
|
str | Path
|
Output directory for the exported scene bundle. |
required |
scene_name
|
str
|
Label stored in the metadata file. |
'device'
|
colors
|
dict[str, str] | None
|
Optional per-layer color overrides keyed by layer name. |
None
|
overwrite
|
bool
|
If |
True
|
verbose
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
DeviceViewExportManifest
|
Manifest describing the files written. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the device is empty or a color override is invalid. |
FileExistsError
|
If |
RuntimeError
|
If the device is not finalized or finalized height arrays are missing. |
Source code in tempura/viewer/export.py
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 | |
Electrostatics
Electrostatics primitives and Poisson-solver helpers.
Device
Ordered device stack used to derive solver geometry.
Source code in tempura/electrostatics/device.py
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 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 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |
dx
property
Return the x lattice spacing alias for :attr:grid.
dy
property
Return the y lattice spacing alias for :attr:grid.
finalized
property
Return whether :meth:finalize has been called successfully.
grid
property
Return the square in-plane lattice spacing.
layers
property
Return the ordered layer stack as a read-only mapping.
__init__(*, length, width, grid=None, dx=None, dy=None)
Create a device with explicit dimensions and base XY lattice spacing.
Source code in tempura/electrostatics/device.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
add_layer(layer)
Add a layer in bottom-to-top stacking order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
LayerInput
|
Either one layer instance or one non-empty list of gates deposited together in the same metal batch. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the device has already been finalized. |
ValueError
|
If names collide, a gate stencil shape is invalid, or two metal batches are added without an intervening non-gate layer. |
TypeError
|
If |
Source code in tempura/electrostatics/device.py
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 | |
finalize()
Realize device geometry in explicit, named stages.
Source code in tempura/electrostatics/device.py
636 637 638 639 640 641 642 643 644 645 | |
Dielectric
dataclass
Bases: LayerBase
Dielectric layer covering the full XY device footprint.
Source code in tempura/electrostatics/device.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
__post_init__()
Validate and normalize the dielectric permittivity.
Source code in tempura/electrostatics/device.py
471 472 473 474 475 476 477 478 | |
Gate
dataclass
Bases: LayerBase
Metallic gate layer described by a device-aligned stencil.
Source code in tempura/electrostatics/device.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
__post_init__()
Validate the gate stencil and normalize it to a boolean mask.
Source code in tempura/electrostatics/device.py
451 452 453 454 455 456 457 458 459 460 461 462 | |
LayerBase
dataclass
Shared validated inputs for device layers.
The public dataclass fields are the user-provided layer specification.
Realized solver geometry is attached later by :meth:Device.finalize and
exposed through read-only properties such as :attr:z_bot_arr and
:attr:shape.
Source code in tempura/electrostatics/device.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 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 | |
shape
property
Return the finalized backend shape, if available.
z_bot_arr
property
Return the finalized bottom height field, if available.
z_bot_fn
property
Return the finalized bottom height sampler, if available.
z_top_arr
property
Return the finalized top height field, if available.
z_top_fn
property
Return the finalized top height sampler, if available.
__post_init__()
Normalize the public layer specification into validated NumPy inputs.
Source code in tempura/electrostatics/device.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
__setattr__(name, value)
Freeze public fields once finalized while allowing private caches.
Source code in tempura/electrostatics/device.py
339 340 341 342 343 | |
TwoDEG
dataclass
Bases: LayerBase
Two-dimensional electron gas (2DEG) layer.
Source code in tempura/electrostatics/device.py
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 | |
__post_init__()
Validate the 2DEG material parameters and boundary condition.
Source code in tempura/electrostatics/device.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
build_problem(device, vacuum_scale=8.0, *, verbose=False)
Build a Poisson problem for a layered device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
Finalized device whose electrostatic stack should be meshed. |
required |
vacuum_scale
|
float
|
Outer vacuum size multiplier relative to the device span. |
8.0
|
verbose
|
bool
|
Whether to emit progress logging during assembly. |
False
|
Returns:
| Type | Description |
|---|---|
ProblemBuilder
|
Tuple of |
RegionMap
|
with Tempura's historical public API. |
Source code in tempura/electrostatics/pescado_wrapper.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
build_rhs_vectors(region_inds, gate_names, *, size=None, charge=None, dtype=DTYPE)
Build the multi-RHS matrix for the ordered gate basis solves.
Source code in tempura/electrostatics/solver.py
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 | |
get_region_inds(pescado_problem_finalized, gate_shapes, boundary_shape, *, boundary_name='Boundary')
Return indices for interior, gates, and the outer boundary.
Source code in tempura/electrostatics/_pescado_solve.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
setup_solver(matrix, *, dtype=DTYPE, blr=BLR, eps_blr=EPS_BLR, symmetric=False)
Create and factor a MUMPS solver for a sparse linear system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Any
|
Real-valued system matrix to factor. |
required |
dtype
|
DTypeLike
|
Real numeric dtype used to cast |
DTYPE
|
blr
|
bool
|
Whether to enable MUMPS block low-rank factorization. |
BLR
|
eps_blr
|
float
|
BLR compression threshold used when |
EPS_BLR
|
symmetric
|
bool
|
Whether |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
Factored MUMPS context that can be reused across solves. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Source code in tempura/electrostatics/solver.py
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 | |
solve_gate_potentials(problem_builder, region_shapes, gate_names, *, charge=None, dtype=DTYPE, blr=BLR, eps_blr=EPS_BLR, rhs_block_size=8, save_2deg_potential=None, twodeg_plane_selection='midpoint', verbose=False)
Solve the gate basis problem with one reused factorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem_builder
|
ProblemBuilder
|
Initialized Pescado problem builder returned by
:func: |
required |
region_shapes
|
RegionMap
|
Mapping of region names to realized region shapes. |
required |
gate_names
|
list[str]
|
Ordered gate names to solve. |
required |
charge
|
ndarray | None
|
Optional distributed charge columns to include in the RHS. |
None
|
dtype
|
DTypeLike
|
Numeric dtype used during factorization and solve. |
DTYPE
|
blr
|
bool
|
Whether to enable MUMPS block low-rank factorization. |
BLR
|
eps_blr
|
float
|
BLR compression threshold when |
EPS_BLR
|
rhs_block_size
|
int
|
Number of gate basis columns to solve per linear solve. |
8
|
save_2deg_potential
|
str | Path | None
|
Optional output directory for static 2DEG export. |
None
|
twodeg_plane_selection
|
PlaneSelection
|
Which realized 2DEG z plane to export when the region spans multiple z coordinates. |
'midpoint'
|
verbose
|
bool
|
Whether to emit progress logging during solving. |
False
|
Returns:
| Type | Description |
|---|---|
PotentialMap
|
Tuple of |
Any
|
historical public API. |
Source code in tempura/electrostatics/pescado_wrapper.py
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 | |
solve_linear_system(matrix, rhs, *, solver=None, dtype=DTYPE, blr=BLR, eps_blr=EPS_BLR, symmetric=False)
Solve matrix x = rhs with a factored MUMPS solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Any
|
Real-valued system matrix to solve. |
required |
rhs
|
Any
|
Dense or sparse right-hand side array. |
required |
solver
|
Any | None
|
Optional existing factored MUMPS context to reuse. |
None
|
dtype
|
DTypeLike
|
Real numeric dtype used to cast the matrix and RHS. Tempura's electrostatics solve path does not preserve imaginary components. |
DTYPE
|
blr
|
bool
|
Whether to enable MUMPS block low-rank factorization. |
BLR
|
eps_blr
|
float
|
BLR compression threshold used when |
EPS_BLR
|
symmetric
|
bool
|
Whether |
False
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, Any]
|
Tuple of |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Source code in tempura/electrostatics/solver.py
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 | |
Return indices for interior, gates, and the outer boundary.
Source code in tempura/electrostatics/_pescado_solve.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
Return the rectangular 2DEG plane extracted from problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Any
|
Finalized Pescado problem exposing |
required |
region_shapes
|
Mapping[str, Any]
|
Mapping of region names to shapes. Must contain |
required |
plane_selection
|
PlaneSelection
|
Which z plane to export when the realized 2DEG spans
multiple z coordinates. Use |
'midpoint'
|
Returns:
| Type | Description |
|---|---|
TwoDEGPlaneData
|
Sorted rectangular plane data for the 2DEG region. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the 2DEG region is missing, empty, or does not form a rectangular plane. |
Source code in tempura/electrostatics/_twodeg.py
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 | |
Reshape solved gate basis vectors onto a rectangular 2DEG plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
basis_potentials
|
Mapping[str, ndarray]
|
Mapping of gate name to solved potential vector. |
required |
gate_names
|
list[str]
|
Gate order to preserve in the returned mapping. |
required |
plane
|
TwoDEGPlaneData
|
Extracted 2DEG plane metadata and sorted solver indices. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Mapping of gate name to |
Source code in tempura/electrostatics/_twodeg.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
Thomas-Fermi wrapper for self-consistent 2DEG solves.
Source code in tempura/electrostatics/solver.py
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 | |
get_charge()
Return the latest self-consistent quantum charge field.
Source code in tempura/electrostatics/solver.py
497 498 499 | |
get_potential()
Return the latest self-consistent chemical potential field.
Source code in tempura/electrostatics/solver.py
493 494 495 | |
solve(voltages, initial_guess=None, max_ite=15)
Solve the self-consistent problem for the provided region voltages.
Source code in tempura/electrostatics/solver.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
Convert daz (density at zero energy) to the ILDOS threshold delta.
Source code in tempura/electrostatics/solver.py
372 373 374 375 | |
Return ILDOS lookup tables and site labels for a 2DEG region.
The returned list contains one piecewise-linear ILDOS table per unique mesh
volume in the selected 2DEG points. sites_ildos maps each 2DEG site to
the corresponding ILDOS table index.
Source code in tempura/electrostatics/solver.py
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 | |
Layout
Layout readers and AOI extraction helpers.
crop_polygons_to_aoi(polygons_by_layer, aoi_bbox, precision=1e-06)
Clip all layers to AOI and return local-coordinate polygons.
Source code in tempura/layout/extraction.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
load_layout_polygons(path)
Load polygons by layer from GDS/GDSII/OAS/DXF.
Source code in tempura/layout/readers.py
243 244 245 | |
make_aoi_bbox_from_ranges(x_range, y_range)
Build AOI bbox from two [min, max]-like ranges.
Source code in tempura/layout/extraction.py
47 48 49 50 51 52 53 54 55 | |
plot_gate_stencil_layers(gate_stencils, *, roi_size, layer_order=None, title='Rasterized gate masks by layer', figsize=None, coordinate_scale=1.0, axis_unit=None, layer_thicknesses=None)
Plot one panel per source layer with all of that layer's gates overlaid.
Source code in tempura/layout/extraction.py
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 | |
plot_layout_interactive(polygons_by_layer, layers=None, exclude_layers=None, title='Layout Layers (interactive)', *, filled=True)
Return interactive Plotly figure for layer inspection.
Source code in tempura/layout/extraction.py
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 | |
plot_layout_layers(polygons_by_layer, *, layers=None, exclude_layers=None, title=None, filled=True, coordinate_scale=1.0, axis_unit=None)
Plot layout polygons with Matplotlib using one shared set of axes.
Source code in tempura/layout/extraction.py
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 | |
polygons_to_vertices(polygons_by_layer)
Convert polygons grouped by layer into nested Python lists.
Source code in tempura/layout/extraction.py
84 85 86 87 88 89 | |
rasterize_gate_vertices(gate_vertices_by_layer, *, dx, dy, roi_bbox)
Rasterize gate polygons into boolean masks on a regular grid.
Converts vector polygon data (gate vertices) organized by layer into rasterized
boolean masks suitable for mask-based analysis or image processing operations.
All polygons are rasterized on the same ROI grid.
Args:
gate_vertices_by_layer: Dictionary mapping layer names to lists of polygon
vertices. Each polygon is defined by an ordered sequence of (x, y) coordinates
forming a closed shape.
dx: Grid spacing in the x-direction (horizontal). Must be positive. Determines
the horizontal resolution of the rasterized output.
dy: Grid spacing in the y-direction (vertical). Must be positive. Determines
the vertical resolution of the rasterized output.
roi_bbox: Rasterization region as (xmin, xmax, ymin, ymax).
Every polygon mask is generated on this ROI-sized grid so all masks have
identical shape and alignment.
Returns:
Dictionary mapping layer names to lists of boolean numpy arrays (masks).
Each mask has shape (ny, nx) where a True value indicates the grid point
is inside the corresponding polygon.
Raises:
ValueError: If dx/dy are invalid or roi_bbox bounds are invalid.
Notes:
- Polygons with fewer than 3 vertices are skipped (degenerate cases).
- Point-in-polygon testing uses matplotlib's Path.contains_points() method.
- Grid points are sampled at cell centers (offset by 0.5 * dx, 0.5 * dy).
- Output masks are indexed as [y, x] (row-major ordering).
- Layers with no valid polygons are omitted from the output dictionary.
Source code in tempura/layout/extraction.py
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 | |
read_dxf_polylines(path)
Read closed DXF POLYLINE entities grouped by DXF layer name.
Source code in tempura/layout/readers.py
258 259 260 | |
read_gds_polygons(path)
Read polygons from a GDS/GDSII layout.
Source code in tempura/layout/readers.py
248 249 250 | |
read_oas_polygons(path)
Read polygons from an OASIS layout.
Source code in tempura/layout/readers.py
253 254 255 | |
Load polygons and available unit metadata from GDS/GDSII/OAS/DXF.
Source code in tempura/layout/readers.py
228 229 230 231 232 233 234 235 236 237 238 239 240 | |
Load a layout file and return an interactive figure for its polygons.
Source code in tempura/layout/extraction.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
Shared helpers for layout-backed demo simulations.
build_device(prepared, stack)
Build a finalized device from prepared masks and an ordered stack spec.
The stack describes the physical layers and may optionally include one
per-layer resolution entry used directly by build_problem(...).
2deg entries may also provide boundary_condition to select the
linear response model for that region. Gate layers may also set
inverted=True when their one source stencil represents an etched
opening rather than deposited metal.
Source code in tempura/layout/layout_pipeline.py
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 | |
format_device_dimensions(device, prepared=None)
Return the physical size and XY grid summary for a device.
Source code in tempura/layout/layout_pipeline.py
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 | |
format_roi_summary(prepared)
Return the ROI size in physical units and grid-normalized units.
Source code in tempura/layout/layout_pipeline.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
prepare_layout(layout_path, aoi_bbox, size_mode, grid_constant_m=DEFAULT_GRID_CONSTANT_M, physical_x_length=None, precision=1e-06, tolerance=1e-06)
Load, crop, scale, and rasterize a layout-backed ROI.
The ROI is first resolved in physical units (meters), then rescaled so one internal XY unit corresponds to one grid constant.
Source code in tempura/layout/layout_pipeline.py
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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
print_device_dimensions(device, prepared=None)
Print a compact device summary.
Source code in tempura/layout/layout_pipeline.py
421 422 423 424 425 426 | |
print_roi_summary(prepared)
Print a compact ROI summary.
Source code in tempura/layout/layout_pipeline.py
387 388 389 | |
solve_demo(device, vacuum_scale=2, rhs_block_size=1)
Solve the electrostatic basis problem and extract a 2DEG slice.
Source code in tempura/layout/layout_pipeline.py
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 | |
Plotting
Plotting helpers for Tempura.
PlaneSpec
dataclass
Describe one 2D slice through a finalized 3D problem.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
Panel title. |
plot_region |
Box
|
2D plotting region in the displayed axes. |
plane_axis |
int
|
Fixed axis in 3D coordinates. |
plane_value |
float
|
Position of the fixed slicing plane. |
axis_indices |
tuple[int, int]
|
Indices of the displayed axes in the 3D coordinate system. |
axis_labels |
tuple[str, str]
|
Labels for the displayed axes. |
Source code in tempura/plotting/meshing.py
27 28 29 30 31 32 33 34 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 | |
add_gate_footprint_contours_xy(ax, x_values, y_values, footprints, *, coordinate_scale=1.0, color='black', linewidth=0.8, alpha=0.7)
Overlay direct XY gate-footprint contours on one existing axis.
Source code in tempura/plotting/meshing.py
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 | |
add_plane_cut_guides(ax, *, x=None, y=None, coordinate_scale=1.0, color='black', linewidth=1.0, linestyle='--')
Overlay one or two cut-guide lines on an existing 2D plane plot.
Source code in tempura/plotting/meshing.py
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 | |
add_region_contours_on_planes(problem, axes, plane_specs, region_shapes, *, region_display_names=None, coordinate_scale=1.0, linewidth=1.0, alpha=0.9)
Overlay region-outline contours on existing plane plots.
Source code in tempura/plotting/meshing.py
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 | |
expand_plane_grid(plane_specs_by_key, grid, *, title_overrides=None)
Expand a named subplot grid into an ordered plane-spec sequence.
Source code in tempura/plotting/meshing.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
make_standard_plane_specs(device, *, xy_title, xy_plane_z, xz_title, xz_plane_y, yz_title=None, yz_plane_x=None, z_padding=1.0)
Build the standard XY/XZ/YZ plotting cuts for one device.
Source code in tempura/plotting/meshing.py
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
make_xy_emphasis_axes(*, figsize=(12.0, 9.8), layout='stack', width_ratios=(1.0, 1.0), height_ratios=(1.0, 1.0, 1.0))
Return three axes for XY, XZ, and YZ cuts in one of two compact layouts.
Source code in tempura/plotting/meshing.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
nearest_axis_value(coordinates, axis, target)
Snap a requested cut to the nearest finalized mesh plane.
Source code in tempura/plotting/meshing.py
76 77 78 79 | |
plot_problem_regions_with_mesh(problem, region_shapes, plane_specs, *, axes=None, region_names=None, region_display_names=None, ncols=None, figsize=(13.0, 11.0), suptitle='Pescado region cuts with overlaid mesh nodes', fill_mode='regions', background_alpha=0.88, tile_edgecolors='white', tile_linewidth=0.6, show_volume_edges=False, show_mesh_points=True, mesh_point_size=12.0, mesh_facecolors='white', mesh_edgecolors='black', mesh_linewidth=0.35, coordinate_scale=1.0, axis_unit=None)
Plot finalized region slices with overlaid mesh nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Any
|
Finalized Pescado problem with a |
required |
region_shapes
|
RegionShapeMap
|
Mapping returned by |
required |
plane_specs
|
Sequence[PlaneSpec]
|
Sequence of |
required |
region_names
|
Sequence[str] | None
|
Optional region order for coloring. Defaults to every
region except |
None
|
region_display_names
|
RegionDisplayMap | None
|
Optional mapping from solver-owned region names to display labels. Regions that share a display label are drawn with the same color and collapsed into one legend entry. |
None
|
ncols
|
int | None
|
Number of subplot columns. Defaults to |
None
|
figsize
|
tuple[float, float]
|
Matplotlib figure size. |
(13.0, 11.0)
|
suptitle
|
str
|
Figure title. |
'Pescado region cuts with overlaid mesh nodes'
|
fill_mode
|
str
|
|
'regions'
|
background_alpha
|
float
|
Alpha used for the ownership tiles under the markers. |
0.88
|
tile_edgecolors
|
str
|
Edge color for the projected mesh control volumes. |
'white'
|
tile_linewidth
|
float
|
Edge line width for the projected mesh control volumes. |
0.6
|
show_volume_edges
|
bool
|
Whether to overlay the projected control-volume boundaries on top of the filled region cross-section. |
False
|
show_mesh_points
|
bool
|
Whether to overlay the selected mesh sites as points. |
True
|
mesh_point_size
|
float
|
Scatter marker size for finalized mesh nodes. |
12.0
|
mesh_facecolors
|
str
|
Scatter face color. |
'white'
|
mesh_edgecolors
|
str
|
Scatter edge color. |
'black'
|
mesh_linewidth
|
float
|
Scatter edge line width. |
0.35
|
coordinate_scale
|
float
|
Multiplicative scale applied to displayed coordinates. |
1.0
|
axis_unit
|
str | None
|
Optional axis-unit label appended to x/y/z labels. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, ndarray]
|
Tuple of |
Notes
For each requested plane, Tempura first selects the mesh sites whose control volumes intersect that plane. The optional marker overlay shows those selected sites explicitly. The colored background can either show the projected control volumes directly or a sampled cross-section of the finalized region shapes.
Source code in tempura/plotting/meshing.py
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 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | |
plot_scalar_field_on_planes(problem, scalar_values, plane_specs, *, axes=None, ncols=None, figsize=(13.0, 11.0), suptitle='Scalar field cuts', colorbar_label='Value', cmap='coolwarm', symmetric=True, vmin=None, vmax=None, tile_edgecolors='none', tile_linewidth=0.0, show_volume_edges=False, coordinate_scale=1.0, axis_unit=None)
Plot one scalar field on a set of mesh-aligned 2D plane cuts.
Source code in tempura/plotting/meshing.py
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 | |
save_problem_regions_with_mesh(problem, region_shapes, plane_specs, output_path, *, region_names=None, region_display_names=None, ncols=None, figsize=(13.0, 11.0), suptitle='Pescado region cuts with overlaid mesh nodes', dpi=220, fill_mode='regions', background_alpha=0.88, tile_edgecolors='white', tile_linewidth=0.6, show_volume_edges=False, show_mesh_points=True, mesh_point_size=12.0, mesh_facecolors='white', mesh_edgecolors='black', mesh_linewidth=0.35, coordinate_scale=1.0, axis_unit=None)
Render region slices with overlaid mesh nodes and save the figure.
This is a convenience wrapper around plot_problem_regions_with_mesh(...)
that also creates the parent directory and closes the Matplotlib figure
after saving.
Source code in tempura/plotting/meshing.py
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 | |
transpose_plane_spec(spec, *, title=None)
Return one plane spec with the displayed axes swapped.
Source code in tempura/plotting/meshing.py
129 130 131 132 133 134 135 136 137 138 139 140 | |
Viewer
Viewer export helpers for serialized device scenes.
DeviceViewExportManifest
dataclass
Paths written by :func:export_device_view.
Attributes:
| Name | Type | Description |
|---|---|---|
scene_name |
str
|
Human-readable scene name stored in |
scene_json_path |
Path
|
Path to the scene metadata file. |
asset_paths |
tuple[Path, ...]
|
Paths to binary array assets referenced by |
Source code in tempura/viewer/export.py
26 27 28 29 30 31 32 33 34 35 36 37 38 | |
export_device_view(device, out_dir, *, scene_name='device', colors=None, overwrite=True, verbose=False)
Export a device into files consumed by the TypeScript 3D viewer.
The exporter writes one scene.json metadata file and one or more binary
array files storing layer height fields (plus gate stencils).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
Device to export. |
required |
out_dir
|
str | Path
|
Output directory for the exported scene bundle. |
required |
scene_name
|
str
|
Label stored in the metadata file. |
'device'
|
colors
|
dict[str, str] | None
|
Optional per-layer color overrides keyed by layer name. |
None
|
overwrite
|
bool
|
If |
True
|
verbose
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
DeviceViewExportManifest
|
Manifest describing the files written. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the device is empty or a color override is invalid. |
FileExistsError
|
If |
RuntimeError
|
If the device is not finalized or finalized height arrays are missing. |
Source code in tempura/viewer/export.py
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 | |