PyLTSpice 5.4.2__tar.gz → 5.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. pyltspice-5.4.4/PKG-INFO +703 -0
  2. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/__init__.py +3 -2
  3. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/client_server/srv_sim_runner.py +1 -1
  4. pyltspice-5.4.4/PyLTSpice/editor/asc_editor.py +45 -0
  5. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/sim/sim_batch.py +2 -2
  6. pyltspice-5.4.4/PyLTSpice.egg-info/PKG-INFO +703 -0
  7. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice.egg-info/SOURCES.txt +0 -11
  8. pyltspice-5.4.4/PyLTSpice.egg-info/requires.txt +1 -0
  9. {pyltspice-5.4.2 → pyltspice-5.4.4}/README.md +9 -0
  10. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/run_montecarlo.py +4 -3
  11. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/sim_runner_asc_example.py +1 -1
  12. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/sim_runner_callback_example.py +1 -1
  13. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/sub_circuit_asc_edits.py +3 -3
  14. {pyltspice-5.4.2 → pyltspice-5.4.4}/pyproject.toml +3 -4
  15. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/ngspice_batch.py +1 -1
  16. pyltspice-5.4.2/PKG-INFO +0 -1368
  17. pyltspice-5.4.2/PyLTSpice/LTSpiceBatch.py +0 -9
  18. pyltspice-5.4.2/PyLTSpice/LTSpice_RawRead.py +0 -10
  19. pyltspice-5.4.2/PyLTSpice/LTSpice_RawWrite.py +0 -10
  20. pyltspice-5.4.2/PyLTSpice/editor/asc_editor.py +0 -23
  21. pyltspice-5.4.2/PyLTSpice/sim/ngspice_simulator.py +0 -106
  22. pyltspice-5.4.2/PyLTSpice/sim/run_task.py +0 -174
  23. pyltspice-5.4.2/PyLTSpice/sim/sim_analysis.py +0 -105
  24. pyltspice-5.4.2/PyLTSpice/sim/simulator.py +0 -123
  25. pyltspice-5.4.2/PyLTSpice/sim/spice_editor.py +0 -1067
  26. pyltspice-5.4.2/PyLTSpice/sim/xyce_simulator.py +0 -135
  27. pyltspice-5.4.2/PyLTSpice/sim_batch.py +0 -488
  28. pyltspice-5.4.2/PyLTSpice.egg-info/PKG-INFO +0 -1368
  29. pyltspice-5.4.2/PyLTSpice.egg-info/requires.txt +0 -1
  30. pyltspice-5.4.2/examples/issue126/testcase/test.py +0 -6
  31. {pyltspice-5.4.2 → pyltspice-5.4.4}/LICENSE +0 -0
  32. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/Histogram.py +0 -0
  33. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/LTSteps.py +0 -0
  34. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/client_server/__init__.py +0 -0
  35. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/client_server/sim_client.py +0 -0
  36. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/client_server/sim_server.py +0 -0
  37. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/editor/__init__.py +0 -0
  38. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/editor/spice_editor.py +0 -0
  39. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/log/__init__.py +0 -0
  40. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/log/logfile_data.py +0 -0
  41. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/log/ltsteps.py +0 -0
  42. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/log/semi_dev_op_reader.py +0 -0
  43. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/raw/__init__.py +0 -0
  44. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/raw/raw_classes.py +0 -0
  45. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/raw/raw_convert.py +0 -0
  46. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/raw/raw_read.py +0 -0
  47. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/raw/raw_write.py +0 -0
  48. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/rawplot.py +0 -0
  49. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/run_server.py +0 -0
  50. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/sim/__init__.py +0 -0
  51. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/sim/ltspice_simulator.py +0 -0
  52. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/sim/process_callback.py +0 -0
  53. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/sim/sim_runner.py +0 -0
  54. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/sim/sim_stepping.py +0 -0
  55. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/sim/tookit/montecarlo.py +0 -0
  56. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/sim/tookit/worst_case.py +0 -0
  57. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/utils/detect_encoding.py +0 -0
  58. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice/utils/sweep_iterators.py +0 -0
  59. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice.egg-info/dependency_links.txt +0 -0
  60. {pyltspice-5.4.2 → pyltspice-5.4.4}/PyLTSpice.egg-info/top_level.txt +0 -0
  61. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/ltsteps_example.py +0 -0
  62. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/raw_plotting.py +0 -0
  63. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/raw_read_example.py +0 -0
  64. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/raw_write_example.py +0 -0
  65. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/run_worst_case.py +0 -0
  66. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/sim_runner_callback_process_example.py +0 -0
  67. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/sim_runner_example.py +0 -0
  68. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/sim_stepper_example.py +0 -0
  69. {pyltspice-5.4.2 → pyltspice-5.4.4}/examples/spice_editor_example.py +0 -0
  70. {pyltspice-5.4.2 → pyltspice-5.4.4}/setup.cfg +0 -0
  71. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/batch_test.py +0 -0
  72. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/batch_test2.py +0 -0
  73. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/batch_test3.py +0 -0
  74. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/batch_test4.py +0 -0
  75. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/batch_test_with_abort.py +0 -0
  76. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/fra_example.py +0 -0
  77. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/raw_plotting.py +0 -0
  78. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/raw_write_tests.py +0 -0
  79. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/raw_write_tools.py +0 -0
  80. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/rc_example.py +0 -0
  81. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/sim_server_example.py +0 -0
  82. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/sketch.py +0 -0
  83. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/test_ltsteps.py +0 -0
  84. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/unittest/sweep_iterators/sweep_iterators_unittest.py +0 -0
  85. {pyltspice-5.4.2 → pyltspice-5.4.4}/tests/unittest/test_pyltspice.py +0 -0
  86. {pyltspice-5.4.2 → pyltspice-5.4.4}/unittests/sweep_iterators_unittest.py +0 -0
  87. {pyltspice-5.4.2 → pyltspice-5.4.4}/unittests/test_asc_editor.py +0 -0
  88. {pyltspice-5.4.2 → pyltspice-5.4.4}/unittests/test_pyltspice.py +0 -0
@@ -0,0 +1,703 @@
1
+ Metadata-Version: 2.4
2
+ Name: PyLTSpice
3
+ Version: 5.4.4
4
+ Summary: A set of tools to Automate LTSpice simulations
5
+ Author-email: Nuno Brum <me@nunobrum.com>
6
+ License-Expression: GPL-3.0
7
+ Project-URL: Homepage, https://github.com/nunobrum/PyLTSpice
8
+ Project-URL: Bug Tracker, https://github.com/nunobrum/PyLTSpice/issues
9
+ Project-URL: Repository, https://github.com/nunobrum/PyLTSpice.git
10
+ Project-URL: Author, https://www.nunobrum.com/
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: spicelib>=1.4.6
17
+ Dynamic: license-file
18
+
19
+ # README #
20
+
21
+ _Current Version 4.5.3_
22
+
23
+ PyLTSpice is a toolchain of python utilities design to interact with LTSpice Electronic Simulator.
24
+ It is mostly based on the spicelib package, being the main difference to it is
25
+ the fact that LTSpice is automatically selected to perform all simulations.
26
+
27
+ [Ad] For finding the best values for passive components I've created the [WizEIA Calculator](https://WizEIA.com).
28
+
29
+ ## What is contained in this repository ##
30
+
31
+ * __LTSteps.py__
32
+ An utility that extracts from LTSpice output files data, and formats it for import in a spreadsheet, such like Excel
33
+ or Calc.
34
+
35
+ * __raw_read.py__
36
+ A pure python class that serves to read raw files into a python class.
37
+
38
+ * __raw_write.py__
39
+ A class to write RAW files that can be read by LTSpice Wave Application.
40
+
41
+ * __spice_editor.py and asc_editor.py__
42
+ Scripts that can update spice netlists. The following methods are available to manipulate the component values,
43
+ parameters as well as the simulation commands. These methods allow to update a netlist without having to open the
44
+ schematic in LTSpice. The simulations can then be run in batch mode (see sim_runner.py).
45
+
46
+ - `set_element_model('D1', '1N4148') # Replaces the Diode D1 with the model 1N4148`
47
+ - `set_component_value('R2', '33k') # Replaces the value of R2 by 33k`
48
+ - `set_parameters(run=1, TEMP=80) # Creates or updates the netlist to have .PARAM run=1 or .PARAM TEMP=80`
49
+ - `add_instructions(".STEP run -1 1023 1", ".dc V1 -5 5")`
50
+ - `remove_instruction(".STEP run -1 1023 1") # Removes previously added instruction`
51
+ - `reset_netlist() # Resets all edits done to the netlist.`
52
+
53
+ * __sim_runner.py__
54
+ A python script that can be used to run LTSpice simulations in batch mode without having to open the LTSpice GUI.
55
+ This in cooperation with the classes defined in spice_editor.py or asc_editor.py is useful because:
56
+
57
+ - Can overcome the limitation of only stepping 3 parameters
58
+ - Different types of simulations .TRAN .AC .NOISE can be run in a single batch
59
+ - The RAW Files are smaller and easier to treat
60
+ - When used with the RawRead.py and LTSteps.py, validation of the circuit can be done automatically.
61
+ - Different models can be simulated in a single batch, by using the following instructions:
62
+
63
+ Note: It was only tested with Windows based installations.
64
+
65
+ * __Analysis Toolkit__
66
+ A set of tools that prepare an LTSpice netlist for a Montecarlo or Worst Case Analysis. The device tolerances are set
67
+ by the user and the netlist is updated accordingly. The netlist can then be used with the sim_runner.py to run a
68
+ batch of simulations or with the LTSpice GUI.
69
+
70
+ * __Histogram.py__
71
+ A python script that uses numpy and matplotlib to create a histogram and calculate the sigma deviations. This is
72
+ useful for Monte-Carlo analysis.
73
+
74
+ ## How to Install ##
75
+
76
+ `pip install PyLTSpice `
77
+
78
+ ### Updating PyLTSpice ###
79
+
80
+ `pip install --upgrade PyLTSpice `
81
+
82
+ ### Using GITHub ###
83
+
84
+ `git clone https://github.com/nunobrum/PyLTSpice.git `
85
+
86
+ If using this method it would be good to add the path where you cloned the site to python path.
87
+
88
+ `import sys `
89
+ `sys.path.append(<path to PyLTSpice>) `
90
+
91
+ ## How to use ##
92
+
93
+ Here follows a quick outlook on how to use each of the tools.
94
+
95
+ More comprehensive documentation can be found in https://pyltspice.readthedocs.io/en/latest/
96
+
97
+ ## LICENSE ##
98
+
99
+ GNU V3 License
100
+ (refer to the LICENSE file)
101
+
102
+ ### RawRead ###
103
+
104
+ The example below reads the data from a Spice Simulation called
105
+ "TRAN - STEP.raw" and displays all steps of the "I(R1)" trace in a matplotlib plot
106
+
107
+ ```python
108
+ from PyLTSpice import RawRead
109
+
110
+ from matplotlib import pyplot as plt
111
+
112
+ LTR = RawRead("./testfiles/TRAN - STEP.raw")
113
+
114
+ print(LTR.get_trace_names())
115
+ print(LTR.get_raw_property())
116
+
117
+ IR1 = LTR.get_trace("I(R1)")
118
+ x = LTR.get_trace('time') # Gets the time axis
119
+ steps = LTR.get_steps()
120
+ for step in range(len(steps)):
121
+ # print(steps[step])
122
+ plt.plot(x.get_wave(step), IR1.get_wave(step), label=steps[step])
123
+
124
+ plt.legend() # order a legend
125
+ plt.show()
126
+ ```
127
+ -- in examples/raw_read_example.py
128
+
129
+ ### RawWrite ###
130
+
131
+ The following example writes a RAW file with a 3 milliseconds transient simulation sine with a 10kHz and a cosine with
132
+ 9.997kHz
133
+
134
+ ```python
135
+ import numpy as np
136
+ from PyLTSpice import RawRead, Trace, RawWrite
137
+ LW = RawWrite(fastacces=False)
138
+ tx = Trace('time', np.arange(0.0, 3e-3, 997E-11))
139
+ vy = Trace('N001', np.sin(2 * np.pi * tx.data * 10000))
140
+ vz = Trace('N002', np.cos(2 * np.pi * tx.data * 9970))
141
+ LW.add_trace(tx)
142
+ LW.add_trace(vy)
143
+ LW.add_trace(vz)
144
+ LW.save("./testfiles/teste_snippet1.raw")
145
+ ```
146
+ -- in examples/raw_write_example.py [RawWrite Example]
147
+
148
+ ### SpiceEditor, AscEditor and SimRunner.py ###
149
+
150
+ This module is used to launch LTSPice simulations. Results then can be processed with either the RawRead or with the
151
+ LTSteps module to read the log file which can contain .MEAS results.
152
+
153
+ The script will firstly invoke the LTSpice in command line to generate a netlist, and then this netlist can be updated
154
+ directly by the script, in order to change component values, parameters or simulation commands.
155
+
156
+ Here follows an example of operation.
157
+
158
+ ```python
159
+ from PyLTSpice import SimRunner
160
+ from PyLTSpice import SpiceEditor
161
+
162
+ # Force another simulatior
163
+ simulator = r"C:\Program Files\LTC\LTspiceXVII\XVIIx64.exe"
164
+
165
+ # select spice model
166
+ LTC = SimRunner(output_folder='./temp')
167
+ LTC.create_netlist('./testfiles/Batch_Test.asc')
168
+ netlist = SpiceEditor('./testfiles/Batch_Test.net')
169
+ # set default arguments
170
+ netlist.set_parameters(res=0, cap=100e-6)
171
+ netlist.set_component_value('R2', '2k') # Modifying the value of a resistor
172
+ netlist.set_component_value('R1', '4k')
173
+ netlist.set_element_model('V3', "SINE(0 1 3k 0 0 0)") # Modifying the
174
+ netlist.set_component_value('XU1:C2', 20e-12) # modifying a define simulation
175
+ netlist.add_instructions(
176
+ "; Simulation settings",
177
+ ";.param run = 0"
178
+ )
179
+ netlist.set_parameter('run', 0)
180
+
181
+ for opamp in ('AD712', 'AD820'):
182
+ netlist.set_element_model('XU1', opamp)
183
+ for supply_voltage in (5, 10, 15):
184
+ netlist.set_component_value('V1', supply_voltage)
185
+ netlist.set_component_value('V2', -supply_voltage)
186
+ print("simulating OpAmp", opamp, "Voltage", supply_voltage)
187
+ LTC.run(netlist)
188
+
189
+ for raw, log in LTC:
190
+ print("Raw file: %s, Log file: %s" % (raw, log))
191
+ # do something with the data
192
+ # raw_data = RawRead(raw)
193
+ # log_data = LTSteps(log)
194
+ # ...
195
+
196
+ netlist.reset_netlist()
197
+ netlist.add_instructions(
198
+ "; Simulation settings",
199
+ ".ac dec 30 10 1Meg",
200
+ ".meas AC Gain MAX mag(V(out)) ; find the peak response and call it ""Gain""",
201
+ ".meas AC Fcut TRIG mag(V(out))=Gain/sqrt(2) FALL=last"
202
+ )
203
+
204
+ # Sim Statistics
205
+ print('Successful/Total Simulations: ' + str(LTC.okSim) + '/' + str(LTC.runno))
206
+
207
+ enter = input("Press enter to delete created files")
208
+ if enter == '':
209
+ LTC.file_cleanup()
210
+ ```
211
+ -- in examples/sim_runner_example.py
212
+
213
+ The example above is using the SpiceEditor to create and modify a spice netlist, but it is also possible to use the
214
+ AscEditor to directly modify the .asc file. The edited .asc file can then be opened by the LTSpice GUI and the
215
+ simulation can be run from there.
216
+
217
+ ### Simulation Analysis Toolkit ###
218
+
219
+ The AscEditor can be used with the Simulation Analysis Toolkit to perform Monte Carlo or Wost Case simulations.
220
+ These simulations can either be done on the LTSpice GUI or using the Runner Class described above.
221
+
222
+ Let's consider the following circuit:
223
+
224
+ ![Sallen-Key Amplifier](./doc/modules/sallenkey.png "Sallen-Key Amplifier")
225
+
226
+ When performing a Monte Carlo simulation on this circuit, we need to manually modify the value of each component,
227
+ and then add the .step command for making several runs on the same circuit.
228
+ To simplify this process, the AscEditor class can be used as exemplified below:
229
+
230
+ ```python
231
+ from PyLTSpice import AscEditor, SimRunner # Imports the class that manipulates the asc file
232
+ from PyLTSpice.sim.tookit.montecarlo import Montecarlo # Imports the Montecarlo toolkit class
233
+
234
+ sallenkey = AscEditor("./testfiles/sallenkey.asc") # Reads the asc file into memory
235
+ runner = SimRunner(output_folder='./temp_mc') # Instantiates the runner class, with the output folder already set
236
+ mc = Montecarlo(sallenkey, runner) # Instantiates the Montecarlo class, with the asc file already in memory
237
+
238
+ # The following lines set the default tolerances for the components
239
+ mc.set_tolerance('R', 0.01) # 1% tolerance, default distribution is uniform
240
+ mc.set_tolerance('C', 0.1, distribution='uniform') # 10% tolerance, explicit uniform distribution
241
+ mc.set_tolerance('V', 0.1, distribution='normal') # 10% tolerance, but using a normal distribution
242
+
243
+ # Some components can have a different tolerance
244
+ mc.set_tolerance('R1', 0.05) # 5% tolerance for R1 only. This only overrides the default tolerance for R1
245
+
246
+ # Tolerances can be set for parameters as well
247
+ mc.set_parameter_deviation('Vos', 3e-4, 5e-3, 'uniform') # The keyword 'distribution' is optional
248
+ mc.prepare_testbench(num_runs=1000) # Prepares the testbench for 1000 simulations
249
+
250
+ # Finally the netlist is saved to a file
251
+ mc.save_netlist('./testfiles/sallenkey_mc.net')
252
+
253
+ mc.run_testbench(runs_per_sim=100) # Runs the simulation with splits of 100 runs each
254
+ logs = mc.read_logfiles() # Reads the log files and stores the results in the results attribute
255
+ logs.obtain_amplitude_and_phase_from_complex_values() # Splits the complex values into real and imaginary parts
256
+ logs.export_data('./temp_mc/data_testbench.csv') # Exports the data to a csv file
257
+ logs.plot_histogram('fcut') # Plots the histograms for the results
258
+ mc.cleanup_files() # Deletes the temporary files
259
+
260
+ print("=====================================")
261
+ # Now using the second method, where the simulations are ran one by one
262
+ mc.clear_simulation_data() # Clears the simulation data
263
+ mc.reset_netlist() # Resets the netlist to the original
264
+ mc.run_analysis(num_runs=1000) # Runs the 1000 simulations
265
+ logs = mc.read_logfiles() # Reads the log files and stores the results in the results attribute
266
+ logs.export_data('./temp_mc/data_sims.csv') # Exports the data to a csv file
267
+ logs.plot_histogram('fcut') # Plots the histograms for the results
268
+ mc.cleanup_files() # Deletes the temporary files
269
+
270
+ ```
271
+ -- in examples/run_montecarlo.py
272
+
273
+ When opening the created sallenkey_mc.net file, we can see that the following circuit.
274
+
275
+ ![Sallen-Key Amplifier with Montecarlo](./doc/modules/sallenkey_mc.png "Sallen-Key Amplifier with Montecarlo")
276
+
277
+ The following updates were made to the circuit:
278
+ - The value of each component was replaced by a function that generates a random value within the specified tolerance.
279
+ - The .step param run command was added to the netlist. Starts at -1 which it's the nominal value simulation, and
280
+ finishes that the number of simulations specified in the prepare_testbench() method.
281
+ - A default value for the run parameter was added. This is useful if the .step param run is commented out.
282
+ - The R1 tolerance is different from the other resistors. This is because the tolerance was explicitly set for R1.
283
+ - The Vos parameter was added to the .param list. This is because the parameter was explicitly set using the
284
+ set_parameter_deviation method.
285
+ - Functions utol, ntol and urng were added to the .func list. These functions are used to generate random values.
286
+ Uniform distributions use the LTSpice built-in mc(x, tol) and flat(x) functions, while normal distributions use the
287
+ gauss(x) function.
288
+
289
+ Similarly, the worst case analysis can also be setup by using the class WorstCaseAnalysis, as exemplified below:
290
+
291
+ ```python
292
+ from PyLTSpice import AscEditor, SimRunner # Imports the class that manipulates the asc file
293
+ from PyLTSpice.sim.tookit.worst_case import WorstCaseAnalysis
294
+
295
+ sallenkey = AscEditor("./testfiles/sallenkey.asc") # Reads the asc file into memory
296
+ runner = SimRunner(output_folder='./temp_wca') # Instantiates the runner class, with the output folder already set
297
+ wca = WorstCaseAnalysis(sallenkey, runner) # Instantiates the Worst Case Analysis class
298
+
299
+ # The following lines set the default tolerances for the components
300
+ wca.set_tolerance('R', 0.01) # 1% tolerance
301
+ wca.set_tolerance('C', 0.1) # 10% tolerance
302
+ wca.set_tolerance('V', 0.1) # 10% tolerance. For Worst Case analysis, the distribution is irrelevant
303
+
304
+ # Some components can have a different tolerance
305
+ wca.set_tolerance('R1', 0.05) # 5% tolerance for R1 only. This only overrides the default tolerance for R1
306
+
307
+ # Tolerances can be set for parameters as well.
308
+ wca.set_parameter_deviation('Vos', 3e-4, 5e-3)
309
+
310
+ # Finally the netlist is saved to a file
311
+ wca.save_netlist('./testfiles/sallenkey_wc.asc')
312
+
313
+ wca.run_testbench() # Runs the simulation with splits of 100 runs each
314
+
315
+ logs = wca.read_logfiles() # Reads the log files and stores the results in the results attribute
316
+ logs.export_data('./temp_wca/data.csv') # Exports the data to a csv file
317
+
318
+ print("Worst case results:")
319
+ for param in ('fcut', 'fcut_FROM'):
320
+ print(f"{param}: min:{logs.min_measure_value(param)} max:{logs.max_measure_value(param)}")
321
+
322
+ wca.cleanup_files() # Deletes the temporary files
323
+ ```
324
+ -- in examples/run_worst_case.py
325
+
326
+ When opening the created sallenkey_wc.net file, we can see that the following circuit.
327
+
328
+ ![Sallen-Key Amplifier with WCA](./doc/modules/sallenkey_wc.png "Sallen-Key Amplifier with WCA")
329
+
330
+ The following updates were made to the circuit:
331
+ - The value of each component was replaced by a function that generates a nominal, minimum and maximum value depending
332
+ on the run parameter and is assigned a unique index number. (R1=0, Vos=1, R2=2, ... V2=7, VIN=8)
333
+ The unique number corresponds to the bit position of the run parameter. Bit 0 corresponds to the minimum value and
334
+ bit 1 corresponds to the maximum value. Calculating all possible permutations of maximum and minimum values for each
335
+ component, we get 2**9 = 512 possible combinations. This maps into a 9 bit binary number, which is the run parameter.
336
+ - The .step param run command was added to the netlist. It starts at -1 which it's the nominal value simulation, then 0
337
+ which corresponds to the minimum value for each component, then it makes all combinations of minimum and maximum values
338
+ until 511, which is the simulation with all maximum values.
339
+ - A default value for the run parameter was added. This is useful if the .step param run is commented out.
340
+ - The R1 tolerance is different from the other resistors. This is because the tolerance was explicitly set for R1.
341
+ - The wc() function is added to the circuit. This function is used to calculate the worst case value for each component,
342
+ given a tolerance value and its respective index.
343
+ - The wc1() function is added to the circuit. This function is used to calculate the worst case value for each component,
344
+ given a minimum and maximum value and its respective index.
345
+
346
+ ### LTSteps.py ###
347
+
348
+ This module defines a class that can be used to parse LTSpice log files where the information about .STEP information is
349
+ written. There are two possible usages of this module, either programmatically by importing the module and then
350
+ accessing data through the class as exemplified here:
351
+
352
+ ```python
353
+ #!/usr/bin/env python
354
+ # coding=utf-8
355
+
356
+ from PyLTSpice.log.ltsteps import LTSpiceLogReader
357
+
358
+ data = LTSpiceLogReader("./testfiles/Batch_Test_AD820_15.log")
359
+
360
+ print("Number of steps :", data.step_count)
361
+ step_names = data.get_step_vars()
362
+ meas_names = data.get_measure_names()
363
+
364
+ # Printing Headers
365
+ print(' '.join([f"{step:15s}" for step in step_names]), end='') # Print steps names with no new line
366
+ print(' '.join([f"{name:15s}" for name in meas_names]), end='\n')
367
+ # Printing data
368
+ for i in range(data.step_count):
369
+ print(' '.join([f"{data[step][i]:15}" for step in step_names]), end='') # Print steps names with no new line
370
+ print(' '.join([f"{data[name][i]:15}" for name in meas_names]), end='\n') # Print Header
371
+
372
+ print("Total number of measures found :", data.measure_count)
373
+ ```
374
+ -- in examples/ltsteps_example.py
375
+
376
+ The second possibility is to use the module directly on the command line
377
+
378
+ # Command Line Interface #
379
+
380
+ ### ltsteps.exe ###
381
+
382
+ The <filename> can be either be a log file (.log), a data export file (.txt) or a measurement output file (.meas)
383
+ This will process all the data and export it automatically into a text file with the extension (tlog, tsv, tmeas)
384
+ where the data read is formatted into a more convenient tab separated format. In case the <logfile> is not provided, the
385
+ script will scan the directory and process the newest log, txt or out file found.
386
+
387
+ ### histogram.exe ###
388
+
389
+ This module uses the data inside on the filename to produce a histogram image.
390
+
391
+ ```
392
+ Usage: Histogram.py [options] LOG_FILE TRACE
393
+
394
+ Options:
395
+ --version show program's version number and exit
396
+ -h, --help show this help message and exit
397
+ -s SIGMA, --sigma=SIGMA
398
+ Sigma to be used in the distribution fit. Default=3
399
+ -n NBINS, --nbins=NBINS
400
+ Number of bins to be used in the histogram. Default=20
401
+ -c FILTERS, --condition=FILTERS
402
+ Filter condition writen in python. More than one
403
+ expression can be added but each expression should be
404
+ preceded by -c. EXAMPLE: -c V(N001)>4 -c parameter==1
405
+ -c I(V1)<0.5
406
+ -f FORMAT, --format=FORMAT
407
+ Format string for the X axis. Example: -f %3.4f
408
+ -t TITLE, --title=TITLE
409
+ Title to appear on the top of the histogram.
410
+ -r RANGE, --range=RANGE
411
+ Range of the X axis to use for the histogram in the
412
+ form min:max. Example: -r -1:1
413
+ -C, --clipboard If the data from the clipboard is to be used.
414
+ -i IMAGEFILE, --image=IMAGEFILE
415
+ Name of the image File. extension 'png'
416
+ ```
417
+
418
+ ### rawconvert.exe ###
419
+
420
+ A tool to convert .raw files into csv or Excel files.
421
+
422
+ ```
423
+ Usage: raw_convert.exe [options] <rawfile> <trace_list>
424
+
425
+ Options:
426
+ --version show program's version number and exit
427
+ -h, --help show this help message and exit
428
+ -o FILE, --output=FILE
429
+ Output file name. Use .csv for CSV output, .xlsx for
430
+ Excel output
431
+ -c, --clipboard Output to clipboard
432
+ -v, --verbose Verbose output
433
+ -s SEPARATOR, --sep=SEPARATOR
434
+ Value separator for CSV output. Default: "\t" <TAB>
435
+ Example: -d ";"
436
+ ```
437
+
438
+ ### run_server.exe ###
439
+
440
+ This command line tool was moved to the spicelib package.
441
+
442
+ ### SemiDevOpReader.py ###
443
+
444
+ This module is used to read from LTSpice log files Semiconductor Devices Operating Point Information. A more detailed
445
+ documentation is directly included in the source file docstrings.
446
+
447
+ ## Debug Logging
448
+
449
+ The library uses the standard `logging` module. Three convenience functions have been added for easily changing logging
450
+ settings across the entire library. `PyLTSpice.all_loggers()` returns a list of all the logger's
451
+ names, `PyLTSpice.set_log_level(logging.DEBUG)`
452
+ would set the library's logging level to debug, and `PyLTSpice.add_log_handler(my_handler)` would add `my_handler` as a
453
+ handler for
454
+ all loggers.
455
+
456
+ ### Single Module Logging
457
+
458
+ It is also possible to set the logging settings for a single module by using its name acquired from
459
+ the `PyLTSpice.all_loggers()`
460
+ function. For example:
461
+
462
+ ```python
463
+ import logging
464
+
465
+ logging.basicConfig(level=logging.INFO) # Set up the root logger first
466
+
467
+ import PyLTSpice # Import PyLTSpice to set the logging levels
468
+
469
+ PyLTSpice.set_log_level(logging.DEBUG) # Set PyLTSpice's global log level
470
+ logging.getLogger("PyLTSpice.RawRead").level = logging.WARNING # Set the log level for only RawRead to warning
471
+ ```
472
+
473
+ Would set only `PyLTSpice.RawRead` file's logging level to warning while the other modules would remain at debug level.
474
+ _Make sure to initialize the root logger before importing the library to be able to see the logs._
475
+
476
+ ## To whom do I talk to? ##
477
+
478
+ For support and improvement requests please open an Issue in [GitHub spicelib issues](https://github.com/nunobrum/spicelib/issues)
479
+
480
+ ## History ##
481
+ * Version 5.4.5
482
+ * Fixing Issue #151
483
+ * Alignment with spicelib 1.4.6
484
+ * Version 5.4.3
485
+ * See spicelib version 1.4.5
486
+ * Version 5.4.2
487
+ * Imported changes from spicelib 1.4.1 (Summary)
488
+ * Added `get_all_parameter_names()` function to all editors (#159)
489
+ * Compatibility with LTspice 24+
490
+ * Fixed Problem with .PARAM regex.
491
+ * Documenting the user library paths
492
+ * AscEditor: Adding support to DATAFLAG
493
+ * LTSteps: Supporting new LTspice data export format
494
+ * Version 5.4.1
495
+ * Fixing Issue #146
496
+ * Version 5.4.0
497
+ * Adding possibility of manipulating parameters on sub-circuits
498
+ * Supporting subcircuit names with dots.
499
+ * Overall documentation improvements (thanks @hb020)
500
+ * Major improvement in Documentation
501
+ * Introduced a read-only property that blocks libraries from being updated.
502
+ * Support for LTspice log files with the option : expanded netlist
503
+ * Supporting library symbols using BLOCK primitive
504
+ * Improved unittest on the .ASC hierarchical design
505
+ * SimRunner simulation iterator only returns successful simulations in order to simplify error management
506
+ * In QschEditor, the replacement of unique dot instructions (ex: .TRAN .AC .NOISE) is only done if the existing instruction is not commented.
507
+ * RunTask.get_results() now returns None if a callback function is provided and the simulation has failed.
508
+ * BigFix: Inclusion of encrypted libraries would crash
509
+ * Bugfix: Prefix were case sensitive in SpiceEditor
510
+ * Bugfix: Parsing netlists with extensions other than .net didn't work properly
511
+ * Version 5.3.2
512
+ * Correction on the readthedocs webhook configuration
513
+ * Alignement with the spicelib 1.2.1
514
+ * Version 5.3.1
515
+ * Bugfixes
516
+ * Updates on the README.md file. Issue #137
517
+ * Hierarchical support on AscEditor. Issue #138
518
+ * Rich format is only used if the user has it already installed. Issue #136
519
+ * Version 5.3.0
520
+ * Hierarchical Support (Aligning with the spicelib 1.1.1)
521
+ * Version 5.2.3
522
+ * Updating loggers to use the "spicelib" IDs.
523
+ * Fixing autodoc errors
524
+ * Correcting Version references
525
+
526
+ * Version 5.2.2
527
+ * Fixes on the unittests after the spicelib update to 1.0.4
528
+
529
+ * Version 5.2.1
530
+ * Correction on the run_montecarlo.py and run_worst_case.py examples.
531
+ * Fixes on the spicelib (Version 1.0.3)
532
+
533
+ * Version 5.2
534
+ * SimAnalysis supporting both Qspice and LTSpice logfiles.
535
+ * FastWorstCaseAnalysis algorithm implemented
536
+ * Fix on the log reading of fourier data.
537
+
538
+ * Version 5.1
539
+ * Important Bugfix on the LTComplex class.
540
+ * Fixes and enhancing the analysis toolkit.
541
+ * Deprecating SpiceEditor.write_netlist in favour of save_netlist()
542
+
543
+ * Version 5.0
544
+ * Making this library dependent on spicelib while trying to maintain backward compatibility as much as possible.
545
+ PyLTspice will be kept alive and its update will be linked to the spicelib. The main difference is that using
546
+ PyLTspice will avert the need of having to select a simulator in all run commands.
547
+
548
+ * Version 4.1.2
549
+ * Adding support for the new QSPICE simulator
550
+ * Improving the timeout mechanism on the SimRunner class
551
+ * Minor bug fixes
552
+
553
+ * Version 4.1.1
554
+ * Completing the Worst-Case Analysis functions. Adding a dedicated example for it.
555
+ * Refactoring the LTSpiceLogReader class in order to use it on the Analysis toolkit
556
+
557
+ * Version 4.1.0 *(requires Python 3.8 or higher)*
558
+ * Adding a new class to manipulate directly the .asc files.
559
+ * Modifying all the other classes in order to use the new class.
560
+ * Adding classes to perform Montecarlo and worst case analysis (Thanks to @mvanriet for his starting this).
561
+ * Removing the deprecated LTSpice_RawRead.py, LTSpice_RawWrite.py and LTSpiceBatch.py files and respective classes.
562
+ * Restructured the folder structure to be more in line with the Python standards.
563
+ * Added an Examples folder with some examples on how to use the library.
564
+
565
+ * Version 4.0.6
566
+ * Fixing issue with the write_netlist() function when receiving a string instead of a pathlib.Path object.
567
+ * Changing the regular expression for the resistor in order to accept the R= prefix on the values.
568
+
569
+ * Version 4.0.5
570
+ * Accepting fixes from aanas-sayed@GitHub that fixes issues with running the LTSpice in Linux.
571
+
572
+ * Version 4.0.4
573
+ * Improved usage of the logging library. (Thanks @TSprech for vastly improving the logging)
574
+ * Included RunTask number in the log messages.
575
+ * Included milliseconds in the time elapsed calculation.
576
+
577
+ * Version 4.0.3
578
+ * Fixing issue in elapsed time calculation.
579
+ * Fixing issue with the import of LTSpiceLogReader from LTSteps.py
580
+
581
+ * Version 4.0.2
582
+ * Changing list of Library dependencies.
583
+
584
+ * Version 4.0.1
585
+ * Bug fix on CLI for the Histogram.py and LTSteps.py
586
+
587
+ * Version 4.0.0
588
+ * Separating the SimCommander into two separate classes, one for the spice netlist editing (SpiceEditor) and another
589
+ for the simulation execution (SimRunner).
590
+ * Implementing simulation server to allow for remote simulation execution and the respective client.
591
+ * Supporting Wiggler element in the new LTSpiceXVII.
592
+ * Renaming all files into lowercase.
593
+ * Creating Error classes for better error handling.
594
+ * Adding support for other simulators (ex: ngspice) where the simulator is defined by a class. This
595
+ support class needs to be a subclass of the abstract class Simulator.
596
+ * Enormous improvement in the documentation of the code.
597
+
598
+ * Version 3.0
599
+ * Eliminating the LTSpice prefixes from files and classes.
600
+ * Adopting the lowercase convention for filenames.
601
+
602
+ * Version 2.3.1
603
+ * Bug fix on the parameter replacement.
604
+
605
+ * Version 2.3
606
+ * Supporting the creation of RAW Noise Analysis
607
+ * Bug Fixes (See GitHub Log)
608
+
609
+ * Version 2.2
610
+ * Making numpy as a requirement and eliminating all code that avoided the use of numpy
611
+ * Using new packaging tool
612
+ * Fixes on the LTSpice_RawWrite
613
+ * Fixes in the handling of stepped operating point simulations
614
+
615
+ * Version 2.1
616
+ * Adopting minimum python version 3.7
617
+ * Starting to use unit tests to validate all modules and improving testbenches
618
+ * Compatibility with NGSpice
619
+ * Avoiding the use of setup.py as per PEP517 and PEP518
620
+ * Bug Fixes (See GitHub log for more information)
621
+ * Improvements on the management of stepped data in the LTSpice_RawRead.py
622
+
623
+ * Version 2.0.2
624
+ * Improvements on Encoding detection
625
+
626
+ * Version 2.0
627
+ * International Support using the correct encoding when loading log files.
628
+ * Code Optimizations on the LTSpice_RawReader that allow faster data loading.
629
+ * Improving the functionality on the LTSpice_RawWriter.py
630
+ * Adding support to editing components inside subcircuits (.subckt)
631
+ * Supporting resistors with Model Definitions
632
+ * Fixing problem with LTSpiceLogReader that would return messed up data
633
+ * Fixing problem with replacing the file extension in certain names
634
+ * Correcting problem with deprecations on the numpy functions used by the Histogram.py
635
+ * Adding back the README.md that somehow was deleted
636
+
637
+ * Version 1.9
638
+ * Adding support for µ character in the SpiceEditor.
639
+ * Adding get_component_floatvalue() method in the netlist manipulating class that handles the conversion of numeric
640
+ fields into a float. This function takes into account the engineering qualifiers 'k' for kilos, 'm' or milis,
641
+ 'u' or 'µ' for microns, 'n' for nanos, 'f' for femtos and 'Meg' for Megas.
642
+
643
+ * Version 1.8
644
+ * Uniforming License reference across files and improvements on the documentation
645
+ * An enormous and wholehearted thanks to @lpherr for the improvements in the documentation.
646
+ * Bugfix on the add_LTspiceRunCmdLineSwitches() ; Supporting .param name value format
647
+ * Allowing the LTSpiceRawRead to proceed when the log file can't be found or when there are problems reading it.
648
+ * Version 1.7
649
+ * Running in Linux under wine is now possible
650
+
651
+ * Version 1.6
652
+ * Adding LTSpice_RawWrite. Adding documentation.
653
+
654
+ * Version 1.5
655
+ * Small fixes and improvements on the class usage. No added features
656
+
657
+ * Version 1.4
658
+ * Adding the LTSpice_SemiDevOpReader module
659
+ * Re-enabling the Histogram functions which where disabled by mistake.
660
+
661
+ * Version 1.3
662
+ * Bug fixes on the SpiceEditor Class
663
+
664
+ * Version 1.2
665
+ * README.md:
666
+ Adding link to readthedocs documentation
667
+ * All files:
668
+ Comprehensive documentation on how to use each module
669
+
670
+ * Version 1.1
671
+ * README.md:
672
+ Updated the description
673
+ * LTSpiceBatch.py:
674
+ Corrected the name of the returned raw file.
675
+ * Added comments throughout the code and cleanup
676
+
677
+ * Version 1.0
678
+ * LTSpiceBatch.py:\
679
+ Implemented a new approach (NOT BACKWARDS COMPATIBLE), that avoids the usage of the sim_settings.inc file.
680
+ And allows to modify not only parameters, but also models and even the simulation commands.
681
+ * LTSpice_RawRead.py:\
682
+ Added the get_time_axis method to the RawRead class to avoid the problems with negative values on time axis,
683
+ when 2nd order compression is enabled in LTSpice.
684
+ * LTSteps.py:\
685
+ Modified the LTSteps, so it can also read measurements on log files without any steps done.
686
+
687
+ * Version 0.6
688
+ * Histogram.py now has an option to make the histogram directly from values stored in the clipboard
689
+
690
+ * Version 0.5
691
+ * The LTSpice_RawReader.py now uses the `struct.unpack` function for a faster execution
692
+
693
+ * Version 0.4
694
+ * Added LTSpiceBatch.py to the collection of tools
695
+
696
+ * Version 0.3
697
+ * A version of LTSteps that can be imported to use in a higher level script
698
+
699
+ * Version 0.2
700
+ * Adding LTSteps.py and Histogram.py
701
+
702
+ * Version 0.1
703
+ * First commit to the bitbucket repository.