quchip.chip.dressing¶
JAX-traceable dressed-state labeling primitives.
Three layers, separated cleanly:
Pure-JAX kernel.
label_eigensystem()takes(evals, evecs, reference, policy)and returns aLabeling. Knows nothing aboutChip, devices, caching, warnings, or backends.References as data.
BareProductReferenceandEigenstateReferenceproduce reference vectors and label keys. Overlaps are computed by one shared kernel,compute_overlaps(), so subspace generalization is a tensor reshape rather than a new subclass.Façade.
ChipAnalysiscalls the kernel and builds the existingDressedResult.
Inspired by SuperGrad’s compute_energy_map: one-line jnp.argmax
for greedy assignment, lax.scan argmax-with-masking for global
greedy, and continuation along a parameter path. Generalized so
references are pluggable as data and the path is a stacked eigvec
tensor rather than a list of chip configurations.
Functions
|
One-shot |
|
Global descending-overlap greedy via |
|
Confidence-ordered row-greedy assignment — |
|
|
|
Pure-JAX labeling kernel. |
|
Phase-fixed transform from Kronecker basis to labeled dressed basis. |
|
Propagate a labeling along a parameter path of stacked eigensystems. |
Classes
|
Bare product basis states in Kronecker order. |
|
Reference vectors are explicit eigenvectors with attached label keys. |
|
A labeled assignment of dressed eigenstates to user-meaningful keys. |
|
Stacked labelings along a parameter path. |
- class quchip.chip.dressing.Labeling(keys, indices, overlaps, margins, duplicates)[source]¶
Bases:
objectA labeled assignment of dressed eigenstates to user-meaningful keys.
Array fields only — no embedded
Referenceobject — so the dataclass is a clean pytree underjax.jit(),jax.vmap(), andjax.grad().indicesis the integer assignment (non-differentiable, conceptuallystop_gradient’d).overlapsandmarginsare differentiable. Energies indexed viaindicesflow gradients through the gathered values:eigvals[labeling.indices[k]]is differentiable w.r.t. parameters that affecteigvals.- Parameters:
- indices: Array¶
- overlaps: Array¶
- margins: Array¶
- duplicates: Array¶
- class quchip.chip.dressing.LabelingPath(keys, indices, overlaps, margins, duplicates, swap_events)[source]¶
Bases:
objectStacked labelings along a parameter path.
Each array field carries a leading
n_stepsaxis vs.Labeling, plus aswap_eventsarray surfacing where labels actually changed dressed-index between adjacent steps. A swap by itself is just a reassignment; combine it with a margin collapse (marginsnear zero) at the same step to identify avoided crossings vs. routine mode mixing.- Parameters:
- indices: Array¶
- overlaps: Array¶
- margins: Array¶
- duplicates: Array¶
- swap_events: Array¶
- class quchip.chip.dressing.BareProductReference(dims)[source]¶
Bases:
objectBare product basis states in Kronecker order.
Vectors are not materialized: bare products are the standard basis of the eigvec matrix in Kronecker order, so overlaps reduce to
|evecs|**2directly (seecompute_overlaps()).
- class quchip.chip.dressing.EigenstateReference(vectors, keys)[source]¶
Bases:
objectReference vectors are explicit eigenvectors with attached label keys.
Used for path continuation: the previous step’s selected eigvecs become the next step’s reference.
vectorsis row-major: each row is one reference state in the Kronecker basis.- vectors: Array¶
- quchip.chip.dressing.compute_overlaps(reference, evecs)[source]¶
|<ref_k | psi_j>|**2matrix, shape(n_labels, n_dressed).Specialized for
BareProductReferenceto skip materializing an identity matrix: bare products are the Kronecker standard basis, so|<k|psi_j>|**2 = |evecs[k, j]|**2.- Parameters:
reference (Any)
evecs (Array)
- Return type:
Array
- quchip.chip.dressing.assign_argmax(overlaps)[source]¶
One-shot
argmaxper row. Allows duplicate dressed-index assignments.Returns
(indices, chosen, margins). Cheap andjit-clean — matches SuperGrad’s default greedy mode. Use when the chip is in a weak-coupling regime where each bare label has a clearly-dominant dressed eigenstate.- Parameters:
overlaps (Array)
- Return type:
tuple[Array, Array, Array]
- quchip.chip.dressing.assign_global_greedy(overlaps)[source]¶
Global descending-overlap greedy via
lax.scanwith masking.At each step, finds the
(label, dressed_idx)pair with the highest remaining overlap, assigns it, and masks out that label’s row and that column so neither is reused. Equivalent to the legacy Pythonsorted+set+dictpath but pure JAX.Margins are computed from the unmasked overlap matrix, so they describe per-label confidence independent of assignment order.
Requires
n_labels <= n_dressed.- Parameters:
overlaps (Array)
- Return type:
tuple[Array, Array, Array]
- quchip.chip.dressing.assign_rowwise_greedy(overlaps)[source]¶
Confidence-ordered row-greedy assignment —
O(n_labels * n_dressed).Labels (rows) are visited in descending row-max-overlap order; each takes its highest-overlap still-available dressed index, then that column is masked so the result is a permutation. Each scan step is a single masked-row
argmaxovern_dressedcolumns, so the whole assignment isO(n_labels * n_dressed)— for a squareD = L**koverlap matrix that isO(L**(2k))versusassign_global_greedy()’sO(L**(3k))(a fullL**(2k)-entryargmaxat each ofL**ksteps). This is the SuperGrad / scqubits confidence-ordered greedy variant.Semantics vs. global-greedy. Identical to
assign_global_greedy()in the near-permutation regime (dispersive / weak hybridization), where each bare label has a clearly dominant dressed eigenstate. They can diverge on strongly-hybridized overlap matrices: global-greedy always commits the single largest remaining entry, whereas this visits rows in (original) row-max order. In exactly that regime the assignment is intrinsically ambiguous andChip.dressalready warns that bare labels are approximate. Passpolicy=assign_global_greedytolabel_eigensystem()for exact legacy semantics. Row-max ties are broken by ascending index (argsort).Margins (
top1 - top2per label) come from the unmasked matrix viatop_k, so they matchassign_global_greedy()’s margins and avoid a full per-row sort. Requiresn_labels <= n_dressed.- Parameters:
overlaps (Array)
- Return type:
tuple[Array, Array, Array]
- quchip.chip.dressing.label_eigensystem(evecs, reference, policy=<function assign_rowwise_greedy>)[source]¶
Pure-JAX labeling kernel.
- Parameters:
evecs (jnp.ndarray) –
(dim, n_dressed)eigenvectors as columns.reference (object) – Data-only object (
BareProductReferenceorEigenstateReference) defining what label keys mean.policy (callable) – Assignment function
overlaps -> (indices, chosen, margins). Defaultassign_rowwise_greedy()— the confidence-ordered row-greedy policy thatChip.dressruns (its sole live caller passes it explicitly).
- Return type:
Notes
Energies are looked up by the caller as
evals[labeling.indices[k]].policyis a static Python callable, resolved once at trace time, not a traced argument — underjax.jitit must be closed over or passed as astatic_argnamesentry, never as a dynamic (traced) argument.
- quchip.chip.dressing.track_path(evals_path, evecs_path, initial_reference, policy=<function assign_global_greedy>)[source]¶
Propagate a labeling along a parameter path of stacked eigensystems.
Step 0 is labeled against
initial_reference. For each subsequent step, the reference becomes the previous step’s selected eigvecs (anEigenstateReference). This is SuperGrad’s continuation trick generalized: the path is a stacked eigvec tensor (typically the output ofvmap(eigh)over a parameter grid), so it composes with any JAX-side parameter sweep.- Parameters:
evals_path (jnp.ndarray) –
(n_steps, n_dressed).evecs_path (jnp.ndarray) –
(n_steps, dim, n_dressed).initial_reference (object) – Bootstrap reference at step 0.
policy (callable) – Per-step assignment function. Defaults to
assign_global_greedy().
- Returns:
Stacked diagnostics including
swap_eventsper step boundary.- Return type:
- quchip.chip.dressing.phase_fixed_transform(labeling, evecs)[source]¶
Phase-fixed transform from Kronecker basis to labeled dressed basis.
Returns a complex
(dim, n_labels)matrix whose columns are the dressed eigenstates assigned tolabeling.keys, with each column phase-rotated so its largest-magnitude component is real-positive. Eigh’s default phase convention is gauge-arbitrary; this fix makesUa smooth function of physical parameters undervmap()and therefore safe forU.conj().T @ O @ U-style dressed-basis transforms (seeChipAnalysis.operator_in_dressed_basis()).Only meaningful when
labeling.indicesis a permutation. If anylabeling.duplicatesis True, two columns ofUwill be identical — caller’s responsibility to guard.- Parameters:
labeling (Labeling)
evecs (Array)
- Return type:
Array