Pete Shadbolt преди 8 години
родител
ревизия
40c2b3caa9
променени са 11 файла, в които са добавени 30 реда и са изтрити 98 реда
  1. +22
    -5
      abp/clifford.py
  2. +3
    -9
      abp/server.py
  3. +1
    -0
      client/api.js
  4. +1
    -1
      client/tables.js
  5. +0
    -1
      examples/abp
  6. +0
    -22
      examples/dream.py
  7. +0
    -18
      examples/use_server.py
  8. +3
    -3
      examples/visualization_demo.py
  9. +0
    -1
      profiling/abp
  10. +0
    -13
      profiling/profile_cz_table.py
  11. +0
    -25
      scripts/make_js_stuff.py

+ 22
- 5
abp/clifford.py Целия файл

@@ -9,7 +9,7 @@ from functools import reduce
import itertools as it
import numpy as np
from tqdm import tqdm
#import argparse
# import argparse

import qi

@@ -120,6 +120,23 @@ def get_cz_table(unitaries):
return cz_table


def write_javascript_tables():
""" Write the tables to javascript files for consumption in the browser """
path = os.path.dirname(sys.argv[0])
path = os.path.split(path)[0]
with open(os.path.join(path, "client/tables.js"), "w") as f:
f.write("var decompositions = {};\n"\
.format(json.dumps(decompositions)))
f.write("var conjugation_table = {};\n"\
.format(json.dumps(conjugation_table.tolist())))
f.write("var times_table = {};\n"\
.format(json.dumps(times_table.tolist())))
f.write("var cz_table = {};\n"\
.format(json.dumps(cz_table.tolist())))
f.write("var clifford = {};\n"\
.format(json.dumps(by_name)))


# First try to load tables from cache. If that fails, build them from
# scratch and store in /tmp/
tempdir = tempfile.gettempdir()
@@ -129,9 +146,9 @@ try:
raise IOError

# Parse command line args
#parser = argparse.ArgumentParser()
#parser.add_argument("-l", "--legacy", help="Use legacy CZ table", action="store_true", default=False)
#args = parser.parse_args()
# parser = argparse.ArgumentParser()
# parser.add_argument("-l", "--legacy", help="Use legacy CZ table", action="store_true", default=False)
# args = parser.parse_args()
legacy_cz = False

unitaries = np.load(temp("unitaries.npy"))
@@ -159,7 +176,7 @@ except IOError:
np.save(temp("conjugation_table.npy"), conjugation_table)
np.save(temp("times_table.npy"), times_table)
np.save(temp("cz_table.npy"), cz_table)
write_javascript_tables()

with open(temp("by_name.json"), "wb") as f:
json.dump(by_name, f)


+ 3
- 9
abp/server.py Целия файл

@@ -6,15 +6,8 @@ import abp
clients = []

def new_message(client, server, message):
decoded_message = json.loads(message)
if "diff" in decoded_message:
server.send_message_to_all(message)
elif "method" in decoded_message:
message = compute_diff(decoded_message)
server.send_message_to_all(message)
else:
print "Could not interpret message"

print "Receieved update from client {}.".format(client["id"])
server.send_message_to_all(message)

def new_client(client, server):
print "Client {} connected.".format(client["id"])
@@ -31,3 +24,4 @@ if __name__ == '__main__':
server.set_fn_client_left(client_left)
server.run_forever()



+ 1
- 0
client/api.js Целия файл

@@ -16,6 +16,7 @@ function connect_to_server() {
ws.onmessage = function (evt)
{
console.log("Received update");
var new_state = JSON.parse(evt.data);
vops = new_state.vops;
ngbh = new_state.ngbh;


+ 1
- 1
client/tables.js
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 0
- 1
examples/abp Целия файл

@@ -1 +0,0 @@
../abp/

+ 0
- 22
examples/dream.py Целия файл

@@ -1,22 +0,0 @@
import abp
import time

psi = abp.GraphState(use_server = True)

# This all happens instantly
psi.add_qubits(xrange(10))
psi.add_qubit(500)
psi.add_qubit(10) # fails

for i in range(10):
psi.act_hadamard(i)

for i in range(10, 100)
psi.act_local_rotation(i, "hadamard")

time.sleep(10)
# The user does some stuff and edits the state

print psi # We see the new qubits



+ 0
- 18
examples/use_server.py Целия файл

@@ -1,18 +0,0 @@
from abp import GraphState
from abp import Client
import time

psi = Client()

psi.draw()
psi.add_nodes(range(10))
psi.draw()
psi.act_hadamard(0)
psi.act_hadamard(1)
psi.draw()
psi.act_cz(0, 1)
psi.draw()
psi.act_cz(0, 1)
server.draw()

server.shutdown()

profiling/profile_viz.py → examples/visualization_demo.py Целия файл

@@ -1,12 +1,12 @@
from abp import VisibleGraphState
from abp.viz import VisibleGraphState
import numpy as np

s = VisibleGraphState()
for i in range(200):
x = 10*np.cos(np.pi*2*i/60)
y = 10*np.sin(np.pi*2*i/60)
s.add_node(i, {"position": (x, y, i/50.)})
s.add_node(i, {"position": (round(x, 2), round(y, 2), round(i/50., 2))})
s.act_local_rotation(i, "hadamard")
for i in range(200-1):
s.act_cz(i, i+1)
s.update()

+ 0
- 1
profiling/abp Целия файл

@@ -1 +0,0 @@
../abp/

+ 0
- 13
profiling/profile_cz_table.py Целия файл

@@ -1,13 +0,0 @@
from abp import make_tables
import cProfile, pstats, StringIO

unitaries = make_tables.get_unitaries()

profiler = cProfile.Profile()
profiler.enable()
make_tables.get_cz_table(unitaries)
profiler.disable()

# Print output
stats = pstats.Stats(profiler).strip_dirs().sort_stats('tottime')
stats.print_stats(10)

+ 0
- 25
scripts/make_js_stuff.py Целия файл

@@ -1,25 +0,0 @@
from abp import clifford
import json

with open("../server/tables.js", "w") as f:
f.write("var decompositions = ")
f.write(json.dumps(clifford.decompositions))
f.write(";\n")

f.write("var conjugation_table = ")
f.write(json.dumps(clifford.conjugation_table.tolist()))
f.write(";\n")

f.write("var times_table = ")
f.write(json.dumps(clifford.times_table.tolist()))
f.write(";\n")

f.write("var cz_table = ")
f.write(json.dumps(clifford.cz_table.tolist()))
f.write(";\n")

f.write("var clifford = ")
f.write(json.dumps(clifford.by_name))
f.write(";\n")



Loading…
Отказ
Запис