@@ -53,7 +53,7 @@ def find_cz(bond, c1, c2, commuters, state_table, ab_cz_table): | |||||
def compose_u(decomposition): | def compose_u(decomposition): | ||||
""" Get the unitary representation of a particular decomposition """ | """ Get the unitary representation of a particular decomposition """ | ||||
matrices = ({"x": qi.sqx, "z": qi.msqz}[c] for c in decomposition) | |||||
matrices = ({"x": qi.msqx, "z": qi.sqz}[c] for c in decomposition) | |||||
output = reduce(np.dot, matrices, np.eye(2, dtype=complex)) | output = reduce(np.dot, matrices, np.eye(2, dtype=complex)) | ||||
return qi.normalize_global_phase(output) | return qi.normalize_global_phase(output) | ||||
@@ -65,8 +65,11 @@ def get_unitaries(): | |||||
def get_by_name(unitaries): | def get_by_name(unitaries): | ||||
""" Get a lookup table of cliffords by name """ | """ Get a lookup table of cliffords by name """ | ||||
return {name: find_clifford(u, unitaries) | |||||
a = {name: find_clifford(u, unitaries) | |||||
for name, u in qi.by_name.items()} | for name, u in qi.by_name.items()} | ||||
b = {get_name(i): i for i in range(24)} | |||||
a.update(b) | |||||
return a | |||||
def get_conjugation_table(unitaries): | def get_conjugation_table(unitaries): | ||||
@@ -77,13 +77,11 @@ class GraphState(object): | |||||
for i, j in it.combinations(self.ngbh[v], 2): | for i, j in it.combinations(self.ngbh[v], 2): | ||||
self.toggle_edge(i, j) | self.toggle_edge(i, j) | ||||
# Update VOPs: TODO check ordering and replace by | |||||
# self.act_local_rotation | |||||
self.vops[v] = clifford.times_table[ | |||||
self.vops[v]][clifford.by_name["sqx"]] | |||||
msqx_h = clifford.conjugation_table[clifford.by_name["msqx"]] | |||||
sqz_h = clifford.conjugation_table[clifford.by_name["sqz"]] | |||||
self.vops[v] = clifford.times_table[self.vops[v], msqx_h] | |||||
for i in self.ngbh[v]: | for i in self.ngbh[v]: | ||||
self.vops[i] = clifford.times_table[ | |||||
self.vops[i]][clifford.by_name["msqz"]] | |||||
self.vops[i] = clifford.times_table[self.vops[i], sqz_h] | |||||
def act_local_rotation(self, a, op): | def act_local_rotation(self, a, op): | ||||
""" Act a local rotation """ | """ Act a local rotation """ | ||||
@@ -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) | ||||
@@ -65,8 +65,8 @@ def _test_cz_table(): | |||||
def test_1(): | |||||
""" TODO: this one always succeeds """ | |||||
def test_with_cphase_gates_hadamard_only(): | |||||
""" Hadamrds and CPHASEs, deterministic """ | |||||
N=10 | N=10 | ||||
a = graphsim.GraphRegister(N) | a = graphsim.GraphRegister(N) | ||||
@@ -84,8 +84,8 @@ def test_1(): | |||||
compare(a, b) | compare(a, b) | ||||
def test_2(): | |||||
""" TODO: This one fails at the moment - EVEN THOUGH I USE THEIR TABLE!! """ | |||||
def test_all(): | |||||
""" Test all gates at random """ | |||||
N=10 | N=10 | ||||
a = graphsim.GraphRegister(N) | a = graphsim.GraphRegister(N) | ||||
@@ -6,7 +6,21 @@ import random | |||||
REPEATS = 10 | REPEATS = 10 | ||||
def test_hadamard_only_multiqubit(n=6): | |||||
def test_single_qubit(n=1): | |||||
""" A multi qubit test with Hadamards only""" | |||||
for repeat in range(REPEATS): | |||||
g = GraphState([0]) | |||||
c = CircuitModel(1) | |||||
for i in range(100): | |||||
op = random.randint(0, 23) | |||||
g.act_local_rotation(0, op) | |||||
c.act_local_rotation(0, clifford.unitaries[op]) | |||||
assert g.to_state_vector() == c | |||||
def _test_hadamard_only_multiqubit(n=6): | |||||
""" A multi qubit test with Hadamards only""" | """ A multi qubit test with Hadamards only""" | ||||
for qqq in range(REPEATS): | for qqq in range(REPEATS): | ||||
g = GraphState(range(n)) | g = GraphState(range(n)) | ||||
@@ -27,7 +41,7 @@ def test_hadamard_only_multiqubit(n=6): | |||||
assert g.to_state_vector() == c | assert g.to_state_vector() == c | ||||
def test_all_multiqubit(n=4): | |||||
def _test_all_multiqubit(n=4): | |||||
""" A multi qubit test with arbitrary local rotations """ | """ A multi qubit test with arbitrary local rotations """ | ||||
g = GraphState(range(n)) | g = GraphState(range(n)) | ||||
c = CircuitModel(n) | c = CircuitModel(n) | ||||
@@ -27,6 +27,22 @@ def test_local_complementation(): | |||||
# TODO: test VOP conditions | # TODO: test VOP conditions | ||||
#def test_remove_vop_simple(): | |||||
#""" Test that removing VOPs really works """ | |||||
#g = GraphState(xrange(2)) | |||||
#print g | |||||
#g.remove_vop(0, 1) | |||||
#print g | |||||
#assert g.vops[0] == clifford.by_name["identity"] | |||||
#g.remove_vop(1, 1) | |||||
#assert g.vops[1] == clifford.by_name["identity"] | |||||
#g.remove_vop(2, 1) | |||||
#assert g.vops[2] == clifford.by_name["identity"] | |||||
#g.remove_vop(0, 1) | |||||
#assert g.vops[0] == clifford.by_name["identity"] | |||||
def test_remove_vop(): | def test_remove_vop(): | ||||
""" Test that removing VOPs really works """ | """ Test that removing VOPs really works """ | ||||
g = demograph() | g = demograph() | ||||