Skip to content

Commit

Permalink
Being able to use the run_testbench just after a prepare_testbench wi…
Browse files Browse the repository at this point in the history
…thout having to call save_netlist first.
  • Loading branch information
nunobrum committed Dec 1, 2024
1 parent 2d9f23c commit 94d9b8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 14 additions & 11 deletions examples/run_montecarlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@
mc.set_parameter_deviation('Vos', 3e-4, 5e-3, 'uniform') # The keyword 'distribution' is optional
mc.prepare_testbench(num_runs=1000) # Prepares the testbench for 1000 simulations

# Finally the netlist is saved to a file. This file contians all the instructions to run the simulation in LTspice
mc.save_netlist('./testfiles/temp/sallenkey_mc.asc')
# -- End of Example 1 --

mc.run_testbench(runs_per_sim=100) # Runs the simulation with splits of 100 runs each
logs = mc.read_logfiles() # Reads the log files and stores the results in the results attribute
logs.obtain_amplitude_and_phase_from_complex_values() # Splits the complex values into real and imaginary parts
logs.export_data('./temp_mc/data_testbench.csv') # Exports the data to a csv file
logs.plot_histogram('fcut') # Plots the histograms for the results
mc.cleanup_files() # Deletes the temporary files
manually_simulating_in_LTspice = False

if manually_simulating_in_LTspice:
# Finally the netlist is saved to a file. This file contains all the instructions to run the simulation in LTspice
mc.save_netlist('./testfiles/temp/sallenkey_mc.asc')
# -- End of Example 1 --
else:
# Using the Toolkit to run the simulation.
mc.run_testbench(runs_per_sim=100) # Runs the simulation with splits of 100 runs each
logs = mc.read_logfiles() # Reads the log files and stores the results in the results attribute
logs.obtain_amplitude_and_phase_from_complex_values() # Splits the complex values into real and imaginary parts
logs.export_data('./temp_mc/data_testbench.csv') # Exports the data to a csv file
logs.plot_histogram('fcut') # Plots the histograms for the results
mc.cleanup_files() # Deletes the temporary files

print("=====================================")
# Now using the second method, where the simulations are ran one by one
Expand All @@ -40,4 +44,3 @@
logs.export_data('./temp_mc/data_sims.csv') # Exports the data to a csv file
logs.plot_histogram('fcut') # Plots the histograms for the results
mc.cleanup_files() # Deletes the temporary files

2 changes: 2 additions & 0 deletions spicelib/sim/tookit/tolerance_deviations.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def run_testbench(self, *,
super()._reset_netlist()
self.play_instructions()
self.prepare_testbench()
else:
self.play_instructions()
self.editor.remove_instruction(".step param run -1 %d 1" % self.last_run_number) # Needs to remove this instruction
self.clear_simulation_data()
# calculate the ideal number of runs per simulation to avoid orphan runs. This is to avoid having a simulation
Expand Down

0 comments on commit 94d9b8e

Please sign in to comment.