master-thesis/python/energy_flow_proper/01_zero_temperature/notebook.org

17 KiB
Raw Blame History

Configuration and Setup

This will be tangled into the config file that can be used with the HOPS cli.

  from hops.core.hierarchy_parameters import HIParams, HiP, IntP, SysP, ResultType
  from hops.core.hierarchyLib import HI
  from hops.util.bcf_fits import get_ohm_g_w
  from hops.util.truncation_schemes import TruncationScheme_Power_multi
  import hops.util.bcf
  import numpy as np
  import hops.util.matrixLib as ml
  from stocproc import StocProc_FFT

  wc = 2
  s = 1

  # The BCF fit
  bcf_terms = 5
  g, w = get_ohm_g_w(bcf_terms, s, wc)

  integration = IntP(t_max=30, t_steps=int(30 // 0.01))
  system = SysP(
      H_sys=0.5 * np.array([[-1, 0], [0, 1]]),
      L=0.5 * np.array([[0, 1], [1, 0]]),
      psi0=np.array([0, 1]),
      g=g,
      w=w,
      bcf_scale=0.5,
      T=0,
  )

  params = HIParams(
      SysP=system,
      IntP=integration,
      HiP=HiP(
          nonlinear=True,
          normalized_by_hand=True,
          result_type=ResultType.ZEROTH_AND_FIRST_ORDER,
          truncation_scheme=TruncationScheme_Power_multi.from_g_w(
              g=.5 * g, w=w, p=1, q=0.5, kfac=1.7
          ),
      ),
      Eta=StocProc_FFT(
          spectral_density=hops.util.bcf.OhmicSD_zeroTemp(
              s,
              1,
              wc,
          ),
          alpha=hops.util.bcf.OhmicBCF_zeroTemp(
              s,
              1,
              wc,
          ),
          t_max=integration.t_max,
          intgr_tol=1e-5,
          intpl_tol=1e-5,
          negative_frequencies=False,
      ),
      EtaTherm=None,
  )

Hops Integration

We can use multiple avenues.

Local Integration

hi 500 integrate

Linux ArLeenUX 5.16.8-zen1 x86_64 15:57:39 up 1 day 5:47, 1 user, load average: 1.55, 1.58, 1.91 impure  ~/D/P/U/m/m/p/e/01_zero_temperature  hi 500 integrate Loading the configuration from config.py. This might take a while… -

And there we go. It is better to run the above command in a vterm-session.

Remote/Distributed Integration

We start the server locally.

  hi 1000 start-server

Linux ArLeenUX 5.15.11-zen1 x86_64 16:34:02 up 2 days 19:58, 1 user, load average: 1.08, 1.67, 2.52 impure  ~/D/P/U/m/m/p/e/01_zero_temperature  hi 1000 start-server Loading the configuration from config.py. This might take a while… / JobManager started on ArLeenUX:42524 (bytearray(b'hierarchy')) [TET-00:12:05[43.6c/min]-TTG-0.00ms————————-100%————————-ETA-20220117_16:46:11-ORT-00:12:05] res_q #0 14.84GB/s 10.51TB|rem.:0, done:500, failed:0, prog.:0

############## in JM SERVER EXIT

HIServer start at 2022-01-17 16:34:05.075876 | runtime 7.280e+02s HIServer total number of jobs : 500

processed : 500
succeeded : 500
failed : 0
timing in sec: min 1.386e+01 max 4.145e+01 avr 2.478e+01
not processed : 0
queried : 0
not queried yet : 0

And jack in with a remote client. In this case my box at home.

Client

Starting a client is trivial.

  client localhost

Linux ArLeenUX 5.16.8-zen1 x86_64 16:06:00 up 5:55, 1 user, load average: 1.29, 0.91, 1.18 impure  ~/D/P/U/m/m/p/e/01_zero_temperature  client localhost connection to (('localhost', 42524), 'hierarchy') could not be established due to '<class 'ConnectionRefusedError' >' File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/jobmanager/jobmana ger.py", line 343, in connect self.manager_objects = self.create_manager_objects() connection refused error FAILED to connect to (('localhost', 42524), 'hierarchy') Traceback (most recent call last): File "nix/store/cphpkvyd3ni0b3b9nfvbnh1xc3cqc4i2-python3.9-hops-1.0/bin.client-wrapped", line 9, in <module> sys.exit(main()) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/cli/client.py", line 86, in main typer.run(start_client) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/typer/main.py", line 864, in run app() File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/typer/main.py", line 214, in call return get_command(self)(*args, **kwargs) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/click/core.py", line 1128, in call return self.main(*args, **kwargs) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, **ctx.params) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/click/core.py", line 754, in invoke return __callback(*args, **kwargs) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/typer/main.py", line 500, in wrapper return callback(**use_params) # type: ignore File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/cli/client.py", line 82, in start_client cl.start() File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/jobmanager/jobma nager.py", line 657, in start raise JMConnectionError("Can not start Client with no connection to server (shared objetcs are not available)" ) ConnectionError: Can not start Client with no connection to server (shared objetcs are not available)

Using the Data

Jupyter Setup

  import matplotlib.pyplot as plt
  import numpy as np
  import utilities as ut
  import figsaver as fs

Let's export some infos about the model to TeX.

  fs.tex_value(system.bcf_scale, prec=1, save="bcf_scale", prefix="η="), fs.tex_value(
      wc, prec=0, save="cutoff_freq", prefix="ω_c="
  )
\(η=0.5\) \(ω_c=2\)
\(η=0.5\) \(ω_c=2\)

Load the Data

  from hopsflow import hopsflow, util
  from hops.core.hierarchyData import HIMetaData

Now we read the trajectory data.

  class result:
      hd = HIMetaData("data", ".").get_HIData(params, read_only=True)
      N = 8000
      τ = hd.get_time()
      ψ_1 = hd.aux_states
      ψ = hd.stoc_traj


  fs.tex_value(result.N, prefix="N=", save="samples")
\(N=8000\)
\(N=8000\)
  with fs.hiro_style():
      ts = np.linspace(0, 4, 1000)
      fs.plot_complex(ts, hops.util.bcf.OhmicBCF_zeroTemp(
              s,
              1,
              wc,
          )(ts))
      plt.title(r"$α$")
      plt.xlabel(r"$τ$")
      plt.title(rf"$J=η Γ(s+1) / (1 + iω_c τ)^{{s+1}}$")
      plt.text(1, 1, rf"$ω_c={wc}$, $s={s}$")
      plt.gcf().set_size_inches(fs.get_figsize(200, 1, .8))
      fs.export_fig("ohmic_bcf")

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/e8263ad2e4b1c1613215313a7dfbc6ed216c2c95.svg /hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/9a4de25aea7ef4a4260362c4f6a95fe799468df0.svg

  with fs.hiro_style():
      ωs = np.linspace(0, 50, 1000)

      plt.plot(ωs, hops.util.bcf.OhmicSD_zeroTemp(
              s,
              1,
              wc,
          )(ωs))
      plt.gcf().set_size_inches(fs.get_figsize(200, 1, .8))
      plt.title(rf"$J=η e^{{-ω/ω_c}} ω^s$")
      plt.text(25, .5, rf"$ω_c={wc}$, $s={s}$")
      plt.xlabel(r"$ω$")
      fs.export_fig("ohmic_sd")

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/e012b8343aea466de837bd13040e5ff970d3fe73.svg /hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/6239e2de72f9def50629c25f04d4a00aab9544f3.svg

Calculate System Energy

Simple sanity check.

  _, e_sys, σ_e_sys = util.operator_expectation_ensemble(
        iter(result.ψ),
        system.H_sys,
        result.N,
        params.HiP.nonlinear,
        save="./results/energy.npy"
    )

  with fs.hiro_style():
      plt.gcf().set_size_inches(fs.get_figsize(239, 1, .8))
      plt.errorbar(result.τ, e_sys.real, yerr=σ_e_sys.real, ecolor="yellow")
      plt.ylabel(r"$\langle H_S\rangle$")
      plt.xlabel(r"$τ$")

      fs.export_fig("system_energy")

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/56225cef8d7c7e496366bed4550d164fea3577c0.svg /hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/605e229b808be7ecd7e77051097440946861864d.svg

The energy bleeds out of the system. We don't reach the steady state yet. Also we don't loose all the energy.

The energy eigenvalues of the system are.

  np.linalg.eig(system.H_sys)[0]
array([-0.5,  0.5])
array([-0.5,  0.5])

The begin and and values of the system energy expectation are.

  e_sys[0].real, e_sys[-1].real
0.5 -0.47523035186448653
0.5 -0.47523035186448653

And the total energy lost is:

  e_sys[0].real - e_sys[-1].real
0.9752303518644865
0.9752303518644865

We do start in the state.

  system.psi0
array([0, 1])
array([0, 1])

Calculate the Heat Flow

Now let's calculate the heatflow. In this simple case it is engouh to know the first hierarchy states.

First we set up some parameter objects for the alogrithm.

  hf_system = hopsflow.SystemParams(
      system.L, system.g, system.w, system.bcf_scale, params.HiP.nonlinear
  )

Now we can apply our tooling to one trajectory for testing.

  hf_sample_run = hopsflow.HOPSRun(result.ψ[0], result.ψ_1[0], hf_system)
  first_flow = hopsflow.flow_trajectory_coupling(hf_sample_run, hf_system)
  with fs.hiro_style():
      plt.plot(result.τ, first_flow)

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/839bee0359e74368e15d081004c52a4ade7f0a2b.svg /hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/eeb3f8a5e4b6b819e982709971ca1cc53b191b48.svg

And now for all trajectories.

  full_flow = hopsflow.heat_flow_ensemble(
      result.ψ, result.ψ_1, hf_system, result.N, every=result.N // 2, save="results/flow_1.npy"
  )

  with fs.hiro_style():
      fig, ax = fs.plot_convergence(result.τ, full_flow, transform=lambda y: -y)
      fig.set_size_inches(fs.get_figsize(239, 1, .8))
      ax.legend()
      ax.set_xlabel("$τ$")
      ax.set_ylabel("$-J$")
      fs.export_fig("flow", fig)

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/d9d54851709c858057226b9308f61a373df1b095.svg /hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/a39c40d4d098cbbd255acbc20dd995b8606ed55d.svg

We can integrate the energy change in the bath:

  import scipy.integrate

  e_bath = np.array([0] + [
      scipy.integrate.simpson(-full_flow[-1][1][:i], result.τ[:i])
      for i in range(1, len(result.τ))
  ])
  plt.plot(result.τ, e_bath)
  σ_e_bath = np.sqrt(np.array([0] + [
      scipy.integrate.simpson(full_flow[-1][2][:i]**2, result.τ[:i])
      for i in range(1, len(result.τ))
  ])).real
  plt.errorbar(result.τ, e_bath, yerr=σ_e_bath, ecolor="yellow")
<ErrorbarContainer object of 3 artists>

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/f41b325da0fb83184132c9153a7aa644b1e8acbf.svg

<ErrorbarContainer object of 3 artists>

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/7268d10b9985d46cfc7c37b862b40c0bf5c0b7fb.svg

Initial Slip

  bcf_im = hops.util.bcf.OhmicBCF_zeroTemp(
              s,
              1,
              wc,
          )(result.τ).imag
  plt.plot(result.τ, bcf_im / np.abs(bcf_im).max())
  plt.plot(result.τ, first_flow / np.abs(first_flow).max())
<matplotlib.lines.Line2D at 0x7f055991c700>

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/0110541064f53964a9c95e377894ff5deb25980c.svg

<matplotlib.lines.Line2D at 0x7f055a2a5520>

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/58fdbc06f0806b834325ca3c4691b47fd7237d01.svg

  plt.plot(result.τ, bcf_im / np.abs(bcf_im).max())
  plt.plot(result.τ, full_flow[-1][1] / np.abs(full_flow[-1][1]).max())
  np.abs(bcf_im).max() / np.abs(full_flow[-1][1]).max()
3.3334210815243313

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/554fea708ef42a3e62404d22d08128ead4938758.svg

3.3334210815243313

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/0fd2ba3362bb5dcff965bdb4f0b96c0588303d34.svg

  _, L_exp_sys, σ_L_exp = util.operator_expectation_ensemble(
        iter(result.ψ),
        system.L @ system.L,
        result.N,
        params.HiP.nonlinear,
        save="./results/L2.npy"
    )
  plt.plot(result.τ, bcf_im * L_exp_sys.real * system.bcf_scale * 2)
  plt.plot(result.τ, full_flow[-1][1], linestyle="--")
<matplotlib.lines.Line2D at 0x7f055987d3d0>

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/3d1b22e410bdd499f6cf5a3ff9119ba90179c55e.svg

<matplotlib.lines.Line2D at 0x7f055922a880>

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/ec64dec84b680bcafb182ae480d9bd188e1fb3e2.svg

  import scipy.optimize

  maxind = np.argmax(np.abs(full_flow[-1][1]))
  res = scipy.optimize.minimize(
      lambda s: np.sum(
          ((bcf_im * L_exp_sys.real * s * system.bcf_scale * 2 - full_flow[-1][1]) ** 2)[
              0:maxind - 15
          ]
      ),
      1,
      tol=1e-4,
  )
  scale = res.x
  res
      fun: 0.00019313991029083397
 hess_inv: array([[1.38958965]])
      jac: array([3.63797881e-12])
  message: 'Optimization terminated successfully.'
     nfev: 6
      nit: 2
     njev: 3
   status: 0
  success: True
        x: array([1.0465576])
      fun: 0.00019313991029083397
 hess_inv: array([[1.38958965]])
      jac: array([3.63797881e-12])
  message: 'Optimization terminated successfully.'
     nfev: 6
      nit: 2
     njev: 3
   status: 0
  success: True
        x: array([1.0465576])
  plt.plot(result.τ, -bcf_im * L_exp_sys.real * 2 * system.bcf_scale * scale)
  #plt.plot(result.τ, -bcf_im * L_exp_sys.real * 2 * system.bcf_scale)
  plt.plot(result.τ, -full_flow[-1][1], linestyle="--")
  plt.yscale('log')

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/db469eea8f92bdb0f4b0eff02b235f1eecc29069.svg /hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/9525681d3c3f15cc84033d73bb2272d32f8dff39.svg

  plt.plot(result.τ, np.abs(-bcf_im * L_exp_sys.real * 2 * system.bcf_scale * scale + full_flow[-1][1]))
  plt.plot(result.τ, np.abs(-bcf_im * L_exp_sys.real * 2 * system.bcf_scale + full_flow[-1][1]), linestyle="--")
  plt.xlim((0, .4))
  plt.yscale('log')

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/d377ba40fb72d3648d216600a8c33e526d0b1374.svg /hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/9a8e4f67eed9973430c368eded35af984d848e0f.svg

Unscaled actually fits better for small times :P.

Calculate the Interaction Energy

First we calculate it from energy conservation.

  e_int = (1/2 - e_sys - e_bath).real
  σ_e_int = np.sqrt(σ_e_sys ** 2 + σ_e_bath ** 2).real
  plt.errorbar(result.τ, e_int, yerr=σ_e_int, ecolor="yellow")
<ErrorbarContainer object of 3 artists>

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/d1f6581fa97e2cf681ac5f802c829d193ffd2ffa.svg

<ErrorbarContainer object of 3 artists>

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/5a97f4646d7e9854e02ce808f69ecbdd9bbbf580.svg

And then from first principles:

  _, e_int_ex, σ_e_int_ex = hopsflow.interaction_energy_ensemble(result.ψ, result.ψ_1, hf_system, result.N, save="inten")
  with fs.hiro_style():
      plt.errorbar(result.τ, e_int_ex, yerr=σ_e_int_ex, ecolor="yellow")
100% 7999/7999 [00:26<00:00, 305.42it/s]

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/f514f5a25b7e830920c9c19e1b598deca3d23873.svg

And both together:

  with fs.hiro_style():
      plt.errorbar(result.τ, e_int, yerr=σ_e_int, label="from energy conservation", ecolor="yellow")
      plt.errorbar(result.τ, e_int_ex, yerr=σ_e_int_ex, label="direct", ecolor="pink")
      plt.gcf().set_size_inches(fs.get_figsize(239, 1, .8))
      plt.legend()
      plt.ylabel(r"$\langle H_I\rangle$")
      plt.xlabel(r"$τ$")
      fs.export_fig("interaction")

/hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/e43dee028684661d30cf72ff39a1b2dcd626e98b.svg /hiro/master-thesis/media/commit/b7a82bd47b564496ced52c35e342e811a8e240e2/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/88c1e4d9f19caaec1df4f9bcec98a46f8256c4c7.svg