Skip to content

Commit 9f8a5ba

Browse files
authored
Merge pull request #142 from issp-center-dev/bse_only_chiloc
[bse]calc_only_chiloc option
2 parents 733c10e + 7a277be commit 9f8a5ba

File tree

8 files changed

+98
-103
lines changed

8 files changed

+98
-103
lines changed

src/dcore/dcore_bse.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from dcore._dispatcher import HDFArchive, dyson
2929
from dcore.dmft_core import DMFTCoreSolver
30-
from dcore.program_options import create_parser, parse_parameters
30+
from dcore.program_options import create_parser, parse_parameters, delete_parameters, print_parameters
3131
from dcore.tools import *
3232
from dcore import impurity_solvers
3333
from .sumkdft_workers.launcher import run_sumkdft
@@ -52,7 +52,7 @@ def compare_str_list(list1, list2):
5252

5353

5454
def calc_g2_in_impurity_model(solver_name, solver_params, mpirun_command, basis_rot, Umat, gf_struct, beta, n_iw,
55-
Sigma_iw, Gloc_iw, num_wb, num_wf, ish, freqs=None):
55+
Sigma_iw, Gloc_iw, num_wb, num_wf, only_chiloc, ish, freqs=None):
5656
"""
5757
5858
Calculate G2 in an impurity model
@@ -86,24 +86,29 @@ def calc_g2_in_impurity_model(solver_name, solver_params, mpirun_command, basis_
8686
# Solve the model
8787
rot = impurity_solvers.compute_basis_rot(basis_rot, sol)
8888
if flag_box:
89-
xloc, chiloc = sol.calc_Xloc_ph(rot, mpirun_command, num_wf, num_wb, s_params)
89+
xloc, chiloc = sol.calc_Xloc_ph(rot, mpirun_command, num_wf, num_wb, s_params, only_chiloc)
9090
else:
9191
xloc, chiloc = sol.calc_Xloc_ph_sparse(rot, mpirun_command, freqs, num_wb, s_params)
9292

9393
# Check results for x_loc
9494
print("\n Checking x_loc...")
95-
assert isinstance(xloc, dict)
96-
for key, data in list(xloc.items()):
97-
# print(" ", key)
98-
if flag_box:
99-
assert data.shape == (num_wb, 2*num_wf, 2*num_wf)
100-
else:
101-
assert data.shape == (freqs.shape[0],)
102-
print(" OK")
95+
if xloc is None:
96+
print(" not computed")
97+
else:
98+
assert isinstance(xloc, dict)
99+
for key, data in list(xloc.items()):
100+
# print(" ", key)
101+
if flag_box:
102+
assert data.shape == (num_wb, 2*num_wf, 2*num_wf)
103+
else:
104+
assert data.shape == (freqs.shape[0],)
105+
print(" OK")
103106

104107
# Check results for chi_loc
105-
if chiloc is not None:
106-
print("\n Checking chi_loc...")
108+
print("\n Checking chi_loc...")
109+
if chiloc is None:
110+
print(" not computed")
111+
else:
107112
assert isinstance(chiloc, dict)
108113
for key, data in list(chiloc.items()):
109114
# print(" ", key)
@@ -498,9 +503,12 @@ def calc_num_flavors(_ish):
498503
self._beta, self._n_iw,
499504
self._sh_quant[ish].Sigma_iw, Gloc_iw_sh[ish],
500505
self._params['bse']['num_wb'],
501-
self._params['bse']['num_wf'], ish, freqs=freqs)
506+
self._params['bse']['num_wf'],
507+
self._params['bse']['calc_only_chiloc'],
508+
ish, freqs=freqs)
502509

503-
subtract_disconnected(x_loc, g_imp, self.spin_block_names, freqs=freqs)
510+
if x_loc is not None:
511+
subtract_disconnected(x_loc, g_imp, self.spin_block_names, freqs=freqs)
504512

505513
# Open HDF5 file to improve performance. Close manually.
506514
bse.h5bse.open('a')
@@ -509,7 +517,8 @@ def calc_num_flavors(_ish):
509517
for icrsh in range(self._n_corr_shells):
510518
if ish == self._sk.corr_to_inequiv[icrsh]:
511519
# X_loc
512-
bse.save_xloc(x_loc, icrsh=icrsh)
520+
if x_loc is not None:
521+
bse.save_xloc(x_loc, icrsh=icrsh)
513522
# chi_loc
514523
if chi_loc is not None:
515524
bse.save_chiloc(chi_loc, icrsh=icrsh)
@@ -618,7 +627,7 @@ def dcore_bse(filename, np=1):
618627
#
619628
# Construct a parser with default values
620629
#
621-
pars = create_parser()
630+
pars = create_parser(['model', 'system', 'impurity_solver', 'mpi', 'bse'])
622631

623632
#
624633
# Parse keywords and store
@@ -629,6 +638,13 @@ def dcore_bse(filename, np=1):
629638
seedname = p["model"]["seedname"]
630639
p["mpi"]["num_processes"] = np
631640

641+
# Delete unnecessary parameters
642+
delete_parameters(p, block='model', delete=['bvec'])
643+
delete_parameters(p, block='system', retain=['beta', 'n_iw', 'mu', 'fix_mu', 'prec_mu', 'with_dc', 'no_tail_fit'])
644+
645+
# Summary of input parameters
646+
print_parameters(p)
647+
632648
#
633649
# Load DMFT data
634650
#
@@ -638,14 +654,11 @@ def dcore_bse(filename, np=1):
638654
print("Number of iterations :", solver.iteration_number)
639655

640656
#
641-
# Compute data for BSE
657+
# Calculate quantities necessary for BSE
642658
#
643659
solver.calc_bse()
644660

645-
646-
#
647661
# Finish
648-
#
649662
print("\n################# Done #####################\n")
650663

651664

src/dcore/impurity_solvers/alps_cthyb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def to_numpy_array(g, block_names):
4343
Rearrange spins and orbitals so that up and down spins appear alternatingly.
4444
If there is a single block, we assume that spin and down spins appear alternatignly.
4545
If there are two blocks, we assume that they are spin1 and spin2 sectors.
46-
46+
4747
Note by HS: The comment above may be wrong. The correct one may be
4848
If there is a single block, we assume that a up-spin block is followed by a down-spin block.
4949
"""
@@ -125,7 +125,7 @@ def solve(self, rot, mpirun_command, params_kw):
125125

126126
self._solve_impl(rot, mpirun_command, None, params_kw)
127127

128-
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw):
128+
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw, only_chiloc):
129129
raise RuntimeError("calc_Xloc_ph is not implemented!")
130130

131131
def calc_G2loc_ph_sparse(self, rot, mpirun_command, wsample_ph, params_kw):

src/dcore/impurity_solvers/alps_cthyb_seg.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -413,29 +413,13 @@ def set_blockgf_from_h5(sigma, group):
413413
# [(s1,o1), (s2,o2), 0]
414414
self.quant_to_save['nn_equal_time'] = nn_equal_time[:, :, 0] # copy
415415

416-
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw):
416+
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw, only_chiloc):
417417
"""
418-
compute local G2 in p-h channel
419-
X_loc = < c_{i1}^+ ; c_{i2} ; c_{i4}^+ ; c_{i3} >
418+
Compute local G2 in p-h channel
420419
421-
Parameters
422-
----------
423-
rot
424-
mpirun_command
425-
num_wf
426-
num_wb
427-
params_kw
428-
429-
Returns
430-
-------
431-
G2_loc : dict
432-
key = (i1, i2, i3, i4)
433-
val = numpy.ndarray(n_w2b, 2*n_w2f, 2*n_w2f)
434-
435-
chi_loc : dict (None if not computed)
436-
key = (i1, i2, i3, i4)
437-
val = numpy.ndarray(n_w2b)
420+
For details, see SolverBase.calc_Xloc_ph
438421
"""
422+
439423
if rot is not None:
440424
# TODO
441425
raise NotImplementedError

src/dcore/impurity_solvers/base.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,32 @@ def solve(self, rot, mpirun_command, params):
147147

148148
# Set self.Gimp_iw, self.G_tau, self.Sigma_iw
149149

150-
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw):
150+
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw, only_chiloc):
151151
"""
152-
Compute Xloc(m, n, n') in p-h channel
153-
and chi_loc(m) (optional)
154-
152+
Compute local G2 in p-h channel
153+
X_loc = < c_{i1}^+ ; c_{i2} ; c_{i4}^+ ; c_{i3} >, and
154+
chi_loc = < c_{i1}^+ c_{i2} ; c_{i4}^+ c_{i3} > (optional)
155155
156156
Parameters
157157
----------
158-
num_wf:
158+
num_wf: int
159159
Number of non-negative fermionic frequencies
160-
num_wb:
160+
num_wb: int
161161
Number of non-negative bosonic frequencies
162+
only_chiloc: bool
163+
If True, only chi_loc is computed (no Xloc).
162164
163165
The other parameters are the same as for solve().
164166
165167
Returns
166168
-------
169+
X_loc : dict
170+
key : (i1, i2, i3, i4)
171+
val : numpy.ndarray(n_w2b, 2*n_w2f, 2*n_w2f)
167172
168-
Xloc(m, n, n') : 3d ndarray of complex type
169-
Data for -num_wf <= n, n' < num_wf and m = 0, 1, ..., num_wb-1.
170-
171-
chi_loc(m) : 1d ndarray of complex type
172-
return None if not computed
173+
chi_loc : dict (None if not computed)
174+
key : (i1, i2, i3, i4)
175+
val : numpy.ndarray(n_w2b)
173176
174177
"""
175178
return NotImplementedError()

src/dcore/impurity_solvers/jo_cthyb_seg.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -357,28 +357,11 @@ def _read(key):
357357
# [(s1,o1), (s2,o2), 0]
358358
# self.quant_to_save['nn_equal_time'] = nn_equal_time[:, :, 0] # copy
359359

360-
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw):
360+
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw, only_chiloc):
361361
"""
362-
compute local G2 in p-h channel
363-
X_loc = < c_{i1}^+ ; c_{i2} ; c_{i4}^+ ; c_{i3} >
364-
365-
Parameters
366-
----------
367-
rot
368-
mpirun_command
369-
num_wf
370-
num_wb
371-
params_kw
372-
373-
Returns
374-
-------
375-
G2_loc : dict
376-
key = (i1, i2, i3, i4)
377-
val = numpy.ndarray(n_w2b, 2*n_w2f, 2*n_w2f)
378-
379-
chi_loc : dict (None if not computed)
380-
key = (i1, i2, i3, i4)
381-
val = numpy.ndarray(n_w2b)
362+
Compute local G2 in p-h channel
363+
364+
For details, see SolverBase.calc_Xloc_ph
382365
"""
383366
raise NotImplementedError
384367

src/dcore/impurity_solvers/pomerol.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -293,44 +293,41 @@ def _read_chiloc(self, params_kw):
293293
dir_suscep = params_kw.get('dir_suscep', './susceptibility')
294294
return self._read_common(dir_suscep)
295295

296-
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw):
296+
def calc_Xloc_ph(self, rot, mpirun_command, num_wf, num_wb, params_kw, only_chiloc):
297297
"""
298-
compute local G2 in p-h channel
299-
X_loc = < c_{i1}^+ ; c_{i2} ; c_{i4}^+ ; c_{i3} >
298+
Compute local G2 in p-h channel
300299
301-
Parameters
302-
----------
303-
rot
304-
mpirun_command
305-
num_wf
306-
num_wb
307-
params_kw
308-
309-
Returns
310-
-------
311-
G2_loc : dict
312-
key = (i1, i2, i3, i4)
313-
val = numpy.ndarray(n_w2b, 2*n_w2f, 2*n_w2f)
314-
315-
chi_loc : dict (None if not computed)
316-
key = (i1, i2, i3, i4)
317-
val = numpy.ndarray(n_w2b)
300+
For details, see SolverBase.calc_Xloc_ph
318301
"""
319302

320-
params_kw['flag_vx'] = 1
321-
params_kw['n_w2f'] = num_wf
322-
params_kw['n_w2b'] = num_wb
303+
# Set parameters
304+
if only_chiloc:
305+
print("\n Calc only chi_loc (X_loc is not computed)\n")
306+
params_kw['flag_vx'] = 0
307+
else:
308+
params_kw['flag_vx'] = 1
309+
params_kw['n_w2f'] = num_wf
310+
params_kw['n_w2b'] = num_wb
311+
323312
params_kw['flag_suscep'] = 1
324313
params_kw['n_wb'] = num_wb
325314

315+
# Run the impurity solver
326316
self.solve(rot, mpirun_command, params_kw)
327317

328-
g2_loc = self._read_g2loc(params_kw)
329-
# 1d array --> (wb, wf1, wf2)
330-
for key, data in list(g2_loc.items()):
331-
g2_loc[key] = data.reshape((num_wb, 2*num_wf, 2*num_wf))
318+
# Get results if computed
319+
g2_loc = chi_loc = None
320+
321+
# X_loc
322+
if params_kw['flag_vx']:
323+
g2_loc = self._read_g2loc(params_kw)
324+
# 1d array --> (wb, wf1, wf2)
325+
for key, data in list(g2_loc.items()):
326+
g2_loc[key] = data.reshape((num_wb, 2*num_wf, 2*num_wf))
332327

333-
chi_loc = self._read_chiloc(params_kw)
328+
# chi_loc
329+
if params_kw['flag_suscep']:
330+
chi_loc = self._read_chiloc(params_kw)
334331

335332
return g2_loc, chi_loc
336333

src/dcore/program_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def create_parser(target_sections=None):
150150
parser.add_option("bse", "h5_output_file", str, 'dmft_bse.h5', "Output HDF5 file for bse data")
151151
parser.add_option("bse", "skip_X0q_if_exists", bool, False, "Skip X_0(q) calc if file already exists")
152152
parser.add_option("bse", "skip_Xloc", bool, False, "Skip X_loc calc (for RPA)")
153+
parser.add_option("bse", "calc_only_chiloc", bool, False, "Calculate only chi_loc but no X_loc (for SCL, rRPA).")
153154
parser.add_option("bse", "use_temp_file", bool, False, "Whether or not temporary file is used in computing X0_q. This option will reduce the memory footprints.")
154155
parser.add_option("bse", "X0q_qpoints_saved", str, 'quadrant', "Specifies for which q points X0q are saved in a HDF file. quadrant or path to a q_path.dat file.")
155156

@@ -240,6 +241,9 @@ def parse_parameters(params):
240241
if params['tool']['n_pade_max'] < 0:
241242
params['tool']['n_pade_max'] = params['system']['n_iw']
242243

244+
if 'bse' in params:
245+
two_options_incompatible(params, ('bse', 'skip_Xloc'), ('bse', 'calc_only_chiloc'))
246+
243247

244248
def parse_knode(knode_string):
245249
"""

src/dcore/sumkdft_opt.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ def eff_atomic_levels(self):
854854
eff_atlevels = None
855855
return mpi.bcast(eff_atlevels)
856856

857+
# This replacement does not work when np_mpi > nk
857858
def calculate_min_max_band_energies(self):
858859
# hop = self.hopping
859860
# diag_hop = numpy.zeros(hop.shape[:-1])
@@ -871,6 +872,16 @@ def calculate_min_max_band_energies(self):
871872
self.max_band_energy = max_band_energy
872873
return min_band_energy, max_band_energy
873874

875+
# Simply set 0
876+
def calculate_min_max_band_energies(self):
877+
if mpi.is_master_node():
878+
warn("Set min_band_energy=0 and max_band_energy=0 when hopping_part is used.")
879+
min_band_energy = 0
880+
max_band_energy = 0
881+
self.min_band_energy = min_band_energy
882+
self.max_band_energy = max_band_energy
883+
return min_band_energy, max_band_energy
884+
874885
# This method is not used for the moment.
875886
# Actually, replacement is simple.
876887
def calc_density_correction(self, filename=None, dm_type='wien2k'):

0 commit comments

Comments
 (0)