开云体育

Date

Re: Simulating Using PyLTSpice Takes Too Long

 

Unfortunately, I can not use .STEP command.?
My main problem is finding multi-port s-parameters of a given circuit. LTSpice only supports 2-port s-parameters. To measure 4-port s-parameters I need to run simulation several times (6 times to be exact), where I change the port locations on each iteration. This requires me to slightly modify the netlist, meaning that I am running practically new simulation each time.
?
Even when I run simulaiton using LTSpice it still takes approximately 1 second, thought, it is harder for me to measure, therefore, I feel the problem is within the simulator itself. I feel like the simulator needs time for initializing, file writting and so on. I have not found a way to disable any additional protocols.
?
Thank you for your responses?


Re: Simulating Using PyLTSpice Takes Too Long

 

Can you re-do your sims using .STEP ?? Thus avoiding PyLTspice?
?
Andy


Re: Simulating Using PyLTSpice Takes Too Long

 

开云体育

I made the schematic in LTspice and it runs very fast. The netlist is:

* C:\Program Files\ADI\LTspice\Draft1.asc
V1 N001 0 AC 1 0
L1 N002 N001 10?
C1 N002 0 1p
R1 N002 0 50k
.ac dec 150 10meg 100G
.backanno
.end

The .ASC is just temporarily stored with that path, because I have not Saved it.

On 2025-03-29 20:45, davitkharshiladze26 via groups.io wrote:
eetch00,
?
I obtained this from viewing LTSpice netlist.
Nevertheless, I tried changing it after your comment and results remained the same
--
OOO - Own Opinions only If something is true: * as far as we know - it's science *for certain - it's mathematics *unquestionably - it's religion

Virus-free.


Re: Simulating Using PyLTSpice Takes Too Long

 

I have no familiarity with PyLTspice.? But you say most of the time is spent doing something other than the LTspice simulation itself.? Which means the cause is something other than LTspice.
?
Maybe there's another way to automate your sims which doesn't use this particular slow Python code, which seems to be the bottleneck.
?
.AC simulations can be quite fast and there's very little dependency on the sweep parameters.? That's because .AC analysis is 100% linear, once the operating point is found.? The sweep requires no iterations and no convergence issues.? It's fast.
?
Contrary to what eT wrote, I think your netlist is fine and without problems.
?
Andy
?


Re: Simulating Using PyLTSpice Takes Too Long

 

eetch00,
?
I obtained this from viewing LTSpice netlist.
Nevertheless, I tried changing it after your comment and results remained the same


Re: Simulating Using PyLTSpice Takes Too Long

 

On Sat, Mar 29, 2025 at 12:42 PM, <davitkharshiladze26@...> wrote:
The circuit may have some unreasonable problems, however, I am not plotting anything, nor am I trying to obtain any meaningful data from this circuit. This is a dummy circuit that represents the problem that my original meaningful circuit had. I can not share my original circuit.
?
Changing frequency sweep keeps the simulation runtime the same. Changing the format of stimulus does not make any change either.
?
You can confirm the netlist format by simulating it directly in LTspice without using python.
It won't run correctly formatted the way you've shown.
See my previous post.
?


Re: Simulating Using PyLTSpice Takes Too Long

 

try the developer.?






On Sat, Mar 29, 2025 at 3:01 PM, davitkharshiladze26 via groups.io
<davitkharshiladze26@...> wrote:
Hello Everyone,
?
I am trying to simulate very simple circuit using PyLTSpice. However, simulation takes too much time. It takes 1 second for the simulation to complete. Even when I increased the complexity of the circuit, time taken for simulation still stays approximately the same. I increased-decreased number of freuqncy points in my ac analysis, this had little to no effect on simulation runtime.
?
I feel like most of the simulation time is spent reading-writing files. Does anybody has any suggestions that can be beneficial to speeding up the process?
?
Currently, I am using LTSpice simulator, as seen on the third line.
?
?
import time
from PyLTSpice import SimRunner
from spicelib.simulators.ltspice_simulator import LTspice


# Create the netlist file (simple_lc.cir)
netlist_content = """* Simple LC Resonant Circuit
V1 N001 0 AC 1
L1 N001 N002 10uH
C1 N002 0 1pF
R1 N002 0 50
.ac lin 1500 40Meg 60g
.save V(N002)
.end
"""

# Save netlist
netlist_filename = "simple_lc.cir"
with open(netlist_filename, "w") as f:
? ? f.write(netlist_content)

LTC = SimRunner(output_folder='/temp', simulator=LTspice) # init simulation runner

for i in range(1,10): # iterate ove reverything
? ? ? ? t1 = time.time()
? ? ? ? LTC.run(netlist=netlist_filename)
? ? ? ? LTC.wait_completion()
? ? ? ? print(f"{t1 - time.time()} - Simrun")


Re: Simulating Using PyLTSpice Takes Too Long

 

The circuit may have some unreasonable problems, however, I am not plotting anything, nor am I trying to obtain any meaningful data from this circuit. This is a dummy circuit that represents the problem that my original meaningful circuit had. I can not share my original circuit.
?
Changing frequency sweep keeps the simulation runtime the same. Changing the format of stimulus does not make any change either.


Re: Simulating Using PyLTSpice Takes Too Long

 

开云体育

I see. but there are problems with this simple circuit. Using a linear sweep with such a wide range doesn't result in a useful frequency response plot. A decade sweep is much better. Also, the 50 ohm load damps the resonance at 48 MHz so much that it cannot be seen on the plot.

On 2025-03-29 19:25, davitkharshiladze26 via groups.io wrote:
I am trying to automate circuit simulation process. This is a simple representation of my large problem.
--
OOO - Own Opinions only If something is true: * as far as we know - it's science *for certain - it's mathematics *unquestionably - it's religion

Virus-free.


Re: Simulating Using PyLTSpice Takes Too Long

 

On Sat, Mar 29, 2025 at 12:01 PM, <davitkharshiladze26@...> wrote:
Hello Everyone,
?
I am trying to simulate very simple circuit using PyLTSpice. However, simulation takes too much time. It takes 1 second for the simulation to complete. Even when I increased the complexity of the circuit, time taken for simulation still stays approximately the same. I increased-decreased number of freuqncy points in my ac analysis, this had little to no effect on simulation runtime.
?
I feel like most of the simulation time is spent reading-writing files. Does anybody has any suggestions that can be beneficial to speeding up the process?
?
Currently, I am using LTSpice simulator, as seen on the third line.
?
?
import time
from PyLTSpice import SimRunner
from spicelib.simulators.ltspice_simulator import LTspice


# Create the netlist file (simple_lc.cir)
netlist_content = """* Simple LC Resonant Circuit
V1 N001 0 AC 1
L1 N001 N002 10uH
C1 N002 0 1pF
R1 N002 0 50
.ac lin 1500 40Meg 60g
.save V(N002)
.end
"""

# Save netlist
netlist_filename = "simple_lc.cir"
with open(netlist_filename, "w") as f:
? ? f.write(netlist_content)

LTC = SimRunner(output_folder='/temp', simulator=LTspice) # init simulation runner

for i in range(1,10): # iterate ove reverything
? ? ? ? t1 = time.time()
? ? ? ? LTC.run(netlist=netlist_filename)
? ? ? ? LTC.wait_completion()
? ? ? ? print(f"{t1 - time.time()} - Simrun")
?
The first line of a spice netlist file is a comment line and is not read. This is standard for a spice netlist.
?
V1 N001 0 AC 1 ? <---this "stimulus" line is not being read. Insert a blank line before this line.
?
Also, the stimulus line should really look like this:
?
V1 N001 0 DC 1 AC 1
?
The AC parameter will override the DC parameter for an AC analysis.
?
eT
?


Re: Simulating Using PyLTSpice Takes Too Long

 

I am trying to automate circuit simulation process. This is a simple representation of my large problem.


Re: Simulating Using PyLTSpice Takes Too Long

 

开云体育

I don't know anything about PyLTspice, but why don't you use LTspice directly? Are you using an OS other than Windows, MAC or Linux?

On 2025-03-29 18:53, davitkharshiladze26 via groups.io wrote:
Hello Everyone,
?
I am trying to simulate very simple circuit using PyLTSpice. However, simulation takes too much time. It takes 1 second for the simulation to complete. Even when I increased the complexity of the circuit, time taken for simulation still stays approximately the same. I increased-decreased number of freuqncy points in my ac analysis, this had little to no effect on simulation runtime.
?
I feel like most of the simulation time is spent reading-writing files. Does anybody has any suggestions that can be beneficial to speeding up the process?
?
Currently, I am using LTSpice simulator, as seen on the third line.
?
?
import time
from PyLTSpice import SimRunner
from spicelib.simulators.ltspice_simulator import LTspice
# Create the netlist file (simple_lc.cir)
netlist_content = """* Simple LC Resonant Circuit
V1 N001 0 AC 1
L1 N001 N002 10uH
C1 N002 0 1pF
R1 N002 0 50
.ac lin 1500 40Meg 60g
.save V(N002)
.end
"""
# Save netlist
netlist_filename = "simple_lc.cir"
with open(netlist_filename, "w") as f:
? ? f.write(netlist_content)
LTC = SimRunner(output_folder='/temp', simulator=LTspice) # init simulation runner
for i in range(1,10): # iterate ove reverything
? ? ? ? t1 = time.time()
? ? ? ? LTC.run(netlist=netlist_filename)
? ? ? ? LTC.wait_completion()
? ? ? ? print(f"{t1 - time.time()} - Simrun")
--
OOO - Own Opinions only If something is true: * as far as we know - it's science *for certain - it's mathematics *unquestionably - it's religion

Virus-free.


Simulating Using PyLTSpice Takes Too Long

 

Hello Everyone,
?
I am trying to simulate very simple circuit using PyLTSpice. However, simulation takes too much time. It takes 1 second for the simulation to complete. Even when I increased the complexity of the circuit, time taken for simulation still stays approximately the same. I increased-decreased number of freuqncy points in my ac analysis, this had little to no effect on simulation runtime.
?
I feel like most of the simulation time is spent reading-writing files. Does anybody has any suggestions that can be beneficial to speeding up the process?
?
Currently, I am using LTSpice simulator, as seen on the third line.
?
?
import time
from PyLTSpice import SimRunner
from spicelib.simulators.ltspice_simulator import LTspice


# Create the netlist file (simple_lc.cir)
netlist_content = """* Simple LC Resonant Circuit
V1 N001 0 AC 1
L1 N001 N002 10uH
C1 N002 0 1pF
R1 N002 0 50
.ac lin 1500 40Meg 60g
.save V(N002)
.end
"""

# Save netlist
netlist_filename = "simple_lc.cir"
with open(netlist_filename, "w") as f:
? ? f.write(netlist_content)

LTC = SimRunner(output_folder='/temp', simulator=LTspice) # init simulation runner

for i in range(1,10): # iterate ove reverything
? ? ? ? t1 = time.time()
? ? ? ? LTC.run(netlist=netlist_filename)
? ? ? ? LTC.wait_completion()
? ? ? ? print(f"{t1 - time.time()} - Simrun")


Re: .MEAS syntax with variable parameters

 

Eagles? Tony, well...?
,?
8-)


Re: Inductance modeling using table issue.

 

My last message didn't format very well, too early in the morning...obviously it is a sixth order polynomial, x6 means x**6 etc
?


Re: Inductance modeling using table issue.

 

Always good to see examples and I know know more about tables. I was idly playing with your data and whilst not really relevant to the discussion here but if you paste your data into Excel, graph it and "add a trendline" you can get very very vlose to your data with
?
y = -3E-07x6 + 6E-05x5 - 0.005x4 + 0.1689x3 - 2.2061x2 + 16.023x + 4.6329
(R? = 0.9954)
?
8-)
Ian
(Retired people have too much time on their hands)


Re: Conductance Negative

 

Can be done easily with a behavioral current source. The equation can be defined by:
?
I = V(Vi,Vo)/R
?
Where Vi and Vo are the voltages across the current source.
?
Example netlist with a sweep:
?
B1 Vi Vo I = V(Vi,Vo)/V(Vr)
V1 Vi 0 5
Rmeas 0 Vo 1m
V2 Vr 0 1
?
?


Re: .MEAS syntax with variable parameters

 

开云体育

On 28/03/2025 23:46, Bell, Dave via groups.io wrote:

Anther .meas feature I learned long ago is that sequence of measurements generally doesn’t matter.

This way, I can put the final result on top in the list, and ignore what went into calculating it…

Yeah. LTspice is clever about that. The parser must (silently) perform a number of iterations to determine the required evaluation precedence. I don't know whether that's generic in SPICE - I suspect it is. I guess it's not that complicated, actually. One of these days (or perhaps, nights - courtesy Eagles), I will walk/run through the original Berkeley code - I archived it years ago. (I'd better do it soon, while I can still read.?? )

--
Regards,
Tony


Re: .MEAS syntax with variable parameters

 

开云体育

Bingo!? Thanks, Tony!

?

I ended up with:

.meas T1 TRIG V(N0)=2.25 TD=3u RISE=1 TARG V(Nx)=Vtarg TD=3u RISE=1

.meas VNx MAX V(Nx) FROM {5*Pw} TO {25*Pw}

.meas Vtarg param 0.9*VNx

?

Which returns the same as using cursors in the plot, but more precise and a LOT easier.

?

Anther .meas feature I learned long ago is that sequence of measurements generally doesn’t matter.

This way, I can put the final result on top in the list, and ignore what went into calculating it…

?

Dave

?

From: [email protected] <[email protected]> On Behalf Of Tony Casey
Sent: Friday, March 28, 2025 3:31 PM
To: [email protected]
Subject: EXTERNAL: Re: [LTspice] .MEAS syntax with variable parameters

?

On 28/03/2025 21:16, Bell, Dave via groups.io wrote:

T1 Fails if I use this instead:

  1. .meas T1 TRIG V(N0)=2.25 TD=3u RISE=1 TARG V(Nx)={0.9*VNx} TD=3u RISE=1

Try:

.meas VNx MAX V(Nx) FROM {5*Pw} TO {25*Pw}
.meas Vtarg param 0.9*VNx
.meas T1 TRIG V(N0)=2.25 RISE=1 TARG V(Nx)=Vtarg TD=3u RISE=1

..instead. (You also had 2x TD=3u in the constraints, but I guess it ignored the 2nd)

Personally, I never use the Trig/Targ syntax, as it's more difficult to debug. Use an additional directive instead, then you can test Trig and Targ independently. YMMV.

--
Regards,
Tony


Re: .MEAS syntax with variable parameters

 

开云体育

On 28/03/2025 21:16, Bell, Dave via groups.io wrote:

T1 Fails if I use this instead:

  1. .meas T1 TRIG V(N0)=2.25 TD=3u RISE=1 TARG V(Nx)={0.9*VNx} TD=3u RISE=1
Try:

.meas VNx MAX V(Nx) FROM {5*Pw} TO {25*Pw}
.meas Vtarg param 0.9*VNx
.meas T1 TRIG V(N0)=2.25 RISE=1 TARG V(Nx)=Vtarg TD=3u RISE=1

..instead. (You also had 2x TD=3u in the constraints, but I guess it ignored the 2nd)

Personally, I never use the Trig/Targ syntax, as it's more difficult to debug. Use an additional directive instead, then you can test Trig and Targ independently. YMMV.

--
Regards,
Tony