MCPcopy Create free account
hub / github.com/LeCAR-Lab/model-based-diffusion / run_path_integral

Function run_path_integral

mbd/planners/path_integral.py:55–148  ·  view source on GitHub ↗
(args: Args)

Source from the content-addressed store, hash-verified

53
54
55def run_path_integral(args: Args):
56
57 rng = jax.random.PRNGKey(seed=args.seed)
58
59 update_fn = {
60 "mppi": softmax_update,
61 "cma-es": cma_es_update,
62 "cem": cem_update,
63 }[args.update_method]
64
65 ## setup env
66
67 # recommended temperature for envs
68 temp_recommend = {
69 "ant": 0.1,
70 "halfcheetah": 0.4,
71 "hopper": 0.1,
72 "humanoidstandup": 0.1,
73 "humanoidrun": 0.1,
74 "walker2d": 0.1,
75 "pushT": 0.2,
76 }
77 Nrefine_recommend = {
78 "pushT": 200,
79 "humanoidrun": 300,
80 }
81 Nsample_recommend = {
82 "humanoidrun": 8192,
83 }
84 Hsample_recommend = {
85 "pushT": 40,
86 }
87 if not args.disable_recommended_params:
88 args.temp_sample = temp_recommend.get(args.env_name, args.temp_sample)
89 args.Nrefine = Nrefine_recommend.get(args.env_name, args.Nrefine)
90 args.Nsample = Nsample_recommend.get(args.env_name, args.Nsample)
91 args.Hsample = Hsample_recommend.get(args.env_name, args.Hsample)
92 print(f"override temp_sample to {args.temp_sample}")
93 env = mbd.envs.get_env(args.env_name)
94 Nx = env.observation_size
95 Nu = env.action_size
96 # env functions
97 step_env_jit = jax.jit(env.step)
98 reset_env_jit = jax.jit(env.reset)
99 eval_us = jax.jit(functools.partial(mbd.utils.eval_us, step_env_jit))
100 render_us = functools.partial(
101 mbd.utils.render_us, step_env_jit, env.sys.replace(dt=env.dt)
102 )
103
104 rng, rng_reset = jax.random.split(rng) # NOTE: rng_reset should never be changed.
105 state_init = reset_env_jit(rng_reset)
106
107 ## run path interal
108
109 mu_0T = jnp.zeros([args.Hsample, Nu])
110
111 @jax.jit
112 def update_once(carry, unused):

Callers 1

path_integral.pyFile · 0.85

Calls 2

updateFunction · 0.85
eval_usFunction · 0.85

Tested by

no test coverage detected