So I’m getting segfaults in randomly places in a piece of code that’s calling a particular Sage/GAP function inside of an alarm…try…except block. The error looks kinda Python-y, rather than Sage-y, so I’m hoping someone here can point me in the right direction.
Error looks like this:
48 [[2, 11, 10, 13], [12, 3, 12, 8], [11, 9], [13, 12, 9], [13], [3, 9, 13, 13], [5, 3, 1], [7, 5, 12], [8, 3, 12, 14], [12, 6], [7], [13, 9]]
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
import fnmatch, glob, traceback, errno, sys, atexit, locale, imp, stat
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/sage/groups/free_group.py", line 878, in _element_constructor_
P = x.parent()
AttributeError: 'list' object has no attribute 'parent'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/cduston/Dropbox/Research/LQG/TopStatesSage/MWE.sage.py", line 39, in <module>
Y1=[H(Y[i]) for i in range(g*V)]
File "/home/cduston/Dropbox/Research/LQG/TopStatesSage/MWE.sage.py", line 39, in <listcomp>
Y1=[H(Y[i]) for i in range(g*V)]
File "sage/structure/parent.pyx", line 898, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9458)
File "sage/structure/coerce_maps.pyx", line 156, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4627)
File "/usr/lib/python3/dist-packages/sage/groups/free_group.py", line 880, in _element_constructor_
return self.element_class(self, x, **kwds)
File "/usr/lib/python3/dist-packages/sage/groups/free_group.py", line 229, in __init__
AbstractWordTietzeWord = libgap.eval('AbstractWordTietzeWord')
File "sage/libs/gap/libgap.pyx", line 400, in sage.libs.gap.libgap.Gap.eval (build/cythonized/sage/libs/gap/libgap.c:4365)
File "sage/libs/gap/util.pyx", line 388, in sage.libs.gap.util.gap_eval (build/cythonized/sage/libs/gap/util.c:6054)
cysignals.signals.SignalError: Segmentation fault
The MWE is included below, but I can pseudo code it:
Randomly Create a List
Use that list to create a finite group (Sage things…)
try to do something with that group
If it fails in some way GAP can handle, tell me
If it fails in some way GAP can’t handle, tell me
If it takes too long, tell me!
If I do this too many times, it Segfaults. Advice?
g=3 # Covers, but this is just a multiplicative factor here
E=5 # edges in the graph
V=4 # Sides in the graph (relations)
W=5 # Max word size for the relations
H=FreeGroup(E*g)
N=1000
ExCases = 0 # To keep track of exceptional cases....
for i in range(N):
# Randomly create some relations
Y = []
for j in range(V*g):
YY = []
for k in range(randrange(1,W)):
num = randrange(1,g*E)
sign = randrange(1,2) # positive or negative
if sign == 1:
YY.append(num)
elif sign == 2:
YY.append(-num)
#print(YY)
Y.append(YY)
print(i,Y)
# Now calculate the structure of the group
Y1=[H(Y[i]) for i in range(g*V)]
G=H/Y1
#G=H/[H(Y[i]) for i in range(g*V)]
print(Y1,G)
alarm(5)
try:
grpstr = str(G.structure_description())
except ValueError:
if G.simplified().relations() == ():
grpstr = "F" + str(G.simplified().ngens())
else:
grpstr = "--"
ExCases += 1
pass
except AlarmInterrupt:
grpstr = "--"
ExCases += 1
pass
except:
print("Some Unhandled exception!")
pass
cancel_alarm()
print("Group Type is:",grpstr)
print("Exceptional cases:",ExCases)