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

Commit

Permalink
update docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu committed Feb 3, 2019
1 parent ab7ea12 commit 7eb8407
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -44,14 +44,13 @@ $ julia j1j2.jl measure --help
## Documentations

* paper: Variational Quantum Eigensolver with Fewer Qubits ([pdf]()), [arXiv:xxxxxx](https://arxiv.org/abs/xxxxxx), Jin-Guo Liu, Yihong Zhang, Yuan Wan and Lei Wang
* slides: [online]()

## Citation

You are welcome to use this code for your research. Please kindly cite:

```
<arXiv citation>
<arXiv preprint will release soon.>
```

## Authors
Expand Down
10 changes: 9 additions & 1 deletion applications.jl
Expand Up @@ -5,6 +5,7 @@ using DelimitedFiles, JLD2, FileIO, Pkg

# CUDA switch
const USE_CUDA = haskey(Pkg.installed(), "CuYao")
if USE_CUDA && println("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 Expand Up @@ -61,8 +62,15 @@ end

"""
run_train(ansatz, model; SAVE_ID, niter=500, start_point=0, save_step=0)
Run a variational quantum eigensolver to solve a `model` Hamiltonian with MPS inspired `ansatz`
* SAVE_ID, token used for saving data,
* niter, number of training steps,
* start_point, load a save point, default is 0 (random parameters).
* save_step, save the training every `save_step` steps.
"""
function run_train(ansatz, model; SAVE_ID, niter=500, start_point=0, save_step=10)
function run_train(ansatz, model; SAVE_ID, niter::Int=500, start_point::Int=0, save_step::Int=10)
nbit = nbit_simulated(ansatz)
V = ansatz.nbit_virtual
filename(k::Int) = "data/chem_$(SAVE_ID)_N$(nbit)_V$(V)_S$(k).jld2"
Expand Down
15 changes: 15 additions & 0 deletions src/AbstractModel.jl
Expand Up @@ -7,6 +7,8 @@ abstract type AbstractHeisenberg{D} <: AbstractModel{D} end
nspin(model::AbstractModel) = prod(size(model))

"""
energy_exact(tc::QuantumMPS, model::AbstractModel) -> Float64
Exact ground state energy.
"""
function energy_exact(tc::QuantumMPS, model::AbstractModel)
Expand All @@ -15,6 +17,8 @@ function energy_exact(tc::QuantumMPS, model::AbstractModel)
end

"""
energy(chem::QuantumMPS, model::AbstractHeisenberg) -> Float64
Ground state energy by sampling Quantum MPS.
The hamiltonian is limited to Heisenberg and J1J2 Type.
"""
Expand All @@ -31,13 +35,24 @@ function energy(chem::QuantumMPS, pauli::PauliGate, model::AbstractHeisenberg)
eng/4
end

"""
ground_state(model::AbstractModel) -> DefaultRegister
Get the exact ground state of a model.
"""
function ground_state(model::AbstractModel)
# get the ground state
hami = hamiltonian(model)
E, v = eigsolve(mat(hami), 1, :SR)
register(v[1])
end

"""
get_bonds(model::AbstractHeisenberg) -> Vector
Get the weighted bonds of a Heisenberg model in the form Tuple(i,j,w_ij).
"""
function get_bonds end

include("Heisenberg.jl")
include("J1J2.jl")
5 changes: 5 additions & 0 deletions src/J1J2.jl
@@ -1,5 +1,10 @@
export J1J2

"""
J1J2{D} <: AbstractHeisenberg{D}
frustrated Heisenberg model.
"""
struct J1J2{D} <: AbstractHeisenberg{D}
size::NTuple{D, Int}
periodic::Bool
Expand Down
6 changes: 6 additions & 0 deletions src/ansatz/su2_circuit.jl
Expand Up @@ -2,6 +2,11 @@ function su2_unit(nbit::Int, i::Int, j::Int)
put(nbit, (i,j)=>rot(SWAP, 0.0))
end

"""
su2_circuit(nbit_virtual::Int, nlayer::Int, nrepeat::Int, pairs::Vector) -> Sequence
SU(2) symmetry quantum circuit ansatz for evolving states in S^2 = 0 good quantum number block. It requires `2+nbit_virtual` qubits, `pairs` is the geometry of entanglements.
"""
function su2_circuit(nbit_virtual::Int, nlayer::Int, nrepeat::Int, pairs::Vector)
circuit = sequence()
nbit_used = 2 + nbit_virtual
Expand Down Expand Up @@ -30,6 +35,7 @@ function su2_circuit(nbit_virtual::Int, nlayer::Int, nrepeat::Int, pairs::Vector
dispatch!(circuit, :random)
end

"""construct a circuit for generating singlets."""
function singlet_block(nbit::Int, i::Int, j::Int)
unit = chain(nbit)
push!(unit, put(nbit, i=>chain(X, H)))
Expand Down
5 changes: 5 additions & 0 deletions src/ansatz/u1_circuit.jl
Expand Up @@ -5,6 +5,11 @@ function u1_unit(nbit::Int, i::Int, j::Int)
)
end

"""
u1_circuit(nbit_measure::Int, nbit_virtual::Int, nlayer::Int, nrepeat::Int, entangler_pairs) -> Sequence
U(1) symmetric quantum circuit ansatz.
"""
function u1_circuit(nbit_measure::Int, nbit_virtual::Int, nlayer::Int, nrepeat::Int, entangler_pairs)
circuit = sequence()
nbit_used = nbit_measure + nbit_virtual
Expand Down

0 comments on commit 7eb8407

Please sign in to comment.