Anders and Briegel in Python
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

47 lines
1.1KB

  1. import json
  2. import networkx as nx
  3. from abp import GraphState, NXGraphState
  4. from abp import clifford
  5. from abp.util import xyz
  6. import pytest
  7. mock = pytest.importorskip("mock")
  8. def test_json_basic():
  9. """ Test that we can export to JSON """
  10. g = mock.simple_graph()
  11. js = g.to_json()
  12. assert "adj" in js
  13. assert "node" in js
  14. def test_tuple_keys():
  15. """ Test that we can use tuple-ish keys """
  16. g = NXGraphState()
  17. g.add_qubit("string")
  18. g.add_qubit((1, 2, 3))
  19. g.add_edge((1, 2, 3), "string")
  20. json.dumps(g.to_json(True))
  21. def networkx_test():
  22. """ Test that NXGraphStates really behave like networkx graphs """
  23. g = NXGraphState()
  24. g.add_qubit(0, position=xyz(10, 0, 0))
  25. g.add_qubit(1, position=xyz(1, 0, 0))
  26. g.act_hadamard(0)
  27. g.act_hadamard(1)
  28. g.act_cz(0, 1)
  29. g.copy()
  30. def test_from_nx():
  31. """ Test that making graphs from networkx objects goes smoothly """
  32. g = nx.random_geometric_graph(100, 2)
  33. psi = NXGraphState(g)
  34. assert psi.node[0]["vop"] == 0
  35. assert len(psi.edges()) > 0
  36. psi.measure(0, "px", detail=True)
  37. psi = NXGraphState(nx.Graph(((0, 1),)))