momentGW.util
Utility functions.
Module Contents
- class momentGW.util.Timer
Timer class.
- total()
Return the total time since initialization.
- Returns:
total – Total time.
- Return type:
- class momentGW.util.DIIS(dev=None, filename=None, incore=getattr(__config__, 'lib_diis_DIIS_incore', False))
Bases:
pyscf.lib.diis.DIISDirect inversion of the iterative subspace (DIIS).
Notes
For some reason, the default pyscf DIIS object can result in fully linearly dependent error vectors in high-moment self-consistent calculations. This class is a drop-in replacement with a fallback in this case.
See also
pyscf.lib.diis.DIISPySCF DIIS object which this class extends.
- update_with_complex_unravel(x, xerr=None)
Execute DIIS where the error vectors are unravelled to concatenate the real and imaginary parts.
- Parameters:
x (numpy.ndarray) – Array to update with DIIS.
xerr (numpy.ndarray, optional) – Error metric for the array. Default is None.
- Returns:
x – Updated array.
- Return type:
numpy.ndarray
- extrapolate(nd=None)
Extrapolate the DIIS vectors.
- Parameters:
nd (int, optional) – Number of vectors to extrapolate. Default is None, which extrapolates all vectors.
- Returns:
xnew – Extrapolated vector.
- Return type:
numpy.ndarray
Notes
This function improves the robustness of the DIIS procedure in the event of linear dependencies.
See also
pyscf.lib.diis.DIIS.extrapolatePySCF DIIS extrapolation which this function refactors.
- update(x, xerr=None)
Extrapolate vector
If xerr the error vector is given, this function will push the target
vector and error vector in the DIIS subspace, and use the error vector to extrapolate the vector and return the extrapolated vector. * If xerr is None, this function will take the difference between the current given vector and the last given vector as the error vector to extrapolate the vector.
- restore(filename, inplace=True)
Read diis contents from a diis file and replace the attributes of current diis object if needed, then construct the vector.
- class momentGW.util.SilentSCF(mf)
Context manager to shut PySCF’s SCF classes up.
- Parameters:
mf (pyscf.scf.SCF) – SCF object to silence.
- momentGW.util.list_union(*args)
Find the union of a list of lists, with the elements sorted by their first occurrence.
- momentGW.util.dict_union(*args)
Find the union of a list of dictionaries, preserving the order of the first occurrence of each key.
- momentGW.util.build_1h1p_energies(mo_energy, mo_occ)
Construct an array of 1h1p energies where elements are
\[\begin{split}\\Delta_{ij} = \\epsilon_i - \\epsilon_j\end{split}\]- Parameters:
mo_energy (numpy.ndarray or tuple of numpy.ndarray) – Molecular orbital energies. If a tuple, the first element is used for occupied orbitals and the second element is used for virtual orbitals.
mo_occ (numpy.ndarray or tuple of numpy.ndarray) – Molecular orbital occupancies. If a tuple, the first element is used for occupied orbitals and the second element is used for virtual orbitals.
- Returns:
d – 1h1p energies.
- Return type:
numpy.ndarray
- momentGW.util.einsum(*operands, **kwargs)
Evaluate an Einstein summation convention on the operands.
Using the Einstein summation convention, many common multi-dimensional, linear algebraic array operations can be represented in a simple fashion. In implicit mode einsum computes these values.
In explicit mode, einsum provides further flexibility to compute other array operations that might not be considered classical Einstein summation operations, by disabling, or forcing summation over specified subscript labels.
See the numpy.einsum documentation for clarification.
- Parameters:
operands (list) – Any valid input to numpy.einsum.
out (numpy.ndarray, optional) – If provided, the calculation is done into this array.
contract (callable, optional) – The function to use for contraction. Default value is _contract.
optimize (bool, optional) – If True, use the numpy.einsum_path to optimize the contraction. Default value is True.
- Returns:
output – The calculation based on the Einstein summation convention.
- Return type:
numpy.ndarray
See also
numpy.einsumNumPy’s einsum function.