Skip to content

Commit 0e0ea4e

Browse files
committed
update QCGAN, new QuGAN
1 parent 736f9a7 commit 0e0ea4e

29 files changed

+697
-534
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1112
Yao = "5a1af4f6-c801-11e8-08ea-1bad16a356b2"
1213

1314
[extras]

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: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1+
# # Grover Search
12
using Yao
2-
using QuAlgorithmZoo: groveriter!, inference_oracle, prob_match_oracle
3+
using LinearAlgebra
4+
using QuAlgorithmZoo: groveriter, inference_oracle, prob_match_oracle
35

6+
# ## Target Space and Evidense
47
num_bit = 12
5-
oracle(reg::DefaultRegister) = (reg.state[100:101,:]*=-1; reg)
6-
target_state = zeros(1<<num_bit); target_state[100:101] = sqrt(0.5)
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)
710

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
815
# then solve the above problem
9-
it = groveriter!(uniform_state(num_bit), oracle)
16+
it = groveriter(uniform_state(num_bit), oracle)
1017
for (i, psi) in enumerate(it)
1118
overlap = abs(statevec(psi)'*target_state)
1219
println("step $(i-1), overlap = $overlap")
1320
end
1421

22+
# ## Inference Example
1523
# we have a state psi0, we know how to prepair it
1624
psi = rand_state(num_bit)
1725

18-
# now we want to search the subspace with [1,3,5,8,9,11,12] fixed to 1 and [4,6] fixed to 0.
19-
evidense = [1, 3, -4, 5, -6, 8, 9, 11, 12]
20-
2126
"""
2227
Doing Inference, psi is the initial state, we want to search target space with specific evidense.
2328
e.g. evidense [1, -3, 6] means the [1, 3, 6]-th bits take value [1, 0, 1].
2429
"""
2530
oracle_infer = inference_oracle(evidense)(nqubits(psi))
26-
it = groveriter!(psi, oracle_infer)
31+
it = groveriter(psi, oracle_infer)
2732
for (i, psi) in enumerate(it)
2833
p_target = prob_match_oracle(psi, oracle_infer)
2934
println("step $(i-1), overlap^2 = $p_target")

0 commit comments

Comments
 (0)