{
"cells": [
{
"cell_type": "code",
"execution_count": 39,
"id": "e47f1fd3-c09d-43cb-80c8-64f42e8161a4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10000"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using SpiDy\n",
"using NPZ\n",
"using DataFrames\n",
"using CSV\n",
"using ProgressMeter\n",
"using Random\n",
"using Statistics\n",
"using LinearAlgebra\n",
"using Plots\n",
"using HypothesisTests\n",
"using LaTeXStrings\n",
"\n",
"########################\n",
"########################\n",
"\n",
"Δt = .2\n",
"N = 1000\n",
"tspan = (0., N*Δt)\n",
"saveat = (0:1:N)*Δt\n",
"\n",
"matrix = IsoCoupling(1)\n",
"\n",
"T = .2\n",
"noise = ClassicalNoise(T);\n",
"\n",
"theta = pi * 1/4\n",
"\n",
"s0 = [0, 1, cos(theta)]\n",
"s0 = s0 ./ norm(s0)\n",
"\n",
"J0 = 1.\n",
"JH = Nchain(1, J0)\n",
"\n",
"nruns = 10000"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "6e3cdf02-c243-4622-a52a-a6d7f987c68d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32mProgress: 100%|█████████████████████████████████████████| Time: 0:00:55\u001b[39m\n"
]
}
],
"source": [
"α = 10. # 0.16\n",
"ω0 = 7. # 1.4\n",
"Γ = 5. # 0.5\n",
"\n",
"J = LorentzianSD(α, ω0, Γ) # coloring the noise\n",
"\n",
"println(\"Starting...\")\n",
"progress = Progress(nruns);\n",
"\n",
"sols_ohm = zeros(nruns, length(saveat), 3)\n",
"\n",
"Threads.@threads for i in 1:nruns\n",
" bfields = [bfield(N, Δt, J, noise),\n",
" bfield(N, Δt, J, noise),\n",
" bfield(N, Δt, J, noise)];\n",
" sol = diffeqsolver(s0, tspan, J, bfields, matrix; JH=JH, saveat=saveat);\n",
" sols_ohm[i, :, :] = transpose(sol[:, :])\n",
" next!(progress)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "a4e3af5e-2db7-4f18-b9e2-113c9091afe6",
"metadata": {},
"outputs": [],
"source": [
"solavg_ohm = mean(sols_ohm, dims=1)[1, :, :];\n",
"solstd_ohm = std(sols_ohm, dims=1)[1, :, :];\n",
"\n",
"velavg_ohm = solavg_ohm[2:N, :] .- solavg_ohm[1:N-1, :];"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "adcc1f01-a10b-4727-9766-72f003e7044a",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(saveat[2:N], velavg_ohm[:, 3])"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "3422af78-2f32-468c-a8a3-a0732a836fd1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32mProgress: 100%|█████████████████████████████████████████| Time: 0:00:26\u001b[39m\n"
]
}
],
"source": [
"α = 0.16\n",
"ω0 = 1.4\n",
"Γ = 0.5\n",
"\n",
"J = LorentzianSD(α, ω0, Γ) # coloring the noise\n",
"\n",
"println(\"Starting...\")\n",
"progress = Progress(nruns);\n",
"\n",
"sols_col = zeros(nruns, length(saveat), 3)\n",
"\n",
"Threads.@threads for i in 1:nruns\n",
" bfields = [bfield(N, Δt, J, noise),\n",
" bfield(N, Δt, J, noise),\n",
" bfield(N, Δt, J, noise)];\n",
" sol = diffeqsolver(s0, tspan, J, bfields, matrix; JH=JH, saveat=saveat);\n",
" sols_col[i, :, :] = transpose(sol[:, :])\n",
" next!(progress)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "fbae64d8-54f9-4c81-868f-91ac450cca74",
"metadata": {},
"outputs": [],
"source": [
"solavg_col = mean(sols_col, dims=1)[1, :, :];\n",
"solstd_col = std(sols_col, dims=1)[1, :, :];\n",
"\n",
"velavg_col = solavg_col[2:N, :] .- solavg_col[1:N-1, :];"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "2540ee8c-7f89-4a3c-82fd-22a0a9e08cc0",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(saveat[1:200], velavg_col[1:200, 3])\n",
"\n",
"axis = twinx()\n",
"plot!(axis, saveat[1:200], solavg_col[1:200, 3], label=L\"s_z\", ls=:dash)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "d16b97dd-b9f5-415c-b388-2b1f3344be45",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(saveat, solstd_col[:, 1], label=L\"\\Delta s_x\")\n",
"plot!(saveat, solstd_col[:, 2], label=L\"\\Delta s_y\")\n",
"\n",
"axis = twinx()\n",
"plot!(axis, saveat, solavg_col[:, 3], label=L\"s_z\", ls=:dash)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "a06addc4-47b2-4467-8148-3e68f3eae702",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(saveat, solstd_col[:, 1])\n",
"plot!(saveat, solstd_col[:, 2])"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "bc1686fd-d86d-42b0-9d87-bcb911526d00",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(saveat, solavg_ohm[:, 3])\n",
"plot!(saveat, solavg_col[:, 3])"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "59ac92d9-6a78-402b-91ae-3f5fd22cc6ff",
"metadata": {},
"outputs": [],
"source": [
"projected_ohm = zeros(nruns, length(saveat), 2)\n",
"\n",
"normalized_avg = [normalize(vec(row)) for row in eachrow(solavg_ohm)]\n",
"\n",
"Threads.@threads for i in 1:length(saveat)\n",
" n = normalized_avg[i, :][1]\n",
"\n",
" u = normalize(cross(n, [0,0,1]))\n",
" v = cross(u, n)\n",
"\n",
" for j in 1:nruns\n",
" b = sols_ohm[j, i, :]\n",
" proj = dot(b, n) * n\n",
" b_ort = b - proj\n",
"\n",
" projected_ohm[j, i, 1] = dot(u,b)\n",
" projected_ohm[j, i, 2] = dot(v,b)\n",
" end\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "f1661b24-42b1-4f59-989a-54dc3ed03bf8",
"metadata": {},
"outputs": [],
"source": [
"projected_col = zeros(nruns, length(saveat), 2)\n",
"\n",
"normalized_avg = [normalize(vec(row)) for row in eachrow(solavg_col)]\n",
"\n",
"Threads.@threads for i in 1:length(saveat)\n",
" n = normalized_avg[i, :][1]\n",
"\n",
" u = normalize(cross(n, [0,0,1]))\n",
" v = cross(u, n)\n",
"\n",
" for j in 1:nruns\n",
" b = sols_col[j, i, :]\n",
" proj = dot(b, n) * n\n",
" b_ort = b - proj\n",
"\n",
" projected_col[j, i, 1] = dot(u,b)\n",
" projected_col[j, i, 2] = dot(v,b)\n",
" end\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "e5b9609e-f467-4bd7-9b51-9a4c1f175738",
"metadata": {},
"outputs": [],
"source": [
"JB_ohm = zeros(N)\n",
"for i in 1:N\n",
" JB_ohm[i] = HypothesisTests.JarqueBeraTest(projected_ohm[:, i, 1]).JB\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "51ccaeb8-2b3d-4630-afc3-2640142c4d54",
"metadata": {},
"outputs": [],
"source": [
"JB_col = zeros(N)\n",
"for i in 1:N\n",
" JB_col[i] = HypothesisTests.JarqueBeraTest(projected_col[:, i, 1]).JB\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "6c63a170-6eff-4c8b-8b80-542eb705666f",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(saveat, JB_ohm, title=\"JB Test for Ohmic and Non-Ohmic Coupling\", label=\"Ohmic\", linewidth=2, xlabel=\"Time\", ylabel=\"JB Test\", legend=:topleft, ylimits=(0, 400))\n",
"plot!(saveat, JB_col, label=\"Non-Ohmic\", linewidth=2)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "ad2674ba-9711-4feb-96ab-a39d88b27ce5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"/work/benstem/SpiDySims/runs/45.png\""
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"right_axis = twinx()\n",
"\n",
"plot!(right_axis, saveat, solavg_ohm[:, 3], label=\"Ohmic\", ls=:dash, ylabel=L\"S_z\", ylimits=(-1.5, 1.5))\n",
"plot!(right_axis, saveat, solavg_col[:, 3], label=\"Non-Ohmic\", ls=:dash)\n",
"\n",
"savefig(\"./45.png\")"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "a1c77edf-652b-42ea-8bc0-445749a22a2c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Jarque-Bera normality test\n",
"--------------------------\n",
"Population details:\n",
" parameter of interest: skewness and kurtosis\n",
" value under h_0: \"0 and 3\"\n",
" point estimate: \"-0.1670969424751246 and 2.352471247359044\"\n",
"\n",
"Test summary:\n",
" outcome with 95% confidence: reject h_0\n",
" one-sided p-value: <1e-48\n",
"\n",
"Details:\n",
" number of observations: 10000\n",
" JB statistic: 221.241\n"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"HypothesisTests.JarqueBeraTest(projected_col[:, 125, 1])"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "48b2963f-d070-46c9-a077-fe4aad09155a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(10000, 1001, 2)"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"size(projected_ohm)"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "74f52e41-7867-40da-8acb-8fff6df32a5c",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"histogram2d(projected_ohm[:, 250, 1], projected_ohm[:, 250, 2], bins=50)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "24f34aa7-c00d-444b-9fcb-f11ddcbdee43",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"histogram2d(projected_col[:, 250, 1], projected_col[:, 250, 2], bins=50)"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "b26e685a-eeb4-47d1-aeb9-2e9d2275f5e8",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[36m\u001b[1m[ \u001b[22m\u001b[39m\u001b[36m\u001b[1mInfo: \u001b[22m\u001b[39mSaved animation to /work/benstem/SpiDySims/runs/45_hist_ohm.gif\n"
]
},
{
"data": {
"text/html": [
"
"
],
"text/plain": [
"Plots.AnimatedGif(\"/work/benstem/SpiDySims/runs/45_hist_ohm.gif\")"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Function to create a single histogram plot\n",
"function plot_histogram(i)\n",
" histogram2d(projected_ohm[:, i, 1], projected_ohm[:, i, 2], nbins=50, xlims=(-1, 1), ylims=(-1, 1), title=\"Time: $(i/5)\")\n",
"end\n",
"\n",
"# Create the animation\n",
"anim = @animate for i in 1:200\n",
" plot_histogram(i)\n",
"end\n",
"\n",
"# Save the animation as a gif\n",
"gif(anim, \"45_hist_ohm.gif\", fps=10)\n"
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "c5c2e13f-3a0a-41b9-b066-84c0f95dd04f",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[36m\u001b[1m[ \u001b[22m\u001b[39m\u001b[36m\u001b[1mInfo: \u001b[22m\u001b[39mSaved animation to /work/benstem/SpiDySims/runs/45_hist_col.gif\n"
]
},
{
"data": {
"text/html": [
"
"
],
"text/plain": [
"Plots.AnimatedGif(\"/work/benstem/SpiDySims/runs/45_hist_col.gif\")"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Function to create a single histogram plot\n",
"function plot_histogram(i)\n",
" histogram2d(projected_col[:, i, 1], projected_col[:, i, 2], nbins=50, xlims=(-1, 1), ylims=(-1, 1), title=\"Time: $(i/5)\")\n",
"end\n",
"\n",
"# Create the animation\n",
"anim = @animate for i in 1:100\n",
" plot_histogram(i)\n",
"end\n",
"\n",
"# Save the animation as a gif\n",
"gif(anim, \"45_hist_col.gif\", fps=10)"
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "cd4c4953-57ec-44dd-9f4c-07faff6726f2",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(saveat[1:200], solavg_col[1:200, 1])\n",
"plot!(twinx(), saveat[1:200], solavg_col[1:200, 3])"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "a7183f4c-b998-4df1-8be4-ba687e837074",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot_histogram(400)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cff3a62d-8ffe-4e55-867b-03a79059c05f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.7.3",
"language": "julia",
"name": "julia-1.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}