Anders and Briegel in Python
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

test_nx.py 1.1KB

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