master-thesis/python/billohops/test_billohops.org

271 lines
10 KiB
Org Mode
Raw Normal View History

2021-10-11 10:27:11 +02:00
#+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-145-e225c2f5410d>:8: DeprecationWarning: `set_matplotlib_formats` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.set_matplotlib_formats()`
2021-10-11 10:27:11 +02:00
: 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
γ = .01 # coupling ratio
2021-10-11 10:27:11 +02:00
ω_c = 1 # center of spect. dens
2021-10-11 11:35:35 +02:00
δ = 1 # breadth BCF
2021-10-11 10:27:11 +02:00
W = -ω_c * 1j - δ # exponent BCF
τ_max = 1.6 # the maximal simulation time
seed = 100 # seed for all pseudo random generators
2021-10-11 10:27:11 +02:00
H_s = σ3
L = 1/2 * (σ1 - 1j * σ2) * γ
L
2021-10-11 10:27:11 +02:00
#+end_src
#+RESULTS:
: matrix([[0. +0.j, 0. +0.j],
: [0.01+0.j, 0. +0.j]])
2021-10-11 10:27:11 +02:00
And for fun: the BCF and the spectral density.
#+begin_src jupyter-python
def α(τ):
2021-10-11 11:35:35 +02:00
return np.sqrt(δ) * np.exp(-1j * ω_c * τ - np.abs(τ) * δ)
2021-10-11 10:27:11 +02:00
def I(ω):
2021-10-11 11:35:35 +02:00
return np.sqrt(δ) / (δ + (ω - ω_c) ** 2 / δ)
2021-10-11 10:27:11 +02:00
#+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 | 0x7f4b46f79f10> |
| <matplotlib.lines.Line2D | at | 0x7f4b46f052b0> |
| <matplotlib.lines.Line2D | at | 0x7f4b46f05730> |
[[file:./.ob-jupyter/531fd66ca2df41e72d6e1f473ebbfb0f48aec9c2.svg]]
2021-10-11 10:27:11 +02:00
: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 1.00e-01 -> diff 9.15e-04
stocproc.method_ft - INFO - requires dt < 1.000e-01
2021-10-11 10:27:11 +02:00
stocproc.method_ft - INFO - get_N_a_b_for_accurate_fourier_integral, please wait ...
2021-10-11 11:35:35 +02:00
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 7.41e-02
2021-10-11 11:35:35 +02:00
stocproc.method_ft - INFO - J_w_min:1.00e-02 N 128 yields: interval [-8.95e+00,1.09e+01] diff 2.00e-01
2021-10-11 10:27:11 +02:00
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
2021-10-11 11:35:35 +02:00
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
2021-10-11 10:27:11 +02:00
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
2021-10-11 11:35:35 +02:00
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 2.78e-01
2021-10-11 11:35:35 +02:00
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
2021-10-11 10:27:11 +02:00
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
2021-10-11 11:35:35 +02:00
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 2.20e-02
2021-10-11 11:35:35 +02:00
stocproc.method_ft - INFO - J_w_min:1.00e-03 N 512 yields: interval [-3.06e+01,3.26e+01] diff 6.33e-02
2021-10-11 10:27:11 +02:00
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
2021-10-11 11:35:35 +02:00
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
2021-10-11 10:27:11 +02:00
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
2021-10-11 11:35:35 +02:00
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 9.94e-02
2021-10-11 11:35:35 +02:00
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
2021-10-11 10:27:11 +02:00
stocproc.method_ft - INFO - increasing N while shrinking the interval does lower the error -> try next level
2021-10-11 11:35:35 +02:00
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 6.56e-03
2021-10-11 10:27:11 +02:00
stocproc.method_ft - INFO - return, cause tol of 0.01 was reached
stocproc.method_ft - INFO - requires dx < 6.176e-01
2021-10-11 11:35:35 +02:00
stocproc.stocproc - INFO - Fourier Integral Boundaries: [-3.152e+02, 3.172e+02]
stocproc.stocproc - INFO - Number of Nodes : 1024
stocproc.stocproc - INFO - yields dx : 6.176e-01
2021-10-11 11:35:35 +02:00
stocproc.stocproc - INFO - yields dt : 9.935e-03
stocproc.stocproc - INFO - yields t_max : 1.016e+01
2021-10-11 10:27:11 +02:00
#+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 (100) for new process
| <matplotlib.lines.Line2D | at | 0x7f4b46e96d90> |
| <matplotlib.lines.Line2D | at | 0x7f4b46ea41f0> |
2021-10-11 10:27:11 +02:00
: Text(0, 0.5, 'η')
: Text(0.5, 0, 'τ')
: <matplotlib.legend.Legend at 0x7f4b46ea44c0>
[[file:./.ob-jupyter/7e3938f40b103b001892d8d9bd055b30abb4d166.svg]]
2021-10-11 10:27:11 +02:00
:END:
** TODO Actual Hops
2021-10-11 10:27:11 +02:00
#+begin_src jupyter-python
h = hops.Hops(η, H_s, L, W, 10, seed)
2021-10-11 12:18:38 +02:00
#+end_src
#+RESULTS:
#+begin_src jupyter-python
res = h.integrate_hops_trajectory([1, 0], τ_max, seed)
2021-10-11 10:27:11 +02:00
#+end_src
#+RESULTS:
: stocproc.stocproc - INFO - use fixed seed (100) for new process
2021-10-11 10:27:11 +02:00
#+begin_src jupyter-python
%%space plot
t = np.linspace(0, τ_max, 1000)
plt.plot(t, np.abs(res.sol(t)[3]))
2021-10-11 10:27:11 +02:00
#+end_src
#+RESULTS:
:RESULTS:
| <matplotlib.lines.Line2D | at | 0x7f4b468bb3d0> |
[[file:./.ob-jupyter/f956b12a0e926cc85149714aaa9f81b87b035181.svg]]
:END:
#+begin_src jupyter-python :results none
ts, ρs, js = h.integrate_hops_ensemble([1, 0], np.linspace(0, τ_max, 1000), 10000)
#+end_src
2021-10-11 10:27:11 +02:00
#+begin_src jupyter-python
energy = [np.trace(ρ) for ρ in ρs]
plt.plot(ts, energy)
2021-10-11 10:27:11 +02:00
#+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 | 0x7f4b46307100> |
[[file:./.ob-jupyter/4bea320be403bb6638004a735d38a82100cdde66.svg]]
2021-10-11 10:27:11 +02:00
:END:
#+begin_src jupyter-python
energy = [np.real(np.trace(ρ @ σ3)/np.trace(ρ)) for ρ in ρs]
plt.plot(ts, energy)
2021-10-11 10:27:11 +02:00
#+end_src
#+RESULTS:
:RESULTS:
| <matplotlib.lines.Line2D | at | 0x7f4b465bacd0> |
[[file:./.ob-jupyter/9b8a70997f86a2ab2d4610dd63420af018aa40b4.svg]]
:END:
And let's plot the heat transfer rate.
2021-10-11 10:27:11 +02:00
#+begin_src jupyter-python
plt.plot(ts, js)
2021-10-11 10:27:11 +02:00
#+end_src
#+RESULTS:
:RESULTS:
| <matplotlib.lines.Line2D | at | 0x7f4b462b5370> |
[[file:./.ob-jupyter/284aa707d9174d730de5b77c3732f952d1b0ad45.svg]]
2021-10-11 10:27:11 +02:00
:END:
#+begin_src jupyter-python
E_t = np.sum(((ts[1:] - ts[:-1]) * js[1:]))
E_t
#+end_src
#+RESULTS:
: 2.978852046217619e-07
#+begin_src jupyter-python
js.mean()
#+end_src
#+RESULTS:
: 1.8599207463571254e-07
#+begin_src jupyter-python
(energy[0] - energy[-1])/E_t
#+end_src
#+RESULTS:
: 340.77341790743804