{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e47f1fd3-c09d-43cb-80c8-64f42e8161a4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10000" ] }, "execution_count": 1, "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", "\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 = .01\n", "noise = ClassicalNoise(T);\n", "\n", "s0 = [0, 1, 0]\n", "J0 = 1.\n", "JH = Nchain(1, J0)\n", "\n", "nruns = 10000" ] }, { "cell_type": "code", "execution_count": 2, "id": "6e3cdf02-c243-4622-a52a-a6d7f987c68d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Starting...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" ] } ], "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\n", "\n", "solavg_ohm = mean(sols_ohm, dims=1)[1, :, :];\n", "solstd_ohm = std(sols_ohm, dims=1)[1, :, :];" ] }, { "cell_type": "code", "execution_count": 3, "id": "3422af78-2f32-468c-a8a3-a0732a836fd1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Starting...\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\n", "\n", "solavg_col = mean(sols_col, dims=1)[1, :, :];\n", "solstd_col = std(sols_col, dims=1)[1, :, :];" ] }, { "cell_type": "code", "execution_count": 24, "id": "d16b97dd-b9f5-415c-b388-2b1f3344be45", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(saveat, solstd_ohm[:, 1])\n", "plot!(saveat, solstd_ohm[:, 2])" ] }, { "cell_type": "code", "execution_count": 25, "id": "a06addc4-47b2-4467-8148-3e68f3eae702", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(saveat, solstd_col[:, 1])\n", "plot!(saveat, solstd_col[:, 2])" ] }, { "cell_type": "code", "execution_count": 6, "id": "bc1686fd-d86d-42b0-9d87-bcb911526d00", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(saveat, solavg_ohm[:, 3])\n", "plot!(saveat, solavg_col[:, 3])" ] }, { "cell_type": "code", "execution_count": 7, "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": 8, "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": 9, "id": "e4ad51fc-0dc7-4106-99e4-2b29e54b1930", "metadata": {}, "outputs": [], "source": [ "using HypothesisTests\n", "using LaTeXStrings" ] }, { "cell_type": "code", "execution_count": 10, "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": 11, "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": 12, "id": "6c63a170-6eff-4c8b-8b80-542eb705666f", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 12, "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, 200))\n", "plot!(saveat, JB_col, label=\"Non-Ohmic\", linewidth=2)" ] }, { "cell_type": "code", "execution_count": 13, "id": "ad2674ba-9711-4feb-96ab-a39d88b27ce5", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 13, "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)" ] }, { "cell_type": "code", "execution_count": 14, "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.010024181624728401 and 2.9355563110404956\"\n", "\n", "Test summary:\n", " outcome with 95% confidence: fail to reject h_0\n", " one-sided p-value: 0.3872\n", "\n", "Details:\n", " number of observations: 10000\n", " JB statistic: 1.89789\n" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HypothesisTests.JarqueBeraTest(projected_col[:, 125, 1])" ] }, { "cell_type": "code", "execution_count": null, "id": "48b2963f-d070-46c9-a077-fe4aad09155a", "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 }