electrostatics.pescado_wrapper — the public solve facade
tempura/electrostatics/pescado_wrapper.py is the thin, stable facade over the
electrostatics pipeline. It exposes the two functions most users call —
build_problem(...) and solve_gate_potentials(...) — and re-exports the
quantum-region extraction helpers. The heavy lifting lives in the internal
modules it delegates to; this file's job is to keep a small, documented surface.
The two-step solve contract
The workflow is intentionally explicit about where geometry ends and the solve begins:
problem_builder = build_problem(device) # assemble the meshed problem
problem = problem_builder.finalized() # freeze it into a pescado problem
basis_potentials = solve_gate_potentials(problem) # one basis field per gate
build_problem(...) returns a ProblemBuilder (see
_pescado_build); you finalize it yourself, then pass the
finalized problem to solve_gate_potentials(...) (see
_pescado_solve). The facade deliberately does not
finalize for you, so the finalize step — and the chance to inspect or hand the
problem elsewhere — stays visible. Passing an un-finalized builder to the solve
raises a clear error.
What you get back
solve_gate_potentials(...) returns a mapping from gate name to the solved
basis-potential vector. Because the solve is linear, any voltage configuration
is the superposition \(\phi = \sum_i V_i\,\phi_i\) of those basis fields — the
factorization is reused, not recomputed, for each new voltage setting.
Handing off to a self-consistent solver
For a nonlinear or voltage-dependent quantum-region response, the basis fields no longer describe the device on their own. The finalized problem is itself the handoff object — it carries the coordinates, region shapes, sparse-vector helpers, and system matrix a self-consistent solver needs:
from pescado.self_consistent import solver as tf_backend
Tempura does not wrap that solver as part of its core API; it hands you the finalized problem and steps out of the way.
API
pescado_wrapper
Compatibility facade for Tempura's active electrostatics pipeline.
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 | |
build_problem(device, vacuum_scale=8.0, *, vacuum_resolution_scale=8.0, dirichlet_boundary=True, 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
|
vacuum_resolution_scale
|
float
|
Coarsening factor applied to the automatic outer-vacuum lattice spacing. |
8.0
|
dirichlet_boundary
|
bool
|
Whether to add a thin outer shell of zero-volt
Dirichlet sites around the simulation box. When |
True
|
verbose
|
bool
|
Whether to emit progress logging during assembly. |
False
|
Returns:
| Type | Description |
|---|---|
ProblemBuilder
|
Initialized Pescado :class: |
ProblemBuilder
|
explicitly before calling :func: |
Source code in tempura/electrostatics/pescado_wrapper.py
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 | |
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 | |
get_region_inds(pescado_problem_finalized, gate_shapes, boundary_shape, *, boundary_name='Boundary')
Return solver indices for interior, gates, and the outer boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pescado_problem_finalized
|
Any
|
Finalized Pescado problem exposing region
index arrays plus |
required |
gate_shapes
|
RegionMap
|
Mapping of gate name to solver-owned gate region shape. |
required |
boundary_shape
|
Shape | None
|
Solver-owned outer Dirichlet boundary shape, or
|
required |
boundary_name
|
str
|
Key used for the boundary entry in the returned mapping. |
'Boundary'
|
Returns:
| Type | Description |
|---|---|
IndexMap
|
Mapping containing |
IndexMap
|
|
IndexMap
|
also contains one entry for |
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
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 | |
solve_gate_potentials(problem, *, charge=None, dtype=DTYPE, blr=BLR, eps_blr=EPS_BLR, rhs_block_size=8, save_quantum_region_potential=None, quantum_region_name='quantum_region', quantum_region_plane_selection='midpoint', verbose=False)
Solve the gate basis problem with one reused factorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Any
|
Finalized Pescado problem returned by
|
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_quantum_region_potential
|
str | Path | None
|
Optional output directory for static quantum region export. |
None
|
quantum_region_name
|
str
|
Region name to export when saving a quantum region basis bundle. |
'quantum_region'
|
quantum_region_plane_selection
|
PlaneSelection
|
Which realized quantum region 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
|
Mapping from gate name to solved basis-potential vector. |
Source code in tempura/electrostatics/pescado_wrapper.py
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 | |