help needed with debugging

84 views
Skip to first unread message

John Cremona

unread,
Jun 14, 2021, 3:41:36 PM6/14/21
to SAGE devel
I need help debugging the following. Unfortunately it only seems to
occur several hours into a computation and so I cannot give a minimal
example.

When you call the metho E.isogeny_class() on an elliptic curve E it
returns a cached object stored as the attribute _isoclass if that
exists, otherwise it computes it, and stores it before returning its
value. This is rather a standard thing to do. The code is around
line 3000 in sage/src/schemes/elliptic_curves/ell_number_field.py.
But here a KeyError is being raised. Can anyone see what is going on
and where the bug is?

John


KeyError Traceback (most recent call last)
/usr/local/sage/sage-9.3/local/lib/python3.9/site-packages/sage/structure/category_object.pyx
in sage.structure.category_object.CategoryObje
ct.getattr_from_category
(build/cythonized/sage/structure/category_object.c:7074)()
838 try:
--> 839 return self.__cached_methods[name]
840 except KeyError:

KeyError: '_isoclass'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
/usr/local/sage/sage-9.3/local/lib/python3.9/site-packages/sage/schemes/elliptic_curves/ell_number_field.py
in isogeny_class(self, reducible
_primes, algorithm, minimal_models)
3033 try:
-> 3034 return self._isoclass
3035 except AttributeError:

/usr/local/sage/sage-9.3/local/lib/python3.9/site-packages/sage/structure/category_object.pyx
in sage.structure.category_object.CategoryObje
ct.__getattr__ (build/cythonized/sage/structure/category_object.c:6993)()
832 """
--> 833 return self.getattr_from_category(name)
834

William Stein

unread,
Jun 14, 2021, 4:18:58 PM6/14/21
to sage-devel
I can't help but wonder what would happen if you change the code to
catch both AttributeError and KeyError. I.e., in

/usr/local/sage/sage-9.3/local/lib/python3.9/site-packages/sage/schemes/elliptic_curves/ell_number_field.py

replace "except AttributeError:" by "except (AttributeError,
KeyError):". At least then maybe your code that you care about
won't crash... Of course, this is not getting to the root cause at
all.
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/CAD0p0K6Uqbt5%3DraxtE0x2hGjnzxm6Vggw8k4rHiKmjmdn3OC%3DA%40mail.gmail.com.



--
William (http://wstein.org)

John Cremona

unread,
Jun 15, 2021, 3:37:27 AM6/15/21
to SAGE devel
Thanks, William. So I don't have to rebuild Sage on the machine this
is running on, what I will do instead is to replace the call to
E.isogeny_class() with what that method actually does behind the
scenes, namely

from sage.schemes.elliptic_curves.isogeny_class import
IsogenyClass_EC_NumberField
self._isoclass = IsogenyClass_EC_NumberField(self,
reducible_primes=reducible_primes, algorithm=algorithm,
minimal_models=minimal_models)

since I know that I will only call this once for each curve anyway.

In case anyone is interested, this is happening while preparing data
for the LMFDB for elliptic curves over Q(sqrt(-19)).

John
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/CACLE5GCFDXjzGMs9xS_qY3pA%3DLYzEO2fxQ-3tR3R5-6xCDQ4Zg%40mail.gmail.com.

Samuel Lelievre

unread,
Jun 15, 2021, 6:07:16 AM6/15/21
to sage-devel
2021-06-15 07:37:27 UTC, John Cremona:
>
> Thanks, William. So I don't have to rebuild Sage on the machine this
> is running on, what I will do instead is to replace the call to
> E.isogeny_class() with what that method actually does behind the
> scenes, namely
>
> from sage.schemes.elliptic_curves.isogeny_class import
> IsogenyClass_EC_NumberField
> self._isoclass = IsogenyClass_EC_NumberField(self,
> reducible_primes=reducible_primes, algorithm=algorithm,
> minimal_models=minimal_models)
>
> since I know that I will only call this once for each curve anyway.
>
> In case anyone is interested, this is happening while preparing data
> for the LMFDB for elliptic curves over Q(sqrt(-19)).
>
> John


Getting a reproducible example to trigger the bug would be nice.

Could this help give one?

```
try:
    E.isogeny_class()

except AttributeError, KeyError:

    # Print out the example
    print(f"\nError calling isogeny_class on:\n{E}\n")

    # Work around the bug
    from sage.schemes.elliptic_curves.isogeny_class import (
            IsogenyClass_EC_NumberField)
    self._isoclass = IsogenyClass_EC_NumberField(self,
            reducible_primes=reducible_primes,
            algorithm=algorithm,
            minimal_models=minimal_models)
```

Of course, the import could be done once for all
at the start of your code:

```
from sage.schemes.elliptic_curves.isogeny_class import (
        IsogenyClass_EC_NumberField)
```

and the computation of isogeny class in your loop could skip it:

```
try:
    E.isogeny_class()

except AttributeError, KeyError:

    # Print out the example
    print(f"\nError calling isogeny_class on:\n{E}\n")

    # Work around the bug
```

John Cremona

unread,
Jun 15, 2021, 6:35:03 AM6/15/21
to SAGE devel
Thanks for the suggestion. At the moment I am more interested in
completing my computation than in debugging Sage internals (this
cannot possibly be anything specific to the elliptic curve class,
surely?), so I am avoiding calling the isogeny_class() method and
calling IsogenyClass_EC_NumberField() directly in the script I am
running.

John
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/f001c8b6-4a55-4818-96ce-5148d1427e29n%40googlegroups.com.

John Cremona

unread,
Jun 15, 2021, 10:45:20 AM6/15/21
to SAGE devel
In case anyone is still interested: doing what I proposed, I got >95%
of the way through my data processing before a similar thing happened,
and now the traceback does help. I will post it here.

In a nutshell, there is a try/except block deep in the coercion code,
specifically these lines 154ff of sage/structure/coerce_maps.pyx:

try:
return C._element_constructor(x)
except Exception:
if print_warnings:
print(type(C), C)
print(type(C._element_constructor), C._element_constructor)
raise

In my code I construct a lot of elliptic curves over finite fields
(which are residue fields of number fields). The actual top-level
error I see is "SystemError: calling remove_from_pari_stack() inside
sig_on()".

John
traceback.txt

John Cremona

unread,
Jun 16, 2021, 4:18:14 AM6/16/21
to SAGE devel
I ran the same code with Sage 9.2 and it completed with no problem.

John
Reply all
Reply to author
Forward
0 new messages