Hooks¶
Extra-check hooks referenced by hook.
A hook is a "module:function" path, resolved dynamically by
circuitgenome.recognizer.subcircuit_recognizer.recognize(). It is
called once per base-template match with (assignment, pins, netlist):
assignment–dict[str, Device]mapping eachPatternDeviceref to the actual matched device.pins– the base template’s resolvedpins, before any hook extension.netlist– the fullParsedNetlistbeing recognized.
It returns either None (reject the match) or a
HookMatch (accept, optionally
appending devices/pins) – see HookMatch
for the full contract.
- circuitgenome.recognizer.hooks.constructed_bias_legs(assignment, pins, netlist)[source]¶
Discover the legs of a constructed multi-reference bias generator.
Hook for the
constructed_biaspattern (config/opamp_patterns.yaml). The synthesizer constructs its bias generator per combination (circuitgenome.synthesizer.bias_construction.construct_bias_generation()): an NMOS master reference onibias(the base template’smref), NMOS-referenced legs mirroring it, and – when any rail needs a PMOS-referenced level – aprefbranch whose diode-connected PMOS gates further PMOS-referenced legs. This hook discovers all of them:Pass 1 (NMOS-referenced): every nmos with gate on
mref’s diode node (theibiasnet) and source onmref’s source (gnd) mirrors the master. What sits on its drain names the leg:a plain diode-connected pmos (
d == g,s == b): a vdd-flavored leg or theprefbranch’s diode (structurally identical – both are claimed; which is which doesn’t matter for sizing); the pmos-diode node is remembered as a potential PMOS-side reference gate;a riding pmos diode (
d == gon the drain,son an internal node) whose source returns to its bulk supply through an unclaimed resistor: a cascode_vdd leg (diode + floor resistor,out = vdd - |V_GSP| - I*R) – all three devices are claimed;an nmos cascode (source on the drain node) topped by a plain pmos diode: the cascoded pref branch (the cascode pins the mirror’s Vds; its gate rides the wide-swing
ncasclevel, whose generator branch is claimed by pass 2 as an ordinary gnd-flavored leg) – the cascode and diode are claimed, the diode node becomes a reference gate;nothing: a bare mirror, claimed alone – a current-sink leg into a consumer’s own diode.
Pass 2 (PMOS-referenced): every pmos gated on a pass-1 pmos-diode node with source on that diode’s supply is a leg only if its drain hosts a diode-connected nmos (a gnd-flavored leg – including the pref branch’s
ncascgenerator – a cascode_gnd leg when the diode rides an unclaimed resistor to gnd, or a current-source leg into a mirror tail’s own reference diode) or a resistor returning tomref’s gnd (a tunable resistor leg). The drain condition keeps consumer devices out: a second-stage PMOS gated by a vdd-flavored rail has neither on its drain.
Returns
Nonewhen neither pass finds constructed-only evidence (no PMOS-referenced leg and no cascode_vdd leg): the structure is then the exact shapediode_connected_mosfet_bias_legs()discovers, and that pattern (listed after this one) claims it instead – keeping legacy single-flavor netlists recognized under their historical names.- Parameters:
- Returns:
A
HookMatchwith every discovered leg’s devices inextra_devicesand its output net aslegN_outinextra_pins(1-indexed by discovery order; rail indices are not a structural property of a leg), plusvddfrom the first pmos diode found.Noneif no PMOS-referenced leg exists.- Return type:
HookMatch | None
- circuitgenome.recognizer.hooks.diode_connected_mosfet_bias_legs(assignment, pins, netlist)[source]¶
Discover the output “legs” attached to a diode-connected bias reference.
Hook for the
diode_connected_mosfet_biaspattern (config/opamp_patterns.yaml). That pattern’s base template matches only a single diode-connected nmos (template refmref:d == g, tied togndvias/b) – the shared reference of the historicaldiode_connected_mosfet_biasvariant, which theconstructed_biaspattern’sconstructed_bias_legs()also shares (that hook rejects the purely-NMOS-referenced shape so this one can claim it under the historical name).This hook does the rest: it walks the netlist looking for “legs” – self-contained 2-device groups that mirror
mrefand deliver one output rail. A leg consists of:an nmos device whose gate ties to
mref’s diode-connected node (mref.g==mref.d, i.e. theibiasnet) and whose source/bulk tie tomref.s(thegndnet) – this mirrorsmref’s reference current; paired witha pmos device that is itself diode-connected (
d == g) at that nmos leg’s drain, withs == b(its own supply net) – this is the leg’s output node.
Each discovered leg’s nmos+pmos pair is appended to
HookMatch.extra_devices, and its output net is recorded aslegN_outinHookMatch.extra_pins(1-indexed by discovery order – which of the eight canonical bias rails (out1..``out8``) a leg corresponds to is not a structural property of the leg itself, and is left for FBR/topology context to determine if needed). The first discovered leg’s supply net is also recorded asvdd.- Parameters:
- Returns:
A
HookMatchwith one(nmos, pmos)pair per discovered leg appended toextra_devices, andlegN_out/vddentries inextra_pins. If zero legs are found, still returnsHookMatch(extra_devices=[], extra_pins={})– a constructed bias generator with no consumed rails collapses to exactly this baremref, with no legs to find. A spurious bare-diode-connected-nmos match elsewhere (e.g.current_mirror_tail_nmos’sm1) is harmless: itsibiaspin won’t equal the realibiasnet, so_connectivity_score()ranks it below the genuine bias-generation candidate.- Return type:
HookMatch | None
- circuitgenome.recognizer.hooks.magic_battery_bias_legs(assignment, pins, netlist)[source]¶
Discover the output “legs” attached to a magic-battery bias reference.
Hook for the
magic_battery_biaspattern (config/opamp_patterns.yaml). That pattern’s base template matches only a single diode-connected pmos (template refmref:d == g, tied tovddvias/b). This mirrorsdiode_connected_mosfet_bias_legs()with polarities flipped: a leg here is a(pmos, nmos)pair, where the pmos mirrorsmreffrom thevddrail and the nmos is diode-connected at the leg’s output node.A leg consists of:
a pmos device whose gate ties to
mref’s diode-connected node (mref.g==mref.d, i.e. theibiasnet) and whose source/bulk tie tomref.s(thevddnet) – this mirrorsmref’s reference current; paired withan nmos device that is itself diode-connected (
d == g) at that pmos leg’s drain, withs == b(its own reference net) – this is the leg’s output node.
Each discovered leg’s pmos+nmos pair is appended to
HookMatch.extra_devices, and its output net is recorded aslegN_outinHookMatch.extra_pins(1-indexed by discovery order). The first discovered leg’s nmos-side reference net is also recorded asgnd.- Parameters:
- Returns:
A
HookMatchwith one(pmos, nmos)pair per discovered leg appended toextra_devices, andlegN_out/gndentries inextra_pins. ReturnsNone(rejecting the match) if zero legs are found – a bare diode-connected pmos with no legs is structurally identical toresistor_bias’smrefin the same 0-rail case, anddiode_connected_mosfet_biasalready claims it then.- Return type:
HookMatch | None
- circuitgenome.recognizer.hooks.resistor_bias_legs(assignment, pins, netlist)[source]¶
Discover the output “legs” attached to a resistor-bias reference.
Hook for the
resistor_biaspattern (config/opamp_patterns.yaml). Likemagic_battery_bias_legs(), the base template matches only a single diode-connected pmos (mref:d == g, tied tovddvias/b). Here, each leg is a(pmos, resistor)pair: a pmos mirrorsmreffrom thevddrail, and a resistor drops the leg’s output node down to itsgnd-referenced terminal.A leg consists of:
a pmos device whose gate ties to
mref’s diode-connected node (mref.g==mref.d, i.e. theibiasnet) and whose source/bulk tie tomref.s(thevddnet) – this mirrorsmref’s reference current; paired witha resistor device with one terminal at that pmos leg’s drain – this is the leg’s output node, and the resistor’s other terminal is the leg’s
gndreference.
Each discovered leg’s pmos+resistor pair is appended to
HookMatch.extra_devices, and its output net is recorded aslegN_outinHookMatch.extra_pins(1-indexed by discovery order). The first discovered leg’s resistor-side reference net is also recorded asgnd.- Parameters:
- Returns:
A
HookMatchwith one(pmos, resistor)pair per discovered leg appended toextra_devices, andlegN_out/gndentries inextra_pins. ReturnsNone(rejecting the match) if zero legs are found – a bare diode-connected pmos with no legs is structurally identical tomagic_battery_bias’smrefin the same 0-rail case, anddiode_connected_mosfet_biasalready claims it then.- Return type:
HookMatch | None
- circuitgenome.recognizer.hooks.resistor_tail_vdd_check(assignment, pins, netlist)[source]¶
Accept only if the matched resistor’s
t1is the globalvdd!rail.Hook for the
resistor_tail_vddpattern (config/opamp_patterns.yaml). That pattern’s template is a single, unconstrained resistor – without this check it would match every resistor in the netlist (e.g. aresistor_load_*’s, aresistor_bias’s, or a degenerated input pair’s degeneration resistor), most of which have nothing to do with the tail current source.- Parameters:
- Returns:
HookMatch(extra_devices=[], extra_pins={})ifr1.t1 == "vdd!", elseNone(reject).- Return type:
HookMatch | None
- circuitgenome.recognizer.hooks.resistor_tail_gnd_check(assignment, pins, netlist)[source]¶
Accept only if the matched resistor’s
t2is the globalgnd!rail.Mirror of
resistor_tail_vdd_check()for theresistor_tail_gndpattern.- Parameters:
- Returns:
HookMatch(extra_devices=[], extra_pins={})ifr1.t2 == "gnd!", elseNone(reject).- Return type:
HookMatch | None