Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/collider to dict #76

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
769a61e
first version of gjk
MaartenBehn Mar 23, 2023
b9c0d9a
it works!!!
MaartenBehn Mar 28, 2023
c4d8fb8
distance working
MaartenBehn Mar 29, 2023
972ac0c
closest points but not done
MaartenBehn Mar 29, 2023
ab5c662
Merge branch 'AlexanderFabisch:master' into feature/accelerated_GJK
MaartenBehn Mar 30, 2023
e740c5b
Benchmarking
MaartenBehn Apr 3, 2023
73250ac
Merge remote-tracking branch 'origin/feature/accelerated_GJK' into fe…
MaartenBehn Apr 3, 2023
321b015
fix
MaartenBehn Apr 4, 2023
a9aea1c
add to_dict to colliders
MaartenBehn Apr 4, 2023
cac3f6d
Merge remote-tracking branch 'maarten/feature/accelerated_GJK' into M…
AlexanderFabisch Apr 4, 2023
700f557
Remove duplicate code
AlexanderFabisch Apr 4, 2023
05a651d
Fix typo
AlexanderFabisch Apr 4, 2023
3d39a41
Add assert
AlexanderFabisch Apr 4, 2023
31c567b
Normal functions
AlexanderFabisch Apr 4, 2023
36b688d
Numba
AlexanderFabisch Apr 4, 2023
f28b63c
Extract iteration
AlexanderFabisch Apr 5, 2023
033d4d4
Simplify check
AlexanderFabisch Apr 5, 2023
a859ae0
Jit nesterov
AlexanderFabisch Apr 5, 2023
9af07d9
Signature
AlexanderFabisch Apr 5, 2023
c66c06d
Merge pull request #2 from AlexanderFabisch/MaartenBehn-feature/accel…
MaartenBehn Apr 5, 2023
0759cc1
moveed constants to be parameters
MaartenBehn Apr 5, 2023
c17923c
remove code for closest point calculations
MaartenBehn Apr 5, 2023
b8e2272
simplex to simpler arrays
MaartenBehn Apr 5, 2023
9786f77
revert changes
MaartenBehn Apr 5, 2023
cbdc96b
debugging
MaartenBehn Apr 5, 2023
43236e8
fix
MaartenBehn Apr 5, 2023
cd631b3
stuff
MaartenBehn Apr 10, 2023
8c64ce4
backup
MaartenBehn Apr 12, 2023
8aae882
Merge branch 'feature/accelerated_GJK' of github.com:MaartenBehn/dist…
MaartenBehn Apr 12, 2023
1a2e388
benchamarks
MaartenBehn Apr 12, 2023
3015784
benchamarks
MaartenBehn Apr 12, 2023
c86661b
iterations
MaartenBehn Apr 13, 2023
2f472fd
merge alexander optimizations
MaartenBehn Apr 14, 2023
b6425c5
unit test pass again, fixed bugs
MaartenBehn Apr 14, 2023
810382a
fix
MaartenBehn Apr 21, 2023
0d46939
fix
MaartenBehn Apr 27, 2023
84ba6ac
fix
MaartenBehn Apr 27, 2023
24f5665
inflation and support function fix
MaartenBehn Apr 27, 2023
be6269f
c++ support functions
MaartenBehn Apr 27, 2023
6f219ed
fixing tests
MaartenBehn Apr 28, 2023
d8e0f13
fixes
MaartenBehn May 3, 2023
3980c0c
test data
MaartenBehn May 3, 2023
b1c5218
test data
MaartenBehn May 3, 2023
2d71be1
test data
MaartenBehn May 3, 2023
dffc2ab
finally all test pass
MaartenBehn May 3, 2023
be6d8fc
simplex fix
MaartenBehn May 3, 2023
8772dec
clean up
MaartenBehn May 3, 2023
4b0bda4
nasterov also works
MaartenBehn May 10, 2023
18d8b4b
clean up code
MaartenBehn May 10, 2023
8b68598
using data tuple
MaartenBehn May 10, 2023
d5e021c
remove index args
MaartenBehn May 10, 2023
a683ac4
fix benchmarks
MaartenBehn May 10, 2023
46be0a1
fix tests
MaartenBehn May 10, 2023
4563cb5
not nesterov is faster
MaartenBehn May 11, 2023
c0529d2
Merge remote-tracking branch 'origin/feature/only_primitives' into fe…
MaartenBehn May 11, 2023
3585471
preliminary separating axis test
MaartenBehn May 11, 2023
d8fce98
format
MaartenBehn May 12, 2023
af39689
ignore
MaartenBehn May 12, 2023
6e599ba
fcl collider loading
MaartenBehn May 19, 2023
fec9e51
Fixed benchmarks
MaartenBehn May 31, 2023
e8b3638
nesterov accelerated
MaartenBehn May 31, 2023
353158a
unit tests
MaartenBehn Jun 2, 2023
3ca2f87
coverage
MaartenBehn Jun 2, 2023
4570c7e
fixes
MaartenBehn Jun 2, 2023
0b9165a
fixes
MaartenBehn Jun 2, 2023
70871e0
clean up collider to dict
MaartenBehn Jun 7, 2023
585528e
Changed to_dict description
MaartenBehn Jun 7, 2023
5bc3ac0
Removed debug calls
MaartenBehn Jun 7, 2023
1ca86d3
added len to mesh to dict
MaartenBehn Jun 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ _auto_examples/
_autosummary/
.idea/
.coverage

*.pclprof
120 changes: 110 additions & 10 deletions benchmarks/benchmark_gjk.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,114 @@
# python -m cProfile -s tottime benchmarks/benchmark_gjk.py > profile
# python -m cProfile -o program.prof benchmarks/benchmark_gjk.py
import timeit
from functools import partial
import numpy as np
from distance3d import colliders
from distance3d.gjk import gjk
from distance3d import colliders, random
from distance3d.gjk import gjk_distance_original, gjk_intersection_jolt, gjk_distance_jolt, \
gjk_nesterov_accelerated_primitives, gjk_nesterov_accelerated
from numba import config

iterations = 200
shapes = []
random_state = np.random.RandomState(84)
shape_names = list(["sphere", "ellipsoid", "capsule", "cone", "cylinder", "box"])

random_state = np.random.RandomState(32)
collider1 = colliders.ConvexHullVertices(random_state.randn(1000, 3))
collider2 = colliders.ConvexHullVertices(random_state.randn(1000, 3))
times = timeit.repeat(partial(gjk, collider1=collider1, collider2=collider2), repeat=10, number=1000)
print(f"Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")
for _ in range(iterations):
shape1 = shape_names[random_state.randint(len(shape_names))]
args1 = random.RANDOM_GENERATORS[shape1](random_state)
shape2 = shape_names[random_state.randint(len(shape_names))]
args2 = random.RANDOM_GENERATORS[shape2](random_state)
collider1 = colliders.COLLIDERS[shape1](*args1)
collider2 = colliders.COLLIDERS[shape2](*args2)

shapes.append((collider1, collider2))


def benchmark_original():
for i in range(iterations):
gjk_distance_original(shapes[i][0], shapes[i][1])


def benchmark_jolt_intersection():
for i in range(iterations):
gjk_intersection_jolt(shapes[i][0], shapes[i][1])


def benchmark_jolt_distance():
for i in range(iterations):
gjk_distance_jolt(shapes[i][0], shapes[i][1])


def benchmark_nesterov_accelerated():
for i in range(iterations):
gjk_nesterov_accelerated(shapes[i][0], shapes[i][1], use_nesterov_acceleration=False)


def benchmark_nesterov_accelerated_with_acceleration():
for i in range(iterations):
gjk_nesterov_accelerated(shapes[i][0], shapes[i][1], use_nesterov_acceleration=True)


def benchmark_nesterov_accelerated_primitives():
for i in range(iterations):
gjk_nesterov_accelerated_primitives(shapes[i][0], shapes[i][1], use_nesterov_acceleration=False)


def benchmark_nesterov_accelerated_primitives_with_acceleration():
for i in range(iterations):
gjk_nesterov_accelerated_primitives(shapes[i][0], shapes[i][1], use_nesterov_acceleration=True)


times = timeit.repeat(benchmark_original, repeat=10, number=1)
print(f"Original Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")

print("\nJolt:")

config.DISABLE_JIT = True
times = timeit.repeat(benchmark_jolt_intersection, repeat=10, number=1)
print(f"Jolt intersection Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")
config.DISABLE_JIT = False

times = timeit.repeat(benchmark_jolt_intersection, repeat=10, number=1)
print(f"Jolt intersection with Numba Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")

config.DISABLE_JIT = True
times = timeit.repeat(benchmark_jolt_distance, repeat=10, number=1)
print(f"Jolt distance Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")
config.DISABLE_JIT = False

times = timeit.repeat(benchmark_jolt_distance, repeat=10, number=1)
print(f"Jolt distance with Numba Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")


print("\nNesterov accelerated:")
times = timeit.repeat(benchmark_nesterov_accelerated, repeat=10, number=1)
print(f"Nesterov Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")

config.DISABLE_JIT = True
times = timeit.repeat(benchmark_nesterov_accelerated, repeat=10, number=1)
print(f"Nesterov with Numba Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")
config.DISABLE_JIT = False

times = timeit.repeat(benchmark_nesterov_accelerated_with_acceleration, repeat=10, number=1)
print(f"Nesterov with acceleration Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")

config.DISABLE_JIT = True
times = timeit.repeat(benchmark_nesterov_accelerated_with_acceleration, repeat=10, number=1)
print(f"Nesterov with acceleration and Numba Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")
config.DISABLE_JIT = False


print("\nNesterov accelerated Primitives:")
times = timeit.repeat(benchmark_nesterov_accelerated_primitives, repeat=10, number=1)
print(f"Nesterov Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")

config.DISABLE_JIT = True
times = timeit.repeat(benchmark_nesterov_accelerated_primitives, repeat=10, number=1)
print(f"Nesterov with Numba Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")
config.DISABLE_JIT = False

times = timeit.repeat(benchmark_nesterov_accelerated_primitives_with_acceleration, repeat=10, number=1)
print(f"Nesterov with acceleration Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")

config.DISABLE_JIT = True
times = timeit.repeat(benchmark_nesterov_accelerated_primitives_with_acceleration, repeat=10, number=1)
print(f"Nesterov with acceleration and Numba Mean: {np.mean(times):.5f}; Std. dev.: {np.std(times):.5f}")
config.DISABLE_JIT = False
2 changes: 1 addition & 1 deletion benchmarks/compare_gjk_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_gjk_intersection_vs_gjk():
args2 = random_function(random_state)
collider2 = Class(*args2)

dist_original, closest_point1_original, closest_point2_original, _ = gjk.gjk_distance_original(collider1, collider2)
dist_original, closest_point1_original, closest_point2_original, _, _ = gjk.gjk_distance_original(collider1, collider2)
dist_jolt, closest_point1_jolt, closest_point2_jolt, _ = gjk.gjk_distance_jolt(collider1, collider2)
gjk_intersection_original = dist_original < 1e-7
gjk_intersection_libccd = gjk.gjk_intersection_libccd(collider1, collider2)
Expand Down
44 changes: 44 additions & 0 deletions benchmarks/compare_gjk_iterations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import json
import os
import numpy as np
from distance3d import colliders, random
from distance3d.gjk._gjk_original import gjk_distance_iterations
from distance3d.gjk._gjk_jolt import gjk_distance_jolt_iterations
from distance3d.gjk._gjk_nesterov_accelerated_primitives import gjk_nesterov_accelerated_primitives_iterations

iterations = 100
random_state = np.random.RandomState(84)
shape_names = ["sphere", "capsule", "cylinder"]

original_iteration_sum = 0
jolt_iteration_sum = 0
nasterov_iteration_sum = 0

for i in range(iterations):
print("Case:", i)

shape1 = shape_names[random_state.randint(len(shape_names))]
args1 = random.RANDOM_GENERATORS[shape1](random_state)
shape2 = shape_names[random_state.randint(len(shape_names))]
args2 = random.RANDOM_GENERATORS[shape2](random_state)
collider1 = colliders.COLLIDERS[shape1](*args1)
collider2 = colliders.COLLIDERS[shape2](*args2)

collider1.round_values(6)
collider2.round_values(6)

original_iterations = gjk_distance_iterations(collider1, collider2)
jolt_iterations = gjk_distance_jolt_iterations(collider1, collider2)
nasterov_iterations = gjk_nesterov_accelerated_primitives_iterations(collider1, collider2)

print("Original Iterations:", original_iterations)
print("Jolt Distance Iterations:", jolt_iterations)
print("Nesterov Iterations", nasterov_iterations)

original_iteration_sum += original_iterations
jolt_iteration_sum += jolt_iterations
nasterov_iteration_sum += nasterov_iterations

print("Original Iterations per Case", original_iteration_sum / iterations)
print("Jolt Distance Iterations per Case", jolt_iteration_sum / iterations)
print("Nesterov Iterations per Case", nasterov_iteration_sum / iterations)
118 changes: 0 additions & 118 deletions benchmarks/external_dependencies/vis_friction_test.py

This file was deleted.

3 changes: 2 additions & 1 deletion benchmarks/vis_gjk_mismatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
print(f"{intersection_jolt=}")
intersection_mpr = mpr.mpr_intersection(collider1, collider2)
print(f"{intersection_mpr=}")
dist_original, cp1_original, cp2_original, _ = gjk.gjk_distance_original(collider1, collider2)
dist_original, cp1_original, cp2_original, _, _ = gjk.gjk_distance_original(collider1, collider2)
print(f"{dist_original=}, {cp1_original=}, {cp2_original=}")
dist_jolt, cp1_jolt, cp2_jolt, _ = gjk.gjk_distance_jolt(collider1, collider2)
print(f"{dist_jolt=}, {cp1_jolt=}, {cp2_jolt=}")

fig = pv.figure()
collider1.make_artist((1, 0, 0))
collider2.make_artist((0, 1, 0))
Expand Down
Loading