Skip to content

Commit

Permalink
Merge pull request #119 from nunobrum/v1.3.3
Browse files Browse the repository at this point in the history
Fixes on the instructions.
  • Loading branch information
nunobrum authored Jan 1, 2025
2 parents a620d0b + 0bede45 commit bd68524
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ set_custom_library_paths() class method as is exemplified in the code snippet be
```python
from spicelib import AscEditor

AscEditor.set_custom_library_paths(r"C:\work\MyLTspiceSymbols", r"C:\work\MyLTspiceLibraries")
AscEditor.set_custom_library_paths([r"C:\work\MyLTspiceSymbols", r"C:\work\MyLTspiceLibraries"])
```
The user can specify one or more search paths. Note that each call to this method will invalidate previously set search
paths. Also, note that this is a class method in all available editors, [SpiceEditor, AscEditor and QschEditor], this
Expand Down Expand Up @@ -794,6 +794,8 @@ _Make sure to initialize the root logger before importing the library to be able
## To whom do I talk?
For support and improvement requests please open an Issue in [GitHub spicelib issues](https://github.com/nunobrum/spicelib/issues)
## History
* Version 1.3.3
* Minor documentation fixes
* Version 1.3.2
* Documenting the user library paths
* AscEditor: Adding support to DATAFLAG
Expand Down
219 changes: 219 additions & 0 deletions doc/classes/editors.drawio

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
author = 'Nuno Brum'

# The full version, including alpha/beta/rc tags
release = '1.3.2'

release = '1.3.3'

try:
# Read the version from the .toml file
Expand Down
4 changes: 2 additions & 2 deletions doc/modules/read_netlist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ Example 2: Setting parameters inside a flat netlist.
# add instructions
net.add_instructions(
"; Simulation settings",
".param run = 0"
"; .step param run 0 10 1"
)
net.set_parameter('run', 0)
net.save_netlist("Batch_Test_Modified.net") # writes the modified netlist to the indicated file
It is possible to update component values inside subcircuits. This is shown in Example 3.
Expand Down
3 changes: 3 additions & 0 deletions examples/run_montecarlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
mc.cleanup_files() # Deletes the temporary files

print("=====================================")
a = input("Make 1000 simulations ? [Y/N]")
if a == 'N':
exit(0)
# Now using the second method, where the simulations are ran one by one
mc.clear_simulation_data() # Clears the simulation data
mc.reset_netlist() # Resets the netlist to the original
Expand Down
11 changes: 8 additions & 3 deletions examples/run_worst_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@

# All components sensitivity
sens = wca.make_sensitivity_analysis('fcut', '*') # Makes the sensitivity analysis for all components
print(sens)
for comp, value in sens.items():
print(f"{comp}: Mean: {value[0]:.2f}% StdDev:{value[1]:.2f}%")
input("Press Enter")

wca.cleanup_files() # Deletes the temporary files

Expand All @@ -51,9 +53,12 @@
min_fcut, max_fcut = wca.get_min_max_measure_value('fcut')
print(f"fcut: min:{min_fcut} max:{max_fcut}")
sens = wca.make_sensitivity_analysis('fcut', 'R1') # Makes the sensitivity analysis for R1
print(sens)
print(f"R1: Mean: {sens[0]:.2f}% StdDev:{sens[1]:.2f}%")
input("Press Enter")

# All components sensitivity
sens = wca.make_sensitivity_analysis('fcut', '*') # Makes the sensitivity analysis for all components
print(sens)
for comp, value in sens.items():
print(f"{comp}: Mean: {value[0]:.2f}% StdDev:{value[1]:.2f}%")
input("Press Enter")
wca.cleanup_files() # Deletes the temporary files
17 changes: 17 additions & 0 deletions examples/spice_editor_doc_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# read netlist
import spicelib

net = spicelib.SpiceEditor("./testfiles/Batch_Test.net") # Loading the Netlist

net.set_parameters(res=0, cap=100e-6) # Updating parameters res and cap
net['R2'].value = '2k' # Updating the value of R2 to 2k
net['R1'].value = 4000 # Updating the value of R1 to 4k
net['V3'].model = "SINE(0 1 3k 0 0 0)" # changing the behaviour of V3

# add instructions
net.add_instructions(
"; Simulation settings",
"; .step param run -1 100 1",
)
net.set_parameter('run', -1)
net.save_netlist("Batch_Test_Modified.net") # writes the modified netlist to the indicated file
9 changes: 6 additions & 3 deletions examples/spice_editor_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
se['R1'].value = 11000
se['C1'].value = 1.1E-6
se['V1'].value = 11
se.save_netlist("./testfiles/Noise_save_obj.net")

# Legacy Approach
se['R1'].value = 11000
se['C1'].value = 1.1E-6
se['V1'].value = 11
se.reset_netlist() # Revert all modifications done above
se.set_component_value('R1', 11000)
se.set_component_value('C1', 1.1E-6)
se.set_component_value('V1', 11)
se.save_netlist("./testfiles/Noise_save_fun.net")

se.run(run_filename="./testfiles/Noise_1.net", timeout=10, simulator=LTspice)
Binary file modified examples/testfiles/Batch_Test_Combine.raw
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ requires = [
build-backend = "setuptools.build_meta"
[project]
name = "spicelib"
version = "1.3.2"
version = "1.3.3"
authors = [
{ name="Nuno Brum", email="[email protected]" },
]
Expand Down
24 changes: 20 additions & 4 deletions spicelib/sim/tookit/worst_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# -------------------------------------------------------------------------------

import logging
from typing import Union, Callable, Type
from typing import Union, Callable, Type, Dict, Tuple

from .tolerance_deviations import ToleranceDeviations, DeviationType
from ..process_callback import ProcessCallback
Expand Down Expand Up @@ -197,7 +197,7 @@ def check_and_add_component(ref1: str):
self.analysis_executed = True

def get_min_max_measure_value(self, meas_name: str):
"""Returns the minimum and maximum values of a measurement"""
"""Returns the minimum and maximum values of a measurement. See SPICE .MEAS primitive documentation."""
if not self.analysis_executed:
_logger.warning("The analysis was not executed. Please run the analysis before calling this method")
return None
Expand All @@ -214,8 +214,24 @@ def get_min_max_measure_value(self, meas_name: str):
else:
return min(meas_data), max(meas_data)

def make_sensitivity_analysis(self, measure: str, ref: str = '*'):
"""Makes a sensitivity analysis for a given measurement and reference component"""
def make_sensitivity_analysis(self, measure: str, ref: str = '*') -> Union[Dict[str, Tuple[float, float]],
Tuple[float, float], None]:
"""
Makes a sensitivity analysis for a given measurement and reference component. The sensitivity is a percentage of
the component error contribution over the total error. As supplement a second value is given that is the
standard deviation of the error contribution of the component across all sensitivity analysis simulations.
If no reference is given, it will return a dictionary where the key is the component reference and the value
is the tuple with (sensitivity, standard_deviation) in percent values of the total error.
Returns None, if no data still exists for the sensitivity analysis.
:param measure: measurement name. See SPICE .MEAS primitive
:type measure: str
:param ref: Optional component reference in the netlist
:type ref: str
:returns: Tuple with sensitivity and a standard deviation or dictionary of tuples.
"""
if self.testbench_prepared and self.testbench_executed or self.analysis_executed:
# Read the log files
log_data: LogfileData = self.read_logfiles()
Expand Down

0 comments on commit bd68524

Please sign in to comment.