From 85afa708c9faf84282a71e67f80c9342bfbeae23 Mon Sep 17 00:00:00 2001 From: Ejaaz Merali Date: Wed, 11 Dec 2019 14:20:37 -0500 Subject: [PATCH 1/4] Update main.jl --- quick-start/5.shor-9-code/main.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quick-start/5.shor-9-code/main.jl b/quick-start/5.shor-9-code/main.jl index cc6f064..66de158 100644 --- a/quick-start/5.shor-9-code/main.jl +++ b/quick-start/5.shor-9-code/main.jl @@ -21,7 +21,7 @@ shor(E) = chain(9, ) # Now we can check whether it can correct a given error by doing symbolic computation -# on a 1-qubit quantum state ``α|0⟩ + β|1⟩`` and an arbitrary weight-9 error. +# on an arbitrary 1-qubit pure quantum state ``α|0⟩ + β|1⟩`` and a specific weight-9 error. @vars α β s = α * ket"0" + β * ket"1" |> addbits!(8) From 0ccdb8e69831410b8ea6499cca34590f57102df3 Mon Sep 17 00:00:00 2001 From: Lei Wang Date: Thu, 12 Dec 2019 17:40:33 +0800 Subject: [PATCH 2/4] simplify vqe; both reverse and forward modes AD --- .../7.variation-quantum-eigen-solver/main.jl | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/quick-start/7.variation-quantum-eigen-solver/main.jl b/quick-start/7.variation-quantum-eigen-solver/main.jl index 706b073..dcce7f6 100644 --- a/quick-start/7.variation-quantum-eigen-solver/main.jl +++ b/quick-start/7.variation-quantum-eigen-solver/main.jl @@ -2,35 +2,22 @@ using Yao, Yao.AD, YaoExtensions - -using YaoExtensions: get_diffblocks, _perturb -using StatsBase - -function _expect(op::AbstractBlock, reg::ArrayReg; nshots=nothing) - if nshots === nothing - expect(op, reg) - else - mean(measure(op, copy(reg); nshots=nshots)) - end -end - -@inline function my_faithful_grad(op::AbstractBlock, pair::Pair{<:ArrayReg, <:AbstractBlock}; nshots=nothing) - map(get_diffblocks(pair.second)) do diffblock - r1, r2 = _perturb(()->_expect(op, copy(pair.first) |> pair.second; nshots=nshots) |> real, diffblock, π/2) - (r2 - r1)/2 - end -end - -n = 4 -d = 5 +n = 4 # number of qubits +d = 5 # depth circuit = dispatch!(variational_circuit(n, d),:random) gatecount(circuit) +nparameters(circuit) + h = heisenberg(n) for i in 1:1000 - grad = my_faithful_grad(h, zero_state(n) => circuit; nshots=100) + # 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)))") From a50a46158e2eb90cde351e91baf6fbfa0fef30e3 Mon Sep 17 00:00:00 2001 From: Lei Wang Date: Mon, 16 Dec 2019 15:57:41 +0800 Subject: [PATCH 3/4] rm unnecessary --- developer-guide/2.cuda-acceleration/main.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/developer-guide/2.cuda-acceleration/main.jl b/developer-guide/2.cuda-acceleration/main.jl index ffdcdca..028b1c1 100644 --- a/developer-guide/2.cuda-acceleration/main.jl +++ b/developer-guide/2.cuda-acceleration/main.jl @@ -34,4 +34,3 @@ # Only if two qubits at `locs` are $0$ and $1$ respectively, they are exchanged, otherwise do nothing. # Although $3/4$ of threads are idle and plenty room for optimization, from this example, we see how easy CUDA programming is with # [CUDAnative](https://github.com/JuliaGPU/CUDAnative.jl). -# In appendix \App{app-reg}, we show another example of creating a register that echos received instructions. From 8df37463c88f8384de741c6c3da110558f1bcb03 Mon Sep 17 00:00:00 2001 From: Rogerluo Date: Mon, 23 Dec 2019 01:18:01 -0500 Subject: [PATCH 4/4] Update main.jl --- .../7.variation-quantum-eigen-solver/main.jl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/quick-start/7.variation-quantum-eigen-solver/main.jl b/quick-start/7.variation-quantum-eigen-solver/main.jl index dcce7f6..5dd694e 100644 --- a/quick-start/7.variation-quantum-eigen-solver/main.jl +++ b/quick-start/7.variation-quantum-eigen-solver/main.jl @@ -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) @@ -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