-
Notifications
You must be signed in to change notification settings - Fork 1
/
visualize.py
72 lines (61 loc) · 1.78 KB
/
visualize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from pathlib import Path
import argparse
import jax.numpy as jnp
import jax.random as jrd
import wandb
from gene.visualize.visualize_brax import visualize_brax, render_brax
from gene.core.models import get_model
from gene.core.distances import Distance_functions
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="Brax Visualization",
description="Performs the evaluation of a learned policy genome by \
retrieving it from weights and biases.",
)
parser.add_argument(
"-p",
"--project",
type=str,
default="Brax expe bench test",
help="Name of the wandb project",
)
parser.add_argument(
"-r",
"--run_id",
type=str,
default="6k8oolw0",
help="identifier of the wandb run.",
)
parser.add_argument(
"-f",
"--file",
type=str,
default="final_best_indiv.npy",
help="File to retrieve from wandb previously defined run.",
)
parser.add_argument(
"--rng",
type=int,
default=0,
help="RNG key used to re-evaluate the genome.",
)
args = parser.parse_args()
run_id = f"arxaqapi/{args.project}/{args.run_id}"
genome_id = args.file
api = wandb.Api()
run = api.run(run_id)
config = run.config
with open(run.file(f"genomes/{genome_id}").download(replace=True).name, "rb") as f:
genome = jnp.load(f)
path = Path("html")
path.mkdir(exist_ok=True)
render_brax(
path / f"run_{run_id.split('/')[-1]}_{genome_id[:-4]}",
*visualize_brax(
config,
genome,
model=get_model(config),
df=Distance_functions[config["encoding"]["distance"]](),
rng=jrd.PRNGKey(args.rng),
),
)