From 9bd4914cd231d363ed6fd709c3149cdcb13d3771 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Sun, 24 Jul 2016 17:59:35 +0100 Subject: [PATCH] Test passing --- abp/graphstate.py | 20 ++++++++++++------- ..._measurement_against_anders_and_briegel.py | 16 +++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/abp/graphstate.py b/abp/graphstate.py index 23e0adc..245a3f8 100644 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -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) diff --git a/tests/test_measurement_against_anders_and_briegel.py b/tests/test_measurement_against_anders_and_briegel.py index 9701e84..84ca309 100644 --- a/tests/test_measurement_against_anders_and_briegel.py +++ b/tests/test_measurement_against_anders_and_briegel.py @@ -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