While SKiDL uses a default_circuit globally, you can instantiate multiple Circuit objects to manage independent designs or hierarchical structures.
Ways to add elements to a specific Circuit:
- Using the
circuit parameter: Pass the circuit instance directly to the constructor of a Part, Net, or Bus. - Using a context manager: Use
with my_circuit: to make my_circuit the default_circuit for all elements created within that block. - Using operators/methods: Use
+= with add_parts, add_nets, or add_buses on the circuit object.
Note: You cannot connect elements (parts, nets, or buses) that reside in different Circuit objects. Once an element is connected within a circuit, it cannot be moved to a different one.
>>> my_circuit = Circuit()
>>> my_circuit += Part("Device",'R') # Add a resistor to the circuit.
>>> my_circuit += Net('GND') # Add a net.
>>> my_circuit += Bus('byte_bus', 8) # Add a bus.
>>> my_circuit = Circuit()
>>> p = Part("Device", 'R', circuit = my_circuit)
>>> n = Net('GND', circuit = my_circuit)
>>> b = Bus('byte_bus', 8, circuit = my_circuit)
my_circuit = Circuit()
with my_circuit:
p = Part('Device', 'R')
n = Net('GND')
b = Bus('byte_bus', 8)