quchip.chip.retarget

Retarget registry: convert control lines stranded by eliminate() (spec §6.4).

A control line whose target has no image in the reduced model — its device was eliminated, or its coupling touched the eliminated mode — would otherwise force the user to unwire it. A per-(drive type, target type, result kind) registry lets a converter replace such a line with equivalent lines wired to the reduced chip instead, e.g. a FluxDrive on an eliminated coupler becomes a ParametricDrive pumping each emitted edge. Extending this registry never touches eliminate() itself; a target with no registered rule still raises the fail-fast unwire/keep error.

Functions

lookup_retarget_rule(drive_type, ...)

MRO-aware registry lookup: the most specific (drive, target) pair wins.

register_retarget_rule(drive_type, ...)

Register a converter for (drive type, eliminated-target type, result kind).

Classes

RetargetContext(chip, reduced_chip, ...)

Everything a converter may consult; built by eliminate() after the fold.

RetargetResult(lines[, transforms, note])

A converter's replacement lines, extra signal-chain transforms, and fold note.

class quchip.chip.retarget.RetargetContext(chip, reduced_chip, mode_label, result_kind, edges)[source]

Bases: object

Everything a converter may consult; built by eliminate() after the fold.

Parameters:
chip

The original chip (read-only; pre-elimination).

Type:

Any

reduced_chip

The final reduced chip. Every emitted or upgraded edge already exists on it; control equipment is not yet attached.

Type:

Any

mode_label

Label of the eliminated device (or coupling, for "crosskerr").

Type:

str

result_kind

Structure of what the reduction produced: "edge" when the eliminated device mediated exchange between two or more survivors (one effective edge per survivor pair), "leaf-fold" for a single-survivor leaf, "crosskerr" for a coupling target.

Type:

str

edges

For "edge" and "crosskerr": the per-pair reduction entries, keyed (label_a, label_b) in emission order, each carrying at least "folded_into" (the edge’s label on the reduced chip) and — for "edge" — the exchange bookkeeping ("j_eff", "dJ_domega_c", …). Always pair-keyed regardless of how many pairs there are: one entry is simply the two-survivor case, not a different shape. None for "leaf-fold".

Type:

dict[tuple[str, str], dict[str, Any]] | None

chip: Any
reduced_chip: Any
mode_label: str
result_kind: str
edges: dict[tuple[str, str], dict[str, Any]] | None
class quchip.chip.retarget.RetargetResult(lines, transforms=(), note='')[source]

Bases: object

A converter’s replacement lines, extra signal-chain transforms, and fold note.

Parameters:
lines

Replacement control lines. Exactly one of them must keep the original line’s label, so existing Crosstalk/Delay entries keyed by it — and replayed schedule() calls — stay valid; any further lines carry derived labels.

Type:

tuple[Any, …]

transforms

Signal-chain transforms to append, in application order (the equipment applies its chain front to back — a transform that feeds a line must precede one that scales it).

Type:

tuple[Any, …]

note

One fold-report line, appended to EliminationResult.notes.

Type:

str

lines: tuple[Any, ...]
transforms: tuple[Any, ...] = ()
note: str = ''
quchip.chip.retarget.register_retarget_rule(drive_type, target_type, result_kind, rule)[source]

Register a converter for (drive type, eliminated-target type, result kind).

Lookup (lookup_retarget_rule()) walks both types’ MROs, so a rule registered for a base type also covers its subclasses; result_kind matches exactly. This is the extension point for teaching eliminate() to carry a new kind of stranded control line without modifying it.

Parameters:
  • drive_type (type) – Control-line class the rule handles.

  • target_type (type) – Eliminated-target class the rule handles: a device type (the eliminated mode itself) for "edge"/"leaf-fold".

  • result_kind (str) – "edge", "leaf-fold", or "crosskerr".

  • rule (callable) – rule(line, ctx: RetargetContext) -> RetargetResult.

Return type:

None

quchip.chip.retarget.lookup_retarget_rule(drive_type, target_type, result_kind)[source]

MRO-aware registry lookup: the most specific (drive, target) pair wins.

Parameters:
  • drive_type (type)

  • target_type (type)

  • result_kind (str)

Return type:

Any | None