@@ -18,7 +18,7 @@ class GraphState(graphstate.GraphState, networkx.Graph): | |||||
try: | try: | ||||
self.ws = websocket.create_connection(uri, timeout=0.1) | self.ws = websocket.create_connection(uri, timeout=0.1) | ||||
atexit.register(self.shutdown) | atexit.register(self.shutdown) | ||||
except socket_error: | |||||
except: #TODO: bad practice | |||||
self.ws = None | self.ws = None | ||||
def shutdown(self): | def shutdown(self): | ||||
@@ -1,5 +1,5 @@ | |||||
""" | """ | ||||
Provides an extremely basic graph structure, based on neighbour lists | |||||
Provides an extremely basic graph structure, based on key/value pairs | |||||
""" | """ | ||||
import itertools as it | import itertools as it | ||||
@@ -6,6 +6,8 @@ import random | |||||
from copy import deepcopy | from copy import deepcopy | ||||
from tqdm import tqdm | from tqdm import tqdm | ||||
REPEATS = 100 | |||||
def assert_equal(a, b): | def assert_equal(a, b): | ||||
assert a.to_json() == b.to_json() | assert a.to_json() == b.to_json() | ||||
@@ -109,7 +111,7 @@ def test_cz_hadamard(N=3): | |||||
a = graphsim.GraphRegister(N) | a = graphsim.GraphRegister(N) | ||||
b = GraphState(range(N)) | b = GraphState(range(N)) | ||||
previous_state, previous_cz = None, None | previous_state, previous_cz = None, None | ||||
for i in tqdm(range(100000), desc="Testing CZ and Hadamard against A&B"): | |||||
for i in tqdm(range(REPEATS), desc="Testing CZ and Hadamard against A&B"): | |||||
if random.random()>0.5: | if random.random()>0.5: | ||||
j = random.randint(0, N-1) | j = random.randint(0, N-1) | ||||
a.hadamard(j) | a.hadamard(j) | ||||
@@ -131,7 +133,7 @@ def test_all(N=5): | |||||
a = graphsim.GraphRegister(N) | a = graphsim.GraphRegister(N) | ||||
b = GraphState(range(N)) | b = GraphState(range(N)) | ||||
previous_state, previous_cz = None, None | previous_state, previous_cz = None, None | ||||
for i in tqdm(range(100000), desc="Testing all gates against Anders and Briegel"): | |||||
for i in tqdm(range(REPEATS), desc="Testing all gates against Anders and Briegel"): | |||||
if random.random()>0.5: | if random.random()>0.5: | ||||
j = random.randint(0, N-1) | j = random.randint(0, N-1) | ||||
u = random.randint(0, 23) | u = random.randint(0, 23) | ||||
@@ -71,7 +71,8 @@ def test_all(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) | ||||
for step in tqdm(xrange(1000), "Testing a deep circuit against the circuit model"): | |||||
depth = 100 # TODO: too small | |||||
for step in tqdm(xrange(depth), "Testing a deep circuit against the circuit model"): | |||||
if random.random()>0.5: | if random.random()>0.5: | ||||
qubit = np.random.randint(0, n - 1) | qubit = np.random.randint(0, n - 1) | ||||
rotation = np.random.randint(0, 24 - 1) | rotation = np.random.randint(0, 24 - 1) | ||||
@@ -83,6 +84,6 @@ def test_all(n=4): | |||||
g.act_cz(a, b) | g.act_cz(a, b) | ||||
c.act_cz(a, b) | c.act_cz(a, b) | ||||
assert g.to_state_vector() == c | assert g.to_state_vector() == c | ||||
print g.to_state_vector() | |||||
print c | |||||
#print g.to_state_vector() | |||||
#print c | |||||
@@ -8,8 +8,9 @@ def test_z_measurement(): | |||||
def test_z_measurement_against_ab(): | def test_z_measurement_against_ab(): | ||||
for i in range(100): | |||||
for i in range(10): | |||||
a = graphsim.GraphRegister(1) | a = graphsim.GraphRegister(1) | ||||
b = GraphState() | b = GraphState() | ||||
b.add_node(0) | b.add_node(0) | ||||
assert a.measure(0, graphsim.lco_Z) == b.measure(0, "pz") | |||||
print a.measure(0, graphsim.lco_Z) | |||||
print b.measure(0, "pz") |