Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Remove backend abstraction and Rust feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jun 21, 2024
1 parent 71dc585 commit eecc916
Show file tree
Hide file tree
Showing 19 changed files with 324 additions and 719 deletions.
31 changes: 11 additions & 20 deletions .github/workflows/build-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,21 @@ jobs:
fail-fast: false
matrix:
include:
- artifact-name: Rust Native - Windows x86_64 (Sleipnir)
optimizer_backend: sleipnir
- artifact-name: Windows x86_64
os: windows-2022
cmake-env:
cargo-build-flags:
- artifact-name: Rust Native - Windows aarch64 (Sleipnir)
optimizer_backend: sleipnir
- artifact-name: Windows aarch64
os: windows-2022
cmake-env:
cargo-build-flags: --target aarch64-pc-windows-msvc
- artifact-name: Rust Native - macOS universal (Sleipnir)
optimizer_backend: sleipnir
- artifact-name: macOS universal
os: macOS-14
cmake_env:
cargo-build-flags:
- artifact-name: Rust Native - Linux x86_64 (Sleipnir)
optimizer_backend: sleipnir
- artifact-name: Linux x86_64
os: ubuntu-24.04
cmake-env:
cargo-build-flags:
- artifact-name: Rust Native - Linux aarch64 (Sleipnir)
optimizer_backend: sleipnir
- artifact-name: Linux aarch64
os: ubuntu-24.04
cmake-env:
cargo-build-flags: --target aarch64-unknown-linux-gnu

name: "${{ matrix.artifact-name }}"
Expand All @@ -46,11 +37,11 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Windows aarch64 Rust compiler
if: matrix.artifact-name == 'Rust Native - Windows aarch64 (Sleipnir)'
if: matrix.artifact-name == 'Windows aarch64'
run: rustup target install aarch64-pc-windows-msvc

- name: Set up Linux aarch64 Rust compiler
if: matrix.artifact-name == 'Rust Native - Linux aarch64 (Sleipnir)'
if: matrix.artifact-name == 'Linux aarch64'
run: |
sudo apt-get update -q
sudo apt-get install -y g++-14-aarch64-linux-gnu
Expand All @@ -67,8 +58,8 @@ jobs:
- run: sudo xcode-select -switch /Applications/Xcode_15.3.app
if: startsWith(matrix.os, 'macOS')

- run: ${{matrix.cmake-env }} cargo build ${{ matrix.cargo-build-flags }} --features ${{ matrix.optimizer_backend }}
- run: cargo build ${{ matrix.cargo-build-flags }}

- run: cargo run --example swerve --features ${{ matrix.optimizer_backend }}
if: matrix.artifact-name != 'Rust Native - Windows aarch64 (Sleipnir)' &&
matrix.artifact-name != 'Rust Native - Linux aarch64 (Sleipnir)'
- run: cargo run --example swerve
if: matrix.artifact-name != 'Windows aarch64' &&
matrix.artifact-name != 'Linux aarch64'
14 changes: 5 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,19 @@ jobs:
fail-fast: false
matrix:
include:
- artifact-name: Native - Windows x86_64 (Sleipnir)
- artifact-name: Windows x86_64
# FIXME: Tests give "Exit code 0xc0000135" for missing DLLs
cmake-args: "-DCMAKE_GENERATOR_PLATFORM=x64 -DBUILD_TESTING=OFF"
optimizer_backend: sleipnir
os: windows-2022
- artifact-name: Native - Windows aarch64 (Sleipnir)
- artifact-name: Windows aarch64
# FIXME: Tests give "Exit code 0xc0000135" for missing DLLs
cmake-args: "-DCMAKE_GENERATOR_PLATFORM=ARM64 -DBUILD_TESTING=OFF"
optimizer_backend: sleipnir
os: windows-2022
- artifact-name: Native - macOS universal (Sleipnir)
- artifact-name: macOS universal
cmake-args: -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
optimizer_backend: sleipnir
os: macOS-14
- artifact-name: Native - Linux x86_64 (Sleipnir)
- artifact-name: Linux x86_64
cmake-args:
optimizer_backend: sleipnir
os: ubuntu-24.04

name: "${{ matrix.artifact-name }}"
Expand All @@ -47,7 +43,7 @@ jobs:
- run: sudo xcode-select -switch /Applications/Xcode_15.3.app
if: startsWith(matrix.os, 'macOS')

- run: cmake -B build -S . -DBUILD_EXAMPLES=ON ${{ matrix.cmake-args }} -DOPTIMIZER_BACKEND=${{ matrix.optimizer_backend }}
- run: cmake -B build -S . -DBUILD_EXAMPLES=ON ${{ matrix.cmake-args }}
- run: cmake --build build --config RelWithDebInfo --parallel 4
- run: ctest --test-dir build -C RelWithDebInfo --output-on-failure
- run: cmake --install build --config RelWithDebInfo --prefix pkg
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ jobs:
- run: cargo fmt --check

- run: cargo clippy --features sleipnir -- -D warnings
- run: cargo clippy -- -D warnings
7 changes: 2 additions & 5 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ jobs:
include:
- sanitizer-name: asan
cmake-args: "-DCMAKE_BUILD_TYPE=Asan"
optimizer_backend: sleipnir
- sanitizer-name: tsan
cmake-args: "-DCMAKE_BUILD_TYPE=Tsan"
optimizer_backend: sleipnir
- sanitizer-name: ubsan
cmake-args: "-DCMAKE_BUILD_TYPE=Ubsan"
optimizer_backend: sleipnir

name: "${{ matrix.sanitizer-name }} with ${{ matrix.optimizer_backend }}"
name: ${{ matrix.sanitizer-name }}
runs-on: ubuntu-24.04

steps:
Expand All @@ -34,6 +31,6 @@ jobs:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 200
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 200
- run: cmake -B build -S . -DBUILD_EXAMPLES=ON ${{ matrix.cmake-args }} -DOPTIMIZER_BACKEND=${{ matrix.optimizer_backend }}
- run: cmake -B build -S . -DBUILD_EXAMPLES=ON ${{ matrix.cmake-args }}
- run: cmake --build build --config RelWithDebInfo --parallel $(nproc)
- run: ctest --test-dir build -C RelWithDebInfo --output-on-failure
47 changes: 19 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,36 +94,27 @@ if(BUILD_TESTING)
fetchcontent_makeavailable(Catch2)
endif()

set(OPTIMIZER_BACKEND "sleipnir" CACHE STRING "Optimizer backend")
set_property(CACHE OPTIMIZER_BACKEND PROPERTY STRINGS sleipnir)

if(${OPTIMIZER_BACKEND} STREQUAL "sleipnir")
message(STATUS "Using Sleipnir optimizer")

set(BUILD_TESTING_SAVE ${BUILD_TESTING})
set(BUILD_EXAMPLES_SAVE ${BUILD_EXAMPLES})

set(BUILD_TESTING OFF)
set(BUILD_EXAMPLES OFF)

fetchcontent_declare(
Sleipnir
GIT_REPOSITORY https://github.com/SleipnirGroup/Sleipnir.git
# main on 2024-06-18
GIT_TAG affeafcd797ad1312b18172dbaed0a69cca6546e
PATCH_COMMAND
git apply
${CMAKE_CURRENT_SOURCE_DIR}/cmake/0001-Downgrade-to-C-20.patch
UPDATE_DISCONNECTED 1
)
fetchcontent_makeavailable(Sleipnir)
set(BUILD_TESTING_SAVE ${BUILD_TESTING})
set(BUILD_EXAMPLES_SAVE ${BUILD_EXAMPLES})

set(BUILD_TESTING OFF)
set(BUILD_EXAMPLES OFF)

fetchcontent_declare(
Sleipnir
GIT_REPOSITORY https://github.com/SleipnirGroup/Sleipnir.git
# main on 2024-06-18
GIT_TAG affeafcd797ad1312b18172dbaed0a69cca6546e
PATCH_COMMAND
git apply ${CMAKE_CURRENT_SOURCE_DIR}/cmake/0001-Downgrade-to-C-20.patch
UPDATE_DISCONNECTED 1
)
fetchcontent_makeavailable(Sleipnir)

set(BUILD_TESTING ${BUILD_TESTING_SAVE})
set(BUILD_EXAMPLES ${BUILD_EXAMPLES_SAVE})
set(BUILD_TESTING ${BUILD_TESTING_SAVE})
set(BUILD_EXAMPLES ${BUILD_EXAMPLES_SAVE})

target_compile_definitions(TrajoptLib PRIVATE OPTIMIZER_BACKEND_SLEIPNIR)
target_link_libraries(TrajoptLib PRIVATE Sleipnir)
endif()
target_link_libraries(TrajoptLib PUBLIC Sleipnir)

target_include_directories(
TrajoptLib
Expand Down
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ serde_json = "1.0"
cxx-build = "1.0"
cmake = "0.1"

[features]
default = []
sleipnir = []

[[example]]
name = "swerve"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ On Windows, open a [Developer PowerShell](https://learn.microsoft.com/en-us/visu
git clone [email protected]:SleipnirGroup/TrajoptLib
cd TrajoptLib

# Configure with Sleipnir backend; automatically downloads library dependencies
cmake -B build -S . -DOPTIMIZER_BACKEND=sleipnir
# Configure
cmake -B build -S .

# Build
cmake --build build
Expand Down Expand Up @@ -78,5 +78,5 @@ On Windows, open a [Developer PowerShell](https://learn.microsoft.com/en-us/visu
git clone [email protected]:SleipnirGroup/TrajoptLib
cd TrajoptLib

cargo build --features sleipnir # Sleipnir backend
cargo build
```
22 changes: 7 additions & 15 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ fn main() {
.profile("Release")
.define("BUILD_TESTING", "OFF");

if cfg!(feature = "sleipnir") {
cmake_config.define("BUILD_SHARED_LIBS", "OFF");

if cfg!(target_os = "windows") {
cmake_config
.define("OPTIMIZER_BACKEND", "sleipnir")
.define("BUILD_SHARED_LIBS", "OFF");

if cfg!(target_os = "windows") {
cmake_config
.generator("Visual Studio 17 2022")
.cxxflag("/EHsc");
}
} else {
panic!("Select an optimizer backend via cargo `--features sleipnir`.");
.generator("Visual Studio 17 2022")
.cxxflag("/EHsc");
}

let cmake_dest = cmake_config.build();
Expand All @@ -43,10 +37,8 @@ fn main() {
);
println!("cargo:rustc-link-lib=trajoptrust");
println!("cargo:rustc-link-lib=TrajoptLib");
if cfg!(feature = "sleipnir") {
println!("cargo:rustc-link-lib=Sleipnir");
println!("cargo:rustc-link-lib=fmt");
}
println!("cargo:rustc-link-lib=Sleipnir");
println!("cargo:rustc-link-lib=fmt");

println!("cargo:rerun-if-changed=src/trajoptlibrust.hpp");
println!("cargo:rerun-if-changed=src/trajoptlibrust.cpp");
Expand Down
11 changes: 2 additions & 9 deletions src/OptimalTrajectoryGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@

#include "trajopt/OptimalTrajectoryGenerator.hpp"

#if defined(OPTIMIZER_BACKEND_SLEIPNIR)
#include "optimization/SleipnirOpti.hpp"
#endif

#include "optimization/algorithms/SwerveDiscreteOptimal.hpp"

namespace trajopt {

expected<SwerveSolution, std::string> OptimalTrajectoryGenerator::Generate(
const SwervePathBuilder& path, bool diagnostics, int64_t handle) {
#if defined(OPTIMIZER_BACKEND_SLEIPNIR)
SwerveDiscreteOptimal<SleipnirExpr, SleipnirOpti> problem(
#endif
path.GetPath(), path.GetControlIntervalCounts(),
path.CalculateInitialGuess(), handle);
SwerveDiscreteOptimal problem(path.GetPath(), path.GetControlIntervalCounts(),
path.CalculateInitialGuess(), handle);
return problem.Generate(diagnostics);
}

Expand Down
33 changes: 18 additions & 15 deletions src/optimization/HolonomicTrajoptUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#pragma once

#include <sleipnir/optimization/OptimizationProblem.hpp>

#include "optimization/TrajoptUtil.hpp"
#include "trajopt/constraint/HeadingConstraint.hpp"
#include "trajopt/constraint/LinePointConstraint.hpp"
Expand All @@ -12,30 +14,31 @@

namespace trajopt {

template <typename Expr, typename Opti>
requires OptiSys<Expr, Opti>
void ApplyHolonomicConstraint(Opti& opti, const Expr& x, const Expr& y,
const Expr& theta, const Expr& vx, const Expr& vy,
const Expr& omega, const Expr& ax, const Expr& ay,
const Expr& alpha,
const HolonomicConstraint& constraint) {
inline void ApplyHolonomicConstraint(
sleipnir::OptimizationProblem& problem, const sleipnir::Variable& x,
const sleipnir::Variable& y, const sleipnir::Variable& theta,
const sleipnir::Variable& vx, const sleipnir::Variable& vy,
const sleipnir::Variable& omega, const sleipnir::Variable& ax,
const sleipnir::Variable& ay, const sleipnir::Variable& alpha,
const HolonomicConstraint& constraint) {
if (std::holds_alternative<HolonomicVelocityConstraint>(constraint)) {
const auto& velocityHolonomicConstraint =
std::get<HolonomicVelocityConstraint>(constraint);
ApplySet2dConstraint(opti, vx, vy,
ApplySet2dConstraint(problem, vx, vy,
velocityHolonomicConstraint.velocityBound);
} else if (std::holds_alternative<AngularVelocityConstraint>(constraint)) {
const auto& angularVelocityConstraint =
std::get<AngularVelocityConstraint>(constraint);
ApplyIntervalSet1dConstraint(
opti, omega, angularVelocityConstraint.angularVelocityBound);
problem, omega, angularVelocityConstraint.angularVelocityBound);
} else if (std::holds_alternative<TranslationConstraint>(constraint)) {
ApplyConstraint(opti, x, y, theta,
ApplyConstraint(problem, x, y, theta,
std::get<TranslationConstraint>(constraint));
} else if (std::holds_alternative<HeadingConstraint>(constraint)) {
ApplyConstraint(opti, x, y, theta, std::get<HeadingConstraint>(constraint));
ApplyConstraint(problem, x, y, theta,
std::get<HeadingConstraint>(constraint));
} else if (std::holds_alternative<LinePointConstraint>(constraint)) {
ApplyConstraint(opti, x, y, theta,
ApplyConstraint(problem, x, y, theta,
std::get<LinePointConstraint>(constraint));
} else if (std::holds_alternative<PointAtConstraint>(constraint)) {
auto pointAtConstraint = std::get<PointAtConstraint>(constraint);
Expand All @@ -60,12 +63,12 @@ void ApplyHolonomicConstraint(Opti& opti, const Expr& x, const Expr& y,
auto dot = hx * ux + hy * uy;

ApplyIntervalSet1dConstraint(
opti, dot, IntervalSet1d(std::cos(headingTolerance), 1.0));
problem, dot, IntervalSet1d(std::cos(headingTolerance), 1.0));
} else if (std::holds_alternative<PointLineConstraint>(constraint)) {
ApplyConstraint(opti, x, y, theta,
ApplyConstraint(problem, x, y, theta,
std::get<PointLineConstraint>(constraint));
} else if (std::holds_alternative<PointPointConstraint>(constraint)) {
ApplyConstraint(opti, x, y, theta,
ApplyConstraint(problem, x, y, theta,
std::get<PointPointConstraint>(constraint));
} // TODO: Investigate a way to condense the code above
}
Expand Down
50 changes: 0 additions & 50 deletions src/optimization/OptiSys.hpp

This file was deleted.

Loading

0 comments on commit eecc916

Please sign in to comment.