Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptualrobots committed Aug 23, 2023
1 parent 75e3611 commit e58d58a
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 3 deletions.
89 changes: 88 additions & 1 deletion nbs/04_hierarchy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,56 @@
" self.data[key]= list"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"class PCTRunProperties():\n",
" \n",
" # def __init__(self):\n",
" # self.environment_properties = {} \n",
" # self.hpct_structure_properties = {}\n",
" # self.hpct_run_properties = {}\n",
" # self.file_properties = {}\n",
" # self.wrapper_properties = {}\n",
"\n",
" \n",
" def load_db(self, file):\n",
" \"Load properties from file.\"\n",
" from jproperties import Properties\n",
"\n",
" # read properties from file\n",
" configs = Properties()\n",
" #print(file)\n",
" with open(file, 'rb') as config_file:\n",
" configs.load(config_file)\n",
"\n",
" items_view = configs.items()\n",
" self.db = {}\n",
" for item in items_view:\n",
" self.db[item[0]] = item[1].data\n",
"\n",
"\n",
" def get_error_properties(self):\n",
" \"Get properties of error function from loaded properties list of the form propertyn.\"\n",
" error_properties = []\n",
" for property in range(1, 100):\n",
" property_key = f'property{property}'\n",
" if property_key in self.db:\n",
" property_string = self.db[property_key]\n",
" strarr = property_string.split(':')\n",
" if strarr[0] == 'error':\n",
" parr = strarr[1].split(',')\n",
" prop=[]\n",
" prop.append(parr[0])\n",
" prop.append(parr[1])\n",
" error_properties.append(prop)\n",
" return error_properties\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1032,7 +1082,44 @@
"\n",
" score=ind.get_error_collector().error()\n",
" \n",
" return ind, score "
" return ind, score \n",
" \n",
"\n",
"\n",
" @classmethod\n",
" def run_from_file(cls, filename, seed=None, render=False, history=False, move=None, plots=None, hpct_verbose= False, runs=None, outdir=None, early_termination = None):\n",
" \n",
" prp = PCTRunProperties()\n",
" prp.load_db(filename)\n",
"\n",
" error_collector_type = prp.db['error_collector_type'].strip()\n",
" error_response_type = prp.db['error_response_type']\n",
" error_limit = eval(prp.db['error_limit'])\n",
" environment_properties = eval(prp.db['environment_properties'])\n",
" \n",
" error_properties = prp.get_error_properties()\n",
" \n",
" if runs==None:\n",
" runs = eval(prp.db['runs'])\n",
" config = eval(prp.db['config'])\n",
" if seed is None:\n",
" seed = eval(prp.db['seed'])\n",
" print(f'Seed={seed}')\n",
" if early_termination is None:\n",
" early_termination = eval(prp.db['early_termination'])\n",
"\n",
" ind, score = cls.run_from_config(config, min, render=render, error_collector_type=error_collector_type, error_response_type=error_response_type, \n",
" error_properties=error_properties, error_limit=error_limit, steps=runs, hpct_verbose=hpct_verbose, history=history, \n",
" environment_properties=environment_properties, seed=seed, early_termination=early_termination, move=move, plots=plots, \n",
" suffixes=True, plots_dir=outdir)\n",
" \n",
" # ind, score = cls.run_from_config(config, min, render=render, error_collector_type=error_collector_type, error_response_type=error_response_type, \n",
" # error_properties=error_properties, error_limit=error_limit, steps=runs, hpct_verbose=hpct_verbose, history=history, \n",
" # environment_properties=env_props, seed=seed, early_termination=early_termination)\n",
"\n",
" \n",
" return score \n",
"\n"
]
},
{
Expand Down
8 changes: 7 additions & 1 deletion pct/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,8 @@
'pct.hierarchy.PCTHierarchy.run': ('hierarchy.html#pcthierarchy.run', 'pct/hierarchy.py'),
'pct.hierarchy.PCTHierarchy.run_from_config': ( 'hierarchy.html#pcthierarchy.run_from_config',
'pct/hierarchy.py'),
'pct.hierarchy.PCTHierarchy.run_from_file': ( 'hierarchy.html#pcthierarchy.run_from_file',
'pct/hierarchy.py'),
'pct.hierarchy.PCTHierarchy.save': ('hierarchy.html#pcthierarchy.save', 'pct/hierarchy.py'),
'pct.hierarchy.PCTHierarchy.set_error_collector': ( 'hierarchy.html#pcthierarchy.set_error_collector',
'pct/hierarchy.py'),
Expand All @@ -784,7 +786,11 @@
'pct.hierarchy.PCTHierarchy.set_name': ('hierarchy.html#pcthierarchy.set_name', 'pct/hierarchy.py'),
'pct.hierarchy.PCTHierarchy.set_order': ('hierarchy.html#pcthierarchy.set_order', 'pct/hierarchy.py'),
'pct.hierarchy.PCTHierarchy.set_suffixes': ('hierarchy.html#pcthierarchy.set_suffixes', 'pct/hierarchy.py'),
'pct.hierarchy.PCTHierarchy.summary': ('hierarchy.html#pcthierarchy.summary', 'pct/hierarchy.py')},
'pct.hierarchy.PCTHierarchy.summary': ('hierarchy.html#pcthierarchy.summary', 'pct/hierarchy.py'),
'pct.hierarchy.PCTRunProperties': ('hierarchy.html#pctrunproperties', 'pct/hierarchy.py'),
'pct.hierarchy.PCTRunProperties.get_error_properties': ( 'hierarchy.html#pctrunproperties.get_error_properties',
'pct/hierarchy.py'),
'pct.hierarchy.PCTRunProperties.load_db': ('hierarchy.html#pctrunproperties.load_db', 'pct/hierarchy.py')},
'pct.network': { 'pct.network.Client': ('network.html#client', 'pct/network.py'),
'pct.network.Client.__init__': ('network.html#client.__init__', 'pct/network.py'),
'pct.network.Client.close': ('network.html#client.close', 'pct/network.py'),
Expand Down
84 changes: 83 additions & 1 deletion pct/hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/04_hierarchy.ipynb.

# %% auto 0
__all__ = ['FunctionsData', 'PCTHierarchy']
__all__ = ['FunctionsData', 'PCTRunProperties', 'PCTHierarchy']

# %% ../nbs/04_hierarchy.ipynb 4
#import numpy as np
Expand Down Expand Up @@ -43,6 +43,50 @@ def add_list(self, key, list):
self.data[key]= list

# %% ../nbs/04_hierarchy.ipynb 7
class PCTRunProperties():

# def __init__(self):
# self.environment_properties = {}
# self.hpct_structure_properties = {}
# self.hpct_run_properties = {}
# self.file_properties = {}
# self.wrapper_properties = {}


def load_db(self, file):
"Load properties from file."
from jproperties import Properties

# read properties from file
configs = Properties()
#print(file)
with open(file, 'rb') as config_file:
configs.load(config_file)

items_view = configs.items()
self.db = {}
for item in items_view:
self.db[item[0]] = item[1].data


def get_error_properties(self):
"Get properties of error function from loaded properties list of the form propertyn."
error_properties = []
for property in range(1, 100):
property_key = f'property{property}'
if property_key in self.db:
property_string = self.db[property_key]
strarr = property_string.split(':')
if strarr[0] == 'error':
parr = strarr[1].split(',')
prop=[]
prop.append(parr[0])
prop.append(parr[1])
error_properties.append(prop)
return error_properties


# %% ../nbs/04_hierarchy.ipynb 8
class PCTHierarchy():
"A hierarchical perceptual control system, of PCTNodes."
def __init__(self, levels=0, cols=0, pre=None, post=None, name="pcthierarchy", clear_names=True, links="single",
Expand Down Expand Up @@ -961,3 +1005,41 @@ def run_from_config(cls, config, min, render=False, error_collector_type=None,
score=ind.get_error_collector().error()

return ind, score



@classmethod
def run_from_file(cls, filename, seed=None, render=False, history=False, move=None, plots=None, hpct_verbose= False, runs=None, outdir=None, early_termination = None):

prp = PCTRunProperties()
prp.load_db(filename)

error_collector_type = prp.db['error_collector_type'].strip()
error_response_type = prp.db['error_response_type']
error_limit = eval(prp.db['error_limit'])
environment_properties = eval(prp.db['environment_properties'])

error_properties = prp.get_error_properties()

if runs==None:
runs = eval(prp.db['runs'])
config = eval(prp.db['config'])
if seed is None:
seed = eval(prp.db['seed'])
print(f'Seed={seed}')
if early_termination is None:
early_termination = eval(prp.db['early_termination'])

ind, score = cls.run_from_config(config, min, render=render, error_collector_type=error_collector_type, error_response_type=error_response_type,
error_properties=error_properties, error_limit=error_limit, steps=runs, hpct_verbose=hpct_verbose, history=history,
environment_properties=environment_properties, seed=seed, early_termination=early_termination, move=move, plots=plots,
suffixes=True, plots_dir=outdir)

# ind, score = cls.run_from_config(config, min, render=render, error_collector_type=error_collector_type, error_response_type=error_response_type,
# error_properties=error_properties, error_limit=error_limit, steps=runs, hpct_verbose=hpct_verbose, history=history,
# environment_properties=env_props, seed=seed, early_termination=early_termination)


return score


0 comments on commit e58d58a

Please sign in to comment.