diff --git a/abp/__init__.py b/abp/__init__.py index 3933731..a2258ac 100644 --- a/abp/__init__.py +++ b/abp/__init__.py @@ -1,4 +1,3 @@ # Alias some stuff to make imports cleaner from abp.graphstate import GraphState from abp.qi import CircuitModel -from abp.client import Client diff --git a/abp/client.py b/abp/client.py deleted file mode 100644 index 7d127cb..0000000 --- a/abp/client.py +++ /dev/null @@ -1,48 +0,0 @@ -import requests -import abp, json - -class ClientError(Exception): - def __init__(self, message): - self.message = message - -class Client(object): - def __init__(self, host="localhost", port=5000, clear=False): - self.session = requests.Session() - self.root = "http://{}:{}".format(host, port) - if clear: - self.clear() - - def get(self, endpoint): - url =self.root+endpoint - response = self.session.get(url) - if response.status_code == 404: - message = "404. Check that the server is running!".format(self.root, endpoint) - raise ClientError(message) - return response.content - - def get_state(self): - response = self.get("/state") - output = abp.GraphState() - output.from_json(json.loads(response)) - return output - - def set_state(self, state): - response = self.session.post(self.root+"/state", data=state.to_json()) - if not response.status_code == 200: - print response.status_code - return response.content - - def add_node(self, node): - return self.get("/add_node/{}".format(node)) - - def act_local_rotation(self, node, operation): - return self.get("/act_local_rotation/{}/{}".format(node, operation)) - - def act_cz(self, a, b): - return self.get("/act_cz/{}/{}".format(a, b)) - - def clear(self): - return self.get("/clear") - - def kill(self): - self.session.close() diff --git a/abp/clifford.py b/abp/clifford.py index c671b91..fa0ed51 100644 --- a/abp/clifford.py +++ b/abp/clifford.py @@ -67,8 +67,8 @@ def get_by_name(unitaries): """ Get a lookup table of cliffords by name """ a = {name: find_clifford(u, unitaries) for name, u in qi.by_name.items()} - b = {get_name(i): i for i in range(24)} - a.update(b) + a.update({get_name(i): i for i in range(24)}) + a.update({i: i for i in range(24)}) return a diff --git a/abp/graphstate.py b/abp/graphstate.py index 81cec6a..0fb9ea7 100644 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -88,14 +88,10 @@ class GraphState(object): for i in self.ngbh[v]: self.vops[i] = clifford.times_table[self.vops[i], sqz_h] - def act_local_rotation(self, a, op): + def act_local_rotation(self, v, op): """ Act a local rotation """ - self.vops[a] = clifford.times_table[op, self.vops[a]] - - def act_local_rotation_by_name(self, qubit, name): - """ Shorthand """ - rotation = clifford.by_name[name] - self.act_local_rotation(qubit, rotation) + rotation = clifford.by_name[str(op)] + self.vops[v] = clifford.times_table[rotation, self.vops[v]] def act_hadamard(self, qubit): """ Shorthand """ @@ -123,15 +119,14 @@ class GraphState(object): for neighbour in self.ngbh[node]: self.del_edge(node, neighbour) if res: - self.act_local_rotation_by_name(neighbour, "pz") + self.act_local_rotation(neighbour, "pz") - # Set final state as appropriate - # TODO: cache these lookups. sux + # Rotate if res: - self.act_local_rotation_by_name(node, "px") - self.act_local_rotation_by_name(node, "hadamard") + self.act_local_rotation(node, "px") + self.act_local_rotation(node, "hadamard") else: - self.act_local_rotation_by_name(node, "hadamard") + self.act_local_rotation(node, "hadamard") return res diff --git a/tests/test_get_state_vector.py b/tests/test_get_state_vector.py index 3b9910d..aa6daae 100644 --- a/tests/test_get_state_vector.py +++ b/tests/test_get_state_vector.py @@ -7,8 +7,8 @@ def test_single_qubit(): g = GraphState() g.add_node(0) g.add_node(1) - g.act_local_rotation_by_name(0, "hadamard") - g.act_local_rotation_by_name(1, "hadamard") + g.act_local_rotation(0, "hadamard") + g.act_local_rotation(1, "hadamard") g.act_cz(0, 1) assert np.allclose(g.to_state_vector().state, qi.bond)