Skip to content

Commit

Permalink
Enhance green-kubo transport and refactor transport module (#97)
Browse files Browse the repository at this point in the history
* update green-kubo transport and refactor transport module
- `TransportAutoCorr` is renamed to `TransportKubo` and `ChargeTransport` is renamed to `ChargeDiffusionDynamics` for accuracy.
- In `TransportKubo` the current operator are now automatically constructed from `MolList2`.
- If Peielrs terms are present in the model `TransportKubo` will split the current operator into two parts and obtain 5 sets of autocorrelation functions in total.

* rename `transport.py` in `example`

* rename `ChargeTransport` in `./example/fmo.py`

* fix several bugs
  • Loading branch information
liwt31 authored Jul 2, 2020
1 parent 54cf9c1 commit 8837a13
Show file tree
Hide file tree
Showing 20 changed files with 643 additions and 343 deletions.
14 changes: 8 additions & 6 deletions doc/source/ct.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Charge Transport
*************************************

charge diffusion simulation
Obtain mobility by Green-Kubo formula
===============================
.. automodule:: renormalizer.transport.kubo
:members:

Charge diffusion simulation dynamics
===========================
.. automodule:: renormalizer.transport.transport
.. automodule:: renormalizer.transport.dynamics
:members:


obtain mobility by Kubo formula
===============================
.. automodule:: renormalizer.transport.autocorr
:members:

14 changes: 7 additions & 7 deletions example/transport.py → example/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import yaml

from renormalizer.model import load_from_dict
from renormalizer.transport import ChargeTransport
from renormalizer.utils import log, Quantity, EvolveConfig, EvolveMethod, RungeKutta, CompressConfig
from renormalizer.transport import ChargeDiffusionDynamics
from renormalizer.utils import log, EvolveConfig, EvolveMethod, CompressConfig

logger = logging.getLogger(__name__)

Expand All @@ -27,15 +27,15 @@
mol_list, temperature = load_from_dict(param, 3, False)
compress_config = CompressConfig(max_bonddim=16)
evolve_config = EvolveConfig(EvolveMethod.tdvp_ps, adaptive=True, guess_dt=2)
ct = ChargeTransport(
cdd = ChargeDiffusionDynamics(
mol_list,
temperature=temperature,
compress_config=compress_config,
evolve_config=evolve_config,
rdm=False,
)
ct.dump_dir = param["output dir"]
ct.job_name = param["fname"]
ct.custom_dump_info["comment"] = param["comment"]
ct.evolve(param.get("evolve dt"), param.get("nsteps"), param.get("evolve time"))
cdd.dump_dir = param["output dir"]
cdd.job_name = param["fname"]
cdd.custom_dump_info["comment"] = param["comment"]
cdd.evolve(param.get("evolve dt"), param.get("nsteps"), param.get("evolve time"))
# ct.evolve(evolve_dt, 100, param.get("evolve time"))
4 changes: 2 additions & 2 deletions example/fmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from renormalizer.model import Phonon, Mol, MolList
from renormalizer.utils import Quantity, EvolveConfig, CompressConfig, CompressCriteria, EvolveMethod
from renormalizer.utils.constant import cm2au
from renormalizer.transport import ChargeTransport, InitElectron
from renormalizer.transport import ChargeDiffusionDynamics, InitElectron

import numpy as np

Expand Down Expand Up @@ -157,7 +157,7 @@
evolve_dt = 160
evolve_config = EvolveConfig(EvolveMethod.tdvp_ps, guess_dt=evolve_dt)
compress_config = CompressConfig(CompressCriteria.fixed, max_bonddim=32)
ct = ChargeTransport(mol_list, evolve_config=evolve_config, compress_config=compress_config, init_electron=InitElectron.fc)
ct = ChargeDiffusionDynamics(mol_list, evolve_config=evolve_config, compress_config=compress_config, init_electron=InitElectron.fc)
ct.dump_dir = "./"
ct.job_name = 'fmo'
ct.stop_at_edge = False
Expand Down
4 changes: 2 additions & 2 deletions example/run.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export PYTHONPATH=../:PYTHONPATH
code=0
for python_args in fmo.py sbm.py h2o_qc.py "transport.py std.yaml" "transport_autocorr.py std.yaml"; do
for python_args in fmo.py sbm.py h2o_qc.py "dynamics.py std.yaml" "transport_kubo.py std.yaml"; do
echo ============================$python_args=============================
timeout 20s python $python_args
exit_code=$?
echo ============================$python_args=============================
# the time out exit code or normal exit code
# if not the time out exit code or normal exit code
if [ $exit_code -ne 124 ] && [ $exit_code -ne 0 ]; then
echo "The script failed with exit code $exit_code" >&2
code=1
Expand Down
8 changes: 4 additions & 4 deletions example/transport_autocorr.py → example/transport_kubo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import yaml

from renormalizer.model import load_from_dict
from renormalizer.transport import TransportAutoCorr
from renormalizer.transport import TransportKubo
from renormalizer.utils import log, Quantity, EvolveConfig, EvolveMethod, RungeKutta, CompressConfig, BondDimDistri

logger = logging.getLogger(__name__)
Expand All @@ -28,9 +28,9 @@
compress_config = CompressConfig(threshold=1e-4)
ievolve_config = EvolveConfig(adaptive=True, guess_dt=temperature.to_beta() / 1000j)
evolve_config = EvolveConfig(adaptive=True, guess_dt=2)
ct = TransportAutoCorr(mol_list, temperature=temperature, ievolve_config=ievolve_config,
compress_config=compress_config, evolve_config=evolve_config, dump_dir=param["output dir"],
job_name=param["fname"] + "_autocorr")
ct = TransportKubo(mol_list, temperature=temperature, ievolve_config=ievolve_config,
compress_config=compress_config, evolve_config=evolve_config, dump_dir=param["output dir"],
job_name=param["fname"] + "_autocorr")
# ct.latest_mps.compress_add = True
ct.evolve(param.get("evolve dt"), param.get("nsteps"), param.get("evolve time"))
# ct.evolve(evolve_dt, 100, param.get("evolve time"))
34 changes: 33 additions & 1 deletion renormalizer/model/mlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Author: Jiajun Ren <jiajunren0522@gmail.com>

import copy
from collections import OrderedDict
from collections import OrderedDict, defaultdict
from typing import List, Union, Dict
from enum import Enum

Expand Down Expand Up @@ -489,6 +489,7 @@ def get_pure_dmrg_mollist(self):

def mol_list2_para(self, formula="vibronic"):
mol_list2 = MolList2.MolList_to_MolList2(self, formula)
self.multi_dof_basis = self.scheme == 4
self.order = mol_list2.order
self.basis = mol_list2.basis
self.model = mol_list2.model
Expand All @@ -510,6 +511,7 @@ def rewrite_model(self, model, model_translator):
mol_list_new.basis = self.basis
mol_list_new.model = model
mol_list_new.model_translator = model_translator
mol_list_new.multi_dof_basis = self.multi_dof_basis
return mol_list_new

def __getitem__(self, idx):
Expand Down Expand Up @@ -553,3 +555,33 @@ def load_from_dict(param, scheme, lam: bool):
j_constant, scheme=scheme
)
return mol_list, temperature


def vibronic_to_general(model):
new_model = defaultdict(list)
for e_k, e_v in model.items():
for kk, vv in e_v.items():
# it's difficult to rename `kk` because sometimes it's related to
# phonons sometimes it's `"J"`
if e_k == "I":
# operators without electronic dof, simple phonon
new_model[kk] = vv
else:
# operators with electronic dof
assert isinstance(e_k, tuple) and len(e_k) == 2
if e_k[0] == e_k[1]:
# diagonal
new_e_k = (e_k[0],)
e_op = (Op(r"a^\dagger a", 0),)
else:
# off-diagonal
new_e_k = e_k
e_op = (Op(r"a^\dagger", 1), Op("a", -1))
if kk == "J":
new_model[new_e_k] = [e_op + (vv,)]
else:
for term in vv:
new_key = new_e_k + kk
new_value = e_op + term
new_model[new_key].append(new_value)
return new_model
8 changes: 3 additions & 5 deletions renormalizer/mps/mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,17 +1808,16 @@ def _mu_regularize(s, epsilon=1e-10):

class BraKetPair:
def __init__(self, bra_mps, ket_mps, mpo=None):
# do copy so that clear_memory won't clear previous braket
self.bra_mps = bra_mps.copy()
self.ket_mps = ket_mps.copy()
self.bra_mps = bra_mps
self.ket_mps = ket_mps
self.mpo = mpo
self.ft = self.calc_ft()

def calc_ft(self):
if self.mpo is None:
dot = self.bra_mps.conj().dot(self.ket_mps)
else:
dot = self.bra_mps.conj().expectation(self.mpo, self.ket_mps)
dot = self.ket_mps.expectation(self.mpo, self.bra_mps.conj())
return complex(
dot * np.conjugate(self.bra_mps.coeff)
* self.ket_mps.coeff
Expand All @@ -1833,7 +1832,6 @@ def __str__(self):
ft_str = "%g" % self.ft
return "bra: %s, ket: %s, ft: %s" % (self.bra_mps, self.ket_mps, ft_str)

# todo: not used?
def __iter__(self):
return iter((self.bra_mps, self.ket_mps))

Expand Down
4 changes: 2 additions & 2 deletions renormalizer/tests/parameter_exact.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from renormalizer.mps import Mpo
from renormalizer.model import Phonon, Mol, MolList
from renormalizer.utils import Quantity
from renormalizer.utils.qutip_utils import get_clist, get_blist, get_hamiltonian, get_gs
from renormalizer.utils.qutip_utils import get_clist, get_blist, get_holstein_hamiltonian, get_gs


OMEGA = 1
Expand All @@ -21,6 +21,6 @@
qutip_blist = get_blist(N_SITES, N_LEVELS)

G = np.sqrt(DISPLACEMENT**2 * OMEGA / 2)
qutip_h = get_hamiltonian(N_SITES, J, OMEGA, G, qutip_clist, qutip_blist)
qutip_h = get_holstein_hamiltonian(N_SITES, J, OMEGA, G, qutip_clist, qutip_blist)

qutip_gs = get_gs(N_SITES, N_LEVELS)
4 changes: 2 additions & 2 deletions renormalizer/transport/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Author: Jiajun Ren <jiajunren0522@gmail.com>

from renormalizer.transport.transport import ChargeTransport, InitElectron, EDGE_THRESHOLD
from renormalizer.transport.autocorr import TransportAutoCorr
from renormalizer.transport.kubo import TransportKubo
from renormalizer.transport.dynamics import ChargeDiffusionDynamics, InitElectron, EDGE_THRESHOLD
164 changes: 0 additions & 164 deletions renormalizer/transport/autocorr.py

This file was deleted.

Loading

0 comments on commit 8837a13

Please sign in to comment.