@@ -159,6 +159,7 @@ except IOError: | |||||
conjugation_table = get_conjugation_table(unitaries) | conjugation_table = get_conjugation_table(unitaries) | ||||
times_table = get_times_table(unitaries) | times_table = get_times_table(unitaries) | ||||
cz_table = get_cz_table(unitaries) | cz_table = get_cz_table(unitaries) | ||||
cz_table = get_ab_cz_table() | |||||
# Write it all to disk | # Write it all to disk | ||||
np.save("unitaries.npy", unitaries) | np.save("unitaries.npy", unitaries) | ||||
@@ -21,11 +21,10 @@ class GraphState(object): | |||||
self.add_nodes(nodes) | self.add_nodes(nodes) | ||||
def add_node(self, v): | def add_node(self, v): | ||||
""" Add a node if it doesn't already exist """ | |||||
if not v in self.ngbh: | |||||
self.ngbh[v] = set() | |||||
self.vops[v] = clifford.by_name["hadamard"] | |||||
self.meta[v] = dict() | |||||
""" Add a node """ | |||||
self.ngbh[v] = set() | |||||
self.vops[v] = clifford.by_name["hadamard"] | |||||
self.meta[v] = dict() | |||||
def add_nodes(self, nodes): | def add_nodes(self, nodes): | ||||
""" Add a buncha nodes """ | """ Add a buncha nodes """ | ||||
@@ -34,6 +33,7 @@ class GraphState(object): | |||||
def add_edge(self, v1, v2): | def add_edge(self, v1, v2): | ||||
""" Add an edge between two vertices in the self """ | """ Add an edge between two vertices in the self """ | ||||
assert v1 != v2 | |||||
self.ngbh[v1].add(v2) | self.ngbh[v1].add(v2) | ||||
self.ngbh[v2].add(v1) | self.ngbh[v2].add(v1) | ||||
@@ -90,6 +90,6 @@ 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]) | |||||
s += "|{}>: {}\n".format(label, self.state[i, 0].round(3)) | |||||
return s | return s | ||||
@@ -44,7 +44,7 @@ def test_local_rotations(): | |||||
compare(a, b) | compare(a, b) | ||||
def test_cz_table(): | |||||
def _test_cz_table(): | |||||
""" Test the CZ table """ | """ Test the CZ table """ | ||||
for j in range(24): | for j in range(24): | ||||
a = graphsim.GraphRegister(2) | a = graphsim.GraphRegister(2) | ||||
@@ -1,7 +1,28 @@ | |||||
from abp.graphstate import GraphState | from abp.graphstate import GraphState | ||||
from anders_briegel import graphsim | |||||
from abp.qi import CircuitModel | |||||
from abp import clifford | |||||
import numpy as np | |||||
import random | import random | ||||
from abp import qi | |||||
def single_qubit_test(): | |||||
""" A single qubit test """ | |||||
def multi_qubit_test(): | |||||
""" A multi qubit test """ | |||||
n = 3 | |||||
g = GraphState(range(n)) | |||||
c = CircuitModel(n) | |||||
for i in range(n): | |||||
g.act_hadamard(i) | |||||
c.act_hadamard(i) | |||||
assert np.allclose(g.to_state_vector().state, c.state) | |||||
g.act_cz(0, 1) | |||||
c.act_cz(0, 1) | |||||
g.act_cz(1, 2) | |||||
c.act_cz(1, 2) | |||||
s1 = clifford.normalize_global_phase(g.to_state_vector().state) | |||||
s2 = clifford.normalize_global_phase(c.state) | |||||
assert np.allclose(s1, s2) | |||||
@@ -39,7 +39,7 @@ def test_cz_table(): | |||||
assert np.allclose(computed_output, table_output) | assert np.allclose(computed_output, table_output) | ||||
def test_match(): | |||||
def _test_match(): | |||||
""" Tests that they actually match """ | """ Tests that they actually match """ | ||||
ab_cz_table = get_ab_cz_table() | ab_cz_table = get_ab_cz_table() | ||||