google-deepmind / google-deepmind/mujoco_mpc

Proposal: ComposeOverrideModel() in Task to allow programmingly constructed model building using mjSpec API

Open
#371 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.7k
Forks
282
PR merge metrics
No merged PRs in 30d

Description

Hi MuJoCo team & everyone,

* Given the current state that, MjMPC could not be easily updated to using the latest mujoco + menagerie repos, largely due to manually crafted XML patches for tasks, it would be nice to allow custom model building per task using [mjSpec API](https://mujoco.readthedocs.io/en/stable/programming/modeledit.html)

* An example implementation for that could be as follows:
In `Task` class:
```
// Compose & configue override model
UniqueMjModel ComposeOverrideModel() {
mjModel* model = ConstructModel();
model_programmingly_built_ = static_cast(model);
if (model) {
ConfigureModel(model);
return {model, mj_deleteModel};
}
return {nullptr, nullptr};
}

// Programmingly construct model
virtual mjModel* ConstructModel() {
// Construct model from either or both of pre-created XML & mjSpec API
return nullptr;
}

// Customizingly configure model options (timestep, gravity, etc.)
virtual void ConfigureModel(mjModel* model) {
}
```
agent.h:
```
// Currently selected task on GUI
Task* GuiTask() const { return tasks_[gui_task_id].get(); }
```
app.cc:
```
mjModel* LoadModel(const mjpc::Agent* agent, mj::Simulate& sim) {
// Set sim.agent's [model_override_] from task, but only if not already provided
if (nullptr == sim.agent->GetOverrideModel()) {
sim.agent->OverrideModel(sim.agent->GuiTask()->ComposeOverrideModel());
}

// Then load the model
mjpc::Agent::LoadModelResult load_model = sim.agent->LoadModel();
...
}
```
Would love to hear your thoughts! Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.