diff --git a/tests/reduction_methods_1D/rational_interpolant_1d.py b/tests/reduction_methods_1D/rational_interpolant_1d.py
index 3e1b673..1abbf23 100644
--- a/tests/reduction_methods_1D/rational_interpolant_1d.py
+++ b/tests/reduction_methods_1D/rational_interpolant_1d.py
@@ -1,69 +1,69 @@
# 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 .
#
import numpy as np
from matrix_fft import matrixFFT
-from rrompy.reduction_methods.standard import RationalInterpolant as RI
+from rrompy.reduction_methods import RationalInterpolant as RI
from rrompy.parameter.parameter_sampling import (QuadratureSampler as QS,
ManualSampler as MS)
from rrompy.parameter import checkParameterList
def test_monomials(capsys):
mu = 1.5
solver = matrixFFT()
params = {"POD": False, "S": 10, "robustTol": 1e-6, "interpRcond": 1e-3,
"polybasis": "MONOMIAL", "sampler": QS([1.5, 6.5], "UNIFORM")}
approx = RI(solver, 4., approx_state = True, approxParameters = params,
verbosity = 10)
approx.setupApprox()
out, err = capsys.readouterr()
assert "poorly conditioned. Reducing N " in out
assert len(err) == 0
assert np.isclose(approx.normErr(mu)[0], 1.4746e-05, atol = 1e-4)
def test_well_cond():
mu = 1.5
solver = matrixFFT()
params = {"POD": True, "S": 10, "robustTol": 1e-14, "interpRcond": 1e-10,
"polybasis": "CHEBYSHEV", "sampler": QS([1., 7.], "CHEBYSHEV")}
approx = RI(solver, 4., approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
poles = approx.getPoles()
for lambda_ in np.arange(1, 8):
assert np.isclose(np.min(np.abs(poles - lambda_)), 0., atol = 1e-4)
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0], 0., atol = 1e-8)
def test_hermite():
mu = 1.5
solver = matrixFFT()
sampler0 = QS([1., 7.], "CHEBYSHEV")
points, _ = checkParameterList(np.tile(sampler0.generatePoints(4)(0), 3))
params = {"POD": True, "S": 12, "polybasis": "CHEBYSHEV",
"sampler": MS([1., 7.], points = points)}
approx = RI(solver, 4., approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
poles = approx.getPoles()
for lambda_ in np.arange(1, 8):
assert np.isclose(np.min(np.abs(poles - lambda_)), 0., atol = 1e-4)
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0], 0., atol = 1e-8)
diff --git a/tests/reduction_methods_1D/rational_interpolant_greedy_1d.py b/tests/reduction_methods_1D/rational_interpolant_greedy_1d.py
index f5ee31d..a4c17ce 100644
--- a/tests/reduction_methods_1D/rational_interpolant_greedy_1d.py
+++ b/tests/reduction_methods_1D/rational_interpolant_greedy_1d.py
@@ -1,100 +1,99 @@
# 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 .
#
import numpy as np
from matrix_fft import matrixFFT
-from rrompy.reduction_methods.standard.greedy import (
- RationalInterpolantGreedy as RIG)
+from rrompy.reduction_methods import RationalInterpolantGreedy as RIG
from rrompy.parameter.parameter_sampling import QuadratureSampler as QS
def test_lax_tolerance(capsys):
mu = 2.25
solver = matrixFFT()
params = {"POD": True, "sampler": QS([1.5, 6.5], "UNIFORM"), "S": 4,
"polybasis": "CHEBYSHEV", "greedyTol": 1e-2,
"errorEstimatorKind": "LOOK_AHEAD",
"trainSetGenerator": QS([1.5, 6.5], "CHEBYSHEV")}
approx = RIG(solver, 4., approx_state = True, approxParameters = params,
verbosity = 100)
approx.setupApprox()
out, err = capsys.readouterr()
assert "Done computing snapshots (final snapshot count: 10)." in out
assert len(err) == 0
assert np.isclose(approx.normErr(mu)[0], 2.169678e-4, rtol = 1e-1)
def test_samples_at_poles():
solver = matrixFFT()
params = {"POD": True, "sampler": QS([1.5, 6.5], "UNIFORM"), "S": 4,
"nTestPoints": 100, "polybasis": "CHEBYSHEV", "greedyTol": 1e-5,
"errorEstimatorKind": "AFFINE",
"trainSetGenerator": QS([1.5, 6.5], "CHEBYSHEV")}
approx = RIG(solver, 4., approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0] / (1e-15+approx.normHF(mu)[0]),
0., atol = 1e-4)
poles = approx.getPoles()
for lambda_ in range(2, 7):
assert np.isclose(np.min(np.abs(poles - lambda_)), 0., atol = 1e-3)
assert np.isclose(np.min(np.abs(np.array(approx.mus(0)) - lambda_)),
0., atol = 1e-1)
def test_maxIter():
solver = matrixFFT()
params = {"POD": True, "sampler": QS([1.5, 6.5], "UNIFORM"),
"S": 5, "nTestPoints": 500, "polybasis": "CHEBYSHEV",
"greedyTol": 1e-6, "maxIter": 10,
"errorEstimatorKind": "INTERPOLATORY",
"trainSetGenerator": QS([1.5, 6.5], "CHEBYSHEV")}
approx = RIG(solver, 4., approx_state = True, approxParameters = params,
verbosity = 0)
approx.input = lambda: "N"
approx.setupApprox()
assert len(approx.mus) == 10
_, _, maxEst = approx.errorEstimator(approx.muTest, True)
assert maxEst > 1e-6
def test_load_copy(capsys):
mu = 3.
solver = matrixFFT()
params = {"POD": True, "sampler": QS([1.5, 6.5], "UNIFORM"), "S": 4,
"nTestPoints": 100, "polybasis": "CHEBYSHEV",
"greedyTol": 1e-5, "errorEstimatorKind": "AFFINE",
"trainSetGenerator": QS([1.5, 6.5], "CHEBYSHEV")}
approx1 = RIG(solver, 4., approx_state = True, approxParameters = params,
verbosity = 100)
approx1.setupApprox()
err1 = approx1.normErr(mu)[0]
out, err = capsys.readouterr()
assert "Solving HF model for mu =" in out
assert len(err) == 0
approx2 = RIG(solver, 4., approx_state = True, approxParameters = params,
verbosity = 100)
approx2.setTrainedModel(approx1)
approx2.setHF(mu, approx1.uHF)
err2 = approx2.normErr(mu)[0]
out, err = capsys.readouterr()
assert "Solving HF model for mu =" not in out
assert len(err) == 0
assert np.isclose(err1, err2, rtol = 1e-10)
diff --git a/tests/reduction_methods_1D/reduced_basis_1d.py b/tests/reduction_methods_1D/reduced_basis_1d.py
index 6885a00..5b77882 100644
--- a/tests/reduction_methods_1D/reduced_basis_1d.py
+++ b/tests/reduction_methods_1D/reduced_basis_1d.py
@@ -1,60 +1,60 @@
# 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 .
#
import numpy as np
from matrix_fft import matrixFFT
-from rrompy.reduction_methods.standard import ReducedBasis as RB
+from rrompy.reduction_methods import ReducedBasis as RB
from rrompy.parameter.parameter_sampling import (QuadratureSampler as QS,
ManualSampler as MS)
from rrompy.parameter import checkParameterList
def test_LS():
solver = matrixFFT()
params = {"POD": True, "R": 5, "S": 10,
"sampler": QS([1., 7.], "CHEBYSHEV")}
approx = RB(solver, 4., approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert not np.isclose(approx.normErr(mu)[0], 0., atol = 1e-7)
approx.POD = False
approx.setupApprox()
for mu in approx.mus[approx.R :]:
assert not np.isclose(approx.normErr(mu)[0], 0., atol = 1e-3)
def test_interp():
solver = matrixFFT()
params = {"POD": False, "S": 10, "sampler": QS([1., 7.], "CHEBYSHEV")}
approx = RB(solver, 4., approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0], 0., atol = 1e-7)
def test_hermite():
mu = 1.5
solver = matrixFFT()
sampler0 = QS([1., 7.], "CHEBYSHEV")
points, _ = checkParameterList(np.tile(sampler0.generatePoints(4)(0), 3))
params = {"POD": True, "S": 12, "sampler": MS([1., 7.], points = points)}
approx = RB(solver, 4., approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0], 0., atol = 1e-8)
diff --git a/tests/reduction_methods_1D/reduced_basis_greedy_1d.py b/tests/reduction_methods_1D/reduced_basis_greedy_1d.py
index 345febd..2f9053e 100644
--- a/tests/reduction_methods_1D/reduced_basis_greedy_1d.py
+++ b/tests/reduction_methods_1D/reduced_basis_greedy_1d.py
@@ -1,60 +1,60 @@
# 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 .
#
import numpy as np
from matrix_fft import matrixFFT
-from rrompy.reduction_methods.standard.greedy import ReducedBasisGreedy as RBG
+from rrompy.reduction_methods import ReducedBasisGreedy as RBG
from rrompy.parameter.parameter_sampling import QuadratureSampler as QS
def test_lax_tolerance(capsys):
mu = 2.25
solver = matrixFFT()
params = {"POD": True, "sampler": QS([1.5, 6.5], "UNIFORM"),
"S": 4, "greedyTol": 1e-2,
"trainSetGenerator": QS([1.5, 6.5], "CHEBYSHEV")}
approx = RBG(solver, 4., approx_state = True, approxParameters = params,
verbosity = 10)
approx.setupApprox()
out, err = capsys.readouterr()
assert "Done computing snapshots (final snapshot count: 10)." in out
assert len(err) == 0
assert len(approx.mus) == 10
_, _, maxEst = approx.errorEstimator(approx.muTest, True)
assert maxEst < 1e-2
assert np.isclose(approx.normErr(mu)[0], 1.5056e-05, rtol = 1e-1)
def test_samples_at_poles():
solver = matrixFFT()
params = {"POD": True, "sampler": QS([1.5, 6.5], "UNIFORM"),
"S": 4, "nTestPoints": 100, "greedyTol": 1e-5,
"trainSetGenerator": QS([1.5, 6.5], "CHEBYSHEV")}
approx = RBG(solver, 4., approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0] / (1e-15+approx.normHF(mu)[0]),
0., atol = 1e-4)
poles = approx.getPoles()
for lambda_ in range(2, 7):
assert np.isclose(np.min(np.abs(poles - lambda_)), 0., atol = 1e-3)
assert np.isclose(np.min(np.abs(np.array(approx.mus(0)) - lambda_)),
0., atol = 1e-1)
diff --git a/tests/reduction_methods_multiD/greedy_pivoted_rational_2d.py b/tests/reduction_methods_multiD/greedy_pivoted_rational_2d.py
index 6d07613..e827904 100644
--- a/tests/reduction_methods_multiD/greedy_pivoted_rational_2d.py
+++ b/tests/reduction_methods_multiD/greedy_pivoted_rational_2d.py
@@ -1,83 +1,83 @@
# 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 .
#
import numpy as np
from matrix_random import matrixRandom
-from rrompy.reduction_methods.pivoted.greedy import (
+from rrompy.reduction_methods import (
RationalInterpolantPivotedGreedy as RIPG,
RationalInterpolantGreedyPivotedGreedy as RIGPG)
from rrompy.parameter.parameter_sampling import QuadratureSampler as QS
from rrompy.parameter import localSparseGrid as LSG
def test_greedy_pivoted():
mu = [5.05, 7.1]
mu0 = [5., 7.]
solver = matrixRandom()
uh = solver.solve(mu)[0]
params = {"POD": True, "S": 5, "polybasis": "CHEBYSHEV",
"samplerPivot": QS([4.75, 5.25], "CHEBYSHEV"),
"MMarginal": 1, "SMarginal": 3, "greedyTolMarginal": 1e-2,
"radialDirectionalWeightsMarginal": 2.,
"polybasisMarginal": "MONOMIAL_GAUSSIAN",
"matchingWeight": 1., "samplerMarginalGrid":LSG([6.75, 7.25])}
approx = RIPG([0], solver, mu0, approx_state = True,
approxParameters = params, verbosity = 0)
approx.setupApprox()
uhP1 = approx.getApprox(mu)[0]
errP = approx.getErr(mu)[0]
errNP = approx.normErr(mu)[0]
myerrP = uhP1 - uh
assert np.allclose(np.abs(errP - myerrP), 0., rtol = 1e-3)
assert np.isclose(solver.norm(errP), errNP, rtol = 1e-3)
resP = approx.getRes(mu)[0]
resNP = approx.normRes(mu)
assert np.isclose(solver.norm(resP), resNP, rtol = 1e-3)
assert np.allclose(np.abs(resP - (solver.b(mu) - solver.A(mu).dot(uhP1))),
0., rtol = 1e-3)
assert np.isclose(errNP / solver.norm(uh), 6.0631706e-04, rtol = 1)
def test_greedy_pivoted_greedy():
mu = [5.05, 7.1]
mu0 = [5., 7.]
solver = matrixRandom()
uh = solver.solve(mu)[0]
params = {"POD": True, "nTestPoints": 100, "greedyTol": 1e-3, "S": 2,
"polybasis": "CHEBYSHEV",
"samplerPivot": QS([4.75, 5.25], "CHEBYSHEV"),
"trainSetGenerator": QS([4.75, 5.25], "CHEBYSHEV"),
"MMarginal": 1, "SMarginal": 3, "greedyTolMarginal": 1e-2,
"radialDirectionalWeightsMarginal": 2.,
"polybasisMarginal": "MONOMIAL_GAUSSIAN",
"matchingWeight": 1., "samplerMarginalGrid":LSG([6.75, 7.25])}
approx = RIGPG([0], solver, mu0, approx_state = True,
approxParameters = params, verbosity = 0)
approx.setupApprox()
uhP1 = approx.getApprox(mu)[0]
errP = approx.getErr(mu)[0]
errNP = approx.normErr(mu)[0]
myerrP = uhP1 - uh
assert np.allclose(np.abs(errP - myerrP), 0., rtol = 1e-3)
assert np.isclose(solver.norm(errP), errNP, rtol = 1e-3)
resP = approx.getRes(mu)[0]
resNP = approx.normRes(mu)
assert np.isclose(solver.norm(resP), resNP, rtol = 1e-3)
assert np.allclose(np.abs(resP - (solver.b(mu) - solver.A(mu).dot(uhP1))),
0., rtol = 1e-3)
assert np.isclose(errNP / solver.norm(uh), 6.0631706e-04, rtol = 1)
diff --git a/tests/reduction_methods_multiD/pivoted_rational_2d.py b/tests/reduction_methods_multiD/pivoted_rational_2d.py
index 804a2d8..c19562c 100644
--- a/tests/reduction_methods_multiD/pivoted_rational_2d.py
+++ b/tests/reduction_methods_multiD/pivoted_rational_2d.py
@@ -1,112 +1,111 @@
# 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 .
#
import numpy as np
from matrix_random import matrixRandom
-from rrompy.reduction_methods.pivoted import (
- RationalInterpolantPivoted as RIP,
+from rrompy.reduction_methods import (RationalInterpolantPivoted as RIP,
RationalInterpolantGreedyPivoted as RIGP)
from rrompy.parameter.parameter_sampling import (QuadratureSampler as QS,
ManualSampler as MS)
def test_pivoted_uniform():
mu = [5.05, 7.1]
mu0 = [5., 7.]
solver = matrixRandom()
uh = solver.solve(mu)[0]
params = {"POD": True, "S": 5, "polybasis": "CHEBYSHEV",
"samplerPivot": QS([4.75, 5.25], "CHEBYSHEV"), "SMarginal": 5,
"polybasisMarginal": "MONOMIAL", "matchingWeight": 1.,
"samplerMarginal": QS([6.75, 7.25], "UNIFORM")}
approx = RIP([0], solver, mu0, approx_state = True,
approxParameters = params, verbosity = 0)
approx.setupApprox()
uhP1 = approx.getApprox(mu)[0]
errP = approx.getErr(mu)[0]
errNP = approx.normErr(mu)[0]
myerrP = uhP1 - uh
assert np.allclose(np.abs(errP - myerrP), 0., rtol = 1e-3)
assert np.isclose(solver.norm(errP), errNP, rtol = 1e-3)
resP = approx.getRes(mu)[0]
resNP = approx.normRes(mu)
assert np.isclose(solver.norm(resP), resNP, rtol = 1e-3)
assert np.allclose(np.abs(resP - (solver.b(mu) - solver.A(mu).dot(uhP1))),
0., rtol = 1e-3)
assert np.isclose(errNP / solver.norm(uh), 6.0631706e-04, rtol = 1)
def test_pivoted_manual_grid(capsys):
mu = [5.05, 7.1]
mu0 = [5., 7.]
solver = matrixRandom()
uh = solver.solve(mu)[0]
params = {"POD": False, "S": 5, "polybasis": "MONOMIAL",
"samplerPivot": MS([4.75, 5.25], np.array([5.])), "SMarginal": 5,
"polybasisMarginal": "MONOMIAL", "matchingWeight": 1.,
"samplerMarginal": MS([6.75, 7.25], np.linspace(6.75, 7.25, 5)),
"robustTol": 1e-6, "interpRcond": 1e-3, "cutOffTolerance": 1.}
approx = RIP([0], solver, mu0, approx_state = True,
approxParameters = params, verbosity = 0)
approx.setupApprox()
uhP1 = approx.getApprox(mu)[0]
errP = approx.getErr(mu)[0]
errNP = approx.normErr(mu)[0]
myerrP = uhP1 - uh
assert np.allclose(np.abs(errP - myerrP), 0., rtol = 1e-3)
assert np.isclose(solver.norm(errP), errNP, rtol = 1e-3)
resP = approx.getRes(mu)[0]
resNP = approx.normRes(mu)
assert np.isclose(solver.norm(resP), resNP, rtol = 1e-3)
assert np.allclose(np.abs(resP - (solver.b(mu) - solver.A(mu).dot(uhP1))),
0., rtol = 1e-3)
assert np.isclose(errNP / solver.norm(uh), .4763489, rtol = 1)
out, err = capsys.readouterr()
assert ("poorly conditioned" not in out)
assert len(err) == 0
def test_pivoted_greedy():
mu = [5.05, 7.1]
mu0 = [5., 7.]
solver = matrixRandom()
uh = solver.solve(mu)[0]
params = {"POD": True, "nTestPoints": 100, "greedyTol": 1e-4,
"collinearityTol": 1e8, "errorEstimatorKind": "DISCREPANCY",
"S": 5, "polybasis": "CHEBYSHEV",
"samplerPivot": QS([4.75, 5.25], "UNIFORM"),
"trainSetGenerator": QS([4.75, 5.25], "CHEBYSHEV"),
"SMarginal": 5, "polybasisMarginal": "MONOMIAL",
"samplerMarginal": QS([6.75, 7.25], "UNIFORM"),
"matchingWeight": 1., "cutOffTolerance": 1.5}
approx = RIGP([0], solver, mu0, approx_state = True,
approxParameters = params, verbosity = 0)
approx.setupApprox()
uhP1 = approx.getApprox(mu)[0]
errP = approx.getErr(mu)[0]
errNP = approx.normErr(mu)[0]
myerrP = uhP1 - uh
assert np.allclose(np.abs(errP - myerrP), 0., rtol = 1e-3)
assert np.isclose(solver.norm(errP), errNP, rtol = 1e-3)
resP = approx.getRes(mu)[0]
resNP = approx.normRes(mu)
assert np.isclose(solver.norm(resP), resNP, rtol = 1e-3)
assert np.allclose(np.abs(resP - (solver.b(mu) - solver.A(mu).dot(uhP1))),
0., rtol = 1e-3)
assert np.isclose(errNP / solver.norm(uh), 1.181958e-02, rtol = 1)
diff --git a/tests/reduction_methods_multiD/rational_interpolant_2d.py b/tests/reduction_methods_multiD/rational_interpolant_2d.py
index 4ef22fb..10a9337 100644
--- a/tests/reduction_methods_multiD/rational_interpolant_2d.py
+++ b/tests/reduction_methods_multiD/rational_interpolant_2d.py
@@ -1,77 +1,77 @@
# 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 .
#
import numpy as np
from matrix_random import matrixRandom
-from rrompy.reduction_methods.standard import RationalInterpolant as RI
+from rrompy.reduction_methods import RationalInterpolant as RI
from rrompy.parameter.parameter_sampling import (QuadratureSampler as QS,
ManualSampler as MS)
def test_monomials(capsys):
mu = [5.05, 7.1]
mu0 = [5., 7.]
solver = matrixRandom()
uh = solver.solve(mu)[0]
params = {"POD": False, "S": 16, "robustTol": 1e-6,
"interpRcond": 1e-3, "polybasis": "MONOMIAL",
"sampler": QS([[4.9, 6.85], [5.1, 7.15]], "UNIFORM")}
approx = RI(solver, mu0, params, verbosity = 100)
approx.setupApprox()
uhP1 = approx.getApprox(mu)[0]
errP = approx.getErr(mu)[0]
errNP = approx.normErr(mu)[0]
myerrP = uhP1 - uh
assert np.allclose(np.abs(errP - myerrP), 0., rtol = 1e-3)
assert np.isclose(solver.norm(errP), errNP, rtol = 1e-3)
resP = approx.getRes(mu)[0]
resNP = approx.normRes(mu)
assert np.isclose(solver.norm(resP), resNP, rtol = 1e-3)
assert np.allclose(np.abs(resP - (solver.b(mu) - solver.A(mu).dot(uhP1))),
0., rtol = 1e-3)
assert np.isclose(errNP / solver.norm(uh), 5.2667e-05, rtol = 1)
out, err = capsys.readouterr()
assert ("poorly conditioned. Reducing N " in out)
assert len(err) == 0
def test_well_cond():
mu = [5.05, 7.1]
mu0 = [5., 7.]
solver = matrixRandom()
params = {"POD": True, "M": 3, "N": 3, "S": 16,
"interpRcond": 1e-10, "polybasis": "CHEBYSHEV",
"sampler": QS([[4.9, 6.85], [5.1, 7.15]], "UNIFORM")}
approx = RI(solver, mu0, params, verbosity = 0)
approx.setupApprox()
assert np.isclose(approx.normErr(mu)[0] / approx.normHF(mu)[0],
5.98695e-05, rtol = 1e-1)
def test_hermite():
mu = [5.05, 7.1]
mu0 = [5., 7.]
solver = matrixRandom()
sampler0 = QS([[4.9, 6.85], [5.1, 7.15]], "UNIFORM")
params = {"POD": True, "M": 3, "N": 3, "S": 25, "polybasis": "CHEBYSHEV",
"sampler": MS([[4.9, 6.85], [5.1, 7.15]],
points = sampler0.generatePoints(9))}
approx = RI(solver, mu0, params, verbosity = 0)
approx.setupApprox()
assert np.isclose(approx.normErr(mu)[0] / approx.normHF(mu)[0],
- 0.000224, rtol = 5e-1)
+ 5.50053e-05, rtol = 5e-1)
diff --git a/tests/reduction_methods_multiD/reduced_basis_2d.py b/tests/reduction_methods_multiD/reduced_basis_2d.py
index a754142..979efa5 100644
--- a/tests/reduction_methods_multiD/reduced_basis_2d.py
+++ b/tests/reduction_methods_multiD/reduced_basis_2d.py
@@ -1,65 +1,65 @@
# 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 .
#
import numpy as np
from matrix_random import matrixRandom
-from rrompy.reduction_methods.standard import ReducedBasis as RB
+from rrompy.reduction_methods import ReducedBasis as RB
from rrompy.parameter.parameter_sampling import (QuadratureSampler as QS,
ManualSampler as MS)
from rrompy.parameter import checkParameterList
def test_LS():
mu0 = [2, 3]
solver = matrixRandom()
params = {"POD": True, "R": 5, "S": 9,
"sampler": QS([[0., 4.], [1., 5.]], "CHEBYSHEV")}
approx = RB(solver, mu0, approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert not np.isclose(approx.normErr(mu)[0], 0., atol = 1e-7)
approx.POD = False
approx.setupApprox()
for mu in approx.mus[approx.R :]:
assert not np.isclose(approx.normErr(mu)[0], 0., atol = 1e-3)
def test_interp():
mu0 = [2, 3]
solver = matrixRandom()
params = {"POD": False, "S": 9,
"sampler": QS([[0., 4.], [1., 5.]], "CHEBYSHEV")}
approx = RB(solver, mu0, approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0], 0., atol = 1e-7)
def test_hermite():
mu0 = [2, 3]
solver = matrixRandom()
sampler0 = QS([[0., 4.], [1., 5.]], "CHEBYSHEV")
points, _ = checkParameterList(np.tile(
sampler0.generatePoints(4).data, [3, 1]))
params = {"POD": True, "S": 12,
"sampler": MS([[0., 4.], [1., 5.]], points = points)}
approx = RB(solver, mu0, approx_state = True, approxParameters = params,
verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0], 0., atol = 1e-8)
diff --git a/tests/utilities/sampling.py b/tests/utilities/sampling.py
index 1e64a43..3d29da7 100644
--- a/tests/utilities/sampling.py
+++ b/tests/utilities/sampling.py
@@ -1,65 +1,64 @@
# 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 .
#
import numpy as np
import scipy.sparse as sp
from rrompy.hfengines.base import LinearAffineEngine, NumpyEngineBase
-from rrompy.sampling.standard import (SamplingEngineStandard,
- SamplingEngineStandardPOD)
+from rrompy.sampling import SamplingEngineStandard, SamplingEngineStandardPOD
from rrompy.parameter import parameterList
class matrixEngine(LinearAffineEngine, NumpyEngineBase):
def __init__(self):
super().__init__(verbosity = 0)
self._affinePoly = True
N = 100
self.npar = 1
self.nAs, self.nbs = 2, 1
self.setAs([sp.spdiags([np.arange(1, 1 + N)], [0], N, N),
- sp.eye(N)])
self.setbs([np.exp(1.j * np.linspace(0, -np.pi, N))])
self.setthAs(self.getMonomialWeights(self.nAs))
self.setthbs(self.getMonomialWeights(self.nbs))
def test_krylov():
mu = 10. + .5j
solver = matrixEngine()
samplingEngine = SamplingEngineStandard(solver, verbosity = 0)
samples = samplingEngine.iterSample([mu] * 5).data
assert samples.shape == (100, 5)
assert np.isclose(np.linalg.norm(samples), 37.02294804524299, rtol = 1e-5)
def test_distributed():
mus = parameterList(np.linspace(5, 15, 11) + .5j)
solver = matrixEngine()
samplingEngine = SamplingEngineStandard(solver, verbosity = 0)
samples = samplingEngine.iterSample(mus).data
assert samples.shape == (100, 11)
assert np.isclose(np.linalg.norm(samples), 8.59778606421386, rtol = 1e-5)
def test_distributed_pod():
mus = np.linspace(5, 15, 11) + .5j
solver = matrixEngine()
samplingEngine = SamplingEngineStandardPOD(solver, verbosity = 0)
samples = samplingEngine.iterSample(mus).data
assert samples.shape == (100, 11)
assert np.isclose(np.linalg.norm(samples), 3.3166247903553994, rtol = 1e-5)
assert np.isclose(np.linalg.cond(samples.conj().T.dot(samples)), 1.,
rtol = 1e-5)