| @@ -9,7 +9,7 @@ from functools import reduce | |||||
| import itertools as it | import itertools as it | ||||
| import numpy as np | import numpy as np | ||||
| from tqdm import tqdm | from tqdm import tqdm | ||||
| #import argparse | |||||
| # import argparse | |||||
| import qi | import qi | ||||
| @@ -120,6 +120,23 @@ def get_cz_table(unitaries): | |||||
| return cz_table | 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 | # First try to load tables from cache. If that fails, build them from | ||||
| # scratch and store in /tmp/ | # scratch and store in /tmp/ | ||||
| tempdir = tempfile.gettempdir() | tempdir = tempfile.gettempdir() | ||||
| @@ -129,9 +146,9 @@ try: | |||||
| raise IOError | raise IOError | ||||
| # Parse command line args | # 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 | legacy_cz = False | ||||
| unitaries = np.load(temp("unitaries.npy")) | unitaries = np.load(temp("unitaries.npy")) | ||||
| @@ -159,7 +176,7 @@ except IOError: | |||||
| np.save(temp("conjugation_table.npy"), conjugation_table) | np.save(temp("conjugation_table.npy"), conjugation_table) | ||||
| np.save(temp("times_table.npy"), times_table) | np.save(temp("times_table.npy"), times_table) | ||||
| np.save(temp("cz_table.npy"), cz_table) | np.save(temp("cz_table.npy"), cz_table) | ||||
| write_javascript_tables() | |||||
| with open(temp("by_name.json"), "wb") as f: | with open(temp("by_name.json"), "wb") as f: | ||||
| json.dump(by_name, f) | json.dump(by_name, f) | ||||
| @@ -6,15 +6,8 @@ import abp | |||||
| clients = [] | clients = [] | ||||
| def new_message(client, server, message): | 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): | def new_client(client, server): | ||||
| print "Client {} connected.".format(client["id"]) | print "Client {} connected.".format(client["id"]) | ||||
| @@ -31,3 +24,4 @@ if __name__ == '__main__': | |||||
| server.set_fn_client_left(client_left) | server.set_fn_client_left(client_left) | ||||
| server.run_forever() | server.run_forever() | ||||
| @@ -16,6 +16,7 @@ function connect_to_server() { | |||||
| ws.onmessage = function (evt) | ws.onmessage = function (evt) | ||||
| { | { | ||||
| console.log("Received update"); | |||||
| var new_state = JSON.parse(evt.data); | var new_state = JSON.parse(evt.data); | ||||
| vops = new_state.vops; | vops = new_state.vops; | ||||
| ngbh = new_state.ngbh; | ngbh = new_state.ngbh; | ||||
| @@ -1 +0,0 @@ | |||||
| ../abp/ | |||||
| @@ -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 | |||||
| @@ -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() | |||||
| @@ -1,12 +1,12 @@ | |||||
| from abp import VisibleGraphState | |||||
| from abp.viz import VisibleGraphState | |||||
| import numpy as np | import numpy as np | ||||
| s = VisibleGraphState() | s = VisibleGraphState() | ||||
| for i in range(200): | for i in range(200): | ||||
| x = 10*np.cos(np.pi*2*i/60) | x = 10*np.cos(np.pi*2*i/60) | ||||
| y = 10*np.sin(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") | s.act_local_rotation(i, "hadamard") | ||||
| for i in range(200-1): | for i in range(200-1): | ||||
| s.act_cz(i, i+1) | s.act_cz(i, i+1) | ||||
| s.update() | |||||
| @@ -1 +0,0 @@ | |||||
| ../abp/ | |||||
| @@ -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) | |||||
| @@ -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") | |||||