Pete Shadbolt 9 лет назад
Родитель
Сommit
b7380f802b
5 измененных файлов: 19 добавлений и 51 удалений
  1. +0
    -4
      TODO
  2. +10
    -19
      tables.py
  3. +2
    -2
      tests/test_graph.py
  4. +7
    -6
      tests/test_viz.py
  5. +0
    -20
      util.py

+ 0
- 4
TODO Просмотреть файл

@@ -1,4 +0,0 @@
Next things to do:
- Read A&B code which expresses C(1) as products of sqrt(iX), sqrt(iY)
- Read A&B code which exposes LC API
- Implement the above

+ 10
- 19
tables.py Просмотреть файл

@@ -7,24 +7,10 @@ unitaries = [p*s for p in permutations for s in signs]


import numpy as np import numpy as np
from tqdm import tqdm from tqdm import tqdm
import qi
import os
from functools import reduce from functools import reduce
import cPickle import cPickle

def cache_to_disk(file_name):
""" A decorator to cache the output of a function to disk """
def wrap(func):
def modified(*args, **kwargs):
try:
output = cPickle.load(open(file_name, "r"))
except (IOError, ValueError):
output = func(*args, **kwargs)
with open(file_name, "w") as f:
cPickle.dump(output, f)
return output
return modified
return wrap

import qi


# TODO: make this more efficient / shorter # TODO: make this more efficient / shorter
def find_up_to_phase(u): def find_up_to_phase(u):
@@ -47,9 +33,11 @@ def name_of(vop):
return "%s" % get_name[vop] if vop in get_name else "VOP%d" % vop return "%s" % get_name[vop] if vop in get_name else "VOP%d" % vop




@cache_to_disk("tables.cache")
def construct_tables():
def construct_tables(filename="tables.cache"):
""" Constructs / caches multiplication and conjugation tables """ """ Constructs / caches multiplication and conjugation tables """
if os.path.exists(filename):
return cPickle.load(open(filename, "r"))

by_name = {name: find_up_to_phase(u)[0] for name, u in qi.by_name.items()} by_name = {name: find_up_to_phase(u)[0] for name, u in qi.by_name.items()}
get_name = {v:k for k, v in by_name.items()} get_name = {v:k for k, v in by_name.items()}
conjugation_table = [find_up_to_phase(u.H)[0] conjugation_table = [find_up_to_phase(u.H)[0]
@@ -57,7 +45,10 @@ def construct_tables():
times_table = [[find_up_to_phase(u * v)[0] for v in unitaries] times_table = [[find_up_to_phase(u * v)[0] for v in unitaries]
for u in tqdm(unitaries)] for u in tqdm(unitaries)]
cz_table = None cz_table = None
return by_name, get_name, conjugation_table, times_table, cz_table
output = by_name, get_name, conjugation_table, times_table, cz_table
with open(filename, "w") as f:
cPickle.dump(output, f)
return output




decompositions = ("xxxx", "xx", "zzxx", "zz", "zxx", "z", "zzz", "xxz", decompositions = ("xxxx", "xx", "zzxx", "zz", "zxx", "z", "zzz", "xxz",


+ 2
- 2
tests/test_graph.py Просмотреть файл

@@ -58,9 +58,9 @@ def test_edgelist():




def test_million_sites(): def test_million_sites():
""" Testing making really big graphs """
""" Testing that making a graph of tent housand qubits takes less than half a second"""
g = GraphState() g = GraphState()
t = time.clock() t = time.clock()
for i in xrange(100000): for i in xrange(100000):
g.add_edge(i, i + 1) g.add_edge(i, i + 1)
print time.clock() - t
assert time.clock() - t < .5

+ 7
- 6
tests/test_viz.py Просмотреть файл

@@ -1,12 +1,13 @@
from graph import GraphState from graph import GraphState
import viz import viz



def test_viz(): def test_viz():
g = GraphState() g = GraphState()
g.add_edge(0,1)
g.add_edge(1,2)
g.add_edge(2,0)
g.add_edge(0,3)
g.add_edge(100,200)
#g.remove_vop(0, 1)
g.add_edge(0, 1)
g.add_edge(1, 2)
g.add_edge(2, 0)
g.add_edge(0, 3)
g.add_edge(100, 200)
# g.remove_vop(0, 1)
viz.draw(g) viz.draw(g)

+ 0
- 20
util.py Просмотреть файл

@@ -1,20 +0,0 @@
"""
Useful but messy crap
"""


def cache_to_disk(file_name):
""" A decorator to cache the output of a function to disk """
def wrap(func):
def modified(*args, **kwargs):
try:
output = cPickle.load(open(file_name, "r"))
except (IOError, ValueError):
output = func(*args, **kwargs)
with open(file_name, "w") as f:
cPickle.dump(output, f)
return output
return modified
return wrap



Загрузка…
Отмена
Сохранить