08: new session for each sub-project

This commit is contained in:
Valentin Boettcher 2022-08-23 14:51:50 +02:00
parent 260521dccf
commit d98174358a
11 changed files with 962 additions and 536 deletions

View file

@ -0,0 +1,16 @@
import energy_shovel as es
import numpy as np
import qutip as qt
import matplotlib.pyplot as plt
import utilities as ut
import figsaver as fs
import hiro_models.model_auxiliary as aux
import plot_utils as pu
import ray
ray.shutdown()
ray.init(address="auto")
from hops.util.logging_setup import logging_setup
import logging
logging_setup(logging.INFO, show_stocproc=False)

View file

@ -1,7 +1,14 @@
import figsaver as fs
from tabulate import tabulate
import matplotlib.pyplot as plt
import plot_utils as pu
from hiro_models.one_qubit_model import QubitModel, StocProcTolerances
import hiro_models.model_auxiliary as aux
from hops.util.utilities import relative_entropy, relative_entropy_single, entropy, trace_distance
from hops.util.utilities import (
relative_entropy,
relative_entropy_single,
entropy,
trace_distance,
)
from hopsflow.util import EnsembleValue
import numpy as np
import qutip as qt
@ -18,33 +25,38 @@ from hops.util.dynamic_matrix import (
ScaleTime,
)
def energy_shovel(
Δ=2,
γ=1 / 10,
periods=5,
L_op=(1 / 2 * qt.sigmax()).full(),
H_op=1 / 2 * (qt.sigmaz() + 1).full(),
H_time_op=qt.sigmay().full() / 2,
dt=.01,
H_mod=qt.sigmay().full() / 2,
dt=0.01,
detune=0,
ω_c=1,
modulate_coupling=True,
modulate_system=True,
k_max=7,
**kwargs,
):
t_max = 2*np.pi/Δ * periods
L = ConstantMatrix(L_op) - Harmonic(
L_op, Δ, np.pi / 2
)
t_max = 2 * np.pi / Δ * periods
L = ConstantMatrix(L_op)
if modulate_coupling:
L = L - Harmonic(L_op, Δ, np.pi / 2)
H = ConstantMatrix(H_op)
if modulate_system:
H = H + γ * Δ * Harmonic(H_time_op, Δ)
H = H + γ * Δ * Harmonic(H_mod, Δ)
model = QubitModel(
options = dict(
δ=1,
ω_c=ω_c,
ω_s=1 + Δ - ω_c + detune,
t=ut.linspace_with_strobe(0, t_max, int(t_max/dt + 1), Δ),
ψ_0=(0.5 * 0 * qt.basis([2], [0]) + qt.basis([2], [1])),
t=ut.linspace_with_strobe(0, t_max, int(t_max / dt + 1), Δ),
ψ_0=(qt.basis([2], [1])),
description=f"Testing the time dependent coupling with smooth step.",
k_max=k_max,
bcf_terms=7,
@ -56,11 +68,81 @@ def energy_shovel(
H=H,
therm_method="fft",
)
model = QubitModel(**(options | kwargs))
strobe_t, strobe_indices = ut.strobe_times(model.t, Δ)
print(fr"\(λ={γ}, Δ={Δ}, T={model.T}\)")
return model, strobe_t, strobe_indices
def ergo(T, ω=1):
"""The ergotropy of a qubit coupled to a bath."""
return (T * np.log(1 + np.exp(-ω / T)))
return T * np.log(1 + np.exp(-ω / T))
def models_table(models, **kwargs):
"""Print a latex table that shows all relevant model parameters."""
table = []
def make_row(title, accessor):
row = [title]
for model, data in aux.model_data_iterator(models):
row += [f"${accessor(model, data)}$"]
return [row]
table += make_row(r"$ω_c$", lambda m, d: m.ω_c)
table += make_row(r"$α(0)$", lambda m, d: m.bcf_scale * m.full_thermal_bcf(0).real)
table += make_row(r"$T$", lambda m, d: m.T)
table += make_row(r"$N$", lambda m, d: d.samples)
table += make_row(r"$k_{\mathrm{max}}$", lambda m, d: m.k_max)
return tabulate(table, **(dict(tablefmt="latex_raw") | kwargs))
def energy_friction_plot(models, strobe_frequency, strobe_indices):
fig, (ax, ax2) = plt.subplots(ncols=2)
for model, data in aux.model_data_iterator(models):
tot_e = model.total_energy_from_power(data).for_bath(0) * (1 / ergo(model.T))
_, _, line = pu.plot_with_σ(
model.t,
tot_e,
ax=ax,
label=model.description,
strobe_frequency=strobe_frequency,
)
pu.plot_with_σ(
model.t,
tot_e,
ax=ax,
color=line[0].get_color(),
alpha=0.1,
)
ax.axhline(
tot_e.value[strobe_indices].min(),
color=line[0].get_color(),
alpha=0.5,
linestyle="--",
)
ax.set_xlabel(r"$\tau$")
ax.set_ylabel(r"$\Delta \langle H\rangle / \mathcal{W}_\mathrm{max}$")
ax.legend()
for model, data in aux.model_data_iterator(models):
ax2.plot(
model.t,
ut.ergotropy(data.rho_t_accum.mean, model.H(0))
/ -model.total_energy(data).for_bath(0).value[strobe_indices].min(),
)
ax2.set_xlabel(r"$\tau$")
ax2.set_ylabel(
r"$\mathcal{W}_\mathrm{S} / (-\Delta \langle H\rangle_\mathrm{min}$)"
)
return fig, (ax, ax2)

View file

@ -9,34 +9,12 @@
outputs = { self, utils, nixpkgs, ... }:
(utils.lib.poetry2nixWrapper nixpkgs {
name = "08_dynamic_one_bath";
extraOverlay = (self: super: {
flint = super.flint.overrideAttrs (old: rec {
pname = "flint";
version = "39ac8817a18710effd96dff38770f4d1c80ad608";
doCheck = false;
src = super.pkgs.fetchFromGitHub {
owner = "wbhart";
repo = "flint2";
rev = version;
sha256 = "sha256-UIdKUT2oSNth6AHHRPZOTLR7gHnxgmxKWdOR4klPPLw=";
};
});
arb = super.arb.overrideAttrs (old: rec {
pname = "arb-git";
version = "4e879e5602a59c14780085900236c9fa141f993d";
doCheck = false;
src = super.pkgs.fetchFromGitHub {
owner = "fredrik-johansson";
repo = "arb";
rev = version;
sha256 = "sha256-JoBZZk824+O5kVctdUv0qzlX9l3X2RWr5/NPedx50oQ=";
};
});
});
shellPackages = (pkgs:
(with pkgs;
[ pyright python39Packages.jupyter sshfs arb]));
[ pyright python39Packages.jupyter sshfs arb (pkgs.texlive.combine {
inherit (pkgs.texlive) scheme-medium
type1cm unicode-math;
})]));
python = pkgs: pkgs.python39Full;
shellOverride = (pkgs: oldAttrs: {

View file

@ -0,0 +1,59 @@
import energy_shovel as es
import numpy as np
import qutip as qt
import matplotlib.pyplot as plt
import utilities as ut
import figsaver as fs
import hiro_models.model_auxiliary as aux
import plot_utils as pu
import ray
ray.shutdown()
ray.init(address="auto")
from hops.util.logging_setup import logging_setup
import logging
logging_setup(logging.INFO, show_stocproc=False)
Δ = 5
options = dict(
Δ=Δ,
periods=40,
modulate_system=True,
modulate_coupling=True,
bcf_terms=7,
k_max=5,
ω_c=2,
δ=.7,
bcf_norm_method = "unit_therm",
T=5,
description="Frictionless"
)
with_friction, strobe_t, strobe_indices = es.energy_shovel(
**(options | dict(H_mod=qt.sigmax()))
)
without_friction, _, _ = es.energy_shovel(**(options | dict(H_mod=qt.sigmaz())))
with_friction.description = r"With Friction $\sigma_x$"
with_friction_y, strobe_t, strobe_indices = es.energy_shovel(
**(options | dict(H_mod=qt.sigmay()))
)
with_friction_y.description = r"With Friction $\sigma_y$"
models = [with_friction, with_friction_y, without_friction]
# print(es.models_table(models))
aux.integrate_multi(models, 2000)
es.ergo(5)
f, _ = es.energy_friction_plot(models, Δ, strobe_indices)
fs.export_fig("quantum_friction", f)
pu.plot_energy_overview(without_friction, strobe_frequency=Δ)
pu.plot_energy_overview(with_friction, strobe_frequency=Δ)
plt.legend()
f, ax, _ = pu.plot_ρ(with_friction, 0, 1)
pu.plot_ρ(with_friction, 0, 1, strobe_frequency=Δ, ax=ax, markersize=5)

View file

@ -0,0 +1,5 @@
#! /usr/bin/env bash
workhorse="141.30.17.16"
sudo mount.nfs $workhorse:/data_local_huge/valentin/master/08_new/.data $(dirname "$0")/.data
sudo mount.nfs $workhorse:/data_local_huge/valentin/master/08_new/results $(dirname "$0")/results

View file

@ -1,75 +1,6 @@
import figsaver as fs
from hiro_models.one_qubit_model import QubitModel, StocProcTolerances
import hiro_models.model_auxiliary as aux
from hops.util.utilities import relative_entropy, relative_entropy_single, entropy, trace_distance
from hopsflow.util import EnsembleValue
import numpy as np
import qutip as qt
import scipy
import utilities as ut
import matplotlib
matplotlib.rcParams.update(fs.MPL_RC_POSTER)
import itertools
import ray
ray.shutdown()
ray.init(address="auto")
from hops.util.logging_setup import logging_setup
import logging
logging_setup(logging.INFO, show_stocproc=False)
from tabulate import tabulate
import hiro_models.model_auxiliary as aux
import hiro_models.model_base as Model
def org_tbl(dct: dict[str, Model]) -> str:
return tabulate(dct, headers=dct.keys(), tablefmt="orgtbl")
def print_diff_tbl(models):
print(
org_tbl(
aux.model_diff_dict(
models,
extra_fields=models[0].std_extra_fields
| {"Samples": lambda model: aux.get_data(model).samples},
)
)
)
def ergo(T, ω=1):
return (T * np.log(1 + np.exp(-ω / T)))
Δ = 2
model, strobe_t, strobe_indices = energy_shovel(Δ=Δ, γ=.5, periods=6)
from hops.util.dynamic_matrix import SmoothStep, Periodic, Harmonic, ConstantMatrix
Δ = 5
γ = 1 / Δ * 1 / 10
# , np.linspace(1.9, 2.3, 25)
# [[file:shovel_experiments.org::*Dependence on Cutoff][Dependence on Cutoff:1]]
ωs = np.unique(np.sort(np.concatenate([[.5], np.linspace(1, 1.8, 6)])))
ω_models = []
# ω_models = [QubitModel(
# δ=1/(ω_c),
# ω_c=ω_c,
# ω_s=1+Δ-ω_c,
# t=ut.linspace_with_strobe(0, t_max, 500, Δ),
# ψ_0=(0.5 * 0 * qt.basis([2], [0]) + qt.basis([2], [1])),
# description=f"Testing the time dependent coupling with smooth step.",
# k_max=5,
# bcf_terms=7,
# truncation_scheme="simplex",
# driving_process_tolerance=StocProcTolerances(1e-3, 1e-3),
# thermal_process_tolerance=StocProcTolerances(1e-3, 1e-3),
# T=3,
# L=L,
# H=H,
# therm_method="fft",
# ) for ω_c in ωs]
for ω_c in ωs:
proto, strobe_t, strobe_indices = energy_shovel(Δ, periods=30, modulate_system=False)
@ -97,12 +28,18 @@ fs.tex_value(
prefix="T=",
save="omega_delta",
)
# Dependence on Cutoff:1 ends here
# [[file:shovel_experiments.org::*Dependence on Cutoff][Dependence on Cutoff:2]]
aux.integrate_multi(ω_models, 10000)
# Dependence on Cutoff:2 ends here
# [[file:shovel_experiments.org::*Dependence on Cutoff][Dependence on Cutoff:3]]
from pprint import pprint
print_diff_tbl(ω_models)
# Dependence on Cutoff:3 ends here
# [[file:shovel_experiments.org::*Energy stuff][Energy stuff:1]]
fig, ax = plt.subplots()
fig.set_size_inches(fs.get_figsize("poster", 0.49))
for model, data in aux.model_data_iterator(ω_models):
@ -143,7 +80,9 @@ ax.set_ylabel(r"$(\langle H\rangle_\tau -\langle H\rangle_0)/\Delta E_\mathrm{ma
# ax.plot(model.t, model.L.operator_norm(model.t), linewidth=1)
ax.legend()
fs.export_fig("omegas_total")
# Energy stuff:1 ends here
# [[file:shovel_experiments.org::*Modulation Frequency Dependence][Modulation Frequency Dependence:1]]
from hops.util.dynamic_matrix import SmoothStep, Periodic, Harmonic, ConstantMatrix
@ -159,9 +98,13 @@ for Δ in Δs:
strobe_ts.append(strobe_t)
strobe_indices_s.append(strobe_indices)
Δ_models.append(proto)
# Modulation Frequency Dependence:1 ends here
# [[file:shovel_experiments.org::*Modulation Frequency Dependence][Modulation Frequency Dependence:2]]
aux.integrate_multi(Δ_models, 1000)
# Modulation Frequency Dependence:2 ends here
# [[file:shovel_experiments.org::*Modulation Frequency Dependence][Modulation Frequency Dependence:3]]
final_e = [[], []]
final_e_error = [[], []]
ensemble_arg = dict(overwrite_cache=False)
@ -199,3 +142,4 @@ for i, energy, σ in zip(itertools.count(0), final_e, final_e_error):
ax.errorbar(Δs, energy, σ, label=rf"$\alpha(0)$ = {δs[i]}")
ax.legend()
fs.export_fig("delta_dependence")
# Modulation Frequency Dependence:3 ends here

View file

@ -0,0 +1 @@
../plot_utils.py

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
#+PROPERTY: header-args :session 08_shovel :kernel python :pandoc no :async yes :tangle no
#+PROPERTY: header-args :session 08_shovel :kernel python :pandoc no :async yes :tangle no :noweb yes :comments link
#+begin_src jupyter-python :results none
#+name: boilerplate
#+begin_src jupyter-python :results none
import energy_shovel as es
import numpy as np
import qutip as qt
@ -8,17 +9,12 @@
import utilities as ut
import figsaver as fs
import hiro_models.model_auxiliary as aux
#+end_src
import plot_utils as pu
Init ray and silence stocproc.
#+begin_src jupyter-python :tangle night.py
import ray
ray.shutdown()
ray.init(address="auto")
#+end_src
#+begin_src jupyter-python :results none :tangle night.py
from hops.util.logging_setup import logging_setup
import logging
logging_setup(logging.INFO, show_stocproc=False)
@ -26,23 +22,184 @@ Init ray and silence stocproc.
* Shovel
** Fricionless vs Friction
:PROPERTIES:
:header-args: :tangle fric_v_nofric.py :session 08_fric_v_nofric :noweb yes :async yes
:END:
- we modulate only the system, once with σx once with σz
#+begin_src jupyter-python :results none
proto, strobe_t, strobe_indices = energy_shovel(Δ, periods=30, modulate_system=False)
for ω_c in ωs:
proto.δ = 2 / ω_c
proto.ω_c = ω_c
proto.ω_s = 1 + Δ - ω_c
proto.k_max = 7
proto.therm_method = "fft"
ω_models.append(proto)
#+begin_src jupyter-python
<<boilerplate>>
#+end_src
** No Bath mod vs Bath mod
#+RESULTS:
#+begin_src jupyter-python
Δ = 5
options = dict(
Δ=Δ,
periods=40,
modulate_system=True,
modulate_coupling=True,
bcf_terms=7,
k_max=5,
ω_c=2,
δ=.7,
bcf_norm_method = "unit_therm",
T=5,
description="Frictionless"
)
with_friction, strobe_t, strobe_indices = es.energy_shovel(
,**(options | dict(H_mod=qt.sigmax()))
)
without_friction, _, _ = es.energy_shovel(**(options | dict(H_mod=qt.sigmaz())))
with_friction.description = r"With Friction $\sigma_x$"
with_friction_y, strobe_t, strobe_indices = es.energy_shovel(
,**(options | dict(H_mod=qt.sigmay()))
)
with_friction_y.description = r"With Friction $\sigma_y$"
models = [with_friction, with_friction_y, without_friction]
# print(es.models_table(models))
#+end_src
#+RESULTS:
: \(λ=0.1, Δ=5, T=5\)
: \(λ=0.1, Δ=5, T=5\)
: \(λ=0.1, Δ=5, T=5\)
#+begin_src jupyter-python
aux.integrate_multi(models, 2000)
#+end_src
#+RESULTS:
#+begin_example
[INFO hops.core.integration 1919116] Choosing the nonlinear integrator.
[INFO hops.core.integration 1919116] Using 24 integrators.
[INFO hops.core.integration 1919116] Some 0 trajectories have to be integrated.
[INFO hops.core.integration 1919116] Using 792 hierarchy states.
0it [00:00, ?it/s]
[INFO hops.core.integration 1919116] Choosing the nonlinear integrator.
[INFO hops.core.integration 1919116] Using 24 integrators.
[INFO hops.core.integration 1919116] Some 0 trajectories have to be integrated.
[INFO hops.core.integration 1919116] Using 792 hierarchy states.
0it [00:00, ?it/s]
[INFO hops.core.integration 1919116] Choosing the nonlinear integrator.
[INFO hops.core.integration 1919116] Using 24 integrators.
[INFO hops.core.integration 1919116] Some 0 trajectories have to be integrated.
[INFO hops.core.integration 1919116] Using 792 hierarchy states.
0it [00:00, ?it/s]
#+end_example
#+begin_src jupyter-python
es.ergo(5)
#+end_src
#+RESULTS:
: 2.9906943469079588
#+begin_src jupyter-python
f, _ = es.energy_friction_plot(models, Δ, strobe_indices)
fs.export_fig("quantum_friction", f)
#+end_src
#+RESULTS:
[[file:./.ob-jupyter/14ef222d0be01acd82256fc3625773767dc4d381.svg]]
#+begin_src jupyter-python
pu.plot_energy_overview(without_friction, strobe_frequency=Δ)
pu.plot_energy_overview(with_friction, strobe_frequency=Δ)
plt.legend()
#+end_src
#+RESULTS:
:RESULTS:
: <matplotlib.legend.Legend at 0x7f616455ca90>
[[file:./.ob-jupyter/c9f3e34931d26016b8789cf3dee06cb3e7082cb1.svg]]
[[file:./.ob-jupyter/0817e1ad74f65fa7d0708142f48569e6b011f1b9.svg]]
:END:
#+begin_src jupyter-python
f, ax, _ = pu.plot_ρ(with_friction, 0, 1)
pu.plot_ρ(with_friction, 0, 1, strobe_frequency=Δ, ax=ax, markersize=5)
#+end_src
#+RESULTS:
:RESULTS:
| hline | <AxesSubplot:> | (None <AxesSubplot:> <ErrorbarContainer object of 3 artists>) |
[[file:./.ob-jupyter/878176ffdb8b483e2661b8b0c45ccd184123096f.svg]]
:END:
** No System mod vs System Mod
:PROPERTIES:
:header-args: :tangle sys_v_no_sys.py :session 08_shovel_sys_v_nosys :async yes :noweb yes
:END:
#+begin_src jupyter-python :noweb yes
<<boilerplate>>
#+end_src
#+RESULTS:
: 2022-08-23 14:36:56,791 INFO worker.py:956 -- Connecting to existing Ray cluster at address: 141.30.17.16:6379
#+begin_src jupyter-python
Δ = 5
options = dict(
Δ=Δ,
periods=40,
modulate_system=False,
modulate_coupling=True,
bcf_terms=7,
k_max=5,
ω_c=2,
δ=0.7,
bcf_norm_method="unit_therm",
T=5,
)
with_system, strobe_t, strobe_indices = es.energy_shovel(
,**(options | dict(modulate_system=True))
)
with_system.description = "System Modulation"
without_system, _, _ = es.energy_shovel(**(options | dict(modulate_system=False)))
without_system.description = "No System Modulation"
models = [without_system, with_system]
#+end_src
#+RESULTS:
: \(λ=0.1, Δ=5, T=5\)
: \(λ=0.1, Δ=5, T=5\)
#+begin_src jupyter-python
aux.integrate_multi(models, 10_000)
#+end_src
#+RESULTS:
: [INFO hops.core.integration 1918183] Choosing the nonlinear integrator.
: [INFO hops.core.integration 1918183] Using 24 integrators.
: [INFO hops.core.integration 1918183] Some 0 trajectories have to be integrated.
: [INFO hops.core.integration 1918183] Using 792 hierarchy states.
: 0it [00:00, ?it/s] 0it [00:00, ?it/s]
: [INFO hops.core.integration 1918183] Choosing the nonlinear integrator.
: [INFO hops.core.integration 1918183] Using 24 integrators.
: [INFO hops.core.integration 1918183] Some 0 trajectories have to be integrated.
: [INFO hops.core.integration 1918183] Using 792 hierarchy states.
: 0it [00:00, ?it/s] 0it [00:00, ?it/s]
#+begin_src jupyter-python
f, _ = es.energy_friction_plot(models, Δ, strobe_indices)
fs.export_fig("system_vs_no_system", f)
#+end_src
#+RESULTS:
[[file:./.ob-jupyter/d3772c4189195b19b49bf3cd1a3f9b017977faf2.svg]]
* Only Coupling Modulation
** Dependence on Cutoff

View file

@ -0,0 +1,2 @@
[FFT]
use_normalized_diff = True

View file

@ -0,0 +1,44 @@
import energy_shovel as es
import numpy as np
import qutip as qt
import matplotlib.pyplot as plt
import utilities as ut
import figsaver as fs
import hiro_models.model_auxiliary as aux
import plot_utils as pu
import ray
ray.shutdown()
ray.init(address="auto")
from hops.util.logging_setup import logging_setup
import logging
logging_setup(logging.INFO, show_stocproc=False)
Δ = 5
options = dict(
Δ=Δ,
periods=40,
modulate_system=False,
modulate_coupling=True,
bcf_terms=7,
k_max=5,
ω_c=2,
δ=0.7,
bcf_norm_method="unit_therm",
T=5,
)
with_system, strobe_t, strobe_indices = es.energy_shovel(
**(options | dict(modulate_system=True))
)
with_system.description = "System Modulation"
without_system, _, _ = es.energy_shovel(**(options | dict(modulate_system=False)))
without_system.description = "No System Modulation"
models = [without_system, with_system]
aux.integrate_multi(models, 10_000)
f, _ = es.energy_friction_plot(models, Δ, strobe_indices)
fs.export_fig("system_vs_no_system", f)