Skip to content

Commit

Permalink
Compile gtsam python for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
talregev committed Dec 31, 2023
1 parent 2049e57 commit 404ac17
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 44 deletions.
7 changes: 3 additions & 4 deletions .github/scripts/python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ function build()
# Set to 2 cores so that Actions does not error out during resource provisioning.
cmake --build build -j2

$PYTHON -m pip install --user build/python
cmake --build build --target python-install
}

function test()
{
cd $GITHUB_WORKSPACE/python/gtsam/tests
$PYTHON -m unittest discover -v
cd $GITHUB_WORKSPACE
cmake --build build --target python-test
cmake --build build --target python-test-unstable
}

# select between build or test
Expand Down
55 changes: 52 additions & 3 deletions .github/workflows/build-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ jobs:
CTEST_PARALLEL_LEVEL: 2
CMAKE_BUILD_TYPE: ${{ matrix.build_type }}
PYTHON_VERSION: ${{ matrix.python_version }}
BOOST_VERSION: 1.72.0
BOOST_EXE: boost_1_72_0-msvc-14.2

strategy:
fail-fast: true
fail-fast: false
matrix:
# Github Actions requires a single row to be added to the build matrix.
# See https://help.github.com/en/articles/workflow-syntax-for-github-actions.
Expand All @@ -30,6 +32,7 @@ jobs:
ubuntu-20.04-gcc-9-tbb,
ubuntu-20.04-clang-9,
macOS-11-xcode-13.4.1,
windows-2019-msbuild,
]

build_type: [Release]
Expand All @@ -56,6 +59,10 @@ jobs:
compiler: xcode
version: "13.4.1"

- name: windows-2019-msbuild
os: windows-2019
platform: 64

steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -97,29 +104,71 @@ jobs:
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
- name: Setup msbuild (Windows)
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x${{matrix.platform}}

- name: Setup python (Windows)
uses: actions/setup-python@v4
if: runner.os == 'Windows'
with:
python-version: ${{ matrix.python_version }}

- name: Install ninja (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
choco install ninja
ninja --version
where ninja
- name: Install Boost (Windows)
if: runner.os == 'Windows'
shell: powershell
run: |
# Snippet from: https://github.com/actions/virtual-environments/issues/2667
$BOOST_PATH = "C:\hostedtoolcache\windows\Boost\$env:BOOST_VERSION\x86_64"
# Use the prebuilt binary for Windows
$Url = "https://sourceforge.net/projects/boost/files/boost-binaries/$env:BOOST_VERSION/$env:BOOST_EXE-${{matrix.platform}}.exe"
(New-Object System.Net.WebClient).DownloadFile($Url, "$env:TEMP\boost.exe")
Start-Process -Wait -FilePath "$env:TEMP\boost.exe" "/SILENT","/SP-","/SUPPRESSMSGBOXES","/DIR=$BOOST_PATH"
# Set the BOOST_ROOT variable
echo "BOOST_ROOT=$BOOST_PATH" >> $env:GITHUB_ENV
- name: Set GTSAM_WITH_TBB Flag
if: matrix.flag == 'tbb'
run: |
echo "GTSAM_WITH_TBB=ON" >> $GITHUB_ENV
echo "GTSAM Uses TBB"
- name: Set Swap Space
- name: Set Swap Space (Linux)
if: runner.os == 'Linux'
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 6

- name: Install System Dependencies
- name: Install System Dependencies (Linux, macOS)
if: runner.os != 'Windows'
run: |
bash .github/scripts/python.sh -d
- name: Install Python Dependencies
shell: bash
run: python$PYTHON_VERSION -m pip install -r python/dev_requirements.txt

- name: Build
shell: bash
run: |
bash .github/scripts/python.sh -b
- name: Test
# Disable running tests for windows because some of them are failing.
# Remove this condition when you want to run tests on windows CI.
# if: runner.os != 'Windows'
shell: bash
run: |
bash .github/scripts/python.sh -t
19 changes: 14 additions & 5 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: '3'

- name: Install python packages
if: success()
Expand All @@ -64,7 +64,7 @@ jobs:
:: C:\ProgramData\chocolatey\bin\python3.11.exe -m pip install pyparsing
python --version
python -m pip --version
python -m pip install pyparsing
python -m pip install -r python/dev_requirements.txt
- name: Install ninja
Expand Down Expand Up @@ -99,13 +99,14 @@ jobs:
-DVCPKG_MANIFEST_DIR=%VCPKG_CONFIGS%\manifest ^
-DVCPKG_INSTALLED_DIR=%VCPKG_ROOT%\installed ^
-DVCPKG_OVERLAY_TRIPLETS=%VCPKG_CONFIGS%\triplets ^
-DVCPKG_TARGET_TRIPLET=x64-windows ^
-DVCPKG_TARGET_TRIPLET=x64-windows-release ^
-DVCPKG_INSTALL_OPTIONS=--clean-after-build ^
-DCMAKE_BUILD_TYPE=Release ^
-DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF ^
-DGTSAM_ROT3_EXPMAP=ON ^
-DGTSAM_POSE3_EXPMAP=ON ^
-DGTSAM_BUILD_PYTHON=OFF ^
-DGTSAM_BUILD_TESTS=ON ^
-DGTSAM_BUILD_PYTHON=ON ^
-DGTSAM_BUILD_TESTS=OFF ^
-DGTSAM_BUILD_UNSTABLE=OFF ^
-DGTSAM_USE_SYSTEM_EIGEN=ON ^
-DGTSAM_USE_SYSTEM_METIS=ON ^
Expand All @@ -125,6 +126,14 @@ jobs:
run: |
cmake --build build --config Release -j 2
- name: Run Python tests
if: success()
shell: cmd
run: |
cmake --build build --target python-install
dir/w build\python\gtsam\
cmake --build build --target python-test
- name: Run tests
if: success()
shell: cmd
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.0)

# This is required to avoid an error in modern pybind11 cmake scripts:
if(POLICY CMP0057)
cmake_policy(SET CMP0057 NEW)
endif()

# Set the version number for the library
set (GTSAM_VERSION_MAJOR 4)
set (GTSAM_VERSION_MINOR 3)
Expand Down
1 change: 1 addition & 0 deletions gtsam/3rdparty/vcpkg/manifest/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"eigen3",
"metis",
"tbb",
"pybind11",
"geographiclib",
{
"name":"intel-mkl",
Expand Down
4 changes: 3 additions & 1 deletion gtsam/base/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#include <iostream>
#include <sstream>

#include <gtsam/dllexport.h>

namespace gtsam {
/**
* For Python __str__().
* Redirect std cout to a string stream so we can return a string representation
* of an object when it prints to cout.
* https://stackoverflow.com/questions/5419356/redirect-stdout-stderr-to-a-string
*/
struct RedirectCout {
struct GTSAM_EXPORT RedirectCout {
/// constructor -- redirect stdout buffer to a stringstream buffer
RedirectCout() : ssBuffer_(), coutBuffer_(std::cout.rdbuf(ssBuffer_.rdbuf())) {}

Expand Down
4 changes: 2 additions & 2 deletions gtsam/discrete/DiscreteValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ inline std::vector<DiscreteValues> cartesianProduct(const DiscreteKeys& keys) {
}

/// Free version of markdown.
std::string markdown(const DiscreteValues& values,
std::string GTSAM_EXPORT markdown(const DiscreteValues& values,
const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DiscreteValues::Names& names = {});

/// Free version of html.
std::string html(const DiscreteValues& values,
std::string GTSAM_EXPORT html(const DiscreteValues& values,
const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DiscreteValues::Names& names = {});

Expand Down
2 changes: 1 addition & 1 deletion gtsam/geometry/Rot3.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class GTSAM_EXPORT Rot3 : public LieGroup<Rot3, 3> {
Matrix3 AdjointMap() const { return matrix(); }

// Chart at origin, depends on compile-time flag ROT3_DEFAULT_COORDINATES_MODE
struct ChartAtOrigin {
struct GTSAM_EXPORT ChartAtOrigin {
static Rot3 Retract(const Vector3& v, ChartJacobian H = {});
static Vector3 Local(const Rot3& r, ChartJacobian H = {});
};
Expand Down
18 changes: 8 additions & 10 deletions gtsam/inference/FactorGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

namespace gtsam {
/// Define collection type:
typedef FastVector<FactorIndex> FactorIndices;
using FactorIndices = FastVector<FactorIndex>;

// Forward declarations
template <class CLIQUE>
Expand All @@ -57,17 +57,15 @@ class HybridValues;
template <class FACTOR>
class FactorGraph {
public:
typedef FACTOR FactorType; ///< factor type
typedef std::shared_ptr<FACTOR>
sharedFactor; ///< Shared pointer to a factor
typedef sharedFactor value_type;
typedef typename FastVector<sharedFactor>::iterator iterator;
typedef typename FastVector<sharedFactor>::const_iterator const_iterator;
using FactorType = FACTOR; ///< factor type
using sharedFactor = std::shared_ptr<FACTOR>; ///< Shared pointer to a factor
using value_type = sharedFactor;
using iterator = typename FastVector<sharedFactor>::iterator;
using const_iterator = typename FastVector<sharedFactor>::const_iterator;

private:
typedef FactorGraph<FACTOR> This; ///< Typedef for this class
typedef std::shared_ptr<This>
shared_ptr; ///< Shared pointer for this class
using This = FactorGraph<FACTOR>; ///< Typedef for this class
using shared_ptr = std::shared_ptr<This>; ///< Shared pointer for this class

/// Check if a DERIVEDFACTOR is in fact derived from FactorType.
template <typename DERIVEDFACTOR>
Expand Down
2 changes: 1 addition & 1 deletion gtsam/nonlinear/CustomFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using CustomErrorFunction = std::function<Vector(const CustomFactor &, const Val
*
* This factor is mainly for creating a custom factor in Python.
*/
class CustomFactor: public NoiseModelFactor {
class GTSAM_EXPORT CustomFactor: public NoiseModelFactor {
protected:
CustomErrorFunction error_function_;

Expand Down
8 changes: 4 additions & 4 deletions gtsam/nonlinear/NonlinearFactorGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ namespace gtsam {

public:

typedef FactorGraph<NonlinearFactor> Base;
typedef NonlinearFactorGraph This;
typedef std::shared_ptr<This> shared_ptr;
using Base = FactorGraph<NonlinearFactor>;
using This = NonlinearFactorGraph;
using shared_ptr = std::shared_ptr<This>;

/// @name Standard Constructors
/// @{
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace gtsam {
std::shared_ptr<GaussianFactorGraph> linearize(const Values& linearizationPoint) const;

/// typdef for dampen functions used below
typedef std::function<void(const std::shared_ptr<HessianFactor>& hessianFactor)> Dampen;
using Dampen = std::function<void(const std::shared_ptr<HessianFactor>& hessianFactor)>;

/**
* Instead of producing a GaussianFactorGraph, pre-allocate and linearize directly
Expand Down
2 changes: 1 addition & 1 deletion gtsam/sfm/DsfTrackGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ using MatchIndicesMap = std::map<IndexPair, CorrespondenceIndices>;
* correspondence indices, from each image.
* @param Length-N list of keypoints, for N images/cameras.
*/
std::vector<SfmTrack2d> tracksFromPairwiseMatches(
std::vector<SfmTrack2d> GTSAM_EXPORT tracksFromPairwiseMatches(
const MatchIndicesMap& matches, const KeypointsVector& keypoints,
bool verbose = false);

Expand Down
Loading

0 comments on commit 404ac17

Please sign in to comment.