|
|
@@ -115,31 +115,26 @@ class GraphState(object): |
|
|
|
if new_edge != edge: |
|
|
|
self.toggle_edge(a, b) |
|
|
|
|
|
|
|
def measure(self, node, basis, force=None): |
|
|
|
def measure(self, node, basis): |
|
|
|
""" Measure in an arbitrary basis """ |
|
|
|
basis = clifford.by_name[basis] |
|
|
|
ha = clifford.conjugation_table[self.node[node]["vop"]] |
|
|
|
basis, phase = clifford.conjugate(basis, ha) |
|
|
|
|
|
|
|
#TODO: wtf |
|
|
|
#force = force ^ 0x01 if force != -1 and phase == 0 else force |
|
|
|
if force != None and phase == 0+0j: |
|
|
|
force = not force |
|
|
|
|
|
|
|
result = random.choice([0, 1]) |
|
|
|
if which == clifford.by_name["px"]: |
|
|
|
result = self.measure_x(node, result) |
|
|
|
elif which == clifford.by_name["py"]: |
|
|
|
result = self.measure_y(node, result) |
|
|
|
elif which == clifford.by_name["pz"]: |
|
|
|
result = self.measure_z(node, result) |
|
|
|
if basis == clifford.by_name["px"]: |
|
|
|
result = self.measure_x(node) |
|
|
|
elif basis == clifford.by_name["py"]: |
|
|
|
result = self.measure_y(node) |
|
|
|
elif basis == clifford.by_name["pz"]: |
|
|
|
result = self.measure_z(node) |
|
|
|
else: |
|
|
|
raise ValueError("You can only measure in PX, PY or PZ") |
|
|
|
raise ValueError("You can only measure in {X,Y,Z}") |
|
|
|
|
|
|
|
if phase == 1: |
|
|
|
# Flip the result if we have negative phase |
|
|
|
if phase == -1: |
|
|
|
result = not result |
|
|
|
|
|
|
|
return res |
|
|
|
return result |
|
|
|
|
|
|
|
def toggle_edges(a, b): |
|
|
|
""" Toggle edges between vertex sets a and b """ |
|
|
@@ -149,11 +144,13 @@ class GraphState(object): |
|
|
|
done.add((i, j), (j, i)) |
|
|
|
self.toggle_edge(i, j) |
|
|
|
|
|
|
|
def measure_x(self, node, result): |
|
|
|
def measure_x(self, node, result=0): |
|
|
|
""" Measure the graph in the X-basis """ |
|
|
|
if len(self.adj[node]) == 0: |
|
|
|
return 0 |
|
|
|
|
|
|
|
result = random.choice([0, 1]) |
|
|
|
|
|
|
|
# Pick a vertex |
|
|
|
friend = next(self.adj[node].iterkeys()) |
|
|
|
|
|
|
@@ -183,8 +180,11 @@ class GraphState(object): |
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
def measure_y(self, node, result): |
|
|
|
def measure_y(self, node, result=None): |
|
|
|
""" Measure the graph in the Y-basis """ |
|
|
|
|
|
|
|
result = random.choice([0, 1]) |
|
|
|
|
|
|
|
# Do some rotations |
|
|
|
for neighbour in self.adj[node]: |
|
|
|
# NB: should these be hermitian_conjugated? |
|
|
@@ -198,8 +198,11 @@ class GraphState(object): |
|
|
|
self.act_local_rotation(node, "msqz" if result else "msqz_h") |
|
|
|
return result |
|
|
|
|
|
|
|
def measure_z(self, node, result): |
|
|
|
def measure_z(self, node, result=None): |
|
|
|
""" Measure the graph in the Z-basis """ |
|
|
|
|
|
|
|
result = random.choice([0, 1]) |
|
|
|
|
|
|
|
# Disconnect |
|
|
|
for neighbour in self.adj[node]: |
|
|
|
self.del_edge(node, neighbour) |
|
|
|