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.

27 lines
579 B

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