Skip to content

Commit

Permalink
Static ANSI code
Browse files Browse the repository at this point in the history
  • Loading branch information
obackhouse committed Mar 4, 2024
1 parent 1cc92c7 commit a6f5ffa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
32 changes: 16 additions & 16 deletions ebcc/brueckner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ebcc import numpy as np
from ebcc import util
from ebcc.damping import DIIS
from ebcc.logging import COLOURS
from ebcc.logging import ANSI
from ebcc.precision import types


Expand Down Expand Up @@ -80,13 +80,13 @@ def __init__(self, cc, log=None, options=None, **kwargs):

# Logging:
init_logging(cc.log)
cc.log.info(f"\n{COLOURS.B}{COLOURS.U}{self.name}{COLOURS.R}")
cc.log.info(f"{COLOURS.B}Options{COLOURS.R}:")
cc.log.info(f" > e_tol: {COLOURS.y}{self.options.e_tol}{COLOURS.R}")
cc.log.info(f" > t_tol: {COLOURS.y}{self.options.t_tol}{COLOURS.R}")
cc.log.info(f" > max_iter: {COLOURS.y}{self.options.max_iter}{COLOURS.R}")
cc.log.info(f" > diis_space: {COLOURS.y}{self.options.diis_space}{COLOURS.R}")
cc.log.info(f" > damping: {COLOURS.y}{self.options.damping}{COLOURS.R}")
cc.log.info(f"\n{ANSI.B}{ANSI.U}{self.name}{ANSI.R}")
cc.log.info(f"{ANSI.B}Options{ANSI.R}:")
cc.log.info(f" > e_tol: {ANSI.y}{self.options.e_tol}{ANSI.R}")
cc.log.info(f" > t_tol: {ANSI.y}{self.options.t_tol}{ANSI.R}")
cc.log.info(f" > max_iter: {ANSI.y}{self.options.max_iter}{ANSI.R}")
cc.log.info(f" > diis_space: {ANSI.y}{self.options.diis_space}{ANSI.R}")
cc.log.info(f" > damping: {ANSI.y}{self.options.damping}{ANSI.R}")
cc.log.debug("")

def get_rotation_matrix(self, u_tot=None, diis=None, t1=None):
Expand Down Expand Up @@ -297,12 +297,12 @@ def kernel(self):
self.cc.log.output("Solving for Brueckner orbitals.")
self.cc.log.debug("")
self.log.info(
f"{COLOURS.B}{'Iter':>4s} {'Energy (corr.)':>16s} {'Energy (tot.)':>18s} "
f"{'Conv.':>8s} {'Δ(Energy)':>13s} {'|T1|':>13s}{COLOURS.R}"
f"{ANSI.B}{'Iter':>4s} {'Energy (corr.)':>16s} {'Energy (tot.)':>18s} "
f"{'Conv.':>8s} {'Δ(Energy)':>13s} {'|T1|':>13s}{ANSI.R}"
)
self.log.info(
f"{0:4d} {self.cc.e_corr:16.10f} {self.cc.e_tot:18.10f} "
f"{[COLOURS.r, COLOURS.g][self.cc.converged]}{self.cc.converged!r:>8}{COLOURS.R}"
f"{[ANSI.r, ANSI.g][self.cc.converged]}{self.cc.converged!r:>8}{ANSI.R}"
)

converged = False
Expand Down Expand Up @@ -341,20 +341,20 @@ def kernel(self):
converged_t = dt < self.options.t_tol
self.log.info(
f"{niter:4d} {self.cc.e_corr:16.10f} {self.cc.e_tot:18.10f}"
f" {[COLOURS.r, COLOURS.g][self.cc.converged]}{self.cc.converged!r:>8}{COLOURS.R}"
f" {[COLOURS.r, COLOURS.g][converged_e]}{de:13.3e}{COLOURS.R}"
f" {[COLOURS.r, COLOURS.g][converged_t]}{dt:13.3e}{COLOURS.R}"
f" {[ANSI.r, ANSI.g][self.cc.converged]}{self.cc.converged!r:>8}{ANSI.R}"
f" {[ANSI.r, ANSI.g][converged_e]}{de:13.3e}{ANSI.R}"
f" {[ANSI.r, ANSI.g][converged_t]}{dt:13.3e}{ANSI.R}"
)

# Check for convergence:
converged = converged_e and converged_t
if converged:
self.log.debug("")
self.log.output(f"{COLOURS.g}Converged.{COLOURS.R}")
self.log.output(f"{ANSI.g}Converged.{ANSI.R}")
break
else:
self.log.debug("")
self.log.warning(f"{COLOURS.r}Failed to converge.{COLOURS.R}")
self.log.warning(f"{ANSI.r}Failed to converge.{ANSI.R}")

self.cc.log.debug("")
self.cc.log.output("E(corr) = %.10f", self.cc.e_corr)
Expand Down
42 changes: 21 additions & 21 deletions ebcc/rebcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ebcc.dump import Dump
from ebcc.eris import RERIs
from ebcc.fock import RFock
from ebcc.logging import COLOURS
from ebcc.logging import ANSI
from ebcc.precision import types
from ebcc.space import Space

Expand Down Expand Up @@ -323,19 +323,19 @@ def __init__(

# Logging:
init_logging(self.log)
self.log.info(f"\n{COLOURS.B}{COLOURS.U}{self.name}{COLOURS.R}")
self.log.debug(f"{COLOURS.B}{'*' * len(self.name)}{COLOURS.R}")
self.log.info(f"\n{ANSI.B}{ANSI.U}{self.name}{ANSI.R}")
self.log.debug(f"{ANSI.B}{'*' * len(self.name)}{ANSI.R}")
self.log.debug("")
self.log.info(f"{COLOURS.B}Options{COLOURS.R}:")
self.log.info(f" > e_tol: {COLOURS.y}{self.options.e_tol}{COLOURS.R}")
self.log.info(f" > t_tol: {COLOURS.y}{self.options.t_tol}{COLOURS.R}")
self.log.info(f" > max_iter: {COLOURS.y}{self.options.max_iter}{COLOURS.R}")
self.log.info(f" > diis_space: {COLOURS.y}{self.options.diis_space}{COLOURS.R}")
self.log.info(f" > damping: {COLOURS.y}{self.options.damping}{COLOURS.R}")
self.log.info(f"{ANSI.B}Options{ANSI.R}:")
self.log.info(f" > e_tol: {ANSI.y}{self.options.e_tol}{ANSI.R}")
self.log.info(f" > t_tol: {ANSI.y}{self.options.t_tol}{ANSI.R}")
self.log.info(f" > max_iter: {ANSI.y}{self.options.max_iter}{ANSI.R}")
self.log.info(f" > diis_space: {ANSI.y}{self.options.diis_space}{ANSI.R}")
self.log.info(f" > damping: {ANSI.y}{self.options.damping}{ANSI.R}")
self.log.debug("")
self.log.info(f"{COLOURS.B}Ansatz{COLOURS.R}: {COLOURS.m}{self.ansatz}{COLOURS.R}")
self.log.info(f"{ANSI.B}Ansatz{ANSI.R}: {ANSI.m}{self.ansatz}{ANSI.R}")
self.log.debug("")
self.log.info(f"{COLOURS.B}Space{COLOURS.R}: {COLOURS.m}{self.space}{COLOURS.R}")
self.log.info(f"{ANSI.B}Space{ANSI.R}: {ANSI.m}{self.space}{ANSI.R}")
self.log.debug("")

def kernel(self, eris=None):
Expand Down Expand Up @@ -372,8 +372,8 @@ def kernel(self, eris=None):
self.log.output("Solving for excitation amplitudes.")
self.log.debug("")
self.log.info(
f"{COLOURS.B}{'Iter':>4s} {'Energy (corr.)':>16s} {'Energy (tot.)':>18s} "
f"{'Δ(Energy)':>13s} {'Δ(Ampl.)':>13s}{COLOURS.R}"
f"{ANSI.B}{'Iter':>4s} {'Energy (corr.)':>16s} {'Energy (tot.)':>18s} "
f"{'Δ(Energy)':>13s} {'Δ(Ampl.)':>13s}{ANSI.R}"
)
self.log.info(f"{0:4d} {e_cc:16.10f} {e_cc + self.mf.e_tot:18.10f}")

Expand Down Expand Up @@ -404,19 +404,19 @@ def kernel(self, eris=None):
converged_t = dt < self.options.t_tol
self.log.info(
f"{niter:4d} {e_cc:16.10f} {e_cc + self.mf.e_tot:18.10f}"
f" {[COLOURS.r, COLOURS.g][converged_e]}{de:13.3e}{COLOURS.R}"
f" {[COLOURS.r, COLOURS.g][converged_t]}{dt:13.3e}{COLOURS.R}"
f" {[ANSI.r, ANSI.g][converged_e]}{de:13.3e}{ANSI.R}"
f" {[ANSI.r, ANSI.g][converged_t]}{dt:13.3e}{ANSI.R}"
)

# Check for convergence:
converged = converged_e and converged_t
if converged:
self.log.debug("")
self.log.output(f"{COLOURS.g}Converged.{COLOURS.R}")
self.log.output(f"{ANSI.g}Converged.{ANSI.R}")
break
else:
self.log.debug("")
self.log.warning(f"{COLOURS.r}Failed to converge.{COLOURS.R}")
self.log.warning(f"{ANSI.r}Failed to converge.{ANSI.R}")

# Include perturbative correction if required:
if self.ansatz.has_perturbative_correction:
Expand Down Expand Up @@ -489,7 +489,7 @@ def solve_lambda(self, amplitudes=None, eris=None):

self.log.output("Solving for de-excitation (lambda) amplitudes.")
self.log.debug("")
self.log.info(f"{COLOURS.B}{'Iter':>4s} {'Δ(Ampl.)':>13s}{COLOURS.R}")
self.log.info(f"{ANSI.B}{'Iter':>4s} {'Δ(Ampl.)':>13s}{ANSI.R}")

converged = False
for niter in range(1, self.options.max_iter + 1):
Expand All @@ -509,16 +509,16 @@ def solve_lambda(self, amplitudes=None, eris=None):

# Log the iteration:
converged = dl < self.options.t_tol
self.log.info(f"{niter:4d} {[COLOURS.r, COLOURS.g][converged]}{dl:13.3e}{COLOURS.R}")
self.log.info(f"{niter:4d} {[ANSI.r, ANSI.g][converged]}{dl:13.3e}{ANSI.R}")

# Check for convergence:
if converged:
self.log.debug("")
self.log.output(f"{COLOURS.g}Converged.{COLOURS.R}")
self.log.output(f"{ANSI.g}Converged.{ANSI.R}")
break
else:
self.log.debug("")
self.log.warning(f"{COLOURS.r}Failed to converge.{COLOURS.R}")
self.log.warning(f"{ANSI.r}Failed to converge.{ANSI.R}")

self.log.debug("")
self.log.debug("Time elapsed: %s", timer.format_time(timer()))
Expand Down
25 changes: 12 additions & 13 deletions ebcc/reom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ebcc import numpy as np
from ebcc import util
from ebcc.logging import COLOURS
from ebcc.logging import ANSI
from ebcc.precision import types


Expand Down Expand Up @@ -71,14 +71,14 @@ def __init__(self, ebcc, options=None, **kwargs):
self.v = None

# Logging:
self.log.info(f"\n{COLOURS.B}{COLOURS.U}{self.name}{COLOURS.R}")
self.log.debug(f"{COLOURS.B}{'*' * len(self.name)}{COLOURS.R}")
self.log.info(f"\n{ANSI.B}{ANSI.U}{self.name}{ANSI.R}")
self.log.debug(f"{ANSI.B}{'*' * len(self.name)}{ANSI.R}")
self.log.debug("")
self.log.info(f"{COLOURS.B}Options{COLOURS.R}:")
self.log.info(f" > nroots: {COLOURS.y}{self.options.nroots}{COLOURS.R}")
self.log.info(f" > e_tol: {COLOURS.y}{self.options.e_tol}{COLOURS.R}")
self.log.info(f" > max_iter: {COLOURS.y}{self.options.max_iter}{COLOURS.R}")
self.log.info(f" > max_space: {COLOURS.y}{self.options.max_space}{COLOURS.R}")
self.log.info(f"{ANSI.B}Options{ANSI.R}:")
self.log.info(f" > nroots: {ANSI.y}{self.options.nroots}{ANSI.R}")
self.log.info(f" > e_tol: {ANSI.y}{self.options.e_tol}{ANSI.R}")
self.log.info(f" > max_iter: {ANSI.y}{self.options.max_iter}{ANSI.R}")
self.log.info(f" > max_space: {ANSI.y}{self.options.max_space}{ANSI.R}")
self.log.debug("")

def amplitudes_to_vector(self, *amplitudes):
Expand Down Expand Up @@ -223,11 +223,11 @@ def davidson(self, eris=None, guesses=None):
# Check for convergence:
if all(converged):
self.log.debug("")
self.log.output(f"{COLOURS.g}Converged.{COLOURS.R}")
self.log.output(f"{ANSI.g}Converged.{ANSI.R}")
else:
self.log.debug("")
self.log.warning(
f"{COLOURS.r}Failed to converge {sum(not c for c in converged)} roots.{COLOURS.R}"
f"{ANSI.r}Failed to converge {sum(not c for c in converged)} roots.{ANSI.R}"
)

# Update attributes:
Expand All @@ -237,14 +237,13 @@ def davidson(self, eris=None, guesses=None):

self.log.debug("")
self.log.output(
f"{COLOURS.B}{'Root':>4s} {'Energy':>16s} {'Weight':>13s} {'Conv.':>8s}{COLOURS.R}"
f"{ANSI.B}{'Root':>4s} {'Energy':>16s} {'Weight':>13s} {'Conv.':>8s}{ANSI.R}"
)
for n, (en, vn, cn) in enumerate(zip(e, v, converged)):
r1n = self.vector_to_amplitudes(vn)[0]
qpwt = self._quasiparticle_weight(r1n)
self.log.output(
f"{n:>4d} {en:>16.10f} {qpwt:>13.5g} "
f"{[COLOURS.r, COLOURS.g][cn]}{cn!r:>8s}{COLOURS.R}"
f"{n:>4d} {en:>16.10f} {qpwt:>13.5g} " f"{[ANSI.r, ANSI.g][cn]}{cn!r:>8s}{ANSI.R}"
)

self.log.debug("")
Expand Down

0 comments on commit a6f5ffa

Please sign in to comment.