Ask Your Question

Resuming a running process in Sage

asked 2012-04-30 23:21:10 -0500

Naji gravatar image

updated 2015-01-13 14:32:54 -0500

FrédéricC gravatar image

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?


edit retag flag offensive close merge delete



I 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.

chaesloc2 gravatar imagechaesloc2 ( 2012-05-01 00:39:23 -0500 )edit

Thanks. It seems the only possible way.

Naji gravatar imageNaji ( 2012-05-01 07:03:07 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2012-05-01 06:51:29 -0500

niles gravatar image

Using 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
                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))
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
edit flag offensive delete link more


Thank 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.

Naji gravatar imageNaji ( 2012-05-01 07:06:15 -0500 )edit

Oh, 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" ?

niles gravatar imageniles ( 2012-05-01 15:12:46 -0500 )edit

No 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!

Naji gravatar imageNaji ( 2012-05-01 23:44:44 -0500 )edit

Strange -- 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/ under your sage installation.

Robert Samal gravatar imageRobert Samal ( 2012-05-10 01:29:48 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-04-30 23:21:10 -0500

Seen: 107 times

Last updated: May 01 '12