How can I use libtorch in microsim?
I only want to use pytorch model to predict vehicle trajectories. When I write some code about torch in MSLaneChanger.cpp, I always make failed. Only when I write code in sumo_main.cpp can success. I can use target_link_libraries at CMakeLists.txt under src to link torch libraries, and it's successful to run torch code in sumo_main.cpp. But when I modify CMakeLists.txt under src/microsim, it's always unsatisfactory.
Some Error found like /usr/bin/ld: ../../../../bin/libsumocpp.so: undefined reference to `c10::UndefinedTensorImpl::_singleton'
If I modify CMakeLists.txt under microsim, it will let something about unittest make failed
Can you maybe publish the code changes somewhere for us to reproduce?
I solved it after I comment out unittest/src/CMakeLists.txt. And I add under code change in sumo/src/microsim/CMakeLists.txt
set(Torch_DIR /path/to/libtorch/share/cmake/Torch)
find_package(Torch REQUIRED)
if(Torch_FOUND)
message(STATUS "Found torch path: " ${TORCH_INCLUDE_DIRS} " \n Found torch libraries: " ${TORCH_LIBRARIES})
include_directories(SYSTEM ${TORCH_INCLUDE_DIRS})
else()
message(FATAL_ERROR "Pytorch Not Found!")
endif(Torch_FOUND)
...
link_libraries(${TORCH_LIBRARIES})
If I modify CMakeLists.txt under microsim, it will let something about unittest make failed
It should not be necessary to disable unit tests. Probably you just need to link the torch libraries there a s well.