Stop profiling mju_halton in testspeed and bechmarks.

PiperOrigin-RevId: 490239351
Change-Id: Id73c101672e5b974f16b6b4da3aae757a657de15
This commit is contained in:
Alessio Quaglino
2022-11-22 07:40:06 -08:00
committed by Copybara-Service
parent 165e72f798
commit c17375fa32
4 changed files with 49 additions and 28 deletions
+7 -3
View File
@@ -42,9 +42,13 @@ std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
static void run_step_benchmark(const mjModel* model, benchmark::State& state) {
mjData* data = mj_makeData(model);
// compute noise
int nsteps = kNumWarmupSteps+kNumBenchmarkSteps;
std::vector<mjtNum> ctrl = GetCtrlNoise(model, nsteps);
// warm-up rollout to get a typcal state
for (int i=0; i < kNumWarmupSteps; i++) {
AddCtrlNoise(model, data, i);
mju_copy(data->ctrl, ctrl.data()+model->nu*i, model->nu);
mj_step(model, data);
}
// save state
@@ -60,8 +64,8 @@ static void run_step_benchmark(const mjModel* model, benchmark::State& state) {
mju_copy(data->act, act.data(), model->na);
mju_copy(data->qacc_warmstart, warmstart.data(), model->nv);
for (int i=0; i < kNumBenchmarkSteps; i++) {
AddCtrlNoise(model, data, i+kNumWarmupSteps);
for (int i=kNumWarmupSteps; i < nsteps; i++) {
mju_copy(data->ctrl, ctrl.data()+model->nu*i, model->nu);
mj_step(model, data);
}
}
+15 -10
View File
@@ -134,18 +134,23 @@ const std::string SaveAndReadXml(const mjModel* model) {
return contents;
}
void AddCtrlNoise(const mjModel* m, mjData* d, int step) {
for (int i = 0; i < m->nu; i++) {
mjtNum center = 0.0;
mjtNum radius = 1.0;
mjtNum* range = m->actuator_ctrlrange + 2 * i;
if (m->actuator_ctrllimited[i]) {
center = (range[1] + range[0]) / 2;
radius = (range[1] - range[0]) / 2;
std::vector<mjtNum> GetCtrlNoise(const mjModel* m, int nsteps,
mjtNum ctrlnoise) {
std::vector<mjtNum> ctrl;
for (int step=0; step < nsteps; step++) {
for (int i = 0; i < m->nu; i++) {
mjtNum center = 0.0;
mjtNum radius = 1.0;
mjtNum* range = m->actuator_ctrlrange + 2 * i;
if (m->actuator_ctrllimited[i]) {
center = (range[1] + range[0]) / 2;
radius = (range[1] - range[0]) / 2;
}
radius *= ctrlnoise;
ctrl.push_back(center + radius * (2 * mju_Halton(step, i+2) - 1));
}
radius *= 0.01;
d->ctrl[i] = center + radius * (2 * mju_Halton(step, i + 2) - 1);
}
return ctrl;
}
} // namespace mujoco
+2 -1
View File
@@ -62,7 +62,8 @@ mjModel* LoadModelFromPath(const char* model_path);
const std::string SaveAndReadXml(const mjModel* model);
// Adds control noise.
void AddCtrlNoise(const mjModel* m, mjData* d, int step);
std::vector<mjtNum> GetCtrlNoise(const mjModel* m, int nsteps,
mjtNum ctrlnoise = 0.01);
} // namespace mujoco
#endif // MUJOCO_TEST_FIXTURE_H_