HOPSFlow-Paper/subprojects/bath_memory/project.org
2023-11-28 13:08:17 -05:00

17 KiB
Raw Blame History

Here we scan bath memory and maybe temperature gradient later.

Boilerplate

  import figsaver as fs
  import plot_utils as pu
  from hiro_models.one_qubit_model import StocProcTolerances
  from hiro_models.otto_cycle import OttoEngine
  import hiro_models.model_auxiliary as aux
  import numpy as np
  import qutip as qt
  import utilities as ut
  import stocproc
  import matplotlib.pyplot as plt
  import otto_utilities as ot
  import hops
  from hopsflow.util import EnsembleValue
  import ray
  ray.shutdown()

  #ray.init(address='auto')
  ray.init()
  from hops.util.logging_setup import logging_setup
  import logging
  logging_setup(logging.INFO)

Cycles

We take the same baseline as in cycle_shift.org.

But we vary the cycle speed while keeping a fixed proportion coupling-change/cycle time.

  T = 50

  def make_model_orig(shift_c, shift_h, switch_t=3.0, switch_t_sys=None, only_cold=False):
      switch_time = switch_t / T
      switch_time_sys = (switch_t_sys if switch_t_sys else switch_t) / T

      (p_H, p_L) = ot.timings(switch_time_sys, switch_time)
      return OttoEngine(
          δ=[0.7, 0.7],
          ω_c=[1, 1],
          ψ_0=qt.basis([2], [1]),
          description=f"Classic Cycle",
          k_max=4,
          bcf_terms=[5] * 2,
          truncation_scheme="simplex",
          driving_process_tolerances=[StocProcTolerances(1e-3, 1e-3)] * 2,
          thermal_process_tolerances=[StocProcTolerances(1e-3, 1e-3)] * 2,
          T=[0.5, 4],
          therm_methods=["tanhsinh", "tanhsinh"],
          Δ=1,
          num_cycles=3,
          Θ=60,
          dt=0.001,
          timings_H=p_H,
          timings_L=p_L,
          streaming_mode=True,
          shift_to_resonance=(False, False),
          L_shift=(shift_c, 0 if only_cold else shift_h),
      )

  def make_model(ω_c, T_c):
      model =  make_model_orig(0, 0, switch_t = 6.)


      model.T[0] = T_c
      model.ω_c = [ω_c, ω_c]
      return model
  ωs = [round(ω, 3) for ω in np.linspace(.5, 1.5, 5)]
  Ts = [round(T, 3) for T in np.linspace(.4, .6, 5)]
  ωs, Ts
0.5 0.75 1.0 1.25 1.5
0.4 0.45 0.5 0.55 0.6
  import itertools
  models = [make_model(ω, T) for ω, T, in itertools.product(ωs, Ts)]

Integrate

  ot.integrate_online_multi(models, 30_000, increment=10_000, analyze_kwargs=dict(every=10_000))
  aux.import_results(other_data_path="taurus/.data", other_results_path="taurus/results", models_to_import=models)

Analysis

  models[1].T
0.45 4
  fig, ax = plt.subplots()
  for model in models:
      pu.plot_with_σ(models[0].t, model.interaction_power().sum_baths().integrate(model.t), ax=ax)
      #print(model.system_energy().N, model.power(steady_idx=2).value, model.T[0], model.ω_c[0])

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/7cd4652956dbe71c4fde9b95d7ee096432644147.svg

  fig, ax = plt.subplots()
  for model in models:
    pu.plot_with_σ(models[0].t, model.system_energy(), ax=ax)

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/67a2ccbd4ef5246c322756d0f0ce3049d54fca26.svg

  ot.plot_energy_deviation(models)
<Figure size 578x240 with 1 Axes> <AxesSubplot: xlabel= $\tau$ ylabel= H /max H $ >

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/64c3e2323df26b946a3d4f214b63ae6d06d42ce5.svg

  fig, ax = plt.subplots()
  styles = [".", "*"]
  for bath, style in enumerate(styles):
      for i, T in enumerate(Ts):
          inters = np.array([abs(model.interaction_energy().for_bath(bath).slice(slice(model.strobe[1][2], -1))).max.value for model in models[i::len(Ts)]])
          bcf_scales = np.array([(model.bcf_scales[bath]) for model in models[i::len(Ts)]])
          ωs_filter = [model.ω_c[0] for model in models[::len(Ts)]]
          #ax.plot(ωs_filter, inters)
          #ax.plot(ωs_filter, bcf_scales, linestyle=style, marker=".", label=rf"$T={T}$" if bath == 0 else None)
          ax.plot(ωs_filter, inters, linestyle="dashed", marker=style, label=rf"${T}$" if bath == 0 else None, color=f"C{i}")


  ax.set_xlabel(r"$\omega_c$")
  ax.set_ylabel(r"$E_\mathrm{I}$")
  from matplotlib.lines import Line2D
  custom_lines = [Line2D([0], [0], linestyle="dashed", color="black", marker=style) for style in styles]
  legend_orig = ax.legend(title=r"$T_c$")
  ax.legend(custom_lines, ["Cold Bath", "Hot Bath"], loc="upper center", bbox_to_anchor=[0.4, 1])
  ax.add_artist(legend_orig)
  fs.export_fig("bath_memory_interaction_strength", x_scaling=1, y_scaling=.7)

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/2287fb919cb11c84e7f14e7eccba7082e915fe5e.svg

  fig, ax = plt.subplots()
  styles = [".", "*"]
  for bath, style in enumerate(styles):
      for i, T in enumerate(Ts):
          inters = np.array([(ot.val_relative_to_steady(
              model,
              -1 * model.interaction_power().for_bath(bath).integrate(model.t) * 1 / model.Θ,
              steady_idx=2,
          )[1].value[-1]) for model in models[i::len(Ts)]])
          bcf_scales = np.array([(model.bcf_scales[bath]) for model in models[i::len(Ts)]])
          ωs_filter = [model.ω_c[0] for model in models[::len(Ts)]]
          #ax.plot(ωs_filter, inters)
          #ax.plot(ωs_filter, bcf_scales, linestyle=style, marker=".", label=rf"$T={T}$" if bath == 0 else None)
          ax.plot(ωs_filter, inters, linestyle="dashed", marker=style, label=rf"${T}$" if bath == 0 else None, color=f"C{i}")


  ax.set_xlabel(r"$\omega_c$")
  ax.set_ylabel(r"$\bar{P}_\mathrm{I}$")
  from matplotlib.lines import Line2D
  custom_lines = [Line2D([0], [0], linestyle="dashed", marker=style, color="black") for style in styles]
  legend_orig = ax.legend(title=r"$T_c$")
  ax.legend(custom_lines, ["Cold Bath", "Hot Bath"], loc="upper center", bbox_to_anchor=[0.6, .56])
  ax.add_artist(legend_orig)
  fs.export_fig("bath_memory_interaction_power", x_scaling=1, y_scaling=.7)

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/3ec5c54f631b4e41f695054f1f927604248d54f1.svg

  fig, ax = plt.subplots()
  for model in models[len(Ts)*4:len(Ts)*5]:
      pu.plot_with_σ(model.t, model.interaction_energy().for_bath(1), ax=ax)
      pu.plot_with_σ(model.t, model.system_energy(), ax=ax)
      pu.plot_with_σ(model.t, model.interaction_power().for_bath(1), ax=ax, linestyle="dashed")

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/6531d94680eae9ed23ff7f5be921c7b77bad45ee.svg

  fig, ax = plt.subplots()
  ax.set_xlim(models[0].Θ * 2, models[0].Θ * 3)
  for i, model in enumerate(models[0::len(Ts)]):
      T_c = model.T[0]
      pu.plot_with_σ(model.t, model.interaction_energy().for_bath(0), ax=ax, color=f"C{i}", label=f"{model.ω_c[0]}")
      pu.plot_with_σ(model.t, model.interaction_energy().for_bath(1), ax=ax, color=f"C{i}", linestyle="dotted")
      pu.plot_with_σ(model.t, model.system_energy(), ax=ax, linestyle="dashed", color=f"C{i}")

      #ax.plot(model.t, model.system.operator_norm(model.t), linestyle="dashed", color=f"C{i}")
      #pu.plot_with_σ(model.t, model.interaction_power().for_bath(1), ax=ax, linestyle="dashed")

  custom_lines = [Line2D([0], [0], linestyle=style, color="black") for style in ["-", "dotted", "dashed"]]
  legend_orig = fig.legend(title=r"$\omega_c$", loc="upper center", bbox_to_anchor=[1.1, .7])
  fig.legend(custom_lines, [r"$\langle H_{\mathrm{I},c}\rangle$", r"$\langle H_{\mathrm{I},h}\rangle$", r"$\langle H_{\mathrm{S}}\rangle$"], loc="upper center", bbox_to_anchor=[1.1, 1])
  fig.add_artist(legend_orig)
  ax.set_title(rf"$T_c={T_c}$")
  ax.set_xlabel(r"$\tau$")
  fs.export_fig("bath_memory_constant_t_overview", x_scaling=1, y_scaling=.7)

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/46963903de121c7d24d3acf6c6f0c7b72cd40a2a.svg

  def thermal_state(T, Ω):
      ρ = np.array([[np.exp(-Ω / T), 0], [0, 1]])
      ρ /= np.sum(np.diag(ρ))

      return ρ
  fig, ax = plt.subplots()
  ax.set_xlim(models[0].Θ * 2, models[0].Θ * 3)

  for i, model in enumerate(models[0::len(Ts)]):
      T_c = model.T[0]
      pu.plot_with_σ(model.t, model.interaction_energy().for_bath(0), ax=ax, color=f"C{i}", label=f"{model.ω_c[0]}")
      pu.plot_with_σ(model.t, model.interaction_energy().for_bath(1), ax=ax, color=f"C{i}", linestyle="dotted")

      with aux.get_data(model) as d:
            pu.plot_with_σ(
                model.t,
                EnsembleValue(
                    hops.util.utilities.trace_distance(
                        d, relative_to=thermal_state(model.T[0], model.energy_gaps[0])
                    )
                ),
                linestyle="dashed",
                color=f"C{i}",
                ax=ax,
            )
            pu.plot_with_σ(
                model.t,
                EnsembleValue(
                    hops.util.utilities.trace_distance(
                        d, relative_to=thermal_state(model.T[1], model.energy_gaps[1])
                    )
                ),
                linestyle="dashdot",
                color=f"C{i}",
                ax=ax,
            )
      #ax.plot(model.t, model.coupling_operators[0].operator_norm(model.t), linestyle="dashed", color=f"C{i}")
      #ax.plot(model.t, model.system.operator_norm(model.t), linestyle="dashed", color=f"C{i}")
      #pu.plot_with_σ(model.t, model.interaction_power().for_bath(1), ax=ax, linestyle="dashed")

  custom_lines = [Line2D([0], [0], linestyle=style, color="black") for style in ["-", "dotted", "dashed", "dashdot"]]
  legend_orig = fig.legend(title=r"$\omega_c$", loc="upper center", bbox_to_anchor=[1.1, .6])
  fig.legend(custom_lines, [r"$\langle H_{\mathrm{I},c}\rangle$", r"$\langle H_{\mathrm{I},h}\rangle$", r"$||\rho(\tau)-\rho_c||$",  r"$||\rho(\tau)-\rho_h||$"], loc="upper center", bbox_to_anchor=[1.15, 1])
  fig.add_artist(legend_orig)
  ax.set_title(rf"$T_c={T_c}$")
  ax.set_xlabel(r"$\tau$")
  fs.export_fig("bath_memory_constant_t_thermalization", x_scaling=1, y_scaling=.7)
/nix/store/fai1b55231rnk4jyj0kjicdnqcgdf9ph-python3-3.9.15-env/lib/python3.9/site-packages/matplotlib/cbook/__init__.py:1369: ComplexWarning: Casting complex values to real discards the imaginary part
  return np.asarray(x, float)
/nix/store/fai1b55231rnk4jyj0kjicdnqcgdf9ph-python3-3.9.15-env/lib/python3.9/site-packages/matplotlib/axes/_axes.py:5340: ComplexWarning: Casting complex values to real discards the imaginary part
  pts[0] = start
/nix/store/fai1b55231rnk4jyj0kjicdnqcgdf9ph-python3-3.9.15-env/lib/python3.9/site-packages/matplotlib/axes/_axes.py:5341: ComplexWarning: Casting complex values to real discards the imaginary part
  pts[N + 1] = end
/nix/store/fai1b55231rnk4jyj0kjicdnqcgdf9ph-python3-3.9.15-env/lib/python3.9/site-packages/matplotlib/axes/_axes.py:5344: ComplexWarning: Casting complex values to real discards the imaginary part
  pts[1:N+1, 1] = dep1slice
/nix/store/fai1b55231rnk4jyj0kjicdnqcgdf9ph-python3-3.9.15-env/lib/python3.9/site-packages/matplotlib/axes/_axes.py:5346: ComplexWarning: Casting complex values to real discards the imaginary part
  pts[N+2:, 1] = dep2slice[::-1]

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/89a0703dce099a82ee239a1414590a9cb312be58.svg

  fig, ax = plt.subplots()
  ax.set_xlim(models[0].Θ * 2, models[0].Θ * 3)


  for i, model in enumerate(models[len(Ts) : 2*len(Ts)]):
      ω_c = model.ω_c[0]
      pu.plot_with_σ(
          model.t,
          model.interaction_energy().for_bath(0),
          ax=ax,
          color=f"C{i}",
          label=f"{model.T[0]}",
      )
      pu.plot_with_σ(
          model.t,
          model.interaction_energy().for_bath(1),
          ax=ax,
          color=f"C{i}",
          linestyle="dotted",
      )
      pu.plot_with_σ(
          model.t, model.system_energy(), ax=ax, linestyle="dashed", color=f"C{i}"
      )

      # ax.plot(model.t, model.coupling_operators[0].operator_norm(model.t), linestyle="dashed", color=f"C{i}")
      # ax.plot(model.t, model.system.operator_norm(model.t), linestyle="dashed", color=f"C{i}")
      # pu.plot_with_σ(model.t, model.interaction_power().for_bath(1), ax=ax, linestyle="dashed")

  custom_lines = [
      Line2D([0], [0], linestyle=style, color="black")
      for style in ["-", "dotted", "dashed"]
  ]
  legend_orig = fig.legend(title=r"$T_c$", loc="upper center", bbox_to_anchor=[1.1, 0.7])
  fig.legend(
      custom_lines,
      [
          r"$\langle H_{\mathrm{I},c}\rangle$",
          r"$\langle H_{\mathrm{I},h}\rangle$",
          r"$\langle H_{\mathrm{S}}\rangle$",
      ],
      loc="upper center",
      bbox_to_anchor=[1.1, 1],
  )
  fig.add_artist(legend_orig)
  ax.set_title(rf"$\omega_c={ω_c}$")
  ax.set_xlabel(r"$\tau$")

  fs.export_fig("bath_memory_constant_omega_overview", x_scaling=1, y_scaling=0.7)

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/46ede42b01c98fcfe172c1c5a155106bb5b96e28.svg

  ot.plot_powers_and_efficiencies(np.array(ωs), models[0::len(Ts)], xlabel=r"$\omega_c$")
<Figure size 578x240 with 2 Axes> <AxesSubplot: xlabel= $\omega_c$ ylabel= $\bar{P}$ > (<AxesSubplot: xlabel= $\omega_c$ ylabel= $\bar{P}$ > <AxesSubplot: ylabel= $\eta$ >)

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/6ca171b158a9eb2cfee33e5416ee97a07e7ab331.svg

  ot.plot_power_eff_convergence(models, 2)
<Figure size 578x240 with 2 Axes> (<AxesSubplot: xlabel= $N$ ylabel= $P$ > <AxesSubplot: xlabel= $N$ ylabel= $\eta$ >)

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/e9189b3befd45cbd6e06b16a711722b7c3ffae3f.svg

  f=ot.plot_contour(
        models,
        lambda model: np.clip(-model.power(steady_idx=2).value, 0, np.inf),
        lambda model: model.T[0],
        lambda model: model.ω_c[0],
        levels=10
    )
  plt.gcf().colorbar(f[2][0])
<matplotlib.colorbar.Colorbar at 0x7f548330b0a0>

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/63986ea2d20252a3701b1bd055cae1c284cfec2d.svg

  f = plt.figure()
  a_power = f.add_subplot(121)
  a_efficiency = f.add_subplot(122)
  axs = [a_power, a_efficiency]

  for ax in axs:
      ax.set_xlabel(r"$T_c$")
      ax.set_ylabel(r"$\omega_c$")

  (_, _, (c1, data1)) = ot.plot_contour(
      models,
      lambda model: np.clip(-model.power(steady_idx=2).value, 0, np.inf),
      lambda model: model.T[0],
      lambda model: model.ω_c[0],
      ax=a_power,
  )
  a_power.set_title(r"$\bar{P}/\Omega$")


  (_, _, (c2, data2)) = ot.plot_contour(
      models,
      lambda model: np.clip(np.nan_to_num(model.efficiency(steady_idx=2).value * 100), 0, np.inf),
      lambda model: model.T[0],
      lambda model: model.ω_c[0],
      ax=a_efficiency,
  )
  a_efficiency.set_title(r"$\eta\, [\%]$")
  f.colorbar(c1, ax=axs[0])
  f.colorbar(c2, ax=axs[1])
  fs.export_fig("bath_memory_power_efficiency_contour", x_scaling=2, y_scaling=.8, data=(data1, data2))

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/b5209e73946c9095b1f46ed2f616bdbb5450aa04.svg

  f = plt.figure()
  a_power = f.add_subplot(121, projection="3d")
  a_efficiency = f.add_subplot(122, projection="3d")

  for ax in [a_power, a_efficiency]:
      ax.set_box_aspect(aspect=None, zoom=0.78)
      ax.set_xlabel(r"$T_c$")
      ax.set_ylabel(r"$\omega_c$")
      ax.xaxis.labelpad = 10
      ax.view_init(elev=30.0, azim=-29, roll=0)

  ot.plot_3d_heatmap(
      models,
      lambda model: np.clip(-model.power(steady_idx=2).value, 0, np.inf),
      lambda model: model.T[0],
      lambda model: model.ω_c[0],
      ax=a_power,
  )
  a_power.set_zlabel(r"$\bar{P}$")


  ot.plot_3d_heatmap(
      models,
      lambda model: np.clip(np.nan_to_num(model.efficiency(steady_idx=2).value * 100), 0, np.inf),
      lambda model: model.T[0],
      lambda model: model.ω_c[0],
      ax=a_efficiency,
  )
  a_efficiency.set_zlabel(r"$\eta$")
  fs.export_fig("bath_memory_power_efficiency", x_scaling=2, y_scaling=1)

/hiro/HOPSFlow-Paper/media/commit/f8240b2411411e0f5e89824cc94cff577c3c4baa/subprojects/bath_memory/.ob-jupyter/c74c871c8882bb295108ab0bffd85b1e466d4827.svg

Things to Look At

  • power and efficiency
  • interaction power