master-thesis/python/billohops/test_billohops.org

11 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-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

  σ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.

  γ = .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) * γ

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 0x7f1609970e20>
<matplotlib.lines.Line2D at 0x7f1609900130>
<matplotlib.lines.Line2D at 0x7f16099006d0>

/hiro/master-thesis/media/commit/fc16acb858127e26d963da3762c5c2dd5de39f72/python/billohops/.ob-jupyter/9c3f7ad09ca2393c6d9b89cb03fc142b6475de10.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 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

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 (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>

/hiro/master-thesis/media/commit/fc16acb858127e26d963da3762c5c2dd5de39f72/python/billohops/.ob-jupyter/4fed2a9479b6fdd1e3607dfae49a7c5ff02017a2.svg

Actual Hops

  step = hops.make_hops_step(η, H_s, L, W, 3)
  step(0, np.array([1, 1, 0, 0, 0, 0, 0, 0]))
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        ])
  res = hops.integrate_hops_trajectory(η, H_s, L, W, 15, [1, 0], τ_max, seed, atol=1e-8, rtol=1e-8)
stocproc.stocproc - INFO - use fixed seed (1) for new process
  %%space plot
  t = np.linspace(0, τ_max, 1000)
  plt.plot(t, np.real(res.sol(t)[10]))
<matplotlib.lines.Line2D at 0x7f160a8d3b20>

/hiro/master-thesis/media/commit/fc16acb858127e26d963da3762c5c2dd5de39f72/python/billohops/.ob-jupyter/e0008afdffe9110ef1e621d637674c9d6a7263a3.svg

  ts, ρs = hops.integrate_hops_ensemble(η, H_s, L, W, 4, [1, 0], τ_max, 1000)
  energy = [np.trace(ρ @ σ3)/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 0x7f160a6e1130>

/hiro/master-thesis/media/commit/fc16acb858127e26d963da3762c5c2dd5de39f72/python/billohops/.ob-jupyter/2bea9d1f2f5d4f0385bad209290439581ffe7afa.svg