Skip to main content

nanobind bindings for GTSAM

Project description

gtsam-nb: nanobind bindings for GTSAM

PyPI - Version Static Badge GitHub Actions Workflow Status

This repository provides Python bindings for GTSAM using nanobind.

Most of the code, tests, data, etc. are originally from the official GTSAM repository, just slightly modified to work with nanobind and clean up python typing.

Installation

It's all available via pip!

pip install gtsam-nb  # if using pip
uv add gtsam-nb       # if using uv

Then use as you would the official gtsam Python bindings:

import gtsam

gtsam-nb should be a near drop-in replacement for the official gtsam python package, with the following (mostly minor) exceptions:

  • Unlike pybind11, nanobind doesn't accept python lists in place of numpy arrays for function arguments. So wrapping lists in np.array(...) is necessary.
  • OrderingType enum values are now accessed as gtsam.OrderingType.XXX instead of gtsam.Ordering.OrderingType.XXX.
  • lambda_ is now lambda_a in gtsam.LevenbergMarquardtOptimizer due to how nanobind handles private methods.

There are likely other tweaks required (please let us know if you find any), but they should all be fairly minor.

Why?

There's a handful of reasons why I decided to make this (most of which should hopefully be resolved when gtsam 4.3 is released):

  • As of the writing of this README, gtsam's most recent python release only supports up to python 3.11. This has restricted the python version for a number of my projects.
  • In addition, the current stable gtsam on pypi are incompatible with numpy>=2.0.
  • The gtsam python bindings don't include type stubs, making development in an IDE and type checking more difficult.
  • A switch to nanobind over pybind11 for a number of reasons, including
    • nanobind results in faster compilation, smaller binaries, and a smaller overhead. See benchmarks for more details.
    • nanobind has built-in stub generation, make setting up type stubs a cakewalk.
    • Based on my knowledge, nanobind has a more permissive ABI compatibility story than pybind11, which makes it easier to extend gtsam with custom C++ code that will just work together. See here and here.
    • Since all my projects now use nanobind, if I want to add new C++ factors to GTSAM from python, I need nanobind bindings.
  • I often have found the gtsam bindings to be missing a method or two that I need. This then requires me to build the bindings from source. By having my own version, I can easily add in any missing methods I need, and get them merged and released on PyPI quickly. This is more difficult for the official gtsam bindings since they are released alongside GTSAM itself.

Hopefully in the future these issues will be resolved in the official gtsam bindings, and this repository will no longer be necessary. But for now, this is a useful stopgap.

Building

Building is all piped through scikit-build-core (which we use behind uv). The only dependency is GTSAM 4.2, which will be resolved in the following order:

  1. If vcpkg.sh was ran to clone vcpkg into the .vcpkg folder, then GTSAM will be built and installed via vcpkg.
  2. If not, GTSAM is searched for in the system paths.
  3. If not found, GTSAM will be cloned and built from source in the build process.

To actually perform the building from source, clone the repository and run:

pip install -e .   # if using pip
uv sync --verbose  # if using uv

This will build the C++ extension and install the package in editable mode in whatever environment you have activated.

Contributing

There is likely a hidden bug or two, and definitely still some missing methods. Please feel free to open issues or PRs! I imagine most PRs will be to add missing methods or classes from GTSAM so they can be merged and released quickly (especially since it's all automated through the our CI setup).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gtsam_nb-0.1.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (16.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

gtsam_nb-0.1.2-cp314-cp314-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

gtsam_nb-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (16.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

gtsam_nb-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gtsam_nb-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (16.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

gtsam_nb-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gtsam_nb-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (16.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

gtsam_nb-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file gtsam_nb-0.1.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dfc59159c18ed53606bc092640c269f79a222070fabaaa0314e419ee3a097911
MD5 3fa3b030439d0219ead0b3645e1347ca
BLAKE2b-256 db3c080fd17c65ea65f18734c178bf55c32930bdeebeab824b2f5260624e1ae3

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: on_main.yml on contagon/gtsam-nb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gtsam_nb-0.1.2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b826180280584a41c760d6e220d4fc03f73f8b2618364d8c3f7c4b43273d6cc3
MD5 2e024c8f3f96685e23e75c538f1b53f2
BLAKE2b-256 9f832853b1d4b51d1b8811903ea6c5101d23054fa650fc95303d5e503c19ee5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.2-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: on_main.yml on contagon/gtsam-nb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gtsam_nb-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cb084fc7089c542480d28bff608cfd500f42e9a4c9f3fd2dc910570f77005e7a
MD5 dd96b6bc9350e713aec9a257549faa15
BLAKE2b-256 8ceab9176ab3c642c8300ac32d16952190f046b8c289598749e80e1b31dde90e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: on_main.yml on contagon/gtsam-nb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gtsam_nb-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 de21f446b4db75706f53a01551c5108c53e926c2b54de59de5af0dd00d4cca84
MD5 b2dd1fa5d67cf0ff6cd7a77ee2030602
BLAKE2b-256 fee2424f32076d133ac5af208fa48ffe8d7d003717cb200c4c6f2ef447108508

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: on_main.yml on contagon/gtsam-nb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gtsam_nb-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e80e4bd5531a01a12c402f34ecedce5308d6eab59fe213f6887254487662475d
MD5 b974dd9a1f10580bebd6ec7263c22ce7
BLAKE2b-256 cc825be09638309ea2573f4a694380e55743047a918b99d9ecddf22510df95a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: on_main.yml on contagon/gtsam-nb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gtsam_nb-0.1.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3391fbe8210c7b0a337c17659dfee1bea6f37978a47ff62ba114d485d63f013e
MD5 913e7272c3026662525eb793593642c2
BLAKE2b-256 27c0f61d976cb950888fd6fba629fe53018d9bcecf6e373f8bc6868afcdc002b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: on_main.yml on contagon/gtsam-nb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gtsam_nb-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f0c7649c4687cc48d6347eaa176d0680cfa621fdb956221fbafb270ad59dd917
MD5 29fe40219cddf92ac4be70129bafaeab
BLAKE2b-256 f8fbc0b84e72ee78e3b954b2854259aeb2b42f5a46fee1238c883a90ecc65f5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: on_main.yml on contagon/gtsam-nb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gtsam_nb-0.1.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f7ce8da63a9cbbd2d10113315b94dbc4a2af2b0e26a91ec994ec1d12dba68a0e
MD5 34b0a3b0b57e71ace6e3008981740477
BLAKE2b-256 55297c11e4853a85ad4639f3b17723e6a28c1013dd46f1ea9d7cdd004067330b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: on_main.yml on contagon/gtsam-nb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page