|
@@ -5,6 +5,7 @@ from abp import clifford |
|
|
from abp.util import xyz |
|
|
from abp.util import xyz |
|
|
from mock import simple_graph |
|
|
from mock import simple_graph |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_json_basic(): |
|
|
def test_json_basic(): |
|
|
""" Test that we can export to JSON """ |
|
|
""" Test that we can export to JSON """ |
|
|
g = simple_graph() |
|
|
g = simple_graph() |
|
@@ -12,6 +13,7 @@ def test_json_basic(): |
|
|
assert "adj" in js |
|
|
assert "adj" in js |
|
|
assert "node" in js |
|
|
assert "node" in js |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_tuple_keys(): |
|
|
def test_tuple_keys(): |
|
|
""" Test that we can use tuple-ish keys """ |
|
|
""" Test that we can use tuple-ish keys """ |
|
|
g = fancy.GraphState() |
|
|
g = fancy.GraphState() |
|
@@ -20,17 +22,22 @@ def test_tuple_keys(): |
|
|
g.add_edge((1, 2, 3), "string") |
|
|
g.add_edge((1, 2, 3), "string") |
|
|
json.dumps(g.to_json(True)) |
|
|
json.dumps(g.to_json(True)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def networkx_test(): |
|
|
def networkx_test(): |
|
|
""" Test that fancy graph states really behave like networkx graphs """ |
|
|
""" Test that fancy graph states really behave like networkx graphs """ |
|
|
g = fancy.GraphState() |
|
|
g = fancy.GraphState() |
|
|
g.add_qubit(0, position = xyz(10, 0, 0)) |
|
|
|
|
|
g.add_qubit(1, position = xyz(1, 0, 0)) |
|
|
|
|
|
|
|
|
g.add_qubit(0, position=xyz(10, 0, 0)) |
|
|
|
|
|
g.add_qubit(1, position=xyz(1, 0, 0)) |
|
|
g.act_hadamard(0) |
|
|
g.act_hadamard(0) |
|
|
g.act_hadamard(1) |
|
|
g.act_hadamard(1) |
|
|
g.act_cz(0, 1) |
|
|
g.act_cz(0, 1) |
|
|
g.copy() |
|
|
g.copy() |
|
|
|
|
|
|
|
|
# TODO: more tests here! |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_from_nx(): |
|
|
|
|
|
""" Test that making graphs from networkx objects goes smoothly """ |
|
|
|
|
|
g = nx.random_geometric_graph(100, 2) |
|
|
|
|
|
psi = fancy.GraphState(g) |
|
|
|
|
|
assert psi.node[0]["vop"] == 0 |
|
|
|
|
|
assert len(psi.edges()) > 0 |
|
|
|
|
|
psi.measure(0, "px", detail=True) |