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.
  • [FEAT] NonlinearFactorGraph and Values interface more like a python list and dict, respectively including constructors and [] usage.

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 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.3-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.3-cp314-cp314-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

gtsam_nb-0.1.3-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.3-cp313-cp313-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gtsam_nb-0.1.3-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.3-cp312-cp312-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gtsam_nb-0.1.3-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.3-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.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9273ecc2566facdce5950369f8d7d84a5db38a9fcc212704beb59837b6cf970c
MD5 1630afdd794982078845d42ccede2dcf
BLAKE2b-256 90e65682a1d78fcd872d3cee2538dba054949c4664844f863b8315c9fb84d168

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.3-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.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 900837c808c949d5159bdfcd74a591bd55ae9af032da8f922298c7c029d4479e
MD5 c432275c24c4296e663a9f69bd7c0436
BLAKE2b-256 ce8a74a4483abd46fc6ca4b52af148634503279211beaf89495cd0914f2c7419

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.3-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.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3e006b13539da336a87a9c0e135efb39d4e51f5c76293520870e5d7720f8cd24
MD5 6b42cca0da27fff65681e3639e63dd3b
BLAKE2b-256 8a6208c67923e2bbd85df75000d3e5d0b108be94a726984b5e63c34a1c5428d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.3-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.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0346ab704bda3471d498938f3626a0c3c8d5531973cc53d33bee0fd2607e91a3
MD5 3c7ddd74f07dccd7f3646b8a72e3521c
BLAKE2b-256 23f3d41a73a88e58787d2c942fb52a7af5030787fa120d28ef2c6205257da77f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.3-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.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2ce9ba737b564b2b289ee55a208eeeecf538459202a3e6e7125e5be6c495d71c
MD5 f770a7e9a0d47310597e82d7230b1ffa
BLAKE2b-256 925cac94f8a5c5bbdfc9308109804233a8118325f738c1b0c11cb24bac0e82da

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.3-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.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 559bebfc2a11252b89e9dc18af9eb0921a6716d57cd2b36ee6c650e58eb6bf65
MD5 b333b4df05e69224ac52b43deaef3f9b
BLAKE2b-256 e0821ee7aba696fb1cf08a4ff036cde89f0d0a387859aa458905597d4b1c74f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.3-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.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f9c94b15c20ac7dad0a5a64acd2b35a9a4e9bb9b8ef637ba7aabcf8fd9722ec2
MD5 a3eb61452672067333ad3295420df690
BLAKE2b-256 32d09bd9095829a5ee559f389fadf99514c9a078e1daa22dfb25d3301bd761f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.3-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.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gtsam_nb-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d1d621e136d61660c3057111338249f9583a420d44cb3a5778abdca6051b1206
MD5 56814cc3ee391ccd14e1f490ee83e2a6
BLAKE2b-256 5e0534428d04eec8c31ac03f4d508868005fa286a4d163df337883ebcde94a49

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtsam_nb-0.1.3-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