Hi, the AI called ChatGPT is amazing. I've actually used it and it does quite a lot of different calculations, so I thought, don't we need humans anymore? I would like to try some quantum programming.
The conclusion is quite good.
'Write the code for the travelling salesman in python and solve it in d-wave neal with quantum annealing QUBO.'
For the subject
import numpy as np
import neal
def tsp_qubo(distances):
n = distances.shape[0]
Q = np.zeros((n, n))
# Set diagonal elements to 0
for i in range(n):
Q[i][i] = 0
# Set off-diagonal elements
for i in range(n):
for j in range(i+1, n):
Q[i][j] = distances[i][j]
Q[j][i] = distances[i][j]
# Set quadratic bias
q = np.ones(n) * -1
return Q, q
Example distances matrix
distances = np.array([[0, 10, 20, 30], [10, 0, 25, 35], [20, 25, 0, 15], [30, 35, 15, 0]])
Q, q = tsp_qubo(distances)
Solve the problem using the D-Wave system
solver = neal.SimulatedAnnealingSampler()
response = solver.sample_qubo(Q, q)
Print the solution
for sample in response.samples():
print(sample)
There are a few mistakes, but it will save time writing code and considerably reduce the amount of work to be done, given that it will be improved in the future.
The above code does not take constraints into account, so we hope for future improvements.
(I found I can add constraint after did conversation with chatGPT to add constraint term)
Somehow I found that quantum annealing does not need a human being if ChatGPT is used. Next, I would like to look at quantum gates.
from blueqat import Circuit
Create a quantum circuit with 2 qubits
qc = Circuit().h[0].cx[0,1].m[:].run()
Apply a Hadamard gate to the first qubit
Apply a controlled-not (CX) gate between the first and second qubits
Measure both qubits
result = qc.result()
Print the result
print(result)
Successfully created a quantum entangled circuit. The last little modification is necessary, and is possible only with qc, since the quantum circuit has a run().
The result of the calculation is
Counter({'11': 1})
and the result is now "1".
Conclusion.
The time is approaching when human quantum programmers will no longer be needed, and I am worried about what will happen in the future if this is the case at this stage, as AI is definitely developing faster. I have to re-think our business. That's all.