This is a follow-up of discussion https://sourceforge.net/p/ngspice/discussion/127605/thread/7ba9a548d7/
NGspice 32 shows a non-deterministic behaviour of its DC transient solution, even with a simple circuit. The algorithm fails to find a solution about 25% of the times I run it. If compiled with STEPDEBUG enabled, and one can see that the results start to diverge after the message 'limited by pre-breakpoint delta' is printed, see attachment.
To reproduce this issue, build ngspice 32 from git master branch, and call several times:
./src/ngspice -b -r Vsetpoint.raw Vsetpoint.cir | grep unrecorded
Thanks in advance.
What happens if you put a really high-value resistor in parallel with C4?
Or maybe put an initial condition on Vref Net-C4-Pad1 ?
--
Kind regards,
Justin Fisher.
Thanks for the hints. I have tried both options you suggested, but still get the same error.
I have also tried removing R4 and C4 completely from the netlist, but it still fails about 25% of the times.
I have also added on C2 and C6 a big resistor in parallel, but it still fails.
If I remove from the circuit either C2, or "c5 and c6", then it works fine. But why should it be non-deterministic otherwise?
Could you please check ngspice from the pre-master branch? That is the actual development branch. There has been removed at least one memory corruption error.
I just tried with the pre-master branch. Similar issue.
One thing I have noticed (in both versions) is that the non-deterministic problem might come from the use of the subcircuit (Potentiometer.lib).
If I replace:
with
the simulation always runs well.
However, I do not see why this subcircuit with the parameters should be wrong; it appears in several examples online, https://electronics.stackexchange.com/a/229548 https://bugs.launchpad.net/kicad/+bug/1766931
Maybe something is not being initalized correctly for Rtot, or w?
I think I found out why it is failing. Apparently, ngspice does not cope well the function 'limit'. What I do not understand is why it does not give a warning saying 'function not recognized, or incorrect signature, or something like that.
So, if one adds this to the subcircuit, it works fine:
.func limit(x, y, z) {min(max(x, min(y, z)), max(z, y))}(https://sourceforge.net/p/ngspice/discussion/133842/thread/5ab13322/)
I found out by enabling ngdebug, where I could see that the expression evaluator was interpreting that the potentiometer has negative resistances, because the 'limit' function was interpreted somehow randomly.
**************** uncommented deck **************In ngspice-32, limit is defined as
There was a reason for the difference.
The limit function is not in the KLU branch and I seem to have
hard-codedit:I did not expect the problem to be in limit(), so I didn't even think about mentioning
it. Anyway, even with a different limit() function non-determinism should not happen.
-marcel
Thanks.
Concerning non-determinism, clang reports some uninitialized values in the code that might be the source of error, see full report here:
https://sourceforge.net/p/ngspice/bugs/502/#d398
On 2020-08-16 19:36, Ferdy wrote:
There is also Occam's razor :-)
Things will become much more interesting as soon as an example is
provided that can be independently verified.
-marcel
This is the typical bug which generates non-determinism.
On Linux, just run your simulation with Valgrind to see that.
The other typical root cause is ordering by pointers, but I don’t think NGSPICE makes usage of it.
Fra
Related
Bugs: #505
Valggrind does not show anything (except for a memory leak when the tran simulation is aborted).
But doing a 'listing e', if run interactively, you may get
Negative resistance, sometimes so (and crashing tran), sometimes
and not crashing.
The root cause is the 'limit' function in line 20 of Potentiometer.lib. We had problems with it already in other places.
It is a problem of compatibility of different 'limit' functions (spice3, ngspice, PSPICE, HSPICE). I will look into this.
Last edit: Holger Vogt 2020-08-17
On 2020-08-16 19:36, Ferdy wrote:
I thought we decided that the perceived problem roots in an incorrect
definition of the build-in 'limit' function.
(Of course) we can't prove that NGSPICE always behaves
deterministically.
If we look at the presented case, we might attempt to state that even
a wrongly defined LIMIT function should still result in NGSPICE doing
the same thing every time. The idea then is that when f is defined
as '3x^2 - 5' instead of '2x^2 - 5' we find different roots for f, but
they are still the same for every run.
However, I think that there should be a restriction here: the
alternative
computation should be well-defined.
In the present case the wrong limit causes negative resistance. As a
result the Vpot goes to infinity around 7ms. So my proposal is to check
values only before that point. When we do that, there is no evidence
of non-determinism.
If we run this file with ngspice 32:
the result is
-marcel
Valgrind should show the unconditional jump due to uninitialized value.
Fra
Related
Bugs: #505
The standard limit function in ngspice is a HSPICE statistical function and is resolved to
and is using random numbers! So we get a strange "non-reproducibility".
Only when PSPICE compatibility is enabled, we have the limit function
I will have to find a meaure to separate the two functions, maybe based on the count of their parameters.
Last edit: Holger Vogt 2020-08-21