mirror of
https://github.com/vale981/master-thesis
synced 2025-03-10 05:06:38 -04:00
235 lines
11 KiB
Org Mode
235 lines
11 KiB
Org Mode
#+PROPERTY: header-args :session billohops :kernel python :pandoc t
|
||
|
||
* Setup
|
||
#+begin_src jupyter-python
|
||
%load_ext autoreload
|
||
%autoreload 2
|
||
%load_ext jupyter_spaces
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
: The autoreload extension is already loaded. To reload it, use:
|
||
: %reload_ext autoreload
|
||
: The jupyter_spaces extension is already loaded. To reload it, use:
|
||
: %reload_ext jupyter_spaces
|
||
|
||
#+begin_src jupyter-python
|
||
import hops
|
||
import stocproc as sp
|
||
import numpy as np
|
||
import matplotlib.pyplot as plt
|
||
import scipy
|
||
plt.style.use('ggplot')
|
||
from IPython.display import set_matplotlib_formats
|
||
set_matplotlib_formats('pdf', 'svg')
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
: <ipython-input-87-e225c2f5410d>:8: DeprecationWarning: `set_matplotlib_formats` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.set_matplotlib_formats()`
|
||
: set_matplotlib_formats('pdf', 'svg')
|
||
|
||
* Auxiliary Definitions
|
||
#+begin_src jupyter-python
|
||
σ1 = np.matrix([[0,1],[1,0]])
|
||
σ2 = np.matrix([[0,-1j],[1j,0]])
|
||
σ3 = np.matrix([[1,0],[0,-1]])
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
|
||
* Model
|
||
Let's set up the basic parameters.
|
||
#+begin_src jupyter-python
|
||
γ = .1 # coupling ratio
|
||
ω_c = 1 # center of spect. dens
|
||
δ = 1 # breadth BCF
|
||
W = -ω_c * 1j - δ # exponent BCF
|
||
τ_max = 10 # the maximal simulation time
|
||
seed = 1 # seed for all pseudo random generators
|
||
H_s = σ3
|
||
L = 1/2 * (σ1 - 1j * σ2) * γ
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
|
||
And for fun: the BCF and the spectral density.
|
||
#+begin_src jupyter-python
|
||
def α(τ):
|
||
return np.sqrt(δ) * np.exp(-1j * ω_c * τ - np.abs(τ) * δ)
|
||
|
||
def I(ω):
|
||
return np.sqrt(δ) / (δ + (ω - ω_c) ** 2 / δ)
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
** Visualize
|
||
#+begin_src jupyter-python
|
||
%%space plot
|
||
t = np.linspace(0, τ_max, 1000)
|
||
ω = np.linspace(ω_c - 10, ω_c + 10, 1000)
|
||
fig, axs = plt.subplots(2)
|
||
axs[0].plot(t, np.real(α(t)))
|
||
axs[0].plot(t, np.imag(α(t)))
|
||
axs[1].plot(ω, I(ω))
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
:RESULTS:
|
||
| <matplotlib.lines.Line2D | at | 0x7f1609970e20> |
|
||
| <matplotlib.lines.Line2D | at | 0x7f1609900130> |
|
||
| <matplotlib.lines.Line2D | at | 0x7f16099006d0> |
|
||
[[file:./.ob-jupyter/9c3f7ad09ca2393c6d9b89cb03fc142b6475de10.svg]]
|
||
:END:
|
||
|
||
* HOPS
|
||
** Process
|
||
Let's get ourselves a realiation of a stochastic process. Mostly stolen
|
||
fromt the ~stocproc~ examples.
|
||
#+begin_src jupyter-python
|
||
η = sp.StocProc_FFT(
|
||
I, τ_max, α, negative_frequencies=True, seed=seed, intgr_tol=1e-2, intpl_tol=1e-2
|
||
)
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
#+begin_example
|
||
stocproc.stocproc - INFO - use neg freq
|
||
stocproc.method_ft - INFO - get_dt_for_accurate_interpolation, please wait ...
|
||
stocproc.method_ft - INFO - acc interp N 33 dt 2.88e-01 -> diff 7.57e-03
|
||
stocproc.method_ft - INFO - requires dt < 2.878e-01
|
||
stocproc.method_ft - INFO - get_N_a_b_for_accurate_fourier_integral, please wait ...
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-02 N 32 yields: interval [-8.95e+00,1.09e+01] diff 2.01e-01
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-03 N 32 yields: interval [-3.06e+01,3.26e+01] diff 6.40e-01
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-02 N 64 yields: interval [-8.95e+00,1.09e+01] diff 2.00e-01
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-04 N 32 yields: interval [-9.90e+01,1.01e+02] diff 1.90e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-03 N 64 yields: interval [-3.06e+01,3.26e+01] diff 1.31e-01
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-02 N 128 yields: interval [-8.95e+00,1.09e+01] diff 2.00e-01
|
||
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-05 N 32 yields: interval [-3.15e+02,3.17e+02] diff 2.68e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-04 N 64 yields: interval [-9.90e+01,1.01e+02] diff 1.15e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-03 N 128 yields: interval [-3.06e+01,3.26e+01] diff 6.33e-02
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-02 N 256 yields: interval [-8.95e+00,1.09e+01] diff 2.00e-01
|
||
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-06 N 32 yields: interval [-9.99e+02,1.00e+03] diff 2.99e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-05 N 64 yields: interval [-3.15e+02,3.17e+02] diff 2.29e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-04 N 128 yields: interval [-9.90e+01,1.01e+02] diff 4.21e-01
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-03 N 256 yields: interval [-3.06e+01,3.26e+01] diff 6.33e-02
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-02 N 512 yields: interval [-8.95e+00,1.09e+01] diff 2.00e-01
|
||
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-07 N 32 yields: interval [-3.16e+03,3.16e+03] diff 3.09e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-06 N 64 yields: interval [-9.99e+02,1.00e+03] diff 2.84e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-05 N 128 yields: interval [-3.15e+02,3.17e+02] diff 1.66e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-04 N 256 yields: interval [-9.90e+01,1.01e+02] diff 5.63e-02
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-03 N 512 yields: interval [-3.06e+01,3.26e+01] diff 6.33e-02
|
||
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-08 N 32 yields: interval [-1.00e+04,1.00e+04] diff 3.13e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-07 N 64 yields: interval [-3.16e+03,3.16e+03] diff 3.04e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-06 N 128 yields: interval [-9.99e+02,1.00e+03] diff 2.57e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-05 N 256 yields: interval [-3.15e+02,3.17e+02] diff 8.81e-01
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-04 N 512 yields: interval [-9.90e+01,1.01e+02] diff 2.00e-02
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-03 N 1024 yields: interval [-3.06e+01,3.26e+01] diff 6.33e-02
|
||
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-09 N 32 yields: interval [-3.16e+04,3.16e+04] diff 3.14e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-08 N 64 yields: interval [-1.00e+04,1.00e+04] diff 3.11e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-07 N 128 yields: interval [-3.16e+03,3.16e+03] diff 2.95e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-06 N 256 yields: interval [-9.99e+02,1.00e+03] diff 2.10e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-05 N 512 yields: interval [-3.15e+02,3.17e+02] diff 2.47e-01
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-04 N 1024 yields: interval [-9.90e+01,1.01e+02] diff 2.00e-02
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-03 N 2048 yields: interval [-3.06e+01,3.26e+01] diff 6.33e-02
|
||
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-10 N 32 yields: interval [-1.00e+05,1.00e+05] diff 3.14e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-09 N 64 yields: interval [-3.16e+04,3.16e+04] diff 3.13e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-08 N 128 yields: interval [-1.00e+04,1.00e+04] diff 3.08e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-07 N 256 yields: interval [-3.16e+03,3.16e+03] diff 2.77e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-06 N 512 yields: interval [-9.99e+02,1.00e+03] diff 1.41e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-05 N 1024 yields: interval [-3.15e+02,3.17e+02] diff 1.94e-02
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-04 N 2048 yields: interval [-9.90e+01,1.01e+02] diff 2.00e-02
|
||
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-11 N 32 yields: interval [-3.16e+05,3.16e+05] diff 3.14e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-10 N 64 yields: interval [-1.00e+05,1.00e+05] diff 3.14e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-09 N 128 yields: interval [-3.16e+04,3.16e+04] diff 3.12e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-08 N 256 yields: interval [-1.00e+04,1.00e+04] diff 3.02e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-07 N 512 yields: interval [-3.16e+03,3.16e+03] diff 2.44e+00
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-06 N 1024 yields: interval [-9.99e+02,1.00e+03] diff 6.29e-01
|
||
stocproc.method_ft - INFO - J_w_min:1.00e-05 N 2048 yields: interval [-3.15e+02,3.17e+02] diff 6.32e-03
|
||
stocproc.method_ft - INFO - return, cause tol of 0.01 was reached
|
||
stocproc.method_ft - INFO - requires dx < 3.088e-01
|
||
stocproc.stocproc - INFO - Fourier Integral Boundaries: [-3.152e+02, 3.172e+02]
|
||
stocproc.stocproc - INFO - Number of Nodes : 2048
|
||
stocproc.stocproc - INFO - yields dx : 3.088e-01
|
||
stocproc.stocproc - INFO - yields dt : 9.935e-03
|
||
stocproc.stocproc - INFO - yields t_max : 2.034e+01
|
||
#+end_example
|
||
|
||
Let's plot it.
|
||
#+begin_src jupyter-python
|
||
%%space plot
|
||
|
||
η.new_process(seed=seed)
|
||
plt.plot(η.t, np.real(η(η.t)), label="Re")
|
||
plt.plot(η.t, np.imag(η(η.t)), linestyle="--", label="Im")
|
||
plt.ylabel("η")
|
||
plt.xlabel("τ")
|
||
plt.legend()
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
:RESULTS:
|
||
: stocproc.stocproc - INFO - use fixed seed (1) for new process
|
||
| <matplotlib.lines.Line2D | at | 0x7f1609888a30> |
|
||
| <matplotlib.lines.Line2D | at | 0x7f1609888ee0> |
|
||
: Text(0, 0.5, 'η')
|
||
: Text(0.5, 0, 'τ')
|
||
: <matplotlib.legend.Legend at 0x7f1609888ca0>
|
||
[[file:./.ob-jupyter/4fed2a9479b6fdd1e3607dfae49a7c5ff02017a2.svg]]
|
||
:END:
|
||
|
||
** Actual Hops
|
||
#+begin_src jupyter-python
|
||
step = hops.make_hops_step(η, H_s, L, W, 3)
|
||
step(0, np.array([1, 1, 0, 0, 0, 0, 0, 0]))
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
: array([ 0. -1.j , -0.09725206+1.04291732j,
|
||
: -0.1 +0.j , 0. +0.j ,
|
||
: 0. +0.j , 0. +0.j ,
|
||
: 0. +0.j , 0. +0.j ])
|
||
|
||
#+begin_src jupyter-python
|
||
res = hops.integrate_hops_trajectory(η, H_s, L, W, 15, [1, 0], τ_max, seed, atol=1e-8, rtol=1e-8)
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
: stocproc.stocproc - INFO - use fixed seed (1) for new process
|
||
|
||
#+begin_src jupyter-python
|
||
%%space plot
|
||
t = np.linspace(0, τ_max, 1000)
|
||
plt.plot(t, np.real(res.sol(t)[10]))
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
:RESULTS:
|
||
| <matplotlib.lines.Line2D | at | 0x7f160a8d3b20> |
|
||
[[file:./.ob-jupyter/e0008afdffe9110ef1e621d637674c9d6a7263a3.svg]]
|
||
:END:
|
||
|
||
#+begin_src jupyter-python
|
||
ts, ρs = hops.integrate_hops_ensemble(η, H_s, L, W, 4, [1, 0], τ_max, 1000)
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
|
||
#+begin_src jupyter-python
|
||
energy = [np.trace(ρ @ σ3)/np.trace(ρ) for ρ in ρs]
|
||
plt.plot(ts, energy)
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
:RESULTS:
|
||
: /nix/store/z1lf15g2zxp79fwaajlnim22xxwh293l-python3-3.9.4-env/lib/python3.9/site-packages/numpy/core/_asarray.py:102: ComplexWarning: Casting complex values to real discards the imaginary part
|
||
: return array(a, dtype, copy=False, order=order)
|
||
| <matplotlib.lines.Line2D | at | 0x7f160a6e1130> |
|
||
[[file:./.ob-jupyter/2bea9d1f2f5d4f0385bad209290439581ffe7afa.svg]]
|
||
:END:
|