zero.circuit module

Electronic circuit class to which linear components can be added and on which simulations can be performed.

class zero.circuit.Circuit[source]

Bases: object

Represents an electronic circuit containing components and nodes.

A circuit can contain components like resistors, capacitors, inductors and op-amps. These are added to the circuit via the add_component() method.

components

The circuit components.

Type

list of Component

nodes

The circuit nodes.

Type

set of Node

RESERVED_NAMES = ['all', 'allop', 'allr', 'sum']
add_capacitor(*args, **kwargs)[source]

Add capacitor to circuit.

add_component(component)[source]

Add existing component to circuit.

Parameters

component (Component) – The component to add.

Raises

ValueError – If component is None, or already present in the circuit.

add_inductor(*args, **kwargs)[source]

Add inductor to circuit.

add_library_opamp(model, **kwargs)[source]

Add library op-amp to circuit.

Keyword arguments can be used to override individual library parameters.

Parameters

model (str) – The op-amp model name.

add_opamp(*args, **kwargs)[source]

Add op-amp to circuit.

add_resistor(*args, **kwargs)[source]

Add resistor to circuit.

property capacitors

The circuit capacitors.

Returns

list of Capacitor – The capacitors in the circuit.

property component_names

The names of the components in the circuit.

Returns

list of str – The component names.

property element_names

The names of the elements (components and nodes) in the circuit.

Yields

str – The element names.

property elements

Circuit nodes and components.

Yields
  • Node – The circuit nodes.

  • Component – The circuit components.

get_component(component_name)[source]

Get circuit component by name.

Parameters

component_name (str or Component) – The name of the component to fetch.

Returns

Component – The component.

Raises

ComponentNotFoundError – If the component is not found.

get_element(element_name)[source]

Get circuit element (component or node) by name.

Parameters

element_name (str) – The name of the element to fetch.

Returns

Component or Node – The found component or element.

Raises

ElementNotFoundError – If the element is not found.

get_node(node_name)[source]

Get circuit node by name.

Parameters

node_name (str or Node) – The name of the node to fetch.

Returns

Node – The node.

Raises

NodeNotFoundError – If the node is not found.

get_noise(noise_name)[source]

Get noise by component or node name.

Parameters

noise_name (str) – The name of the noise to fetch.

Returns

Noise – The noise.

Raises

NoiseNotFoundError – If the noise is not found.

has_component(component_name)[source]

Check if component is present in circuit.

Parameters

component_name (str) – The name of the component to check.

Returns

bool – True if component exists, False otherwise.

has_element(element_name)[source]

Check if element (component or node) is present in circuit.

Parameters

element_name (str) – The name of the element to check.

Returns

bool – True if element exists, False otherwise.

property has_input

Whether the circuit has an input.

Returns

bool – True if the circuit has an input, False otherwise.

has_node(node_name)[source]

Check if node is present in circuit.

Parameters

node_name (str) – The name of the node to check.

Returns

bool – True if node exists, False otherwise.

property inductors

The circuit inductors.

Returns

list of Inductor – The inductors in the circuit.

property input_component

The circuit input component.

Returns

Input – The circuit input.

property input_impedance

The circuit input impedance.

Returns

float – circuit input impedance

property n_components

The number of components in the circuit.

Returns

int – The number of components.

property n_nodes

The number of nodes in the circuit.

Returns

int – The number of nodes.

property node_names

The names of the nodes in the circuit.

Returns

list of str – The node names.

property noise_sources

The noise sources in the circuit.

Returns

list of ComponentNoise or NodeNoise – The component and node noise sources.

property non_gnd_nodes

Circuit nodes, excluding ground.

Returns

list of Node – The circuit nodes.

property opamp_noise_sources

The op-amp noise sources in the circuit.

Yields

Noise – The op-amp noise source.

property opamp_output_nodes

Circuit op-amp output nodes.

Returns

list of Node – The op-amp output nodes.

property opamps

The op-amps in the circuit.

Returns

list of OpAmp – The op-amps.

property passive_components

The circuit passive components.

Yields
  • Resistor – The resistors in the circuit.

  • Capacitor – The capacitors in the circuit.

  • Inductor – The inductors in the circuit.

remove_component(component)[source]

Remove component from circuit.

Parameters

component (str or Component) – The component to remove.

Raises

ComponentNotFoundError – If the component is not found.

replace_component(current_component, new_component)[source]

Replace circuit component with a new one.

This can be used to replace components of the same type, but can also replace components of different types as long as they have the same number of nodes.

Parameters
  • current_component (Component) – The component to replace.

  • new_component (str or Component) – The new component.

Raises
  • ComponentNotFoundError – If the current component is not in the circuit.

  • ValueError – If the new component is already in the circuit, or if the nodes of the new component are incompatible with those of the current component.

property resistor_noise_sources

The resistor noise sources in the circuit.

Yields

Noise – The resistor noise source.

property resistors

The circuit resistors.

Returns

list of Resistor – The resistors in the circuit.

set_inductor_coupling(inductor_1, inductor_2, coupling_factor=1)[source]

Set the coupling factor between the specified inductors

Parameters
  • inductor_1, inductor_2 (str or components.Inductor) – The inductors to couple.

  • coupling_factor (any, optional) – The coupling factor between the specified inductors, specified between 0 and 1. A coupling factor less than 1 represents loss.

Raises

ValueError – If a specified inductor is not an inductor.