ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 10 May 2012 08:29:48 +0200Resuming a running process in Sagehttps://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/Dear all,
I am running the Sage on Ubuntu and I am using the vertex_coloring() to calculate
the k-colorablity of a specific graph. As you might know the process is long enough
and the electricity may gone through the process. Is there any way that I could make
a sage process resumable or in way moderate the vertex_coloring() to resume the things
from the last point it left?
Thanks.Tue, 01 May 2012 06:21:10 +0200https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/Comment by Naji for <p>Dear all,</p>
<p>I am running the Sage on Ubuntu and I am using the vertex_coloring() to calculate
the k-colorablity of a specific graph. As you might know the process is long enough
and the electricity may gone through the process. Is there any way that I could make
a sage process resumable or in way moderate the vertex_coloring() to resume the things
from the last point it left?</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19835#post-id-19835Thanks. It seems the only possible way.Tue, 01 May 2012 14:03:07 +0200https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19835#post-id-19835Comment by chaesloc2 for <p>Dear all,</p>
<p>I am running the Sage on Ubuntu and I am using the vertex_coloring() to calculate
the k-colorablity of a specific graph. As you might know the process is long enough
and the electricity may gone through the process. Is there any way that I could make
a sage process resumable or in way moderate the vertex_coloring() to resume the things
from the last point it left?</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19840#post-id-19840I suspect (but don't know) that you will need to write your own vertex_coloring function. Copy the source of the built-in function and modify it so that it saves whatever it has calculated every now and then. Tue, 01 May 2012 07:39:23 +0200https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19840#post-id-19840Answer by niles for <p>Dear all,</p>
<p>I am running the Sage on Ubuntu and I am using the vertex_coloring() to calculate
the k-colorablity of a specific graph. As you might know the process is long enough
and the electricity may gone through the process. Is there any way that I could make
a sage process resumable or in way moderate the vertex_coloring() to resume the things
from the last point it left?</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?answer=13521#post-id-13521Using the double question mark to see the source code (`vertex_coloring??`) I see that it loops over increasingly large values of `k`, testing whether the graph is `k`-colorable:
while True:
# tries to color the graph, increasing k each time it fails.
tmp = vertex_coloring(g, k=k, value_only=value_only,
hex_colors=hex_colors, verbose=verbose)
if tmp is not False:
if value_only:
return k
else:
return tmp
k += 1
So one simple idea is to do this loop manually. If the process quits, at least you'll know what values of `k` have already been checked:
sage: from sage.graphs.graph_coloring import vertex_coloring
sage: from sys import stdout
sage: g = graphs.CompleteGraph(9)
sage: for k in range(15):
print '%s-colorable: %s'%(k,vertex_coloring(g, k=k, value_only=True))
stdout.flush()
....:
0-colorable: False
1-colorable: False
2-colorable: False
3-colorable: False
4-colorable: False
5-colorable: False
6-colorable: False
7-colorable: False
8-colorable: False
9-colorable: True
10-colorable: True
11-colorable: True
12-colorable: True
13-colorable: True
14-colorable: True
Tue, 01 May 2012 13:51:29 +0200https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?answer=13521#post-id-13521Comment by Naji for <p>Using the double question mark to see the source code (<code>vertex_coloring??</code>) I see that it loops over increasingly large values of <code>k</code>, testing whether the graph is <code>k</code>-colorable:</p>
<pre><code> while True:
# tries to color the graph, increasing k each time it fails.
tmp = vertex_coloring(g, k=k, value_only=value_only,
hex_colors=hex_colors, verbose=verbose)
if tmp is not False:
if value_only:
return k
else:
return tmp
k += 1
</code></pre>
<p>So one simple idea is to do this loop manually. If the process quits, at least you'll know what values of <code>k</code> have already been checked:</p>
<pre><code>sage: from sage.graphs.graph_coloring import vertex_coloring
sage: from sys import stdout
sage: g = graphs.CompleteGraph(9)
sage: for k in range(15):
print '%s-colorable: %s'%(k,vertex_coloring(g, k=k, value_only=True))
stdout.flush()
....:
0-colorable: False
1-colorable: False
2-colorable: False
3-colorable: False
4-colorable: False
5-colorable: False
6-colorable: False
7-colorable: False
8-colorable: False
9-colorable: True
10-colorable: True
11-colorable: True
12-colorable: True
13-colorable: True
14-colorable: True
</code></pre>
https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19826#post-id-19826No problem. Thanks for helping.Yes this is the code I tried:
from sage.graphs.graph_coloring import vertex_coloring;
vertex_coloring??;
And this is what I get:
"No object vertex_coloring" in a box!Wed, 02 May 2012 06:44:44 +0200https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19826#post-id-19826Comment by niles for <p>Using the double question mark to see the source code (<code>vertex_coloring??</code>) I see that it loops over increasingly large values of <code>k</code>, testing whether the graph is <code>k</code>-colorable:</p>
<pre><code> while True:
# tries to color the graph, increasing k each time it fails.
tmp = vertex_coloring(g, k=k, value_only=value_only,
hex_colors=hex_colors, verbose=verbose)
if tmp is not False:
if value_only:
return k
else:
return tmp
k += 1
</code></pre>
<p>So one simple idea is to do this loop manually. If the process quits, at least you'll know what values of <code>k</code> have already been checked:</p>
<pre><code>sage: from sage.graphs.graph_coloring import vertex_coloring
sage: from sys import stdout
sage: g = graphs.CompleteGraph(9)
sage: for k in range(15):
print '%s-colorable: %s'%(k,vertex_coloring(g, k=k, value_only=True))
stdout.flush()
....:
0-colorable: False
1-colorable: False
2-colorable: False
3-colorable: False
4-colorable: False
5-colorable: False
6-colorable: False
7-colorable: False
8-colorable: False
9-colorable: True
10-colorable: True
11-colorable: True
12-colorable: True
13-colorable: True
14-colorable: True
</code></pre>
https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19833#post-id-19833Oh, I didn't notice that you were only working on a specific value for k -- sorry! Did you first type "from sage.graphs.graph_coloring import vertex_coloring" ?Tue, 01 May 2012 22:12:46 +0200https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19833#post-id-19833Comment by Robert Samal for <p>Using the double question mark to see the source code (<code>vertex_coloring??</code>) I see that it loops over increasingly large values of <code>k</code>, testing whether the graph is <code>k</code>-colorable:</p>
<pre><code> while True:
# tries to color the graph, increasing k each time it fails.
tmp = vertex_coloring(g, k=k, value_only=value_only,
hex_colors=hex_colors, verbose=verbose)
if tmp is not False:
if value_only:
return k
else:
return tmp
k += 1
</code></pre>
<p>So one simple idea is to do this loop manually. If the process quits, at least you'll know what values of <code>k</code> have already been checked:</p>
<pre><code>sage: from sage.graphs.graph_coloring import vertex_coloring
sage: from sys import stdout
sage: g = graphs.CompleteGraph(9)
sage: for k in range(15):
print '%s-colorable: %s'%(k,vertex_coloring(g, k=k, value_only=True))
stdout.flush()
....:
0-colorable: False
1-colorable: False
2-colorable: False
3-colorable: False
4-colorable: False
5-colorable: False
6-colorable: False
7-colorable: False
8-colorable: False
9-colorable: True
10-colorable: True
11-colorable: True
12-colorable: True
13-colorable: True
14-colorable: True
</code></pre>
https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19800#post-id-19800Strange -- in notebook I also get "No object vertex_coloring" (is this a bug?). It works well in the command-line interface to sage though. Also one can look directly at the file, which is (as vertex_coloring? or vertex_coloring?? on command-line tells you) at local/lib/python2.6/site-packages/sage/graphs/graph_coloring.py under your sage installation.Thu, 10 May 2012 08:29:48 +0200https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19800#post-id-19800Comment by Naji for <p>Using the double question mark to see the source code (<code>vertex_coloring??</code>) I see that it loops over increasingly large values of <code>k</code>, testing whether the graph is <code>k</code>-colorable:</p>
<pre><code> while True:
# tries to color the graph, increasing k each time it fails.
tmp = vertex_coloring(g, k=k, value_only=value_only,
hex_colors=hex_colors, verbose=verbose)
if tmp is not False:
if value_only:
return k
else:
return tmp
k += 1
</code></pre>
<p>So one simple idea is to do this loop manually. If the process quits, at least you'll know what values of <code>k</code> have already been checked:</p>
<pre><code>sage: from sage.graphs.graph_coloring import vertex_coloring
sage: from sys import stdout
sage: g = graphs.CompleteGraph(9)
sage: for k in range(15):
print '%s-colorable: %s'%(k,vertex_coloring(g, k=k, value_only=True))
stdout.flush()
....:
0-colorable: False
1-colorable: False
2-colorable: False
3-colorable: False
4-colorable: False
5-colorable: False
6-colorable: False
7-colorable: False
8-colorable: False
9-colorable: True
10-colorable: True
11-colorable: True
12-colorable: True
13-colorable: True
14-colorable: True
</code></pre>
https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19834#post-id-19834Thank you very much but as I mentioned I am only calculating vertex_coloring(G,k=12,value_only=False) in my code... So as I believe this doesn't help(?)
About vertex_coloring?? I don't know why but I get : "No object vertex_coloring" in a box! Thanks again.Tue, 01 May 2012 14:06:15 +0200https://ask.sagemath.org/question/8941/resuming-a-running-process-in-sage/?comment=19834#post-id-19834