ContactEngineering / ContactMechanics

Contact mechanics using elastic half-space methods
https://contactengineering.github.io/ContactMechanics/
MIT License
21 stars 5 forks source link

scipy 1.19.0 causes broadcoast errors with numpy #80

Open sannant opened 2 years ago

sannant commented 2 years ago

Causes

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
ContactMechanics/Systems.py:840: in dual_minimize_proxy
    result = optim.minimize(self.dual_objective(offset, gradient=True),
../venv/lib/python3.10/site-packages/scipy/optimize/_minimize.py:684: in minimize
    bounds = standardize_bounds(bounds, x0, meth)
../venv/lib/python3.10/site-packages/scipy/optimize/_minimize.py:947: in standardize_bounds
    bounds = new_bounds_to_old(bounds.lb, bounds.ub, x0.shape[0])
../venv/lib/python3.10/site-packages/scipy/optimize/_constraints.py:390: in new_bounds_to_old
    lb = np.broadcast_to(lb, n)
<__array_function__ internals>:180: in broadcast_to
    ???
../venv/lib/python3.10/site-packages/numpy/lib/stride_tricks.py:413: in broadcast_to
    return _broadcast_to(array, shape, subok=subok, readonly=True)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

array = array([0., 0., 0., ..., 0., 0., 0.]), shape = (128,), subok = False, readonly = True

    def _broadcast_to(array, shape, subok, readonly):
        shape = tuple(shape) if np.iterable(shape) else (shape,)
        array = np.array(array, copy=False, subok=subok)
        if not shape and array.shape:
            raise ValueError('cannot broadcast a non-scalar to a scalar array')
        if any(size < 0 for size in shape):
            raise ValueError('all elements of broadcast shape must be non-'
                             'negative')
        extras = []
>       it = np.nditer(
            (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras,
            op_flags=['readonly'], itershape=shape, order='C')
E       ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (16384,)  and requested shape (128,)

../venv/lib/python3.10/site-packages/numpy/lib/stride_tricks.py:349: ValueError
sannant commented 2 years ago

e.g. workflow run

https://github.com/ContactEngineering/ContactMechanics/runs/7583136340?check_suite_focus=true

I did a vimdiff between a running and a broken workflow: config_broken.txt config_working.txt

It indicated me the solution: with scipy 1.18 it works.

As a temporary fix I set scipy<=1.18.1 as requirement

sannant commented 2 years ago

We will need to figure out what to change. Note that I expect this to affect Adhesion as well