Skip to content

Commit 964edea

Browse files
committed
Merge branch 'main' into dev/mutablemapping
2 parents 2df42a4 + bfbd23d commit 964edea

File tree

1 file changed

+130
-31
lines changed

1 file changed

+130
-31
lines changed

README.md

+130-31
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
# treevalue
1+
<div align="center">
2+
<a href="https://opendilab.github.io/treevalue/"><img width="1000px" height="auto" src="https://github.com/opendilab/treevalue/blob/main/docs/source/_static/title-banner.png"></a>
3+
</div>
24

5+
---
6+
7+
[![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2Fopendilab)](https://twitter.com/opendilab)
38
[![PyPI](https://img.shields.io/pypi/v/treevalue)](https://pypi.org/project/treevalue/)
49
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/treevalue)
510
![Loc](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/HansBug/ff0bc026423888cd7c4f287eaed4b3f5/raw/loc.json)
611
![Comments](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/HansBug/ff0bc026423888cd7c4f287eaed4b3f5/raw/comments.json)
712

8-
913
[![Docs Deploy](https://github.com/opendilab/treevalue/workflows/Docs%20Deploy/badge.svg)](https://github.com/opendilab/treevalue/actions?query=workflow%3A%22Docs+Deploy%22)
1014
[![Code Test](https://github.com/opendilab/treevalue/workflows/Code%20Test/badge.svg)](https://github.com/opendilab/treevalue/actions?query=workflow%3A%22Code+Test%22)
1115
[![Badge Creation](https://github.com/opendilab/treevalue/workflows/Badge%20Creation/badge.svg)](https://github.com/opendilab/treevalue/actions?query=workflow%3A%22Badge+Creation%22)
1216
[![Package Release](https://github.com/opendilab/treevalue/workflows/Package%20Release/badge.svg)](https://github.com/opendilab/treevalue/actions?query=workflow%3A%22Package+Release%22)
1317
[![codecov](https://codecov.io/gh/opendilab/treevalue/branch/main/graph/badge.svg?token=XJVDP4EFAT)](https://codecov.io/gh/opendilab/treevalue)
1418

19+
![GitHub Org's stars](https://img.shields.io/github/stars/opendilab)
1520
[![GitHub stars](https://img.shields.io/github/stars/opendilab/treevalue)](https://github.com/opendilab/treevalue/stargazers)
1621
[![GitHub forks](https://img.shields.io/github/forks/opendilab/treevalue)](https://github.com/opendilab/treevalue/network)
1722
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/opendilab/treevalue)
@@ -22,25 +27,65 @@
2227

2328
`TreeValue` is a generalized tree-based data structure mainly developed by [OpenDILab Contributors](https://github.com/opendilab).
2429

25-
Almost all the operation can be supported in form of trees in a convenient way to simplify the structure processing when the calculation is tree-based.
30+
Almost all the operations can be supported in the form of trees in a convenient way to simplify the structure processing when the calculation is tree-based.
31+
32+
## Outline
33+
34+
* [Overview](#overview)
35+
* [Getting Started](#getting-started)
36+
* [Prerequisite](#prerequisite)
37+
* [Installation](#installation)
38+
* [Quick Usage](#quick-usage)
39+
* [Tutorials](#tutorials)
40+
* [External](#external)
41+
* [Speed Performance](#speed-performance)
42+
* [Change Log](#change-log)
43+
* [Feedback and Contribute](#feedback-and-contribute)
44+
* [Citation](#citation)
45+
* [License](#license)
46+
47+
## Overview
48+
49+
When we build a complex nested structure, we need to model it as a tree structure, and the native list and dict in Python are often used to solve this problem. However, it takes a lot of codes and some complex and non-intuitive calculation logic, which is not easy to modify and extend related code and data, and parallelization is impossible.
50+
51+
Therefore, we need a kind of more proper data container, named `TreeValue`. It is designed for solving the following problems:
52+
53+
- **Ease of Use**: When the existing operations are applied to tree structures such as dict, they will become completely unrecognizable, with really low readability and maintainability.
54+
- **Diversity of Data**: In the tree structure operation, various abnormal conditions (structure mismatch, missing key-value, type mismatch, etc.) occur from time to time, and the code will be more complicated if it needs to be handled properly.
55+
- **Scalability and Parallelization**: When any multivariate operation is performed, the calculation logic needs to be redesigned under the native Python code implementation, and the processing will be more complicated and confusing, and the code quality is difficult to control.
56+
57+
## Getting Started
2658

27-
## Installation
59+
### Prerequisite
60+
61+
`treevalue` has been fully tested in the Linux, macOS and Windows environments and with multiple Python versions, and it works properly on all these platforms.
62+
63+
However, **`treevalue` currently does not support PyPy**, so just pay attention to this when using it.
64+
65+
### Installation
2866

2967
You can simply install it with `pip` command line from the official PyPI site.
3068

3169
```shell
3270
pip install treevalue
3371
```
3472

35-
For more information about installation, you can refer to the [installation guide](https://opendilab.github.io/treevalue/main/tutorials/installation/index.html).
73+
Or just from the source code on github
3674

37-
## Documentation
75+
```shell
76+
pip install git+https://github.com/opendilab/treevalue.git@main
77+
```
78+
79+
For more information about installation, you can refer to the [installation guide](https://opendilab.github.io/treevalue/main/tutorials/installation/index.html).
3880

39-
The detailed documentation are hosted on [https://opendilab.github.io/treevalue](https://opendilab.github.io/treevalue/).
81+
After this, you can check if the installation is processed properly with the following code
4082

41-
Only english version is provided now, the chinese documentation is still under development.
83+
```python
84+
from treevalue import __version__
85+
print('TreeValue version is', __version__)
86+
```
4287

43-
## Quick Start
88+
### Quick Usage
4489

4590
You can easily create a tree value object based on `FastTreeValue`.
4691

@@ -140,15 +185,43 @@ print(1 + (t - 0.8) ** 2 * 1.5) # math operators
140185
# [1.0782, 1.0037, 1.5075, 1.0658]])
141186
```
142187

143-
For more quick start explanation and further usage, take a look at:
188+
189+
190+
### Tutorials
191+
192+
For more examples, explanations and further usages, take a look at:
144193

145194
* [Quick Start](https://opendilab.github.io/treevalue/main/tutorials/quick_start/index.html)
195+
* [Create a Simplest Tree](https://opendilab.github.io/treevalue/main/tutorials/quick_start/index.html#create-a-simplest-tree)
196+
* [Create a Slightly Complex Tree](https://opendilab.github.io/treevalue/main/tutorials/quick_start/index.html#create-a-slightly-complex-tree)
146197
* [Basic Usage](https://opendilab.github.io/treevalue/main/tutorials/basic_usage/index.html)
198+
* [Create a Tree](https://opendilab.github.io/treevalue/main/tutorials/basic_usage/index.html#create-a-tree)
199+
* [Edit a Tree](https://opendilab.github.io/treevalue/main/tutorials/basic_usage/index.html#edit-the-tree)
200+
* [Do Index or Slice Calculation on The Tree](https://opendilab.github.io/treevalue/main/tutorials/basic_usage/index.html#do-index-or-slice-calculation-on-the-tree)
201+
* [Do Math Calculation on The Tree](https://opendilab.github.io/treevalue/main/tutorials/basic_usage/index.html#do-calculation-on-the-tree)
202+
* [Make Function Tree-Supported](https://opendilab.github.io/treevalue/main/tutorials/basic_usage/index.html#make-function-tree-supported)
147203
* [Advanced Usage](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html)
204+
* [Function Modes](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#function-modes)
205+
* [Inheriting on Trees](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#inheriting-on-trees)
206+
* [Process Missing Values](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#process-missing-values)
207+
* [Functional Utilities](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#functional-utilities)
208+
* [Structural Utilities](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#structural-utilities)
209+
* [Tree Utilities](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#tree-utilities)
210+
* [Flatten Utilities](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#flatten-utilities)
211+
* [IO Utilities](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#io-utilities)
212+
* [Object Oriented Usage](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#object-oriented-usage)
213+
* [Costumize My TreeValue Class](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#diy-treevalue-class)
214+
* [Visualization of TreeValue](https://opendilab.github.io/treevalue/main/tutorials/advanced_usage/index.html#draw-graph-for-treevalue)
215+
216+
### External
217+
218+
We provide an official treevalue-based-wrapper for numpy and torch called [DI-treetensor](https://github.com/opendilab/DI-treetensor) since the `treevalue` is often used with libraries like `numpy` and `torch`. It will actually be helpful while working with AI fields.
219+
220+
148221

149222
## Speed Performance
150223

151-
Here is the speed performance of all the operations in `FastTreeValue`, the following table is the performance comparison result with [dm-tree](https://github.com/deepmind/tree).
224+
Here is the speed performance of all the operations in `FastTreeValue`; the following table is the performance comparison result with [dm-tree](https://github.com/deepmind/tree).
152225

153226
| | flatten | flatten(with path) | mapping | mapping(with path) |
154227
| --------------------------------------------------- | :--------------: | :-------------------: | :-------------------: | :-------------------------: |
@@ -183,7 +256,7 @@ The following table is the performance comparison result with [tianshou Batch](h
183256
| [treevalue](https://github.com/opendilab/treevalue) | 51.6 ns ± 0.609 ns | **64.4 ns ± 0.564 ns** | **750 ns ± 14.2 ns** | **88.9 µs ± 887 ns** | **50.2 µs ± 771 ns** | **40.3 µs ± 1.08 µs** | **62 µs ± 1.2 µs** |
184257
| [tianshou Batch](https://github.com/thu-ml/tianshou) | **43.2 ns ± 0.698 ns** | 396 ns ± 8.99 ns | 11.1 µs ± 277 ns | 89 µs ± 1.42 µs | 119 µs ± 1.1 µs | 194 µs ± 1.81 µs | 653 µs ± 17.8 µs |
185258

186-
And this is the comparison between tianshou Batch and us, with `cat` , `stack` and `split` operations (**lower value means less time cost and runs faster**)
259+
And this is the comparison between Tianshou Batch and us, with `cat` , `stack` and `split` operations (**lower value means less time cost and runs faster**)
187260

188261
![Time cost of cat operation](docs/source/_static/Time%20cost%20of%20cat%20operation.svg)
189262

@@ -197,36 +270,62 @@ Test benchmark code can be found here:
197270
* [Comparison with jax-libtree](https://github.com/opendilab/treevalue/blob/main/test/compare/jax/test_jax.py)
198271
* [Comparison with tianshou Batch](https://github.com/opendilab/treevalue/blob/main/test/compare/tianshou/test_tianshou_batch.py)
199272

200-
## Extension
273+
## Change Log
201274

202-
If you need to translate `treevalue` object to runnable source code, you may use the [potc-treevalue](https://github.com/potc-dev/potc-treevalue) plugin with the installation command below
275+
<details><summary><b>Version History</b> <i>[click to expand]</i></summary>
276+
<div>
203277

204-
```shell
205-
pip install potc-treevalue
206-
```
278+
* 2022-05-03
279+
1.3.1: Change definition of getitem, setitem and delitem; add pop method for TreeValue class.
280+
* 2022-03-15
281+
1.3.0: Add getitem, setitem and delitem for adding, editing and removing items in TreeValue class.
282+
* 2022-02-22
283+
1.2.2: Optimize union function; add walk utility method.
284+
* 2022-01-26
285+
1.2.1: Update tree printing; add keys, values, items on TreeValue; add comparision to facebook nest library.
286+
* 2022-01-04
287+
1.2.0: Add flatten_values and flatten_keys; fix problem in mapping function; add support for potc.
288+
* 2021-12-03
289+
1.1.0: Add version information; fix bug of default value; add flatten and unflatten; optimization speed performance.
290+
* 2021-10-24
291+
1.0.0: Greatly optimize the speed performance using cython, overhead has been reduced to a negligible level.
292+
</div>
293+
</details>
207294

208-
Or just install it with `treevalue` itself
295+
## Feedback and Contribute
209296

210-
```shell
211-
pip install treevalue[potc]
212-
```
297+
Welcome to **OpenDILab** community - treevalue!
213298

214-
In potc, you can translate the objects to runnable python source code, which can be loaded to objects afterwards by the python interpreter, like the following graph
299+
If you meet some problem or have some brilliant ideas, you can [file an issue](https://github.com/opendilab/treevalue/issues/new/choose).
215300

216-
![potc system](docs/source/_static/potc-doing.svg)
301+
<b>Scan the QR code and add us on Wechat:</b>
217302

218-
For more information, you can refer to
303+
<div align="center">
304+
<img src='https://github.com/opendilab/DI-engine/raw/main/assets/wechat.png' width="25%" />
305+
</div>
219306

220-
* [potc-dev/potc](https://github.com/potc-dev/potc)
221-
* [potc-dev/potc-treevalue](https://github.com/potc-dev/potc-treevalue)
222-
* [Potc Plugin Installation](https://opendilab.github.io/treevalue/main/tutorials/plugins/index.html#potc-support)
307+
Or just contact us with [slack](https://opendilab.slack.com/join/shared_invite/zt-v9tmv4fp-nUBAQEH1_Kuyu_q4plBssQ#/shared-invite/email) or email (opendilab.contact@gmail.com).
223308

224-
## Contribution
309+
Please check [Contributing Guidances](https://github.com/opendilab/treevalue/blob/main/CONTRIBUTING.md).
225310

226-
We appreciate all contributions to improve treevalue, both logic and system designs. Please refer to CONTRIBUTING.md for more guides.
311+
Thanks to the following contributors!
227312

228-
And users can join our [slack communication channel](https://join.slack.com/t/opendilab/shared_invite/zt-v9tmv4fp-nUBAQEH1_Kuyu_q4plBssQ), or contact the core developer [HansBug](https://github.com/HansBug) for more detailed discussion.
313+
<a href="https://github.com/opendilab/treevalue/graphs/contributors">
314+
<img src="https://contrib.rocks/image?repo=opendilab/treevalue" />
315+
</a>
316+
317+
## Citation
318+
319+
```
320+
@misc{treevalue,
321+
title={{TreeValue} - Tree-Structure Computing Solution},
322+
author={TreeValue Contributors},
323+
publisher = {GitHub},
324+
howpublished = {\url{https://github.com/opendilab/treevalue}},
325+
year={2021},
326+
}
327+
```
229328

230329
## License
231330

232-
`treevalue` released under the Apache 2.0 license.
331+
`treevalue` released under the Apache 2.0 license. See the [LICENSE](./LICENSE) file for details.

0 commit comments

Comments
 (0)