ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 30 Jul 2013 05:39:54 -0500Force Gap to forget graph automorphism groupshttp://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/I'm interested in computing and storing a huge number of graphs. For each graph I compute, I temporarily need to compute its automorphism group -- but I don't need to, and don't want to, remember that automorphism group. It looks like sage deals with graphs on its own but calls Gap to deal with automorphism groups.
The problem is that Gap, not sage, exceeds it permitted memory. Why? Here is a (silly) example of what I'm talking about: running
mylist=[];
count = 1;
while True:
g = graphs.RandomGNP(6, .5);
aut = g.automorphism_group();
mylist.append(g);
if aut.order() > 1:
print "Graph number %s has nontrivial automorphisms!"%(count);
count += 1;
gives me after some hours
RuntimeError: Gap produced error output
Error, exceeded the permitted memory (`-o' command line option)
How can I force sage/gap to forget the automorphism groups attached to the graphs (but remember the graphs)? Ideally Gap should only need to store one automorphism group at a time.Fri, 26 Jul 2013 02:43:43 -0500http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/Answer by Volker Braun for <p>I'm interested in computing and storing a huge number of graphs. For each graph I compute, I temporarily need to compute its automorphism group -- but I don't need to, and don't want to, remember that automorphism group. It looks like sage deals with graphs on its own but calls Gap to deal with automorphism groups. </p>
<p>The problem is that Gap, not sage, exceeds it permitted memory. Why? Here is a (silly) example of what I'm talking about: running</p>
<pre><code>mylist=[];
count = 1;
while True:
g = graphs.RandomGNP(6, .5);
aut = g.automorphism_group();
mylist.append(g);
if aut.order() > 1:
print "Graph number %s has nontrivial automorphisms!"%(count);
count += 1;
</code></pre>
<p>gives me after some hours</p>
<pre><code>RuntimeError: Gap produced error output
Error, exceeded the permitted memory (`-o' command line option)
</code></pre>
<p>How can I force sage/gap to forget the automorphism groups attached to the graphs (but remember the graphs)? Ideally Gap should only need to store one automorphism group at a time.</p>
http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?answer=15276#post-id-15276Any live Sage object will keep a reference to a GAP object alive. Also, Sage objects in cyclic references will never have their bound GAP objects cleared (though that works in LibGAP). Use `gap.NamesUserGVars()` to list all global GAP variables (the ones starting with `$sage` are associated to Sage objects).Mon, 29 Jul 2013 03:57:49 -0500http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?answer=15276#post-id-15276Comment by MT for <p>Any live Sage object will keep a reference to a GAP object alive. Also, Sage objects in cyclic references will never have their bound GAP objects cleared (though that works in LibGAP). Use <code>gap.NamesUserGVars()</code> to list all global GAP variables (the ones starting with <code>$sage</code> are associated to Sage objects).</p>
http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17219#post-id-17219Thanks -- gap.NamesUserGVars() is very useful. Can you clarify what is meant by "Sage objects in cyclic references will never have their bound GAP objects cleared?" is there an instance of cyclic referencing in the sample code? It's strange: if I delete the "if" statement that computes the order of the group aut, then adding the line del(aut) at the end of the loop solves the memory leak. But if I compute the order of the group, or compute anything else about it, then no amount of deleting gets rid of it (not even saving its properties like order in separate variables and deleting them.)Mon, 29 Jul 2013 15:48:37 -0500http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17219#post-id-17219Comment by slelievre for <p>Any live Sage object will keep a reference to a GAP object alive. Also, Sage objects in cyclic references will never have their bound GAP objects cleared (though that works in LibGAP). Use <code>gap.NamesUserGVars()</code> to list all global GAP variables (the ones starting with <code>$sage</code> are associated to Sage objects).</p>
http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17218#post-id-17218Volker: by "Sage objects in cyclic references", do you mean Sage objects referenced
in a loop? What about in a test clause?
MT: have you tried
g.automorphism_group(order=True,return_group=False)
Mon, 29 Jul 2013 16:26:12 -0500http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17218#post-id-17218Comment by MT for <p>Any live Sage object will keep a reference to a GAP object alive. Also, Sage objects in cyclic references will never have their bound GAP objects cleared (though that works in LibGAP). Use <code>gap.NamesUserGVars()</code> to list all global GAP variables (the ones starting with <code>$sage</code> are associated to Sage objects).</p>
http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17217#post-id-17217thanks much, I didn't know about the option to return only the order. I should clarify that sadly, in my actual code, I *do* need to look at all of the automorphisms (the sample code was oversimplified).Mon, 29 Jul 2013 17:07:40 -0500http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17217#post-id-17217Comment by Volker Braun for <p>Any live Sage object will keep a reference to a GAP object alive. Also, Sage objects in cyclic references will never have their bound GAP objects cleared (though that works in LibGAP). Use <code>gap.NamesUserGVars()</code> to list all global GAP variables (the ones starting with <code>$sage</code> are associated to Sage objects).</p>
http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17214#post-id-17214If there is caching somewhere in the code for automorphism_group() and order() then its easy to get cyclic references. I haven't checked myself, though.
You can try to use libgap, e.g. libgap(g.automorphism_group()).Order()Tue, 30 Jul 2013 05:39:54 -0500http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17214#post-id-17214Answer by slelievre for <p>I'm interested in computing and storing a huge number of graphs. For each graph I compute, I temporarily need to compute its automorphism group -- but I don't need to, and don't want to, remember that automorphism group. It looks like sage deals with graphs on its own but calls Gap to deal with automorphism groups. </p>
<p>The problem is that Gap, not sage, exceeds it permitted memory. Why? Here is a (silly) example of what I'm talking about: running</p>
<pre><code>mylist=[];
count = 1;
while True:
g = graphs.RandomGNP(6, .5);
aut = g.automorphism_group();
mylist.append(g);
if aut.order() > 1:
print "Graph number %s has nontrivial automorphisms!"%(count);
count += 1;
</code></pre>
<p>gives me after some hours</p>
<pre><code>RuntimeError: Gap produced error output
Error, exceeded the permitted memory (`-o' command line option)
</code></pre>
<p>How can I force sage/gap to forget the automorphism groups attached to the graphs (but remember the graphs)? Ideally Gap should only need to store one automorphism group at a time.</p>
http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?answer=15278#post-id-15278About your code. (1) Lists are indexed from 0, so initializing `count` at 0
would let you access graph number `n` by typing `mylist[n]`. (2) No need for
semicolons. (3) You can compute the order of the automorphism group without
giving it a name. Maybe that's what's making GAP store them.
Below is a rewrite of your code taking these comments into account.
mylist=[]
count = 0
while True:
g = graphs.RandomGNP(6, .5)
mylist.append(g)
if g.automorphism_group().order() > 1:
print "Graph number %s has nontrivial automorphisms!"%(count)
count += 1
If you still experience memory problems, the GAP manual has [a section about memory
information](http://www.gap-system.org/Manuals/doc/ref/chap7.html#X85679F17791D9B63),
telling you how to check how much memory is used.
There is also [an FAQ entry](http://www.gap-system.org/Faq/faq.html)
telling you how to force garbage collection in GAP.
It says: 2. Garbage collection. The GAP memory manager runs when the system
runs out of free memory and can take significant time. To standardise when
this happens, run GASMAN("collect") before each test.
Finally, the GAP mailing list archive has
[this post](http://mail.gap-system.org/pipermail/forum/2010/002985.html)
about garbage collection.
EDIT: You can add options to the `automorphism_group` method so that it will return the order and not the group. Maybe that can solve your problem?
mylist=[]
count = 0
while True:
g = graphs.RandomGNP(6, .5)
mylist.append(g)
if g.automorphism_group(order=True,return_group=False) > 1:
print "Graph number %s has nontrivial automorphisms!"%(count)
count += 1
Fri, 26 Jul 2013 05:23:56 -0500http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?answer=15278#post-id-15278Comment by MT for <p>About your code. (1) Lists are indexed from 0, so initializing <code>count</code> at 0
would let you access graph number <code>n</code> by typing <code>mylist[n]</code>. (2) No need for
semicolons. (3) You can compute the order of the automorphism group without
giving it a name. Maybe that's what's making GAP store them.</p>
<p>Below is a rewrite of your code taking these comments into account.</p>
<pre><code>mylist=[]
count = 0
while True:
g = graphs.RandomGNP(6, .5)
mylist.append(g)
if g.automorphism_group().order() > 1:
print "Graph number %s has nontrivial automorphisms!"%(count)
count += 1
</code></pre>
<p>If you still experience memory problems, the GAP manual has <a href="http://www.gap-system.org/Manuals/doc/ref/chap7.html#X85679F17791D9B63">a section about memory
information</a>,
telling you how to check how much memory is used.</p>
<p>There is also <a href="http://www.gap-system.org/Faq/faq.html">an FAQ entry</a>
telling you how to force garbage collection in GAP.</p>
<p>It says: 2. Garbage collection. The GAP memory manager runs when the system
runs out of free memory and can take significant time. To standardise when
this happens, run GASMAN("collect") before each test.</p>
<p>Finally, the GAP mailing list archive has
<a href="http://mail.gap-system.org/pipermail/forum/2010/002985.html">this post</a>
about garbage collection.</p>
<p>EDIT: You can add options to the <code>automorphism_group</code> method so that it will return the order and not the group. Maybe that can solve your problem?</p>
<pre><code>mylist=[]
count = 0
while True:
g = graphs.RandomGNP(6, .5)
mylist.append(g)
if g.automorphism_group(order=True,return_group=False) > 1:
print "Graph number %s has nontrivial automorphisms!"%(count)
count += 1
</code></pre>
http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17220#post-id-17220Thanks for the links and cleaning up my code. I've looked into what's going on in gap and it does look like a problem with gap's garbage collection being leaky, so I've contacted the gap folks.Mon, 29 Jul 2013 02:55:23 -0500http://ask.sagemath.org/question/10389/force-gap-to-forget-graph-automorphism-groups/?comment=17220#post-id-17220