Ask Your Question

Revision history [back]

Yes they are different, the documentation of canonical_label states that it takes an algorithm parameter, and the default is to use bliss if it is available. There is no nauty option because SageMath currently has only a very limited integration of nauty, only using some of its executables to generate graphs.

Relevant:

Here is a workaround, using the labelg executable (assuming SageMath has nauty installed):

def nauty_canonical_label(g):
    from sage.env import SAGE_NAUTY_BINS_PREFIX
    import subprocess
    labelg = subprocess.run([SAGE_NAUTY_BINS_PREFIX + 'labelg', '-q'], input=g.graph6_string(), encoding='ascii', capture_output=True)
    return labelg.stdout.strip()

Example:

sage: nauty_canonical_label(Graph('E{EG'))
'E@ro'

Yes they are different, the documentation of canonical_label states that it takes an algorithm parameter, and the default is to use bliss if it is available. There is no nauty option because SageMath currently has only a very limited integration of nauty, only using some of its executables to generate graphs.

Relevant:

Here is a workaround, using the labelg executable (assuming SageMath has nauty installed):

def nauty_canonical_label(g):
    from sage.env import SAGE_NAUTY_BINS_PREFIX
    import subprocess
    labelg = subprocess.run([SAGE_NAUTY_BINS_PREFIX + 'labelg', '-q'], input=g.graph6_string(), encoding='ascii', capture_output=True)
    return labelg.stdout.strip()

Example:

sage: nauty_canonical_label(Graph('E{EG'))
'E@ro'