Przeglądaj źródła

Remove act_local_rotation_by_name (simplifies API)

master
Pete Shadbolt 8 lat temu
rodzic
commit
b063d1ff1f
5 zmienionych plików z 12 dodań i 66 usunięć
  1. +0
    -1
      abp/__init__.py
  2. +0
    -48
      abp/client.py
  3. +2
    -2
      abp/clifford.py
  4. +8
    -13
      abp/graphstate.py
  5. +2
    -2
      tests/test_get_state_vector.py

+ 0
- 1
abp/__init__.py Wyświetl plik

@@ -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

+ 0
- 48
abp/client.py Wyświetl plik

@@ -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()

+ 2
- 2
abp/clifford.py Wyświetl plik

@@ -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




+ 8
- 13
abp/graphstate.py Wyświetl plik

@@ -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



+ 2
- 2
tests/test_get_state_vector.py Wyświetl plik

@@ -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)



Ładowanie…
Anuluj
Zapisz