Skip to content

Commit 4979329

Browse files
committed
Merge branch 'python-test-matrix' into 'development'
test min Python version on merge request See merge request damask/DAMASK!1029
2 parents 94f0b13 + 7c7051b commit 4979329

File tree

4 files changed

+63
-24
lines changed

4 files changed

+63
-24
lines changed

.gitlab-ci.yml

+44-8
Original file line numberDiff line numberDiff line change
@@ -54,42 +54,78 @@ create_testroot:
5454
script:
5555
- mkdir -p ${TESTROOT}
5656

57+
.on_merge:
58+
rules:
59+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
60+
5761
###################################################################################################
5862

59-
.python:
63+
.python_base:
6064
stage: python
65+
image: git.damask-multiphysics.org:5050/damask/damask/python:$PYTHON_IMAGE
6166
tags:
6267
- matesting2-container-runner
63-
image: git.damask-multiphysics.org:5050/damask/damask:python310_2412
6468
before_script:
69+
- python --version
6570
- pip list
6671

67-
create_package:
68-
extends: .python
72+
.python_default:
73+
extends: .python_base
74+
variables: {PYTHON_IMAGE: 2025.01.05}
75+
76+
.python_min:
77+
extends: .python_base
78+
variables: {PYTHON_IMAGE: '310_2412'}
79+
80+
81+
.create_package:
6982
script:
7083
- sed -i 's/-[[:digit:]]*-.*//' VERSION
7184
- cd python
7285
- python3 -m build --wheel --no-isolation
7386

74-
pytest:
75-
extends: .python
87+
create_package:
88+
extends:
89+
- .create_package
90+
- .python_default
91+
92+
create_package_min:
93+
extends:
94+
- .create_package
95+
- .python_min
96+
- .on_merge
97+
98+
99+
.pytest:
76100
script:
77101
- export DAMASK_ROOT=$(pwd)
78102
- PYTHONPATH=${DAMASK_ROOT}/python:$PYTHONPATH
79103
- cd python
80104
- python3 -m pytest -v --cov=damask --cov-report=xml --damaskroot=${DAMASK_ROOT}
81105
- coverage report --fail-under=90 --show-missing
82106

107+
pytest:
108+
extends:
109+
- .pytest
110+
- .python_default
111+
112+
pytest_min:
113+
extends:
114+
- .pytest
115+
- .python_min
116+
- .on_merge
117+
118+
83119
doctest:
84-
extends: .python
120+
extends: .python_default
85121
script:
86122
- export DAMASK_ROOT=$(pwd)
87123
- PYTHONPATH=${DAMASK_ROOT}/python:$PYTHONPATH
88124
- cd python
89125
- python3 -m pytest -v --doctest-modules -k 'not result and not configmaterial and not orientation and not rotation and not geomgrid' damask
90126

91127
mypy:
92-
extends: .python
128+
extends: .python_default
93129
script:
94130
- cd python
95131
- mypy damask

python/damask/_orientation.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import copy
22
import warnings
3-
from typing import Optional, Union, TypeVar, Literal, Sequence, NamedTuple # mypy 1.11, overload
3+
from typing import Optional, Union, TypeVar, Literal, Sequence, NamedTuple, overload
44

55
import numpy as np
66
import numpy.typing as npt
@@ -1311,7 +1311,7 @@ def disorientation_angle(self: MyType,
13111311
else:
13121312
return self.disorientation(other).as_axis_angle(pair=True)[1] # type: ignore
13131313

1314-
return 2.*np.arccos(np.clip(np.round(trace_max[...,0],15),None,1.))
1314+
return 2.*np.arccos(np.clip(trace_max[...,0].round(15),None,1.))
13151315

13161316

13171317
def average(self: MyType, # type: ignore[override]
@@ -1355,18 +1355,20 @@ def average(self: MyType,
13551355
else:
13561356
return self.copy(Rotation(r).average(weights))
13571357

1358-
# mypy 1.11
1359-
#@overload
1360-
#def to_SST(self, vector: FloatSequence, proper: bool = False, # noqa
1361-
# return_operator: Literal[False] = False) -> np.ndarray: ...
1362-
#@overload
1363-
#def to_SST(self, vector: FloatSequence, proper: bool = False, # noqa
1364-
# return_operator: Literal[True] = True) -> Tuple[np.ndarray,np.ndarray]: ...
1358+
@overload
1359+
def to_SST(self, vector: FloatSequence, proper: bool = False,
1360+
return_operator: Literal[False] = False,
1361+
return_operators: bool = False) -> np.ndarray:
1362+
...
1363+
@overload
1364+
def to_SST(self, vector: FloatSequence, proper: bool = False,
1365+
return_operator: Literal[True] = True,
1366+
return_operators: bool = False) -> ToSSTTuple:
1367+
...
13651368
def to_SST(self,
13661369
vector: FloatSequence,
13671370
proper: bool = False,
13681371
return_operator: bool = False,
1369-
# return_operators: bool = False) -> Union[np.ndarray,Tuple[np.ndarray,np.ndarray]]:
13701372
return_operators: bool = False) -> Union[np.ndarray, ToSSTTuple]:
13711373
"""
13721374
Rotate lab frame vector to ensure it falls into (improper or proper) standard stereographic triangle of crystal symmetry.
@@ -1531,7 +1533,7 @@ def IPF_color(self,
15311533
np.broadcast_to(self.standard_triangle['improper'], vector_.shape+(3,)),
15321534
np.block([vector_[...,:2],np.abs(vector_[...,2:3])])), 12)
15331535

1534-
in_SST_ = np.all(components >= 0.0,axis=-1)
1536+
in_SST_ = np.all(components >= 0.0,axis=-1) #type: ignore
15351537

15361538
with np.errstate(invalid='ignore',divide='ignore'):
15371539
rgb = (components/np.linalg.norm(components,axis=-1,keepdims=True))**(1./3.) # smoothen color ramps

python/tests/conftest.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ def report_nonclose(a, b, rtol, atol, N, msg):
244244
Description of differences.
245245
246246
"""
247-
a_ = np.array(a)
248-
b_ = np.array(b)
247+
a_ = np.asarray(a)
248+
b_ = np.asarray(b)
249+
if a_.shape != b_.shape: b_ = np.broadcast_to(b_,a.shape)
249250

250251
absdiff = np.abs(a_ - b_)
251252
absmax = np.max(np.abs(np.stack((a_, b_))), axis=0)

python/tests/test_Orientation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,10 @@ def test_disorientation_invalid(self,np_rng):
294294
o_1.disorientation_angle(o_2)
295295

296296
@pytest.mark.parametrize('family',crystal_families)
297-
def test_disorientation_zero(self,set_of_quaternions,family):
297+
def test_disorientation_zero(self,assert_allclose,set_of_quaternions,family):
298298
o = Orientation.from_quaternion(q=set_of_quaternions,family=family)
299-
assert np.allclose(o.disorientation_angle(o),0.0,atol=1e-15,rtol=0.)
300-
assert np.allclose(o.disorientation(o).as_axis_angle(pair=True)[1],0.,atol=1e-15,rtol=0.)
299+
assert_allclose(o.disorientation_angle(o),0.0,atol=1e-7,rtol=0.)
300+
assert_allclose(o.disorientation(o).as_axis_angle(pair=True)[1],0.,atol=1e-15,rtol=0.)
301301

302302
@pytest.mark.parametrize('color',[{'label':'red', 'RGB':[1,0,0],'direction':[0,0,1]},
303303
{'label':'green','RGB':[0,1,0],'direction':[0,1,1]},

0 commit comments

Comments
 (0)