master-thesis/python/graveyard/billohops/test_billohops.org

10 KiB
Raw Blame History

Setup

  %load_ext autoreload
  %autoreload 2
  %load_ext jupyter_spaces
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
  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')
<ipython-input-145-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

  σ1 = np.matrix([[0,1],[1,0]])
  σ2 = np.matrix([[0,-1j],[1j,0]])
  σ3 = np.matrix([[1,0],[0,-1]])

Model

Let's set up the basic parameters.

  γ = .01 # coupling ratio
  ω_c = 1 # center of spect. dens
  δ = 1 # breadth BCF
  W = -ω_c * 1j - δ # exponent BCF
  τ_max = 1.6 # the maximal simulation time
  seed = 100 # seed for all pseudo random generators
  H_s = σ3
  L = 1/2 * (σ1 - 1j * σ2) * γ

  L
matrix([[0.  +0.j, 0.  +0.j],
        [0.01+0.j, 0.  +0.j]])

And for fun: the BCF and the spectral density.

  def α(τ):
      return np.sqrt(δ) * np.exp(-1j * ω_c * τ - np.abs(τ) * δ)

  def I(ω):
      return np.sqrt(δ) / (δ + (ω - ω_c) ** 2 / δ)

Visualize

  %%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(ω))
<matplotlib.lines.Line2D at 0x7f4b46f79f10>
<matplotlib.lines.Line2D at 0x7f4b46f052b0>
<matplotlib.lines.Line2D at 0x7f4b46f05730>

/hiro/master-thesis/media/commit/4f8c7e75eaf1b2b85615979aaac0ef3ad683fa0d/python/graveyard/billohops/.ob-jupyter/531fd66ca2df41e72d6e1f473ebbfb0f48aec9c2.svg

HOPS

Process

Let's get ourselves a realiation of a stochastic process. Mostly stolen fromt the stocproc examples.

  η = sp.StocProc_FFT(
      I, τ_max, α, negative_frequencies=True, seed=seed, intgr_tol=1e-2, intpl_tol=1e-2
  )
  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
  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 7.41e-02
  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 2.78e-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 2.20e-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 9.94e-02
  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 6.56e-03
  stocproc.method_ft - INFO - return, cause tol of 0.01 was reached
  stocproc.method_ft - INFO - requires dx < 6.176e-01
  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
  stocproc.stocproc - INFO - yields dt                  : 9.935e-03
  stocproc.stocproc - INFO - yields t_max               : 1.016e+01

Let's plot it.

  %%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()
stocproc.stocproc - INFO - use fixed seed (100) for new process
<matplotlib.lines.Line2D at 0x7f4b46e96d90>
<matplotlib.lines.Line2D at 0x7f4b46ea41f0>
Text(0, 0.5, 'η')
Text(0.5, 0, 'τ')
<matplotlib.legend.Legend at 0x7f4b46ea44c0>

/hiro/master-thesis/media/commit/4f8c7e75eaf1b2b85615979aaac0ef3ad683fa0d/python/graveyard/billohops/.ob-jupyter/7e3938f40b103b001892d8d9bd055b30abb4d166.svg

TODO Actual Hops

  h = hops.Hops(η, H_s, L, W, 10, seed)
  res = h.integrate_hops_trajectory([1, 0], τ_max, seed)
stocproc.stocproc - INFO - use fixed seed (100) for new process
  %%space plot
  t = np.linspace(0, τ_max, 1000)
  plt.plot(t, np.abs(res.sol(t)[3]))
<matplotlib.lines.Line2D at 0x7f4b468bb3d0>

/hiro/master-thesis/media/commit/4f8c7e75eaf1b2b85615979aaac0ef3ad683fa0d/python/graveyard/billohops/.ob-jupyter/f956b12a0e926cc85149714aaa9f81b87b035181.svg

  ts, ρs, js = h.integrate_hops_ensemble([1, 0], np.linspace(0, τ_max, 1000), 10000)
  energy = [np.trace(ρ) for ρ in ρs]
  plt.plot(ts, energy)
/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>

/hiro/master-thesis/media/commit/4f8c7e75eaf1b2b85615979aaac0ef3ad683fa0d/python/graveyard/billohops/.ob-jupyter/4bea320be403bb6638004a735d38a82100cdde66.svg

 energy = [np.real(np.trace(ρ @ σ3)/np.trace(ρ)) for ρ in ρs]
 plt.plot(ts, energy)
<matplotlib.lines.Line2D at 0x7f4b465bacd0>

/hiro/master-thesis/media/commit/4f8c7e75eaf1b2b85615979aaac0ef3ad683fa0d/python/graveyard/billohops/.ob-jupyter/9b8a70997f86a2ab2d4610dd63420af018aa40b4.svg

And let's plot the heat transfer rate.

 plt.plot(ts, js)
<matplotlib.lines.Line2D at 0x7f4b462b5370>

/hiro/master-thesis/media/commit/4f8c7e75eaf1b2b85615979aaac0ef3ad683fa0d/python/graveyard/billohops/.ob-jupyter/284aa707d9174d730de5b77c3732f952d1b0ad45.svg

    E_t = np.sum(((ts[1:] - ts[:-1]) * js[1:]))
    E_t
2.978852046217619e-07
  js.mean()
1.8599207463571254e-07
  (energy[0] - energy[-1])/E_t
340.77341790743804