Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
pyMOR
pymor
Commits
871cb8cf
Unverified
Commit
871cb8cf
authored
Jun 22, 2022
by
René Fritze
Committed by
GitHub
Jun 22, 2022
Browse files
Merge pull request #1580 from peoe/skip-missing-decorator
Add decorator for required test modules
parents
1327fd91
db823cc0
Pipeline
#146301
passed with stages
in 35 minutes and 42 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/pymortests/base.py
View file @
871cb8cf
...
...
@@ -12,8 +12,10 @@ import hypothesis
import
numpy
as
np
from
pickle
import
dump
,
load
from
pkg_resources
import
resource_filename
,
resource_stream
from
pytest
import
skip
from
pymor.algorithms.basic
import
almost_equal
,
relative_error
from
pymor.core.exceptions
import
DependencyMissing
def
runmodule
(
filename
):
...
...
@@ -92,3 +94,27 @@ def might_exceed_deadline(deadline=-1):
return
hypothesis
.
settings
(
deadline
=
dl
)(
func
)(
*
args
,
**
kwargs
)
return
_inner_wrapper
return
_outer_wrapper
def
skip_if_missing
(
config_name
):
"""Wrapper for requiring certain module dependencies on tests.
Parameters
----------
config_name
if `pymor.core.config.HAVE_config_name` evaluates to `False` and we're not in the
Docker CI environment, the test is skipped.
"""
def
_outer_wrapper
(
func
):
@
wraps
(
func
)
def
_inner_wrapper
(
*
args
,
**
kwargs
):
try
:
func
(
*
args
,
**
kwargs
)
except
DependencyMissing
as
dm
:
# skip does not return
if
config_name
in
str
(
dm
.
dependency
)
and
not
os
.
environ
.
get
(
'DOCKER_PYMOR'
,
False
):
skip_string
=
'skipped test due to missing dependency '
+
config_name
skip
(
skip_string
)
raise
dm
return
_inner_wrapper
return
_outer_wrapper
src/pymortests/lyapunov.py
View file @
871cb8cf
...
...
@@ -2,7 +2,6 @@
# Copyright pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
import
os
from
itertools
import
chain
,
product
import
numpy
as
np
...
...
@@ -16,8 +15,8 @@ from pymor.algorithms.lyapunov import (
solve_cont_lyap_lrcf
,
solve_disc_lyap_lrcf
,
)
from
pymor.core.config
import
config
from
pymor.operators.numpy
import
NumpyMatrixOperator
from
pymortests.base
import
skip_if_missing
n_list_small
=
[
10
,
20
]
n_list_big
=
[
300
]
...
...
@@ -118,25 +117,14 @@ def relative_residual(A, E, B, X, cont_time, trans=False):
return
res
/
rhs
def
_check_availability
(
lyap_solver
):
if
(
lyap_solver
.
startswith
(
'slycot'
)
and
not
os
.
environ
.
get
(
'DOCKER_PYMOR'
,
False
)
and
not
config
.
HAVE_SLYCOT
):
pytest
.
skip
(
'slycot not available'
)
if
(
lyap_solver
.
startswith
(
'pymess'
)
and
not
os
.
environ
.
get
(
'DOCKER_PYMOR'
,
False
)
and
not
config
.
HAVE_PYMESS
):
pytest
.
skip
(
'pymess not available'
)
@
pytest
.
mark
.
parametrize
(
'm'
,
m_list
)
@
pytest
.
mark
.
parametrize
(
'with_E'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'trans'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'n,lyap_solver'
,
chain
(
product
(
n_list_small
,
cont_lyap_dense_solver_list
),
product
(
n_list_big
,
cont_lyap_lrcf_solver_list
)))
@
skip_if_missing
(
'SLYCOT'
)
@
skip_if_missing
(
'PYMESS'
)
def
test_cont_lrcf
(
n
,
m
,
with_E
,
trans
,
lyap_solver
):
_check_availability
(
lyap_solver
)
if
not
with_E
:
A
=
conv_diff_1d_fd
(
n
,
1
,
0.1
,
cont_time
=
True
)
E
=
None
...
...
@@ -163,9 +151,9 @@ def test_cont_lrcf(n, m, with_E, trans, lyap_solver):
@
pytest
.
mark
.
parametrize
(
'with_E'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'trans'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'lyap_solver'
,
disc_lyap_dense_solver_list
)
@
skip_if_missing
(
'SLYCOT'
)
@
skip_if_missing
(
'PYMESS'
)
def
test_disc_lrcf
(
n
,
m
,
with_E
,
trans
,
lyap_solver
):
_check_availability
(
lyap_solver
)
if
not
with_E
:
A
=
conv_diff_1d_fd
(
n
,
1
,
0.1
,
cont_time
=
False
)
E
=
None
...
...
@@ -193,9 +181,9 @@ def test_disc_lrcf(n, m, with_E, trans, lyap_solver):
@
pytest
.
mark
.
parametrize
(
'with_E'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'trans'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'lyap_solver'
,
cont_lyap_dense_solver_list
)
@
skip_if_missing
(
'SLYCOT'
)
@
skip_if_missing
(
'PYMESS'
)
def
test_cont_dense
(
n
,
m
,
with_E
,
trans
,
lyap_solver
):
_check_availability
(
lyap_solver
)
np
.
random
.
seed
(
0
)
A
=
np
.
random
.
randn
(
n
,
n
)
E
=
np
.
eye
(
n
)
+
np
.
random
.
randn
(
n
,
n
)
/
n
if
with_E
else
None
...
...
@@ -214,9 +202,9 @@ def test_cont_dense(n, m, with_E, trans, lyap_solver):
@
pytest
.
mark
.
parametrize
(
'with_E'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'trans'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'lyap_solver'
,
disc_lyap_dense_solver_list
)
@
skip_if_missing
(
'SLYCOT'
)
@
skip_if_missing
(
'PYMESS'
)
def
test_disc_dense
(
n
,
m
,
with_E
,
trans
,
lyap_solver
):
_check_availability
(
lyap_solver
)
np
.
random
.
seed
(
0
)
A
=
np
.
random
.
randn
(
n
,
n
)
E
=
np
.
eye
(
n
)
+
np
.
random
.
randn
(
n
,
n
)
/
n
if
with_E
else
None
...
...
src/pymortests/riccati.py
View file @
871cb8cf
...
...
@@ -11,7 +11,8 @@ import scipy.linalg as spla
from
pymor.algorithms.lyapunov
import
_chol
from
pymor.algorithms.riccati
import
solve_pos_ricc_lrcf
,
solve_ricc_dense
,
solve_ricc_lrcf
from
pymor.operators.numpy
import
NumpyMatrixOperator
from
pymortests.lyapunov
import
_check_availability
,
conv_diff_1d_fd
,
conv_diff_1d_fem
,
fro_norm
from
pymortests.lyapunov
import
conv_diff_1d_fd
,
conv_diff_1d_fem
,
fro_norm
from
pymortests.base
import
skip_if_missing
n_list_small
=
[
10
,
20
]
n_list_big
=
[
250
]
...
...
@@ -68,9 +69,9 @@ def relative_residual(A, E, B, C, R, Z, trans):
@
pytest
.
mark
.
parametrize
(
'trans'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'n'
,
n_list_small
)
@
pytest
.
mark
.
parametrize
(
'solver'
,
ricc_dense_solver_list
)
@
skip_if_missing
(
'SLYCOT'
)
@
skip_if_missing
(
'PYMESS'
)
def
test_ricc_dense
(
n
,
m
,
p
,
with_E
,
with_R
,
trans
,
solver
):
_check_availability
(
solver
)
if
not
with_E
:
A
=
conv_diff_1d_fd
(
n
,
1
,
1
)
A
=
A
.
todense
()
...
...
@@ -102,9 +103,9 @@ def test_ricc_dense(n, m, p, with_E, with_R, trans, solver):
@
pytest
.
mark
.
parametrize
(
'trans'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'n,solver'
,
chain
(
product
(
n_list_small
,
ricc_lrcf_solver_list_small
),
product
(
n_list_big
,
ricc_lrcf_solver_list_big
)))
@
skip_if_missing
(
'SLYCOT'
)
@
skip_if_missing
(
'PYMESS'
)
def
test_ricc_lrcf
(
n
,
m
,
p
,
with_E
,
with_R
,
trans
,
solver
):
_check_availability
(
solver
)
if
not
with_E
:
A
=
conv_diff_1d_fd
(
n
,
1
,
1
)
E
=
None
...
...
@@ -144,9 +145,9 @@ def test_ricc_lrcf(n, m, p, with_E, with_R, trans, solver):
@
pytest
.
mark
.
parametrize
(
'with_R'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'trans'
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
'solver'
,
ricc_lrcf_solver_list_small
)
@
skip_if_missing
(
'SLYCOT'
)
@
skip_if_missing
(
'PYMESS'
)
def
test_pos_ricc_lrcf
(
n
,
m
,
p
,
with_E
,
with_R
,
trans
,
solver
):
_check_availability
(
solver
)
if
not
with_E
:
A
=
conv_diff_1d_fd
(
n
,
1
,
1
)
E
=
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment