-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from theovincent/clean_exp
Clean exp
- Loading branch information
Showing
209 changed files
with
8,595 additions
and
13,993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
colors = { | ||
"LSPI": "#984ea3", | ||
"FQI": "#e41a1c", | ||
"DQN": "#e41a1c", | ||
"ProFQI": "#4daf4a", | ||
"ProDQN": "#4daf4a", | ||
"blue": "#377eb8", | ||
"orange": "#ff7f00", | ||
"pink": "#f781bf", | ||
"brown": "#a65628", | ||
"grey": "#999999", | ||
"yellow": "#dede00", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import sys | ||
import argparse | ||
import json | ||
import jax | ||
|
||
from experiments.base.parser import addparse | ||
from experiments.base.print import print_info | ||
|
||
|
||
def run_cli(argvs=sys.argv[1:]): | ||
import warnings | ||
|
||
warnings.simplefilter(action="ignore", category=FutureWarning) | ||
|
||
parser = argparse.ArgumentParser("Train DQN on Acrobot.") | ||
addparse(parser, seed=True) | ||
args = parser.parse_args(argvs) | ||
print_info(args.experiment_name, "DQN", "Acrobot", args.max_bellman_iterations, args.seed) | ||
p = json.load(open(f"experiments/acrobot/figures/{args.experiment_name}/parameters.json")) # p for parameters | ||
|
||
from experiments.acrobot.utils import ( | ||
define_environment, | ||
define_q, | ||
collect_random_samples, | ||
collect_samples, | ||
generate_keys, | ||
) | ||
from pbo.sample_collection.replay_buffer import ReplayBuffer | ||
from experiments.base.DQN import train | ||
|
||
sample_key, exploration_key, q_key, _ = generate_keys(args.seed) | ||
|
||
env = define_environment(jax.random.PRNGKey(p["env_seed"]), p["gamma"]) | ||
replay_buffer = ReplayBuffer(p["max_size"]) | ||
collect_random_samples(env, sample_key, replay_buffer, p["n_initial_samples"], p["horizon"]) | ||
q = define_q( | ||
env.actions_on_max, | ||
p["gamma"], | ||
q_key, | ||
p["layers_dimension"], | ||
learning_rate={ | ||
"first": p["starting_lr_dqn"], | ||
"last": p["ending_lr_dqn"], | ||
"duration": args.max_bellman_iterations * p["fitting_steps_dqn"], | ||
}, | ||
) | ||
|
||
train("acrobot", args, q, p, exploration_key, sample_key, replay_buffer, collect_samples, env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import sys | ||
import argparse | ||
import multiprocessing | ||
import json | ||
import jax | ||
import jax.numpy as jnp | ||
import numpy as np | ||
|
||
from experiments.base.parser import addparse | ||
from experiments.base.print import print_info | ||
|
||
|
||
def run_cli(argvs=sys.argv[1:]): | ||
with jax.default_device(jax.devices("cpu")[0]): | ||
import warnings | ||
|
||
warnings.simplefilter(action="ignore", category=FutureWarning) | ||
|
||
parser = argparse.ArgumentParser("Evaluate a DQN on Acrobot.") | ||
addparse(parser, seed=True) | ||
args = parser.parse_args(argvs) | ||
print_info(args.experiment_name, "DQN", "Acrobot", args.max_bellman_iterations, args.seed, train=False) | ||
p = json.load(open(f"experiments/acrobot/figures/{args.experiment_name}/parameters.json")) # p for parameters | ||
|
||
from experiments.acrobot.utils import define_environment, define_q | ||
from pbo.networks.learnable_q import FullyConnectedQ | ||
from pbo.utils.params import load_params | ||
|
||
env = define_environment(jax.random.PRNGKey(p["env_seed"]), p["gamma_evaluation"]) | ||
|
||
q = define_q(env.actions_on_max, p["gamma"], jax.random.PRNGKey(0), p["layers_dimension"]) | ||
iterated_params = load_params( | ||
f"experiments/acrobot/figures/{args.experiment_name}/DQN/{args.max_bellman_iterations}_P_{args.seed}" | ||
) | ||
|
||
def evaluate(iteration: int, j_list: list, q: FullyConnectedQ, q_weights: jnp.ndarray, horizon: int): | ||
j_list[iteration] = env.evaluate( | ||
q, | ||
q.to_params(q_weights), | ||
horizon, | ||
p["n_simulations"], | ||
video_path=f"{args.experiment_name}/DQN/{iteration}_{args.seed}", | ||
) | ||
|
||
manager = multiprocessing.Manager() | ||
iterated_j = manager.list(list(np.nan * np.zeros(args.max_bellman_iterations + 1))) | ||
|
||
processes = [] | ||
for iteration in range(args.max_bellman_iterations + 1): | ||
processes.append( | ||
multiprocessing.Process( | ||
target=evaluate, | ||
args=( | ||
iteration, | ||
iterated_j, | ||
q, | ||
q.to_weights(iterated_params[f"{iteration}"]), | ||
p["horizon_evaluation"], | ||
), | ||
) | ||
) | ||
|
||
for process in processes: | ||
process.start() | ||
|
||
for process in processes: | ||
process.join() | ||
|
||
np.save( | ||
f"experiments/acrobot/figures/{args.experiment_name}/DQN/{args.max_bellman_iterations}_J_{args.seed}.npy", | ||
iterated_j, | ||
) |
Oops, something went wrong.