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

15 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
z16zulpojyom5baq0jum

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.8\) \(ω_c=2\)

Load the Data

  from hopsflow import hopsflow, util
  from hops.core.hierarchyLib import HI

Now we read the trajectory data.

  class result:
      with HI(params, 500).get_data(read_only=True) as hd:
          N = hd.samples
          τ = hd.get_time()
          ρ = hd.get_rho_t()
          ψ_1 = np.array(hd.aux_states)[0:N]
          ψ = np.array(hd.stoc_traj)[0:N]
  fs.tex_value(result.N, prefix="N=", save="samples")
  ---------------------------------------------------------------------------
  RuntimeError                              Traceback (most recent call last)
  /tmp/ipykernel_86433/975144810.py in <module>
  ----> 1 class result:
        2     with HI(params, 500).get_data(read_only=True) as hd:
        3         N = hd.samples
        4         τ = hd.get_time()
        5         ρ = hd.get_rho_t()

  /tmp/ipykernel_86433/975144810.py in result()
        2     with HI(params, 500).get_data(read_only=True) as hd:
        3         N = hd.samples
  ----> 4         τ = hd.get_time()
        5         ρ = hd.get_rho_t()
        6         ψ_1 = np.array(hd.aux_states)[0:N]

  /nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/hops/core/hierarchyData.py in get_time(self)
      757 
      758         if not self.time_set:
  --> 759             raise RuntimeError("can not get time, time has not been set yet.")
      760         return self.time[:]  # type: ignore
      761 

  RuntimeError: can not get time, time has not been set yet.
  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/ec3f5d140056ec4ff6d7ccc41c92c39cee5b2105/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/307ffa8ed20e93410c6858e7aed624294982fbb9.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/ec3f5d140056ec4ff6d7ccc41c92c39cee5b2105/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/90244163620b237d5a8d493923f8dd87ba0cb01a.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/ec3f5d140056ec4ff6d7ccc41c92c39cee5b2105/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/d47cf2752cb838d4024b053730d50295639dca3c.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])

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

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

And the total energy lost is:

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

We do start in the state.

  system.psi0
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/ec3f5d140056ec4ff6d7ccc41c92c39cee5b2105/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/72d61a32bd4c505790dd3f70698a0525f693e078.svg

And now for all trajectories.

  full_flow = hopsflow.heat_flow_ensemble(
      result.ψ, result.ψ_1, hf_system, result.N, every=result.N // 4, 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/ec3f5d140056ec4ff6d7ccc41c92c39cee5b2105/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/ab447d51128e3ac19bfd435aabb0a71bd9143a12.svg

We can integrate the energy change in the bath:

  e_bath = util.integrate_array(-full_flow[-1][1], result.τ)
  plt.plot(result.τ, e_bath)
<matplotlib.lines.Line2D at 0x7f21fed6e550>

/hiro/master-thesis/media/commit/ec3f5d140056ec4ff6d7ccc41c92c39cee5b2105/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/cf8ab2488d384d9cdbc0ac97168442808be05939.svg

Calculate the Interaction Energy

First we calculate it from energy conservation.

  e_int = (1/2 - e_sys - e_bath).real
  with fs.hiro_style():
      plt.plot(result.τ, e_int)

/hiro/master-thesis/media/commit/ec3f5d140056ec4ff6d7ccc41c92c39cee5b2105/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/1fad72f04d79f936bf6fccffdb3fb63e1f9e13e3.svg

And then from first principles:

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

/hiro/master-thesis/media/commit/ec3f5d140056ec4ff6d7ccc41c92c39cee5b2105/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/b2e4348b02a6a8db2e23c0b3d40357350bc2e9a6.svg

And both together:

  with fs.hiro_style():
       plt.errorbar(result.τ, e_int_ex, yerr=σ_e_int_ex, ecolor="yellow", label="direct")
       plt.xlabel("$τ$")
       plt.ylabel(r"$\langle H_I\rangle$")
       plt.plot(result.τ, e_int, label="from energy conservation")
       plt.legend()

       plt.gcf().set_size_inches(fs.get_figsize(239, 1, .8))
       fs.export_fig("interaction")

/hiro/master-thesis/media/commit/ec3f5d140056ec4ff6d7ccc41c92c39cee5b2105/python/energy_flow_proper/01_zero_temperature/.ob-jupyter/8fa5f86b96629477c4c599359c0668f6750d4b88.svg