瀏覽代碼

Cleaning up tests -- not finished

master
Pete Shadbolt 8 年之前
父節點
當前提交
c7ae201fb2
共有 24 個檔案被更改,包括 119 行新增22 行删除
  1. +16
    -22
      abp/graphstate.py
  2. +4
    -0
      tests/config.py
  3. +99
    -0
      tests/mock.py
  4. +0
    -0
      tests/old/test_against_anders_and_briegel.py
  5. +0
    -0
      tests/old/test_against_circuit_model.py
  6. +0
    -0
      tests/old/test_circuit_model_against_chp.py
  7. +0
    -0
      tests/old/test_circuit_model_fails.py
  8. +0
    -0
      tests/old/test_clifford.py
  9. +0
    -0
      tests/old/test_clifford_names.py
  10. +0
    -0
      tests/old/test_conjugation.py
  11. +0
    -0
      tests/old/test_cphase_against_anders.py
  12. +0
    -0
      tests/old/test_cphase_table.py
  13. +0
    -0
      tests/old/test_get_state_vector.py
  14. +0
    -0
      tests/old/test_graph.py
  15. +0
    -0
      tests/old/test_json.py
  16. +0
    -0
      tests/old/test_layout.py
  17. +0
    -0
      tests/old/test_local_complementation.py
  18. +0
    -0
      tests/old/test_measurement.py
  19. +0
    -0
      tests/old/test_measurement_against_anders_and_briegel.py
  20. +0
    -0
      tests/old/test_measurement_deterministic.py
  21. +0
    -0
      tests/old/test_normalize_global_phase.py
  22. +0
    -0
      tests/old/test_nxgraphstate.py
  23. +0
    -0
      tests/old/test_qi_circuit_model.py
  24. +0
    -0
      tests/old/test_single_qubit_measurement_against_anb.py

+ 16
- 22
abp/graphstate.py 查看文件

@@ -36,18 +36,13 @@ class GraphState(object):
for n in nodes:
self.add_node(n)

def add_edge(self, v1, v2, data={}):
def _add_edge(self, v1, v2, data={}):
""" Add an edge between two vertices """
assert v1 != v2
self.adj[v1][v2] = data
self.adj[v2][v1] = data

def add_edges(self, edges):
""" Add a buncha edges """
for (v1, v2) in edges:
self.add_edge(v1, v2)

def del_edge(self, v1, v2):
def _del_edge(self, v1, v2):
""" Delete an edge between two vertices """
del self.adj[v1][v2]
del self.adj[v2][v1]
@@ -56,16 +51,15 @@ class GraphState(object):
""" Test existence of an edge between two vertices """
return v2 in self.adj[v1]

def toggle_edge(self, v1, v2):
def _toggle_edge(self, v1, v2):
""" Toggle an edge between two vertices """
if self.has_edge(v1, v2):
self.del_edge(v1, v2)
self._del_edge(v1, v2)
else:
self.add_edge(v1, v2)
self._add_edge(v1, v2)

def edgelist(self):
""" Describe a graph as an edgelist """
# TODO: inefficient
""" Describe a graph as an edgelist # TODO: inefficient """
edges = set(tuple(sorted((i, n)))
for i, v in self.adj.items()
for n in v)
@@ -88,7 +82,7 @@ class GraphState(object):
def local_complementation(self, v, prefix=""):
""" As defined in LISTING 1 of Anders & Briegel """
for i, j in it.combinations(self.adj[v], 2):
self.toggle_edge(i, j)
self._toggle_edge(i, j)

self.node[v]["vop"] = clifford.times_table[
self.node[v]["vop"], clifford.by_name["msqx_h"]]
@@ -141,7 +135,7 @@ class GraphState(object):
new_edge, self.node[a]["vop"], self.node[b]["vop"] = \
clifford.cz_table[int(edge), va, vb]
if new_edge != edge:
self.toggle_edge(a, b)
self._toggle_edge(a, b)

def measure(self, node, basis, force=None):
""" Measure in an arbitrary basis """
@@ -170,7 +164,7 @@ class GraphState(object):

return result

def toggle_edges(self, a, b):
def _toggle_edges(self, a, b):
""" Toggle edges between vertex sets a and b """
# TODO: i'm pretty sure this is just a single-line it.combinations or equiv
done = set()
@@ -178,7 +172,7 @@ class GraphState(object):
if i != j and not (i, j) in done:
done.add((i, j))
done.add((j, i))
self.toggle_edge(i, j)
self._toggle_edge(i, j)

def _measure_x(self, node, result):
""" Measure the graph in the X-basis """
@@ -208,13 +202,13 @@ class GraphState(object):
# Toggle the edges. TODO: Yuk. Just awful!
a = set(self.adj[node].keys())
b = set(self.adj[friend].keys())
self.toggle_edges(a, b)
self._toggle_edges(a, b)
intersection = a & b
for i, j in it.combinations(intersection, 2):
self.toggle_edge(i, j)
self._toggle_edge(i, j)

for n in a - {friend}:
self.toggle_edge(friend, n)
self._toggle_edge(friend, n)

return result

@@ -227,7 +221,7 @@ class GraphState(object):
# A sort of local complementation
vngbh = set(self.adj[node]) | {node}
for i, j in it.combinations(vngbh, 2):
self.toggle_edge(i, j)
self._toggle_edge(i, j)

self._update_vop(node, 5 if result else 6) # TODO: naming: # lcoS.herm_adjoint() if result else lcoS
return result
@@ -236,7 +230,7 @@ class GraphState(object):
""" Measure the graph in the Z-basis """
# Disconnect
for neighbour in tuple(self.adj[node]):
self.del_edge(node, neighbour)
self._del_edge(node, neighbour)
if result:
self._update_vop(neighbour, "pz")

@@ -321,7 +315,7 @@ class GraphState(object):
if __name__ == '__main__':
g = GraphState()
g.add_nodes(range(10))
g.add_edge(0, 5)
g._add_edge(0, 5)
g.act_local_rotation(6, 10)
print g
print g.to_state_vector()


+ 4
- 0
tests/config.py 查看文件

@@ -1,2 +1,6 @@
"""
Generic configuration for testing
"""

REPEATS = 100
DEPTH = 100

+ 99
- 0
tests/mock.py 查看文件

@@ -0,0 +1,99 @@
"""
Mock graphs used for testing
"""

import numpy as np
from abp import GraphState, clifford
from anders_briegel import graphsim

# We always run with A&B's CZ table when we are testing
clifford.use_old_cz()


class AndersWrapper(graphsim.GraphRegister):

""" A wrapper for A&B to make the interface identical and enable equality testing """

def __init__(self, nodes):
assert list(nodes) == range(len(nodes))
super(AndersWrapper, self).__init__(len(nodes))

def act_local_rotation(qubit, operation):
super(AndersWrapper, self).local_op(
qubit, graphsim.LocCliffOp(operation))

def act_cz(a, b):
super(AndersWrapper, self).cphase(a, b)

def measure(qubit, basis, force):
basis = clifford.by_name[basis]
basis = {1: graphsim.lco_X,
2: graphsim.lco_Y,
3: graphsim.lco_Z}[clifford.by_name[basis]]
super(AndersWrapper, self).measure(qubit, basis, None, force)

def __str__(self):
return "A wrapped A&B state ({})".format(super(AndersWrapper, self).__str__())

def __repr__(self):
return self.__str__()

class PeteWrapper(GraphState):

""" A wrapper for abp, just to ensure determinism """

def random_graph_state(N=10):
""" A random Graph state. """

for base in PeteWrapper, AndersWrapper:
g = base(range(N))

for i in range(N):
g.act_hadamard(i)

for i in range(10):
j, k = np.random.choice(range(N), 2, replace=False)
g.act_cz(j, k)

yield g


def random_stabilizer_state(N=10):
a, b = random_state()

for i in range(N):
j = np.random.choice(range(N))
k = np.random.choice(range(24))
a.act_local_rotation(j, k)
b.local_op(j, graphsim.LocCliffOp(k))

return a, b


def bell():
a = GraphState(range(2))
b = graphsim.GraphRegister(2)
a.act_hadamard(0)
a.act_hadamard(1)
b.hadamard(0)
b.hadamard(1)
a.act_cz(0, 1)
b.cphase(0, 1)
return a, b


def onequbit():
a = GraphState(range(1))
b = graphsim.GraphRegister(1)
return a, b


def demograph():
""" A graph for testing with """
g = GraphState([0, 1, 2, 3, 100, 200])
g.add_edge(0, 1)
g.add_edge(1, 2)
g.add_edge(2, 0)
g.add_edge(0, 3)
g.add_edge(100, 200)
return g

tests/test_against_anders_and_briegel.py → tests/old/test_against_anders_and_briegel.py 查看文件


tests/test_against_circuit_model.py → tests/old/test_against_circuit_model.py 查看文件


tests/test_circuit_model_against_chp.py → tests/old/test_circuit_model_against_chp.py 查看文件


tests/test_circuit_model_fails.py → tests/old/test_circuit_model_fails.py 查看文件


tests/test_clifford.py → tests/old/test_clifford.py 查看文件


tests/test_clifford_names.py → tests/old/test_clifford_names.py 查看文件


tests/test_conjugation.py → tests/old/test_conjugation.py 查看文件


tests/test_cphase_against_anders.py → tests/old/test_cphase_against_anders.py 查看文件


tests/test_cphase_table.py → tests/old/test_cphase_table.py 查看文件


tests/test_get_state_vector.py → tests/old/test_get_state_vector.py 查看文件


tests/test_graph.py → tests/old/test_graph.py 查看文件


tests/test_json.py → tests/old/test_json.py 查看文件


tests/test_layout.py → tests/old/test_layout.py 查看文件


tests/test_local_complementation.py → tests/old/test_local_complementation.py 查看文件


tests/test_measurement.py → tests/old/test_measurement.py 查看文件


tests/test_measurement_against_anders_and_briegel.py → tests/old/test_measurement_against_anders_and_briegel.py 查看文件


tests/test_measurement_deterministic.py → tests/old/test_measurement_deterministic.py 查看文件


tests/test_normalize_global_phase.py → tests/old/test_normalize_global_phase.py 查看文件


tests/test_nxgraphstate.py → tests/old/test_nxgraphstate.py 查看文件


tests/test_qi_circuit_model.py → tests/old/test_qi_circuit_model.py 查看文件


tests/test_single_qubit_measurement_against_anb.py → tests/old/test_single_qubit_measurement_against_anb.py 查看文件


Loading…
取消
儲存