Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions ebcc/cc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ebcc.ext.eccc import BaseExternalCorrection
from ebcc.ext.tcc import BaseTailor
from ebcc.ham.base import BaseElectronBoson, BaseFock
from ebcc.opt.base import BaseBruecknerEBCC
from ebcc.opt.base import BaseBruecknerEBCC, BaseOptimisedEBCC
from ebcc.util import Namespace

T = floating
Expand Down Expand Up @@ -81,6 +81,7 @@ class BaseEBCC(ABC):
CDERIs: type[BaseERIs]
ElectronBoson: type[BaseElectronBoson]
Brueckner: type[BaseBruecknerEBCC]
Optimised: type[BaseOptimisedEBCC]
ExternalCorrection: type[BaseExternalCorrection]
Tailor: type[BaseTailor]

Expand Down Expand Up @@ -294,11 +295,11 @@ def kernel(self, eris: Optional[ERIsInputType] = None) -> float:
converged = converged_e and converged_t
if converged:
self.log.debug("")
self.log.output(f"{ANSI.g}Converged.{ANSI.R}")
self.log.output(f"{ANSI.g}Converged{ANSI.R}.")
break
else:
self.log.debug("")
self.log.warning(f"{ANSI.r}Failed to converge.{ANSI.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 @@ -385,11 +386,11 @@ def solve_lambda(
# Check for convergence:
if converged:
self.log.debug("")
self.log.output(f"{ANSI.g}Converged.{ANSI.R}")
self.log.output(f"{ANSI.g}Converged{ANSI.R}.")
break
else:
self.log.debug("")
self.log.warning(f"{ANSI.r}Failed to converge.{ANSI.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 Expand Up @@ -451,6 +452,21 @@ def brueckner(self, *args: Any, **kwargs: Any) -> float:
bcc = self.Brueckner(self, *args, **kwargs)
return bcc.kernel()

def optimised(self, *args: Any, **kwargs: Any) -> float:
"""Run an optimised coupled cluster calculation.

The coupled cluster object will be updated in-place.

Args:
*args: Arguments to pass to the optimised object.
**kwargs: Keyword arguments to pass to the optimised object.

Returns:
Correlation energy.
"""
opt = self.Optimised(self, *args, **kwargs)
return opt.kernel()

def external_correction(self, *args: Any, **kwargs: Any) -> float:
"""Run an externally corrected coupled cluster calculation.

Expand Down Expand Up @@ -625,7 +641,7 @@ def energy(
eris=eris,
amplitudes=amplitudes,
)
res: float = ensure_scalar(func(**kwargs)).real
res: float = np.real(ensure_scalar(func(**kwargs)))
return astype(res, float)

def energy_perturbative(
Expand All @@ -650,7 +666,7 @@ def energy_perturbative(
amplitudes=amplitudes,
lambdas=lambdas,
)
res: float = ensure_scalar(func(**kwargs)).real
res: float = np.real(ensure_scalar(func(**kwargs)))
return res

@abstractmethod
Expand Down
3 changes: 2 additions & 1 deletion ebcc/cc/gebcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ebcc.ham.eris import GERIs
from ebcc.ham.fock import GFock
from ebcc.ham.space import Space
from ebcc.opt.gbrueckner import BruecknerGEBCC
from ebcc.opt.gopt import BruecknerGEBCC, OptimisedGEBCC

if TYPE_CHECKING:
from typing import Any, Optional, TypeAlias, Union
Expand Down Expand Up @@ -47,6 +47,7 @@ class GEBCC(BaseEBCC):
Fock = GFock
ElectronBoson = GElectronBoson
Brueckner = BruecknerGEBCC
Optimised = OptimisedGEBCC
ExternalCorrection = ExternalCorrectionGEBCC
Tailor = TailorGEBCC

Expand Down
3 changes: 2 additions & 1 deletion ebcc/cc/rebcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ebcc.ham.eris import RERIs
from ebcc.ham.fock import RFock
from ebcc.ham.space import Space
from ebcc.opt.rbrueckner import BruecknerREBCC
from ebcc.opt.ropt import BruecknerREBCC, OptimisedREBCC

if TYPE_CHECKING:
from typing import Any, Optional, TypeAlias, Union
Expand All @@ -43,6 +43,7 @@ class REBCC(BaseEBCC):
CDERIs = RCDERIs
ElectronBoson = RElectronBoson
Brueckner = BruecknerREBCC
Optimised = OptimisedREBCC
ExternalCorrection = ExternalCorrectionREBCC
Tailor = TailorREBCC

Expand Down
3 changes: 2 additions & 1 deletion ebcc/cc/uebcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ebcc.ham.eris import UERIs
from ebcc.ham.fock import UFock
from ebcc.ham.space import Space
from ebcc.opt.ubrueckner import BruecknerUEBCC
from ebcc.opt.uopt import BruecknerUEBCC, OptimisedUEBCC

if TYPE_CHECKING:
from typing import Any, Optional, TypeAlias, Union
Expand Down Expand Up @@ -45,6 +45,7 @@ class UEBCC(BaseEBCC):
CDERIs = UCDERIs
ElectronBoson = UElectronBoson
Brueckner = BruecknerUEBCC
Optimised = OptimisedUEBCC
ExternalCorrection = ExternalCorrectionUEBCC
Tailor = TailorUEBCC

Expand Down
4 changes: 2 additions & 2 deletions ebcc/eom/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ def davidson(
# Check for convergence:
if all(converged):
self.log.debug("")
self.log.output(f"{ANSI.g}Converged.{ANSI.R}")
self.log.output(f"{ANSI.g}Converged{ANSI.R}.")
else:
self.log.debug("")
self.log.warning(
f"{ANSI.r}Failed to converge {sum(not c for c in converged)} roots.{ANSI.R}"
f"{ANSI.r}Failed to converge {sum(not c for c in converged)} roots{ANSI.R}."
)

# Update attributes:
Expand Down
24 changes: 24 additions & 0 deletions ebcc/ham/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ def vmask(self, char: str) -> NDArray[B]:
"""
return self.mask(char)[self.virtual]

def xmask(self, char: str) -> NDArray[B]:
"""Like `mask`, but returns only a mask into only the correlated sector.

Args:
char: Character to convert.

Returns:
Mask of the space.
"""
return self.mask(char)[self.correlated]

def oslice(self, char: str) -> _slice:
"""Like `slice`, but returns only a slice into only the occupied sector.

Expand All @@ -194,6 +205,19 @@ def vslice(self, char: str) -> _slice:
nocc = self.nocc
return slice(max(s.start, nocc) - nocc, s.stop - nocc)

def xslice(self, char: str) -> _slice:
"""Like `slice`, but returns only a slice into only the correlated sector.

Args:
char: Character to convert.

Returns:
Slice of the space.
"""
s = self.slice(char)
nfocc = self.nfocc
return slice(s.start - nfocc, s.stop - nfocc)

# Full space:

@property
Expand Down
6 changes: 3 additions & 3 deletions ebcc/opt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Orbital-optimised coupled cluster approaches."""

from ebcc.opt.gbrueckner import BruecknerGEBCC
from ebcc.opt.rbrueckner import BruecknerREBCC
from ebcc.opt.ubrueckner import BruecknerUEBCC
from ebcc.opt.gopt import BruecknerGEBCC
from ebcc.opt.ropt import BruecknerREBCC
from ebcc.opt.uopt import BruecknerUEBCC
Loading
Loading