quchip.engine.dressing¶
Assign dressed eigenvectors to bare or eigenstate references, and build dressed results.
label_eigensystem() supports greedy, global-greedy, and continuation
assignments. BareProductReference and EigenstateReference
supply vectors and labels, and compute_overlaps() computes their
overlaps. The assignment kernels are inspired by SuperGrad’s
compute_energy_map. DressedResult is the eager, label-keyed view
of one dressed eigensystem that Chip.dress() and EngineResult.dress()
return.
Functions
|
One-shot |
|
Global descending-overlap greedy with |
|
Confidence-ordered row-greedy assignment — |
|
|
|
Materialize the instantaneous dressed eigensystem of an engine snapshot. |
|
Return the phase factor that makes each column's assigned reference amplitude real and nonnegative. |
|
Pure-JAX labeling kernel. |
|
Diagonalize a static analysis result and assign its bare product labels. |
|
Build the eager label-keyed result shared by chip and resolved dressing. |
|
Express solver eigenvectors in the captured reference coordinates. |
|
Propagate a labeling along a parameter path of stacked eigensystems. |
|
Warn when the dressed state assigned to a label keeps less than 0.9 of its bare product. |
Classes
|
Bare product basis states in Kronecker order. |
|
Store a frozen snapshot of a dressed-state diagonalization. |
|
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.engine.dressing.Labeling(keys, indices, overlaps, margins, duplicates)[source]¶
Bases:
objectA labeled assignment of dressed eigenstates to user-meaningful keys.
The dataclass has only array fields and no embedded
Referenceobject, so it 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, soeigvals[labeling.indices[k]]is differentiable with respect to parameters that affecteigvals.- indices: Array¶
- overlaps: Array¶
- margins: Array¶
- duplicates: Array¶
- class quchip.engine.dressing.LabelingPath(keys, indices, overlaps, margins, duplicates, swap_events)[source]¶
Bases:
objectStacked labelings along a parameter path.
Compared with
Labeling, each array field has a leadingn_stepsaxis. Aswap_eventsarray shows where labels changed dressed-index between adjacent steps. A swap alone is only a reassignment. To distinguish avoided crossings from routine mode mixing, combine a swap with a margin collapse (marginsnear zero) at the same step.- indices: Array¶
- overlaps: Array¶
- margins: Array¶
- duplicates: Array¶
- swap_events: Array¶
- class quchip.engine.dressing.BareProductReference(dims, local_vectors=())[source]¶
Bases:
objectBare product basis states in Kronecker order.
Optional local vectors map each component’s energy states into its solver basis, and None denotes an identity factor. The full product matrix is never materialized; identity references reduce directly to
|evecs|**2.
- class quchip.engine.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.engine.dressing.reference_amplitudes(reference, evecs)[source]¶
Express solver eigenvectors in the captured reference coordinates.
Concrete inputs combine on the host, where they compile no device programs.
- quchip.engine.dressing.compute_overlaps(reference, evecs)[source]¶
|<ref_k | psi_j>|**2matrix, shape(n_labels, n_dressed).
- quchip.engine.dressing.assign_argmax(overlaps)[source]¶
One-shot
argmaxper row. Allows duplicate dressed-index assignments.Returns
(indices, chosen, margins). This policy is cheap andjit-clean, and matches SuperGrad’s default greedy mode. Use it in a weak-coupling regime where each bare label has a clearly dominant dressed eigenstate.
- quchip.engine.dressing.assign_global_greedy(overlaps)[source]¶
Global descending-overlap greedy with
lax.scanand masking.At each step, the function assigns the
(label, dressed_idx)pair with the highest remaining overlap. It then masks out that label’s row and that column, so this pure-JAX implementation assigns each label and dressed index at most once.Margins are computed from the unmasked overlap matrix, so they describe per-label confidence independent of assignment order.
Requires
n_labels <= n_dressed.
- quchip.engine.dressing.assign_rowwise_greedy(overlaps)[source]¶
Confidence-ordered row-greedy assignment —
O(n_labels * n_dressed).The function visits labels (rows) in descending row-max-overlap order. Each label takes its highest-overlap still-available dressed index, and the function masks that column, 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, this isO(L**(2k)).assign_global_greedy()isO(L**(3k))(a fullL**(2k)-entryargmaxat each ofL**ksteps). This is the SuperGrad / scqubits confidence-ordered greedy variant.Semantics vs. global-greedy. This function is identical to
assign_global_greedy()in the near-permutation regime (dispersive / weak hybridization), where each bare label has a clearly dominant dressed eigenstate. The two can diverge on strongly-hybridized overlap matrices. Global-greedy always commits the single largest remaining entry, whereas this function visits rows in (original) row-max order. In exactly that regime the assignment is intrinsically ambiguous, andChip.dressalready warns that bare labels are approximate. For global-greedy ordering, passpolicy=assign_global_greedytolabel_eigensystem(). Row-max ties are broken by ascending index (argsort).Margins (
top1 - top2per label) come from the unmasked matrix viatop_k, so they match the margins ofassign_global_greedy(). Requiresn_labels <= n_dressed.
- quchip.engine.dressing.warn_weak_assignment(label, overlap)[source]¶
Warn when the dressed state assigned to a label keeps less than 0.9 of its bare product.
Every query that selects the dressed state of a label calls this. A traced overlap does not warn. The warning names the first caller outside quchip.
- quchip.engine.dressing.gauge_phases(amplitudes, indices)[source]¶
Return the phase factor that makes each column’s assigned reference amplitude real and nonnegative.
- Parameters:
amplitudes (array_like) –
(n_labels, n_dressed)amplitudes<ref_k|psi_j>of the dressed columns.indices (array_like) – Column assigned to each reference label.
Notes
The anchor of a column is its amplitude on the label assigned to it. A one-to-one assignment can give a column whose assigned amplitude is zero. When that amplitude is not above a floor, the square root of the floating-point epsilon, and for an unassigned column, the anchor is the first amplitude within a relative
1e-6of the column’s largest magnitude. The factor of a column isconj(anchor) / |anchor|. The rule is piecewise: the phase can jump where the assigned amplitude crosses the floor or where the fallback selects another amplitude. A phase cannot fix a rotation, so an exactly degenerate eigenspace keeps the basis of the eigensolver.
- quchip.engine.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).
Notes
The caller gets energies as
evals[labeling.indices[k]].policyis a static Python callable resolved once at trace time, not a traced argument. Underjax.jit, close overpolicyor pass it as astatic_argnamesentry. Never pass it as a dynamic (traced) argument.
- quchip.engine.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. At each later step, the reference becomes the previous step’s selected eigvecs (anEigenstateReference). This continuation method accepts a stacked eigvec tensor (usually 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:
- class quchip.engine.dressing.DressedResult(eigenvalues, state_map, dressed_eigenvalues, assignment_overlaps, hybridized_labels, bare_labels, bare_labels_by_dressed_index, eigenvector_matrix=None, overlap_threshold=0.5, labeling='DE', _eigensystem=None)[source]¶
Bases:
objectStore a frozen snapshot of a dressed-state diagonalization.
- Variables:
eigenvalues (array-like) – Sorted dressed eigenvalues in GHz.
eigenstates (array-like) – Backend eigenstate objects in the same order as
eigenvalues, with the phases ofeigenvector_matrix. They are materialized lazily on first access from the underlyingEigensystemData. The dressing and sweep hot path never touches them, so the backend builds per-column kets only on request.state_map (dict[tuple[int, ...], int]) – Map from each bare product-basis label (one int per device) to the dressed eigenstate index with the largest overlap.
dressed_eigenvalues (dict[tuple[int, ...], Any]) – Dressed eigenvalue for each assigned bare label, the direct lookup path for
Chip.energy().assignment_overlaps (dict[tuple[int, ...], float]) –
|⟨bare|dressed⟩|²of each assignment. Values belowoverlap_thresholdflag hybridization.hybridized_labels (tuple[tuple[int, ...], ...]) – Bare labels whose assignment quality is below
overlap_threshold. A non-empty tuple triggers a user warning at dress time.bare_labels (tuple[tuple[int, ...], ...]) – Labels of the product energy levels exposed by the chip’s resolved local dimensions, in chip order.
bare_labels_by_dressed_index (dict[int, tuple[int, ...]]) – Inverse of
state_map: dressed index → assigned bare label.eigenvector_matrix (array-like or None) – Dressed eigenvectors as columns, in the resolved solver basis, used by
ChipAnalysis.operator_in_dressed_basis()andChipAnalysis.state_components(). Each column has a real, nonnegative amplitude on its assigned bare state (gauge_phases()).overlap_threshold (float) – Minimum overlap for a confident assignment.
labeling (str) – Algorithm id (currently only
"DE"). It resolves to the confidence-ordered row-greedy overlap-matching policy run byChipAnalysis.dress()(assign_rowwise_greedy()).
- quchip.engine.dressing.materialize_dressed_result(eigenvalues, eigenvector_matrix, eigensystem, kernel_labeling, *, overlap_threshold, labeling, warning_stacklevel)[source]¶
Build the eager label-keyed result shared by chip and resolved dressing.
- quchip.engine.dressing.dress_engine_result(result, *, at_time=None, overlap_threshold=0.5, labeling='DE')[source]¶
Materialize the instantaneous dressed eigensystem of an engine snapshot.
- quchip.engine.dressing.labeled_eigensystem(engine_result, backend)[source]¶
Diagonalize a static analysis result and assign its bare product labels.
Returns
(eigenvalues, eigenvector_matrix, eigensystem, labeling); traced Hamiltonians stay traced. Each eigenvector follows the phase convention ofgauge_phases().