Skip to content

Components and instances

A Component is a reusable, validated factory. An Instance is one object created by that factory and placed in a circuit.

Define a component

from nimphel import Component, ComponentKind

nmos = Component(
    target="nmos_65nm",
    pins=("d", "g", "s", "b"),
    kind=ComponentKind.MOSFET,
    defaults={
        "w": None,
        "l": "65n",
    },
)

The fields have distinct roles:

Field Meaning
target Primitive, model, or definition instantiated in the netlist
pins Ordered connection names accepted by the factory
kind Simulator-independent component family
ref_prefix Optional reference prefix override
defaults Default and required instance parameters

A default of None means that the caller must supply the parameter.

Component kinds

ComponentKind is a string enum:

Kind Default prefix
RESISTOR R
CAPACITOR C
INDUCTOR L
VOLTAGE_SOURCE V
CURRENT_SOURCE I
MOSFET M
SUBCIRCUIT X
CUSTOM X

Custom elements can override the prefix:

memory_cell = Component(
    target="memory_cell",
    pins=("word", "bit"),
    kind=ComponentKind.CUSTOM,
    ref_prefix="I",
)

The prefix controls ergonomic reference allocation. The semantic kind remains independent of that spelling.

Bind nodes by position

transistor = nmos(
    ("out", "in", 0, 0),
    w="1u",
)

Nodes follow the declared pin order: drain, gate, source, bulk.

Bind nodes by pin name

transistor = nmos(
    {
        "g": "in",
        "d": "out",
        "b": 0,
        "s": 0,
    },
    w="1u",
)

Named bindings are reordered to the component's pin declaration. Missing, unexpected, or duplicate pin names raise an error.

Reuse components in loops

Calling a component always produces a fresh unowned instance:

from nimphel import Circuit

with Circuit(name="chain") as chain:
    instances = [
        nmos(
            (f"out_{index}", f"in_{index}", 0, 0),
            w=f"{index + 1}u",
        )
        for index in range(4)
    ]

assert [instance.ref for instance in instances] == [
    "M1", "M2", "M3", "M4"
]

Do not clone a component-generated instance merely to place the component again. Call the component factory again. Clone only when an existing configured instance should be copied.

Construct an instance directly

Readers and advanced code can construct Instance explicitly:

from nimphel import Instance

instance = Instance(
    ref="M12",
    ref_prefix="M",
    target="nmos_65nm",
    kind=ComponentKind.MOSFET,
    nodes=("out", "in", 0, 0),
    params={"w": "1u", "l": "65n"},
)

Direct construction does not inspect the active context. Register it explicitly:

circuit.add(instance)

This keeps parsing and deserialization free of ambient side effects.

Lightweight pins

Pins are currently represented by names. This keeps ordinary construction concise. A future Pin model can add direction, power-domain, or ERC metadata without requiring that detail for every component.

Next