vgvassilev / clad

clad -- automatic differentiation for C/C++
GNU Lesser General Public License v3.0
292 stars 122 forks source link

Improve the printing of the DynamicGraph #1009

Open vgvassilev opened 4 months ago

vgvassilev commented 4 months ago

https://github.com/vgvassilev/clad/blob/69d15a31d11fa38b193d274e2392a086f54006bc/include/clad/Differentiator/DynamicGraph.h#L112 outputs something like:

f1__order_1__mode_hessian: #0 (source), (done)
f2__order_1__mode_hessian: #1 (source), (done)
f3__order_1__mode_hessian: #2 (source), (done)
f4__order_1__mode_hessian: #3 (source), (done)
f5__order_1__mode_hessian: #4 (source), (done)
f6__order_1__mode_hessian: #5 (source), (done)
f7__order_1__mode_hessian: #6 (source), (done)
f8__order_1__mode_hessian: #7 (source), (done)
f1__order_1__mode_forward: #8, (done)
f1_darg0__order_1__mode_reverse: #9, (done)
f2__order_1__mode_forward: #10, (done)
f2_darg0__order_1__mode_reverse: #11, (done)
f3__order_1__mode_forward: #12, (done)
f3_darg0__order_1__mode_reverse: #13, (done)
f4__order_1__mode_forward: #14, (done)
f4_darg0__order_1__mode_reverse: #15, (done)
f5__order_1__mode_forward: #16, (done)
f5_darg0__order_1__mode_reverse: #17, (done)
f6__order_1__mode_forward: #18, (done)
f6_darg0__order_1__mode_reverse: #19, (done)
f6__order_1__mode_forward: #20, (done)
f6_darg1__order_1__mode_reverse: #21, (done)
f7__order_1__mode_forward: #22, (done)
f7_darg0__order_1__mode_reverse: #23, (done)
f7__order_1__mode_forward: #24, (done)
f7_darg1__order_1__mode_reverse: #25, (done)
sin_pushforward__order_1__mode_pullback: #26, (done)
cos_pushforward__order_1__mode_pullback: #27, (done)
exp_pushforward__order_1__mode_pullback: #28, (done)
log_pushforward__order_1__mode_pullback: #29, (done)
pow_pushforward__order_1__mode_pullback: #30, (done)
__builtin_pow_pushforward__order_1__mode_pullback: #31, (unprocessed)
__builtin_pow__order_1__mode_pullback: #32, (unprocessed)
0 -> 8
0 -> 9
1 -> 10
1 -> 11
2 -> 12
2 -> 13
3 -> 14
3 -> 15
4 -> 16
4 -> 17
5 -> 18
5 -> 19
5 -> 20
5 -> 21
6 -> 22
6 -> 23
6 -> 24
6 -> 25
9 -> 26
9 -> 27
11 -> 28
13 -> 29
15 -> 30
30 -> 31
31 -> 32

It would be more understandable if we visualize it they way we visualize the AST with indentations such as:

`f1__order_1__mode_hessian: #0 (source), (done)
|   `f1__order_1__mode_forward: #8, (done)
|   `f1_darg0__order_1__mode_reverse: #9, (done)
|  ...
Aenk-Singhal commented 3 months ago

Hi I would like to try it out !