Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,287 changes: 674 additions & 613 deletions examples/qaoa_example.ipynb

Large diffs are not rendered by default.

43 changes: 20 additions & 23 deletions examples/training_example1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"metadata": {},
"outputs": [],
"source": [
"using Qaintessent\n",
"using Qaintellect\n",
"using LinearAlgebra\n",
"using Flux\n",
Expand Down Expand Up @@ -57,14 +58,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"rx = RxGate([0.2852979630949063])\n",
"ry = RyGate([5.897114323717471])\n"
"rx = RxGate(Float32[0.2345506])\n",
"ry = RyGate(Float32[4.734649])\n"
]
},
{
"data": {
"text/plain": [
"RyGate([5.897114323717471])"
"RyGate(Float32[4.734649])"
]
},
"execution_count": 2,
Expand Down Expand Up @@ -132,15 +133,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
"ψ = Complex{Float64}[1.0 + 0.0im, 0.0 + 0.0im]\n"
"ψ = ComplexF32[1.0f0 + 0.0f0im, 0.0f0 + 0.0f0im]\n"
]
},
{
"data": {
"text/plain": [
"2-element Array{Complex{Float64},1}:\n",
" 1.0 + 0.0im\n",
" 0.0 + 0.0im"
"2-element Vector{ComplexF32}:\n",
" 1.0f0 + 0.0f0im\n",
" 0.0f0 + 0.0f0im"
]
},
"execution_count": 4,
Expand All @@ -149,7 +150,7 @@
}
],
"source": [
"ψ = ComplexF64[1, 0]\n",
"ψ = ComplexQ[1, 0]\n",
"e = -1\n",
"@show(ψ)"
]
Expand All @@ -170,9 +171,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"paras = Params([[0.2852979630949063], [5.897114323717471], \n",
" [1, 1] = 1.0+0.0im\n",
" [2, 2] = -1.0+0.0im])\n"
"paras = Params([Float32[0.2345506], Float32[4.734649], sparse([1, 2], [1, 2], ComplexF32[1.0f0 + 0.0f0im, -1.0f0 + 0.0f0im], 2, 2)])\n"
]
},
{
Expand All @@ -188,7 +187,7 @@
],
"source": [
"# create loss function: note that circuit `c` is applied to `x`\n",
"loss(x, y) = Flux.mse(c(x), y)\n",
"loss(x, y) = Flux.mse(apply(x, c), y)\n",
"\n",
"# gather parameters from Circuit\n",
"paras = Flux.params(c)\n",
Expand All @@ -212,8 +211,8 @@
{
"data": {
"text/plain": [
"1-element Array{Float64,1}:\n",
" 1.3650695278938842"
"1-element Vector{Float32}:\n",
" 1.9868569"
]
},
"execution_count": 6,
Expand Down Expand Up @@ -243,7 +242,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"loss(ψ, e) = 2.094566636677492\n"
"loss(ψ, e) = 0.4340008f0\n"
]
}
],
Expand All @@ -259,9 +258,7 @@
{
"data": {
"text/plain": [
"Params([[-0.06611831314621944], [3.1552160317265447], \n",
" [1, 1] = 1.0+0.0im\n",
" [2, 2] = -1.0+0.0im])"
"Params([Float32[0.00041586455], Float32[3.1005328], sparse([1, 2], [1, 2], ComplexF32[1.0f0 + 0.0f0im, -1.0f0 + 0.0f0im], 2, 2)])"
]
},
"execution_count": 8,
Expand Down Expand Up @@ -289,8 +286,8 @@
{
"data": {
"text/plain": [
"1-element Array{Float64,1}:\n",
" -0.9977223864977636"
"1-element Vector{Float32}:\n",
" -0.9991572"
]
},
"execution_count": 9,
Expand All @@ -305,15 +302,15 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.5.4",
"display_name": "Julia 1.7.0",
"language": "julia",
"name": "julia-1.5"
"name": "julia-1.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.5.4"
"version": "1.7.0"
}
},
"nbformat": 4,
Expand Down
136 changes: 17 additions & 119 deletions examples/training_example2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,9 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[?25l\u001b[2K"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m git-repo `https://github.com/Qaintum/Qaintessent.jl`\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[?25h"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m registry at `~/.julia/registries/General`\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[?25l\u001b[2K"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m git-repo `https://github.com/JuliaRegistries/General.git`\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[?25h"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"┌ Warning: Some registries failed to update:\n",
"│ — /home/ga53vuw/.julia/registries/General — failed to fetch from repo\n",
"└ @ Pkg.Types /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Pkg/src/Types.jl:1194\n",
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
"\u001b[32m\u001b[1mNo Changes\u001b[22m\u001b[39m to `/import/home/ga53vuw/Documents/PhD/projects/QAI/Qaintellect.jl/Project.toml`\n",
"\u001b[32m\u001b[1mNo Changes\u001b[22m\u001b[39m to `/import/home/ga53vuw/Documents/PhD/projects/QAI/Qaintellect.jl/Manifest.toml`\n"
]
}
],
"outputs": [],
"source": [
"using Pkg; Pkg.add(url=\"https://github.com/Qaintum/Qaintessent.jl\");\n",
"using Qaintessent\n",
"using Qaintellect\n",
"using LinearAlgebra\n",
"using Flux\n",
Expand All @@ -100,7 +38,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"rg = RotationGate([-0.3770941769323742, -0.18191239085016125, -0.4684997756909257])\n"
"rg = RotationGate(Float32[-0.53703034, 0.05597703, -0.3213241])\n"
]
},
{
Expand All @@ -127,7 +65,7 @@
"N = 4\n",
"\n",
"ry = RyGate(√2)\n",
"n = randn(Float64, 3)\n",
"n = randn(FloatQ, 3)\n",
"n /= norm(n)\n",
"rg = RotationGate(0.2π, n)\n",
"@show(rg)\n",
Expand All @@ -153,49 +91,7 @@
{
"data": {
"text/plain": [
"Params([[4.71238898038469], [0.3], [-0.3770941769323742, -0.18191239085016125, -0.4684997756909257], \n",
" [1 , 1] = 1.0+0.0im\n",
" [2 , 2] = 1.0+0.0im\n",
" [3 , 3] = 1.0+0.0im\n",
" [4 , 4] = 1.0+0.0im\n",
" [5 , 5] = 1.0+0.0im\n",
" [6 , 6] = 1.0+0.0im\n",
" [7 , 7] = 1.0+0.0im\n",
" [8 , 8] = 1.0+0.0im\n",
" [9 , 9] = 1.0+0.0im\n",
" [10, 10] = 1.0+0.0im\n",
" [11, 11] = 1.0+0.0im\n",
" [12, 12] = 1.0+0.0im\n",
" [13, 13] = 1.0+0.0im\n",
" [14, 14] = 1.0+0.0im\n",
" [15, 15] = 1.0+0.0im\n",
" [16, 16] = 1.0+0.0im, \n",
" [1 , 1] = 0.412232+0.0im\n",
" [2 , 1] = 1.12021-0.256048im\n",
" [3 , 1] = 0.302475+0.717748im\n",
" [4 , 1] = -2.45391-0.991839im\n",
" [5 , 1] = -0.84334+0.657044im\n",
" [6 , 1] = -0.843339+0.632229im\n",
" [7 , 1] = -1.27159+1.11835im\n",
" [8 , 1] = -0.360019-0.698453im\n",
" [9 , 1] = -1.21463-0.462286im\n",
" [10, 1] = 0.246136+0.40925im\n",
" [11, 1] = 0.614472+0.0312881im\n",
" [12, 1] = -0.301658+0.415073im\n",
" ⋮\n",
" [4 , 16] = -0.282751-1.06899im\n",
" [5 , 16] = -1.55817+1.4844im\n",
" [6 , 16] = 0.24081-0.161829im\n",
" [7 , 16] = -0.475453-0.114766im\n",
" [8 , 16] = 0.233323+0.248452im\n",
" [9 , 16] = -0.303145+0.68772im\n",
" [10, 16] = -1.31163-0.0208782im\n",
" [11, 16] = -0.145369-0.0330198im\n",
" [12, 16] = -1.20301-0.620426im\n",
" [13, 16] = 0.446624+1.19501im\n",
" [14, 16] = -1.15907+0.118706im\n",
" [15, 16] = 1.05218-0.523801im\n",
" [16, 16] = 1.56749+0.0im])"
"Params([Float32[4.712389], Float32[0.3], Float32[-0.53703034, 0.05597703, -0.3213241], sparse([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], ComplexF32[1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im, 1.0f0 + 0.0f0im], 16, 16), sparse([1, 2, 3, 4, 5, 6, 7, 8, 9, 10 … 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1 … 16, 16, 16, 16, 16, 16, 16, 16, 16, 16], ComplexF32[-1.4366738f0 + 0.0f0im, 0.03560376f0 - 0.6054848f0im, -0.527578f0 - 0.27173388f0im, -1.3991385f0 - 1.1131895f0im, -1.1278617f0 - 0.37390763f0im, 0.75828916f0 - 0.37697834f0im, -0.17399871f0 + 0.68030006f0im, -0.9440648f0 - 0.098141216f0im, 0.24595958f0 + 0.6661913f0im, -0.4319537f0 - 0.27240527f0im … 1.8054765f0 + 0.6945263f0im, 0.7939487f0 - 0.21607582f0im, 0.027468143f0 + 0.08795561f0im, 0.9270779f0 + 0.29685333f0im, -0.1285605f0 - 0.32457453f0im, 0.6224388f0 + 0.89071685f0im, 0.1555624f0 - 0.021069005f0im, -0.5535621f0 + 0.8260739f0im, -0.20685427f0 - 1.1576917f0im, -0.72568375f0 + 0.0f0im], 16, 16)])"
]
},
"execution_count": 3,
Expand Down Expand Up @@ -228,16 +124,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Initial model evaluation: -0.6411689764188402, target: 0.65\n",
"loss(ψ, e) = 3.2547793683377075\n",
"loss(ψ, e) = 7.703719777548943e-30\n",
"Final model evaluation: 0.6500000000000004, target: 0.65\n"
"Initial model evaluation: -0.5137484192848205, target: 0.65\n",
"loss(ψ, e) = 4.427609752931719\n",
"loss(ψ, e) = 1.1252841773625583e-5\n",
"loss(ψ, e) = 1.1828014123388259e-11\n",
"loss(ψ, e) = 2.1850610211407502e-12\n",
"Final model evaluation: 0.6499985218048095, target: 0.65\n"
]
}
],
"source": [
"# input quantum state\n",
"ψ = randn(ComplexF64, 2^N)\n",
"ψ = randn(ComplexQ, 2^N)\n",
"ψ /= norm(ψ)\n",
"\n",
"# desired output\n",
Expand Down Expand Up @@ -268,8 +166,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"ry = RyGate([1.4142135623730951])\n",
"rg = RotationGate([2.2792445765601532, 14.620422188462491, 4.557172204234055])\n"
"ry = RyGate(Float32[1.4142135])\n",
"rg = RotationGate(Float32[2.4036388, -1.0326958, -0.18446656])\n"
]
}
],
Expand All @@ -284,15 +182,15 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.5.3",
"display_name": "Julia 1.7.0",
"language": "julia",
"name": "julia-1.5"
"name": "julia-1.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.5.3"
"version": "1.7.0"
}
},
"nbformat": 4,
Expand Down
Loading