11"""
2- Support for gymnax is experimental and mainly meant to test the already_vectorized
3- env API used by XLand MiniGrid (an unsolved environment) with classic gym envs.
2+ Support for gymnax is experimental and mainly meant to test the already_vectorized
3+ env API used by XLand MiniGrid (an unsolved environment) with classic gym envs.
44Many of the gymnax envs appear to be broken by recent versions of jax.
55There are a couple memory/meta-RL bsuite envs where AMAGO+Transformer
66is significantly better than the gymnax reference scores though.
2424from amago .envs import AMAGOEnv
2525from amago .envs .builtin .gymnax_envs import GymnaxCompatibility
2626from amago .nets .cnn import GridworldCNN
27- from amago . cli_utils import *
27+ from amago import cli_utils
2828
2929
3030def add_cli (parser ):
@@ -52,7 +52,7 @@ def guess_tstep_encoder(config, obs_shape):
5252 if len (obs_shape ) == 3 :
5353 print (f"Guessing CNN for observation of shape { obs_shape } " )
5454 channels_first = np .argmin (obs_shape ).item () == 0
55- return switch_tstep_encoder (
55+ return cli_utils . switch_tstep_encoder (
5656 config ,
5757 "cnn" ,
5858 cnn_type = GridworldCNN ,
@@ -61,7 +61,7 @@ def guess_tstep_encoder(config, obs_shape):
6161 else :
6262 print (f"Guessing MLP for observation of shape { obs_shape } " )
6363 dim = math .prod (obs_shape ) # FFTstepEncoder will flatten the obs on input
64- return switch_tstep_encoder (
64+ return cli_utils . switch_tstep_encoder (
6565 config ,
6666 "ff" ,
6767 d_hidden = max (dim // 3 , 128 ),
@@ -72,7 +72,7 @@ def guess_tstep_encoder(config, obs_shape):
7272
7373if __name__ == "__main__" :
7474 parser = ArgumentParser ()
75- add_common_cli (parser )
75+ cli_utils . add_common_cli (parser )
7676 add_cli (parser )
7777 args = parser .parse_args ()
7878
@@ -81,7 +81,7 @@ def guess_tstep_encoder(config, obs_shape):
8181
8282 # config
8383 config = {}
84- traj_encoder_type = switch_traj_encoder (
84+ traj_encoder_type = cli_utils . switch_traj_encoder (
8585 config ,
8686 arch = args .traj_encoder ,
8787 memory_size = args .memory_size ,
@@ -91,16 +91,16 @@ def guess_tstep_encoder(config, obs_shape):
9191 test_env , env_params = gymnax .make (args .env )
9292 test_obs_shape = test_env .observation_space (env_params ).shape
9393 tstep_encoder_type = guess_tstep_encoder (config , test_obs_shape )
94- agent_type = switch_agent (config , args .agent_type )
94+ agent_type = cli_utils . switch_agent (config , args .agent_type )
9595
96- use_config (config , args .configs )
96+ cli_utils . use_config (config , args .configs )
9797 make_env = partial (
9898 make_gymnax_amago , env_name = args .env , parallel_envs = args .parallel_actors
9999 )
100100 group_name = f"{ args .run_name } _{ args .env } "
101101 for trial in range (args .trials ):
102102 run_name = group_name + f"_trial_{ trial } "
103- experiment = create_experiment_from_cli (
103+ experiment = cli_utils . create_experiment_from_cli (
104104 args ,
105105 make_train_env = make_env ,
106106 make_val_env = make_env ,
@@ -116,7 +116,7 @@ def guess_tstep_encoder(config, obs_shape):
116116 l2_coeff = 1e-4 ,
117117 save_trajs_as = "npz-compressed" ,
118118 )
119- experiment = switch_async_mode (experiment , args .mode )
119+ experiment = cli_utils . switch_async_mode (experiment , args .mode )
120120 amago_device = experiment .DEVICE .index or torch .cuda .current_device ()
121121 env_device = jax .devices ("gpu" )[amago_device ]
122122 with jax .default_device (env_device ):
0 commit comments