Browse Source

Running Mercedes' example

master
Pete Shadbolt 8 years ago
parent
commit
ccabb2b7b5
4 changed files with 74 additions and 5 deletions
  1. +5
    -4
      abp/graphstate.py
  2. +1
    -1
      abp/static/scripts/materials.js
  3. +48
    -0
      examples/mercedes_demo.py
  4. +20
    -0
      tests/mercedes.py

+ 5
- 4
abp/graphstate.py View File

@@ -342,12 +342,13 @@ class GraphState(object):
if len(self.node) > 15: if len(self.node) > 15:
raise ValueError("Cannot build state vector: too many qubits") raise ValueError("Cannot build state vector: too many qubits")
state = qi.CircuitModel(len(self.node)) state = qi.CircuitModel(len(self.node))
for i in range(len(self.node)):
state.act_hadamard(i)
mapping = {node: i for i, node in enumerate(sorted(self.node))}
for n in self.node:
state.act_hadamard(mapping[n])
for i, j in self.edgelist(): for i, j in self.edgelist():
state.act_cz(i, j)
state.act_cz(mapping[i], mapping[j])
for i, n in self.node.items(): for i, n in self.node.items():
state.act_local_rotation(i, clifford.unitaries[n["vop"]])
state.act_local_rotation(mapping[i], clifford.unitaries[n["vop"]])
return state return state


def to_stabilizer(self): def to_stabilizer(self):


+ 1
- 1
abp/static/scripts/materials.js View File

@@ -1,7 +1,7 @@
var materials = {}; var materials = {};


var curveProperties = { var curveProperties = {
splineDensity: 1,
splineDensity: 10,
curvature: 20 curvature: 20
}; };




+ 48
- 0
examples/mercedes_demo.py View File

@@ -0,0 +1,48 @@
from abp.fancy import GraphState as FGS
import abp
from abp.util import xyz

def linear_cluster(n):
g = FGS(range(n), deterministic=True)
g.act_circuit([(i, "hadamard") for i in range(n)])
g.act_circuit([((i, i+1), "cz") for i in range(n-1)])
return g


def test_mercedes_example_1():
""" Run an example provided by mercedes """

g = linear_cluster(5)
g.measure(3, "px", 1)
g.measure(2, "px", 0)
g.remove_nodes_from((2, 3))
print g.node

g = linear_cluster(5)
g.measure(2, "px", 0)
g.measure(3, "px", 0)
g.remove_vop(0, 1)
g.remove_vop(1, 0)
g.remove_nodes_from((2, 3))
a = g.to_state_vector()
print g.node


g = linear_cluster(5)
g.measure(2, "px", 0)
g.measure(3, "px", 1)
g.remove_vop(0, 1)
g.remove_vop(1, 0)
g.remove_nodes_from((2, 3))
b = g.to_state_vector()
print g.node







if __name__ == '__main__':
test_mercedes_example_1()

+ 20
- 0
tests/mercedes.py View File

@@ -0,0 +1,20 @@
from abp import GraphState
from abp.util import xyz

def linear_cluster(n):
g = GraphState(range(n))
g.act_circuit([(i, "hadamard") for i in range(n)])
g.act_circuit([((i, i+1), "cz") for i in range(n-1)])
return g


def test_mercedes_example_1():
""" Run an example provided by mercedes """
g = linear_cluster(5)
g.measure(3, "px")
g.measure(2, "px")
assert set(g.adj[0]) == {1}
assert set(g.adj[1]) == {0, 4}
assert set(g.adj[4]) == {1}



Loading…
Cancel
Save