Simulating Dependent Sources (CCVS works but VCVS does not?!)

Hello,

I am trying to run the following code for the circuit:Circuit

###############################################################

import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()

################################################################

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

#################################################################

circuit = Circuit(‘Circuit with VCVS’)

circuit.R(1, 1, circuit.gnd, 6@u_Ω)
circuit.R(2, 2, 3, 4@u_Ω)
circuit.R(3, 3, 4, 8@u_Ω)
circuit.R(4, 5, circuit.gnd, 15@u_Ω)
circuit.V(1, 2, 1, 65@u_V)
circuit.E(1, 4, 3, 2, 3, 3)

simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.operating_point()

for node in analysis.nodes.values():
print(‘Node {}: {:4.1f} V’.format(str(node), float(node)))

When I run, it gives an error:

Traceback (most recent call last):
File “C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\PySpice\Spice\Netlist.py”, line 928, in getattr
return self.getitem(attribute_name)
File “C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\PySpice\Spice\Netlist.py”, line 921, in getitem
raise IndexError(attribute_name) # KeyError
IndexError: E

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:/Users/Desktop/PySpice/node-voltage-method-example8.py”, line 22, in
circuit.E(1, 4, 3, 2, 3, 3)
File “C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\PySpice\Spice\Netlist.py”, line 930, in getattr
raise AttributeError(attribute_name)
AttributeError: E

I am not sure where I am going wrong. I have been able to simulate a CCVS (part name H) but all other dependent sources seem to give an error.

Can anyone please point out what is wrong in the code above?

Thanks

Salman

The following code for a CCVS works (part name H):

##############################################################

import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()

################################################################

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

#################################################################

circuit = Circuit(‘Circuit with CCVS’)

circuit.R(1, 1, 2, 2@u_Ω)
circuit.R(2, 2, circuit.gnd, 20@u_Ω)
circuit.R(3, 2, 3, 5@u_Ω)
circuit.R(4, 4, circuit.gnd, 10@u_Ω)
circuit.R(5, 4, 5, 2@u_Ω)
circuit.V(1, 1, circuit.gnd, 20@u_V)
circuit.V(‘test’, 3, 4, 0@u_V)
circuit.H(1, 5, circuit.gnd, ‘Vtest’, 8)

simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.operating_point()

for node in analysis.nodes.values():
print(‘Node {}: {:4.1f} V’.format(str(node), float(node)))

I figured out the problem. See here: How to simulate dependent sources in PySpice