Skip to content

Commit

Permalink
Released version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sammorley-short committed Mar 4, 2019
1 parent 595cbc8 commit c84342f
Show file tree
Hide file tree
Showing 6 changed files with 783 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore dirs
build
nauty
nauty27b11
674 changes: 674 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions README

This file was deleted.

37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Pynauty
*by Sam Morley-Short*

This is a fork of `pynauty`--a Python extension of the C module `nauty`--to add extra features needed for exploring LC classes of quantum graph states.

It was made entirely for use by my other Graph State Compass (gsc) module, which can be found [here](https://github.com/sammorley-short/gsc).

It is redistributed under the GPL v3 copyleft lisence WITHOUT ANY WARRANTY.

To install, follow the instructions provided [here](https://web.cs.dal.ca/~peter/software/pynauty/html/install.html).

Loosely, this requires:

1. Downloading nauty, (working as of version 27b11, found [here](http://users.cecs.anu.edu.au/~bdm/nauty/nauty27b11.tar.gz)),
2. Unzipping it and placing it in `/pynauty-hack`,
3. Symbolic link the nauty directory to `/nauty` (for the above case on Mac OS X this means running `ln -s nauty27b11 nauty` from the command line),
4. Installing pynauty (`make user-ins` can be used to install globally).

## Original warranty

pynauty -- isomorphism testing and automorphism groups of graphs
version: 0.6

Copyright (c) 2015 Peter Dobsan

This is the source distribution of pynauty, a Python/C extension module.
It can be used to compare graphs for isomorphism and to determine their
automorphism group. It is based on the Nauty C procedures.

pynauty is compatible both Python-2 and Python-3.

pynauty is distributed under the terms GPL v3 WITHOUT ANY WARRANTY.
For exact details on licencing see the file COPYING.

For documentations, including instructions for installation, API and
User's Guide see the docs/ directory.

29 changes: 22 additions & 7 deletions src/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'''
from __future__ import absolute_import

__LICENSE__ = '''
__LICENSE__ = '''
Copyright (c) 2015 Peter Dobsan
This program is free software; you can redistribute it and/or modify it
Expand All @@ -23,6 +23,7 @@
'autgrp',
'isomorphic',
'certificate',
'canon_label',
'delete_random_edge',
]

Expand Down Expand Up @@ -67,8 +68,8 @@ def _check_vertices(self, vs):
for v in vs:
if not (0 <= v and v < self.number_of_vertices):
raise ValueError(
'vertex %d conflicts with number_of_vertices=%d' %
(v, self.number_of_vertices))
'vertex %d conflicts with number_of_vertices=%d' %
(v, self.number_of_vertices))

def _get_adjacency_dict(self):
return self._adjacency_dict
Expand Down Expand Up @@ -141,9 +142,9 @@ def __repr__(self):
s = ['Graph(number_of_vertices=%d, directed=%s,' %
(self.number_of_vertices, self.directed)]
s.append(' adjacency_dict = {')
for k,v in self._adjacency_dict.items():
for k, v in self._adjacency_dict.items():
v.sort()
s.append(' %d: %s,' % (k,v))
s.append(' %d: %s,' % (k, v))
s.append(' },')
s.append(' vertex_coloring = [')
for x in self._vertex_coloring:
Expand Down Expand Up @@ -184,6 +185,21 @@ def certificate(g):
return nautywrap.graph_cert(g)


def canon_label(g):
'''
Finds the canonical labeling of vertices.
*g*
A Graph object.
return ->
A list with each node relabelled.
'''
if not isinstance(g, Graph):
raise TypeError
return nautywrap.graph_canonlab(g)


def isomorphic(a, b):
'''
Determine if two graphs are isomorphic.
Expand Down Expand Up @@ -214,7 +230,7 @@ def delete_random_edge(g):
'''
if g.adjacency_dict:
# pick a random vertex 'x' which is connected
x = random.sample(list(g.adjacency_dict),1)[0]
x = random.sample(list(g.adjacency_dict), 1)[0]
# remove a random edge connected to 'x'
xs = g.adjacency_dict[x]
y = xs.pop(random.randrange(len(xs)))
Expand All @@ -229,4 +245,3 @@ def delete_random_edge(g):
# the graph has no edges
x, y = None, None
return (x, y)

48 changes: 46 additions & 2 deletions src/nautywrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void destroy_nygraph(NyGraph *g)
NyGraph * create_nygraph(int no_vertices)
//
// Allocate a data structure to hold all data structures used by Nauty
//
//
{
NyGraph *g;
int i, *p;
Expand All @@ -127,7 +127,7 @@ NyGraph * create_nygraph(int no_vertices)
g->no_setwords = (no_vertices + WORDSIZE - 1) / WORDSIZE;
nauty_check(WORDSIZE, g->no_setwords, g->no_vertices, NAUTYVERSIONID);

if ((g->matrix = malloc((size_t) g->no_setwords *
if ((g->matrix = malloc((size_t) g->no_setwords *
(size_t) (no_vertices * sizeof(setword)))) == NULL) {
destroy_nygraph(g);
return NULL;
Expand Down Expand Up @@ -546,11 +546,55 @@ graph_cert(PyObject *self, PyObject *args)
return pyret;
}

// SMS EDIT: New function graph_canonlab
static char graph_canonlab_docs[] =
"graph_canonlab(g): \n\
Return the canonical relabelling of NyGraph 'g'.\n";

static PyObject*
graph_canonlab(PyObject *self, PyObject *args)
{
int i;
PyObject *py_graph;
NyGraph * g;
PyObject *pyret;

if (!PyArg_ParseTuple(args, "O", &py_graph)) {
PyErr_SetString(PyExc_TypeError, "Missing argument.");
return NULL;
}
g = _make_nygraph(py_graph);
if (g == NULL) return NULL;

// produce graph certificate by computing canonical labeling
g->options->getcanon = TRUE;
if (extend_canonical(g) == NULL) {
PyErr_SetString(PyExc_MemoryError,
"Allocating canonical matrix failed");
return NULL;
}
// the produced generators are ignored
g->options->userautomproc = NULL;

// *** nauty ***
nauty(g->matrix, g->lab, g->ptn, NULL, g->orbits,
g->options, g->stats, g->workspace, g->worksize,
g->no_setwords, g->no_vertices, g->cmatrix);

pyret = PyList_New(g->no_vertices);
for (i=0; i < g->no_vertices; i++) {
PyList_SET_ITEM(pyret, i, Py_BuildValue("i", g->lab[i]));
}

destroy_nygraph(g);
return pyret;
}

// Python module initialization =============================================

static PyMethodDef nautywrap_methods[] = {
{"graph_cert", graph_cert, METH_VARARGS, graph_cert_docs},
{"graph_canonlab", graph_canonlab, METH_VARARGS, graph_canonlab_docs},
{"graph_autgrp", graph_autgrp, METH_VARARGS, graph_autgrp_docs},
{"make_nygraph", make_nygraph, METH_VARARGS, make_nygraph_docs},
{"delete_nygraph", delete_nygraph, METH_VARARGS, delete_nygraph_docs},
Expand Down

0 comments on commit c84342f

Please sign in to comment.