adjtomo / seisflows

An automated workflow tool for full waveform inversion and adjoint tomography
http://seisflows.readthedocs.org
BSD 2-Clause "Simplified" License
178 stars 122 forks source link

Model class does not work with decomposed Cartesian meshes & NumPy>=1.24 #214

Closed bch0w closed 4 months ago

bch0w commented 4 months ago

TL;DR NumPy does not like making lists of lists where the individual lists have different arrays. SeisFlows likes to do this and will have to change it's implementation to satisfy NumPy. If you are using CUBIT meshes, please downgrade to NumPy <= 1.23

@casarotti has pointed out that the latest versions of Numpy.array() do not play nice with lists of varying lengths. SeisFlows' Model class builds internal representations of SPECFEM models by shoving all the chunks into an array of arrays. This is fine for regularly decomposed meshes (which is what 3DGLOBE and "french-fry" decomposed meshes in 3D_Cartesian) does, but for meshes that are more intelligently decomposed (like those coming out of Cubit), this does not hold true and the Model class fails to read in files. The line of code in question is:

https://github.com/adjtomo/seisflows/blob/dc956e1b3c17bd723f557d838eaee0d98bc51b55/seisflows/tools/model.py#L736-L739

The resulting error message will look something like:

ValueError: setting an array element with a sequence. The requested
array has an inhomogeneous shape after 1 dimensions. The detected
shape was (8,) + inhomogeneous part.

With NumPy <= 1.23 you will get a VisibleDeprecationWarning:

VisibleDeprecationWarning: Creating an ndarray from ragged
nested sequences (which is a list-or-tuple of lists-or-tuples-or
ndarrays with different lengths or shapes) is deprecated. If you meant
to do this, you must specify 'dtype=object' when creating the ndarray.

Might be worth trying dtype=object, but my previous comment above the aforementioned code line makes me think this will not work as we want. More testing required but for now any Users that hit this error (likely those using CUBIT meshes in 3D_Cartesian) will need to downgrade to NumPy 1.23

bch0w commented 4 months ago

Fixed in #215