ソースを参照

Progress towards working measurement

master
Pete Shadbolt 7年前
コミット
b4872397e9
5個のファイルの変更33行の追加13行の削除
  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 ファイルの表示

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


+ 1
- 1
abp/clifford.py ファイルの表示

@@ -6,7 +6,7 @@ It provides tables for Clifford group multiplication and conjugation,
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
import itertools as it
import numpy as np


+ 22
- 2
abp/graphstate.py ファイルの表示

@@ -117,6 +117,26 @@ class GraphState(object):
if new_edge != edge:
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):
""" Measure the graph in the Z-basis """
res = force if force != None else random.choice([0, 1])
@@ -136,12 +156,12 @@ class GraphState(object):

return res

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

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


+ 4
- 0
abp/util.py ファイルの表示

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

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

+ 5
- 10
tests/test_measurement.py ファイルの表示

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


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")

読み込み中…
キャンセル
保存