### Install and launch the Visualizer Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/modules/visualizer.rst Install the `viz` extra and start the Streamlit server with the `circuitgenome visualize` command. The command opens the app in your browser. ```default pip install circuitgenome[viz] circuitgenome visualize ``` -------------------------------- ### Install viz extra and launch visualizer Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/usage/cli.rst One-time installation of the viz extra is required before running the visualizer. The command launches the Streamlit web UI for browsing topologies and module variants. ```bash pip install circuitgenome[viz] # one-time: the visualizer needs the viz extra circuitgenome visualize ``` -------------------------------- ### Install CircuitGenome from source Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/installation.rst Clones the repository and performs an editable install so changes to the source are picked up without reinstalling. ```bash git clone https://github.com/analog-ml/CircuitGenome.git cd CircuitGenome pip install -e . ``` -------------------------------- ### Setup: query output slots, mirror refs, cascode load, and grid rule Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/gmid/geometry_explained.html Runs before the per-device loop. Calls _output_stage_slots() and _mirror_tied_refs() to get the output-stage slots and mirror-tied references, then checks whether any load device has a CASCODE role. The comment notes the grid rule is tech.width.snap, a GridSpec method that rounds to a step and clamps into [min, max]. ```python out_slots = _output_stage_slots(slot_transistors) # Part 4a mirror_tied = _mirror_tied_refs(all_transistors) # Part 4b cascode_load = any(intents[d.ref].role == CASCODE for d in ...load...) # the grid rule itself is tech.width.snap — a GridSpec method (models.py): # v = round(x / step) * step; clamped into [min, max] ``` -------------------------------- ### Example input: all_transistors and cascode_refs Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/gmid/intent_explained.html Shows a sample circuit with two transistors (M1 and M5) and an empty cascode set, used for the hand-traced walkthrough. ```python all_transistors = { "M1": (input_pair_device, "input_pair"), # is_signal_device → True "M5": (load_device, "load"), # is_signal_device → False } cascode_refs = set() # nothing cascoded here ``` -------------------------------- ### Install circuitgenome from PyPI Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/installation.rst Installs the latest release of the circuitgenome package from the Python Package Index. Requires Python 3.9 or later; PyYAML ≥ 6.0 is installed automatically. ```bash pip install circuitgenome ``` -------------------------------- ### Run tests with pip (pip 25.1+) Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/installation.rst Installs the dev group and runs the test suite with pip 25.1 or later. ```bash pip install -e . --group dev pytest tests/ ``` -------------------------------- ### Load custom modules and topologies and enumerate circuits Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/extending.rst Pass file paths directly to load_modules and load_topologies, then iterate over the generated circuits with enumerate_circuits. The example prints the name of each circuit. ```python from circuitgenome.synthesizer.loader import load_modules, load_topologies from circuitgenome.synthesizer import enumerate_circuits modules = load_modules("my_modules.yaml") topologies = load_topologies("my_topologies.yaml") for circuit in enumerate_circuits(topologies[0], modules): print(circuit.name) ``` -------------------------------- ### Parse a sized SPICE .subckt with parse() and recognize() Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/api/recognizer/netlist_parser.rst Parses a flat SPICE .subckt block (with sized MOSFET lines) into a ParsedNetlist, then prints device type and width parameter, and runs topology recognition. The example uses the sky130_fd_pr__pfet_01v8 model and shows that sizing parameters ride along on the device params. ```python from circuitgenome.recognizer import parse, recognize parsed = parse(''' .subckt ota in1 in2 out vdd! gnd! m1 net1 in1 tail vdd! sky130_fd_pr__pfet_01v8 W=4u L=0.5u nf=2 m=1 m2 net2 in2 tail vdd! sky130_fd_pr__pfet_01v8 W=4u L=0.5u nf=2 m=1 .ends''') print(parsed.devices[0].type) # "pmos" print(parsed.devices[0].params["W"]) # "4u" result = recognize(parsed) # topology match, sizes ride along ``` -------------------------------- ### MOSFET line example Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/recognizer/netlist_parser.html Example of a sized MOSFET line in SPICE netlist format. The bare tokens are positional arguments, while the W=, L=, nf=, and m= tokens are named parameters. ```spice m1 net1 in1 tail vdd! sky130_fd_pr__pfet_01v8 W=4u L=0.5u nf=2 m=1 ``` -------------------------------- ### Load topologies with load_topologies Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/api/loader.rst Loads topology templates from a YAML file, defaulting to the built-in opamp_topologies.yaml. Returns a list of TopologyTemplate objects. The example iterates over the loaded topologies and prints each topology's name and config. ```python from circuitgenome.synthesizer.loader import load_topologies for topo in load_topologies(): print(topo.name, topo.config) ``` -------------------------------- ### Traced example of GridSpec.snap() with real numbers Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/gmid/dc-bias-feasibility_explained.html Shows the step-by-step calculation of snap() with step=0.1, min=0.5, max=100, and input 2.34, resulting in 2.3 µm. ```text round(2.34 / 0.1) * 0.1 = round(23.4) * 0.1 = 23 * 0.1 = 2.3 µm max(2.3, 0.5) = 2.3 min(2.3, 100) = 2.3 -> 2.3 µm ``` -------------------------------- ### M5 TransistorIntent example Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/gmid/intent_explained.html The resulting TransistorIntent for M5, with a concrete gm_id of 10.0 indicating a chosen strong inversion region. ```python TransistorIntent("M5", "active_load", CURRENT_SOURCE, 10.0, 4.0, "First-stage active …") ``` -------------------------------- ### Spec YAML input for load_spec() Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/loader_explained.html Example spec YAML file with five keys. The `provenance` key is not a SizingSpec field and is dropped by the lenient parser. ```yaml vdd: 5.0 vss: 0.0 ibias: 1.0e-5 cl: 10.0e-12 provenance: "hand-tuned 2026" # not a SizingSpec field ``` -------------------------------- ### Numerical example: R = 0.5 / 0.002 S = 250 Ω and gm1_factor = 0.667 Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/gmid/resistors_explained.html Shows a numerical example with gm1 = 2 mS and degeneration_factor = 0.5. The resistor value is 250 Ω and the gm1_factor is 0.667, which matches the textbook degenerated-gm formula gm/(1+gm·R). The 250 Ω resistor cuts the pair's effective gm to two-thirds. ```text R = 0.5 / 0.002 S = 250 Ω gm1_factor = 1 / (1 + 0.5) = 0.667 ``` -------------------------------- ### M1 TransistorIntent example Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/gmid/intent_explained.html The resulting TransistorIntent for M1, showing gm_id as None because its inversion region will be solved later. ```python TransistorIntent("M1", "input_stage", SIGNAL, None, 2.0, "Convert the diff …") ``` -------------------------------- ### circuitgenome recognize sample output Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/usage/cli.rst Example output from `circuitgenome recognize` for a topology-free two-stage circuit. Lists six recognized structures with their device names. ```default Netlist: circuit_0001_flat.ckt Recognized structures (6): [input_pair] differential_pair_pmos (devices: m1_input_pair, m2_input_pair) [load] active_load_nmos (devices: m1_load, m2_load) [tail_current] current_mirror_tail_pmos (devices: m1_tail_current, m2_tail_current) [bias_generation] diode_connected_mosfet_bias (devices: mn1_bias_gen) [second_stage] common_source (devices: mn_second_stage, mp_second_stage) [compensation] miller_cap (devices: c1_comp) ``` -------------------------------- ### _stack_bound() — walk a device stack and sum Vdsat floors Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/gmid/stage-interface_explained.html Core helper that walks a series stack of same-type devices from the stage-interface net toward its anchor, adding each device's Vdsat floor, and returns the voltage the stack demands. Call once for "nmos" to get the lower wall and once for "pmos" to get the upper wall. The implementation indexes devices by drain net, tracks diode-tied devices, and walks until it revisits a node. ```python def _stack_bound(net, dtype, devs, pair_refs, sizing, spec) -> float | None: sgn = 1.0 if dtype == "nmos" else -1.0 vcm = spec.vcm # the input common mode # index devices of this type by their drain net; note the diode-tied ones by_drain, diode_by_net = {}, {} for d in devs: if d.type != dtype: continue by_drain.setdefault(d.terminals.get("d"), d) if d.terminals.get("g") == d.terminals.get("d"): diode_by_net.setdefault(d.terminals.get("d"), d) node, floor, seen = net, 0.0, set() while node not in seen: seen.add(node) dev = by_drain.get(node) # ... (rest of the walk) ... break return None ``` -------------------------------- ### synthesize() usage example Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/api/synthesizer.rst Calls the synthesizer with a topology and bias-generation configuration. The bias_generation slot is not part of the enumeration product; its variant is constructed per combination from what the other slots consume on each bias rail. ```python from circuitgenome.synthesizer import synthesize synthesize(topology, bias_generation=...) # placeholder ``` -------------------------------- ### Run circuitgenome design with spec_03_hard.yaml Source: https://github.com/analog-ml/circuitgenome/blob/main/examples/gf180_difficulty_specs/README.md Command to run a design using the two_stage_opamp_single_ended topology with the spec_03_hard.yaml specification on the gf180mcu technology, outputting to out/. This is the usage example for the difficulty ladder. ```bash circuitgenome design --topology two_stage_opamp_single_ended \ --spec examples/gf180_difficulty_specs/spec_03_hard.yaml \ --tech gf180mcu -o out/ ``` -------------------------------- ### Design summary output for two_stage_opamp_single_ended Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/modules/designer.rst Example output from a `circuitgenome design` sweep. Shows 3 of 12 circuits meeting the spec (25.0%) with a 2.5s runtime, and lists top rejection reasons plus best design points. ```text Design summary (tech: gf180mcu_3v3): template evaluated sizing✗ bias✗ spec✗ unverif✗ error accepted two_stage_opamp_single_ended 12 0 0 9 0 0 3 3/12 circuits meet the spec (25.0%) | runtime 2.5s Top rejection reasons — two_stage_opamp_single_ended: 9 missed spec(s): gain_db Best design points: Highest gain two_stage_opamp_single_ended/circuit_0010 (81.21 dB) Highest GBW two_stage_opamp_single_ended/circuit_0011 (8.13 MHz) Highest phase margin two_stage_opamp_single_ended/circuit_0011 (112.93 °) Lowest power two_stage_opamp_single_ended/circuit_0003 (0.31 mW) ``` -------------------------------- ### Full-end-to-end pipeline using parse, recognize, group_by_category Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/recognizer/__init__.html This example exercises the full recognition pipeline across three layers: text parsing to a structured netlist, recognition of candidate structures (with overlaps), and topology-free grouping by category. It prints, for each block and category, the name of the highest-ranked structure. Use this as a worked call sequence to verify the end-to-end flow of the recognizer. ```python from circuitgenome.recognizer import parse, recognize, group_by_category # Layer 0 — text → structured netlist netlist = parse(spice_text) # Layer 1 — netlist → every candidate structure (overlaps and all) sr = recognize(netlist) # Layer 2 (topology-free) — candidates → ranked functional groups fbr = group_by_category(sr, netlist) for block, cats in fbr.groups.items(): for cat, structs in cats.items(): print(block, cat, structs[0].name) # best guess per category ``` -------------------------------- ### Size a two-stage single-ended netlist with circuitgenome size Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/usage/cli.rst Sizes the transistors in a flat SPICE netlist against a generic-technology spec. Requires the topology name (for FBR slot assignment) and a YAML spec file. The example targets a two-stage single-ended op-amp netlist with the generic-tech spec file. ```bash circuitgenome size \ circuits/two_stage_opamp_single_ended/circuit_0001_flat.ckt \ --topology two_stage_opamp_single_ended \ --spec examples/two_stage_se_specs/spec_generic.yaml ``` -------------------------------- ### Load module variants with load_modules Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/api/loader.rst Loads module variant definitions from a YAML file, defaulting to the built-in opamp_modules.yaml. Returns a dictionary mapping category names to lists of ModuleVariant objects. The example iterates over the 'input_pair' category and prints each variant's name and display_name. ```python from circuitgenome.synthesizer.loader import load_modules modules = load_modules() for variant in modules["input_pair"]: print(variant.name, variant.display_name) ``` -------------------------------- ### Mapping gm requirements to transistors Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/physics/physics-preprocess_explained.html Maps stage-level gm requirements to individual transistors. Only the signal transistor of a stage gets a gm requirement; its partner (current-source load) gets 0.0. ```python for ref, (device, slot) in all_transistors.items(): if slot == "input_pair": gm_req_map[ref] = gm1_req elif slot in SECOND_STAGE_SLOTS: gm_req_map[ref] = gm2_req if is_signal_device(device) else 0.0 elif slot in THIRD_STAGE_SLOTS: gm_req_map[ref] = gm3_req if is_signal_device(device) else 0.0 ``` -------------------------------- ### Sample output (generic tech — Level-1 analytical path) Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/usage/cli.rst Sample output for the generic technology Level-1 analytical path. Reports the netlist, topology, tech, solver, and a warning when the second-stage gm requirement exceeds the weak-inversion ceiling, then prints per-transistor sizing results. ```text Netlist: circuit_0001_flat.ckt | Topology: two_stage_opamp_single_ended Tech: generic_parameterized Solver: OPTIMAL ⚠ second-stage gm requirement exceeds the weak-inversion ceiling — increase second_stage_current_ratio/ibias or relax gain. Transistor sizing: m1_input_pair W=9.000µm L=1.000µm IDS=5.00µA VGS=-0.611V VDS_sat=0.111V ... mp1_second_stage W=5.000µm L=1.000µm IDS=25.00µA VGS=-0.833V VDS_sat=0.111V ``` -------------------------------- ### Shared prep block: analyze_circuit, assign_ids, size_load_resistors, compute_requirements Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/analytical/level1_explained.html Prepares the solver inputs from the recognizer's output: builds a circuit view, assigns drain currents, sizes resistor loads, and computes per-device gm and VOD targets. Requires the Level1Model from Part 2; the same function works with the gm/Id model as a plug-in. ```python view = analyze_circuit(fbr_result, topology) # slots, dedup, warnings ids_map = assign_ids(view.slot_transistors, view.all_transistors, spec) # Size resistor loads (deterministic) and fold them into first-stage Rout. resistors = size_load_resistors(view.slot_resistors, spec, tech) gd_load_r = (1.0 / min(resistors.values())) if resistors else 0.0 dev_model = Level1Model(tech) gm_req_map, vod_max_map, cc_pf, cc2_pf, gm_ceiling_warnings = compute_requirements( slot_transistors, all_transistors, ids_map, tech, spec, dev_model, gd_load_r ) all_warnings = topology_warnings + gm_ceiling_warnings ``` -------------------------------- ### AC sweep starting at 1 mHz (SPICE-like) Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/verify/verify-measure_explained.html Starts the AC sweep three decades below 1 Hz so the first sample is a genuine DC value. A high-gain multi-stage amplifier can have a dominant pole below 1 Hz; starting at 1 Hz would roll off the reported DC gain and skew the phase baseline by tens of degrees, corrupting the phase margin. ```text ac dec 30 1e-3 1e10 ``` -------------------------------- ### plan_devices() - derive requirements and intents into SizingPlan Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/gmid/plan_explained.html Core Phase 3 function that builds the gm/Id oracle, computes performance requirements (gm, Vdsat, compensation caps), resolves per-device design intent, and packs everything into a SizingPlan. Two independent derivations (requirements and intents) converge into the output object. ```python def plan_devices(view, currents, spec, tech, intent) -> SizingPlan: model = _model_for(tech, intent) gm_req_map, vod_max_map, cc_pf, cc2_pf, ceil_warnings = compute_requirements( view.slot_transistors, view.all_transistors, currents.ids_map, tech, spec, model, currents.gd_load_r, ) tintents = resolve_transistor_intents( view.all_transistors, view.cascode_refs, intent.block_intents) return SizingPlan(model=model, gm_req_map=gm_req_map, vod_max_map=vod_max_map, cc_pf=cc_pf, cc2_pf=cc2_pf, tintents=tintents, warnings=ceil_warnings) ``` -------------------------------- ### circuitgenome.sizer.verify.deck.pdk_netlist(sized_text, tech, base_dir=None) Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/api/sizer/verify.rst Rewrites a sized generic netlist into a PDK-native simulatable form. Raises ValueError if tech lacks spice_lib and device_map. ```APIDOC ## circuitgenome.sizer.verify.deck.pdk_netlist(sized_text, tech, base_dir=None) ### Description Rewrite a sized generic netlist into the PDK-native, simulatable form. ### Method Function call ### Endpoint circuitgenome.sizer.verify.deck.pdk_netlist ### Parameters #### Path Parameters - **sized_text** (str) - Required - Sized netlist text - **tech** (TechParams) - Required - Technology parameters - **base_dir** (Path | str | None) - Optional - Base directory for header paths ### Raises - **ValueError** – for a tech without `spice_lib` + `device_map` ### Return Type str ### Response Example ``` .lib "" .subckt dut in out x1 in out vdd vss nmos_3p3 w=10 l=0.5 .ends ``` ``` -------------------------------- ### Phase 1 & 2 — analyze_circuit and assign_currents Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/_extra/walkthrough/gmid/gmid-sizer_explained.html Two sequential steps: first build the structural CircuitView with analyze_circuit, then assign bias currents with assign_currents. The CircuitView is a pure description (no sizes) that every later phase reads from. ```python # Phase 1 — Analyze: structural view of the recognised circuit. view = analyze_circuit(fbr_result, topology) # Phase 2 — Bias currents: IDS from KCL, rail-referenced load resistors. currents = assign_currents(view, spec, tech, intent) ``` -------------------------------- ### Size a two-stage opamp with size_circuit and SizingSpec Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/usage/python_api.rst Runs the full sizing flow: builds a two-stage opamp netlist, runs SR and FBR, defines a SizingSpec, loads the generic technology, and calls size_circuit. The result prints solver status, transistor W/L and IDS, compensation capacitor, and analytical metrics. The metrics are analytical estimates; the CLI measures performance in ngspice instead. ```python from circuitgenome.synthesizer.loader import load_modules, load_topologies from circuitgenome.synthesizer import enumerate_circuits, to_flat_spice from circuitgenome.recognizer import parse, recognize from circuitgenome.recognizer.functional_block_recognizer import assign_slots # Public API is re-exported from the package root (internals live under # circuitgenome.sizer.physics / .analytical / .gmid). from circuitgenome.sizer import size_circuit, load_tech, SizingSpec # 1. Build / load a netlist and run SR + FBR topology = next( t for t in load_topologies() if t.name == "two_stage_opamp_single_ended" ) circuit = next(enumerate_circuits(topology, load_modules())) netlist_text = to_flat_spice(circuit) parsed = parse(netlist_text) sr_result = recognize(parsed) fbr_result = assign_slots(sr_result, topology) # 2. Define performance specification spec = SizingSpec( vdd=5.0, vss=0.0, ibias=10e-6, # 10 µA tail current cl=20e-12, # 20 pF load second_stage_current_ratio=2.5, gain_min_db=80, gbw_min_hz=2.5e6, # 2.5 MHz phase_margin_min_deg=60, slew_rate_min_vps=3.5e6, # 3.5 V/µs power_max_w=1e-3, ) # 3. Load technology and run the sizer tech = load_tech("generic") # built-in config name, or a YAML path result = size_circuit(parsed, sr_result, fbr_result, topology, tech, spec) print(result.solver_status) # e.g. "OPTIMAL" / "FEASIBLE" / "GMID" for ref, s in result.transistors.items(): print(f" {ref:30s} W={s.w_um:.2f} µm L={s.l_um:.2f} µm IDS={s.ids_a*1e6:.1f} µA") if result.cc_pf is not None: print(f" Cc = {result.cc_pf:.2f} pF") print(result.metrics, result.bias_feasible) ``` -------------------------------- ### Design every topology template with circuitgenome design --all Source: https://github.com/analog-ml/circuitgenome/blob/main/docs/usage/cli.rst Runs the full design flow for every topology template against the given YAML spec, writing surviving sized netlists and a report.json to the output directory. ```bash circuitgenome design --all \ --spec examples/gf180_difficulty_specs/spec_01_easy.yaml \ --output-dir designs/ ``` -------------------------------- ### Run circuitgenome design per template (bash) Source: https://github.com/analog-ml/circuitgenome/blob/main/examples/sky130_results/README.md Runs the circuitgenome design synthesizer for a single opamp template on the SKY130 1.8 V core tech against the shared survey spec. The command is run per-template because the synthesizer is not invoked with --all (see the Reproducing section). ```bash circuitgenome design --topology