Skip to content

Commit

Permalink
Refactor code to use DataManagerSingleton for data retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptualrobots committed Aug 24, 2024
1 parent e29c5be commit ce1231a
Show file tree
Hide file tree
Showing 7 changed files with 518 additions and 274 deletions.
68 changes: 25 additions & 43 deletions nbs/05_environments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"from pct.webots import WebotsHelper\n",
"# from pct.yaw_module import YawEnv\n",
"from pct.arc import ARCEnv\n",
"from pct.helpers import ListChecker, ChallengesDataManager"
"from pct.helpers import ListChecker, DataManagerSingleton"
]
},
{
Expand Down Expand Up @@ -1558,9 +1558,12 @@
"\n",
" def set_properties(self, props: dict) -> None:\n",
"\n",
" data = props['data']\n",
" # data = props['data']\n",
"\n",
" data_mgr = DataManagerSingleton.get_instance(folder = 'c:/tmp/arc-prize-2024', prefix = 'arc-agi_simple_', show_timing=True)\n",
" data = data_mgr.get_data_for_code(props['code'])\n",
" props['test_output_array'] = data_mgr.get_solutions_for_code(props['code'])\n",
"\n",
" # props['data']=data\n",
" self.env.initialise(props, data)\n",
" self.fitness = self.env.fitness\n",
" self.history = props.get('history', 5)\n",
Expand Down Expand Up @@ -1667,7 +1670,6 @@
" self.done, details = ListChecker.check_list_unchanged(self.boxcar, rel_tol =get_rel_tol('ARC-change'), abs_tol=get_abs_tol('ARC-change'), gradient_abs_tol=get_abs_tol('ARC-gradient'))\n",
" if self.done:\n",
" self.env.add_to_gradient_list(details['gradient_range']) \n",
" # self.env.fitness_isclose_to_zero = ListChecker.check_float_list_close_to_zero(self.boxcar, rel_tol = 0, abs_tol=get_abs_tol('ARC-zero'), gradient_abs_tol=get_abs_tol('ARC-gradient'))\n",
"\n",
" if self.done:\n",
" self.env.add_to_fitness_list(max(self.boxcar) )\n",
Expand Down Expand Up @@ -1747,51 +1749,31 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'num_actions': 1, 'grid_shape': 'equal', 'dims': 1}\n",
"ARC ARC | [4] | links constant \n",
"ARC ARC | [5] | links constant \n",
"ARC ARC | [6] | links constant \n",
"ARC ARC | [7] | links constant \n",
"ARC ARC | [8] | links constant \n",
"ARC ARC | [9] | links constant \n",
"{'type': 'ARC', 'name': 'ARC', 'value': [9], 'links': {0: 'constant'}, 'env_name': 'ARC'}\n",
"\n",
"1.000 \n",
"9.000 0 True {'num_actions': 1, 'grid_shape': 'equal', 'dims': 1}\n",
"\n",
"[9]\n"
]
}
],
"outputs": [],
"source": [
"#| gui\n",
"env = ARC()\n",
"env.add_link(Constant(1))\n",
"# env.add_link(Constant(0))\n",
"properties = { 'dir': 'C:\\\\packages\\\\arc-prize-2024', 'file_prefix':'arc-agi_training_', 'code':'007bbfb7', 'dataset': 'train', 'control_set': ['dims'], 'input_set': ['env']}\n",
"file_name = os.path.join(properties['dir'], properties['file_prefix']) + 'challenges.json' \n",
"challenges_manager = ChallengesDataManager(file_name)\n",
"data = challenges_manager.get_data_for_key(properties['code'])\n",
"properties['data']=data\n",
"\n",
"env.set_properties(properties)\n",
"env.set_render(True)\n",
"env.reset()\n",
"print(env.env.info)\n",
"for i in range(6):\n",
" state = env()\n",
" env.summary() \n",
" # print()\n",
"print(env.get_config())\n",
"print()\n",
"print(env.output_string()) \n",
"print()\n",
"print(state)\n",
"# file_name = os.path.join(properties['dir'], properties['file_prefix']) + 'challenges.json' \n",
"# challenges_manager = ChallengesDataManager(file_name)\n",
"# data = challenges_manager.get_data_for_key(properties['code'])\n",
"# properties['data']=data\n",
"\n",
"# env.set_properties(properties)\n",
"# env.set_render(True)\n",
"# env.reset()\n",
"# print(env.env.info)\n",
"# for i in range(6):\n",
"# state = env()\n",
"# env.summary() \n",
"# # print()\n",
"# print(env.get_config())\n",
"# print()\n",
"# print(env.output_string()) \n",
"# print()\n",
"# print(state)\n",
"\n",
"# env.close()"
]
Expand Down
Loading

0 comments on commit ce1231a

Please sign in to comment.