Skip to content

Conversation

@Parskatt
Copy link
Collaborator

@Parskatt Parskatt commented Jul 28, 2025

Introduction

This PR introduces CI for publishing wheels to pypi (I've refrained from autopushing to pypi as it's immutable, so if you screw up you have to bump package version), and additionally comes with some bugfixes to the python bindings, and automatic python stub generation (courtesy of pycolmap). The CI is currently running over at my fork, so any updates to this PR can be tested there first, before merging into master here.

Changes

  • Addition of cross-platform wheels for pypi through cibuildwheel in .github/workflows/build-pypi.yaml.
  • No longer build python package in .github/workflows/main.yaml, as python version now has some dependencies, keep main.yaml dep free.
  • Unify target_compile_options across cmakelists as
if(MSVC)
  target_compile_options(benchmark PRIVATE /bigobj /fp:fast)
else()
  if (MARCH_NATIVE)
    target_compile_options(benchmark PRIVATE
      -march=native -Wall -Werror -fPIC -Wno-sign-compare
      -Wno-unused-variable -ffast-math -Wno-ignored-optimization-argument)
  else()
    target_compile_options(benchmark PRIVATE
      -Wall -Werror -fPIC -Wno-sign-compare
      -Wno-unused-variable -ffast-math)
  endif()
  if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    target_compile_options(benchmark PRIVATE
      -Wno-maybe-uninitialized)
  endif()
endif()
  • Some explicit Eigen::Vector2d::Zero() to satisfy picky compilers
  • Follow pycolmap and use _core for the python module, and move it into a folder poselib package folder, instead of just the raw .so.
  • Add pyproject.toml to specify build-dependencies of the python package
  • Add automatic stub generation, following pycolmap
  • Added constructor bindings for poselib::Camera (and also fixed segfault bug).

TODO / Possible improvements

  • Make equivalent of current benchmark for python module to be able to test for regressions etc. We might also consider running entire posebench
  • Move away from dict-type wrappers for pybind and just bind the underlying classes/structs (e.g. RansacOptions etc). Currently it's a headache for me to remember the names, also easy to make mistakes.
  • More explicit errors. Running something like relative pose estimation with a broken camera should result in an error, currently just returns 0 inliers.
  • Update poselib.Camera (Camera pybind improvements #99)

Related PRs/Issues:

#72
#73
#99

@vlarsson
Copy link
Collaborator

@vlarsson @pablospe Some improvements:

Great! So currently I guess it only checks if posebench crashes or not?

TODO

I agree. I can see if I can move it.

  • Currently the data for posebench is downloaded for each python and each arch in the CI. Probably there are ways to cache the data, or do something to prevent this repeated downloading. Should probably look into that.

Potentially we could also set it up to only run on a subset of datasets as well. So it does not have to download everything at once.

@Parskatt
Copy link
Collaborator Author

Yeah, I can make a subset dataset which should be fine to dl many times.

@vlarsson
Copy link
Collaborator

Regarding

Move away from dict-type wrappers for pybind and just bind the underlying classes/structs (e.g. RansacOptions etc). Currently it's a headache for me to remember the names, also easy to make mistakes.
More explicit errors. Running something like relative pose estimation with a broken camera should result in an error, currently just returns 0 inliers.

I agree, but would hold off on this until dev is merged. In dev we have split the options into AbsolutePoseOptions etc. Ideally we have the option to still pass dicts into the pybinds, but they are automatically wrapped to corresponding structs with error messages if there are extra/invalid fields. In particular for cameras, which are often stored/serialized, it is nicer to represent them as dicts instead of these pybind classes. So I would want to keep this functionality.

pyproject.toml Outdated

[project.optional-dependencies]
test = [
"posebench @ git+https://github.com/Parskatt/posebench.git; python_version < \"3.14\"",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pablospe
Copy link
Collaborator

@Parskatt great, progress! Press the button "Ready for review" when you think this is ready and we go over; it looks already quite good.

@Parskatt
Copy link
Collaborator Author

Thanks! I need to sort out a few things with python 3.14, but then should be ready. Don't want to feature-creep this PR too much.

@Parskatt Parskatt marked this pull request as ready for review August 1, 2025 03:09
@Parskatt
Copy link
Collaborator Author

Parskatt commented Aug 1, 2025

(Hopefully) final update:

  • test command via pytest + posebench on a subset of the data that is not very heavy to run.

There are now a few new files.
uv.lock (dependency locking), pyproject.toml, the pyposelib folder, and the tests folder.

uv.lock could arguably be removed, and added to .gitignore. uv maintainers however recommend that it not be ignored.
pyproject.toml should definitely remain.
pyposelib needs to be somewhere for the package files. The naming can be arbitrary and we could move it later to a subfolder.
tests could possibly be renamed or be a subfolder of something else, it is however a pretty standard place for python packages to store tests.

I think these additions are fine, and pretty easy to revert later if we want to change the project structure.

@pablospe
Copy link
Collaborator

pablospe commented Aug 1, 2025

yes, we should keep uv.lock. What I don't see it is where did you use it? I was expecting to find something like uv pip sync. Perhaps we need to add some documentation?

@vlarsson
Copy link
Collaborator

vlarsson commented Aug 4, 2025

(Hopefully) final update:

  • test command via pytest + posebench on a subset of the data that is not very heavy to run.

There are now a few new files. uv.lock (dependency locking), pyproject.toml, the pyposelib folder, and the tests folder.

uv.lock could arguably be removed, and added to .gitignore. uv maintainers however recommend that it not be ignored. pyproject.toml should definitely remain. pyposelib needs to be somewhere for the package files. The naming can be arbitrary and we could move it later to a subfolder. tests could possibly be renamed or be a subfolder of something else, it is however a pretty standard place for python packages to store tests.

I think these additions are fine, and pretty easy to revert later if we want to change the project structure.

Is this ready to merge now? Or do you have more changes planned?

@Parskatt
Copy link
Collaborator Author

Parskatt commented Aug 5, 2025

@vlarsson should be ready to merge.

@pablospe I used uv for building and dep management, but did not add any instructions, no. Basically just uv sync and uv add used. Should be noted that uv is still somewhat a pain to use with c-based projects as package is very often rebuilt, even for minor changes.

@Parskatt Parskatt merged commit 7e9f5f5 into PoseLib:master Aug 6, 2025
1 check passed
@pablospe
Copy link
Collaborator

pablospe commented Aug 6, 2025

should we create a new tag: 2.0.5?

@Parskatt
Copy link
Collaborator Author

Parskatt commented Aug 7, 2025

@pablospe +1, the wheels are prebuilt, you can try them out from the wheelhouse to see if there are any obvious issues, otherwise Id say ready.

@vlarsson bump?

@pablospe
Copy link
Collaborator

@vlarsson Should we bump the version to 2.0.5?
@Parskatt Do we need to only add the new tag, right? Or manually create a release? Or manually triggering the CI? How do we proceed here?

@Parskatt
Copy link
Collaborator Author

CI will trigger for both release and push, so just changing the version in appropriate places will build wheels with correct tags. Then I'll push the wheels manually.

@pablospe
Copy link
Collaborator

I created an issue and assigned to copilot :P even though it was easy, it is amazing it worked out :)
#149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants