@@ -1,6 +1,5 @@ | |||||
from matplotlib import pyplot as plt | |||||
from graph import * | from graph import * | ||||
from viz import draw | |||||
import viz | |||||
import itertools as it | import itertools as it | ||||
import clifford | import clifford | ||||
@@ -16,15 +15,12 @@ def local_complementation(g, vops, v): | |||||
vops[i] = clifford.times_table[vops[i]][clifford.msqz] | vops[i] = clifford.times_table[vops[i]][clifford.msqz] | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
g, vops = graph(10) | |||||
g, vops = graph() | |||||
add_edge(g, 0, 1) | add_edge(g, 0, 1) | ||||
add_edge(g, 1, 3) | |||||
add_edge(g, 3, 2) | |||||
add_edge(g, 3, 0) | |||||
add_edge(g, 2, 0) | |||||
add_edge(g, 0, 5) | |||||
vops[0] = 1 | |||||
draw(g, vops) | |||||
plt.clf() | |||||
add_edge(g, 1, 2) | |||||
add_edge(g, 0, 2) | |||||
add_edge(g, 0, 3) | |||||
viz.draw(g, vops, "out.pdf") | |||||
local_complementation(g, vops, 0) | local_complementation(g, vops, 0) | ||||
draw(g, vops, "out2.pdf") | |||||
viz.draw(g, vops, "out2.pdf") |
@@ -0,0 +1,19 @@ | |||||
import cz | |||||
from graph import * | |||||
import viz | |||||
def test_local_complementation(): | |||||
""" Test that local complementation works as expected """ | |||||
g, vops = graph() | |||||
add_edge(g, 0, 1) | |||||
add_edge(g, 0, 2) | |||||
add_edge(g, 1, 2) | |||||
add_edge(g, 0, 3) | |||||
cz.local_complementation(g, vops, 0) | |||||
assert has_edge(g, 0, 1) | |||||
assert has_edge(g, 0, 2) | |||||
assert not has_edge(g, 1, 2) | |||||
assert has_edge(g, 3, 2) | |||||
assert has_edge(g, 3, 1) | |||||
# TODO: test VOP conditions |
@@ -6,10 +6,11 @@ import networkx as nx | |||||
from matplotlib import pyplot as plt | from matplotlib import pyplot as plt | ||||
from graph import * | from graph import * | ||||
VOP_COLORS = ["red", "green", "blue"] | |||||
VOP_COLORS = ["red", "green", "blue", "orange", "yellow", "purple", "black", "white"] | |||||
def draw(graph, vops, filename="out.pdf", ns=500): | def draw(graph, vops, filename="out.pdf", ns=500): | ||||
""" Draw a graph with networkx layout """ | """ Draw a graph with networkx layout """ | ||||
plt.clf() | |||||
g = nx.from_edgelist(edgelist(graph)) | g = nx.from_edgelist(edgelist(graph)) | ||||
pos = nx.spring_layout(g) | pos = nx.spring_layout(g) | ||||
colors = [VOP_COLORS[vop % len(VOP_COLORS)] for vop in vops] | colors = [VOP_COLORS[vop % len(VOP_COLORS)] for vop in vops] | ||||
@@ -21,7 +22,7 @@ def draw(graph, vops, filename="out.pdf", ns=500): | |||||
plt.savefig(filename) | plt.savefig(filename) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
g, vops = graph(10) | |||||
g, vops = graph() | |||||
add_edge(g, 0, 1) | add_edge(g, 0, 1) | ||||
add_edge(g, 1, 3) | add_edge(g, 1, 3) | ||||
add_edge(g, 3, 2) | add_edge(g, 3, 2) | ||||