Skip to content

Commit

Permalink
Update main.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed Dec 23, 2019
1 parent e88fe43 commit 8df3746
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions quick-start/7.variation-quantum-eigen-solver/main.jl
Expand Up @@ -2,8 +2,11 @@

using Yao, Yao.AD, YaoExtensions

n = 4 # number of qubits
d = 5 # depth
# number of qubits
n = 4

# depth
d = 5
circuit = dispatch!(variational_circuit(n, d),:random)

gatecount(circuit)
Expand All @@ -12,13 +15,13 @@ 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
# pick the one you like
# either reverse-mode
_, grad = expect'(h, zero_state(n) => circuit)
# or forward mode
#grad = faithful_grad(h, zero_state(n) => circuit; nshots=100)

dispatch!(-, circuit, 1e-2 * grad)
println("Step $i, energy = $(real.(expect(h, zero_state(n)=>circuit)))")
end
Expand Down

0 comments on commit 8df3746

Please sign in to comment.