Netlist¶
SPICE netlist serializers.
Two output formats are supported:
Flat (
to_flat_spice()) — all devices inlined into a single.subcktblock. Maximally portable; every SPICE simulator can read it.Hierarchical (
to_hierarchical_spice()) — one.subcktdefinition per module variant, instantiated viaXcalls 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
.subcktblock. 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:
circuit (SynthesizedCircuit) – A
SynthesizedCircuitreturned bysynthesize()orenumerate_circuits().name (str | None) – Override the subcircuit name. Defaults to
circuit.name.
- Returns:
A SPICE netlist string starting with
.subcktand ending with.ends.- Return type:
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
.subcktdefinition per distinct module variant used, followed by a top-level.subcktthat instantiates them withXcalls. Duplicate module variants (same name) are defined only once.- Parameters:
circuit (SynthesizedCircuit) – A
SynthesizedCircuit.name (str | None) – Override the top-level subcircuit name.
- Returns:
A multi-block SPICE string.
- Return type:
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"))