Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

Commit

Permalink
update for Yao 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu committed Apr 29, 2019
1 parent 41a802c commit 28f3506
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions TFI_onefile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion applications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions src/Core.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/correlation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/gradient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 28f3506

Please sign in to comment.