Open tbarton1197 opened 2 years ago
This error was resolved for me after I removed SubCircuit from my import list (only import SubCircuitFactory)
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?
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)
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:
path= "lib/1n4148.lib"
circuit.include(path)
circuit.X('name_of_imported_diode", '1N4148', 1, 2)
raw_spice_line = ".include lib\\1n4148.lib"
circuit.rawspice += raw_spice_line + os.linesep
circuit.X('name_of_imported_diode', '1N4148', 1, 2)
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, [])
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