layout.layout_pipeline — the layout-to-device workflow
tempura/layout/layout_pipeline.py chains the layout steps into the two
convenience functions most users call: prepare_layout(...), which reads,
crops, scales, and rasterizes a layout in one call, and build_device(...),
which combines the prepared masks with a vertical stack into a finalized
Device. The module also holds the small ROI/device summary helpers.
prepare_layout — into internal units
prepare_layout(...) resolves the ROI in physical units, then rescales it so one
internal XY cell equals one grid constant. The physical ROI length comes either
from the file's unit metadata (size_mode="layout_size") or from an explicit
physical_x_length with the \(y\) length inferred from the AOI aspect ratio
(size_mode="explicit_x"). The resolved physical ROI must be an integer number
of grid cells:
Polygons are scaled independently in \(x\) and \(y\) onto that cell grid and
rasterized into the gate_stencils of a PreparedLayout.
After prepare_layout(...), you are in grid units
Tempura stops working in meters once the layout is rasterized. If
grid_constant_m = 10e-9, one internal unit is 10 nm, and from then on
the AOI size, gate masks, device.length/device.width, layer
thicknesses, and every resolution=[dx, dy, dz] are in those units.
grid_constant_m is what converts back to meters.
build_device — masks plus a stack
build_device(...) takes the PreparedLayout and an ordered stack specification
(bottom-to-top) and returns a finalized device. Each stack entry is a small
mapping with a kind of "dielectric", "quantum_region", or "gate", and
the relevant physical parameters. A gate entry names the source_layer whose
rasterized masks become metal.
A single gate entry can expand into several Gate objects: if its source layer
rasterizes to multiple disconnected masks, Tempura emits one gate per connected
component and suffixes the names _0, _1, and so on.
A "quantum_region" entry may carry an optional stencil — a boolean mask
matching the prepared grid_shape — to pattern the active region into a partial
footprint instead of covering the whole ROI:
stack = [
{"kind": "dielectric", "name": "buffer", "permittivity": 12.9, "thickness": 10.0},
{
"kind": "quantum_region",
"name": "quantum_region",
"permittivity": 12.9,
"thickness": 2.0,
"stencil": active_mask, # (ny, nx) boolean, matches prepared.grid_shape
},
{"kind": "gate", "name": "plunger", "source_layer": "L3D2", "thickness": 2.0},
]
Coplanar batches: {"kind": "batch", ...}
Most stack entries deposit one layer (or one gate that expands into connected
components). To deposit several layers at the same height, wrap them in a
batch entry whose layers is a list of ordinary stack entries:
{
"kind": "batch",
"layers": [
{"kind": "gate", "name": "left", "source_layer": "L4D2", "thickness": 2.0},
{"kind": "gate", "name": "right", "source_layer": "L5D2", "thickness": 2.0},
],
}
Every layer produced by the batch is deposited coplanar, and their footprints
must be disjoint — overlapping footprints raise a ValueError. This mirrors
Device.add_layer([...]) at the device level.
Etched openings: inverted=True
Sometimes a layout layer stores the opening in a metal sheet — the hole etched
into a global gate — rather than the metal itself. Set inverted=True on the
gate entry: Tempura flips the single source stencil so the metal becomes the
"on" region, then splits the remaining metal into one gate per disconnected
component. This requires exactly one non-empty source stencil to invert, and it
applies only to gate layers. (The minimal Kitaev chain example uses this to
recover an aluminum gate stored as an opening.)
Summary helpers
format_roi_summary(...) / print_roi_summary(...) and
format_device_dimensions(...) / print_device_dimensions(...) render compact
text summaries of the prepared ROI and the finalized device for quick checks.
API
layout_pipeline
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(...).
quantum_region entries may also provide boundary_condition to select
the linear response model for that region plus a literal stencil for one
patterned quantum-region footprint. Gate layers may also set
inverted=True when their one source stencil represents an etched opening
rather than deposited metal. Layout-backed gate entries expand into one or
more concrete Gate objects whose emitted names are suffixed as _0,
_1, and so on. One explicit coplanar batch may be expressed as
{"kind": "batch", "layers": [...]}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prepared
|
PreparedLayout
|
Typed payload returned by :func: |
required |
stack
|
list[dict[str, object]]
|
Ordered layer specification from bottom to top. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Finalized |
Device
|
class: |
Device
|
prepared layout masks and stack specification. |
Source code in tempura/layout/layout_pipeline.py
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 | |
format_device_dimensions(device, prepared=None)
Return the physical size and XY grid summary for a device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
Finalized device to summarize. |
required |
prepared
|
PreparedLayout | None
|
Optional layout-preparation metadata used to include physical size conversions. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line summary string describing device dimensions, grid shape, and |
str
|
layer names. |
Source code in tempura/layout/layout_pipeline.py
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 | |
format_roi_summary(prepared)
Return the ROI size in physical units and grid-normalized units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prepared
|
PreparedLayout
|
Typed payload returned by :func: |
required |
Returns:
| Type | Description |
|---|---|
str
|
Multi-line summary string describing ROI size and grid shape. |
Source code in tempura/layout/layout_pipeline.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout_path
|
str | Path
|
Filesystem path to the source layout file. |
required |
aoi_bbox
|
tuple[float, float, float, float]
|
AOI bounds in the layout coordinate system. |
required |
size_mode
|
str
|
|
required |
grid_constant_m
|
float
|
Physical size represented by one internal XY unit. |
DEFAULT_GRID_CONSTANT_M
|
physical_x_length
|
float | None
|
Physical x span used when |
None
|
precision
|
float
|
Boolean-operation precision passed to AOI clipping. |
1e-06
|
tolerance
|
float
|
Tolerance used when validating that the physical ROI size is
an integer multiple of |
1e-06
|
Returns:
| Type | Description |
|---|---|
PreparedLayout
|
Typed layout payload containing the rasterized masks plus the minimum |
PreparedLayout
|
geometry and scaling data needed by :func: |
Source code in tempura/layout/layout_pipeline.py
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 | |
print_device_dimensions(device, prepared=None)
Print a compact device summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
Finalized device to summarize. |
required |
prepared
|
PreparedLayout | None
|
Optional layout-preparation metadata used to include physical size conversions. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in tempura/layout/layout_pipeline.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
print_roi_summary(prepared)
Print a compact ROI summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prepared
|
PreparedLayout
|
Typed payload returned by :func: |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in tempura/layout/layout_pipeline.py
592 593 594 595 596 597 598 599 600 601 | |
solve_demo(device, vacuum_scale=2, rhs_block_size=1)
Solve the basis problem and extract one rectangular quantum region slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
Finalized device to solve. |
required |
vacuum_scale
|
float
|
Outer vacuum size multiplier passed to
:func: |
2
|
rhs_block_size
|
int
|
Number of gate basis columns solved per linear-system block. |
1
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
Mapping containing gate names, full basis vectors, quantum region plane |
dict[str, object]
|
data, and the finalized problem. |
Source code in tempura/layout/layout_pipeline.py
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 | |