electrostatics._quantum_region — quantum-region plane extraction
tempura/electrostatics/_quantum_region.py turns solved solver vectors into a
rectangular view of the active region — the plane where dots, barriers, or
Majorana modes live. Its two entry points,
extract_quantum_region_plane(...) and extract_quantum_region_basis(...), are
re-exported from tempura.electrostatics for use after a solve.
Why a separate step
A solved basis potential is a flat vector aligned with the finalized problem's mesh sites, not an image. To plot or analyze the field in the quantum region you need the subset of sites inside that region, arranged on a regular grid. This module extracts that grid and reshapes the vectors onto it.
Extracting the plane
extract_quantum_region_plane(...) resolves the target \(z\) plane from the
region's realized \(z\) levels (by "lower", "midpoint", "upper", or an
explicit value), then samples the mesh on a slab spanning the region's own
bounding box rather than only the cells the region owns. It selects the sites
at the target \(z\) and sorts them lexicographically by \((y, x)\). Sampling the
region's bounding box — instead of just the owned footprint — is what lets a
patterned quantum region still produce a complete plane: the patterned cells
sit inside an otherwise rectangular grid of sites at the same \(z\). Deriving the
slab from the region's own box (rather than a symmetric extent over every
region) keeps it off neighboring, coarser layers and works for devices that are
not centered on the origin.
It then verifies the selected sites form a complete rectangle:
and that the sorted \(x\) and \(y\) coordinates broadcast back to a regular grid.
The result is a frozen QuantumRegionPlaneData carrying the sorted solver
indices, the coordinates, the unique \(x\)/\(y\) values, the shared \(z\),
\((n_x, n_y)\), and a region_mask. The rectangular-grid check is what
guarantees a clean reshape downstream.
Because the plane spans the region's full bounding box, a patterned region
leaves non-owned filler cells inside that rectangle. region_mask is an
\((n_y, n_x)\) boolean array — the same membership test as points_inside — that
flags exactly the cells the region owns, so callers can blank the filler
instead of treating it as active material. For a full-footprint region every
entry is True.
Reshaping the basis
Given that plane, extract_quantum_region_basis(...) indexes each gate's solver
vector by the plane's sorted indices and reshapes it to \((n_y, n_x)\), returning
one image per gate in the requested order. project_gate_footprints_to_plane(...)
similarly samples each gate's footprint onto the same plane for overlays.
API
_quantum_region
Helpers for extracting rectangular quantum region planes from solved problems.
QuantumRegionPlaneData
dataclass
Rectangular quantum region plane data extracted from a solved problem.
Attributes:
| Name | Type | Description |
|---|---|---|
sorted_indices |
NDArray[int_]
|
Solver-vector indices sorted lexicographically by
|
coords |
NDArray[float64]
|
Sorted |
x_values |
NDArray[float64]
|
Unique x coordinates spanning the rectangular plane. |
y_values |
NDArray[float64]
|
Unique y coordinates spanning the rectangular plane. |
z_value |
float
|
Shared z coordinate of the selected plane. |
nx |
int
|
Number of x samples in the plane. |
ny |
int
|
Number of y samples in the plane. |
region_mask |
NDArray[bool_]
|
|
Source code in tempura/electrostatics/_quantum_region.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
extract_quantum_region_basis(basis_potentials, gate_names, plane)
Reshape solved gate basis vectors onto a rectangular quantum region 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
|
QuantumRegionPlaneData
|
Extracted quantum region plane metadata and sorted solver indices. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Mapping of gate name to |
Source code in tempura/electrostatics/_quantum_region.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
extract_quantum_region_plane(problem, region_shapes, *, region_name='quantum_region', plane_selection='midpoint')
Return one rectangular quantum region 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. |
required |
region_name
|
str
|
Region to extract from |
'quantum_region'
|
plane_selection
|
PlaneSelection
|
Which z plane to export when the realized quantum region spans
multiple z coordinates. Use |
'midpoint'
|
Returns:
| Type | Description |
|---|---|
QuantumRegionPlaneData
|
Sorted rectangular plane data for the selected z slice across the full |
QuantumRegionPlaneData
|
device XY span. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the quantum region is missing, empty, or the selected sampling slab does not form a rectangular plane. |
Source code in tempura/electrostatics/_quantum_region.py
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 | |
project_gate_footprints_to_plane(gate_shapes, plane)
Project gate XY footprints onto the exported rectangular quantum region plane.
Each gate is sampled at the midpoint of its z extent so the resulting mask matches the gate's in-plane footprint while remaining aligned to the quantum region export grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate_shapes
|
Mapping[str, Any]
|
Mapping of gate name to callable solver-owned gate shape. |
required |
plane
|
QuantumRegionPlaneData
|
Rectangular quantum region plane onto which the footprints should be sampled. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Mapping of gate name to |
dict[str, ndarray]
|
|
Source code in tempura/electrostatics/_quantum_region.py
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 | |