Halite - an analog circuit simulator in ~1k lines of code

DSP, Plug-in and Host development discussion.
User avatar
Audiority
KVRian
738 posts since 15 Nov, 2005 from Italy

Post Mon Feb 12, 2018 3:37 am

Do you have a struct for the input signal to share? I'm used to place it in the U vector, but I'm a bit clueless how to place it in your code.

Thanks!
Audiority
Need a Kontakt scripter? Contact me.

mystran
KVRAF
4981 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Halite - an analog circuit simulator in ~1k lines of code

Post Mon Feb 12, 2018 3:57 am

Audiority wrote:Do you have a struct for the input signal to share? I'm used to place it in the U vector, but I'm a bit clueless how to place it in your code.
If you're talking about Halite, just look at what the function generator does: it puts the signal into a variable that it stamps as a "dynamic load" to the mna.b vector, so it gets replaced with the actual value every time it solves the system.

While the function generator uses a callback function to generate the input signal, you could just modify that part of the code to stream from a buffer or something instead.
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

User avatar
Audiority
KVRian
738 posts since 15 Nov, 2005 from Italy

Re: Halite - an analog circuit simulator in ~1k lines of code

Post Mon Feb 12, 2018 5:06 am

Thanks mystran. I totally missed out the function generator!
Audiority
Need a Kontakt scripter? Contact me.

Miles1981
KVRian
1355 posts since 26 Apr, 2004 from UK

Re: Halite - an analog circuit simulator in ~1k lines of code

Post Fri Mar 23, 2018 12:21 pm

I was wondering if an optimized version could be better done in Python.
Explaining myself. Let's say the JIT is LLVM. It may actually be easier to target clang AST instead of LLVM IR. From the AST, the matrix can be statically defined (and using Eigen, for instance), the derivatives could also be done symbolically and perhaps even some matrix inverses directly as well.

mystran
KVRAF
4981 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Halite - an analog circuit simulator in ~1k lines of code

Post Fri Mar 23, 2018 7:25 pm

Miles1981 wrote:I was wondering if an optimized version could be better done in Python.
Explaining myself. Let's say the JIT is LLVM. It may actually be easier to target clang AST instead of LLVM IR. From the AST, the matrix can be statically defined (and using Eigen, for instance), the derivatives could also be done symbolically and perhaps even some matrix inverses directly as well.
I honestly don't really understand any of what you are trying to say here... I mean I obviously understand what the words mean, but the underlying logic completely evades me.
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

Miles1981
KVRian
1355 posts since 26 Apr, 2004 from UK

Re: Halite - an analog circuit simulator in ~1k lines of code

Post Fri Mar 23, 2018 11:41 pm

I'm just thinking at what would be the easiest to target. LLVM IR or Clang AST, and the fact that in Python there are potentially more tools for automatic differentiation that in C++ (although there is DCO). So it may be easier to generate optimized code in Python than in C++.

mystran
KVRAF
4981 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Halite - an analog circuit simulator in ~1k lines of code

Post Sat Mar 24, 2018 12:22 am

Miles1981 wrote:I'm just thinking at what would be the easiest to target. LLVM IR or Clang AST, and the fact that in Python there are potentially more tools for automatic differentiation that in C++ (although there is DCO). So it may be easier to generate optimized code in Python than in C++.
Well, you only need automatic differentiation if you want to allow components with arbitrary equations that the user can type in (and automatically generate Newton evaluation for these). This runs into a whole new can of worms though. For example, if you try to implement something as simple as a diode in Spice (eg. I've tried in LtSpice) using a voltage controlled behavioural current source, you'll find that you run into all kinds of convergence issues that the built in diode doesn't have.

As well as LLVM IR goes, it's just SSA and if you can't generate SSA you probably can't generate an AST either... so personally I don't see a point why you'd want to draw clang into the mix (although I have to say I'm not convinced I want to use LLVM either; let's not discuss that though).
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

Return to “DSP and Plug-in Development”