Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openspice #393

Open
wants to merge 115 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
b29b0da
Smaller diff with original
Kreijstal Nov 23, 2024
0fdb3b0
Making it work for Mingw for the msys2 project
Kreijstal Nov 23, 2024
96c8578
Sanity test
Kreijstal Nov 23, 2024
6ca355b
Update pyspice-test.yml
Kreijstal Nov 23, 2024
7c13027
Add Background simulations
Kreijstal Nov 23, 2024
7f9b8a6
Bumping NgSpice version
Kreijstal Nov 24, 2024
494eede
Exception ignored from cffi callback <function NgSpiceShared._backgro…
Kreijstal Nov 24, 2024
e542ad0
Don't error on halt
Kreijstal Nov 25, 2024
a0a672d
Add OpenSPICE native Python simulator support
Mar 24, 2022
42f7e56
First commit
Dec 28, 2021
c68bab5
Add matrix solving
Dec 30, 2021
9969d8f
Add a test circuit with independent current sources
Dec 30, 2021
7e0b3ac
Added inductors, capacitors, and independent current sources
Mar 16, 2022
422a21b
Make solver more efficient
Mar 16, 2022
399d588
Intro behavioral source. Root eval implementation
Mar 16, 2022
dead93e
Added highly nonlinear, generic, simple solver. Still has bugs
Mar 17, 2022
8907403
noodle terminates. Still need to fix mismatches with yspice
Mar 17, 2022
78e5053
Really trying here. Getting values that at least aren't ludicrous
Mar 18, 2022
1641d06
Added comparison test
Mar 18, 2022
e71ea32
Broyden's method solver works!
Mar 20, 2022
5962c34
Limit function in OpenSPICE
Mar 20, 2022
acfe5f7
OpenSPICE about 200x slower. Time to start optimizing
Mar 21, 2022
d523a91
Halved time by removing sympy
Mar 21, 2022
593b8cf
Should have had this the whole time
Mar 21, 2022
b12286f
Doubled speed again by optimizing imports
Mar 21, 2022
fa145b0
300x slowdown using OpenSPICE for transient... time to start closing …
Mar 22, 2022
fd0922a
Optimize lambda eval to close gap to 100x slowdown
Mar 22, 2022
f0300e4
Add profiling script
Mar 22, 2022
c71067d
Somehow broyden2 gives 20% speedup over broyden1
Mar 22, 2022
c091d94
Now in the vicinity of about 10x slowdown
Mar 22, 2022
f21ec59
Whoops. There was a bug. About 10x slowdown now.
Mar 22, 2022
5c3473d
Optimize away one of the evals
Mar 22, 2022
e06b492
Marginal import optimization
Mar 22, 2022
44efa0f
Got transient with sine waves working
Mar 22, 2022
8764b63
Hacked netlist translation from ngspice PySpice interface
Mar 24, 2022
0c81da6
Fix some bugs
Mar 25, 2022
c56b910
Fix some node indexing bugs
Mar 25, 2022
9367be6
Fixed current sources
Mar 26, 2022
2d2c1ec
Test netlist
Mar 27, 2022
56c2633
Remove dead cmp test
Mar 27, 2022
6b81d98
Remove a lot of unnecessary OpenSPICE files
Mar 27, 2022
1c4cf88
Get examples passing. Many tests excluded. No guarantee of correctness.
Mar 28, 2022
628fd5f
Made some headway on AC analysis. Need to figure out complex number h…
Mar 28, 2022
7038689
Enable fundamental laws tests
Mar 28, 2022
c957593
Got passive test yielding results. Not sure if they're correct
Mar 29, 2022
cfcd5ec
Fixed broken transient sims
Mar 29, 2022
3ba573b
Enable passive test and results dumping
Mar 29, 2022
7ce898d
Make dumping optional
Mar 30, 2022
231cb7b
Additional transient parameter support added
Mar 31, 2022
f373725
Fixed remaining bug breaking examples
Mar 31, 2022
3787a50
Can parse resistors
Mar 31, 2022
c350aa2
Cleaned up resistor parsing
Mar 31, 2022
8fa340a
Added capacitor support. No test yet.
Mar 31, 2022
1a1d42e
Fixed capacitor support
Mar 31, 2022
60e3473
Organize code better
Mar 31, 2022
a1131b7
Added inductor support
Mar 31, 2022
f7fdefc
Fixed RLC bugs
Mar 31, 2022
5966890
Technical plan for OpenSPICE revamp
Mar 31, 2022
0f7c8cc
Devplan
Mar 31, 2022
97d6d89
Added vsources
Mar 31, 2022
63b9147
Added isources
Mar 31, 2022
2786cdd
Check off current sources from todo list
Mar 31, 2022
74c4517
Add external sources
Mar 31, 2022
61e6be7
Add VCCS to parser
Mar 31, 2022
25d2ac5
Add generic dependent source formatting
Mar 31, 2022
5d6289f
Added full linear dependent source support
Mar 31, 2022
44c9942
Checked off linear dependent sources from todo list
Mar 31, 2022
bd5c172
Add scaffolding for behavioral sources. Fix later.
Mar 31, 2022
f6f123a
Administrative changes for behav sources
Mar 31, 2022
50dec17
Add behavioral source todo
Mar 31, 2022
00b12fd
Add initial scaffolding for control expression
Mar 31, 2022
51fd538
Added control parsing logic. No testing yet.
Mar 31, 2022
92e5ac0
Op point parsing working
Mar 31, 2022
ba24216
Basic tran working
Mar 31, 2022
af9b5c0
Updated TODOs file
Mar 31, 2022
bf3fa2f
Added another comment todos file.
Mar 31, 2022
ba2da1a
Broke off component classes into components.py file
Apr 1, 2022
e2ec253
Add strategy pattern skeleton to eqnstr.py
Apr 1, 2022
93129be
Basic KCL op point formatting working
Apr 1, 2022
706dbe7
Enabled equation generation for op point sims
Apr 1, 2022
7d9fcbe
Modify common formatting to support most of the behavioral source syntax
Apr 1, 2022
c08d45f
Move function to abstract class
Apr 1, 2022
fb90b6a
Move another function to abstract class
Apr 1, 2022
70a2b97
Added transient equations
Apr 1, 2022
b4d71e7
Transient equations working
Apr 1, 2022
fadd3d3
Get OpenSPICE preliminary top level script working
Apr 1, 2022
7458310
Remove unnecessary context object
Apr 1, 2022
721a556
Fixed equation string formatting for op pt sims
Apr 1, 2022
a5d5717
Fixed transient sim eqn gen
Apr 1, 2022
3e348b0
Add initial conditions to eqnstr
Apr 2, 2022
b86b271
Solvers works, but spits out incorrect result
Apr 2, 2022
06d5e4c
Fixed op point bug
Apr 3, 2022
035824b
Narrowed down bizarre bug
Apr 3, 2022
0c6e5a6
Added transient solver code
Apr 3, 2022
2e71e70
Updated eqn generation for transient sims
Apr 3, 2022
61d74c0
Finish up basic OpenSPICE script
Apr 4, 2022
a94c76f
Basic OpenSPICE integration
Apr 5, 2022
6bbf25d
Fixed some parser issues
Apr 5, 2022
b004858
Enable Thevenin test
Apr 5, 2022
cd913a9
Enabled voltage divider test
Apr 5, 2022
fc98b65
Fix SI unit regex
Apr 5, 2022
c72f3ab
Fixed bug in transient sim
Apr 8, 2022
014a043
Refactor components.py
Nov 12, 2022
422108d
Clean up common.py
Nov 12, 2022
ff9a6f0
Document components library
Nov 12, 2022
7a12d2c
Document eqnstr.py
Nov 12, 2022
e2547ea
Add documentation to genout.py
Nov 14, 2022
d029b5d
Add assertions to genout
Nov 14, 2022
08dfa4c
Add documentation to netlist.py
Nov 17, 2022
721eb16
Remove useless comment from netlist.py
Nov 18, 2022
05df35f
Add documentation to solve.py
Nov 18, 2022
230fbb4
Add documentation
Nov 18, 2022
f506183
Update documentation with mainpage
Nov 18, 2022
f83505e
If-else branch OS removed.
gdetor Nov 23, 2022
b33df85
Fix Windows issue
thejackal360 Feb 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/pyspice-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Pyspice Test

on:
push:
branches: [ master ]
branches: "*"
pull_request:
branches: [ master ]
branches: "*"

jobs:
build:
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions OpenSPICE-revamp/dep_sources.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
G1 1 0 1 0 1
E1 1 0 1 0 1
F1 1 0 1 0 1
H1 1 0 1 0 1
R1 1 0 1
4 changes: 4 additions & 0 deletions OpenSPICE-revamp/ext_sources.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
V1 1 0 dc 0 external
R1 1 2 1
R2 2 3 1
I1 3 0 dc 0 external
2 changes: 2 additions & 0 deletions OpenSPICE-revamp/isource.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
I1 1 0 1
R1 1 0 1
4 changes: 4 additions & 0 deletions OpenSPICE-revamp/multi_r_netlist.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
R1 1 0 1
R2 2 3 1
R3 1 2 4
R4 3 0 5
1 change: 1 addition & 0 deletions OpenSPICE-revamp/one_r_netlist.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
R1 1 0 1
6 changes: 6 additions & 0 deletions OpenSPICE-revamp/op_pt.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
V1 1 0 1
R1 1 0 1

.control
.op
.end
7 changes: 7 additions & 0 deletions OpenSPICE-revamp/op_pt_divider.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
V1 1 0 1
R1 1 2 1
R2 2 0 1

.control
.op
.end
2 changes: 2 additions & 0 deletions OpenSPICE-revamp/rc_netlist.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
R1 1 0 1
C1 1 0 1
2 changes: 2 additions & 0 deletions OpenSPICE-revamp/rc_netlist_w_ic.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
R1 1 0 1
C1 1 0 1 ic=1
1 change: 1 addition & 0 deletions OpenSPICE-revamp/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Arpeggio==1.10.2
2 changes: 2 additions & 0 deletions OpenSPICE-revamp/rl_netlist.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
R1 1 0 1
L1 1 0 1
3 changes: 3 additions & 0 deletions OpenSPICE-revamp/rlc_netlist.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
R1 1 0 1
L1 1 0 1
C1 1 0 1
3 changes: 3 additions & 0 deletions OpenSPICE-revamp/rlc_netlist_w_ic.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
R1 1 0 1
L1 1 0 1 ic=1
C1 1 0 1 ic=1
7 changes: 7 additions & 0 deletions OpenSPICE-revamp/tran.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
V1 1 0 1
R1 1 2 1
C1 2 0 1 ic=1

.control
.tran 1 100 0 1 uic
.end
2 changes: 2 additions & 0 deletions OpenSPICE-revamp/vccs.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
G1 1 0 1 0 1
R1 1 0 1
2 changes: 2 additions & 0 deletions OpenSPICE-revamp/vsource.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
V1 1 0 1
R1 1 0 1
6 changes: 6 additions & 0 deletions PySpice/Config/ConfigInstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def __init__(self):
self._name = 'windows'
elif sys.platform.startswith('darwin'):
self._name = 'osx'
elif sys.platform.startswith('freebsd'):
self._name = 'freebsd'

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

Expand All @@ -40,6 +42,10 @@ def on_windows(self):
def on_osx(self):
return self._name == 'osx'

@property
def on_freebsd(self):
return self._name == 'freebsd'

OS = OsFactory()

####################################################################################################
Expand Down
30 changes: 25 additions & 5 deletions PySpice/Spice/NgSpice/Shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,31 @@ def setup_platform(cls):
cls.LIBRARY_PATH = _
else:
if ConfigInstall.OS.on_windows:
ngspice_path = Path(__file__).parent.joinpath('Spice64_dll')
cls.NGSPICE_PATH = ngspice_path
# path = ngspice_path.joinpath('dll-vs', 'ngspice-{version}{id}.dll')
path = ngspice_path.joinpath('dll-vs', 'ngspice{}.dll')
# Check for MSYSTEM environment first
msystem = os.environ.get('MSYSTEM')
mingw_prefix = os.environ.get('MINGW_PREFIX')

if msystem and mingw_prefix:
# Use MINGW paths
path = str(Path(mingw_prefix) / 'bin' / 'libngspice-0{}.dll')
if 'SPICE_LIB_DIR' not in os.environ:
os.environ['SPICE_LIB_DIR'] = str(Path(mingw_prefix) / 'share' / 'ngspice' / 'scripts')
else:
# Fall back to original Windows paths
ngspice_path = Path(__file__).parent.joinpath('Spice64_dll')
cls.NGSPICE_PATH = ngspice_path
# path = ngspice_path.joinpath('dll-vs', 'ngspice-{version}{id}.dll')
path = str(ngspice_path.joinpath('dll-vs', 'ngspice{}.dll'))

elif ConfigInstall.OS.on_osx:
path = 'libngspice{}.dylib'

elif ConfigInstall.OS.on_linux:
path = 'libngspice{}.so'

elif ConfigInstall.OS.on_freebsd:
path = 'libngspice{}.so'

else:
raise NotImplementedError

Expand Down Expand Up @@ -620,7 +634,12 @@ def _send_char(message_c, ngspice_id, user_data):
self._stderr.append(content)
if content.startswith('Warning:'):
func = self._logger.warning
# elif content.startswith('Warning:'):
elif content.startswith('Using'): # Ignore "Using ... as Direct Linear Solver" messages
func = self._logger.debug
elif content.startswith('doAnalyses:'):
func = self._logger.debug
elif content.startswith('run simulation interrupted'):
func = self._logger.debug
else:
self._error_in_stderr = True
func = self._logger.error
Expand Down Expand Up @@ -697,6 +716,7 @@ def _background_thread_running(is_running, ngspice_id, user_data):
self = ffi.from_handle(user_data)
self._logger.debug('ngspice_id-{} background_thread_running {}'.format(ngspice_id, is_running))
self._is_running = is_running
return 0

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

Expand Down
14 changes: 9 additions & 5 deletions PySpice/Spice/NgSpice/Simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,23 @@ def ngspice(self):
##############################################

def _run(self, analysis_method, *args, **kwargs):
background = kwargs.pop('background', False)

super()._run(analysis_method, *args, **kwargs)

self._ngspice_shared.destroy()
# load circuit and simulation
# Fixme: Error: circuit not parsed.
self._ngspice_shared.load_circuit(str(self))
self._ngspice_shared.run()
self._ngspice_shared.run(background=background)
self._logger.debug(str(self._ngspice_shared.plot_names))
self.reset_analysis()
if not background:
self.reset_analysis()

plot_name = self._ngspice_shared.last_plot
if plot_name == 'const':
raise NameError('Simulation failed')
plot_name = self._ngspice_shared.last_plot
if plot_name == 'const':
raise NameError('Simulation failed')
else:
return True #Nothing to show yet!

return self._ngspice_shared.plot(self, plot_name).to_analysis()
2 changes: 1 addition & 1 deletion PySpice/Spice/NgSpice/SimulationType.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
'charge',
)

LAST_VERSION = 34 # released on January 31st, 2021
LAST_VERSION = 43 # released on January 31st, 2021

for version in range(28, LAST_VERSION +1):
SIMULATION_TYPE[version] = SIMULATION_TYPE[27]
Expand Down
Loading