tambetm / gym-minecraft

Minecraft environment for Open AI Gym, based on Microsoft's Malmo.
277 stars 29 forks source link

Import pytorch gives segmentation fault #15

Open JunhongXu opened 7 years ago

JunhongXu commented 7 years ago

I have been playing with this environment these days and would like to use pytorch to train a RL agent. However, when I import pytorch inside the script, the program gives a segmentation fault.

Code:

import gym_minecraft
import gym
import torch

if __name__ == '__main__':
    env = gym.make('MinecraftBasic-v0')
    env.init(start_minecraft=True)
    obs = env.reset()

The minecraft program is launched but does not load any task and throws a segmentation fault:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

However, if I remove import torch, it works fine.

Edit:

Here is the backtrace:

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007fffc15e8577 in void std::__once_call_impl<std::_Bind_simple<void (*())()> >() () from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/torch/lib/libTHC.so.1
(gdb) where
#0  0x00007fffc15e8577 in void std::__once_call_impl<std::_Bind_simple<void (*())()> >() () from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/torch/lib/libTHC.so.1
#1  0x00007ffff77eba99 in __pthread_once_slow (once_control=0x7fffa98b3ea0 <malmo::test_schemas_flag>, init_routine=0x7fffb9711fe1 <std::__once_proxy()>) at pthread_once.c:116
#2  0x00007fffa9448a89 in malmo::AgentHost::startMission(malmo::MissionSpec const&, malmo::ClientPool const&, malmo::MissionRecordSpec const&, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) () from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#3  0x00007fffa9441cbe in boost::python::detail::caller_arity<6u>::impl<void (malmo::AgentHost::*)(malmo::MissionSpec const&, malmo::ClientPool const&, malmo::MissionRecordSpec const&, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >), boost::python::default_call_policies, boost::mpl::vector7<void, malmo::AgentHost&, malmo::MissionSpec const&, malmo::ClientPool const&, malmo::MissionRecordSpec const&, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::operator()(_object*, _object*) ()
   from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#4  0x00007fffa959969d in boost::python::objects::function::call(_object*, _object*) const ()
   from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#5  0x00007fffa9599898 in boost::detail::function::void_function_ref_invoker0<boost::python::objects::(anonymous namespace)::bind_return, void>::invoke(boost::detail::function::function_buffer&) ()
   from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#6  0x00007fffa95a1883 in boost::python::detail::exception_handler::operator()(boost::function0<void> const&) const ()
   from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#7  0x00007fffa940a823 in boost::detail::function::function_obj_invoker2<boost::_bi::bind_t<bool, boost::python::detail::translate_exception<malmo::MissionException, void (*)(malmo::MissionException const&)>, boost::_bi::list3<boost::arg<1>, boost::arg<2>, boost::_bi::value<void (*)(malmo::MissionException const&)> > >, bool, boost::python::detail::exception_handler const&, boost::function0<void> const&>::invoke(boost::detail::function::function_buffer&, boost::python::detail::exception_handler const&, boost::function0<void> const&) ()
   from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#8  0x00007fffa95a1858 in boost::python::detail::exception_handler::operator()(boost::function0<void> const&) const ()
   from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#9  0x00007fffa940a7d3 in boost::detail::function::function_obj_invoker2<boost::_bi::bind_t<bool, boost::python::detail::translate_exception<xsd::cxx::tree::exception<char>, void (*)(xsd::cxx::tree::exception<char> const&)>, boost::_bi::list3<boost::arg<1>, boost::arg<2>, boost::_bi::value<void (*)(xsd::cxx::tree::exception<char> const&)> > >, bool, boost::python::detail::exception_handler const&, boost::function0<void> const&>::invoke(boost::detail::function::function_buffer&, boost::python::detail::exception_handler const&, boost::function0<void> const&) ()
   from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#10 0x00007fffa95a163d in boost::python::handle_exception_impl(boost::function0<void>) ()
   from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#11 0x00007fffa9596a79 in function_call () from /home/junhong/anaconda3/envs/MC-research/lib/python2.7/site-packages/minecraft_py/Malmo/Python_Examples/MalmoPython.so
#12 0x00007ffff7a42773 in PyObject_Call () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#13 0x00007ffff7ad653b in PyEval_EvalFrameEx () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#14 0x00007ffff7adcdac in PyEval_EvalFrameEx () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#15 0x00007ffff7adcdac in PyEval_EvalFrameEx () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#16 0x00007ffff7ade4e9 in PyEval_EvalCodeEx () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#17 0x00007ffff7ade70a in PyEval_EvalCode () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#18 0x00007ffff7af793d in run_mod () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#19 0x00007ffff7af8ab8 in PyRun_FileExFlags () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#20 0x00007ffff7af9cd8 in PyRun_SimpleFileExFlags () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#21 0x00007ffff7b0bd3c in Py_Main () from /home/junhong/anaconda3/envs/MC-research/bin/../lib/libpython2.7.so.1.0
#22 0x00007ffff6d23830 in __libc_start_main (main=0x555555554850 <main>, argc=2, argv=0x7fffffffdc58, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdc48)
    at ../csu/libc-start.c:291
#23 0x000055555555487f in _start ()
mikeXwang commented 7 years ago

I got the same situation. Did this issue solved?

unnir commented 7 years ago

@mikeXwang Did you solve it?

I'm facing the same issue

JunhongXu commented 7 years ago

It turns out that we need to start Minecraft before we import PyTorch. I have successfully trained a A2C agent to navigate in the simplest environment in PyTorch. You can check out the code if you are interested https://github.com/JunhongXu/pytorch-a2c-minecraft/blob/master/run_minecraft.py

unnir commented 7 years ago

@JunhongXu wow! thank you