Browse Source

Progress towards working measurement

master
Pete Shadbolt 8 years ago
parent
commit
b4872397e9
5 changed files with 33 additions and 13 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -1
      abp/clifford.py
  3. +22
    -2
      abp/graphstate.py
  4. +4
    -0
      abp/util.py
  5. +5
    -10
      tests/test_measurement.py

+ 1
- 0
.gitignore View File

@@ -1,3 +1,4 @@
.noseids
debug_anders.txt debug_anders.txt
*.o *.o
*.chp *.chp


+ 1
- 1
abp/clifford.py View File

@@ -6,7 +6,7 @@ It provides tables for Clifford group multiplication and conjugation,
as well as CZ and decompositions of the 2x2 Cliffords. as well as CZ and decompositions of the 2x2 Cliffords.
""" """


import os, json, tempfile, os, sys, json, string
import os, json, tempfile, json
from functools import reduce from functools import reduce
import itertools as it import itertools as it
import numpy as np import numpy as np


+ 22
- 2
abp/graphstate.py View File

@@ -117,6 +117,26 @@ class GraphState(object):
if new_edge != edge: 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 """
basis = clifford.by_name[basis]
old_basis = basis
ha = clifford.conjugation_table[self.node[node]["vop"]]
basis, phase = clifford.conjugate(basis, ha)
print basis, phase
assert phase in (-1, 1) # TODO: remove

# TODO: wtf
force = force ^ 0x01 if force != -1 and phase == 0 else force

which = {1: self.measure_x, 2: self.measure_y, 3: self.measure_z}[basis]
res = which(node, force)
res = res if phase == 1 else not res

# TODO: put the asserts from graphsim.cpp into tests
return res


def measure_z(self, node, force=None): def measure_z(self, node, force=None):
""" Measure the graph in the Z-basis """ """ Measure the graph in the Z-basis """
res = force if force != None else random.choice([0, 1]) res = force if force != None else random.choice([0, 1])
@@ -136,12 +156,12 @@ class GraphState(object):


return res return res


def measure_x(self, i):
def measure_x(self, node, force=None):
""" Measure the graph in the X-basis """ """ Measure the graph in the X-basis """
# TODO # TODO
pass pass


def measure_y(self, i):
def measure_y(self, node, force=None):
""" Measure the graph in the Y-basis """ """ Measure the graph in the Y-basis """
# TODO # TODO
pass pass


+ 4
- 0
abp/util.py View File

@@ -1,2 +1,6 @@
"""
Utility functions for ABP
"""

def xyz(x, y, z=0): def xyz(x, y, z=0):
return {"x": x, "y": y, "z": z} return {"x": x, "y": y, "z": z}

+ 5
- 10
tests/test_measurement.py View File

@@ -8,13 +8,8 @@ def test_z_measurement():




def test_z_measurement_against_ab(): def test_z_measurement_against_ab():
a = graphsim.GraphRegister(1)
b = GraphState()
b.add_node(0)

print a.measure(0, graphsim.lco_Z)
print b.measure_z(0)




for i in range(100):
a = graphsim.GraphRegister(1)
b = GraphState()
b.add_node(0)
assert a.measure(0, graphsim.lco_Z) == b.measure(0, "pz")

Loading…
Cancel
Save