Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d36deef
added base coord class
fhtanaka Feb 1, 2023
d7c2b95
organized nodes
fhtanaka Feb 1, 2023
fefc499
updated task list with more information
fhtanaka Feb 1, 2023
5df0ce9
typing for tasks
fhtanaka Feb 1, 2023
9440e40
typing for tasks pt2
fhtanaka Feb 1, 2023
a0989f0
config reproduction to have unique ids between all pops
fhtanaka Feb 2, 2023
c0c2f7c
base grid working
fhtanaka Feb 3, 2023
4bde899
simple test
fhtanaka Feb 3, 2023
41dbbb9
changed strategy, now population in coordinates share the same conn a…
fhtanaka Feb 7, 2023
6667e98
added notebook to visualize results and cleaner of sgr pop
fhtanaka Feb 8, 2023
e49515d
fix initial pop ids
fhtanaka Feb 8, 2023
c59daee
added grid creator
fhtanaka Feb 8, 2023
c3ffd1a
locomotion env and common obs
fhtanaka Feb 9, 2023
5768d76
locomotion results
Feb 10, 2023
03b171c
fixed gambiarra and created new visualization
fhtanaka Feb 10, 2023
340dcd7
manipulation task
fhtanaka Feb 10, 2023
d15c531
manipulation task fix
fhtanaka Feb 10, 2023
f1fc11c
manipulation test results
Feb 13, 2023
aea5a6c
reformulated the main
fhtanaka Feb 13, 2023
4317102
removed cps
fhtanaka Feb 13, 2023
156a1ae
new locomotion results
Feb 14, 2023
9b09174
new snk test
fhtanaka Feb 14, 2023
112d10f
snk results
Feb 15, 2023
d0ac9d7
deepcopy when neighbor and saving genome dict
fhtanaka Feb 15, 2023
08b3d57
generate gif file
fhtanaka Feb 16, 2023
d3cd18d
preparing for new tests
Feb 16, 2023
08ed5d9
new test
fhtanaka Feb 16, 2023
1723903
forgot to add files from main path for test
fhtanaka Feb 16, 2023
663afaf
fixes
Feb 16, 2023
78b87b5
better image generator
fhtanaka Feb 19, 2023
8a936ce
new tests
Feb 20, 2023
5a77890
merge
Feb 20, 2023
fefacc2
new image generator
fhtanaka Feb 20, 2023
76843dd
new image generator
fhtanaka Feb 22, 2023
d143122
new caption
Feb 22, 2023
cdcd628
merge
Feb 22, 2023
8d578ad
new tests with higher speciation thrshold
Feb 24, 2023
39256e8
genetic tree generator
fhtanaka Feb 25, 2023
b44d24e
trying to fix skip evaluated and new 3k test
Feb 28, 2023
81efe63
Merge branch 'alife23' of https://github.com/fhtanaka/SGR into alife23
Feb 28, 2023
42feaa6
fix
Mar 1, 2023
c7b30c5
better notebook
fhtanaka Mar 1, 2023
60378df
Merge branch 'alife23' of github.com:fhtanaka/SGR into alife23
fhtanaka Mar 1, 2023
c8f7e04
new scripts for testing
Mar 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,7 @@ dynamic_env/*.json
checkpoints/*
.vscode
*.txt
multiple_env_results/
multiple_env_results/
cp_*.pkl
island_cp/*
island_cp_v2/*
13 changes: 12 additions & 1 deletion arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def default_values():
"spec_genotype_weight": .8,
"spec_phenotype_weight": 5,
"substrate_type": "cppn",
"seed": 1997,

# used for POET, not required
"height_mutation_chance": 0.35,
Expand All @@ -35,6 +36,9 @@ def default_values():
"create_frequency": 49,
"p_transfer_frequency": 10,
"d_transfer_frequency": 27,

# used for grid_world]
"task_grid": "grid_world/grids/config.json",
}

return default
Expand Down Expand Up @@ -68,9 +72,11 @@ def create_parser(default_args):
parser.add_argument("--max_pair_population_size", nargs="?", default=default_args["max_pair_population_size"], help="", type=int)
parser.add_argument("--n_nearest_neighbors", nargs="?", default=default_args["n_nearest_neighbors"], help="", type=int)
parser.add_argument("--p_transfer_gens", nargs="?", default=default_args["p_transfer_gens"], help="", type=int)
parser.add_argument("--seed", nargs="?", default=default_args["seed"], help="", type=int)

parser.add_argument("--p_transfer_frequency", nargs="?", default=default_args["p_transfer_frequency"], help="", type=int)
parser.add_argument("--d_transfer_frequency", nargs="?", default=default_args["d_transfer_frequency"], help="", type=int)
parser.add_argument("--task_grid", nargs="?", default=default_args["task_grid"], help="", type=str)

return parser

Expand All @@ -89,7 +95,6 @@ def parse_args():
with open(path, 'r', encoding='utf-8') as f:
file_args = json.load(f)
for k, v in file_args.items():
print(k, v)
default_args[k] = v

# "real" parser to get the values from the command line that have priority over the
Expand All @@ -111,6 +116,7 @@ def parse_args():
args_dict["spec_genotype_weight"] = command_line_args.spec_genotype_weight
args_dict["spec_phenotype_weight"] = command_line_args.spec_phenotype_weight
args_dict["substrate_type"] = command_line_args.substrate
args_dict["seed"] = command_line_args.seed

args_dict["height_mutation_chance"] = command_line_args.height_mutation_chance
args_dict["max_height_mutation"] = command_line_args.max_height_mutation
Expand All @@ -127,6 +133,8 @@ def parse_args():
args_dict["p_transfer_frequency"] = command_line_args.p_transfer_frequency
args_dict["d_transfer_frequency"] = command_line_args.d_transfer_frequency

args_dict["task_grid"] = command_line_args.task_grid

return Parameters(args_dict)

class Parameters:
Expand All @@ -145,6 +153,7 @@ def __init__(self, args_dict):
self.spec_genotype_weight = args_dict["spec_genotype_weight"]
self.spec_phenotype_weight = args_dict["spec_phenotype_weight"]
self.substrate_type = args_dict["substrate_type"]
self.seed = args_dict["seed"]

self.p_transfer_gens = args_dict["p_transfer_gens"]
self.height_mutation_chance = args_dict["height_mutation_chance"]
Expand All @@ -161,6 +170,8 @@ def __init__(self, args_dict):

self.p_transfer_frequency = args_dict["p_transfer_frequency"]
self.d_transfer_frequency = args_dict["d_transfer_frequency"]

self.task_grid = args_dict["task_grid"]
# if report is not None:
for k, v in args_dict.items():
print(f"{k}: {v}")
Expand Down
17 changes: 17 additions & 0 deletions configs/grid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"gens": 3001,
"robot_size": 5,
"steps": 600,
"n_threads": 12,
"save_to": "",
"goal_fit": 10,
"pop_size": 5,
"max_stag": 100,
"neat_config": "neat_configs/grid_v2.cfg",
"save_gen_interval": 10,
"spec_genotype_weight": 1,
"spec_phenotype_weight": 2,
"substrate_type": "3d",
"task_grid": "grid_world/grids/locomotion.json"
}

19 changes: 19 additions & 0 deletions generate_img.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# declare -a arr=("locomotion_3d" "locomotion_cppn" "snk_3d" "snk_cppn" "random_loc_3d" "random_loc_cppn" "snk_3d_2" "snk_cppn_2" "random_loc_3d_2" "random_loc_cppn_2")

# Set the directory path
dir_path="$1"

# Loop over the files in the directory
for dir in "${@:2}"
do
for file in "${dir_path}/${dir}"/*.pkl
do
# Check if the file is a regular file
if [[ -f "$file" ]]; then
# Call the Python function with the file as an argument
python generate_imgs.py "${file}"
fi
done
done
40 changes: 40 additions & 0 deletions generate_imgs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pickle as pkl
import os
from grid_world.graph import Graph
import sys

def main(file_path):
print(file_path)
results_dir, test_dir, file_name = file_path.split("/")
if "pkl" not in file_path:
print("Not a pkl file")
return

file_name = file_name.split(".")[0]
p1, p2, test_number = file_name.split("_")
test_number = test_number.zfill(4)
img_name = f"{p1}_{p2}_{test_number}"

if os.path.exists(f"{results_dir}/{test_dir}/{img_name}.jpeg"):
print("Image already exists")
return

try:
with open(file_path, "rb") as file:
grid: Graph = pkl.load(file)
except:
print("Couldnt open the pkl")
return

n_rows, n_cols = 6, 6
if "locomotion" in file_path:
n_rows, n_cols = 4, 4

grid.save_grid_img(n_rows, n_cols, img_name+ ".jpeg", img_name.replace("_", " "))


if __name__ == "__main__":
file_path = sys.argv[1]
# print(file_path)
main(file_path)
print()
19 changes: 19 additions & 0 deletions grid_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import json
from arg_parser import parse_args
from sgr.sgr import SGR
from grid_world.graph import Graph
import pickle

def main():
params = parse_args()
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, params.neat_config)

graph = Graph(seed=params.seed, params=params)
graph.interpret_json(params.task_grid, config_path)

graph.evolve_random_coords(params.gens)

if __name__ == "__main__":
main()
Empty file added grid_world/__init__.py
Empty file.
Binary file added grid_world/arial.ttf
Binary file not shown.
94 changes: 94 additions & 0 deletions grid_world/create_grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import json
from tasks import Task
import numpy as np
def locomotion_task():
def task_func(x, y):
aux = y%4
if aux == 1:
return "UpStepper-v0"
elif aux == 2:
return "Hurdler-v0"
return "Walker-v0"

create_base_grid(size=(4,4), file_name="./locomotion.json", task_function=task_func)

def manipulation_task():
def task_func(x, y):
aux = y%4
if aux == 1:
return "Thrower-v0"
elif aux == 2:
return "Carrier-v1"
return "Carrier-v0"

create_base_grid(file_name="./manipulation.json", task_function=task_func)

def snk_task():
def task_func(x, y):
if x == 1 and y != 0 and y != 5:
return "ObstacleTraverser-v1"
elif x == 4 and y != 0 and y != 5:
return "ObstacleTraverser-v1"
elif y == 1 and x != 0 and x != 5:
return "ObstacleTraverser-v1"
elif y == 4 and x != 0 and x != 5:
return "ObstacleTraverser-v1"
return "ObstacleTraverser-v0"
create_base_grid(size=(6,6), file_name="./snk.json", task_function=task_func)

def random_locomotion_task():

possible_tasks = [
"Walker-v0",
"BridgeWalker-v0",
"UpStepper-v0",
"DownStepper-v0",
"ObstacleTraverser-v0",
"ObstacleTraverser-v1",
"Hurdler-v0",
"PlatformJumper-v0",
"GapJumper-v0",
]
def task_func(x, y):
task = np.random.choice(possible_tasks, 1)[0]
print(task)
return task
create_base_grid(size=(6,6), file_name="./random_loc.json", task_function=task_func)

def create_base_grid(size=(4,4), file_name="./temp.json", task_function=None):
x, y = size

grid = []
for i in range(x):
grid.append([])
for j in range(y):
grid[i].append(j + i*y)

for i in grid:
print(i)

json_grid = {}
for i in range(x):
for j in range(y):
value = {
"neighbors":[]
}
if task_function != None:
value["task"] = task_function(i, j)
print(i, j, value["task"])
else:
value["task"] = "Walker-v0"

for i2 in range(i-1, i+2):
for j2 in range(j-1, j+2):
if i2 < 0 or i2 >= x or j2 < 0 or j2 >= y or grid[i2][j2] == grid[i][j]:
continue
value["neighbors"].append(grid[i2][j2])

json_grid[grid[i][j]] = value

with open(file_name, 'w') as f:
json.dump(json_grid, f, indent = 4, ensure_ascii = False)

if __name__ == "__main__":
random_locomotion_task()
Loading