Skip to content

Commit e6be71d

Browse files
authored
Phase estimation and HHL algorithm (#2)
* new HHL * fix example for v0.3 compacity * update QCGAN, new QuGAN * new hamiltonian solvers
1 parent d104cba commit e6be71d

32 files changed

+1109
-489
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99
LuxurySparse = "d05aeea4-b7d4-55ac-b691-9e7fabb07ba2"
1010
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
11-
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
11+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
12+
Yao = "5a1af4f6-c801-11e8-08ea-1bad16a356b2"
1213

1314
[extras]
1415
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

docs/make.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ makedocs(
4242
pages = [
4343
"Home" => "index.md",
4444
"Tutorial" => TUTORIALS,
45+
"Manual" => Any[
46+
"man/zoo.md",
47+
],
4548
],
4649
html_prettyurls = !("local" in ARGS),
4750
html_canonical = "https://quantumbfs.github.io/QuAlgorithmZoo.jl/latest/",

docs/src/index.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,21 @@ CurrentModule = QuAlgorithmZoo
55
# Quantum Algorithm Zoo
66

77
A curated implementation of quantum algorithms with [Yao.jl](https://github.com/QuantumBFS/Yao.jl)
8+
9+
## Tutorial
10+
```@contents
11+
Pages = [
12+
"tutorial/Grover.md",
13+
"tutorial/QCBM.md",
14+
"tutorial/QuGAN.md",
15+
]
16+
Depth = 1
17+
```
18+
19+
## Manual
20+
```@contents
21+
Pages = [
22+
"man/zoo.md",
23+
]
24+
Depth = 1
25+
```

docs/src/man/zoo.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# QuAlgorithmZoo
2+
3+
```@autodocs
4+
Modules = [QuAlgorithmZoo]
5+
Order = [:module, :constant, :type, :macro, :function]
6+
```

examples/Grover.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# # Grover Search
2+
using Yao
3+
using LinearAlgebra
4+
using QuAlgorithmZoo: groveriter, inference_oracle, prob_match_oracle
5+
6+
# ## Target Space and Evidense
7+
num_bit = 12
8+
oracle = matrixgate(Diagonal((v = ones(1<<num_bit); v[100:101]*=-1; v)))
9+
target_state = zeros(1<<num_bit); target_state[100:101] .= sqrt(0.5)
10+
11+
# now we want to search the subspace with [1,3,5,8,9,11,12] fixed to 1 and [4,6] fixed to 0.
12+
evidense = [1, 3, -4, 5, -6, 8, 9, 11, 12]
13+
14+
# ## Search
15+
# then solve the above problem
16+
it = groveriter(uniform_state(num_bit), oracle)
17+
for (i, psi) in enumerate(it)
18+
overlap = abs(statevec(psi)'*target_state)
19+
println("step $(i-1), overlap = $overlap")
20+
end
21+
22+
# ## Inference Example
23+
# we have a state psi0, we know how to prepair it
24+
psi = rand_state(num_bit)
25+
26+
"""
27+
Doing Inference, psi is the initial state, we want to search target space with specific evidense.
28+
e.g. evidense [1, -3, 6] means the [1, 3, 6]-th bits take value [1, 0, 1].
29+
"""
30+
oracle_infer = inference_oracle(evidense)(nqubits(psi))
31+
it = groveriter(psi, oracle_infer)
32+
for (i, psi) in enumerate(it)
33+
p_target = prob_match_oracle(psi, oracle_infer)
34+
println("step $(i-1), overlap^2 = $p_target")
35+
end

0 commit comments

Comments
 (0)