Skip to content

Commit

Permalink
ignore unresolved import for optional package
Browse files Browse the repository at this point in the history
and reraise cc solver exception
  • Loading branch information
mcocdawc committed Nov 21, 2024
1 parent ecbc796 commit 8d93ebd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/molbe/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def be_func(
rdm1_tmp = mc.make_rdm1(civec, mc.norb, mc.nelec)

elif solver == "HCI":
# pylint: disable-next=E0611
from pyscf import hci # noqa: PLC0415 # optional module

nao, nmo = fobj._mf.mo_coeff.shape
Expand Down Expand Up @@ -172,6 +173,7 @@ def be_func(
rdm2s = rdm2aa + rdm2ab + rdm2ab.transpose(2, 3, 0, 1) + rdm2bb

elif solver == "SHCI":
# pylint: disable-next=E0611,E0401
from pyscf.shciscf import shci # noqa: PLC0415 # shci is optional

if scratch_dir is None and be_var.CREATE_SCRATCH_DIR:
Expand Down Expand Up @@ -203,6 +205,7 @@ def be_func(
rdm1_tmp, rdm2s = mch.fcisolver.make_rdm12(0, nmo, nelec)

elif solver == "SCI":
# pylint: disable-next=E0611
from pyscf import cornell_shci # noqa: PLC0415 # optional module

nao, nmo = fobj._mf.mo_coeff.shape
Expand Down Expand Up @@ -685,16 +688,11 @@ def solve_ccsd(
try:
cc__.verbose = verbose
cc__.kernel(eris=eris)
except:
except Exception as e:
print(flush=True)
print(
"Exception in CCSD -> applying level_shift=0.2, diis_space=25", flush=True
)
print("Exception in CCSD, play with different CC options.", flush=True)
print(flush=True)
cc__.verbose = 4
cc__.diis_space = 25
cc__.level_shift = 0.2
cc__.kernel(eris=eris)
raise e

# Extract the CCSD amplitudes
t1 = cc__.t1
Expand Down Expand Up @@ -782,6 +780,7 @@ def solve_block2(mf: object, nocc: int, frag_scratch: str = None, **solver_kwarg
"""
# pylint: disable-next=E0611
from pyscf import dmrgscf # noqa: PLC0415 # optional module

use_cumulant = solver_kwargs.pop("use_cumulant", True)
Expand Down

0 comments on commit 8d93ebd

Please sign in to comment.