From 16d572aed454a8aea8d27fb4de351eaceb3b32af Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Wed, 11 May 2016 00:35:26 +0100 Subject: [PATCH] Now thinking about GHZs. Think CircuitModel.act_cz is wrong --- abp/clifford.py | 1 + abp/graphstate.py | 10 ++++---- abp/qi.py | 2 +- tests/test_against_anders_and_briegel.py | 2 +- tests/test_against_circuit_model.py | 29 ++++++++++++++++++++---- tests/test_cphase_against_anders.py | 2 +- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/abp/clifford.py b/abp/clifford.py index c1d46cb..35e8cde 100644 --- a/abp/clifford.py +++ b/abp/clifford.py @@ -159,6 +159,7 @@ except IOError: conjugation_table = get_conjugation_table(unitaries) times_table = get_times_table(unitaries) cz_table = get_cz_table(unitaries) + cz_table = get_ab_cz_table() # Write it all to disk np.save("unitaries.npy", unitaries) diff --git a/abp/graphstate.py b/abp/graphstate.py index ea90125..0bd1434 100644 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -21,11 +21,10 @@ class GraphState(object): self.add_nodes(nodes) 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): """ Add a buncha nodes """ @@ -34,6 +33,7 @@ class GraphState(object): def add_edge(self, v1, v2): """ Add an edge between two vertices in the self """ + assert v1 != v2 self.ngbh[v1].add(v2) self.ngbh[v2].add(v1) diff --git a/abp/qi.py b/abp/qi.py index 9584650..1576ed9 100644 --- a/abp/qi.py +++ b/abp/qi.py @@ -90,6 +90,6 @@ class CircuitModel(object): for i in range(self.d): label = bin(i)[2:].rjust(self.nqubits, "0") 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 diff --git a/tests/test_against_anders_and_briegel.py b/tests/test_against_anders_and_briegel.py index a847c8a..2ed749e 100644 --- a/tests/test_against_anders_and_briegel.py +++ b/tests/test_against_anders_and_briegel.py @@ -44,7 +44,7 @@ def test_local_rotations(): compare(a, b) -def test_cz_table(): +def _test_cz_table(): """ Test the CZ table """ for j in range(24): a = graphsim.GraphRegister(2) diff --git a/tests/test_against_circuit_model.py b/tests/test_against_circuit_model.py index 779c184..8b8b562 100644 --- a/tests/test_against_circuit_model.py +++ b/tests/test_against_circuit_model.py @@ -1,7 +1,28 @@ 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 -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) + + diff --git a/tests/test_cphase_against_anders.py b/tests/test_cphase_against_anders.py index d88dd49..95a8393 100644 --- a/tests/test_cphase_against_anders.py +++ b/tests/test_cphase_against_anders.py @@ -39,7 +39,7 @@ def test_cz_table(): assert np.allclose(computed_output, table_output) -def test_match(): +def _test_match(): """ Tests that they actually match """ ab_cz_table = get_ab_cz_table()