locuslab / lcp-physics

A differentiable LCP physics engine in PyTorch.
Apache License 2.0
293 stars 28 forks source link

Issue when running demos #5

Closed baceituno closed 4 years ago

baceituno commented 4 years ago

Hi! I just downloaded your code with interest in academic applications for simulation and have been unable to run any of the demos properly. More concretely I am obtaining the following error:

`Traceback (most recent call last): File "demo.py", line 168, in slide_demo(screen) File "demo.py", line 114, in slide_demo run_world(world, run_time=TIME, screen=screen, recorder=recorder) File "/usr/local/lib/python3.7/site-packages/lcp_physics/physics/world.py", line 267, in run_world world.step() File "/usr/local/lib/python3.7/site-packages/lcp_physics/physics/world.py", line 80, in step self.step_dt(dt) File "/usr/local/lib/python3.7/site-packages/lcp_physics/physics/world.py", line 86, in step_dt new_v = self.engine.solve_dynamics(self, dt) File "/usr/local/lib/python3.7/site-packages/lcp_physics/physics/engines.py", line 76, in solve_dynamics x = -self.lcp_solver(max_iter=self.max_iter, verbose=-1)(M, u, G, h, Je, b, F) File "/usr/local/lib/python3.7/site-packages/lcp_physics/lcp/lcp.py", line 28, in forward self.Q_LU, self.S_LU, self.R = pdipm.pre_factor_kkt(Q, G, F, A) File "/usr/local/lib/python3.7/site-packages/lcp_physics/lcp/solvers/pdipm.py", line 368, in pre_factor_kkt """) RuntimeError: lcp Error: Cannot perform LU factorization on Q. Please make sure that your Q matrix is PSD and has a non-zero diagonal.

`

I wonder if this is related to my particular setup.

All the best, BAC

baceituno commented 4 years ago

Correction: I posted the incomplete error message. The result is:

` pygame 1.9.5.dev0 Hello from the pygame community. https://www.pygame.org/contribute.html Warning: Legacy autograd function with non-static forward method is deprecated and will be removed in 1.3. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function) (THPFunction_do_forward at ../torch/csrc/autograd/python_function.cpp:622) 1 / 1 30.0 Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/lcp_physics/lcp/solvers/pdipm.py", line 362, in pre_factor_kkt Q_LU = btrifact_hack(Q) File "/usr/local/lib/python3.7/site-packages/lcp_physics/lcp/solvers/pdipm.py", line 18, in btrifact_hack return x.btrifact(pivot=not x.is_cuda) AttributeError: 'Tensor' object has no attribute 'btrifact'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "demo.py", line 168, in slide_demo(screen) File "demo.py", line 114, in slide_demo run_world(world, run_time=TIME, screen=screen, recorder=recorder) File "/usr/local/lib/python3.7/site-packages/lcp_physics/physics/world.py", line 267, in run_world world.step() File "/usr/local/lib/python3.7/site-packages/lcp_physics/physics/world.py", line 80, in step self.step_dt(dt) File "/usr/local/lib/python3.7/site-packages/lcp_physics/physics/world.py", line 86, in step_dt new_v = self.engine.solve_dynamics(self, dt) File "/usr/local/lib/python3.7/site-packages/lcp_physics/physics/engines.py", line 76, in solve_dynamics x = -self.lcp_solver(max_iter=self.max_iter, verbose=-1)(M, u, G, h, Je, b, F) File "/usr/local/lib/python3.7/site-packages/lcp_physics/lcp/lcp.py", line 28, in forward self.Q_LU, self.S_LU, self.R = pdipm.pre_factor_kkt(Q, G, F, A) File "/usr/local/lib/python3.7/site-packages/lcp_physics/lcp/solvers/pdipm.py", line 368, in pre_factor_kkt """) RuntimeError: lcp Error: Cannot perform LU factorization on Q. Please make sure that your Q matrix is PSD and has a non-zero diagonal. ` I have pytorch 1.4 and I'm running all in python 3.7

filipeabperes commented 4 years ago

Hi, from your last message this seems like it might be an issue of the name of the btrifact function having changed in recent torch versions.

Torch has changed rapidly since this code was written, and unfortunately as of now it is probably outdated in many respects. If you want to, you could try running it with an older version of torch.

Maybe 0.4 or 0.3 would work, I think.

baceituno commented 4 years ago

Effectively, the methods btrifact() and btrisolve() were replaced with lu() and lu_solve(). This simple change makes the examples work.