Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing GTSAM in combination with RoboStack ROS Noetic on Windows 10 #25

Closed
hmaarten opened this issue May 14, 2024 · 20 comments
Closed
Labels
question Further information is requested

Comments

@hmaarten
Copy link

hmaarten commented May 14, 2024

Comment:

I aim to implement a ROS package in Python that lives completely within an Anaconda environment on a Windows computer (we have some other software that must run on Windows). I have been using RoboStack ROS Noetic to implement the ROS side of things. Additionally, I require GTSAM in one of my ros nodes. After having installed ROS using mamba install ros-noetic-desktop I install GTSAM using mamba install gtsam which does work, however, it installs version gtsam-4.2.0-py311h669d342_3 which is not the latest build. When running the following snippet of code (minimal reproducible example)

import gtsam
import numpy as np

graph = gtsam.NonlinearFactorGraph()

pose_key = gtsam.symbol('x', 0)
vel_key = gtsam.symbol('v', 0)
bias_key = gtsam.symbol('b', 0)

current_pose = gtsam.Pose3(np.eye(4))
current_vel = np.zeros(3)
current_bias = gtsam.imuBias.ConstantBias()

graph.add(gtsam.PriorFactorPose3(pose_key, current_pose, gtsam.noiseModel.Isotropic.Sigma(6, 0.1)))
graph.add(gtsam.PriorFactorVector(vel_key, current_vel, gtsam.noiseModel.Isotropic.Sigma(3, 0.1)))
graph.add(gtsam.PriorFactorConstantBias(bias_key, current_bias, gtsam.noiseModel.Isotropic.Sigma(6, 0.1)))

initial_estimate = gtsam.Values()
initial_estimate.insert(pose_key, current_pose)
initial_estimate.insert(vel_key, current_vel)
initial_estimate.insert(bias_key, current_bias)

pose_key += 1
vel_key += 1
bias_key += 1

new_pose = gtsam.Pose3(np.eye(4))
graph.add(gtsam.PriorFactorPose3(pose_key, new_pose, gtsam.noiseModel.Diagonal.Sigmas(np.array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1]))))

imu_accum = gtsam.PreintegratedImuMeasurements(gtsam.PreintegrationParams(np.asarray([0, 0, 9.81])))
predicted_nav_state = imu_accum.predict(gtsam.NavState(current_pose, current_vel), current_bias)
imu_factor = gtsam.ImuFactor(pose_key-1, vel_key-1, pose_key, vel_key, bias_key, imu_accum)
graph.add(imu_factor)

initial_estimate.insert(pose_key, predicted_nav_state.pose())
initial_estimate.insert(vel_key, predicted_nav_state.velocity())
initial_estimate.insert(bias_key, gtsam.imuBias.ConstantBias())

bias_factor = gtsam.BetweenFactorConstantBias(bias_key-1, bias_key, gtsam.imuBias.ConstantBias(), gtsam.noiseModel.Diagonal.Sigmas(np.array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])))
graph.add(bias_factor)

isam = gtsam.ISAM2(gtsam.ISAM2Params())
result = isam.update(graph, initial_estimate)

the following error is thrown:

RuntimeError: Attempting to retrieve value with key "v1", type stored in Values is class gtsam::GenericValue<class Eigen::Matrix<double,-1,1,0,-1,1> > but requested type was class Eigen::Matrix<double,3,1,0,3,1>

This is a known issue and was fixed in this pull request. Indeed, when installing the latest build of GTSAM (gtsam-4.2.0-py311hdd3dd35_5) no error is thrown for the upper code snippet. However, this version is incompatible with mamba install ros-noetic-desktop, as versions of libboost 1.82 and 1.84 collide.

What could be a workaround to ensure compatibility? Should GTSAM be rebuilt for libboost 1.82, while still incorporating the changes of the above-mentioned pull request? Or is there a combination of versions that is compatible with my requirements and does not throw this error? I have tried installing only a subset of the ROS package, but that didn't work. Also, trying other Python versions yielded no success as ROS Noetic is only built for Python 3.11 as it seems. Any help would be appreciated as I am not well versed with package building using conda-forge.

@hmaarten hmaarten added the question Further information is requested label May 14, 2024
@traversaro
Copy link
Contributor

This is unfortunately a recurrent problem with robostack packages. conda-forge has ABI migration occuring regularly (https://conda-forge.org/blog/2019/12/06/cfep09/), but at robostack at the moment we only do periodic rebuilds, that however use the version of dependencies used in conda-forge packages built at the moment we did the rebuild (as you noticed, currently libboost 1.82, see https://github.com/RoboStack/ros-noetic/blob/7f743314408fbaea5701b8f09193e11136b9b899/additional_recipes/ros-distro-mutex/recipe.yaml#L33).

The "proper" solution is to do a rebuild with updated libboost pinning set to 1.84, but that takes time. Other solutions involve separating gtsam and ros code in two separated conda environment, and make them communicate over some kind of non-ROS IPC. Yes another workaround is to compile gtsam from source.

However, as the boost 1.84 migration is still ongoing (see https://conda-forge.org/status/migration/boost1840) probably at least for gtsam we can do a dual 1.82/1.84 . Doing this for all packages it is not sustainable but for this specific case I do not think it is particularly problematic.

@traversaro
Copy link
Contributor

Ok, one step back as I may be a bit confused.

This is a known issue and was fixed in borglab/gtsam#1685. Indeed, when installing the latest build of GTSAM (gtsam-4.2.0-py311hdd3dd35_5) no error is thrown for the upper code snippet.

If this is issue was fixed in borglab/gtsam#1685, how is this related to gtsam 4.2.0 that was released several months before borglab/gtsam#1685 was merged? Can you try if you see the same problem with gtsam-4.2.0===_4 ? Thanks!

@hmaarten
Copy link
Author

hmaarten commented May 14, 2024

Thanks for your response and the explanation. I will check again tomorrow as I don't have my PC but I am quite certain that the behavior is already fixed in _4 but the same compatibility issues regarding libboost arose, i.e. it would only let me install version _3 alongside RoboStack ROS. However, the timeline is indeed confusing as borglab/gtsam/#1685 is not even part of the current build as I understand? Could just upgrading libboost to 1.84 have implicity solved the problem (i. e., downgrading would again yield the same error)?

@traversaro
Copy link
Contributor

Could just upgrading libboost to 1.84 have implicity solved the problem (i. e., downgrading would again yield the same error)?

If that is the case, then a rebuild against liboost 1.82 will not help.

@traversaro
Copy link
Contributor

Just to double check, can you check if you can install suitesparse==7 with the packages you need? If you can't, again the rebuild in #26 will not be useful for you.

@hmaarten
Copy link
Author

hmaarten commented May 15, 2024

mamba install -c conda-forge suitesparse=7.7.0 is installable alongside Robostack ROS. Even though #26 will probably not resolve my problems as you mentioned, it might still be worth the try. Otherwise, my remaining option would be to build the version borglab/gtsam/#1685 from the gtsam development branch with libboost 1.82. Would that be feasible?

@traversaro
Copy link
Contributor

Would that be feasible?

I do not see any specific problem that could emerge. There are a bunch of patches in https://github.com/conda-forge/gtsam-feedstock/tree/main/recipe, but hopefully they are superseded in master thanks to the PR borglab/gtsam#1685, so a good attempt would just to try to compile the master version as it is is. You can get inspiration from the https://github.com/conda-forge/gtsam-feedstock/blob/main/recipe/bld.bat script, just make sure that you use %CONDA_PREFIX% instead of %PREFIX% if you build outside of conda-build.

Even though #26 will probably not resolve my problems as you mentioned, it might still be worth the try.

To be honest, I am not sure about that. Not sure if I am missing anything, but issue does not seem to be related to boost.

@hmaarten
Copy link
Author

Okay, so #26 should be closed then.
Regarding building the GTSAM develop branch, would you suggest following the python wrapper building instructions (so do not work with conda-build) as I aim to use it only locally? I am not experienced in building packages, so if you have any other pointers on how to start, let me know.
Thanks

@traversaro
Copy link
Contributor

Those instructions seems fine, the only thing that is important is not to install any dependency with pip, but rather use conda to install the dependencies listed in https://github.com/conda-forge/gtsam-feedstock/blob/main/recipe/meta.yaml#L30-L53 . Note that instead of the compilers macros, you can just use the compilers package, and you can ignore all the lines that end with # [build_platform != target_platform].

@traversaro
Copy link
Contributor

I just tested your script, and it is failing with the reported error with the following environment:

(gtsam) D:\src\gtsamws>conda list
# packages in environment at D:\miniforge3\envs\gtsam:
#
# Name                    Version                   Build  Channel
bzip2                     1.0.8                hcfcfb64_5    conda-forge
ca-certificates           2024.2.2             h56e8100_0    conda-forge
geographiclib-cpp         2.3                  h91493d7_1    conda-forge
gtsam                     4.2.0           py312h8ae2717_5    conda-forge
intel-openmp              2024.1.0           h57928b3_965    conda-forge
libblas                   3.9.0              22_win64_mkl    conda-forge
libboost                  1.84.0               h9a677ad_3    conda-forge
libcblas                  3.9.0              22_win64_mkl    conda-forge
libexpat                  2.6.2                h63175ca_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libflang                  5.0.0           h6538335_20180525    conda-forge
libhwloc                  2.10.0          default_h2fffb23_1000    conda-forge
libiconv                  1.17                 hcfcfb64_2    conda-forge
liblapack                 3.9.0              22_win64_mkl    conda-forge
libsqlite                 3.45.3               hcfcfb64_0    conda-forge
libxml2                   2.12.7               h283a6d9_0    conda-forge
libzlib                   1.2.13               hcfcfb64_5    conda-forge
llvm-meta                 5.0.0                         0    conda-forge
metis                     5.1.0             h63175ca_1007    conda-forge
mkl                       2024.1.0           h66d3029_692    conda-forge
numpy                     1.26.4          py312h8753938_0    conda-forge
openmp                    5.0.0                    vc14_1    conda-forge
openssl                   3.3.0                hcfcfb64_0    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
pthreads-win32            2.9.1                hfa6e2cd_3    conda-forge
pyparsing                 3.1.2              pyhd8ed1ab_0    conda-forge
python                    3.12.3          h2628c8c_0_cpython    conda-forge
python_abi                3.12                    4_cp312    conda-forge
setuptools                69.5.1             pyhd8ed1ab_0    conda-forge
suitesparse               7.7.0                h7e725d4_1    conda-forge
tbb                       2021.12.0            h91493d7_0    conda-forge
tk                        8.6.13               h5226925_1    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
vc                        14.3                hcf57466_18    conda-forge
vc14_runtime              14.38.33130         h82b7239_18    conda-forge
vs2015_runtime            14.38.33130         hcb4865c_18    conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    conda-forge
xz                        5.2.6                h8d14728_0    conda-forge
zstd                      1.5.6                h0ea2cb4_0    conda-forge

Also installing python==3.11.* it still fails. @hmaarten can you please report the exact environment in which the test is working? Thanks!

@hmaarten
Copy link
Author

Hmm, I just realized that it indeed only works with build _4, so the overall dependencies are

(gtsam_test) C:\>mamba list
# packages in environment at C:\miniconda3\envs\gtsam_test:
#
# Name                    Version                   Build  Channel
bzip2                     1.0.8                hcfcfb64_5    conda-forge
ca-certificates           2024.2.2             h56e8100_0    conda-forge
geographiclib-cpp         2.3                  h91493d7_1    conda-forge
gtsam                     4.2.0           py311h0631a01_4    conda-forge
intel-openmp              2024.1.0           h57928b3_965    conda-forge
libblas                   3.9.0              22_win64_mkl    conda-forge
libboost                  1.84.0               h9a677ad_3    conda-forge
libcblas                  3.9.0              22_win64_mkl    conda-forge
libexpat                  2.6.2                h63175ca_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libhwloc                  2.10.0          default_h2fffb23_1000    conda-forge
libiconv                  1.17                 hcfcfb64_2    conda-forge
liblapack                 3.9.0              22_win64_mkl    conda-forge
liblapacke                3.9.0              22_win64_mkl    conda-forge
libsqlite                 3.45.3               hcfcfb64_0    conda-forge
libxml2                   2.12.7               h283a6d9_0    conda-forge
libzlib                   1.2.13               hcfcfb64_5    conda-forge
metis                     5.1.0             h63175ca_1007    conda-forge
mkl                       2024.1.0           h66d3029_692    conda-forge
numpy                     1.26.4          py311h0b4df5a_0    conda-forge
openssl                   3.3.0                hcfcfb64_0    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
pthreads-win32            2.9.1                hfa6e2cd_3    conda-forge
pyparsing                 3.1.2              pyhd8ed1ab_0    conda-forge
python                    3.11.9          h631f459_0_cpython    conda-forge
python_abi                3.11                    4_cp311    conda-forge
setuptools                69.5.1             pyhd8ed1ab_0    conda-forge
suitesparse               5.4.0                h5d0cbe0_1    conda-forge
tbb                       2021.12.0            h91493d7_0    conda-forge
tk                        8.6.13               h5226925_1    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
vc                        14.3                hcf57466_18    conda-forge
vc14_runtime              14.38.33130         h82b7239_18    conda-forge
vs2015_runtime            14.38.33130         hcb4865c_18    conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    conda-forge
xz                        5.2.6                h8d14728_0    conda-forge
zstd                      1.5.6                h0ea2cb4_0    conda-forge

The main difference seems to be the version of suitesparse (5.4.0 vs 7.7.0). With this environment, my script works fine...
No idea how to interpret this behavior.

@hmaarten
Copy link
Author

hmaarten commented May 16, 2024

On another note, I tried to build gtsam from source using changes in borglab/gtsam/#1685. I tried two approaches

  1. Managing the build process from within an Anaconda environment. For this I

However, here already cmake failed as it could not find boost

-- Could NOT find Boost: missing: serialization system filesystem thread program_options date_time timer chrono regex (found C:/Users/hmaarten/miniforge3/envs/gtsam_build/Library/lib/cmake/Boost-1.82.0/BoostConfig.cmake (found suitable version "1.82.0", minimum required is "1.65"))
CMake Error at cmake/HandleBoost.cmake:32 (message):
  Missing required Boost components >= v1.65, please install/upgrade Boost or
  configure your search paths.
Call Stack (most recent call first):
  CMakeLists.txt:69 (include)

The subcomponents are all present in the environments Library/include and Library/lib folder, respectively. So not sure what to do with that. Here I did not understand exactly what to do with %LIBRARY_PREFIX% variable, I just set it to the Library folder of my anaconda environment using set at the beginning of the .bat script. @traversaro you mention

just make sure that you use %CONDA_PREFIX% instead of %PREFIX% if you build outside of conda-build.

Could you elaborate on that?

  1. Managing the build process outside of anaconda. For this I
  • Installed boost 1.82 using precompiled binaries from the official website and the other dependencies using pip
  • Tried to apply patches using git apply ..., most of them resulted in patch does not apply though (I think as there are changes already in the branch)
  • Used python wrapper building instructions for cmake, yielding an .sln file
  • Used MSVS 2019 to build the python-test package
  • Installed it using pip installl . in the build/python folder

This approach almost works, however when I try to import gtsam it throws

>>> import gtsam
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\hmaarten\Documents\gtsam_build\gtsam_with_patches\gtsam\build\python\gtsam\__init__.py", line 9, in <module>
    from gtsam import gtsam, utils
ImportError: cannot import name 'gtsam' from partially initialized module 'gtsam' (most likely due to a circular import) (C:\Users\hmaarten\Documents\gtsam_build\gtsam_with_patches\gtsam\build\python\gtsam\__init__.py)

I found a similar issue here #19, and the workaround is included in the https://github.com/conda-forge/gtsam-feedstock/blob/main/recipe/bld.bat file with
python\gtsam\gtsam.*.pyd "%SP_DIR%\gtsam\"
i.e., copying some .pyd files. However, when I look in my output build folder, I only find a .pyd file in gtsam\build\python\gtsam\Release (gtsam_py.pyd), so it does not really match the structure of that command. Maybe because I used MSVS 2019 instead of ninja in the 2nd approach.

So currently I am a bit stuck with both approaches. Any additional inputs would be appreciated.

@traversaro
Copy link
Contributor

I reproduced the problem in CI in #26 . Let's just backport the patch and if that works and live happy.

@traversaro
Copy link
Contributor

here already cmake failed as it could not find boost (it did identify version 1.82, but said a bunch of subcomponents were missing, even though they are all present in the environments Library/include and Library/lib folder, respectively.

Please, always include the exact error that you are experiencing, not a recap. The exact errors are important to provide you feedback.

@traversaro
Copy link
Contributor

just make sure that you use %CONDA_PREFIX% instead of %PREFIX% if you build outside of conda-build.

Could you elaborate on that?

conda-build works with two environments, a build and host environment. If you do a local build, you just have an environment, pointed by CONDA_PREFIX. LIBRARY_PREFIX,PREFIX and similar are all conda-build env variables, see https://docs.conda.io/projects/conda-build/en/latest/user-guide/environment-variables.html .

@traversaro
Copy link
Contributor

Maybe because I used MSVS 2019 instead of ninja in the 2nd approach.

Yes, that is the reason. VS is a so-called multiple config generator, while ninja is a single config, so all the outpus of VS generator have an additional folder to identify the config. Just change the copy command to handle the difference folder structure, or use ninja .

@hmaarten
Copy link
Author

Please, always include the exact error that you are experiencing, not a recap. The exact errors are important to provide you feedback.

Here a more detailed description of approach 1:

Made a gtsam_build env with the following packages:

(gtsam_build) C:\Users\hmaarten\Documents\gtsam_build\gtsam>conda list
# packages in environment at C:\Users\hmaarten\miniforge3\envs\gtsam_build:
#
# Name                    Version                   Build  Channel
bzip2                     1.0.8                h2bbff1b_6
c-compiler                1.7.0                hcfcfb64_1    conda-forge
ca-certificates           2024.3.11            haa95532_0
clangdev                  5.0.0                   flang_3    conda-forge
cmake                     3.29.3               h75d51d9_0    conda-forge
compilers                 1.7.0                h57928b3_1    conda-forge
cxx-compiler              1.7.0                h91493d7_1    conda-forge
eigen                     3.4.0                h91493d7_0    conda-forge
flang                     5.0.0           he025d50_20180525    conda-forge
flang_win-64              5.0.0           h13ae965_20180526    conda-forge
fortran-compiler          1.7.0                h9655429_1    conda-forge
geographiclib-cpp         2.3                  h91493d7_1    conda-forge
intel-openmp              2024.1.0           h57928b3_965    conda-forge
krb5                      1.21.2               heb0366b_0    conda-forge
libblas                   3.9.0              22_win64_mkl    conda-forge
libboost                  1.82.0               h65993cd_6    conda-forge
libboost-devel            1.82.0               h91493d7_6    conda-forge
libboost-headers          1.82.0               h57928b3_6    conda-forge
libcblas                  3.9.0              22_win64_mkl    conda-forge
libcurl                   8.7.1                hd5e4a3a_0    conda-forge
libexpat                  2.6.2                h63175ca_0    conda-forge
libffi                    3.4.4                hd77b12b_1
libflang                  5.0.0           h6538335_20180525    conda-forge
libhwloc                  2.10.0          default_h2fffb23_1000    conda-forge
libiconv                  1.17                 hcfcfb64_2    conda-forge
liblapack                 3.9.0              22_win64_mkl    conda-forge
liblapacke                3.9.0              22_win64_mkl    conda-forge
libssh2                   1.11.0               h7dfc565_0    conda-forge
libuv                     1.48.0               hcfcfb64_0    conda-forge
libxml2                   2.12.7               h283a6d9_0    conda-forge
libzlib                   1.2.13               hcfcfb64_5    conda-forge
llvm-meta                 5.0.0                         0    conda-forge
metis                     5.2.1                hcfcfb64_0    conda-forge
mkl                       2024.1.0           h66d3029_692    conda-forge
ninja                     1.12.1               hc790b64_0    conda-forge
numpy                     1.26.4          py311h0b4df5a_0    conda-forge
openmp                    5.0.0                    vc14_1    conda-forge
openssl                   3.3.0                hcfcfb64_0    conda-forge
pip                       24.0            py311haa95532_0
pthreads-win32            2.9.1                hfa6e2cd_3    conda-forge
pybind11                  2.12.0          py311h005e61a_0    conda-forge
pybind11-global           2.12.0          py311h005e61a_0    conda-forge
pyparsing                 3.1.2              pyhd8ed1ab_0    conda-forge
python                    3.11.9               he1021f5_0
python_abi                3.11                    2_cp311    conda-forge
setuptools                69.5.1          py311haa95532_0
sqlite                    3.45.3               h2bbff1b_0
suitesparse               5.4.0                h5d0cbe0_1    conda-forge
tbb                       2021.12.0            h91493d7_0    conda-forge
tbb-devel                 2021.12.0            h3ec46f0_0    conda-forge
tk                        8.6.14               h0416ee5_0
tzdata                    2024a                h04d1e81_0
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
vc                        14.2                 h21ff451_1
vc14_runtime              14.38.33130         h82b7239_18    conda-forge
vs2015_runtime            14.38.33130         hcb4865c_18    conda-forge
vs2019_win-64             19.29.30139         he1865b1_18    conda-forge
vswhere                   3.1.4                h57928b3_0    conda-forge
wheel                     0.43.0          py311haa95532_0
xz                        5.4.6                h8cc25b3_1
zlib                      1.2.13               hcfcfb64_5    conda-forge
zstd                      1.5.6                h0ea2cb4_0    conda-forge

Cloned gtsam into C:\Users\hmaarten\Documents\gtsam_build\gtsam. Defined bld.bat as

@echo off
mkdir build
cd build

set CONDA_PREFIX=C:\Users\hmaarten\miniforge3\envs\gtsam_build
set CONDA_PY=C:\Users\hmaarten\miniforge3\envs\gtsam_build\python.exe

set SRC_DIR=C:\Users\hmaarten\Documents\gtsam_build\gtsam 
set LIBRARY_PREFIX=%CONDA_PREFIX%\Library
set PYTHON=%CONDA_PY%


cmake ^
    -GNinja ^
    -DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
    -DGTSAM_BUILD_UNSTABLE:OPTION=ON ^
    -DGTSAM_BUILD_STATIC_LIBRARY=OFF ^
    -DGTSAM_BUILD_WITH_MARCH_NATIVE=OFF ^
    -DGTSAM_USE_SYSTEM_EIGEN=ON ^
    -DGTSAM_INSTALL_CPPUNITLITE=OFF ^
    -DGTSAM_BUILD_PYTHON=ON ^
    -DGTSAM_USE_SYSTEM_METIS=ON ^
    -DBoost_LIBRARYDIR:FILEPATH="%LIBARY_PREFIX%\lib" ^
    -DBoost_INCLUDEDIR:FILEPATH="%LIBARY_PREFIX%\include" ^
    -DBoost_USE_STATIC_LIBS:BOOL=OFF ^
    -DGTSAM_CMAKE_CONFIGURATION_TYPES="Release" ^
    -DCMAKE_BUILD_TYPE="Release" ^
    -DPython3_EXECUTABLE=%PYTHON% ^
    -DPython_EXECUTABLE=%PYTHON% ^
    -DPYTHON_EXECUTABLE=%PYTHON% ^
    %SRC_DIR%

if errorlevel 1 (
    echo CMake configuration failed. Exiting...
    cd ..
    pause
    exit /b 1
)

ninja install -j1

if errorlevel 1 (
    echo Ninja installation failed. Exiting...
    pause
    exit /b 1
)

cd python
python -m pip install . -vv

if errorlevel 1 (
    echo Pip installation failed. Exiting...
    pause
    exit /b 1
)

cd ..

copy python\gtsam\gtsam.*.pyd "%SP_DIR%\gtsam\"

if errorlevel 1 (
    echo Copying gtsam files failed. Exiting...
    pause
    exit /b 1
)

copy python\gtsam_unstable\gtsam_unstable.*.pyd "%SP_DIR%\gtsam_unstable\"

if errorlevel 1 (
    echo Copying gtsam_unstable files failed. Exiting...
    pause
    exit /b 1
)

@rem ninja check

pause

Then the output from cmake is

(gtsam_build) C:\Users\hmaarten\Documents\gtsam_build\gtsam>call bld.bat
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The CXX compiler identification is MSVC 19.29.30154.0
-- The C compiler identification is MSVC 19.29.30154.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- GTSAM is a shared library due to GTSAM_FORCE_SHARED_LIB
-- GTSAM_POSE3_EXPMAP=ON, enabling GTSAM_ROT3_EXPMAP as well
-- Could NOT find Boost: missing: serialization system filesystem thread program_options date_time timer chrono regex (found C:/Users/hmaarten/miniforge3/envs/gtsam_build/Library/lib/cmake/Boost-1.82.0/BoostConfig.cmake (found suitable version "1.82.0", minimum required is "1.65"))
CMake Error at cmake/HandleBoost.cmake:32 (message):
  Missing required Boost components >= v1.65, please install/upgrade Boost or
  configure your search paths.
Call Stack (most recent call first):
  CMakeLists.txt:69 (include)


-- Configuring incomplete, errors occurred!
CMake configuration failed. Exiting...
Press any key to continue . . .

Yes, that is the reason. VS is a so-called multiple config generator, while ninja is a single config, so all the outpus of VS generator have an additional folder to identify the config. Just change the copy command to handle the difference folder structure, or use ninja .

I tried copying the .pyd file from gtsam\build\python\gtsam\Release to miniconda3\envs\ros_noetic_minimal\Lib\site-packages\gtsam\Release, this did not yield any change, however.

@traversaro
Copy link
Contributor

Can you try to set CMAKE_PREFIX_PATH cmake variable to C:\Users\hmaarten\miniforge3\envs\gtsam_build\Library ?

I tried copying the .pyd file from gtsam\build\python\gtsam\Release to miniconda3\envs\ros_noetic_minimal\Lib\site-packages\gtsam\Release, this did not yield any change, however.

Any change w.r.t. to what?

@hmaarten
Copy link
Author

hmaarten commented May 16, 2024

Changed it now to

set CONDA_PREFIX=C:\Users\hmaarten\miniforge3\envs\gtsam_build
set CONDA_PY=C:\Users\hmaarten\miniforge3\envs\gtsam_build\python.exe

set CMAKE_PREFIX_PATH=C:\Users\hmaarten\miniforge3\envs\gtsam_build\Library
set SRC_DIR=C:\Users\hmaarten\Documents\gtsam_build\gtsam 
set LIBRARY_PREFIX=%CONDA_PREFIX%\Library
set PYTHON=%CONDA_PY%

which did not change anything of the cmake output (still boost error). Same goes for adding flag -DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX% or -DCMAKE_PREFIX_PATH=%CONDA_PREFIX%.

Any change w.r.t. to what?

As in the circular import issue

>>> import gtsam
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\hmaarten\Documents\gtsam_build\gtsam_with_patches\gtsam\build\python\gtsam\__init__.py", line 9, in <module>
    from gtsam import gtsam, utils
ImportError: cannot import name 'gtsam' from partially initialized module 'gtsam' (most likely due to a circular import) (C:\Users\hmaarten\Documents\gtsam_build\gtsam_with_patches\gtsam\build\python\gtsam\__init__.py)

remains. Using ninja instead for the build outside of anaconda, i.e., changing

cmake .. -DGTSAM_BUILD_PYTHON=1 -DGTSAM_PYTHON_VERSION=3.11

to

cmake .. -GNinja -DGTSAM_BUILD_PYTHON=1 -DGTSAM_PYTHON_VERSION=3.11

yields

CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The CXX compiler identification is GNU 13.1.0
-- The C compiler identification is GNU 13.1.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Strawberry/c/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- GTSAM is a shared library due to GTSAM_FORCE_SHARED_LIB
-- GTSAM_POSE3_EXPMAP=ON, enabling GTSAM_ROT3_EXPMAP as well
-- Performing Test COMPILER_HAS_WSUGGEST_OVERRIDE
-- Performing Test COMPILER_HAS_WSUGGEST_OVERRIDE - Success
-- Performing Test COMPILER_HAS_WMISSING_OVERRIDE
-- Performing Test COMPILER_HAS_WMISSING_OVERRIDE - Failed
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Could NOT find Boost (missing: Boost_INCLUDE_DIR serialization system filesystem thread program_options date_time timer chrono regex) (Required is at least version "1.65")
CMake Error at cmake/HandleBoost.cmake:33 (message):
  Missing required Boost components >= v1.65, please install/upgrade Boost or
  configure your search paths.
Call Stack (most recent call first):
  CMakeLists.txt:66 (include)

-- Configuring incomplete, errors occurred!

so indicating again a boost not found error. (without -GNinja flag boost was found and cmake is successful)

Thanks for your continued support, I much appreciate it. If the patch that you suggest in #26 actually works (from what I can see it does), I'd be very happy with that and the issue can be closed from my side.

@hmaarten
Copy link
Author

Problem is fixed for me with the latest build #26 , thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants