Skip to content

Commit fc3ccaf

Browse files
committed
fix shor
1 parent 3bdfaf1 commit fc3ccaf

File tree

23 files changed

+67
-20
lines changed

23 files changed

+67
-20
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
77

88
[compat]
99
julia = "1"
10-
Yao = "0.7"
10+
Yao = "0.8"
1111

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

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ Then open directory `.julia/dev/QuAlgorithmZoo/examples` to find algorithms.
2121

2222
In examples folder, you will find
2323

24-
- [Variational Quantum Eigensolver](examples/QSVD)
24+
- [Variational Quantum Eigensolver](examples/VQE)
25+
- [Variational Quantum Eigensolver (with OpenFermion)](examples/VQE_openfermion)
2526
- [Quantum SVD](examples/QSVD)
2627
- [Imaginary Time Evolution Quantum Eigensolver](examples/GroundStateSolvers)
2728
- [HHL algorithm](examples/HHL)
2829
- [QAOA](examples/QAOA)
2930
- [Quantum Circuit Born Machine](examples/QCBM)
30-
- [QuGAN](examples/QuGAN)
31+
- [Quantum GAN](examples/QuGAN)
3132
- [Shor](examples/Shor)
3233
- [Grover search](examples/Grover)
34+
- [Learning a general two qubit unitary gate](examples/GateLearning)
3335

3436
Examples of using Yao in other projects
3537
- [QuODE](https://github.com/QuantumBFS/QuDiffEq.jl)
3638
- [TensorNetwork Inspired Circuits](https://github.com/GiggleLiu/QuantumPEPS.jl)
39+
- [Beta-VQE](https://github.com/wangleiphy/BetaVQE.jl)
40+
- [Quantum Neural Network Classifier](https://github.com/LWKJJONAK/Quantum_Neural_Network_Classifiers)
3741

3842
## License
3943

examples/GateLearning/Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
44
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
55

66
[compat]
7-
Yao = "0.7"
8-
Optim = "1.6"
7+
Yao = "0.8"
8+
Optim = "1.7"

examples/GroundStateSolvers/Project.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
55
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
66

77
[compat]
8-
Yao = "0.7"
8+
Yao = "0.8"
9+
Optimisers = "0.2"

examples/Grover/Project.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[deps]
22
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
33
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
4+
5+
[compat]
6+
Yao = "0.8"

examples/HHL/HHLlib.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Yao.nqudits(cr::HHLCRot) = cr.n
2424
a, -b, b, a
2525
end
2626

27-
function YaoBlocks._apply!(reg::ArrayReg, hr::HHLCRot{NC, T}) where {NC, T}
27+
function YaoBlocks.unsafe_apply!(reg::ArrayReg, hr::HHLCRot{NC, T}) where {NC, T}
2828
mask = bmask(hr.ibit)
2929
step = 1<<(hr.ibit-1)
3030
step_2 = step*2

examples/HHL/Project.toml

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
33
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
44
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
5+
6+
[compat]
7+
Yao = "0.8"

examples/PortZygote/Project.toml

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[deps]
22
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
3+
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
34
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
45
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6+
7+
[compat]
8+
Yao = "0.8"
9+
Optim = "1.7"

examples/QAOA/Project.toml

+6
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
66
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
77
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
88
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
9+
10+
[compat]
11+
Yao = "0.8"
12+
SCS = "1.1"
13+
NLopt = "0.6"
14+
Convex = "0.15"

examples/QAOA/main.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Yao, Yao.BitBasis
33
using NLopt
44

5-
# TODO: switch to GraphTensorNetworks
5+
# TODO: switch to GenericTensorNetworks
66
include("maxcut_gw.jl")
77

88
HB(nbit::Int) = sum([put(nbit, i=>X) for i=1:nbit])

examples/QCBM/Project.toml

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
33
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
44
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
5+
6+
[compat]
7+
Yao = "0.8"
8+
Optimisers = "0.2"

examples/QCBM/main.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pg = gaussian_pdf(1:N, N/2-0.5, N/4);
4040
# Using a random differentiable circuit of depth 6 for training, the kernel function is universal RBF kernel
4141
depth = 6
4242
kernel = rbf_kernel(0.25)
43-
c = variational_circuit(nbit, depth, Yao.EasyBuild.pair_ring(nbit))
43+
c = variational_circuit(Float64, nbit, depth, Yao.EasyBuild.pair_ring(nbit))
4444
dispatch!(c, :random)
4545
qcbm = QCBM(c, MMD(kernel, pg))
4646

examples/QSVD/Project.toml

+4
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
44
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
55
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
66
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
7+
8+
[compat]
9+
Yao = "0.8"
10+
Optimisers = "0.2"

examples/QuGAN/Project.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[deps]
22
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
3+
4+
[compat]
5+
Yao = "0.8"

examples/Shor/Mod.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Mod <: PrimitiveBlock{2}
3030
end
3131
Yao.nqudits(m::Mod) = m.n
3232

33-
function Yao.unsafe_apply!(reg::AbstractArrayReg, m::Mod)
33+
function YaoBlocks.unsafe_apply!(reg::AbstractArrayReg, m::Mod)
3434
nstate = zero(reg.state)
3535
for i in basis(reg)
3636
_i = buffer(i) >= m.L ? buffer(i)+1 : mod(buffer(i)*m.a, m.L)+1
@@ -44,7 +44,7 @@ end
4444

4545
function Yao.mat(::Type{T}, m::Mod) where {T}
4646
perm = Vector{Int}(undef, 1<<m.n)
47-
for i in basis(m.n)
47+
for i in Yao.basis(m.n)
4848
@inbounds perm[i >= m.L ? i+1 : mod(i*m.a, m.L)+1] = i+1
4949
end
5050
PermMatrix(perm, ones(T, 1<<m.n))
@@ -82,11 +82,11 @@ function bint2_reader(T, k::Int)
8282
return b -> (b&mask, b>>k)
8383
end
8484

85-
function Yao.unsafe_apply!(reg::ArrayReg, m::KMod)
85+
function YaoBlocks.unsafe_apply!(reg::ArrayReg, m::KMod)
8686
nstate = zero(reg.state)
8787

8888
reader = bint2_reader(Int, m.k)
89-
for b in basis(reg)
89+
for b in Yao.basis(reg)
9090
k, i = reader(buffer(b))
9191
_i = i >= m.L ? i : mod(i*powermod(m.a, k, m.L), m.L)
9292
_b = k + _i<<m.k + 1
@@ -101,11 +101,11 @@ end
101101
function Yao.mat(::Type{T}, m::KMod) where {T}
102102
perm = Vector{Int}(undef, 1<<m.n)
103103
reader = bint2_reader(Int, m.k)
104-
for b in 0:1<<m.n-1
105-
k, i = reader(b)
104+
for b in Yao.basis(m.n)
105+
k, i = reader(buffer(b))
106106
_i = i >= m.L ? i : mod(i*powermod(m.a, k, m.L), m.L)
107107
_b = k + _i<<m.k + 1
108-
@inbounds perm[_b] = b+1
108+
@inbounds perm[_b] = buffer(b)+1
109109
end
110110
YaoBlocks.LuxurySparse.PermMatrix(perm, ones(T, 1<<m.n))
111111
end

examples/Shor/Project.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[deps]
22
BitBasis = "50ba71b6-fa0f-514d-ae9a-0916efc90dcf"
33
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
4+
5+
[compat]
6+
Yao = "0.8"

examples/Shor/main.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function shor(L::Int, ver=Val(:quantum); maxtry=100)
3030
x = NumberTheory.rand_primeto(L)
3131

3232
## step 2
33-
r = get_order(ver, x, L; )
33+
r = get_order(ver, x, L)
3434
if r%2 == 0 && powermod(x, r÷2, L) != L-1
3535
## step 3
3636
f1, f2 = gcd(powermod(x, r÷2, L)-1, L), gcd(powermod(x, r÷2, L)+1, L)
@@ -125,4 +125,4 @@ end
125125
# ## Run
126126
# Factorizing `15`, you should see `3` or `5`, please report a bug if it is not...
127127
using Random; Random.seed!(129) #src
128-
shor(15, Val(:quantum))
128+
println("Factoring 15 gives: ", shor(15, Val(:quantum)))

examples/VQE/Project.toml

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
33
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
44
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
5+
6+
[compat]
7+
Yao = "0.8"
8+
Optimisers = "0.2"
9+
KrylovKit = "0.5"

examples/VQE_openfermion/Project.toml

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
33
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
44
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
55
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
6+
7+
[compat]
8+
Yao = "0.8"
9+
PyCall = "1"
10+
Plots = "1"
11+
Flux = "0.13"

examples/_StructureOpt/Bag.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Including `mat`, `apply!`, `ishermitian`, `isreflexive`, `isunitary`,
99
abstract type AbstractBag{BT, D}<:TagBlock{BT, D} end
1010

1111
Yao.mat(::Type{T}, bag::AbstractBag) where {T} = mat(T, content(bag))
12-
_apply!(reg::AbstractRegister, bag::AbstractBag) = _apply!(reg, content(bag))
12+
YaoBlocks.unasfe_apply!(reg::AbstractRegister, bag::AbstractBag) = unasfe_apply!(reg, content(bag))
1313
Yao.ishermitian(bag::AbstractBag) = ishermitian(content(bag))
1414
Yao.isreflexive(bag::AbstractBag) = isreflexive(content(bag))
1515
Yao.isunitary(bag::AbstractBag) = isunitary(content(bag))

examples/run_examples.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ do
66
echo "executing example: $folder"
77
julia --project=$folder -e "using Pkg; Pkg.instantiate()"
88
julia --project=$folder "$folder/main.jl"
9-
done
9+
done

0 commit comments

Comments
 (0)