Functional Block Recognizer¶
Layer 2 — Functional Block Recognizer (FBR).
Two modes:
Topology mode (
assign_slots()): requires aTopologyTemplate. Assigns each slot to its best-matching SR candidate using expected net connectivity (_connectivity_score). Handles repeated-category slots (e.g. twocompensationslots in a fully-differential topology).Topology-free mode (
group_by_category()): no topology needed. Groups SR structures bycircuit_block(outer) andcategory(inner) using a three-pass algorithm: (1) filter pass for single-categorygain_stage_*blocks — three classes of spurious candidates are dropped: (A)inpin on an external port (bias nmos re-matched as a gain stage); (B)biaspin on an external port (bias mirror pmos re-matched); (C) any nmos device whose source is notgnd!(cascode load devices); (2) multi-categorygain_stage_*pass (gain_stage_1) — re-sortsinput_paircandidates by the count of distinct external ports among{in1, in2}(real differential pairs have both signal inputs on distinct external ports; bias mirrors and spurious stage-device pairs do not), then uses the topinput_pairresult to guideloadandtail_currentvia signal-chain following (load.in1/in2matched againstinput_pair.out1/out2;tail_current.outmatched againstinput_pair.tail), with external-port exclusion filters applied to each category first; (3) split pass — single-categorygain_stage_*blocks with more than one remaining candidate are split into consecutivegain_stage_Ngroups ordered by ascending external-port adjacency, enabling disambiguation of three-stage opamp stages without a topology.
- circuitgenome.recognizer.functional_block_recognizer.group_by_category(sr_result, netlist)[source]¶
Group SR structures by circuit block and category without a topology.
Produces a
CategoryGroupResultwhosegroupsdict is keyed first bycircuit_block(e.g."gain_stage_1","gain_stage_2","bias") then bycategory(e.g."input_pair","load"). Structures withcircuit_block=None(primitives, structural composites) are excluded.Two-pass algorithm:
Filter pass — for every
gain_stage_*candidate that has aninpin, check whether that pin’s net is an external port. Real gain stages receive their input from an internal intermediate net (the previous stage’s output); spurious matches arise when an input-pair nmos or a bias device is re-matched by a gain-stage pattern, puttingin1/in2oribiason theinpin. Removing those candidates eliminates the majority of SR noise before the split pass.Split pass —
gain_stage_*blocks that have exactly one remaining category and more than one remaining candidate are split into consecutivegain_stage_Ngroups ordered by ascending_external_port_score(). The instance whoseoutpin connects to the external output port scores highest and is promoted to the highest-numbered stage. Blocks with multiple categories (e.g.gain_stage_1which holdsinput_pair,load, andtail_current) are never split; their candidates are simply sorted descending and the top-1 is the best topology-free guess.
- Parameters:
sr_result (SubcircuitRecognitionResult) – Layer 1 output from
recognize().netlist (ParsedNetlist) – The parsed netlist, used to retrieve external port names for
_external_port_score().
- Returns:
CategoryGroupResultwith grouped, ranked candidates andunrecognized_devicespassed through unchanged.- Return type:
- circuitgenome.recognizer.functional_block_recognizer.assign_slots(sr_result, topology)[source]¶
Assign each
Slotintopology.slotsto its best-matching SR candidate.For each slot, candidates are filtered by
category==category, then ranked by_connectivity_score()againstslot_connections()for that slot. The highest-scoring candidate is assigned (design doc section 6.3, steps 2-3). A slot with no candidates of its category is silently omitted fromslot_assignments.Connectivity scoring is applied even when a category has only one slot: SR’s patterns can structurally overlap (e.g.
current_mirror_tail_nmosalso matches the bias-generation reference’s diode-connected pair), so a category can have multiple candidates regardless of how many slots need it. Once a candidate is assigned to a slot its id is added toassigned_idsso it cannot be double-assigned to a second slot of the same category (e.g.comp_p/comp_nintwo_stage_opamp_fully_differential).- Parameters:
sr_result (SubcircuitRecognitionResult) – Layer 1’s output – every candidate
RecognizedStructure, possibly with multiple overlapping candidates per category (seeSubcircuitRecognitionResult).topology (TopologyTemplate) – The
TopologyTemplatethat the recognized netlist is known to have been synthesized from – supplies both the slots to fill (slots) and each slot’s expected wiring (slot_connections()).
- Returns:
A
FunctionalBlockRecognitionResultwith oneSlotAssignmentper filled slot (slot_assignments), every unassigned candidate structure inunassigned_structures, andunrecognized_devicespassed through unchanged fromsr_result.- Return type: