GithubHelp home page GithubHelp logo

yilingqiao / diffsim Goto Github PK

View Code? Open in Web Editor NEW
156.0 156.0 13.0 27.82 MB

Scalable Differentiable Physics for Learning and Control (ICML2020)

Makefile 0.17% Python 1.01% HTML 11.15% C++ 81.01% C 6.56% Batchfile 0.03% MATLAB 0.02% Shell 0.05%

diffsim's People

Contributors

vkoltun avatar yilingqiao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

diffsim's Issues

Specifying constraints on objects.

Thanks again for the great paper and code.

I'd like to constrain movement of some of the objects so they can only move with 1 or 2 DF, so I can do some simple 2D experiments.

Is there an example of how to do that somewhere? I was unable to find an example.

isnan and isinf declared twice

On my system, it appears the arcsim/dependencies/include/taucs.h suffers from a problem where isinf and isnan are already declared, but as functions, in a the included math library, and the #ifndef guards do not function, as they expect a macro, not a function.

I hacked a fix by commenting out these lines, and the code seems to compile and run.

arcsim/dependencies/include/taucs.h:804

I replaced..

#ifndef isnan
extern int isnan(double);
#endif
#ifndef finite
extern int finite(double);
#endif
#ifndef isinf
extern int isinf(double);
#endif

with

/* #ifndef isnan
extern int isnan(double);
#endif
*/
#ifndef finite
extern int finite(double);
#endif
/*
#ifndef isinf
extern int isinf(double);
#endif
*/

Memory Leak problem in arcsim.step()

Hi, when I am running modified exp_inverse.py example to fold a cloth, it seems that there is memory leakage, for each epoch when I check the memory using htop, the memory of exp_inverse.py is always increasing. And the process will be automatically killed if the epoch is long. Here is our code

import torch
import arcsim
import gc
import time
import json
import sys
import gc
import os
import numpy as np
import matplotlib.pyplot as plt

from datetime import datetime
now = datetime.now()
timestamp = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
steps = 30
epochs= 10
node_number = 0
handles = [25, 60, 30, 54]
losses = []
param_g = torch.zeros([steps, 12],dtype=torch.float64, requires_grad=True)
default_dir = 'results/'+time.ctime()
os.mkdir(default_dir)
out_path = default_dir + '/default_out'
os.mkdir(out_path)
with open('conf/rigidcloth/drag/drag.json','r') as f:
    config = json.load(f)


def save_config(config, file):
    with open(file,'w') as f:
        json.dump(config, f)

save_config(config, out_path+'/conf.json')


torch.set_num_threads(16)
scalev=1

def reset_sim(sim, epoch):

    if epoch < 20:

        arcsim.init_physics(out_path+'/conf.json', out_path+'/out%d'%epoch,False)
    else:
        arcsim.init_physics(out_path+'/conf.json',out_path+'/out',False)

def get_target_mesh():
    sim = arcsim.get_sim()
    arcsim.init_physics('conf/rigidcloth/fold_targets/target1.json',out_path+'/target',False)
    global node_number
    node_number = len(sim.cloths[0].mesh.nodes)
    ref = [sim.cloths[0].mesh.nodes[i].x.numpy() for i in range(node_number)]
    ref = torch.from_numpy(np.vstack(ref))
    return ref

def get_loss(sim,ref):
    reg  = torch.norm(param_g, p=2)*0.001
    loss = 0
    for i in range(ref.shape[0]):
        loss += torch.norm(ref[i]-sim.cloths[0].mesh.nodes[i].x)**2
    loss /= node_number
    loss += reg
    return loss

def run_sim(steps,sim,ref):
    # sim.obstacles[2].curr_state_mesh.dummy_node.x = param_g[1]
    print("step")
    for step in range(steps):
        print(step)
        for i in range(len(handles)):
            inc_v = param_g[step,3*i:3*i+3]
            sim.cloths[0].mesh.nodes[handles[i]].v += inc_v
            del inc_v
        arcsim.sim_step()
    loss = get_loss(sim,ref)
    return loss

@profile
def do_train(cur_step,optimizer,scheduler,sim):
    epoch = 0
    ref = get_target_mesh()
    print(ref)
    while True:
        reset_sim(sim, epoch)
        st = time.time()
        loss = run_sim(steps, sim,ref)
        en0 = time.time()
        optimizer.zero_grad()


        loss.backward()
        en1 = time.time()
        print("=======================================")
        f.write('epoch {}:  loss={} \n'.format(epoch,  loss.data))
        print('epoch {}:  loss={} \n'.format(epoch, loss.data))

        print('forward time={}'.format(en0-st))
        print('backward time={}'.format(en1-en0))


        optimizer.step()
        #scheduler.step(epoch)
        losses.append(loss)
        if epoch>=epochs:
            break
        epoch = epoch + 1
        # break

def visualize_loss(losses,dir_name):
    plt.plot(losses)
    plt.title('losses')
    plt.xlabel('epochs')
    plt.ylabel('losses')
    plt.savefig(dir_name+'/'+'loss.jpg')

with open(out_path+('/log%s.txt'%timestamp),'w',buffering=1) as f:
    tot_step = 1
    sim=arcsim.get_sim()
    # reset_sim(sim)
    lr = 10
    momentum = 0.4
    f.write('lr={} momentum={}\n'.format(lr,momentum))
    optimizer = torch.optim.SGD([{'params':param_g,'lr':lr}],momentum=momentum)
    scheduler = torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer,10,2,eta_min=0.0001)
    for cur_step in range(tot_step):
        do_train(cur_step,optimizer,scheduler,sim)
    visualize_loss(losses,default_dir)

print("done")

Also, I used memory profiler to inspect the code and find that arcsim.step() takes most memory without releasing them.

Undefined symbol in arcsim.cpython-36m-x86_64-linux-gnu.so

After installing, I got the following error when I try to import arcsim:

ImportError: /home/chenwang/anaconda3/envs/diffsim/lib/python3.6/site-packages/arcsim-0.0.0-py3.6-linux-x86_64.egg/arcsim.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN6caffe26detail37_typeMetaDataInstance_preallocated_14E

By using

echo _ZN6caffe26detail37_typeMetaDataInstance_preallocated_14E | c++filt

I find the undefined symbol is

caffe2::detail::_typeMetaDataInstance_preallocated_14

It seems that the linked pytorch lib has some problem. I installed torch==1.3.0 with pip install torch==1.3.0 as in the instruction.
I find this issue persists in both Ubuntu18.04 and 20.04.

Segmentation fault (core dumped)

When I run demo exp_inverse.py , the error occurs: Segmentation fault (core dumped)
I found the error comes from arcsim.init_physics(out_path+'/conf.json', out_path+'/out%d'%epoch,False)
What should I do?

Bug when bash script_build.sh

arcsim/src/taucs.cpp:37:10: fatal error: taucs.h: No such file or directory
#include "taucs.h"
^~~~~~~~~
compilation terminated.
Makefile:80: recipe for target 'arcsim/objs/taucs.o' failed
make: *** [arcsim/objs/taucs.o] Error 1

Awesome work!

But this is my error report when I bash it. Have any idea how to fix it, guys?

Visualization of the Examples

Hello,

I have managed to run the examples and their corresponding visualizations locally but the visualizations do not look like the ones in the repository. When I run the msim.py, the visualization appears but the meshes are all white and everything is texture-free. Do we need to make other changes to make the textures appear? I am attaching a representative screenshot to explain what I mean.

Thank you for your great contribution.
image

Linux dependencies (Ubuntu)

Few dependencies not mentioned in the docs.

sudo apt install gcc-4.8 gcc-5
sudo apt-get install libblas-dev liblapack-dev
sudo apt-get install libopenblas-dev
sudo apt-get install gfortran
sudo apt-install scons
sudo apt-install libpng-dev

Collision Resolution Unable to Converge

Hi, when using the diffsim framework, it is very likely that during the training process, the code will yield Collision Resolution Unable to Converge problem from arcsim.step() even when the max iteration has been changed to 10,000. May I know what scenario will lead to such a problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.