quchip.chip.transformations.plumbing¶
Shared control-plane and chip-rebuild plumbing for quchip.chip.transformations.
Every transformation of shape Chip -> (Chip + diagnostics) faces the same
control-plane problem: a control line whose target has no image in the reduced
model (its device was eliminated, or its coupling touched the eliminated mode)
must either be converted by a registered retarget rule or fail fast. It also
rebuilds a reduced Chip from surviving devices and
couplings, reattaches the converted equipment, and detaches the intermediate
clone. These four steps are identical across the device and coupling reduction
paths, so they live here as single-purpose functions reused by any
Chip -> EliminationResult transformation without touching dispatch — the
same shared-plumbing role quchip.chip.retarget plays for the rule
lookup itself.
The two reduction paths differ only in how a doomed line is detected and what
fail-fast message it raises; both feed a per-path classify closure into
plan_stranded_lines(), which owns the detection order and the rule
lookup.
Functions
|
Detach the intermediate clone from the surviving devices deterministically. |
|
Partition control lines into survivors and a retarget plan, failing fast on missing rules. |
|
Apply the retarget plan and attach the survivor plus converted lines to the reduced chip. |
|
Construct a reduced chip carrying the source chip's frame, RWA, backend, and baths. |
Classes
|
One doomed control line's retarget target and its fail-fast message. |
- class quchip.chip.transformations.plumbing.StrandedLine(rule_target, missing_rule_message)[source]¶
Bases:
objectOne doomed control line’s retarget target and its fail-fast message.
- rule_target¶
The eliminated target a converter would retarget the line onto — a coupling object for a coupling reduction, a device or an edge coupling for a device reduction. Its type drives the MRO lookup in
lookup_retarget_rule().- Type:
Any
- missing_rule_message¶
The exact
ValueErrormessageplan_stranded_lines()raises when no rule converts the line. Each reduction path builds its own message so the wording matches the target it eliminated.- Type:
- quchip.chip.transformations.plumbing.plan_stranded_lines(equipment, classify, result_kind)[source]¶
Partition control lines into survivors and a retarget plan, failing fast on missing rules.
Each line is classified: a survivor (
classifyreturnsNone) passes through untouched; a doomed line (classifyreturns aStrandedLine) has its converter looked up now, before any fold work, so a missing rule raises immediately. Rule application is deferred toreattach_equipment()(a converter may need an edge the reduction has not emitted yet), so this pass only detects and fails fast — the same ordering the device and coupling paths rely on.- Parameters:
equipment (Any) – The source chip’s
ControlEquipment, orNonewhen no equipment is wired.classify (Callable[[Any], StrandedLine | None]) –
classify(line) -> StrandedLine | None:Nonemarks a survivor, aStrandedLinemarks a doomed line.result_kind (str) – The reduction’s result kind (
"edge","leaf-fold", or"crosskerr"), matched exactly by the rule lookup.
- Returns:
(survivor_lines, retarget_plan)in original line order:survivor_linesis the list of pass-through lines,retarget_planis a list of(line, rule)pairs.- Return type:
- Raises:
ValueError – With the doomed line’s
missing_rule_messagewhen no registered rule converts it.
- quchip.chip.transformations.plumbing.rebuild_chip(source_chip, *, devices, couplings)[source]¶
Construct a reduced chip carrying the source chip’s frame, RWA, backend, and baths.
The label, frame (deep-copied when a per-device dict), RWA flag, backend, and baths are copied off
source_chip;devicesandcouplingsare the reduction’s survivors. An emptycouplingsbecomesNone(a chip with no couplings), matching the constructor’s own convention.- Parameters:
- Returns:
The reduced chip, before control equipment is attached.
- Return type:
- quchip.chip.transformations.plumbing.reattach_equipment(source_chip, final_chip, equipment, survivor_lines, retarget_plan, *, mode_label, result_kind, edges, notes)[source]¶
Apply the retarget plan and attach the survivor plus converted lines to the reduced chip.
A no-op when
equipment is None. Otherwise each(line, rule)inretarget_planis converted against aRetargetContextbuilt from the reduction’smode_label,result_kind, and emittededges; every converter’s note is appended tonotes. The survivor lines and the converted lines are then combined and connected tofinal_chip.- Parameters:
source_chip (Any) – The original (pre-reduction) chip the converters read from.
final_chip (Any) – The reduced chip the equipment is attached to.
equipment (Any) – The source chip’s control equipment, or
None.survivor_lines (list[Any]) – Lines that pass through unchanged, from
plan_stranded_lines().retarget_plan (list[tuple[Any, Any]]) –
(line, rule)pairs fromplan_stranded_lines().mode_label (str) – The eliminated device (or coupling) label, for the retarget context.
result_kind (str) – The reduction’s result kind, for the retarget context.
edges (Any) – The per-pair emitted-edge entries (
"edge"/"crosskerr") orNone("leaf-fold"), for the retarget context.notes (list[str]) – The result’s note list, extended in place with each converter’s note.
- Return type:
None