Page MenuHomec4science

sampling_engine_base.py
No OneTemporary

File Metadata

Created
Fri, Aug 2, 05:08

sampling_engine_base.py

# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
from rrompy.utilities.base.types import Np1D, HFEng, strLst
from rrompy.utilities.base import verbosityDepth
__all__ = ['SamplingEngineBase']
class SamplingEngineBase:
"""HERE"""
nameBase = 0
def __init__(self, HFEngine:HFEng, verbosity : int = 10):
self.verbosity = verbosity
if self.verbosity >= 10:
verbosityDepth("INIT",
"Initializing sampling engine of type {}.".format(
self.name()),
end = "")
self.HFEngine = HFEngine
if self.verbosity >= 10:
verbosityDepth("DEL", " Done.", inline = True)
def name(self) -> str:
return self.__class__.__name__
def __str__(self) -> str:
return self.name()
def resetHistory(self):
self.samples = None
self.nsamples = 0
@property
def HFEngine(self):
"""Value of HFEngine. Its assignment resets history."""
return self._HFEngine
@HFEngine.setter
def HFEngine(self, HFEngine):
self._HFEngine = HFEngine
self.resetHistory()
def solveLS(self, mu:complex, RHS : Np1D = None,
homogeneized : bool = False) -> Np1D:
"""
Solve linear system.
Args:
mu: Parameter value.
Returns:
Solution of system.
"""
if self.verbosity >= 5:
verbosityDepth("INIT", "Solving HF model for mu = {}.".format(mu))
u = self.HFEngine.solve(mu, RHS, homogeneized)
if self.verbosity >= 5:
verbosityDepth("DEL", "Done solving HF model.")
return u
def plotSamples(self, name : str = "u", save : str = None,
what : strLst = 'all', saveFormat : str = "eps",
saveDPI : int = 100, **figspecs):
"""
Do some nice plots of the samples.
Args:
name(optional): Name to be shown as title of the plots. Defaults to
'u'.
save(optional): Where to save plot(s). Defaults to None, i.e. no
saving.
what(optional): Which plots to do. If list, can contain 'ABS',
'PHASE', 'REAL', 'IMAG'. If str, same plus wildcard 'ALL'.
Defaults to 'ALL'.
saveFormat(optional): Format for saved plot(s). Defaults to "eps".
saveDPI(optional): DPI for saved plot(s). Defaults to 100.
figspecs(optional key args): Optional arguments for matplotlib
figure creation.
"""
for j in range(self.nsamples):
self.HFEngine.plot(self.samples[:, j],
name = "{}_{}".format(name, j + self.nameBase),
save = save, what = what,
saveFormat = saveFormat, saveDPI = saveDPI,
**figspecs)

Event Timeline