-
Notifications
You must be signed in to change notification settings - Fork 63
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
Enable dynamic parameters #238
base: master
Are you sure you want to change the base?
Conversation
Cool, regarding the vst plugin, we can cherry pick some stuff from my
implementation. Also, did you added the option to disable dynamic
parameters for spefific potentiometer?
…On Thu, 5 Dec 2024 at 10:39, Dillon ***@***.***> wrote:
This branch reverts a ~10 year old commit 238ba01
<238ba01>
to make simulation parameters (potentiometers) work the way they should:
the circuit is compiled with the potentiometer value as a variable, and
then the variable is substituted during simulation. This allows
continuously and smoothly varying the parameters!
Unfortunately, that approach struggled a lot with performance and
scalability. However, some recent discoveries (thanks to conversations with
@andy-cytomic <https://github.com/andy-cytomic> and @Federer
<https://github.com/Federer>'s #196
<#196>) have revived this
approach! Currently, there's still a pretty significant hit to performance
with this branch, but it's not *terrible*:
Circuit master dynamic-parameters
59 Bassman Preamp+Tone Stack 129.1 82.35 0.6378776143
Big Muff Pi 90.2 54.57 0.6049889135
Boss Super Overdrive SD-1 779.6 440.2 0.5646485377
Bridge Rectifier 812.4 828.1 1.019325455
Common Cathode Triode Amplifier 438.8 426.6 0.9721969006
Common Emitter Transistor Amplifier 1294 1261 0.9744976816
Dunlop Cry Baby GCB-95 308.1 119.9 0.3891593638
Fender 5e3 41.96 21.67 0.5164442326
Ibanez Tube Screamer TS-9 1285 552.4 0.4298832685
Marshall Blues Breaker 521.3 221 0.4239401496
Marshall JCM2000 DSL Preamp 59.91 36.25 0.6050742781
Marshall JCM800 2203 preamp modded 59.13 35.93 0.6076441739
Marshall JCM800 2203 Preamp 61.24 47.49 0.7754735467
MXR Distortion + 522.8 292 0.558530987
MXR Phase 90 38.07 49.92 1.311268716
Op-Amp Model 1482 1085 0.7321187584
The really key observation was from discussing this with @andy-cytomic
<https://github.com/andy-cytomic>, I realized that if we make an
intermediate variable for capacitor currents, that avoids the really
problematic impact of the parameter variables on the solution. More details
on #94 <#94>. This was
literally a one line change that already existed in the code! 5398a63
<5398a63>
This now means we do something more similar to the standard MNA procedure
for capacitors.
Still TODO:
- Update the VST plugin (cc @mikeoliphant
<https://github.com/mikeoliphant>)
- One of the example circuits is failing on this branch, due to an
expression explosion.
- The performance hit is not great. Unfortunately, the optimization in
#237 <#237>
disproportionately benefited master, so the gap between master and this
branch is now even bigger than it otherwise would have been.
I am pretty close to thinking that we should just merge this despite the
performance regression. Dynamic parameters are a huge win, I think they're
worth the performance hit, and I have a clear line of site to
ComputerAlgebra improvements that should mitigate the regression. I have
ideas for how to improve ComputerAlgebra significantly for this new
approach. Unfortunately me from 15 years ago was a bit dumb, so it's harder
than it should be to fix it.
Fixes #94 <#94>
------------------------------
You can view, comment on, or merge this pull request online at:
#238
Commit Summary
- 238ba01
<238ba01>
Revert "Admitting defeat on solving circuits with pots as variables"
- 5398a63
<5398a63>
Add a variable to the system for capacitor currents. This seemingly small
change means that we don't need to solve for differentials before
discretization, which may enable dynamic parameters to work! Partially
addressing #94
- c271540
<c271540>
Don't factor expressions in solve
- fc2c9d0
<fc2c9d0>
Don't try to parse parameter names as expressions
- b187c77
<b187c77>
Refactor sweep min/max for easier experimenting
- 61afff4
<61afff4>
Remove unused `Name`
- 06af620
<06af620>
Minor refactor
- ec3c0e3
<ec3c0e3>
Parameter values don't need to be expressions
- c01596e
<c01596e>
Respect Sweep type of Potentiometer/VariableResistor
- 5aa0347
<5aa0347>
Don't add unknowns for anonymous constants or other simple expressions
- 0eda7a6
<0eda7a6>
Merge branch 'master' into dynamic-parameters
File Changes
(11 files <https://github.com/dsharlet/LiveSPICE/pull/238/files>)
- *M* Circuit/Analysis.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-1a36e9638f12ee07463eb9d5f2265cdb1d6afb23e184cade70e78f0137c1ef50>
(55)
- *M* Circuit/Component.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-d9a5967bd0dba661575c7f61c3d40ea939cb8f4ba647ccb12d575cebf825429e>
(4)
- *M* Circuit/Components/Capacitor.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-4287d46d1258c51d822727bfeb9f0d82db02f2992b81f58197d058aba0bc2877>
(2)
- *M* Circuit/Components/Potentiometer.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-0455f866e45fa558b57d64e4b2fd8cd72434a53060600ae9b8296200bb757949>
(2)
- *M* Circuit/Components/VacuumTubes/Triode.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-9418e740399fb21a853f631dcc7513f11eb2591fec5b61f09f78cd447c466d32>
(6)
- *M* Circuit/Components/VariableResistor.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-623b20c6b2d82b7e35a7bf73f6eb22b975a008b3851fc44dd63138974cd9d1d2>
(4)
- *M* Circuit/Components/VoltageSource.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-f8d6b36551657d049741d5250f8d94bad276abdb407aeb9774ac9cbc2d96e0cc>
(8)
- *M* Circuit/Simulation/Simulation.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-10ec730892034e800c291d0f805a733d7b3037a427b51803eddf26122816a89b>
(34)
- *M* Circuit/Simulation/TransientSolution.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-f765db047225015311c8bede0be6b9c084287d0941abfe9907eaaa35ec69beb5>
(9)
- *M* LiveSPICE/LiveSimulation.xaml.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-988e19d3717b86b0300a4c81443fe82d3a256b370b8f288a423943c37be6a26e>
(128)
- *M* Tests/Test.cs
<https://github.com/dsharlet/LiveSPICE/pull/238/files#diff-cfa8996439db179bb0a50dc67481d2ae354c5533c12db174eede5603c02b8b03>
(13)
Patch Links:
- https://github.com/dsharlet/LiveSPICE/pull/238.patch
- https://github.com/dsharlet/LiveSPICE/pull/238.diff
—
Reply to this email directly, view it on GitHub
<#238>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEVGU4FT6EHBHDJAJZTPAAL2EANN5AVCNFSM6AAAAABTCBBDPOVHI2DSMVQWIX3LMV43ASLTON2WKOZSG4YTSOBXHEZDOMA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Thanks for the pointer, I think it will be helpful, I'll take a closer look tomorrow.
I didn't, but maybe we should. That would give an escape hatch in the case the performance hit is significant. I generally was thinking this was necessary when I thought the penalty for dynamic parameters was so much larger. IIRC you said on your branch that only one dynamic parameter was possible at a time. But now, just making all potentiometers dynamic seems to be OK (I can still run a lot of the big amp simulations with all potentiometers dynamic in real time). I think what we should do is:
|
Looking at this more closely, it probably makes more sense to have @Federerer update the VST, since it will involve refactoring the parameter UI interface. I thought the UI changes from a while back looked good. |
In the interest of moving this along, I took a stab at updating the VST code: Basically, it just removes the re-build on parameter changes, and passes the parameters when running the simulation. I'm getting an error when running, though. Not sure why. It happens when using the Mock VST as well, so it's easy to reproduce. @dsharlet any ideas? |
Thanks for doing that. I had a similar change I tried locally, and I ran into an issue where it seemed like the lifetime of the Circuit and Analysis objects were somehow not matching. I was hoping I just did something dumb in my VST update, but it sounds like you are hitting the same thing... so I'll take a closer look at that. BTW, quick update: I've been trying to find quick hack improvements to the computer algebra system to make this mergeable without the issues (performance slowdown + one broken example), but I think it's not happening. I have a clear line of sight to bigger changes to make, so I think I'm still going to merge this soon, and then work on a computer algebra system improvement in a follow-up change. |
I think I've got a race condition in the asyc simulation updating. Looking into fixing it now. |
Turns out, no - I forgot the background loading was using a lock. |
I've been refactoring the LiveSimulation class to break out the underlying simulation run/update behavior so that it can be reused in the VST. I've now got the VST not crashing, but the pots don't work because the values have to be updated differently now. Working on a fix for that. |
This branch reverts a ~10 year old commit 238ba01 to make simulation parameters (potentiometers) work the way they should: the circuit is compiled with the potentiometer value as a variable, and then the variable is substituted during simulation. This allows continuously and smoothly varying the parameters!
Unfortunately, that approach struggled a lot with performance and scalability. However, some recent discoveries (thanks to conversations with @andy-cytomic and @Federer's #196) have revived this approach! Currently, there's still a pretty significant hit to performance with this branch, but it's not terrible:
The really key observation was from discussing this with @andy-cytomic, I realized that if we make an intermediate variable for capacitor currents, that avoids the really problematic impact of the parameter variables on the solution. More details on #94. This was literally a one line change that already existed in the code! 5398a63 This now means we do something more similar to the standard MNA procedure for capacitors.
Still TODO:
I am pretty close to thinking that we should just merge this despite the performance regression. Dynamic parameters are a huge win, I think they're worth the performance hit, and I have a clear line of sight to ComputerAlgebra improvements that should mitigate the regression. I have ideas for how to improve ComputerAlgebra significantly for this new approach. Unfortunately me from 15 years ago was a bit dumb, so it's harder than it should be to fix it.
Fixes #94