Quellcode durchsuchen

Test passing

master
Pete Shadbolt vor 8 Jahren
Ursprung
Commit
9bd4914cd2
2 geänderte Dateien mit 21 neuen und 15 gelöschten Zeilen
  1. +13
    -7
      abp/graphstate.py
  2. +8
    -8
      tests/test_measurement_against_anders_and_briegel.py

+ 13
- 7
abp/graphstate.py Datei anzeigen

@@ -129,8 +129,7 @@ class GraphState(object):
""" Measure in an arbitrary basis """
basis = clifford.by_name[basis]
ha = clifford.conjugation_table[self.node[node]["vop"]]
#basis, phase = clifford.conjugate(basis, ha)
basis, phase = clifford.conjugate(basis, self.node[node]["vop"])
basis, phase = clifford.conjugate(basis, ha)

#print "MEASURE"
#print "Op: {} Phase: {}".format(basis, phase)
@@ -169,28 +168,35 @@ class GraphState(object):
def measure_x(self, node, result):
""" Measure the graph in the X-basis """
if len(self.adj[node]) == 0:
print "gXm{},D".format(node),
print "gXm{},D".format(node)
return 0


print "gXm{},{:d}".format(node, result),
print "gXm{},{:d}".format(node, result)

# Pick a vertex
#friend = next(self.adj[node].iterkeys())
# TODO this is enforced determinism for testing purposes
friend = sorted(self.adj[node].keys())[0]
print "Friend: {}".format(friend)

# Update the VOPs. TODO: pretty ugly
if result:
# Do a z on all ngb(vb) \ ngb(v) \ {v}, and some other stuff
self.act_local_rotation2(node, "pz")
self.act_local_rotation2(friend, "msqy")
self.act_local_rotation2(node, "pz")

print "sq(-Y) on", friend
print "Z on", node
for n in set(self.adj[friend]) - set(self.adj[node]) - {node}:
print "Z on", n
self.act_local_rotation2(n, "pz")
else:
# Do a z on all ngb(v) \ ngb(vb) \ {vb}, and sqy on the friend
self.act_local_rotation2(friend, "sqy")
print "sq(Y) on", friend
for n in set(self.adj[node]) - set(self.adj[friend]) - {friend}:
print "Z on", n
self.act_local_rotation2(n, "pz")

# Toggle the edges. TODO: Yuk. Just awful!
@@ -208,7 +214,7 @@ class GraphState(object):

def measure_y(self, node, result):
""" Measure the graph in the Y-basis """
print "gYm{},{:d}".format(node, result),
print "gYm{},{:d}".format(node, result)
# Do some rotations
for neighbour in self.adj[node]:
# NB: should these be hermitian_conjugated?
@@ -229,7 +235,7 @@ class GraphState(object):

def measure_z(self, node, result):
""" Measure the graph in the Z-basis """
print "gZm{},{:d}".format(node, result),
print "gZm{},{:d}".format(node, result)
# Disconnect
for neighbour in tuple(self.adj[node]):
self.del_edge(node, neighbour)


+ 8
- 8
tests/test_measurement_against_anders_and_briegel.py Datei anzeigen

@@ -39,14 +39,14 @@ def test_multiqubit2():
a.act_local_rotation(0, str(rotation))
b.local_op(0, graphsim.LocCliffOp(rotation))
print "{} ------------------".format(rotation)
print "pjs b4:", a.to_json()
print "a&b b4:", b.to_json()
#print "{} ------------------".format(rotation)
#print "pjs b4:", a.to_json()
#print "a&b b4:", b.to_json()
oa = a.measure(0, str(measurement), outcome)
ob = b.measure(0, m[measurement], None, outcome)
assert oa == ob, (oa, ob)
print "pjs af:", a.to_json()
print "a&b af:", b.to_json()
assert a == b, (measurement, outcome)
print
assert oa == ob, (oa, ob, rotation)
#print "pjs af:", a.to_json()
#print "a&b af:", b.to_json()
assert a == b, (measurement, outcome, rotation)
#print

Laden…
Abbrechen
Speichern