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

Pari stack overflow #9

Closed
ghost opened this issue Sep 12, 2006 · 1 comment
Closed

Pari stack overflow #9

ghost opened this issue Sep 12, 2006 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 12, 2006

Once the Pari stack overflows, subsequent sage commands which use the Pari library do not work.

Ifti.


burhanud@sage:~$ sage
--------------------------------------------------------
| SAGE Version 1.3.7.1, Build Date: 2006-09-10-2157    |
| Distributed under the GNU General Public License V2. |
--------------------------------------------------------


sage: E = EllipticCurve([0,0,0,-307*1907,0])

sage: E.Lseries_deriv_at1()
---------------------------------------------------------------------------
exceptions.RuntimeError                              Traceback (most
recent call last)

/home/burhanud/<ipython console>

/home/was/sage/local/lib/python2.4/site-packages/sage/schemes/elliptic_curves/ell_rational_field.py
in Lseries_deriv_at1(self, k)
   1724         # Compute z = e^(-2pi/sqrt(N))
   1725         pi = 3.14159265358979323846
-> 1726         v = transcendental.exponential_integral_1(2*pi/sqrtN, k)
   1727         L = 2*float(sum([ (v[n-1] * an[n])/n for n in
xrange(1,k+1)]))
   1728         error = 2*exp(-2*pi*(k+1)/sqrtN)/(1-exp(-2*pi/sqrtN))

/home/was/sage/local/lib/python2.4/site-packages/sage/functions/transcendental.py
in exponential_integral_1(x, n)
     83         return float(pari(x).eint1())
     84     else:
---> 85         return [float(z) for z in pari(x).eint1(n)]
     86
     87 def gamma(s):

/home/burhanud/gen.pyx in gen._pari_trap()

RuntimeError: The PARI stack overflowed.  Use pari.allocatemem() to double
the stack.

sage: factor(4)
---------------------------------------------------------------------------
exceptions.RuntimeError                              Traceback (most
recent call last)

/home/burhanud/<ipython console>

/home/was/sage/local/lib/python2.4/site-packages/sage/rings/arith.py in
factor(n, proof, int_, algorithm, verbose)
   1244     if algorithm == 'pari':
   1245         return factorization.Factorization(__factor_using_pari(n,
-> 1246                                    int_=int_,
debug_level=verbose), unit)
   1247     elif algorithm == 'kash':
   1248         F = kash.eval('Factorization(%s)'%n)

/home/was/sage/local/lib/python2.4/site-packages/sage/rings/arith.py in
__factor_using_pari(n, int_, debug_level)
   1168         import sage.rings.integer_ring
   1169         Z = sage.rings.integer_ring.IntegerRing()
-> 1170     prev = pari.get_debug_level()
   1171     pari.set_debug_level(debug_level)
   1172     F = pari(n).factor()

/home/burhanud/gen.pyx in gen.PariInstance.get_debug_level()

/home/burhanud/gen.pyx in gen.PariInstance.default()

/home/burhanud/gen.pyx in gen._pari_trap()

RuntimeError: The PARI stack overflowed.  Use pari.allocatemem() to double
the stack.

sage: factor(4, algorithm='kash')
 2^2

Component: basic arithmetic

Issue created by migration from https://trac.sagemath.org/ticket/9

Repository owner added c: basic arithmetic labels Sep 12, 2006
@williamstein
Copy link
Contributor

comment:1

Fixed by modifying _pari_trap in devel/sage/sage/libs/pari/gen.pyx:

cdef void _pari_trap "_pari_trap" (long errno, long retries) except *:
    if retries > 100:
        raise RuntimeError, "_pari_trap recursion too deep"
    if errno == errpile:
        P.allocatemem()
        raise RuntimeError, "The PARI stack overflowed.  It has automaticallyed been doubled using pari.allocatemem().  Please retry your computation, possibly after you manually call pari.allocatemem() a few times."
    

vbraun pushed a commit that referenced this issue Mar 26, 2023
    
### 📚 Description

Trac branch `u/gh-collares/gap-gc` from #34701, now migrated to GitHub.
Currently based atop #35093; will rebase once that is merged.

The rest of the description below is copied from #34701:

A refactor in #27946 introduced "unprotected" (not surrounded by
`GAP_Enter`/`GAP_Leave`) `GAP_ValueGlobalVariable` calls. I believe this
might be a GC hazard, because after updating to GAP 4.12.1 I started
seeing aarch64 crashes on NixOS infrastructure such as:

```
#0  0x0000fffff79740e8 in wait4 ()
#1  0x0000fffff5dc6b78 in print_enhanced_backtrace ()
#2  0x0000fffff5dc8190 in sigdie ()
#3  0x0000fffff5dcb1c0 in cysigs_signal_handler ()
#4  0x0000fffff7ffb7cc in __kernel_rt_sigreturn ()
#5  0x0000ffff99a0bf28 in ConvString ()
#6  0x0000000000000000 in ?? ()
#7  0x0000000000000000 in ?? ()
#8  0x0000000000000000 in ?? ()
#9  0x0000ffff99989930 in Pr ()
#10 0x0000ffff9998aa18 in CloseOutput ()
#11 0x0000ffff99884828 in capture_stdout () at /build/sage-
src-9.7/pkgs/sagemath-standard/sage/libs/gap/element.pyx:154
...
```
I also see cases where `capture_stdout` throws errors such as
`sage.libs.gap.util.GAPError: Error, Length: <list> must be a list (not
the integer 255)` and then crashes. Both types of errors are fixed by
this ticket.

Note that I am nesting `GAP_Enter`/`GAP_Leave` calls because I didn't
remove the preexisting calls inside `capture_stdout`. That's because I
feared removing the innermost calls might create a new footgun (and I
believe nested `GAP_Enter`/`GAP_Leave` calls are explicitly supported),
but removing them should cause no problem. Removing them might even be
preferable for performance reasons, I don't know.

Fixes #34701

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] I have made sure that the title is self-explanatory and the
description concisely explains the PR.
- [x] I have linked an issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies
<!-- List all open pull requests that this PR logically depends on -->
<!--
- #xyz: short description why this is a dependency
- #abc: ...
-->
- #35093: GAP 4.12.2 upgrade, which touches the same function and should
land first.
    
URL: #35114
Reported by: Mauricio Collares
Reviewer(s): Dima Pasechnik
vbraun pushed a commit that referenced this issue Jun 3, 2023
jsantillan3 pushed a commit to jsantillan3/sage that referenced this issue Jul 28, 2023
vbraun pushed a commit that referenced this issue Oct 8, 2023
xuluze added a commit to xuluze/sage that referenced this issue Dec 12, 2023
xuluze added a commit to xuluze/sage that referenced this issue Feb 23, 2024
xuluze added a commit to xuluze/sage that referenced this issue Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants