10000 Add profiling code · hzyjerry/robotics-toolbox-python@30f1368 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30f1368

Browse files
committed
Add profiling code
1 parent 230da06 commit 30f1368

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-14
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
*.sw*
33
*.gif
44
*.so
5+
data/
6+
*.mp4
7+
*.png
58

69
.idea/*
710

roboticstoolbox/examples/benchmark.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# cd Projects/Motion/robotics-toolbox-python/
2+
# source activate pytorch3d
3+
4+
5+
# python roboticstoolbox/examples/chomp.py --pts 1 --vb --nq 10 > data/verbose_pts0001_nq10.txt
6+
# python roboticstoolbox/examples/chomp.py --pts 5 --vb --nq 10 > data/verbose_pts0005_nq10.txt
7+
# python roboticstoolbox/examples/chomp.py --pts 5 --vb --nq 10 > data/verbose_pts0005_nq10.txt
8+
# python roboticstoolbox/examples/chomp.py --pts 5 --vb --nq 10 > data/verbose_pts0005_nq10.txt
9+
# python roboticstoolbox/examples/chomp.py --pts 5 --vb --nq 10 > data/verbose_pts0005_nq10.txt
10+
11+
# for i in 1 5 20 50 100 200 400 800 1600 3200 6400
12+
# do
13+
# a=`printf "%.4d" $i`
14+
# echo "data/verbose_pts${a}_nq10.txt"
15+
# python roboticstoolbox/examples/chomp.py --pts $i --vb --nq 10 > "data/verbose_pts${a}_nq10.txt"
16+
# done
17+
18+
19+
# for i in 1 5 20 50 100 200 400 800 1600 3200 6400
20+
for i in 6400
21+
do
22+
a=`printf "%.4d" $i`
23+
echo "data/noverb_pts${a}_nq10.txt"
24+
python roboticstoolbox/examples/chomp.py --pts $i --nq 10 > "data/noverb_pts${a}_nq10.txt"
25+
done

roboticstoolbox/examples/chomp.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
import math
1515
from numba import vectorize
1616

17-
visualize = True
18-
verbose = False
19-
use_mesh = True
2017

21-
MODES = {"PTS", "LINKS", "TS"}
18+
MODES = {"PTS", "LINKS", "TS", "NONE"}
2219
"""
2320
Speed:
2421
@@ -45,9 +42,10 @@
4542

4643
fknm_ = None
4744

48-
def chomp(mode, seed=0):
45+
def chomp(mode, seed=0, num_pts=1, nq=10):
4946
np.random.seed(seed)
5047
assert mode in MODES
48+
print(f"CHOMP Mode {mode}")
5149

5250
robot = rtb.models.DH.Panda() # load Mesh version (for collisions)
5351
# robot = rtb.models.URDF.Panda() # load URDF version of the Panda (for visuals)
@@ -80,11 +78,9 @@ def chomp(mode, seed=0):
8078

8179
# Hyperparameters
8280
dt = 1
83-
nq = 50
8481
lmbda = 1000
8582
eta = 1000
8683
iters = 4
87-
num_pts = 50
8884

8985
# Make cost field, starting & end points
9086
cdim = len(qtraj.q[0])
@@ -112,7 +108,7 @@ def chomp(mode, seed=0):
112108

113109

114110
for t in range(iters):
115-
with Profiler(f"Iteration {mode}"):
111+
with Profiler(f"Mode {mode} iteration"):
116112
nabla_smooth = AA.dot(xi) + bb
117113
nabla_obs = np.zeros(xidim)
118114
xidd = AA.dot(xi)
@@ -295,7 +291,8 @@ def chomp(mode, seed=0):
295291
# dxi = Ainv.dot(lmbda * nabla_smooth)
296292
dxi = Ainv.dot(nabla_obs + lmbda * nabla_smooth)
297293
xi -= dxi / eta
298-
print(f"Iteration {t} total cost {total_cost}")
294+
if verbose:
295+
print(f"Iteration {t} total cost {total_cost}")
299296

300297

301298
if visualize:
@@ -419,7 +416,21 @@ def test_parallel(seed=0):
419416

420417

421418
if __name__ == "__main__":
422-
chomp(mode="PTS")
423-
chomp(mode="LINKS")
424-
chomp(mode="TS")
419+
import argparse
420+
parser = argparse.ArgumentParser(description='Process some integers.')
421+
parser.add_argument('--pts', type=int, default=50)
422+
parser.add_argument('--nq', type=int, default=10)
423+
parser.add_argument('--vb', action="store_true", default=False)
424+
425+
opt = parser.parse_args()
426+
visualize = True
427+
verbose = opt.vb
428+
num_pts = opt.pts
429+
nq = opt.nq
430+
use_mesh = True
431+
432+
chomp(mode="NONE", num_pts=num_pts, nq=nq)
433+
chomp(mode="PTS", num_pts=num_pts, nq=nq)
434+
chomp(mode="LINKS", num_pts=num_pts, nq=nq)
435+
chomp(mode="TS", num_pts=num_pts, nq=nq)
425436
# test_parallel()

roboticstoolbox/tools/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from numba import vectorize
1515

1616
fknm_ = None
17+
PATH = "/home/jerry/Projects/Motion/robotics-toolbox-python/roboticstoolbox/cuda/fknm"
1718

1819
def vmatmul(mat1, mat2):
1920
# mat1: (N, a, b)
@@ -61,7 +62,7 @@ def jacob0_pts_vec(robot, end, pts, jacob_vec, qt=None, verbose=False):
6162
if qt is None:
6263
qt = robot.q
6364
if fknm_ is None:
64-
fknm_=np.ctypeslib.load_library('roboticstoolbox/cuda/fknm','.')
65+
fknm_=np.ctypeslib.load_library(PATH,'.')
6566
# Parallel, use cuda
6667
N = len(pts)
6768
pts_tool = vrepeat(np.eye(4), N)
@@ -137,7 +138,7 @@ def jacob0_vec(robot, nq, njoints, link_bases, pts, jacob_vec, qt=None, verbose=
137138
if qt is None:
138139
qt = np.tile(np.array(robot.q), nq)
139140
if fknm_ is None:
140-
fknm_=np.ctypeslib.load_library('roboticstoolbox/cuda/fknm','.')
141+
fknm_=np.ctypeslib.load_library(PATH,'.')
141142
# Parallel, use cuda
142143
N = len(pts)
143144
num_pts = int(N / len(link_bases))

0 commit comments

Comments
 (0)
0