PySpice
PySpice copied to clipboard
How to pass parameters during object call and not during object creation ?
From the documentation, this is how we create a parallel resistor subcircuit:
class ParallelResistor2(SubCircuit):
NODES = ('n1', 'n2')
def __init__(self, name, R1=1@u_Ω, R2=2@u_Ω):
SubCircuit.__init__(self, name, *self.NODES)
self.R(1, 'n1', 'n2', R1)
self.R(2, 'n1', 'n2', R2)
This is how they can be instantiated:
circuit = Circuit('Test')
circuit.subcircuit(ParallelResistor2('pr1', R2=2@u_Ω))
circuit.X('1', 'pr1', 1, circuit.gnd)
circuit.subcircuit(ParallelResistor2('pr2', R2=3@u_Ω))
circuit.X('2', 'pr2', 1, circuit.gnd)
My question is, instead of the above, why can't we have:
circuit = Circuit('Test')
circuit.subcircuit(ParallelResistor2('pr'))
circuit.X('1', 'pr', 1, circuit.gnd, R2=2@u_Ω)
circuit.X('2', 'pr', 1, circuit.gnd, R2=3@u_Ω)
This is less code and results in a smaller netlist if we have to use the same subcircuit a couple of times. Is something like this possible ?
I also want to do the same . Please do comment if you got any progress.