Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F81842140
sampling_engine_base.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Sep 8, 05:29
Size
3 KB
Mime Type
text/x-python
Expires
Tue, Sep 10, 05:29 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20623434
Attached To
R6746 RationalROMPy
sampling_engine_base.py
View Options
# 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
Log In to Comment