sumo icon indicating copy to clipboard operation
sumo copied to clipboard

How can I use libtorch in microsim?

Open ckh0715 opened this issue 3 years ago • 5 comments

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.

ckh0715 avatar Feb 12 '23 11:02 ckh0715

Some Error found like /usr/bin/ld: ../../../../bin/libsumocpp.so: undefined reference to `c10::UndefinedTensorImpl::_singleton'

ckh0715 avatar Feb 12 '23 11:02 ckh0715

If I modify CMakeLists.txt under microsim, it will let something about unittest make failed

ckh0715 avatar Feb 12 '23 13:02 ckh0715

Can you maybe publish the code changes somewhere for us to reproduce?

behrisch avatar Feb 13 '23 11:02 behrisch

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

ckh0715 avatar Feb 14 '23 13:02 ckh0715

It should not be necessary to disable unit tests. Probably you just need to link the torch libraries there a s well.

behrisch avatar Feb 17 '23 09:02 behrisch