Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (21 sloc) 601 Bytes
# # Variational Quantum Eigen Solver
using Yao, Yao.AD, YaoExtensions
# number of qubits
n = 4
# depth
d = 5
circuit = dispatch!(variational_circuit(n, d),:random)
gatecount(circuit)
nparameters(circuit)
h = heisenberg(n)
# pick the one you like
# either reverse-mode
# or forward mode
# grad = faithful_grad(h, zero_state(n) => circuit; nshots=100)
for i in 1:1000
_, grad = expect'(h, zero_state(n) => circuit)
dispatch!(-, circuit, 1e-2 * grad)
println("Step $i, energy = $(real.(expect(h, zero_state(n)=>circuit)))")
end
using LinearAlgebra
w, _ = eigen(Matrix(mat(h)))
You can’t perform that action at this time.