diff --git a/graph.py b/graph.py index 7ea22fd..243d9e4 100644 --- a/graph.py +++ b/graph.py @@ -2,11 +2,11 @@ Provides an extremely basic graph structure, based on neighbour lists """ -def graph(n): +from collections import defaultdict + +def graph(): """ Generate a graph with Hadamards on each qubit """ - graph = [set() for i in xrange(n)] - vops = [0 for i in xrange(n)] # TODO: seems ugly - return graph, vops + return defaultdict(set), defaultdict(int) def add_edge(graph, v1, v2): """ Add an edge between two vertices in the graph """ @@ -29,10 +29,10 @@ def toggle_edge(graph, v1, v2): else: add_edge(graph, v1, v2) -def edgelist(graph): +def edgelist(g): """ Describe a graph as an edgelist """ edges = frozenset(frozenset((i, n)) - for i, v in enumerate(graph) + for i, v in enumerate(g.values()) for n in v) return [tuple(e) for e in edges] diff --git a/tests/test_clifford.py b/tests/test_clifford.py index b9c1b75..2760761 100644 --- a/tests/test_clifford.py +++ b/tests/test_clifford.py @@ -14,12 +14,11 @@ def identify_pauli(m): return sign, pauli_label -def test_find_up_to_phase(): +def _test_find_up_to_phase(): """ Test that slightly suspicious function """ - pass - #assert lc.find_up_to_phase(id) == (0, 0) - #assert lc.find_up_to_phase(px) == (1, 0) - #assert lc.find_up_to_phase(exp(1j*pi/4.)*ha) == (4, 7) + assert lc.find_up_to_phase(id) == (0, 0) + assert lc.find_up_to_phase(px) == (1, 0) + assert lc.find_up_to_phase(exp(1j*pi/4.)*ha) == (4, 7) def get_action(u): """ What does this unitary operator do to the Paulis? """ @@ -40,7 +39,7 @@ def test_we_have_all_useful_gates(): """ Check that all the interesting gates are included up to a global phase """ common_us = id, px, py, pz, ha, ph, sqz, msqz, sqy, msqy, sqx, msqx for u in common_us: - print lc.find_up_to_phase(u) + lc.find_up_to_phase(u) def test_group(): diff --git a/tests/test_graph.py b/tests/test_graph.py index 0f0e6f9..ab28870 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -1,7 +1,7 @@ from graph import * def test_graph(): - g, v = graph(3) + g, v = graph() add_edge(g, 0,1) add_edge(g, 1,2) add_edge(g, 2,0)