<p dir="auto">I recently purchased new Mac Pro w/ Mac Os X 11.0.1 &amp; Apple Silicon M1.</p>
<p dir="auto">I installed homebrew (when enabling Rosetta) and managed to install python3.9 and other packages through brew (numpy==1.19.5 &amp; scipy==1.6.0, amongst others).</p>
<p dir="auto">However, executing my one-liner script yields a "bus error". That happens when I try to import curve_fit from scipy.optimize. Any ideas how to solve that?</p>
<p dir="auto">I believe this is hardware related and is due to non optimal compilation of scipy for the M1 architecture (data are lost somewhere on the memory bus? <a href="https://www.quora.com/Why-there-is-a-bus-error-in-the-Python-program-when-it-recurs-over-18-713-times" rel="nofollow">https://www.quora.com/Why-there-is-a-bus-error-in-the-Python-program-when-it-recurs-over-18-713-times</a> ).</p>
<p dir="auto">Python code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from scipy.optimize import curve_fit"><pre class="notranslate"><code class="notranslate">from scipy.optimize import curve_fit
</code></pre></div>
<p dir="auto">Error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="zsh: bus error"><pre class="notranslate"><code class="notranslate">zsh: bus error
</code></pre></div>
<p dir="auto">Tail lines when running this code in python3.9 with -v option.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import 'scipy.sparse.linalg.dsolve' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x1182ad040&gt;
# /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/__pycache__/__init__.cpython-39.pyc matches /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/__init__.py
# code object from '/opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/__pycache__/__init__.cpython-39.pyc'
# /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__pycache__/__init__.cpython-39.pyc matches /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__init__.py
# code object from '/opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__pycache__/__init__.cpython-39.pyc'
# /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__pycache__/arpack.cpython-39.pyc matches /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.py
# code object from '/opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__pycache__/arpack.cpython-39.pyc'
zsh: bus error  python3.9 -v debug.py"><pre class="notranslate"><code class="notranslate">import 'scipy.sparse.linalg.dsolve' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x1182ad040&gt;
# /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/__pycache__/__init__.cpython-39.pyc matches /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/__init__.py
# code object from '/opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/__pycache__/__init__.cpython-39.pyc'
# /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__pycache__/__init__.cpython-39.pyc matches /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__init__.py
# code object from '/opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__pycache__/__init__.cpython-39.pyc'
# /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__pycache__/arpack.cpython-39.pyc matches /opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.py
# code object from '/opt/homebrew/lib/python3.9/site-packages/scipy/sparse/linalg/eigen/arpack/__pycache__/arpack.cpython-39.pyc'
zsh: bus error  python3.9 -v debug.py
</code></pre></div>
<p dir="auto">I also posted this question on stack overflow: <a href="https://stackoverflow.com/questions/65838231/importing-scipy-in-python-3-9-1-yields-zsh-bus-error-apple-silicon-m1-mac-os-1" rel="nofollow">https://stackoverflow.com/questions/65838231/importing-scipy-in-python-3-9-1-yields-zsh-bus-error-apple-silicon-m1-mac-os-1</a></p>
<p dir="auto">My issue is about NaNs produced using scipy.interpolate.griddata.</p>
<p dir="auto">Consider that the values from <code class="notranslate">values.csv</code> are defined for each point from <code class="notranslate">points.csv</code>.<br>
We would like to get interpolated values for points from <code class="notranslate">xi.csv</code>.<br>
In the following code snippet I check whether the interpolated values contain any NaNs.</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from scipy.interpolate import griddata
import numpy as np
import pandas as pd

points = pd.read_csv('points.csv').values
values = pd.read_csv('values.csv').values
xi = pd.read_csv('xi.csv').values

interpolated = griddata(points, values, xi, method='linear', rescale=True)

idx_nan = np.where(np.isnan(interpolated))[0]
if idx_nan.any():
    print('NaNs are present')
    print(xi[idx_nan])
else:
    print('Success')
"><pre class="notranslate"><code class="notranslate">from scipy.interpolate import griddata
import numpy as np
import pandas as pd

points = pd.read_csv('points.csv').values
values = pd.read_csv('values.csv').values
xi = pd.read_csv('xi.csv').values

interpolated = griddata(points, values, xi, method='linear', rescale=True)

idx_nan = np.where(np.isnan(interpolated))[0]
if idx_nan.any():
    print('NaNs are present')
    print(xi[idx_nan])
else:
    print('Success')

</code></pre></div>
<p dir="auto">I used two sets of inputs for points and values: <code class="notranslate">with_duplicates</code> and <code class="notranslate">no_duplicates</code>.<br>
In the former ones there are points with the duplicate coordinates, while in the other one they are eliminated.</p>
<h3 dir="auto">Outputs</h3>
<h4 dir="auto">With Duplicates</h4>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="NaNs are present
[[ 2.   0.   0.  30. ]
 [ 2.   0.   0.  50. ]
 [ 2.   0.   0.  70. ]
 [ 2.5  0.   0.  30. ]
 [ 2.5  0.   0.  50. ]
 [ 2.5  0.   0.  70. ]
 [ 3.   0.   0.  30. ]
 [ 3.   0.   0.  50. ]
 [ 3.   0.   0.  70. ]
 [ 3.5  0.   0.  30. ]
 [ 3.5  0.   0.  50. ]
 [ 3.5  0.   0.  70. ]
 [ 4.   0.   0.  30. ]
 [ 4.   0.   0.  50. ]
 [ 4.   0.   0.  70. ]
 [ 4.5  0.   0.  30. ]
 [ 4.5  0.   0.  50. ]
 [ 4.5  0.   0.  70. ]
 [ 5.   0.   0.  30. ]
 [ 5.   0.   0.  50. ]
 [ 5.   0.   0.  70. ]]
"><pre class="notranslate"><code class="notranslate">NaNs are present
[[ 2.   0.   0.  30. ]
 [ 2.   0.   0.  50. ]
 [ 2.   0.   0.  70. ]
 [ 2.5  0.   0.  30. ]
 [ 2.5  0.   0.  50. ]
 [ 2.5  0.   0.  70. ]
 [ 3.   0.   0.  30. ]
 [ 3.   0.   0.  50. ]
 [ 3.   0.   0.  70. ]
 [ 3.5  0.   0.  30. ]
 [ 3.5  0.   0.  50. ]
 [ 3.5  0.   0.  70. ]
 [ 4.   0.   0.  30. ]
 [ 4.   0.   0.  50. ]
 [ 4.   0.   0.  70. ]
 [ 4.5  0.   0.  30. ]
 [ 4.5  0.   0.  50. ]
 [ 4.5  0.   0.  70. ]
 [ 5.   0.   0.  30. ]
 [ 5.   0.   0.  50. ]
 [ 5.   0.   0.  70. ]]

</code></pre></div>
<p dir="auto">I wonder why the NaNs were generated not for all points.<br>
Note, that there were no NaNs for <code class="notranslate">[1 0 0 30]</code> point, for example.</p>
<p dir="auto">The points, where we have NaNs as a results on interpolation are actually present in <code class="notranslate">points.csv</code>, for example <code class="notranslate">[5, 0, 0, 30]</code> is there.<br>
Thus, it is surprising why interpolation led to NaNs even if there is a perfect match in the <code class="notranslate">points</code> array.</p>
<h4 dir="auto">No Duplicates</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Success"><pre class="notranslate"><code class="notranslate">Success
</code></pre></div>
<p dir="auto">I removed duplicate points and re-ran the code snippet. Now it was a success.</p>
<p dir="auto">It is not clear, though, why there would be such a behavior with <code class="notranslate">with_duplicates</code>. If the point from <code class="notranslate">xi</code> matches point from <code class="notranslate">points</code> array, then it seems that the algorithm should just pick the corresponding value.</p>
<h3 dir="auto">Scipy/Numpy/Python version information:</h3>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
1.2.1 1.16.3 sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
1.2.1 1.16.3 sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
</code></pre></div>
<h2 dir="auto">Files with data</h2>
<p dir="auto"><a href="https://github.com/scipy/scipy/files/3321221/xi.zip">xi.zip</a><br>
<a href="https://github.com/scipy/scipy/files/3321213/with_duplicates.zip">with_duplicates.zip</a><br>
<a href="https://github.com/scipy/scipy/files/3321225/no_duplicates.zip">no_duplicates.zip</a></p>