microsoft/scenepic

numpy 1.23 breaks scenepick

TadasBaltrusaitis opened this issue · 9 comments

Update to numpy==1.23.0 breaks scenepic 1.0.8 (on Windows and Ubuntu).

Reproduced by using a reduced jelly example:

import scenepic as sp
import numpy as np

scene = sp.Scene()
canvas = scene.create_canvas_3d(width=700, height=700)

jelly_mesh = sp.load_obj(r"C:\Users\tabaltru\Downloads\jelly.obj")
texture = scene.create_image("texture")
texture.load(r"C:\Users\tabaltru\Downloads\jelly.png")

base_mesh = scene.create_mesh("jelly_base")
base_mesh.texture_id = texture.image_id
base_mesh.use_texture_alpha = True
base_mesh.add_mesh(jelly_mesh)

positions = jelly_mesh.positions.copy()
mesh_update = scene.update_mesh_without_normals("jelly_base", positions)

Leads to the following error:

Exception has occurred: TypeError
update_mesh_without_normals(): incompatible function arguments. The following argument types are supported:
    1. (self: scenepic._scenepic.Scene, base_mesh_id: str, positions: numpy.ndarray[numpy.float32[m, 3], flags.c_contiguous], mesh_id: str = '') -> scenepic._scenepic.MeshUpdate

Invoked with: <scenepic._scenepic.Scene object at 0x000001FB7FD8ECB0>, 'jelly_base', array([], shape=(0, 3), dtype=float32)
  File "C:\code\mrai.moai\moai\sampling\scenepic_test.py", line 17, in <module>
    mesh_update = scene.update_mesh_without_normals("jelly_base", positions)

Tried in a clean conda environment both with numpy==1.22.0 and numpy==1.23.0 with only the latter breaking.

I tried to reproduce, but couldn't do so with numpy 1.23.0 and scenepic 1.0.8 on Python 3.9.6 in a virtualenv. The following seems to complete without error (where test.py is the example above):

> virtualenv testnpsp
created virtual environment CPython3.9.6.final.0-64 in 8103ms
  creator CPython3Windows(dest=D:\Repos\scenepic\testnpsp, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=~\AppData\Local\pypa\virtualenv)
    added seed packages: pip==22.1.2, setuptools==62.6.0, wheel==0.37.1
  activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

> cd testnpsp

testnpsp> Scripts\activate

(testnpsp) testnpsp> pip install numpy==1.23.0 scenepic==1.0.8
Collecting numpy==1.23.0
  Using cached numpy-1.23.0-cp39-cp39-win_amd64.whl (14.7 MB)
Collecting scenepic==1.0.8
  Using cached scenepic-1.0.8-cp39-cp39-win_amd64.whl (557 kB)
Collecting pillow>=5.2.0
  Using cached Pillow-9.1.1-cp39-cp39-win_amd64.whl (3.3 MB)
Collecting scipy>=1.4.1
  Using cached scipy-1.8.1-cp39-cp39-win_amd64.whl (36.9 MB)
Installing collected packages: pillow, numpy, scipy, scenepic
Successfully installed numpy-1.23.0 pillow-9.1.1 scenepic-1.0.8 scipy-1.8.1

(testnpsp) testnpsp> python test.py
scenepic[info]> Disabling VideoWriter due to ImportError

Maybe we need a bit more info on the configuration where the error occurs?

Interesting, here's my pip freeze on a Windows machine with Python 3.8.13 environment managed through Miniconda3:

numpy==1.23.0
Pillow==9.1.1
scenepic==1.0.8
scipy==1.8.1
wincertstore==0.2

Just tried with Python 3.9.12 on my machine and it still fails. Complete repro steps with miniconda:

conda create -n scenepic python=3.9
conda activate scenepic
pip install numpy==1.23
pip install scenepic

Still results in above error, if I do:

pip uninstall numpy
pip install numpy==1.22

The above error is fixed

Pip freeze after installing numpy==1.22, seems like all the other modules are the same, the only difference in numpy

numpy==1.22.0
Pillow==9.1.1
scenepic==1.0.8
scipy==1.8.1
wincertstore==0.2

unable to replicate with python 3.9 or 3.10 😒

Here is a minimal example that replicates the issue we are seeing - I think Tadas' above was not correct:

import scenepic as sp
import numpy as np

scene = sp.Scene()
mesh = scene.create_mesh("a_mesh", shared_color=sp.Colors.Blue)
mesh.add_mesh_without_normals(np.zeros((5, 3), dtype=float), np.zeros((5, 3), dtype=int))

For me this works with numpy==1.22 and fails with numpy==1.23:

Traceback (most recent call last):
  File "c:\Users\chewitt\Dev\tmp\scenepic_test.py", line 8, in <module>
    mesh.add_mesh_without_normals(np.zeros((5, 3), dtype=np.float32), np.zeros((5, 3), dtype=np.uint8))
TypeError: add_mesh_without_normals(): incompatible function arguments. The following argument types are supported:
    1. (self: scenepic._scenepic.Mesh, vertices: numpy.ndarray[numpy.float32[m, 3], flags.c_contiguous], triangles: numpy.ndarray[numpy.uint32[m, 3], flags.c_contiguous], colors: numpy.ndarray[numpy.float32[m, 3], flags.c_contiguous] = array([], shape=(0, 3), dtype=float32), uvs: numpy.ndarray[numpy.float32[m, 2], flags.c_contiguous] = array([], shape=(0, 2), dtype=float32), transform: numpy.ndarray[numpy.float32[4, 4]] = array([[1., 0., 0., 0.],
       [0., 1., 0., 0.],
       [0., 0., 1., 0.],
       [0., 0., 0., 1.]], dtype=float32), reverse_triangle_order: bool = False, fill_triangles: bool = True, add_wireframe: bool = False) -> None

Invoked with: {
        "CameraSpace": false,
        "CommandType": "DefineMesh",
        "Definition":
        {
                "Color": "eAEBDADz/4eGhj6GhQU/AACAPx33A+ADAAAAAQ==",
                "IndexBufferType": "UInt16",
                "LineBuffer": "eAEDAAAAAAEAAAAAAg==",
                "PrimitiveType": "SingleColorMesh",
                "TriangleBuffer": "eAEDAAAAAAEAAAAAAw==",
                "VertexBuffer": "eAEDAAAAAAEAAAAABg=="
        },
        "DoubleSided": false,
        "IsBillboard": false,
        "IsLabel": false,
        "LayerId": null,
        "MeshId": "jelly_base"
}
, array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]], dtype=float32), array([[0, 0, 0],
       [0, 0, 0],
       [0, 0, 0],
       [0, 0, 0],
       [0, 0, 0]], dtype=uint8)

@matajoh - any ideas on this, currently breaking a lot of our CI :(

I think this is the root issue: pybind/pybind11#4038 (and hence will be fixed by the next pybind11 release, or by pulling pybind11 from source at commit 479e9a5 or later).

I verified that Charlie's repro leads to an array with zero-size dimensions in pybind11, which leads to EigenConformable::stride_compatible returning false for earlier versions of pybind11.

I tried making the update to pybind11 in #35 , which is waiting on a review.

Local test confirmed that @tjcashman's fix works so this issue can be closed 😄

Closing this issue as resolved, thanks for the help everyone!