Skip to content

Commit 25eb93f

Browse files
Saurav AgarwalSaurav Agarwal
authored andcommitted
Update setup
1 parent 8e0ab19 commit 25eb93f

File tree

16 files changed

+144
-101
lines changed

16 files changed

+144
-101
lines changed

cppsrc/core/python_bindings/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
cmake_minimum_required(VERSION 3.24)
22
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
33

44
set(CMAKE_CXX_STANDARD 17)

cppsrc/main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
66
set(CMAKE_COLOR_DIAGNOSTICS ON)
77

88
find_package(Torch REQUIRED)
9-
find_package(TorchVision REQUIRED)
9+
# find_package(TorchVision REQUIRED)
1010
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS} -Wall -Wextra -Wshadow -Wformat=2 -Wunused -pedantic")
1111

1212
find_package(OpenMP REQUIRED)

cppsrc/main/coverage_algorithm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int main(int argc, char** argv) {
6666
env->StepActions(actions);
6767
if(ii%1 == 0) {
6868
/* env->RecordPlotData(); */
69-
env->PlotMapVoronoi(dir, ii, oracle.GetVoronoi(), oracle.GetGoals());
69+
/* env->PlotMapVoronoi(dir, ii, oracle.GetVoronoi(), oracle.GetGoals()); */
7070
}
7171
if(cont_flag == false) {
7272
break;
@@ -80,7 +80,7 @@ int main(int argc, char** argv) {
8080
for(int ii = 0; ii < 90; ++ii) {
8181
env->StepActions(zero_actions);
8282
/* env->RecordPlotData(); */
83-
env->PlotMapVoronoi(dir, ii, oracle.GetVoronoi(), oracle.GetGoals());
83+
/* env->PlotMapVoronoi(dir, ii, oracle.GetVoronoi(), oracle.GetGoals()); */
8484
}
8585

8686
env->PlotMapVoronoi(dir, 1, oracle.GetVoronoi(), oracle.GetGoals());

cppsrc/setup.sh

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
print_usage() {
3-
printf "bash $0 [-c (for clean)] [-i (for install)]\n"
3+
printf "bash $0 [-c <for clean>] [-i <for install>] [-t <for torch>] [-p <for python>] [-d <workspace_dir>]\n"
44
}
55

6+
# Get directory of script
7+
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
8+
SOURCE=${BASH_SOURCE[0]}
9+
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
10+
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
11+
SOURCE=$(readlink "$SOURCE")
12+
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
13+
done
14+
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
15+
616
WITH_TORCH=0
7-
while getopts 'ictp' flag; do
17+
while getopts 'd:ictp' flag; do
818
case "${flag}" in
919
i) INSTALL=true;;
1020
c) CLEAN=true;;
1121
t) WITH_TORCH=ON;;
1222
p) WITH_PYTHON=true;;
23+
d) WS_DIR=${OPTARG};;
1324
*) print_usage
1425
exit 1 ;;
1526
esac
1627
done
1728

18-
BUILD_DIR=${COVERAGECONTROL_WS}/build
19-
# INSTALL_DIR=${COVERAGECONTROL_WS}/install
29+
# if -d was given then set build_dir and install_dir to that
2030

31+
CMAKE_END_FLAGS="-DCMAKE_BUILD_TYPE=Release"
2132
if [[ ${WITH_TORCH} == "ON" ]]
2233
then
23-
CMAKE_END_FLAGS="-DCMAKE_PREFIX_PATH=$Torch_DIR -DCMAKE_BUILD_TYPE=RelWithDebInfo"
34+
CMAKE_END_FLAGS="${CMAKE_END_FLAGS} -DCMAKE_PREFIX_PATH=${Torch_DIR}"
35+
fi
36+
if [[ ${WS_DIR} ]]
37+
then
38+
BUILD_DIR=${WS_DIR}/build/
39+
INSTALL_DIR=${WS_DIR}/install/CoverageControl/
40+
CMAKE_END_FLAGS="${CMAKE_END_FLAGS} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}"
2441
else
25-
CMAKE_END_FLAGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo"
42+
TMP_DIR=$(mktemp -d)
43+
BUILD_DIR=${TMP_DIR}/build
2644
fi
2745

28-
CleanBuild () {
29-
rm -rf ${BUILD_DIR}
30-
rm -rf ${INSTALL_DIR}
31-
}
32-
3346
InstallCoverageControlCore () {
34-
cmake -S ${COVERAGECONTROL_WS}/src/CoverageControl/cppsrc/core -B ${BUILD_DIR}/CoverageControlCore ${CMAKE_END_FLAGS}
47+
cmake -S ${DIR}/core -B ${BUILD_DIR}/CoverageControlCore ${CMAKE_END_FLAGS}
3548
cmake --build ${BUILD_DIR}/CoverageControlCore -j$(nproc)
3649
if [ $? -ne 0 ]; then
3750
echo "CoverageControlCore build failed"
@@ -46,7 +59,7 @@ InstallCoverageControlCore () {
4659
}
4760

4861
InstallCoverageControlTorch () {
49-
cmake -S ${COVERAGECONTROL_WS}/src/CoverageControl/cppsrc/torch -B ${BUILD_DIR}/CoverageControlTorch ${CMAKE_END_FLAGS} -DCMAKE_PREFIX_PATH=${Torch_DIR}
62+
cmake -S ${DIR}/torch -B ${BUILD_DIR}/CoverageControlTorch ${CMAKE_END_FLAGS}
5063
cmake --build ${BUILD_DIR}/CoverageControlTorch -j$(nproc)
5164
if [ $? -ne 0 ]; then
5265
echo "CoverageControlTorch build failed"
@@ -62,7 +75,7 @@ InstallCoverageControlTorch () {
6275
}
6376

6477
InstallCoverageControlTests () {
65-
cmake -S ${COVERAGECONTROL_WS}/src/CoverageControl/cppsrc/tests -B ${BUILD_DIR}/CoverageControlTests ${CMAKE_END_FLAGS} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
78+
cmake -S ${DIR}/tests -B ${BUILD_DIR}/CoverageControlTests ${CMAKE_END_FLAGS} -DWITH_TORCH=${WITH_TORCH}
6679
cmake --build ${BUILD_DIR}/CoverageControlTests -j$(nproc)
6780
if [ $? -ne 0 ]; then
6881
echo "CoverageControlTests build failed"
@@ -78,7 +91,7 @@ InstallCoverageControlTests () {
7891
}
7992

8093
InstallCoverageControlMain () {
81-
cmake -S ${COVERAGECONTROL_WS}/src/CoverageControl/cppsrc/main -B ${BUILD_DIR}/CoverageControlMain ${CMAKE_END_FLAGS} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DWITH_TORCH=${WITH_TORCH}
94+
cmake -S ${DIR}/main -B ${BUILD_DIR}/CoverageControlMain ${CMAKE_END_FLAGS} -DWITH_TORCH=${WITH_TORCH}
8295
cmake --build ${BUILD_DIR}/CoverageControlMain -j$(nproc)
8396
if [ $? -ne 0 ]; then
8497
echo "CoverageControlMain build failed"
@@ -98,9 +111,9 @@ then
98111
if [[ ${WITH_TORCH} == "ON" ]]
99112
then
100113
InstallCoverageControlTorch
114+
InstallCoverageControlTests
101115
fi
102116
InstallCoverageControlMain
103-
InstallCoverageControlTests
104117
fi
105118

106119
if [[ ${CLEAN} ]]

cppsrc/tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
66
set(CMAKE_COLOR_DIAGNOSTICS ON)
77

88
find_package(Torch REQUIRED)
9-
find_package(TorchVision REQUIRED)
9+
# find_package(TorchVision REQUIRED)
1010
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
1111

1212
find_package(OpenMP REQUIRED)

cppsrc/tests/test_maps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(int argc, const char* argv[]) {
3838
std::string py_filename = py_dir + filename;
3939
std::string cpp_filename = cpp_dir + filename;
4040
std::cout << filename << std::endl;
41-
torch::Tensor tensor = GetTensorFromBytes(py_filename);
41+
torch::Tensor tensor = CoverageControlTorch::GetTensorFromBytes(py_filename);
4242
std::cout << filename << " " << tensor.sizes() << std::endl;
4343
torch::save(tensor, cpp_filename);
4444
torch::Tensor temp;

cppsrc/torch/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
99
set(CMAKE_COLOR_DIAGNOSTICS ON)
1010

1111
find_package(Torch REQUIRED)
12-
find_package(TorchVision REQUIRED)
12+
# find_package(TorchVision REQUIRED)
1313
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
1414

1515
find_package(OpenCV REQUIRED)
@@ -41,7 +41,7 @@ target_compile_options(compiler_flags INTERFACE
4141
set(sources_list base.cpp)
4242
list(TRANSFORM sources_list PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/src/")
4343

44-
set(dependencies_list CoverageControlCore ${TORCH_LIBRARIES} TorchVision::TorchVision)
44+
set(dependencies_list CoverageControlCore ${TORCH_LIBRARIES})
4545

4646
add_library(CoverageControl_torch SHARED ${sources_list})
4747

install/docker/.bashrc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,3 @@ alias tmux='tmux -2'
126126

127127
export VISUAL=vim
128128
export EDITOR="$VISUAL"
129-
130-
source /root/venv/bin/activate
131-
132-

install/docker/Dockerfile

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,32 @@ RUN rm -rf /var/lib/apt/lists/*; \
6060
rm -f /var/cache/apt/archives/parital/*.deb; \
6161
rm -f /var/cache/apt/*.bin
6262

63-
COPY requirements.txt /root/requirements.txt
64-
RUN python3.11 -m venv /root/venv
65-
RUN /root/venv/bin/pip install --no-cache-dir -r /root/requirements.txt
63+
COPY requirements.txt /opt/requirements.txt
64+
RUN python3.11 -m venv /opt/venv
65+
RUN /opt/venv/bin/pip install --no-cache-dir -r /opt/requirements.txt
6666

6767
RUN mkdir download; \
6868
wget https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcu118.zip -O download/libtorch.zip; \
69-
unzip download/libtorch.zip -d /root/; \
69+
unzip download/libtorch.zip -d /opt/; \
7070
rm -r download
7171

72-
ENV LD_LIBRARY_PATH /usr/local/lib:/root/libtorch/lib:${LD_LIBRARY_PATH}
73-
ENV Torch_ROOT /root/libtorch/
74-
ENV Torch_DIR /root/libtorch/share/cmake/
72+
ENV LD_LIBRARY_PATH /usr/local/lib:/opt/libtorch/lib:${LD_LIBRARY_PATH}
73+
ENV Torch_ROOT /opt/libtorch/
74+
ENV Torch_DIR /opt/libtorch/share/cmake/
7575

76-
RUN mkdir -p /root/dependencies/build; \
77-
mkdir -p /root/dependencies/src
78-
COPY install_dependencies.sh /root/dependencies/install_dependencies.sh
79-
RUN ["/bin/bash", "-c", "/root/dependencies/install_dependencies.sh /root/dependencies"]
80-
RUN rm -r /root/dependencies
76+
RUN mkdir -p /opt/dependencies/build; \
77+
mkdir -p /opt/dependencies/src
78+
COPY install_dependencies.sh /opt/dependencies/install_dependencies.sh
79+
RUN ["/bin/bash", "-c", "/opt/dependencies/install_dependencies.sh"]
80+
RUN rm -r /opt/dependencies
8181

82-
ENV TorchVision_DIR /root/libtorch/share/cmake/
83-
84-
ENV COVERAGECONTROL_WS /root/CoverageControl_ws
85-
ENV LD_LIBRARY_PATH ${COVERAGECONTROL_WS}/install/lib:${LD_LIBRARY_PATH}
82+
ENV COVERAGECONTROL_WS /opt/CoverageControl_ws
83+
ENV LD_LIBRARY_PATH ${COVERAGECONTROL_WS}/install/CoverageControl/lib:${LD_LIBRARY_PATH}
8684
ENV PATH ${COVERAGECONTROL_WS}/install/bin:${PATH}
87-
ENV LIBTORCH_PYTHON_PATH /root/libtorch/lib/libtorch_python.so
85+
ENV LIBTORCH_PYTHON_PATH /opt/libtorch/lib/libtorch_python.so
8886
COPY .bashrc /root/.bashrc
89-
RUN echo "source /root/venv/bin/activate" >> /root/.bashrc
87+
COPY .bashrc /opt/.bashrc
88+
RUN echo "source /opt/venv/bin/activate" >> /root/.bashrc
9089

9190
RUN mkdir -p ${COVERAGECONTROL_WS}
9291
WORKDIR ${COVERAGECONTROL_WS}

install/docker/create_gpu_container.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
IMAGE_NAME=agarwalsaurav/gnn_ros
1+
IMAGE_NAME=agarwalsaurav/gnn
22
COVERAGECONTROL_WS=${1}
33

4-
COVERAGECONTROL_VOLUME="--volume=${COVERAGECONTROL_WS}:/root/CoverageControl_ws:rw"
5-
CONTAINERNAME="gnn-${USER}-ros"
4+
COVERAGECONTROL_VOLUME="--volume=${COVERAGECONTROL_WS}:/opt/CoverageControl_ws:rw"
5+
CONTAINERNAME="gnn-${USER}"
66

77
docker run -it \
88
--name=$CONTAINERNAME \

0 commit comments

Comments
 (0)