Genesis icon indicating copy to clipboard operation
Genesis copied to clipboard

/examples/vizualization.py not rendering on M1 Mac

Open vinny-888 opened this issue 1 year ago • 4 comments

Warning

[Genesis] [21:31:56] [WARNING] Non-linux system detected. In order to use the interactive viewer, you need to manually run simulation in a separate thread and then start viewer. See `examples/render_on_macos.py`.
[Genesis] [21:31:56] [INFO] Viewer created. Resolution: 1280×960, max_FPS: 60.

The program hangs after the first FPS is printed

I tried running render_on_macos.py while it is running but it just runs to completion and no visuals.

There is no video.mp4 produced from vizualization.py and it has to be killed

vinny-888 avatar Dec 19 '24 05:12 vinny-888

I also ran into this (running on a M1 Max). Note that you have to use the --vis flag (i.e. run_on_macos.py --vis). But in my case, it still fails with an OpenGL error:

python3.11 scripts/run_on_macos.py --vis
objc[38862]: Class GLFWHelper is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/taichi/_lib/core/taichi_python.cpython-311-darwin.so (0x15b600570) and /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygel3d/libPyGEL.dylib (0x3007157c0). One of the two will be used. Which one is undefined.
objc[38862]: Class GLFWApplicationDelegate is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/taichi/_lib/core/taichi_python.cpython-311-darwin.so (0x15b6005c0) and /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygel3d/libPyGEL.dylib (0x300715810). One of the two will be used. Which one is undefined.
objc[38862]: Class GLFWWindowDelegate is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/taichi/_lib/core/taichi_python.cpython-311-darwin.so (0x15b6005e8) and /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygel3d/libPyGEL.dylib (0x300715838). One of the two will be used. Which one is undefined.
objc[38862]: Class GLFWContentView is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/taichi/_lib/core/taichi_python.cpython-311-darwin.so (0x15b600638) and /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygel3d/libPyGEL.dylib (0x300715888). One of the two will be used. Which one is undefined.
objc[38862]: Class GLFWWindow is implemented in both /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/taichi/_lib/core/taichi_python.cpython-311-darwin.so (0x15b6006b0) and /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pygel3d/libPyGEL.dylib (0x300715900). One of the two will be used. Which one is undefined.
[Genesis] [23:07:10] [INFO] ╭─────────────────────────────────────────────────────────────────────────────────────╮
[Genesis] [23:07:10] [INFO] │┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉ Genesis ┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉│
[Genesis] [23:07:10] [INFO] ╰─────────────────────────────────────────────────────────────────────────────────────╯
[Genesis] [23:07:10] [INFO] Running on [Apple M1 Max] with backend gs.metal. Device memory: 32.00 GB.
[Genesis] [23:07:10] [INFO] 🚀 Genesis initialized. 🔖 version: 0.2.0, 🌱 seed: None, 📏 precision: '32', 🐛 debug: False, 🎨 theme: 'dark'.
[Genesis] [23:07:10] [INFO] Scene <ef5c424> created.
[Genesis] [23:07:10] [INFO] Adding <gs.RigidEntity>. idx: 0, uid: <dc593dc>, morph: <gs.morphs.Plane>, material: <gs.materials.Rigid>.
[Genesis] [23:07:10] [INFO] Adding <gs.RigidEntity>. idx: 1, uid: <be13865>, morph: <gs.morphs.MJCF(file='/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/assets/xml/franka_emika_panda/panda.xml')>, material: <gs.materials.Rigid>.
[Genesis] [23:07:11] [INFO] Building scene <ef5c424>...
[Genesis] [23:07:13] [INFO] Compiling simulation kernels...
[Genesis] [23:07:17] [INFO] Building visualizer...
[Genesis] [23:07:18] [WARNING] Non-linux system detected. In order to use the interactive viewer, you need to manually run simulation in a separate thread and then start viewer. See `examples/render_on_macos.py`.
[Genesis] [23:07:18] [INFO] Viewer created. Resolution: 744×558, max_FPS: 60.
[Genesis] [23:07:18] [INFO] Running at 2391.24 FPS.
119.56055984721074 FPS
[Genesis] [23:07:19] [INFO] Running at 717.60 FPS.
50.040014793781836 FPS
[Genesis] [23:07:19] [INFO] Running at 432.92 FPS.
50.53317429910483 FPS
[Genesis] [23:07:19] [INFO] Running at 314.56 FPS.
50.59168928291418 FPS
[Genesis] [23:07:19] [INFO] Running at 249.46 FPS.
50.36085729723239 FPS
2024-12-18 23:07:19.087 Python[38862:1236166] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/vz/gjbpzw6x6xj9kndxtnlpy0p40000gn/T/org.python.python.savedState
[Genesis] [23:07:19] [INFO] Running at 209.17 FPS.
51.20750109879377 FPS
[Genesis] [23:07:19] [INFO] Running at 184.33 FPS.
56.354602496405874 FPS
[Genesis] [23:07:19] [INFO] Running at 162.77 FPS.
50.25164737737522 FPS
[Genesis] [23:07:19] [INFO] Running at 146.67 FPS.
50.44080189530143 FPS
[Genesis] [23:07:19] [INFO] Running at 128.61 FPS.
38.35668952903521 FPS
Traceback (most recent call last):
  File "/Users/rob/Developer/Genesis/scripts/run_on_macos.py", line 68, in <module>
    main()
  File "/Users/rob/Developer/Genesis/scripts/run_on_macos.py", line 44, in main
    scene.viewer.start()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/vis/viewer.py", line 91, in start
    self._pyrender_viewer.start()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/viewer.py", line 386, in start
    self._init_and_start_app()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/viewer.py", line 1149, in _init_and_start_app
    pyglet.clock.tick()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/clock.py", line 528, in tick
    return _default.tick(poll)
           ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/clock.py", line 270, in tick
    self.call_scheduled_functions(delta_t)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/clock.py", line 217, in call_scheduled_functions
    item.func(now - item.last_ts, *item.args, **item.kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/viewer.py", line 941, in _time_event
    self.on_draw()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/viewer.py", line 640, in on_draw
    self._render()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/viewer.py", line 1086, in _render
    retval = renderer.render(self.scene, flags, seg_node_map=seg_node_map)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/renderer.py", line 168, in render
    retval = self._forward_pass(scene, flags, seg_node_map=seg_node_map)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/renderer.py", line 534, in _forward_pass
    self.jit.forward_pass(
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/jit_render.py", line 708, in forward_pass
    self.load_programs(renderer, flags, program_flags)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/jit_render.py", line 349, in load_programs
    program = renderer._get_primitive_program(primitive, flags, program_flags)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/renderer.py", line 1142, in _get_primitive_program
    program._add_to_context()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/ext/pyrender/shader_program.py", line 125, in _add_to_context
    self._program_id = gl_shader_utils.compileProgram(*shader_ids, validate=False)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/OpenGL/GL/shaders.py", line 196, in compileProgram
    program.check_validate()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/OpenGL/GL/shaders.py", line 105, in check_validate
    raise RuntimeError(
RuntimeError: Validation failure (0): b"Validation Failed: Sampler error:\n  Samplers of different types use the same texture image unit.\n   - or -\n  A sampler's texture unit is out of range (greater than max allowed or negative).\n"
^C2024-12-18 23:11:01.851 Python[38862:1236166] +[IMKClient subclass]: chose IMKClient_Modern
Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: initialized

Thread 0x0000000385807000 (most recent call first):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/vis/viewer.py", line 19 in __enter__
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/vis/viewer.py", line 112 in update
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/vis/visualizer.py", line 135 in update
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/engine/scene.py", line 676 in step
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/genesis/utils/misc.py", line 48 in wrapper
  File "/Users/rob/Developer/Genesis/scripts/run_on_macos.py", line 55 in run_sim
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 982 in run
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1045 in _bootstrap_inner
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1002 in _bootstrap

Current thread 0x00000002000d0240 (most recent call first):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1058 in __call__
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1094 in __call__
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyglet/app/cocoa.py", line 193 in term_received
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1590 in _shutdown

Extension modules: numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, torch._C, torch._C._dynamo.autograd_compiler, torch._C._dynamo.eval_frame, torch._C._dynamo.guards, torch._C._dynamo.utils, torch._C._fft, torch._C._linalg, torch._C._nested, torch._C._nn, torch._C._sparse, torch._C._special, psutil._psutil_osx, psutil._psutil_posix, PIL._imaging, cython.cimports.libc.math, scipy._lib._ccallback_c, scipy.sparse._sparsetools, _csparsetools, scipy.sparse._csparsetools, scipy.linalg._fblas, scipy.linalg._flapack, scipy.linalg.cython_lapack, scipy.linalg._cythonized_array_utils, scipy.linalg._solve_toeplitz, scipy.linalg._decomp_lu_cython, scipy.linalg._matfuncs_sqrtm_triu, scipy.linalg.cython_blas, scipy.linalg._matfuncs_expm, scipy.linalg._decomp_update, scipy.sparse.linalg._dsolve._superlu, scipy.sparse.linalg._eigen.arpack._arpack, scipy.sparse.linalg._propack._spropack, scipy.sparse.linalg._propack._dpropack, scipy.sparse.linalg._propack._cpropack, scipy.sparse.linalg._propack._zpropack, scipy.sparse.csgraph._tools, scipy.sparse.csgraph._shortest_path, scipy.sparse.csgraph._traversal, scipy.sparse.csgraph._min_spanning_tree, scipy.sparse.csgraph._flow, scipy.sparse.csgraph._matching, scipy.sparse.csgraph._reordering, scipy.spatial._ckdtree, scipy._lib.messagestream, scipy.spatial._qhull, scipy.spatial._voronoi, scipy.spatial._distance_wrap, scipy.spatial._hausdorff, scipy.special._ufuncs_cxx, scipy.special._ufuncs, scipy.special._specfun, scipy.special._comb, scipy.special._ellip_harm_2, scipy.spatial.transform._rotation, vtkmodules.vtkCommonCore, vtkmodules.vtkCommonMath, vtkmodules.vtkCommonTransforms, vtkmodules.vtkCommonDataModel, vtkmodules.vtkCommonExecutionModel, vtkmodules.vtkImagingSources, vtkmodules.vtkCommonMisc, vtkmodules.vtkFiltersCore, vtkmodules.vtkFiltersPython, vtkmodules.vtkCommonComputationalGeometry, vtkmodules.vtkIOCore, vtkmodules.vtkIOLegacy, vtkmodules.vtkIOXMLParser, vtkmodules.vtkRenderingCore, vtkmodules.vtkDomainsChemistry, vtkmodules.vtkFiltersGeneral, vtkmodules.vtkFiltersExtraction, vtkmodules.vtkFiltersFlowPaths, vtkmodules.vtkFiltersGeometry, vtkmodules.vtkFiltersHybrid, vtkmodules.vtkFiltersModeling, vtkmodules.vtkFiltersHyperTree, vtkmodules.vtkFiltersSources, vtkmodules.vtkFiltersTexture, vtkmodules.vtkParallelCore, vtkmodules.vtkFiltersParallel, vtkmodules.vtkFiltersParallelDIY2, vtkmodules.vtkFiltersPoints, vtkmodules.vtkFiltersStatistics, vtkmodules.vtkFiltersVerdict, vtkmodules.vtkImagingCore, vtkmodules.vtkImagingGeneral, vtkmodules.vtkImagingHybrid, vtkmodules.vtkIOGeometry, vtkmodules.vtkIOXML, vtkmodules.vtkIOInfovis, vtkmodules.vtkIOPLY, vtkmodules.vtkImagingMorphological, vtkmodules.vtkRenderingContext2D, vtkmodules.vtkPythonContext2D, vtkmodules.vtkImagingFourier, vtkmodules.vtkIOParallelXML, vtkmodules.vtkRenderingFreeType, kiwisolver._cext, tetgen._tetgen, scipy.optimize._group_columns, scipy.optimize._trlib._trlib, scipy.optimize._lbfgsb, _moduleTNC, scipy.optimize._moduleTNC, scipy.optimize._cobyla, scipy.optimize._slsqp, scipy.optimize._minpack, scipy.optimize._lsq.givens_elimination, scipy.optimize._zeros, scipy.optimize._highs.cython.src._highs_wrapper, scipy.optimize._highs._highs_wrapper, scipy.optimize._highs.cython.src._highs_constants, scipy.optimize._highs._highs_constants, scipy.linalg._interpolative, scipy.optimize._bglu_dense, scipy.optimize._lsap, scipy.optimize._direct, lxml._elementpath, lxml.etree, scipy.ndimage._nd_image, _ni_label, scipy.ndimage._ni_label, scipy.interpolate._fitpack, scipy.interpolate._dfitpack, scipy.interpolate._bspl, scipy.interpolate._ppoly, scipy.interpolate.interpnd, scipy.interpolate._rbfinterp_pythran, scipy.interpolate._rgi_cython, vtkmodules.vtkWebCore, vtkmodules.vtkIOImage, vtkmodules.vtkRenderingSceneGraph, vtkmodules.vtkRenderingVtkJS, vtkmodules.vtkIOExport, vtkmodules.vtkWebGLExporter, vtkmodules.vtkCommonSystem, vtkmodules.vtkRenderingHyperTreeGrid, vtkmodules.vtkRenderingUI, vtkmodules.vtkRenderingOpenGL2, vtkmodules.vtkRenderingContextOpenGL2, vtkmodules.vtkRenderingVolume, vtkmodules.vtkImagingMath, vtkmodules.vtkRenderingVolumeOpenGL2, vtkmodules.vtkInteractionWidgets, vtkmodules.vtkViewsCore, vtkmodules.vtkViewsContext2D, vtkmodules.vtkTestingRendering, vtkmodules.vtkInteractionStyle, vtkmodules.vtkViewsInfovis, vtkmodules.vtkRenderingVolumeAMR, vtkmodules.vtkRenderingParallel, vtkmodules.vtkRenderingVR, vtkmodules.vtkRenderingMatplotlib, vtkmodules.vtkRenderingLabel, vtkmodules.vtkRenderingLOD, vtkmodules.vtkRenderingLICOpenGL2, vtkmodules.vtkRenderingImage, vtkmodules.vtkRenderingExternal, vtkmodules.vtkFiltersCellGrid, vtkmodules.vtkRenderingCellGrid, vtkmodules.vtkIOXdmf2, vtkmodules.vtkIOVeraOut, vtkmodules.vtkIOVPIC, vtkmodules.vtkIOTecplotTable, vtkmodules.vtkIOTRUCHAS, vtkmodules.vtkIOSegY, vtkmodules.vtkIOLSDyna, vtkmodules.vtkIOParallelLSDyna, vtkmodules.vtkIOExodus, vtkmodules.vtkIOParallelExodus, vtkmodules.vtkIOPIO, vtkmodules.vtkIOMovie, vtkmodules.vtkIOOggTheora, vtkmodules.vtkIOOMF, vtkmodules.vtkIONetCDF, vtkmodules.vtkIOMotionFX, vtkmodules.vtkIOParallel, vtkmodules.vtkIOMINC, vtkmodules.vtkIOImport, vtkmodules.vtkIOIOSS, vtkmodules.vtkIOH5part, vtkmodules.vtkIOH5Rage, vtkmodules.vtkIOGeoJSON, vtkmodules.vtkIOFLUENTCFF, vtkmodules.vtkIOVideo, vtkmodules.vtkIOExportPDF, vtkmodules.vtkRenderingGL2PSOpenGL2, vtkmodules.vtkIOExportGL2PS, vtkmodules.vtkIOEnSight, vtkmodules.vtkIOCityGML, vtkmodules.vtkIOChemistry, vtkmodules.vtkIOCesium3DTiles, vtkmodules.vtkIOCellGrid, vtkmodules.vtkIOCONVERGECFD, vtkmodules.vtkIOHDF, vtkmodules.vtkIOCGNSReader, vtkmodules.vtkIOAsynchronous, vtkmodules.vtkIOAMR, vtkmodules.vtkInteractionImage, vtkmodules.vtkImagingStencil, vtkmodules.vtkImagingStatistics, vtkmodules.vtkImagingOpenGL2, vtkmodules.vtkIOSQL, vtkmodules.vtkCommonColor, vtkmodules.vtkInfovisCore, vtkmodules.vtkGeovisCore, vtkmodules.vtkInfovisLayout, vtkmodules.vtkRenderingAnnotation, vtkmodules.vtkImagingColor, vtkmodules.vtkFiltersTopology, vtkmodules.vtkFiltersTensor, vtkmodules.vtkFiltersSelection, vtkmodules.vtkFiltersSMP, vtkmodules.vtkFiltersReduction, vtkmodules.vtkFiltersProgrammable, vtkmodules.vtkFiltersParallelStatistics, vtkmodules.vtkFiltersImaging, vtkmodules.vtkFiltersParallelImaging, vtkmodules.vtkFiltersGeometryPreview, vtkmodules.vtkFiltersGeneric, vtkmodules.vtkFiltersAMR, vtkmodules.vtkDomainsChemistryOpenGL2, vtkmodules.vtkCommonPython, vtkmodules.vtkChartsCore, vtkmodules.vtkAcceleratorsVTKmCore, vtkmodules.vtkAcceleratorsVTKmDataModel, vtkmodules.vtkAcceleratorsVTKmFilters, numba.core.typeconv._typeconv, numba._helperlib, numba._dynfunc, numba._dispatcher, numba.core.runtime._nrt_python, numba.np.ufunc._internal, numba.experimental.jitclass._box, PIL._imagingft, objc._objc, CoreFoundation._CoreFoundation, CoreFoundation._inlines, Foundation._Foundation, Foundation._inlines, AppKit._AppKit, AppKit._inlines, PIL._imagingmath (total: 256)
[1]    38862 abort      python3.11 scripts/run_on_macos.py --vis

RobRoyce avatar Dec 19 '24 07:12 RobRoyce

Try pip install -U PyOpenGL

RobRoyce avatar Dec 19 '24 07:12 RobRoyce

I get this error with python render_on_macos.py --vis

OpenGL.error.GLError: GLError(
	err = 1282,
	description = b'invalid operation',
	baseOperation = glBindFramebuffer,
	cArguments = (GL_DRAW_FRAMEBUFFER, 0)

Is the intention that you run this in one terminal

python visualization.py

and in another terminal run

python render_on_macos.py --vis

vinny-888 avatar Dec 20 '24 01:12 vinny-888

@vinny-888 You can try this. It works for me, I'm using M1 Mac too.

https://github.com/Genesis-Embodied-AI/Genesis/issues/36#issuecomment-2556229369

YutoYasunaga avatar Dec 20 '24 03:12 YutoYasunaga