Netlist

SPICE netlist serializers.

Two output formats are supported:

  • Flat (to_flat_spice()) — all devices inlined into a single .subckt block. Maximally portable; every SPICE simulator can read it.

  • Hierarchical (to_hierarchical_spice()) — one .subckt definition per module variant, instantiated via X calls in the top-level block. Easier to read and avoids repeating shared subcircuits across many circuits.

circuitgenome.synthesizer.netlist.to_flat_spice(circuit, name=None)[source]

Serialize circuit as a flat SPICE subcircuit.

All devices from every module slot are inlined into a single .subckt block. Device reference designators are suffixed with the slot name (e.g. m1_input_pair) so the leading character still identifies the SPICE primitive type; internal nets are prefixed with the slot name (e.g. load_internal_0).

Parameters:
Returns:

A SPICE netlist string starting with .subckt and ending with .ends.

Return type:

str

Example:

from circuitgenome import synthesize
from circuitgenome.synthesizer import to_flat_spice

circuit = synthesize({"topology": "one_stage_opamp"})[0]
print(to_flat_spice(circuit, name="my_ota"))
circuitgenome.synthesizer.netlist.to_hierarchical_spice(circuit, name=None)[source]

Serialize circuit as a hierarchical SPICE netlist.

Emits one .subckt definition per distinct module variant used, followed by a top-level .subckt that instantiates them with X calls. Duplicate module variants (same name) are defined only once.

Parameters:
Returns:

A multi-block SPICE string.

Return type:

str

Example:

from circuitgenome import synthesize
from circuitgenome.synthesizer import to_hierarchical_spice

circuit = synthesize({"topology": "one_stage_opamp"})[0]
print(to_hierarchical_spice(circuit, name="my_ota_hier"))