Skip to content

Commit 3a1a774

Browse files
jeongseok-metafacebook-github-bot
authored andcommitted
Add tensor_ik and solver targets (#223)
Summary: Now that the internal dependencies have been removed from the tensor_ik and solver targets, they can be exposed on GitHub. This is needed to enable running IK on GitHub. Pull Request resolved: #223 Test Plan: GitHub CI: https://github.com/facebookincubator/momentum/actions/runs/13572878021/job/37942078578?pr=223 ``` ============================= test session starts ============================== platform linux -- Python 3.12.9, pytest-8.3.4, pluggy-1.5.0 rootdir: /home/runner/work/momentum/momentum configfile: pyproject.toml collected 43 items pymomentum/test/test_blend_shape.py ..... [ 11%] pymomentum/test/test_closest_points.py .. [ 16%] pymomentum/test/test_fbx.py . [ 18%] pymomentum/test/test_fbx_io.py .. [ 23%] pymomentum/test/test_parameter_transform.py . [ 25%] pymomentum/test/test_pose_prior.py . [ 27%] pymomentum/test/test_process_markers.py ... [ 34%] pymomentum/test/test_quaternion.py .......... [ 58%] pymomentum/test/test_sequence_ik.py . [ 60%] pymomentum/test/test_skel_state.py ........ [ 79%] pymomentum/test/test_skeleton.py . [ 81%] pymomentum/test/test_solver.py ........ [100%] ``` --- The Python reference API doc for solver: {F1975513289} Reviewed By: cdtwigg Differential Revision: D70250178 Pulled By: jeongseok-meta fbshipit-source-id: 593a3b1d67f705cd919ed11f4da9fa0c28cd72d3
1 parent 079f0ab commit 3a1a774

File tree

13 files changed

+137
-37
lines changed

13 files changed

+137
-37
lines changed

cmake/mt_defs.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ function(mt_python_binding)
433433
)
434434
set(oneValueArgs
435435
NAME
436+
MODULE_NAME
436437
)
437438
set(multiValueArgs
438439
HEADERS
@@ -486,6 +487,13 @@ function(mt_python_binding)
486487
target_link_libraries(${_ARG_NAME} PRIVATE ${_ARG_LINK_LIBRARIES})
487488
target_compile_options(${_ARG_NAME} PRIVATE ${_ARG_COMPILE_OPTIONS})
488489

490+
if(NOT _ARG_MODULE_NAME)
491+
set(_ARG_MODULE_NAME ${_ARG_NAME})
492+
endif()
493+
set_target_properties(${_ARG_NAME} PROPERTIES
494+
OUTPUT_NAME "${_ARG_MODULE_NAME}"
495+
)
496+
489497
if(NOT ${_ARG_EXCLUDE_FROM_INSTALL})
490498
set_property(GLOBAL APPEND PROPERTY PYMOMENTUM_TARGETS_TO_INSTALL ${_ARG_NAME})
491499
endif()

pixi.toml

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,7 @@ build_py = { cmd = "pip install . -vv", env = { FBXSDK_PATH = ".deps/fbxsdk", CM
204204
""", MOMENTUM_ENABLE_SIMD = "ON" }, depends-on = [
205205
"install_deps",
206206
] }
207-
test_py = { cmd = """
208-
pytest \
209-
pymomentum/test/test_closest_points.py \
210-
pymomentum/test/test_fbx.py \
211-
pymomentum/test/test_parameter_transform.py \
212-
pymomentum/test/test_quaternion.py \
213-
pymomentum/test/test_skel_state.py \
214-
pymomentum/test/test_skeleton.py
215-
""", env = { MOMENTUM_MODELS_PATH = "momentum/" }, depends-on = [
207+
test_py = { cmd = "pytest pymomentum/test/*.py", env = { MOMENTUM_MODELS_PATH = "momentum/" }, depends-on = [
216208
"build_py",
217209
] }
218210
install_py = { cmd = "pip install -e ." }
@@ -237,15 +229,8 @@ build_py = { cmd = "pip install . -vv", env = { CMAKE_ARGS = """
237229
-DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \
238230
-DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD
239231
""", MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } }
240-
test_py = { cmd = """
241-
pytest \
242-
pymomentum/test/test_closest_points.py \
243-
pymomentum/test/test_fbx.py \
244-
pymomentum/test/test_parameter_transform.py \
245-
pymomentum/test/test_quaternion.py \
246-
pymomentum/test/test_skel_state.py \
247-
pymomentum/test/test_skeleton.py
248-
""", env = { MOMENTUM_MODELS_PATH = "momentum/" }, depends-on = [
232+
# TODO: Remove -k option, once this tests are disabled programmatically if momentum is not built with FBX support
233+
test_py = { cmd = "pytest pymomentum/test/*.py -k 'not (TestFBXIO and (test_save_motions_with_joint_params or test_save_motions_with_model_params))'", env = { MOMENTUM_MODELS_PATH = "momentum/" }, depends-on = [
249234
"build_py",
250235
] }
251236
install_py = { cmd = "pip install -e ." }
@@ -270,15 +255,8 @@ build_py = { cmd = "pip install . -vv", env = { CMAKE_ARGS = """
270255
-DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \
271256
-DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD
272257
""", MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } }
273-
test_py = { cmd = """
274-
pytest \
275-
pymomentum/test/test_closest_points.py \
276-
pymomentum/test/test_fbx.py \
277-
pymomentum/test/test_parameter_transform.py \
278-
pymomentum/test/test_quaternion.py \
279-
pymomentum/test/test_skel_state.py \
280-
pymomentum/test/test_skeleton.py
281-
""", env = { MOMENTUM_MODELS_PATH = "momentum/" }, depends-on = [
258+
# TODO: Remove -k option, once this tests are disabled programmatically if momentum is not built with FBX support
259+
test_py = { cmd = "pytest pymomentum/test/*.py -k 'not (TestFBXIO and (test_save_motions_with_joint_params or test_save_motions_with_model_params))'", env = { MOMENTUM_MODELS_PATH = "momentum/" }, depends-on = [
282260
"build_py",
283261
] }
284262
install_py = { cmd = "pip install -e ." }

pymomentum/CMakeLists.txt

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ mt_library(
8383
PUBLIC_INCLUDE_DIRECTORIES
8484
${ATEN_INCLUDE_DIR}
8585
PRIVATE_INCLUDE_DIRECTORIES
86-
${TORCH_LIBRARIES}
86+
${TORCH_INCLUDE_DIRS}
8787
PUBLIC_LINK_LIBRARIES
8888
momentum
89+
diff_ik
8990
${ATEN_LIBRARIES}
9091
pybind11::pybind11
9192
PRIVATE_LINK_LIBRARIES
9293
python_utility
9394
tensor_utility
94-
axel
9595
Ceres::ceres
9696
Dispenso::dispenso
9797
Eigen3::Eigen
@@ -102,13 +102,35 @@ mt_library(
102102
EXCLUDE_FROM_INSTALL
103103
)
104104

105+
mt_library(
106+
NAME tensor_ik
107+
PYMOMENTUM_HEADERS_VARS tensor_ik_public_headers
108+
PYMOMENTUM_SOURCES_VARS tensor_ik_sources
109+
PUBLIC_INCLUDE_DIRECTORIES
110+
${ATEN_INCLUDE_DIR}
111+
${TORCH_INCLUDE_DIRS}
112+
PUBLIC_LINK_LIBRARIES
113+
momentum
114+
diff_ik
115+
${ATEN_LIBRARIES}
116+
PRIVATE_LINK_LIBRARIES
117+
tensor_utility
118+
Dispenso::dispenso
119+
Eigen3::Eigen
120+
${TORCH_LIBRARIES}
121+
${torch_python}
122+
PUBLIC_COMPILE_OPTIONS
123+
${TORCH_CXX_FLAGS}
124+
EXCLUDE_FROM_INSTALL
125+
)
126+
105127
mt_python_binding(
106128
NAME geometry
107129
PYMOMENTUM_HEADERS_VARS geometry_public_headers
108130
PYMOMENTUM_SOURCES_VARS geometry_sources
109131
INCLUDE_DIRECTORIES
110132
${ATEN_INCLUDE_DIR}
111-
${TORCH_LIBRARIES}
133+
${TORCH_INCLUDE_DIRS}
112134
LINK_LIBRARIES
113135
character
114136
character_test_helpers
@@ -129,6 +151,29 @@ mt_python_binding(
129151
${TORCH_CXX_FLAGS}
130152
)
131153

154+
mt_python_binding(
155+
NAME pymomentum_solver
156+
MODULE_NAME solver
157+
PYMOMENTUM_HEADERS_VARS solver_public_headers
158+
PYMOMENTUM_SOURCES_VARS solver_sources
159+
INCLUDE_DIRECTORIES
160+
${ATEN_INCLUDE_DIR}
161+
${TORCH_INCLUDE_DIRS}
162+
LINK_LIBRARIES
163+
character_solver
164+
math
165+
skeleton
166+
python_utility
167+
tensor_ik
168+
tensor_momentum
169+
tensor_utility
170+
${ATEN_LIBRARIES}
171+
${TORCH_LIBRARIES}
172+
${torch_python}
173+
COMPILE_OPTIONS
174+
${TORCH_CXX_FLAGS}
175+
)
176+
132177
mt_python_binding(
133178
NAME marker_tracking
134179
PYMOMENTUM_HEADERS_VARS marker_tracking_public_headers
@@ -165,6 +210,15 @@ if(MOMENTUM_BUILD_TESTING)
165210
PYMOMENTUM_SOURCES_VARS tensor_utility_test_sources
166211
LINK_LIBRARIES tensor_utility
167212
)
213+
214+
mt_test(
215+
NAME tensor_ik_test
216+
PYMOMENTUM_SOURCES_VARS tensor_ik_test_sources
217+
LINK_LIBRARIES
218+
character_test_helpers
219+
tensor_ik
220+
tensor_utility
221+
)
168222
endif()
169223

170224
#===============================================================================

pymomentum/cmake/build_variables.bzl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,46 @@ tensor_momentum_sources = [
5050
"tensor_momentum/tensor_transforms.cpp",
5151
]
5252

53+
tensor_ik_public_headers = [
54+
"tensor_ik/solver_options.h",
55+
"tensor_ik/tensor_collision_error_function.h",
56+
"tensor_ik/tensor_diff_pose_prior_error_function.h",
57+
"tensor_ik/tensor_distance_error_function.h",
58+
"tensor_ik/tensor_error_function_utility.h",
59+
"tensor_ik/tensor_error_function.h",
60+
"tensor_ik/tensor_gradient.h",
61+
"tensor_ik/tensor_ik_utility.h",
62+
"tensor_ik/tensor_ik.h",
63+
"tensor_ik/tensor_limit_error_function.h",
64+
"tensor_ik/tensor_marker_error_function.h",
65+
"tensor_ik/tensor_motion_error_function.h",
66+
"tensor_ik/tensor_pose_prior_error_function.h",
67+
"tensor_ik/tensor_projection_error_function.h",
68+
"tensor_ik/tensor_residual.h",
69+
"tensor_ik/tensor_vertex_error_function.h",
70+
]
71+
72+
tensor_ik_sources = [
73+
"tensor_ik/tensor_collision_error_function.cpp",
74+
"tensor_ik/tensor_diff_pose_prior_error_function.cpp",
75+
"tensor_ik/tensor_distance_error_function.cpp",
76+
"tensor_ik/tensor_error_function.cpp",
77+
"tensor_ik/tensor_gradient.cpp",
78+
"tensor_ik/tensor_ik_utility.cpp",
79+
"tensor_ik/tensor_ik.cpp",
80+
"tensor_ik/tensor_limit_error_function.cpp",
81+
"tensor_ik/tensor_marker_error_function.cpp",
82+
"tensor_ik/tensor_motion_error_function.cpp",
83+
"tensor_ik/tensor_pose_prior_error_function.cpp",
84+
"tensor_ik/tensor_projection_error_function.cpp",
85+
"tensor_ik/tensor_residual.cpp",
86+
"tensor_ik/tensor_vertex_error_function.cpp",
87+
]
88+
89+
tensor_ik_test_sources = [
90+
"cpp_test/tensor_ik_test.cpp",
91+
]
92+
5393
geometry_public_headers = [
5494
"geometry/momentum_geometry.h",
5595
"geometry/momentum_io.h",
@@ -61,6 +101,15 @@ geometry_sources = [
61101
"geometry/momentum_io.cpp",
62102
]
63103

104+
solver_public_headers = [
105+
"solver/momentum_ik.h",
106+
]
107+
108+
solver_sources = [
109+
"solver/momentum_ik.cpp",
110+
"solver/solver_pybind.cpp",
111+
]
112+
64113
quaternion_sources = [
65114
"quaternion.py",
66115
]

pymomentum/cpp_test/tensor_ik_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ at::Tensor concatBatch(std::vector<at::Tensor> tensors) {
6464
}
6565

6666
const auto sizes = tensors[0].sizes();
67-
std::vector<long> sizes_batch = {(long)tensors.size()};
67+
std::vector<int64_t> sizes_batch = {(int64_t)tensors.size()};
6868
std::copy(
6969
std::begin(sizes), std::end(sizes), std::back_inserter(sizes_batch));
7070

pymomentum/doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Welcome to PyMomentum
88
geometry
99
quaternion
1010
skel_state
11+
solver
1112
marker_tracking

pymomentum/doc/solver.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pymomentum.solver
2+
=================
3+
4+
.. automodule:: pymomentum.solver
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

pymomentum/quaternion.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# Copyright (c) Meta Platforms, Inc. and affiliates.
32
#
43
# This source code is licensed under the MIT license found in the

pymomentum/skel_state.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
16
from typing import Sequence
27

38
import torch

pymomentum/solver/momentum_ik.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <ATen/ATen.h>
1616
#include <pybind11/pybind11.h>
17+
#include <torch/extension.h> // @manual=//caffe2:torch_extension
1718
#include <torch/torch.h>
1819

1920
#include <optional>

0 commit comments

Comments
 (0)