Pete Shadbolt 5 роки тому
джерело
коміт
04f8ef0f6e
14 змінених файлів з 56 додано та 17 видалено
  1. +1
    -0
      abp/__init__.py
  2. +1
    -0
      abp/anders_cz.py
  3. +6
    -3
      abp/build_tables.py
  4. +14
    -3
      abp/clifford.py
  5. +11
    -7
      abp/graphstate.py
  6. +1
    -0
      abp/nxgraphstate.py
  7. +3
    -0
      abp/qi.py
  8. +2
    -0
      abp/stabilizer.py
  9. +1
    -0
      abp/tables.py
  10. +4
    -1
      examples/mix_graph_and_networkx.py
  11. +3
    -1
      examples/stabilizers.py
  12. +3
    -1
      examples/visualization/pull.py
  13. +4
    -0
      examples/visualization/raussendorf.py
  14. +2
    -1
      tests/test_qi.py

+ 1
- 0
abp/__init__.py Переглянути файл

@@ -1,4 +1,5 @@
# Alias some stuff to make imports cleaner
from __future__ import absolute_import
from abp.graphstate import GraphState
from abp.nxgraphstate import NXGraphState
from abp.qi import CircuitModel


+ 1
- 0
abp/anders_cz.py Переглянути файл

@@ -2,6 +2,7 @@
Copied from Anders' original C++ implementation
S. Anders, H. J. Briegel: Fast Simulation of Stabilizer Circuits using a Graph State Formalism quant-ph/0504117
"""
from __future__ import absolute_import
import numpy as np
cz_table = ((((1, 0, 0), (1, 0, 0), (1, 0, 3), (1, 0, 3), (1, 0, 5), (1, 0, 5),
(1, 0, 6), (1, 0, 6), (0, 3, 8), (0, 3, 8), (0, 0, 10), (0, 0, 10),


+ 6
- 3
abp/build_tables.py Переглянути файл

@@ -3,12 +3,15 @@ This program computes lookup tables and stores them as tables.py and tables.js
# TODO: clifford naming discrepancy
"""

from __future__ import absolute_import
from __future__ import print_function
import numpy as np
import itertools as it
from functools import reduce
from os.path import dirname, join, split
import json
from . import qi, clifford
from six.moves import range


DECOMPOSITIONS = (
@@ -51,8 +54,8 @@ def find_cz(bond, c1, c2, commuters, state_table):
target = qi.normalize_global_phase(target)

# Choose the sets to search over
s1 = commuters if c1 in commuters else range(24)
s2 = commuters if c2 in commuters else range(24)
s1 = commuters if c1 in commuters else list(range(24))
s2 = commuters if c2 in commuters else list(range(24))

# Find a match
for bondp, c1p, c2p in it.product([0, 1], s1, s2):
@@ -173,7 +176,7 @@ def get_display_table(unitaries):
c = qi.CircuitModel(1)
c.act_local_rotation(0, u)
state = c.state.round(2)
print("{:.2f}, {:.2f}".format(state[0][0], state[1][0]))
print(("{:.2f}, {:.2f}".format(state[0][0], state[1][0])))


def compute_everything():


+ 14
- 3
abp/clifford.py Переглянути файл

@@ -40,7 +40,10 @@ The complete set of aliases for single-qubit Cliffords is as follows:

"""

from tables import *
from __future__ import absolute_import
from __future__ import print_function
from .tables import *
from six.moves import range

# Aliases
identity = by_name["identity"]
@@ -51,6 +54,15 @@ pz = by_name["pz"]
msqx_h = by_name["msqx_h"]
sqz_h = by_name["sqz_h"]

class Thing(object):
def __init__(self):
""" Constructor """
return None

def hunt(self):
""" Pete is cool """
pass

def conjugate(operator, unitary):
""" Returns transform * vop * transform^dagger and a phase in {+1, -1} """
return measurement_table[operator, unitary]
@@ -73,14 +85,13 @@ def is_diagonal(v):
""" Checks if a VOP is diagonal or not """
return v in {0, 3, 5, 6}


if __name__ == '__main__':
from itertools import groupby

for i in range(24):
members = [key for key, value in list(by_name.items()) if value == i and str(key)!=str(i)]
members = sorted(members, key=len)
print("* {}: {}".format(i, ", ".join(members)))
print(("* {}: {}".format(i, ", ".join(members))))



+ 11
- 7
abp/graphstate.py Переглянути файл

@@ -4,12 +4,16 @@
This module implements Anders and Briegel's method for fast simulation of Clifford circuits.
"""

from __future__ import absolute_import
from __future__ import print_function
import itertools as it
import json, random
from . import qi, clifford, util
import abp
from .stabilizer import Stabilizer
import requests
from six.moves import range
from six.moves import zip


class GraphState(object):
@@ -63,12 +67,12 @@ class GraphState(object):
self._del_node(node)

def _add_node(self, node, **kwargs):
""" Add a node.
""" Add a node.

By default, nodes are initialized with ``vop=``:math:`I`, i.e. they are in the :math:`|+\\rangle` state.
"""
if node in self.node:
print("Warning: node {} already exists".format(node))
print(("Warning: node {} already exists".format(node)))
return

default = kwargs.get("default", "identity")
@@ -91,7 +95,7 @@ class GraphState(object):

>>> g._add_node(0, label="fred", position=(1,2,3))
>>> g.node[0]["label"]
fred
fred

"""
kwargs["vop"] = clifford.by_name[
@@ -500,17 +504,17 @@ class GraphState(object):
self.url = requests.get("https://abv.peteshadbolt.co.uk/").url

data = json.dumps(self.to_json(stringify=True))
print("Shared state to {}".format(self.url))
print(("Shared state to {}".format(self.url)))
return requests.post("{}/graph".format(self.url), data=data)

def pull(self, url=None):
""" Loads the state from the server """
if url:
if url:
self.url = url

response = requests.get("{}/graph".format(self.url))
self.from_json(json.loads(response.content))





+ 1
- 0
abp/nxgraphstate.py Переглянути файл

@@ -1,3 +1,4 @@
from __future__ import absolute_import
import networkx as nx
import numpy as np
from . import graphstate


+ 3
- 0
abp/qi.py Переглянути файл

@@ -6,9 +6,12 @@ Exposes a few basic QI operators
And a circuit-model simulator
"""

from __future__ import absolute_import
import numpy as np
import itertools as it
from fractions import Fraction
from six.moves import range
from six.moves import zip

def hermitian_conjugate(u):
""" Shortcut to the Hermitian conjugate """


+ 2
- 0
abp/stabilizer.py Переглянути файл

@@ -2,8 +2,10 @@
Implements a simple Stabilizer object.
"""

from __future__ import absolute_import
import itertools as it
from abp import clifford
from six.moves import map

I = clifford.identity
X = clifford.px


+ 1
- 0
abp/tables.py Переглянути файл

@@ -1,3 +1,4 @@
from __future__ import absolute_import
import numpy as np

# Define lookup tables


+ 4
- 1
examples/mix_graph_and_networkx.py Переглянути файл

@@ -1,10 +1,13 @@
from __future__ import absolute_import
from __future__ import print_function
from abp import NXGraphState
from abp.util import xyz
import networkx as nx
from six.moves import range

n = 10
g = NXGraphState(list(range(n)))
nx.set_node_attributes(g, "color", "red")
g.add_edges_from([i, i+1] for i in range(n-1))
print(g.node[0]["color"])
print((g.node[0]["color"]))


+ 3
- 1
examples/stabilizers.py Переглянути файл

@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
from abp import GraphState

edges = (0, 1), (1, 2), (2, 0), (0, 3), (100, 200)
@@ -7,5 +9,5 @@ g.act_circuit((edge, "cz") for edge in edges)

g.act_local_rotation(3, 9)

print(g.to_stabilizer())
print((g.to_stabilizer()))


+ 3
- 1
examples/visualization/pull.py Переглянути файл

@@ -1,6 +1,8 @@
from __future__ import absolute_import
from __future__ import print_function
from abp import GraphState

psi = GraphState()
psi.pull("https://abv.peteshadbolt.co.uk/dakota-illinois-nuts-blue")
print psi
print(psi)


+ 4
- 0
examples/visualization/raussendorf.py Переглянути файл

@@ -1,9 +1,13 @@
from __future__ import absolute_import
from __future__ import print_function
from abp import GraphState
from abp.util import xyz
import numpy as np
import time
import itertools
import networkx as nx
from six.moves import map
from six.moves import zip

raussendorf_unit_cell = (
((1, 0, 0), (1, 1, 0)), ((0, 1, 0), (1, 1, 0)),


+ 2
- 1
tests/test_qi.py Переглянути файл

@@ -1,6 +1,7 @@
import numpy as np
from abp import qi, GraphState
import mock
import pytest

DEPTH = 1000

@@ -125,7 +126,7 @@ def test_against_chp(n=5):
try:
import chp
except ImportError:
raise nose.SkipTest("CHP is not installed")
raise pytest.skip("CHP is not installed")

def get_chp_state():
""" Helper to convert CHP to CircuitModel """


Завантаження…
Відмінити
Зберегти