# torchkin
<p align="center">
<!-- License -->
<a href="https://github.com/facebookresearch/theseus/blob/main/torchkin/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" height="20">
</a>
<!-- pypi -->
<a href="https://pypi.org/project/torchkin/">
<img src="https://img.shields.io/pypi/v/torchkin" alt="pypi"
heigh="20">
<!-- Downloads counter -->
<a href="https://pypi.org/project/torchkin/">
<img src="https://pepy.tech/badge/torchkin" alt="PyPi Downloads" height="20">
</a>
<!-- Python -->
<a href="https://www.python.org/downloads/release/">
<img src="https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue.svg" alt="Python" height="20">
</a>
<!-- Pre-commit -->
<a href="https://github.com/pre-commit/pre-commit">
<img src="https://img.shields.io/badge/pre--commit-enabled-green?logo=pre-commit&logoColor=white" alt="pre-commit" height="20">
</a>
<!-- Black -->
<a href="https://github.com/psf/black">
<img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="black" height="20">
</a>
<!-- PRs -->
<a href="https://github.com/facebookresearch/theseus/blob/main/CONTRIBUTING.md">
<img src="https://img.shields.io/badge/PRs-welcome-green.svg" alt="PRs" height="20">
</a>
</p>
<p align="center">
<i>A library for differentiable kinematics</i>
</p>
-----
## Getting Started
### Prerequisites
- We *strongly* recommend you install torchkin in a venv or conda environment with Python 3.8-3.10.
- torchkin requires `torch` installation. To install for your particular CPU/CUDA configuration, follow the instructions in the PyTorch [website](https://pytorch.org/get-started/locally/).
### Installing
- **pypi**
```bash
pip install torchkin
```
- #### **From source**
The simplest way to install torchkin from source is by running the following
```bash
git clone https://github.com/facebookresearch/theseus.git && cd theseus/torchkin
pip install -e .
```
If you are interested in contributing to torchkin, also install
```bash
pip install -r ../requirements/dev.txt
pre-commit install
```
and follow the more detailed instructions in [CONTRIBUTING](https://github.com/facebookresearch/theseus/blob/main/CONTRIBUTING.md).
## Example
An inverse kinematics example is available in [script](https://github.com/facebookresearch/theseus/blob/main/examples/inverse_kinematics.py).
```python
import torch
import torchkin as kin
# We can load a robot model from a URDF file
dtype = torch.float64
device = "cuda"
robot = kin.Robot.from_urdf_file(YOUR_URDF_FILE, dtype=dtype, device=device)
# Print robot name, number of links and degrees of freedom
print(f"{robot.name} has {len(robot.get_links())} links and {robot.dof} degrees of freedom.\n")
# Print joint id and name
for id, name in enumerate(robot.joint_map):
# A joint is not fixed if and only if id < robot.dof
print(f"joint {id}: {name} is {'not fixed' if id < robot.dof else 'fixed'}")
print("\n")
# Print link id and name
for link in robot.get_links():
print(f"link {link.id}: {link.name}")
# We can get differentiable forward kinematics functions for specific links
# by using `get_forward_kinematics_fns`. This function creates three differentiable
# functions for evaluating forward kinematics, body jacobian and spatial jacobian of
# the selected links, in that order. The return types of these functions are as
# follows:
#
# - fk: return a tuple of link poses in the order of link names
# - jfk_b: returns a tuple where the first is a list of link body jacobians, and the
# second is a tuple of link poses---both are in the order of link names
# - jfk_s: same as jfk_b except returning the spatial jacobians
link_names = [LINK1, LINK2, LINK3]
fk, jfk_b, jfk_s = kin.get_forward_kinematics_fns(
robot=robot, link_names=link_names)
batch_size = 10
# The joint states are in the order of the joint ids
joint_states = torch.rand(batch_size, robot.dof, dtype=dtype, device=device)
# Get link poses
link_poses = fk(joint_states)
# Get body jacobians and link poses
jacs_b, link_poses = jfk_b(joint_states)
# Get spatial jacobians and link poses
jacs_s, link_poses = jfk_s(joint_states)
```
## Citing torchkin
If you use torchkin in your work, please cite the [paper](https://arxiv.org/abs/2207.09442) with the BibTeX below.
```bibtex
@article{pineda2022theseus,
title = {{Theseus: A Library for Differentiable Nonlinear Optimization}},
author = {Luis Pineda and Taosha Fan and Maurizio Monge and Shobha Venkataraman and Paloma Sodhi and Ricky TQ Chen and Joseph Ortiz and Daniel DeTone and Austin Wang and Stuart Anderson and Jing Dong and Brandon Amos and Mustafa Mukadam},
journal = {Advances in Neural Information Processing Systems},
year = {2022}
}
```
## License
torchkin is MIT licensed. See the [LICENSE](https://github.com/facebookresearch/theseus/blob/main/torchkin/LICENSE) for details.
## Additional Information
- Join the community on [Github Discussions](https://github.com/facebookresearch/theseus/discussions) for questions and sugesstions.
- Use [Github Issues](https://github.com/facebookresearch/theseus/issues/new/choose) for bugs and features.
- See [CONTRIBUTING](https://github.com/facebookresearch/theseus/blob/main/CONTRIBUTING.md) if interested in helping out.
Raw data
{
"_id": null,
"home_page": "https://github.com/facebookresearch/theseus/lie",
"name": "torchkin",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "lie groups,differentiable optimization",
"author": "Meta Research",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/b6/b3/3c73baa7370e5230a348c9a4e545aee05b8ef2dc7a930bfafa90224b8597/torchkin-0.1.1.tar.gz",
"platform": null,
"description": "# torchkin\n\n<p align=\"center\">\n <!-- License -->\n <a href=\"https://github.com/facebookresearch/theseus/blob/main/torchkin/LICENSE\">\n <img src=\"https://img.shields.io/badge/license-MIT-blue.svg\" alt=\"License\" height=\"20\">\n </a>\n <!-- pypi -->\n <a href=\"https://pypi.org/project/torchkin/\">\n <img src=\"https://img.shields.io/pypi/v/torchkin\" alt=\"pypi\"\n heigh=\"20\">\n <!-- Downloads counter -->\n <a href=\"https://pypi.org/project/torchkin/\">\n <img src=\"https://pepy.tech/badge/torchkin\" alt=\"PyPi Downloads\" height=\"20\">\n </a>\n <!-- Python -->\n <a href=\"https://www.python.org/downloads/release/\">\n <img src=\"https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue.svg\" alt=\"Python\" height=\"20\">\n </a>\n <!-- Pre-commit -->\n <a href=\"https://github.com/pre-commit/pre-commit\">\n <img src=\"https://img.shields.io/badge/pre--commit-enabled-green?logo=pre-commit&logoColor=white\" alt=\"pre-commit\" height=\"20\">\n </a>\n <!-- Black -->\n <a href=\"https://github.com/psf/black\">\n <img src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"black\" height=\"20\">\n </a>\n <!-- PRs -->\n <a href=\"https://github.com/facebookresearch/theseus/blob/main/CONTRIBUTING.md\">\n <img src=\"https://img.shields.io/badge/PRs-welcome-green.svg\" alt=\"PRs\" height=\"20\">\n </a>\n</p>\n\n<p align=\"center\">\n <i>A library for differentiable kinematics</i>\n</p>\n\n-----\n\n## Getting Started\n\n### Prerequisites\n- We *strongly* recommend you install torchkin in a venv or conda environment with Python 3.8-3.10.\n- torchkin requires `torch` installation. To install for your particular CPU/CUDA configuration, follow the instructions in the PyTorch [website](https://pytorch.org/get-started/locally/).\n\n### Installing\n\n- **pypi**\n ```bash\n pip install torchkin\n ```\n\n- #### **From source**\n The simplest way to install torchkin from source is by running the following\n ```bash\n git clone https://github.com/facebookresearch/theseus.git && cd theseus/torchkin\n pip install -e .\n ```\n If you are interested in contributing to torchkin, also install\n ```bash\n pip install -r ../requirements/dev.txt\n pre-commit install\n ```\n and follow the more detailed instructions in [CONTRIBUTING](https://github.com/facebookresearch/theseus/blob/main/CONTRIBUTING.md).\n\n\n## Example\n\nAn inverse kinematics example is available in [script](https://github.com/facebookresearch/theseus/blob/main/examples/inverse_kinematics.py).\n\n```python\nimport torch\n\nimport torchkin as kin\n\n# We can load a robot model from a URDF file\ndtype = torch.float64\ndevice = \"cuda\"\nrobot = kin.Robot.from_urdf_file(YOUR_URDF_FILE, dtype=dtype, device=device)\n\n# Print robot name, number of links and degrees of freedom\nprint(f\"{robot.name} has {len(robot.get_links())} links and {robot.dof} degrees of freedom.\\n\")\n\n# Print joint id and name\nfor id, name in enumerate(robot.joint_map):\n # A joint is not fixed if and only if id < robot.dof\n print(f\"joint {id}: {name} is {'not fixed' if id < robot.dof else 'fixed'}\")\nprint(\"\\n\")\n\n# Print link id and name\nfor link in robot.get_links():\n print(f\"link {link.id}: {link.name}\")\n\n# We can get differentiable forward kinematics functions for specific links\n# by using `get_forward_kinematics_fns`. This function creates three differentiable\n# functions for evaluating forward kinematics, body jacobian and spatial jacobian of\n# the selected links, in that order. The return types of these functions are as\n# follows:\n#\n# - fk: return a tuple of link poses in the order of link names\n# - jfk_b: returns a tuple where the first is a list of link body jacobians, and the\n# second is a tuple of link poses---both are in the order of link names\n# - jfk_s: same as jfk_b except returning the spatial jacobians\nlink_names = [LINK1, LINK2, LINK3]\nfk, jfk_b, jfk_s = kin.get_forward_kinematics_fns(\n robot=robot, link_names=link_names)\n\nbatch_size = 10\n# The joint states are in the order of the joint ids\njoint_states = torch.rand(batch_size, robot.dof, dtype=dtype, device=device)\n\n# Get link poses\nlink_poses = fk(joint_states)\n\n# Get body jacobians and link poses\njacs_b, link_poses = jfk_b(joint_states) \n\n# Get spatial jacobians and link poses\njacs_s, link_poses = jfk_s(joint_states) \n```\n\n## Citing torchkin\n\nIf you use torchkin in your work, please cite the [paper](https://arxiv.org/abs/2207.09442) with the BibTeX below.\n\n```bibtex\n@article{pineda2022theseus,\n title = {{Theseus: A Library for Differentiable Nonlinear Optimization}},\n author = {Luis Pineda and Taosha Fan and Maurizio Monge and Shobha Venkataraman and Paloma Sodhi and Ricky TQ Chen and Joseph Ortiz and Daniel DeTone and Austin Wang and Stuart Anderson and Jing Dong and Brandon Amos and Mustafa Mukadam},\n journal = {Advances in Neural Information Processing Systems},\n year = {2022}\n}\n```\n\n## License\n\ntorchkin is MIT licensed. See the [LICENSE](https://github.com/facebookresearch/theseus/blob/main/torchkin/LICENSE) for details.\n\n\n## Additional Information\n\n- Join the community on [Github Discussions](https://github.com/facebookresearch/theseus/discussions) for questions and sugesstions.\n- Use [Github Issues](https://github.com/facebookresearch/theseus/issues/new/choose) for bugs and features.\n- See [CONTRIBUTING](https://github.com/facebookresearch/theseus/blob/main/CONTRIBUTING.md) if interested in helping out.\n",
"bugtrack_url": null,
"license": "",
"summary": "Torch extension for differentiable kinematics.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/facebookresearch/theseus/lie"
},
"split_keywords": [
"lie groups",
"differentiable optimization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ac28447bb1038a9c8d76ba7a63b15561e13d285262b326d978e1f967561ed574",
"md5": "8c186bc1d8bbdc8e052b12dcc37549dc",
"sha256": "1f05babc4c9b578754417fa28ad1f0f2520f4ad6c0215d0865be46ee457093f5"
},
"downloads": -1,
"filename": "torchkin-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8c186bc1d8bbdc8e052b12dcc37549dc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10884,
"upload_time": "2023-07-07T15:28:05",
"upload_time_iso_8601": "2023-07-07T15:28:05.025939Z",
"url": "https://files.pythonhosted.org/packages/ac/28/447bb1038a9c8d76ba7a63b15561e13d285262b326d978e1f967561ed574/torchkin-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b6b33c73baa7370e5230a348c9a4e545aee05b8ef2dc7a930bfafa90224b8597",
"md5": "43aded1e01ef4dd0467eb67e2345c4a6",
"sha256": "7827345ff787469a461aaf453bb33da968107886536fa4f2b00d1c0f006b6450"
},
"downloads": -1,
"filename": "torchkin-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "43aded1e01ef4dd0467eb67e2345c4a6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 12068,
"upload_time": "2023-07-07T15:28:06",
"upload_time_iso_8601": "2023-07-07T15:28:06.686483Z",
"url": "https://files.pythonhosted.org/packages/b6/b3/3c73baa7370e5230a348c9a4e545aee05b8ef2dc7a930bfafa90224b8597/torchkin-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-07 15:28:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "facebookresearch",
"github_project": "theseus",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"circle": true,
"lcname": "torchkin"
}