Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backports #873

Merged
merged 7 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
- name: Configure MKL
if: ${{ matrix.matrix-backend == 'mkl' }}
run: |
python -um pip install --upgrade --upgrade-strategy eager 'mkl<2024'
python -um pip install --upgrade --upgrade-strategy eager mkl
python -um devtools.gha.configure_mkl
- name: Test
run: python -um coverage run -m unittest discover -b -q -t . -s tests
Expand Down
28 changes: 14 additions & 14 deletions examples/cahnhilliard.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,22 @@ def test_multipatchcircle(self):
args = main(epsilon=parse('5cm'), mobility=parse('1μL*s/kg'), nelems=3, etype='multipatch', degree=2, timestep=parse('1h'), endtime=parse('2h'))
with self.subTest('concentration'):
self.assertAlmostEqual64(args['φ'], '''
eNoNyE9Ik3EYB3BwZohodpCSIk9NQub7/n7PA5IHu7Y6xKBbgUQK0mGUMIS6jIgmJRZitc3MEi/VxQVz
XsouDcHn+7w///B22HYU/wTBOuwUmcfPp8Yhr/JfrnOJJ3iU2/g1X+YHXKMcrdnvVLYt9NwMmlTfBn2g
ZhL71OZMl214H72yu+6KmtFdpPxFbzjcu3Rl59rmafdMe1xVS7iFdk2jKdjRcb0JHxGQhriDs/oeoRTk
SMoyiJN4JVl5I7OSdLeDqJ6y2ybtj6Ahb8NDXTr+PLpRoEWy9If2qUCz9oV/n+ZsJajil9/hcvyS77JS
iSbJcJEStGxbqWC+mHp/zc7bIdttV82cv2aS/ufYuOurLATr2qPzXjX2wx3qCZ1AHMbNBBVd8rZiDXdD
v+FM0KEJdGIEXfhtHppJ7ypdpEf2yGV0zER60ziPBc2ik/9Rltpp2tituCb6c8G5YBcHGEAU21KUKXmC
ZlzAT3knjyUvn+SefJVNWTl2TXrxHyMaybw=''')
eNoNwk1I02EcB/AGnYQCQcvDBqYYVGz7P8/v93QIyhdYK8lyDktKx8ouQ0hz6EEdjOpWdIqCXrAONrAg
AhGGBSHhxe/v+f//8yVpWIGXgk5DSAjf+HzyZsKkTZv5xdf5PN01A8aYCndwgrKq2hw0bzjEtfTdmfIK
/JBX6Z2eiN6zz+Uf+bSt76g635WoFHVO59SfyFE3KxsIqU2nyZmMOF6rjclbeSTDcmNfv3RLFEEoXEIe
s/iKT3iMJ3iJaczgPUL2s4wISQVFvEBKG92oLkSSblGCEuezvEgnKKOueWXp46tczz/pMI2qW94DkzPt
5pDJ8yx16Sqzw/M8xt+orCvObb7IB7hAazql5laDtK4zuqSGnd3lTrcuHCid9pLumh20W7JQivkfXbFL
ckq+oDV6LHzTv+8esc0iOKOeOqlIjT9oe6SMBBE906/V35N52y9JjvMPukxLaqh03DasxN0tGZD/2JaU
/MYCpvABWZzDFaQxjl60YAgFdKMT7XiFgOwBQRG+vg==''')
with self.subTest('chemical-potential'):
self.assertAlmostEqual64(args['η'], '''
eNoBggF9/lU4VTgzOIo4kDhIOCY3Lzd5Ngw4xjf1N1o3YzV70II3ijZoNuIyZcpFybM1jjXxzgY28TVH
zyLKzMjGyXfICsjfx73Hl8dyMzozgstEylLKFsqEyU3I2snuyJvHZMc7yLzHKctJy6rKqci4yGDIrcqK
yvLID8royADInMcIyJ7HI8jnx13HcMdax2fHWNPez6/JHzZENjI1V8jHx7AxHMpqx2PHpMgAyDk4SDgR
OH84gThhONA3ejY/OJw3Y84NyYY2C8x1NqU2BjfJyQTKYC9rN303ATZmNnY3TTaMNmI0e8mFyf3KKjYz
Nj80DDD+Mn3MhsqCM/bLsslNyRo3BzcuNUbLEMk7yDfI0snXyWjJu817zdTK+8hRyLPJt8jYx4/HEMiy
x5wzXTNbzP02CTdQNmLKFslCNc7MRcjSx5DJZ8hiOG04JDjJN4020jBZySIwQsvxyJDInMlnyCzIxMes
x3DHmMeAx1fHVMdfx0vHS8dsxzzHl8csxz3HSceixxfIfsLEFg==''')
eNoN0F8onWEcB/AjQ1pNoZb8u8Ki0HvO+zy/F4uJ2eTG7I9W1q602toOdS4pIXZSs+zUpJN2ywXJboTE
/H7f53lf08nalZqkJldGmXYzbj+Xn2X6StM0RKf6v0rtvKS3dI8yqFOd2W5k0i3K0MfhLPNeiuQ+NVC6
O4NK6ec33ESKYu4/PJdJjnGzJm0jIRvIT45zcnc19SVo9PPMX3FkClOYxBg+YxuMqmt5KsOyJ9UoQ1Jm
RORCbuI2DuQAh/iNfbxCCPOSr+v0kKp1e/yQKUSH99g7olZKKt8HHE956d4G/dLFasXGKUHvqIXiulnN
+7m6TEf1pm7TnaokcMMPw2nK1eeqVtUEp86WMxuei9REup1Rm/P9xk6j32XJ1tmPZs2kTML0mj6sSYVs
mxPzw6pgwNQjKgmzZKr8wVSBncaieOq1unSb3PLgkSnFChlqp096ws3y15GNdowgiif4w3fkhYzLkjzg
AV7kM74rz/gDf+M8iV0fLvAxt8mWXAGfucYq''')


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions nutils/SI.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ def __pow_like(op, *args, **kwargs):
return (dim0**args[1]).wrap(op(arg0, *args[1:], **kwargs))

@register('isfinite', 'isnan', 'shape', 'ndim', 'size', 'normal', 'normalized')
def __unary_drop(op, *args, **kwargs):
def __unary_op(op, *args, **kwargs):
(_dim0, arg0), = Quantity.__unpack(args[0])
return op(arg0, *args[1:], **kwargs)

@register('lt', 'le', 'eq', 'ne', 'gt', 'ge', 'equal', 'not_equal', 'less',
'less_equal', 'greater', 'greater_equal')
def __binary_drop(op, *args, **kwargs):
def __binary_op(op, *args, **kwargs):
(dim0, arg0), (dim1, arg1) = Quantity.__unpack(args[0], args[1])
if dim0 != dim1:
raise TypeError(f'incompatible arguments for {op.__name__}: {dim0.__name__}, {dim1.__name__}')
Expand Down
18 changes: 12 additions & 6 deletions nutils/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def log_arguments(*args, **kwargs):
with treelog.context('arguments'):
for k, v in bound.arguments.items():
try:
s = stringly.dumps(sig.parameters[k].annotation, v)
s = stringly.dumps(_infer_type(sig.parameters[k]), v)
except:
s = str(v)
treelog.info(f'{k}={s}')
Expand Down Expand Up @@ -694,6 +694,16 @@ def add_htmllog(outrootdir: str = '~/public_html', outrooturi: str = '', scriptn
treelog.info(f'log written to: {loguri}')


def _infer_type(param):
'''Infer argument type from annotation or default value.'''

if param.annotation is not param.empty:
return param.annotation
if param.default is not param.empty:
return type(param.default)
raise Exception(f'cannot determine type for argument {param.name!r}')


def cli(f, *, argv=None):
'''Call a function using command line arguments.'''

Expand All @@ -706,11 +716,7 @@ def cli(f, *, argv=None):
mandatory = set()

for param in inspect.signature(f).parameters.values():
T = param.annotation
if T == param.empty and param.default != param.empty:
T = type(param.default)
if T == param.empty:
raise Exception(f'cannot determine type for argument {param.name!r}')
T = _infer_type(param)
try:
s = stringly.serializer.get(T)
except Exception as e:
Expand Down
11 changes: 8 additions & 3 deletions nutils/evaluable.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,16 @@ def _iter_stack(self):
for i, (op, indices) in enumerate(self.serialized, start=1):
s = [f'%{i} = {op}']
if indices:
args = [f'%{i}' for i in indices]
try:
sig = inspect.signature(op.evalf)
except ValueError:
s.extend(f'%{i}' for i in indices)
pass
else:
s.extend(f'{param}=%{i}' for param, i in zip(sig.parameters, indices))
for i, param in enumerate(sig.parameters.values()):
if i < len(args) and param.kind == param.POSITIONAL_OR_KEYWORD:
args[i] = param.name + '=' + args[i]
s.extend(args)
yield ' '.join(s)

def _format_stack(self, values, e):
Expand Down Expand Up @@ -2417,6 +2421,7 @@ def _simplified(self):
lower_dividend, upper_dividend = dividend._intbounds
if 0 <= lower_dividend and upper_dividend < lower_divisor:
return dividend
return super()._simplified()


class ArcTan2(Pointwise):
Expand Down Expand Up @@ -2447,7 +2452,7 @@ def _simplified(self):
if self.ndim == 2:
u1, w1 = unalign(a1)
u2, w2 = unalign(a2)
if u1 == u2 and isinstance(u1, Range):
if u1.ndim == u2.ndim == 1 and u1 == u2 and w1 != w2 and isinstance(u1, Range):
# NOTE: Once we introduce isunique we can relax the Range bound
return Diagonalize(ones(u1.shape, bool))
return super()._simplified()
Expand Down
6 changes: 1 addition & 5 deletions nutils/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,9 @@ def multipatch(patches, nelems, patchverts=None, name: Optional[str] = None):
]).T
coords.append(patchcoords)

# build patch boundary data

boundarydata = topology.MultipatchTopology.build_boundarydata(patches)

# join patch topologies, geometries

topo = topology.MultipatchTopology(tuple(map(topology.Patch, topos, patches, boundarydata)))
topo = topology.MultipatchTopology(topos, patches)
funcsp = topo.basis('spline', degree=1, patchcontinuous=False)
geom = (funcsp * numpy.concatenate(coords, axis=1)).sum(-1)

Expand Down
Loading
Loading