Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptualrobots committed Aug 6, 2024
1 parent 5804969 commit 2a42ecf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions nbs/01_putils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@
"#| export\n",
"def get_abs_tol(key):\n",
" # dic = {'evolve': 0.01, 'ARC-evolve' : 0.01, 'ARC-display': 0.01, 'ARC': 0.01}\n",
" dic = { 'ARC-evolve' : 0.001, 'ARC-display': 0.1, 'ARC': 0.01, 'ARC-change' : 1e-2}\n",
" dic = { 'ARC-evolve' : 0.01, 'ARC-display': 0.1, 'ARC': 0.01, 'ARC-change' : 1e-2}\n",
"\n",
" # if key in dic:\n",
" return dic[key]\n",
Expand All @@ -902,7 +902,7 @@
"source": [
"#| export\n",
"def get_rel_tol(key):\n",
" dic = { 'ARC-change' : 1e-2}\n",
" dic = { 'ARC-change' : 1e-3}\n",
"\n",
" # if key in dic:\n",
" return dic[key]\n",
Expand Down
12 changes: 8 additions & 4 deletions nbs/05_environments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"outputs": [],
"source": [
"#| export\n",
"import gym, json, math, os\n",
"import gym, math, os\n",
"import numpy as np\n",
"from abc import abstractmethod\n",
"from typing import Any, List, Optional"
Expand All @@ -54,7 +54,7 @@
"#| export\n",
"import pct.putils as vid\n",
"from pct.functions import BaseFunction, Constant\n",
"from pct.putils import FunctionsList, SingletonObjects, NumberStats, map_to_int_even_range, map_to_int_odd_range, get_rel_tol\n",
"from pct.putils import FunctionsList, SingletonObjects, NumberStats, map_to_int_even_range, map_to_int_odd_range, get_rel_tol, get_abs_tol\n",
"from pct.network import ClientConnectionManager\n",
"from pct.webots import WebotsHelper\n",
"from pct.yaw_module import YawEnv\n",
Expand Down Expand Up @@ -1580,6 +1580,7 @@
" def early_terminate(self) -> None:\n",
" if self.early_termination:\n",
" if self.done:\n",
" self.env_done = False\n",
" if not self.env.next():\n",
" raise Exception(f'1001: Env: {self.env_name} has finished.')\n",
"\n",
Expand All @@ -1598,7 +1599,7 @@
"\n",
" def parse_obs(self) -> None:\n",
" self.fitness = self.obs[1]\n",
" self.done = self.obs[2]\n",
" self.env_done = self.obs[2]\n",
" self.info = self.obs[3]\n",
" self.add_to_fitness_history(self.fitness)\n",
"\n",
Expand Down Expand Up @@ -1634,7 +1635,10 @@
"\n",
" self.boxcar.append(fitness)\n",
" self.boxcar.pop(0)\n",
" self.done, details = ListChecker.check_list_unchanged(self.boxcar, rel_tol =get_rel_tol('ARC-change'), abs_tol=0)\n",
" if self.env_done:\n",
" self.done = self.env_done\n",
" else:\n",
" self.done, details = ListChecker.check_list_unchanged(self.boxcar, rel_tol =get_rel_tol('ARC-change'), abs_tol=get_abs_tol('ARC-change'))\n",
" pass\n",
"\n",
" def get_fitness_list(self):\n",
Expand Down
1 change: 1 addition & 0 deletions pct/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def next(self):
return False
if self.initial_index is not None:
return False
print('index', self.index)
self.create_env()
return True

Expand Down
12 changes: 8 additions & 4 deletions pct/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
'WebotsWrestlerSupervisor', 'Bridge', 'MicroGrid', 'ARC']

# %% ../nbs/05_environments.ipynb 3
import gym, json, math, os
import gym, math, os
import numpy as np
from abc import abstractmethod
from typing import Any, List, Optional

# %% ../nbs/05_environments.ipynb 4
import pct.putils as vid
from .functions import BaseFunction, Constant
from .putils import FunctionsList, SingletonObjects, NumberStats, map_to_int_even_range, map_to_int_odd_range, get_rel_tol
from .putils import FunctionsList, SingletonObjects, NumberStats, map_to_int_even_range, map_to_int_odd_range, get_rel_tol, get_abs_tol
from .network import ClientConnectionManager
from .webots import WebotsHelper
from .yaw_module import YawEnv
Expand Down Expand Up @@ -1331,6 +1331,7 @@ def get_env_inputs_indexes(self):
def early_terminate(self) -> None:
if self.early_termination:
if self.done:
self.env_done = False
if not self.env.next():
raise Exception(f'1001: Env: {self.env_name} has finished.')

Expand All @@ -1349,7 +1350,7 @@ def apply_actions_get_obs(self) -> Any:

def parse_obs(self) -> None:
self.fitness = self.obs[1]
self.done = self.obs[2]
self.env_done = self.obs[2]
self.info = self.obs[3]
self.add_to_fitness_history(self.fitness)

Expand Down Expand Up @@ -1385,7 +1386,10 @@ def add_to_fitness_history(self, fitness):

self.boxcar.append(fitness)
self.boxcar.pop(0)
self.done, details = ListChecker.check_list_unchanged(self.boxcar, rel_tol =get_rel_tol('ARC-change'), abs_tol=0)
if self.env_done:
self.done = self.env_done
else:
self.done, details = ListChecker.check_list_unchanged(self.boxcar, rel_tol =get_rel_tol('ARC-change'), abs_tol=get_abs_tol('ARC-change'))
pass

def get_fitness_list(self):
Expand Down
4 changes: 2 additions & 2 deletions pct/putils.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def clip_value(val, range):
# %% ../nbs/01_putils.ipynb 43
def get_abs_tol(key):
# dic = {'evolve': 0.01, 'ARC-evolve' : 0.01, 'ARC-display': 0.01, 'ARC': 0.01}
dic = { 'ARC-evolve' : 0.001, 'ARC-display': 0.1, 'ARC': 0.01, 'ARC-change' : 1e-2}
dic = { 'ARC-evolve' : 0.01, 'ARC-display': 0.1, 'ARC': 0.01, 'ARC-change' : 1e-2}

# if key in dic:
return dic[key]
Expand All @@ -513,7 +513,7 @@ def get_abs_tol(key):

# %% ../nbs/01_putils.ipynb 44
def get_rel_tol(key):
dic = { 'ARC-change' : 1e-2}
dic = { 'ARC-change' : 1e-3}

# if key in dic:
return dic[key]
Expand Down

0 comments on commit 2a42ecf

Please sign in to comment.