PySpice-org / PySpice

Simulate electronic circuit using Python and the Ngspice / Xyce simulators
https://pyspice.fabrice-salvaire.fr
GNU General Public License v3.0
641 stars 169 forks source link

Value after * must be an iterable, not NoneType #326

Open tbarton1197 opened 2 years ago

tbarton1197 commented 2 years ago

Environment (OS, Python version, PySpice version, simulator)

Spyder, Windows 11, pyspice v1.5, ngspice

I'm running code nearly copied from the example here but with different components

https://pyspice.fabrice-salvaire.fr/releases/v1.3/examples/advanced-usages/netlist-manipulations.html

`class neuron(SubCircuitFactory): name = 'neuron' nodes = ('in', 'out') def init(self): super().init(self.name, self.nodes, [])

    self.include(spice_library['1N4148'])
    self.X('D1','1N4148', 'in', self.gnd)
    self.X('D2','1N4148', self.gnd, 'in')
    self.VCVS(1, 'out', self.gnd, 'in', self.gnd, voltage_gain=4)`

But when I instantiate the class, I get this error:TypeError: Value after * must be an iterable, not NoneType

`from PySpice.Spice.Netlist import Circuit, SubCircuit, SubCircuitFactory from PySpice.Unit import * import PySpice.Logging.Logging as Logging import subcircuits as tbsc

logger = Logging.setup_logging() circuit = Circuit('one_neuron') ground = circuit.gnd

circuit.subcircuit(neuron())`

here is the full traceback

Traceback (most recent call last):

File "C:\Users\tbart\Miniconda3\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec exec(code, globals, locals)

File "c:\users\tbart\documents\grad school\research\eqprop\v_pyspice\setup.py", line 21, in circuit.subcircuit(tbsc.BasicOperationalAmplifier())

File "C:\Users\tbart\Documents\Grad School\Research\eqprop\v_pyspice\subcircuits.py", line 44, in init super().init()

File "C:\Users\tbart\Miniconda3\lib\site-packages\PySpice\Spice\Netlist.py", line 1125, in init super().init(self.NAME, *self.NODES, **kwargs)

TypeError: Value after * must be an iterable, not NoneType

k411e commented 2 years ago

This error was resolved for me after I removed SubCircuit from my import list (only import SubCircuitFactory)

kdre commented 8 months ago

Have the same issue when trying to execute with PySpice 1.5: https://github.com/OlzhasT/PySpiceCircuits-/blob/master/adc_dac_ideal_subcircuit_class_test.py

Ans solutions?

AshuPat commented 8 months ago

A potential work around can be found as following. Source: the 'EngineeringThings' YouTube channel, please refer to the video at this link: [https://youtu.be/znaERIx1tL8].

from PySpice.Spice.Netlist import SubCircuit
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *

class MySubCir(SubCircuit):
    __nodes__=('t_in','t_out')
    def __init__(self, name, r=1@u_kOhm):
        SubCircuit.__init__(self,name,*self.__nodes__)
        self.R(1,'t_in','t_out',r)
        return
circuit = Circuit('Main Circuit')
circuit.subcircuit(MySubCir('sub1',r=1@u_kOhm))
circuit.X(1,'sub1', 1 ,circuit.gnd)
benedictjones commented 7 months ago

Unfortunately, the example import spice_library['1N4148'] does seem to work. However, you can work around this by importing the desired component/library differently (you will need to source these yourself, but are widely available). This is explained in a different EngineeringThings tutorial: PySpice - Part 5: Including Models & Libraries

Basically, if you have a library with the components you want in: path = lib/1N4148.lib you can: