Skip to content

Commit 2bc2caa

Browse files
committed
remove commented out code
1 parent 33e23f9 commit 2bc2caa

File tree

6 files changed

+9
-97
lines changed

6 files changed

+9
-97
lines changed

models/contact_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def get_dv_w_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi):
314314
A_decom, Jac_v, mu, n_cld, d
315315
)
316316
except SolverError as e:
317-
self.save(e, "comp", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi)
317+
# self.save(e, "comp", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi)
318318
impulse = torch.zeros(n_cld*d, 1).type_as(v)
319319
# velocity after compression phase (before retitution phase)
320320
M_hat_inv = L_V_s @ L_V_s.t() #(n*d, n*d)
@@ -334,7 +334,7 @@ def get_dv_w_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi):
334334
A_decom, Jac_v_prev_r, v_star_c, mu, n_cld, d, target_impulse=target_impulse
335335
)
336336
except SolverError as e:
337-
self.save(e, "rest", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi)
337+
# self.save(e, "rest", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi)
338338
impulse_star_r = torch.zeros(n_cld*d, 1).type_as(v)
339339
# velocity after restitution phase, compensate penetration
340340
dv_rest = (M_hat_inv_Jac_T @ impulse_star_r).reshape(n, d)
@@ -403,7 +403,7 @@ def get_dv_wo_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor):
403403
A_decom, Jac_v, mu, n_cld, d
404404
)
405405
except SolverError as e:
406-
self.save(e, "comp", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor)
406+
# self.save(e, "comp", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor)
407407
impulse = torch.zeros(n_cld*d, 1).type_as(v)
408408
# velocity after compression phase (before retitution phase)
409409
Minv_Jac_T = (Minv @ Jac.reshape(n_cld*d, n*d).t().reshape(n, d*n_cld*d)).reshape(n*d, n_cld*d)
@@ -422,7 +422,7 @@ def get_dv_wo_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor):
422422
A_decom, Jac_v_prev_r, v_star_c, mu, n_cld, d, target_impulse=target_impulse
423423
)
424424
except:
425-
self.save(e, "rest", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor)
425+
# self.save(e, "rest", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor)
426426
impulse_star_r = torch.zeros(n_cld*d, 1).type_as(v)
427427
# velocity after restitution phase
428428
dv_rest = (Minv_Jac_T @ impulse_star_r).reshape(n, d)

models/contact_model_reg.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,7 @@ def get_dv_w_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi):
6666
J_e = J_e_T.t() #
6767
Minv_J_e_T = (Minv @ J_e_T.reshape(n, d*C)).reshape(n*d, C)
6868
J_e_Minv_J_e_T = J_e @ Minv_J_e_T # (C, C)
69-
# M_e = torch.inverse(J_e_Minv_J_e_T + torch.eye(J_e_Minv_J_e_T.shape[0]).type_as(v)*1e-3) # (C, C) inertia in equality contact space
7069
M_e = torch.inverse(J_e_Minv_J_e_T) # (C, C) inertia in equality contact space
71-
# L = torch.cholesky(Minv) # (n, n)
72-
# L_T = L.t() # (n, n)
73-
# L_T_J_e_T = (L_T @ J_e_T.reshape(n, d*C)).reshape(n*d, C)
74-
# Q = (L_T_J_e_T @ M_e) @ L_T_J_e_T.t() # (n*d, n*d)
75-
# e, V = symeig(Q)
76-
# if not torch.allclose(e, (e>0.5).to(dtype=e.dtype), atol=1e-6):
77-
# print(f"warning: eigenvalues is {e}")
78-
# L_V_s = (L @ V[:, :n*d-C].reshape(n, d*(n*d-C))).reshape(n*d, n*d-C) # (n*d, n*d-C)
79-
# V_s_T_L_T_Jac_T = L_V_s.t() @ Jac.reshape(n_cld*d, n*d).t() # (n*d-C, n_cld*d)
8070
factor = torch.eye(n*d).type_as(v) - J_e_T @ M_e @ Minv_J_e_T.t()
8171
M_hat_inv = (Minv @ factor.reshape(n, d*n*d)).reshape(n*d, n*d)
8272
A = Jac.reshape(n_cld*d, n*d) @ M_hat_inv @ Jac.reshape(n_cld*d, n*d).t()
@@ -86,14 +76,9 @@ def get_dv_w_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi):
8676
else:
8777
reg = self.reg
8878
A_decom = torch.cholesky(A+torch.eye(A.shape[0]).type_as(A)*reg, upper=True)
89-
# A_decom = V_s_T_L_T_Jac_T
9079
# make sure v_star is "valid", avoid unbounded cvx problem
9180
v_star_c = self.get_v_star_c_w_J_e(n_cld, n, d, v_star, Jac.reshape(n_cld*d, n*d), J_e)
9281

93-
# Jac_T_v_star = Jac.reshape(n_cld*d, n*d).t() @ v_star.reshape(n_cld*d, 1) # (n*d, 1)
94-
# J_e_Jac_T_v_star = J_e @ Jac_T_v_star # (C, 1)
95-
# v_right = J_e_T @ torch.solve(J_e_Jac_T_v_star, J_e @ J_e_T)[0] # (n*d, 1)
96-
# v_star_c = Jac.reshape(n_cld*d, n*d) @ (Jac_T_v_star - v_right) # (n_cld*d, 1)
9782
# compression phase impulse
9883
try:
9984
impulse = self.solve_compression_impulse(
@@ -105,10 +90,9 @@ def get_dv_w_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi):
10590
A_decom, Jac_v, mu, n_cld, d
10691
)
10792
except SolverError as e:
108-
self.save(e, "comp", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi)
93+
# self.save(e, "comp", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi)
10994
impulse = torch.zeros(n_cld*d, 1).type_as(v)
11095
# velocity after compression phase (before retitution phase)
111-
# M_hat_inv = L_V_s @ L_V_s.t() #(n*d, n*d)
11296
M_hat_inv_Jac_T = M_hat_inv @ Jac.reshape(n_cld*d, n*d).t() # (n*d, n_cld*d)
11397
dv_comp = (M_hat_inv_Jac_T @ impulse).reshape(n, d)
11498
v_prev_r = v[bs_idx] + dv_comp
@@ -125,7 +109,7 @@ def get_dv_w_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi):
125109
A_decom, Jac_v_prev_r, v_star_c, mu, n_cld, d, target_impulse=target_impulse
126110
)
127111
except SolverError as e:
128-
self.save(e, "rest", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi)
112+
# self.save(e, "rest", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor, DPhi)
129113
impulse_star_r = torch.zeros(n_cld*d, 1).type_as(v)
130114
# velocity after restitution phase, compensate penetration
131115
dv_rest = (M_hat_inv_Jac_T @ impulse_star_r).reshape(n, d)
@@ -137,9 +121,6 @@ def get_dv_wo_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor):
137121
n_cld, d, n_o, n_p, _ = Jac.shape
138122
n = n_o * n_p
139123
# calculate A_decom
140-
# Minv_sqrt = torch.cholesky(Minv) # (n, n)
141-
# Minv_sqrt_Jac_T = (Minv_sqrt @ Jac.reshape(n_cld*d, n*d).t().reshape(n, d*n_cld*d)).reshape(n*d, n_cld*d)
142-
# A_decom = Minv_sqrt_Jac_T
143124
Minv_Jac_T = (Minv @ Jac.reshape(n_cld*d, n*d).t().reshape(n, d*n_cld*d)).reshape(n*d, n_cld*d)
144125
A = Jac.reshape(n_cld*d, n*d) @ Minv_Jac_T
145126

@@ -185,10 +166,9 @@ def get_dv_wo_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor):
185166
A_decom, Jac_v, mu, n_cld, d
186167
)
187168
except SolverError as e:
188-
self.save(e, "comp", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor)
169+
# self.save(e, "comp", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor)
189170
impulse = torch.zeros(n_cld*d, 1).type_as(v)
190171
# velocity after compression phase (before retitution phase)
191-
# Minv_Jac_T = (Minv @ Jac.reshape(n_cld*d, n*d).t().reshape(n, d*n_cld*d)).reshape(n*d, n_cld*d)
192172
dv_comp = (Minv_Jac_T @ impulse).reshape(n, d)
193173
v_prev_r = v[bs_idx] + dv_comp
194174
# restitution phase impulse
@@ -204,7 +184,7 @@ def get_dv_wo_J_e(self, bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor):
204184
A_decom, Jac_v_prev_r, v_star_c, mu, n_cld, d, target_impulse=target_impulse
205185
)
206186
except:
207-
self.save(e, "rest", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor)
187+
# self.save(e, "rest", bs_idx, v, Minv, Jac, Jac_v, v_star, mu, cor)
208188
impulse_star_r = torch.zeros(n_cld*d, 1).type_as(v)
209189
# velocity after restitution phase
210190
dv_rest = (Minv_Jac_T @ impulse_star_r).reshape(n, d)

symeig.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,6 @@
66
from torch.autograd import Function
77
import torch
88

9-
# class Symeig(Function):
10-
11-
# @staticmethod
12-
# def forward(ctx, input):
13-
# lambda_, v = torch.symeig(input, eigenvectors=True, upper=True)
14-
# ctx.save_for_backward(input, lambda_, v)
15-
# return lambda_, v
16-
17-
# @staticmethod
18-
# def backward(ctx, glambda_, gv):
19-
# # unpack and initializaiton
20-
# input, lambda_, v = ctx.saved_tensors
21-
# result = torch.zeros_like(input)
22-
# #
23-
# vh = v.conj().transpose(-2, -1)
24-
# # contribution from the eigenvectors
25-
# if gv is not None:
26-
# F = lambda_.unsqueeze(-2) - lambda_.unsqueeze(-1)
27-
# F.diagonal(0, -2, -1).fill_(float("Inf"))
28-
# F.pow_(-1)
29-
# result = v @ ((F * (vh @ gv)) @ vh)
30-
# else:
31-
# result = torch.zeros_like(input)
32-
# # contribution from eigenvalues
33-
# if glambda_ is not None:
34-
# glambda_ = glambda_.type_as(input)
35-
# glambda_term = (v * glambda_.unsqueeze(-2)) @ vh
36-
# result = result + glambda_term
37-
38-
# grad_input = result.add(result.conj().transpose(-2, -1)).mul_(0.5)
39-
40-
# return grad_input
41-
42-
# my_symeig = Symeig.apply
43-
449

4510
class Symeig(Function):
4611

systems/billiards.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ def __init__(self, qt, body):
205205
if d!=3: self.ax.set_aspect("equal")
206206

207207
empty = d * [[]]
208-
# self.colors = np.random.choice([f"C{i}" for i in range(15)], size=n, replace=False)
209208
self.colors = [f"C{i}" for i in range(15)]
210209
self.objects = {
211210
'pts': sum([self.ax.plot(*empty, ms=6, color=self.colors[i]) for i in range(n)], [])
@@ -218,14 +217,11 @@ def __init__(self, qt, body):
218217
self.ax.set_xlim(0.0, 1.0)
219218
self.ax.set_ylim(0.0, 1.0)
220219
self.ax.axis("off"),
221-
# self.ax.set_facecolor('green')
222220
self.fig.set_size_inches(10.5, 10.5)
223221
self.fig.patch.set_facecolor('#3C733F')
224222

225223
empty = self.qt.shape[-1] * [[]]
226-
# self.objects["pts"] = sum(
227-
# [self.ax.plot(*empty, c=self.colors[i]) for i in range(0, qt.shape[1])], []
228-
# )
224+
229225
self.circles = [Circle([[0], [0]], body.ls[0], color='#CCCCCC', lw=None)] + \
230226
[Circle([[0], [0]], body.ls[i], color='#F20530', lw=None) for i in range(1, qt.shape[1]-1)] + \
231227
[Circle([[0], [0]], body.ls[-1], color="#3344cc", lw=None)] + \
@@ -238,20 +234,8 @@ def update(self, i=0):
238234
T, n, d = self.qt.shape
239235
for j in range(n):
240236
self.circles[j].center = self.qt[i, j][0], self.qt[i, j][1]
241-
# qt = self.qt.reshape(T, self.n_o, self.n_p, d)
242-
# for j in range(self.n_o):
243-
# # draw trails
244-
# xyz = qt[i: i+1, j, 0, :]
245-
# # draw points
246-
# self.objects['pts'][j].set_data(*xyz[-1:,...,:2].T)
247-
# if d==3: self.objects['pts'][j].set_3d_properties(xyz[-1:,...,2].T)
248-
# return sum(self.objects.values(), [])
249237
return self.circles
250238

251-
# def animate(self):
252-
# return animation.FuncAnimation(self.fig, self.update, frames=self.qt.shape[0],
253-
# interval=64, init_func=self.init, blit=True,)#.save("test.gif")#.to_html5_video()
254-
255239

256240
class BilliardsDummyAnimation(BilliardsAnimation):
257241
def __init__(self, qt, body, vx, vy):

systems/chain_pendulum_with_contact.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,6 @@ def __init__(self, qt, body):
220220
self.n_o = body.n_o
221221
self.n_p = body.n_p
222222

223-
# x_min, x_max = self.ax.get_xlim()
224-
# y_min, y_max = self.ax.get_ylim()
225-
# x_min = x_min if x_min < -body.lb-0.1 else -body.lb-0.1
226-
# x_max = x_max if x_max > body.rb+0.1 else body.rb+0.1
227-
# self.ax.set_xlim(x_min, x_max)
228-
229223
x_min, y_min, x_max, y_max = -1.1, -1.1, 1.1, 1.1
230224
self.ax.set_xlim(x_min, x_max)
231225
self.ax.set_ylim(y_min, y_max)
@@ -248,7 +242,6 @@ def __init__(self, qt, body):
248242
lines = [[(x_min, -1), (x_max, -1)]]
249243
else:
250244
lines = [[(-1, y_min), (-1, y_max)], [(1, y_min), (1, y_max)]]
251-
# lines = [[(-body.lb, y_min), (-body.lb, y_max)], [(body.rb, y_min), (body.rb, y_max)]]
252245
lc = mc.LineCollection(lines, linewidths=4, color="k")
253246
self.ax.add_collection(lc)
254247

systems/gyroscope_with_wall.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ def __init__(self, qt, body):
234234
# plot the cone
235235
self.cone = [self.ax.plot_surface(xx, yy, zz, zorder=1)]
236236

237-
238237
# plot the lines
239238
# self.objects['lines'] = sum([self.ax.plot([],[],[],"-",c="k") for _ in range(4)], [])
240239
self.objects["lines"] = sum([self.ax.plot([], [], [], "-", c="k", zorder=5) for _ in range(2)], [])
@@ -260,15 +259,6 @@ def update(self, i=0):
260259
self.objects['lines'][0].set_3d_properties(np.array([p0[2],p1[2]]))
261260
self.objects['lines'][1].set_data(np.array([p0[0], p2[0]]), np.array([p0[1],p2[1]]))
262261
self.objects['lines'][1].set_3d_properties(np.array([p0[2],p2[2]]))
263-
264-
265-
# x, y, z = self.qt[i,0].T
266-
# self.objects['lines'][0].set_data(np.array([0,x]), np.array([0,y]))
267-
# self.objects['lines'][0].set_3d_properties(np.array([0,z]))
268-
# for j in range(1,4):
269-
# self.objects['lines'][j].set_data(*self.qt[i, (0, j)].T[:2])
270-
# self.objects['lines'][j].set_3d_properties(self.qt[i, (0, j)].T[2])
271-
272262
# plot cone
273263
self.cone[0].remove()
274264
step = 40

0 commit comments

Comments
 (0)