Qiskit 0.24.0的Max-Cut和Travelling Salesman Problem教程中如何解决大于3个节点的TSP问题?

How to solve TSP problem with more than 3 nodes in the tutorial of Max-Cut and Traveling Salesman Problem Qiskit 0.24.0?

我不得不尝试 qiskit 的例子 Traveling Salesman Problem 3 个节点并在 IBM 后端执行它 simulator_statevector.Can 执行并正常得到结果。

但是当尝试解决超过 3 个节点的 TSP 问题时,我将 n = 3 更改为 n = 4。

# Generating a graph of 3 nodes
n = 4
num_qubits = n ** 2
ins = tsp.random_tsp(n, seed=123)
print('distance\n', ins.w)

# Draw the graph
G = nx.Graph()
G.add_nodes_from(np.arange(0, ins.dim, 1))
colors = ['r' for node in G.nodes()]

for i in range(0, ins.dim):
    for j in range(i+1, ins.dim):
        G.add_edge(i, j, weight=ins.w[i,j])

pos = {k: v for k, v in enumerate(ins.coord)}

draw_graph(G, colors, pos)

并且我将设备上的后端从 Aer.get_backend ('statevector_simulator') 运行 更改为 IBM 后端上的 provider.backend.simulator_statevector 运行。

aqua_globals.random_seed = np.random.default_rng(123)
seed = 10598
backend = provider.backend.simulator_statevector
#backend = Aer.get_backend('statevector_simulator')
quantum_instance = QuantumInstance(backend, seed_simulator=seed, seed_transpiler=seed)

但是出来的结果出错了

energy: -1303102.65625
time: 5626.549758911133
feasible: False
solution: [1, 0, 2, []]
solution objective: []
Traceback (most recent call last):
  File "<ipython-input-10-bc5619b5292f>", line 14, in <module>
    draw_tsp_solution(G, z, colors, pos)
  File "<ipython-input-4-999185567031>", line 29, in draw_tsp_solution
    G2.add_edge(order[i], order[j], weight=G[order[i]][order[j]]['weight'])
  File "/opt/conda/lib/python3.8/site-packages/networkx/classes/coreviews.py", line 51, in __getitem__
    return self._atlas[key]
TypeError: unhashable type: 'list'

Use %tb to get the full traceback.

我该如何解决?请给我一些建议。

我找到了答案,我的方法是将 Ansat 重复次数从 5 次增加到 7 次。

来自解决 TSP 4 节点问题

spsa = SPSA(maxiter=300)
ry = TwoLocal(qubitOp.num_qubits, 'ry', 'cz', reps=7, entanglement='linear')
vqe = VQE(qubitOp, ry, spsa, quantum_instance=quantum_instance)

result = vqe.run(quantum_instance)