@@ -1,3 +1,4 @@ | |||||
.venv | |||||
.anders | .anders | ||||
.noseids | .noseids | ||||
debug_anders.txt | debug_anders.txt | ||||
@@ -177,6 +177,14 @@ def get_cz_table(unitaries): | |||||
cz_table[bond, c2, c1] = [newbond, c2p, c1p] | cz_table[bond, c2, c1] = [newbond, c2p, c1p] | ||||
return cz_table | return cz_table | ||||
def get_display_table(unitaries): | |||||
""" Used to display VOPs in a human readable style """ | |||||
for u in unitaries: | |||||
c = qi.CircuitModel(1) | |||||
c.act_local_rotation(0, u) | |||||
state = c.state.round(2) | |||||
print "{:.2f}, {:.2f}".format(state[0][0], state[1][0]) | |||||
def compute_everything(): | def compute_everything(): | ||||
""" Compute all lookup tables """ | """ Compute all lookup tables """ | ||||
@@ -221,7 +229,8 @@ def write_javascript(data): | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
data = compute_everything() | |||||
data = human_readable(data) | |||||
write_python(data) | |||||
write_javascript(data) | |||||
get_display_table(get_unitaries()) | |||||
#data = compute_everything() | |||||
#data = human_readable(data) | |||||
#write_python(data) | |||||
#write_javascript(data) |
@@ -18,9 +18,15 @@ def use_old_cz(): | |||||
from anders_cz import cz_table | from anders_cz import cz_table | ||||
def get_name(i): | def get_name(i): | ||||
""" Get the human-readable name of this clifford """ | |||||
""" Get the name of this clifford """ | |||||
return "IXYZ"[i & 0x03] + "ABCDEF"[i / 4] | return "IXYZ"[i & 0x03] + "ABCDEF"[i / 4] | ||||
def human_name(i): | |||||
""" Get the human-readable name of this clifford - slow """ | |||||
choices = sorted((key for key, value in by_name.items() if value == i), key=len) | |||||
return choices[-1] | |||||
def is_diagonal(v): | def is_diagonal(v): | ||||
""" TODO: remove this. Checks if a VOP is diagonal or not """ | """ TODO: remove this. Checks if a VOP is diagonal or not """ | ||||
return v in {0, 3, 5, 6} | return v in {0, 3, 5, 6} | ||||
@@ -220,10 +220,25 @@ class GraphState(object): | |||||
def __str__(self): | def __str__(self): | ||||
""" Represent as a string for quick debugging """ | """ Represent as a string for quick debugging """ | ||||
node = {key: clifford.get_name(value["vop"]) | |||||
for key, value in self.node.items()} | |||||
nbstr = str(self.adj) | |||||
return "graph:\n node: {}\n adj: {}\n".format(node, nbstr) | |||||
s = "" | |||||
for key in sorted(self.node.keys()): | |||||
s += "{}: {}\t".format(key, clifford.get_name(self.node[key]["vop"]).replace("YC", "-")) | |||||
if self.adj[key]: | |||||
s += str(tuple(self.adj[key].keys())).replace(" ", "") | |||||
else: | |||||
s += "-" | |||||
s += "\n" | |||||
return s | |||||
#clean = lambda n: str(n["vop"]) | |||||
#nodes = ("{}: {}".format(key, clean(value)) for key, value in sorted(self.node.items())) | |||||
#nodes = "\n".join(nodes) | |||||
#return "Nodes:\n{}\n\nEdges:\n{}".format(nodes, "") | |||||
#node = {key: clifford.get_name(value["vop"]) | |||||
#for key, value in self.node.items()} | |||||
#nbstr = str(self.adj) | |||||
#return "graph:\n node: {}\n adj: {}\n".format(node, nbstr) | |||||
def to_json(self, stringify=False): | def to_json(self, stringify=False): | ||||
""" | """ | ||||
@@ -275,3 +290,11 @@ class GraphState(object): | |||||
""" Check equality between graphs """ | """ Check equality between graphs """ | ||||
return self.adj == other.adj and self.node == other.node | return self.adj == other.adj and self.node == other.node | ||||
if __name__ == '__main__': | |||||
g = GraphState() | |||||
g.add_nodes(range(10)) | |||||
g.add_edge(0, 5) | |||||
g.act_local_rotation(6, 10) | |||||
print g | |||||
print g.to_state_vector() | |||||
@@ -93,9 +93,9 @@ class CircuitModel(object): | |||||
where = 1 << qubit | where = 1 << qubit | ||||
output = np.zeros((self.d, 1), dtype=complex) | output = np.zeros((self.d, 1), dtype=complex) | ||||
for i, v in enumerate(self.state): | for i, v in enumerate(self.state): | ||||
q = i & where > 0 | |||||
q = int(i & where > 0) | |||||
output[i] += v * ha[q, q] | output[i] += v * ha[q, q] | ||||
output[i ^ where] += v * ha[not q, q] | |||||
output[i ^ where] += v * ha[int(not q), q] | |||||
self.state = output | self.state = output | ||||
def act_local_rotation(self, qubit, u): | def act_local_rotation(self, qubit, u): | ||||
@@ -103,9 +103,9 @@ class CircuitModel(object): | |||||
where = 1 << qubit | where = 1 << qubit | ||||
output = np.zeros((self.d, 1), dtype=complex) | output = np.zeros((self.d, 1), dtype=complex) | ||||
for i, v in enumerate(self.state): | for i, v in enumerate(self.state): | ||||
q = i & where > 0 | |||||
q = int(i & where > 0) | |||||
output[i] += v * u[q, q] # TODO this is probably wrong | output[i] += v * u[q, q] # TODO this is probably wrong | ||||
output[i ^ where] += v * u[not q, q] | |||||
output[i ^ where] += v * u[int(not q), q] | |||||
self.state = output | self.state = output | ||||
def __eq__(self, other): | def __eq__(self, other): | ||||
@@ -120,5 +120,5 @@ class CircuitModel(object): | |||||
for i in range(self.d): | for i in range(self.d): | ||||
label = bin(i)[2:].rjust(self.nqubits, "0") | label = bin(i)[2:].rjust(self.nqubits, "0") | ||||
if abs(self.state[i, 0]) > 0.00001: | if abs(self.state[i, 0]) > 0.00001: | ||||
s += "|{}>: {}\n".format(label, self.state[i, 0].round(3)) | |||||
s += "|{}>: {:.2f}\n".format(label, self.state[i, 0]) | |||||
return s | return s |