#+PROPERTY: header-args :session bath_memory :kernel python :pandoc no :async yes Here we scan bath memory and maybe temperature gradient later. * Boilerplate #+name: boilerplate #+begin_src jupyter-python :results none :tangle tangle/bath_memory.py 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) #+end_src * Cycles We take the same baseline as in [[id:c06111fd-d719-433d-a316-c163f6e1d384][cycle_shift.org]]. But we vary the cycle speed while keeping a fixed proportion coupling-change/cycle time. #+begin_src jupyter-python :tangle tangle/bath_memory.py 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 #+end_src #+RESULTS: #+begin_src jupyter-python :tangle tangle/bath_memory.py ω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 #+end_src #+RESULTS: | 0.5 | 0.75 | 1.0 | 1.25 | 1.5 | | 0.4 | 0.45 | 0.5 | 0.55 | 0.6 | #+begin_src jupyter-python :tangle tangle/bath_memory.py import itertools models = [make_model(ω, T) for ω, T, in itertools.product(ωs, Ts)] #+end_src #+RESULTS: * Integrate #+begin_src jupyter-python :tangle tangle/bath_memory.py ot.integrate_online_multi(models, 30_000, increment=10_000, analyze_kwargs=dict(every=10_000)) #+end_src #+begin_src jupyter-python aux.import_results(other_data_path="taurus/.data", other_results_path="taurus/results", models_to_import=models) #+end_src * Analysis #+begin_src jupyter-python models[1].T #+end_src #+RESULTS: | 0.45 | 4 | #+begin_src jupyter-python 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]) #+end_src #+RESULTS: [[file:./.ob-jupyter/7cd4652956dbe71c4fde9b95d7ee096432644147.svg]] #+begin_src jupyter-python fig, ax = plt.subplots() for model in models: pu.plot_with_σ(models[0].t, model.system_energy(), ax=ax) #+end_src #+RESULTS: [[file:./.ob-jupyter/67a2ccbd4ef5246c322756d0f0ce3049d54fca26.svg]] #+begin_src jupyter-python ot.plot_energy_deviation(models) #+end_src #+RESULTS: :RESULTS: |
| | [[file:./.ob-jupyter/64c3e2323df26b946a3d4f214b63ae6d06d42ce5.svg]] :END: #+begin_src jupyter-python 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) #+end_src #+RESULTS: [[file:./.ob-jupyter/2287fb919cb11c84e7f14e7eccba7082e915fe5e.svg]] #+begin_src jupyter-python 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) #+end_src #+RESULTS: [[file:./.ob-jupyter/3ec5c54f631b4e41f695054f1f927604248d54f1.svg]] #+begin_src jupyter-python 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") #+end_src #+RESULTS: [[file:./.ob-jupyter/6531d94680eae9ed23ff7f5be921c7b77bad45ee.svg]] #+begin_src jupyter-python 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) #+end_src #+RESULTS: [[file:./.ob-jupyter/46963903de121c7d24d3acf6c6f0c7b72cd40a2a.svg]] #+begin_src jupyter-python 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) #+end_src #+RESULTS: :RESULTS: : /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] [[file:./.ob-jupyter/89a0703dce099a82ee239a1414590a9cb312be58.svg]] :END: #+begin_src jupyter-python 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) #+end_src #+RESULTS: [[file:./.ob-jupyter/46ede42b01c98fcfe172c1c5a155106bb5b96e28.svg]] #+begin_src jupyter-python ot.plot_powers_and_efficiencies(np.array(ωs), models[0::len(Ts)], xlabel=r"$\omega_c$") #+end_src #+RESULTS: :RESULTS: |
| | ( ) | [[file:./.ob-jupyter/6ca171b158a9eb2cfee33e5416ee97a07e7ab331.svg]] :END: #+begin_src jupyter-python ot.plot_power_eff_convergence(models, 2) #+end_src #+RESULTS: :RESULTS: |
| ( ) | [[file:./.ob-jupyter/e9189b3befd45cbd6e06b16a711722b7c3ffae3f.svg]] :END: #+begin_src jupyter-python 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]) #+end_src #+RESULTS: :RESULTS: : [[file:./.ob-jupyter/63986ea2d20252a3701b1bd055cae1c284cfec2d.svg]] :END: #+begin_src jupyter-python 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)) #+end_src #+RESULTS: [[file:./.ob-jupyter/b5209e73946c9095b1f46ed2f616bdbb5450aa04.svg]] #+begin_src jupyter-python 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) #+end_src #+RESULTS: [[file:./.ob-jupyter/c74c871c8882bb295108ab0bffd85b1e466d4827.svg]] * Things to Look At - power and efficiency - interaction power