Skip to content

Core reference

This page summarizes the current public construction and manipulation API. Concept pages explain the behavior and tradeoffs in more detail.

Core models

Element

Base class for circuit elements.

Member Result
owner Current Circuit or Subcircuit, otherwise None
clone() Independent, unowned deep copy

ComponentKind

String enum containing RESISTOR, CAPACITOR, INDUCTOR, VOLTAGE_SOURCE, CURRENT_SOURCE, MOSFET, SUBCIRCUIT, and CUSTOM.

Component

Component(
    *,
    target: str,
    pins: tuple[str, ...],
    kind: ComponentKind = ComponentKind.CUSTOM,
    ref_prefix: str | None = None,
    defaults: dict[str, Scalar | None] = {},
)
Method Result
component(nodes, **params) Fresh instance, registered in the active context
new(nodes, params=None, ref=None) Fresh instance with optional explicit reference

Instance

Instance(
    *,
    target: str,
    nodes: tuple[int | str, ...],
    params: dict[str, Scalar] = {},
    kind: ComponentKind = ComponentKind.CUSTOM,
    ref_prefix: str = "X",
    ref: str | None = None,
)
Method Meaning
matches_topology(other) Compare kind, target, and connected nodes
matches_exactly(other) Also compare parameters and reference prefix
clone() Deep independent copy

Model

Model(
    *,
    name: str,
    base: str,
    params: dict[str, Scalar] = {},
)

Containers

Circuit and Subcircuit share the manipulation methods below.

Method Behavior
add(element) Attach one unowned element and return it
extend(elements) Attach elements in order and return them
walk(recursive=False) Iterate elements in source order
find(ref=None, target=None, kind=None, recursive=False) Return matching instances
get(ref, recursive=False) Return one unambiguous instance
remove(ref) Detach and return one instance
rename(old_ref, new_ref) Safely change a reference
replace(ref, replacement) Replace in place and return the old instance
clone() Deep clone the container and nested elements

Filtered views:

container.instances
container.models
container.subcircuits
container.directives

Circuit

Circuit(
    *,
    name: str = "main",
    elements: list[Element] = [],
    path: Path | None = None,
)
Method Behavior
validate_integrity() Validate definitions, bindings, and dependency cycles

Subcircuit

Subcircuit(
    *,
    name: str,
    ports: tuple[str, ...],
    defaults: dict[str, Scalar | None] = {},
    ref_prefix: str = "X",
    elements: list[Element] = [],
)

A subcircuit is also callable:

instance = definition(nodes, **params)

The resulting instance has kind=ComponentKind.SUBCIRCUIT.

Directives

Class Main fields
TransientAnalysis stop, step, start, max_step, name, vendor_options
GlobalNodes nodes
Include path, section
Save signals
RawDirective dialect, text

Import semantic directives from nimphel.directives.

Exceptions

Exception Meaning
ElementOwnershipError An element is already owned or a reference was assigned unsafely
CircuitValidationError One or more hierarchy integrity checks failed
UnsupportedElementError A writer cannot represent an element or raw dialect
KeyError Lookup or mutation could not find a reference
LookupError Recursive get found an ambiguous reference
ValueError Invalid binding, duplicate reference, or invalid field value

Type aliases

Alias Definition
Node int | str
Scalar str | int | float | bool
Params dict[str, Scalar]