quchip.utils.labeling

Component labels and lookup by object or label.

A component without an explicit label gets "{prefix}_{n}". Each prefix has a process-wide counter starting at zero. Labels identify components in a chip. resolve_label() accepts the component or its label. Use reset_label_counters() to get deterministic labels in tests.

Functions

auto_label(prefix)

Return the next "{prefix}_{n}" label, where each prefix starts at zero.

bare_label_from_mapping(device_labels, ...)

Build a bare-state tuple in device_labels order from a partial mapping.

merge_labeled_values(mapping, kwargs)

Merge object-or-label keys and keyword arguments into a dict with label keys.

reset_label_counters()

Reset the process-wide label counters, usually in test fixtures.

resolve_label(obj)

Return a string label from a string or a labeled component.

top_components(eigenvector_matrix, ...)

Return the top n bare-basis probabilities of a dressed eigenvector.

Classes

LabelKeyedDict

Result mapping with label keys that also accepts component objects.

quchip.utils.labeling.auto_label(prefix)[source]

Return the next "{prefix}_{n}" label, where each prefix starts at zero.

Parameters:

prefix (str) – Prefix of the component type. Each prefix has its own process-wide counter.

quchip.utils.labeling.reset_label_counters()[source]

Reset the process-wide label counters, usually in test fixtures.

quchip.utils.labeling.resolve_label(obj)[source]

Return a string label from a string or a labeled component.

Raise TypeError if the object has no usable label.

Parameters:

obj (str or object) – A label string, returned unchanged, or an object with a non-None label attribute.

quchip.utils.labeling.merge_labeled_values(mapping, kwargs)[source]

Merge object-or-label keys and keyword arguments into a dict with label keys.

Duplicate labels raise ValueError, including a label supplied through both inputs. Values pass through unchanged, and callers validate their types and bounds.

quchip.utils.labeling.bare_label_from_mapping(device_labels, mapping, kwargs)[source]

Build a bare-state tuple in device_labels order from a partial mapping.

Keys can be devices or labels. Unspecified devices get the default Fock index zero. Unknown or duplicate labels raise ValueError. Callers validate values.

class quchip.utils.labeling.LabelKeyedDict[source]

Bases: dict

Result mapping with label keys that also accepts component objects.

Tuple keys with two elements match in each order. Iteration and serialization show the stored keys.

get(key, default=None)[source]

Return the value for key, or default if key is absent (through __getitem__()).

quchip.utils.labeling.top_components(eigenvector_matrix, bare_labels, dressed_idx, n)[source]

Return the top n bare-basis probabilities of a dressed eigenvector.

It pairs the squared amplitudes from column dressed_idx with bare labels in descending order. It requires a concrete eigenvector matrix.