Skip to content

Commit 8b6c5c1

Browse files
authored
Merge pull request #30 from pymor/ruff_fixes
Ruff fixes
2 parents 1bda92b + ef06632 commit 8b6c5c1

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

.ci/make_env_file.py

100644100755
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from os.path import expanduser
55
from shlex import quote
66

7-
home = expanduser("~")
7+
home = expanduser('~')
88

9-
prefixes = os.environ.get("ENV_PREFIXES", "TRAVIS CI encrypt TOKEN TESTS").split(" ")
10-
blacklist = ["TRAVIS_COMMIT_MESSAGE"]
11-
env_file = os.environ.get("ENV_FILE", os.path.join(home, "env"))
12-
with open(env_file, "wt") as env:
9+
prefixes = os.environ.get('ENV_PREFIXES', 'TRAVIS CI encrypt TOKEN TESTS').split(' ')
10+
blacklist = ['TRAVIS_COMMIT_MESSAGE']
11+
env_file = os.environ.get('ENV_FILE', os.path.join(home, 'env'))
12+
with open(env_file, 'w') as env:
1313
for k, v in os.environ.items():
1414
for pref in prefixes:
1515
if k.startswith(pref) and k not in blacklist:
16-
env.write("{}={}\n".format(k, quote(v)))
16+
env.write(f'{k}={quote(v)}\n')

src/pymor_dealii/pymor/demo.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
# Copyright 2013-2018 pyMOR developers and contributors. All rights reserved.
33
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
44

5-
from pymor.basic import *
5+
from dealii_elasticity import ElasticityExample
6+
from pymor.basic import (
7+
CoerciveRBReductor,
8+
ExpressionParameterFunctional,
9+
LincombOperator,
10+
ProjectionParameterFunctional,
11+
StationaryModel,
12+
VectorOperator,
13+
rb_greedy,
14+
reduction_error_analysis,
15+
)
616

17+
from pymor_dealii.pymor.gui import DealIIVisualizer
718
from pymor_dealii.pymor.operator import DealIIMatrixOperator
819
from pymor_dealii.pymor.vectorarray import DealIIVectorSpace
9-
from pymor_dealii.pymor.gui import DealIIVisualizer
10-
from dealii_elasticity import ElasticityExample
1120

1221
cpp_disc = ElasticityExample(refine_steps=7)
1322

@@ -20,12 +29,12 @@ def run(plot_error=True):
2029
DealIIMatrixOperator(cpp_disc.mu_mat()),
2130
],
2231
[
23-
ProjectionParameterFunctional("lambda"),
24-
ProjectionParameterFunctional("mu"),
32+
ProjectionParameterFunctional('lambda'),
33+
ProjectionParameterFunctional('mu'),
2534
],
2635
),
2736
rhs=VectorOperator(DealIIVectorSpace.make_array([cpp_disc.rhs()])),
28-
products={"energy": DealIIMatrixOperator(cpp_disc.mu_mat())},
37+
products={'energy': DealIIMatrixOperator(cpp_disc.mu_mat())},
2938
visualizer=DealIIVisualizer(cpp_disc),
3039
)
3140
parameter_space = d.parameters.space((1, 10))
@@ -34,46 +43,46 @@ def run(plot_error=True):
3443
reductor = CoerciveRBReductor(
3544
d,
3645
product=d.energy_product,
37-
coercivity_estimator=ExpressionParameterFunctional("max(mu)", d.parameters),
46+
coercivity_estimator=ExpressionParameterFunctional('max(mu)', d.parameters),
3847
)
3948

4049
# greedy basis generation
4150
greedy_data = rb_greedy(
4251
d,
4352
reductor,
4453
parameter_space.sample_uniformly(3),
45-
extension_params={"method": "gram_schmidt"},
54+
extension_params={'method': 'gram_schmidt'},
4655
max_extensions=5,
4756
)
4857

4958
# get reduced order model
50-
rd = greedy_data["rom"]
59+
rd = greedy_data['rom']
5160

5261
# validate reduced order model
5362
result = reduction_error_analysis(
5463
rd,
5564
d,
5665
reductor,
5766
test_mus=parameter_space.sample_randomly(10),
58-
basis_sizes=reductor.bases["RB"].dim + 1,
67+
basis_sizes=reductor.bases['RB'].dim + 1,
5968
condition=True,
6069
error_norms=[d.energy_norm],
6170
plot=plot_error,
6271
)
6372

6473
# visualize solution for parameter with maximum reduction error
65-
mu_max = result["max_error_mus"][0, -1]
74+
mu_max = result['max_error_mus'][0, -1]
6675
U = d.solve(mu_max)
6776
U_rb = reductor.reconstruct(rd.solve(mu_max))
6877
return result, U, U_rb, d
6978

7079

71-
if __name__ == "__main__":
80+
if __name__ == '__main__':
7281
# print/plot results of validation
7382
from matplotlib import pyplot as plt
7483

7584
result, U, U_rb, d = run()
76-
print(result["summary"])
85+
print(result['summary'])
7786
ERR = U - U_rb
78-
d.visualize([U, U_rb, ERR], legend=["fom", "rom", "error"])
87+
d.visualize([U, U_rb, ERR], legend=['fom', 'rom', 'error'])
7988
plt.show()

src/pymor_dealii/pymor/gui.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ def visualize(
2727
assert title is None or filename is None
2828
assert legend is None or len(legend) == len(U)
2929

30-
base_name = title or filename or "out"
30+
base_name = title or filename or 'out'
3131
if len(U) == 1 and not legend:
3232
filenames = [base_name]
3333
else:
3434
legend = legend or list(map(str, list(range(len(U)))))
35-
filenames = ["_".join((base_name, l)) for l in legend]
35+
filenames = ['_'.join((base_name, l)) for l in legend]
3636

3737
for u, n in zip(U, filenames):
3838
uu = u.vectors[0]
3939
if uu.imag_part is not None:
40-
self.logger.warning("Imaginary part ignored.")
41-
self.impl.visualize(uu.real_part.impl, n + ".vtk")
40+
self.logger.warning('Imaginary part ignored.')
41+
self.impl.visualize(uu.real_part.impl, n + '.vtk')

src/pymor_dealii/pymor/operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Copyright 2013-2018 pyMOR developers and contributors. All rights reserved.
33
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
44

5+
import pymor_dealii_bindings as pd2
56
from pymor.operators.list import LinearComplexifiedListVectorArrayOperatorBase
67

78
from pymor_dealii.pymor.vectorarray import DealIIVectorSpace
8-
import pymor_dealii_bindings as pd2
99

1010

1111
class DealIIMatrixOperator(LinearComplexifiedListVectorArrayOperatorBase):

src/pymor_dealii/pymor/vectorarray.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
HAVE_DEALII = False
1111

1212
import numpy as np
13-
1413
from pymor.vectorarrays.list import ComplexifiedListVectorSpace, CopyOnWriteVector
1514

1615

test/test_bindings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ def test_vector():
4343
assert np.allclose(npdd, ddones)
4444

4545

46-
if __name__ == "__main__":
46+
if __name__ == '__main__':
4747
test_vector()

test/test_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ def test_demo_results(ndarrays_regression):
33

44
result, _, _, _ = run(plot_error=False)
55

6-
compare = ["errors", "basis_sizes", "rel_errors"]
6+
compare = ['errors', 'basis_sizes', 'rel_errors']
77
ndarrays_regression.check({k: v for k, v in result.items() if k in compare})

0 commit comments

Comments
 (0)