-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Memory exhaustion calculating very large integers #1152
Comments
It seems that the problem appears when it tries to calculate
|
Huh, I wonder where that power is coming from, it should only be calculating >>> 2**16777496
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit The other power is too big for WMA even, but at least it prints an error message instead: In[4]:= Power[2, 35184372088832]
General::nomem: The current computation was aborted because there was insufficient memory available to
complete the computation.
Throw::sysexc: Uncaught SystemException returned to top level. Can be caught with Catch[…,
_SystemException].
Out[4]= SystemException[MemoryAllocationFailure] |
I found where the evaluation stucks by wrapping the expression with The collapse of the evaluation does not happen if you use arbitrary precision Real numbers instead of integers. My guess is that WMA switch automatically the representation when it founds a so large number. |
@davidar, if in Python the computation works, and fails in Mathics, it could be also related to our cache/memoize mechanism. Maybe the problem is in trying to build a hash for such a large number. Something to check is to see what happens if we disable it. |
Interesting... |
I looked at this today. Basically, SymPy's Pow function can't handle the exponent it is given: 35184372088832 If you use TraceEvaluation, you'll see that exponent. Try this from Python:
mpmath can raise to 2 to this power:
but if you try to convert it into a MachineReal, this fails:
I am at a loss for what to do. Recently a change made by @mmatera made breaking the computation possible. Do you I suppose we could forward this problem to the mpmath or SymPy community to see how they suggest how to handle? |
WMA can do its own checks about the size of a problem, and decide to limit the time and memory that the computation used. When we send the computation to Sympy, we lose the control over the computation. What I did to allow the use of The problem is that even if we get disattached from the thread, the thread continues consuming resources, and for cases like the one in the example, eventually raises a core dump. |
Is your feature request related to a problem? Please describe.
The following program from https://oeis.org/A000643 causes mathics to use over 10GB of RAM, and I end up having to kill it to avoid it from exhausting all the memory on my machine:
To be fair, the program attempts to calculate an integer with over 5 million digits (inside the list
a
), which is why I'm not calling this a bug. But at the same time WMA handles this program completely fine, and gives a result almost immediately (it just takes a long time if you try to print the final value ofa
, but doesn't appear to use any substantial amount of memory)Describe the solution you'd like
Better memory efficiency for arbitrary precision arithmetic.
Describe alternatives you've considered
Don't attempt to calculate numbers that are that big ;)
The text was updated successfully, but these errors were encountered: