erwincoumans / tiny-differentiable-simulator

Tiny Differentiable Simulator is a header-only C++ and CUDA physics library for reinforcement learning and robotics with zero dependencies.
Apache License 2.0
1.2k stars 129 forks source link

Add Laikago whole body control example #67

Closed AiRuiChen closed 3 years ago

AiRuiChen commented 3 years ago

Added a cpp version of laikago whole body control example. (python version is here)

A TDS network can now be constructed with a json file with neural network parameters. Thus, we can load a neural network's params to a json file in python, and use the same model in tds.

google-cla[bot] commented 3 years ago

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

google-cla[bot] commented 3 years ago

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

google-cla[bot] commented 3 years ago

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

google-cla[bot] commented 3 years ago

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

eric-heiden commented 3 years ago

@googlebot I consent.

erwincoumans commented 3 years ago

Thanks for the contribution. Quick note: Please don't use include_directories(tds/third_party/nlohmann/include) best to have the example/demo load the data, and convert it to generic data (std::vector or Algebra:: types etc) and then pass that to the neural network. The src folder should not be come dependent on a json header. Also, in general use target_include_directories instead of include_directories.

AiRuiChen commented 3 years ago

Thanks for the contribution. Quick note: Please don't use include_directories(tds/third_party/nlohmann/include) best to have the example/demo load the data, and convert it to generic data (std::vector or Algebra:: types etc) and then pass that to the neural network. The src folder should not be come dependent on a json header. Also, in general use target_include_directories instead of include_directories.

I see. One concern is we might want to add a dump() functionality for tds::NeuralNetwork in order to save a trained model. We'd probably still rely on json as the output format as it is cross platform and easy to serialize to disk. Json dependency sounds mandatory if we want this.

Can we add a cmake option USE_JSON and include the json header conditionally?

erwincoumans commented 3 years ago

Haven't looked at the details yet. We can have the load and save methods in a derived class (which can depend on json), and store that class somewhere outside of src, such as in the examples directory?

Also, please don't use include_directories, always use target_include_directories for a specific target.

AiRuiChen commented 3 years ago

Haven't looked at the details yet. We can have the load and save methods in a derived class (which can depend on json), and store that class somewhere outside of src, such as in the examples directory?

Also, please don't use include_directories, always use target_include_directories for a specific target.

Done. Please take a look at the updated code.

erwincoumans commented 3 years ago

Thanks. There are a few nits that I'll fix after merging:

  int secs_since_start;
  while (secs_since_start < TOTAL_SECS) {

Initialize secs_since_start to 0 before using it (in comparison).

Move mpc_ffn_model.json to the data folder, and use this code (instead of argv[1]:

std::string nn_json_filename;
  tds::FileUtils::find_file("mpc_ffn_model.json",
                            nn_json_filename);