You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
812 B

5 years ago
5 years ago
  1. import networkx as nx
  2. def qubo_to_nx_graph(qubo):
  3. graph = nx.Graph()
  4. for coupler, energy in qubo.items():
  5. if coupler[0] != coupler[1]:
  6. graph.add_edge(coupler[0], coupler[1], weight=energy)
  7. return graph
  8. def negate_qubo(qubo):
  9. negative_qubo = {}
  10. for coupler, energy in qubo.items():
  11. negative_qubo[coupler] = -1 * energy
  12. return negative_qubo
  13. def create_qpu_solver_nxgraph(solver):
  14. graph = nx.Graph()
  15. graph.name = solver.id
  16. graph.add_edges_from(solver.edges)
  17. return graph
  18. def split_ising(ising):
  19. h = {}
  20. J = {}
  21. for coupler, energy in ising.items():
  22. if coupler[0] == coupler[1]:
  23. h[coupler[0]] = energy
  24. else:
  25. J[coupler] = energy
  26. return h, J