Browse Source

Infinite size graphs

master
Pete Shadbolt 8 years ago
parent
commit
d0535b59f7
3 changed files with 12 additions and 13 deletions
  1. +6
    -6
      graph.py
  2. +5
    -6
      tests/test_clifford.py
  3. +1
    -1
      tests/test_graph.py

+ 6
- 6
graph.py View File

@@ -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]


+ 5
- 6
tests/test_clifford.py View File

@@ -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():


+ 1
- 1
tests/test_graph.py View File

@@ -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)


Loading…
Cancel
Save