Isn't VQE coming in the NISQ era? (Is it really coming ...?) So I implemented a simple problem with Blueqat. This time, I will try to solve a trivial combination optimization problem in the sense of checking the program operation.
Solve the following combination of $ q (0) $ and $ q (1) $ that minimizes the Hamiltonian $ H
By the way, Hamiltonian takes the following values for all combinations of $ q (0) and q (1) $.
from blueqat.pauli import qubo_bit as q
from blueqat.vqe import Vqe, QaoaAnsatz
#Hamiltonian
h = 1.0 - q(0) - q(1)
ansatz = QaoaAnsatz(h, 10)
runner = Vqe(ansatz)
result = runner.run()
print("mode:")
print(result.most_common())
print("minimum value:")
print(runner.ansatz.get_energy(result.circuit, runner.sampler))
I won't explain the details of the source code, but it's fairly easy to write.
mode:
(((1, 1), 0.9999999999996781),)
minimum value:
-0.9999999999996781
Combination of solutions of $ (1,1) \ rightarrow q (0) = 1, q (1) = 1 $
Probability of appearance of $ 0.999999999996781 \ rightarrow (1,1) $ (result changes each time execution)
It was really easy to implement! In the future, I would like to make some applications.
Recommended Posts