def test_many_sims_rendering(): model = load_model_from_xml(BASIC_MODEL_XML) sims = [MjSim(model) for _ in range(5)] pool = MjSimPool(sims) pool.forward() for sim in sims: img, depth = sim.render(200, 200, depth=True) assert img.shape == (200, 200, 3) compare_imgs(img, 'test_rendering.freecam.png')
def test_mj_sim_pool_basics(): model = load_model_from_xml(BASIC_MODEL_XML) sims = [MjSim(model) for _ in range(2)] sim_pool = MjSimPool(sims, nsubsteps=2) sim_pool.reset() sim_pool.step() sim_pool.forward()
def test_mj_sim_pool_buffers(): model = load_model_from_xml(BASIC_MODEL_XML) foo = 10 def udd_callback(sim): return {"foo": foo} sims = [MjSim(model, udd_callback=udd_callback) for _ in range(2)] sim_pool = MjSimPool(sims, nsubsteps=2) for i in range(len(sim_pool.sims)): assert(sim_pool.sims[i].udd_state is not None) assert(sim_pool.sims[i].udd_state["foo"] == 10) foo = 11 sim_pool.step() for i in range(len(sim_pool.sims)): assert(sim_pool.sims[i].udd_state is not None) assert(sim_pool.sims[i].udd_state["foo"] == 11)
<worldbody> <body name="box" pos="0 0 0.2"> <geom size="0.15 0.15 0.15" type="box"/> <joint axis="1 0 0" name="box:x" type="slide"/> <joint axis="0 1 0" name="box:y" type="slide"/> </body> <body name="floor" pos="0 0 0.025"> <geom size="1.0 1.0 0.02" rgba="0 1 0 1" type="box"/> </body> </worldbody> <actuator> <motor gear="2000.0" joint="box:x"/> <motor gear="2000.0" joint="box:y"/> </actuator> </mujoco> """ model = load_model_from_xml(MODEL_XML) pool = MjSimPool([MjSim(model) for _ in range(20)]) for i, sim in enumerate(pool.sims): sim.data.qpos[:] = 0.0 sim.data.qvel[:] = 0.0 sim.data.ctrl[:] = i # Advance all 20 simulations 100 times. for _ in range(100): pool.step() for i, sim in enumerate(pool.sims): print("%d-th sim qpos=%s" % (i, str(sim.data.qpos)))