From 28f350600a0e88fe54eaa01e45661473434c12ae Mon Sep 17 00:00:00 2001 From: GiggleLiu Date: Tue, 30 Apr 2019 00:59:02 +0800 Subject: [PATCH] update for Yao 0.4 --- TFI_onefile.jl | 4 ++-- applications.jl | 2 +- src/Core.jl | 6 +++--- src/correlation.jl | 2 +- src/gradient.jl | 2 +- test/runtests.jl | 10 +++++----- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/TFI_onefile.jl b/TFI_onefile.jl index 45ed2fd..6bd8f59 100644 --- a/TFI_onefile.jl +++ b/TFI_onefile.jl @@ -73,7 +73,7 @@ end using Test, Random nbit_simulated(qmps) = length(collect_blocks(Measure, qmps)) -function chem2circuit(circuit) +function expand_circuit(circuit) nbit = nbit_simulated(circuit) nm = 1 nv = 1 @@ -117,7 +117,7 @@ train(circuit, model; α=0.5) nbit = hei.length circuit = twoqubit_circuit(2, nbit-1) println("Number of parameters is ", circuit|> nparameters) - bigc = chem2circuit(circuit) + bigc = expand_circuit(circuit) eng = energy(circuit, hei; nbatch=10000) hami = hamiltonian(hei) @show bigc diff --git a/applications.jl b/applications.jl index 8c05259..7f2594d 100644 --- a/applications.jl +++ b/applications.jl @@ -4,7 +4,7 @@ using QMPS using DelimitedFiles, JLD2, FileIO, Pkg # CUDA switch -const USE_CUDA = false #haskey(Pkg.installed(), "CuYao") +const USE_CUDA = haskey(Pkg.installed(), "CuYao") USE_CUDA && println("Hint: Using CUDA since `CuYao` is detected. Edit `applications.jl` file to modify CUDA settings, like switching computing devices.") USE_CUDA && include("CuChem.jl") USE_CUDA && device!(CuDevice(0)) diff --git a/src/Core.jl b/src/Core.jl index 830fc68..fa0f82f 100644 --- a/src/Core.jl +++ b/src/Core.jl @@ -1,4 +1,4 @@ -export getblock, nbit_used, nbit_simulated, nrepeat, chem2circuit, QuantumMPS +export getblock, nbit_used, nbit_simulated, nrepeat, expand_circuit, QuantumMPS export state_exact, fidelity_exact export gensample @@ -29,7 +29,7 @@ nbit_used(chem::QuantumMPS) = nqubits(chem.circuit[1]) nbit_simulated(chem::QuantumMPS) = chem.nbit_measure*nrepeat(chem) + chem.nbit_virtual """convert a chem circuit to a circuit with no reuse""" -function chem2circuit(tnchem) +function expand_circuit(tnchem) nbit = nbit_simulated(tnchem) + tnchem.nbit_ancilla nm = tnchem.nbit_measure nv = tnchem.nbit_virtual + tnchem.nbit_ancilla @@ -41,7 +41,7 @@ function chem2circuit(tnchem) end function state_exact(chem::QuantumMPS) - circuit = chem2circuit(chem) + circuit = expand_circuit(chem) if chem.nbit_ancilla == 0 return product_state(nqubits(circuit), chem.input_state|>packbits) |> circuit else diff --git a/src/correlation.jl b/src/correlation.jl index 4156eb7..75a5ca9 100644 --- a/src/correlation.jl +++ b/src/correlation.jl @@ -54,6 +54,6 @@ function _measure!(reg::AbstractRegister{B, T}, i, sl, input_state, reset) where return @inbounds 1 .- 2 .* (reset ? measure_collapseto!(reg, 1; config=input_state[i+1]) : measure_remove!(reg, 1)) end end - reset ? measure_collapseto!(reg, 1; config=input_state[i+1]) : measure_collapseto!(reg, 1) + reset ? measure_collapseto!(reg, 1; config=input_state[i+1]) : measure_remove!(reg, 1) nothing end diff --git a/src/gradient.jl b/src/gradient.jl index d5e4218..da26600 100644 --- a/src/gradient.jl +++ b/src/gradient.jl @@ -30,7 +30,7 @@ end function gradients_exact(chem, hami; dbs=nothing) nbit = nbit_simulated(chem) - circuit = chem2circuit(chem) + circuit = expand_circuit(chem) if dbs == nothing dbs = collect_blocks(AbstractDiff, circuit) end diff --git a/test/runtests.jl b/test/runtests.jl index ae76ab2..70ae394 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,20 +9,20 @@ using Test, Random @testset "convert wave function check" begin chem = model(:su2; nbit=9, nlayer=2, B=10, V=5, pairs=pair_ring(5)) c = random_circuit(1, 4, 2, 5, pair_ring(5)) - circuit = chem2circuit(chem) + circuit = expand_circuit(chem) @test zero_state(nqubits(circuit)) |> circuit |> statevec |> length == 2^10 end @testset "measure check" begin Random.seed!(5) chem = model(:su2; nbit=9, nlayer=2, B=10000, V=5, pairs=pair_ring(5)) - circuit = chem2circuit(chem) + circuit = expand_circuit(chem) for (i, j) in [(3,5), (5,3), (3,7), (7,3), (6,8), (8,6)] @show (i,j) mean35 = expect(heisenberg_ij(nqubits(circuit), i, j), zero_state(nqubits(circuit)) |> circuit) |> real eng = sum(g->measure_corr(chem, i=>g, j=>g), [X, Y, Z]) - @test isapprox(mean35, eng, rtol=0.3) + @test isapprox(mean35, eng, rtol=0.4) end end @@ -52,7 +52,7 @@ end pairs = pair_ring(xmodel==:su2 ? 4 : 5) chem = model(:general; nbit=nbit, B=10000, V=4, pairs=pairs) println("Number of parameters is ", chem.circuit |> nparameters) - circuit = chem2circuit(chem) + circuit = expand_circuit(chem) eng = energy(chem, hei) hami = hamiltonian(hei) eng_exact = expect(hami, product_state(nbit, chem.input_state |> packbits) |> circuit) |> real @@ -69,7 +69,7 @@ end @show xmodel chem = model(xmodel; nbit=nbit, B=10000) println("Number of parameters is ", chem.circuit |> nparameters) - circuit = chem2circuit(chem) + circuit = expand_circuit(chem) eng = energy(chem, hei) hami = hamiltonian(hei) @show circuit