Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions apprentice/agents/ModularAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,13 @@ def check(self, state, selection, action, inputs):

def get_skills(self, states=None):
out = []
print("GET_SKILLS")
print(states)
# print("GET_SKILLS")
# print(states)
for state in states:
req = self.request(state,
add_skill_info=True)

pprint(req)
# pprint(req)
if(len(req) != 0):
req["when"] = json.dumps(req["when"])
req["where"] = json.dumps(req["where"])#tuple(len(list(req["where"].keys())) * ["?"])
Expand Down
2 changes: 1 addition & 1 deletion apprentice/learners/WhenLearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def ifit(self, rhs, state, mapping, reward):

if(self.cross_rhs_inference == "implicit_negatives"):
this_state = state.get_view(("variablize",rhs,tuple(mapping)))
pprint(this_state)
# pprint(this_state)
if(self.type == "one_learner_per_label"):
key = rhs.label
elif(self.type == "one_learner_per_rhs"):
Expand Down
16 changes: 8 additions & 8 deletions apprentice/learners/WhereLearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def ifit(self, t, x, y):
sm = StructureMapper(self.concept)
x = sm.transform(ns.transform(x))

pprint(x)
# pprint(x)
# pprint(x)
self.concept.increment_counts(x)

Expand All @@ -696,7 +696,7 @@ def ifit(self, t, x, y):
else:
self.neg_concept.increment_counts(x)

print(self.pos_concept)
# print(self.pos_concept)

# print()
# print('POSITIVE')
Expand All @@ -723,10 +723,10 @@ def ifit(self, t, x, y):
args.append(val_gensym)
pos_instance[attr] = val_gensym

pprint(pos_instance)
pprint(pos_args)
print("av_counts")
pprint(self.pos_concept.av_counts)
# pprint(pos_instance)
# pprint(pos_args)
# print("av_counts")
# pprint(self.pos_concept.av_counts)

# if len(self.pos_concept.av_counts[attr]) == 1:
# for val in self.pos_concept.av_counts[attr]:
Expand Down Expand Up @@ -758,7 +758,7 @@ def ifit(self, t, x, y):
conditions = ([(a, pos_instance[a]) for a in pos_instance] +
[('not', (a, neg_instance[a])) for a in neg_instance])

print(conditions)
# print(conditions)

# print("========CONDITIONS======")
# pprint(conditions)
Expand All @@ -767,7 +767,7 @@ def ifit(self, t, x, y):
self.target_types = ['?foa%s' % i for i in range(len(t))]
self.operator = Operator(tuple(['Rule'] + self.target_types),
conditions, [])
print("_-----------------------------------")
# print("_-----------------------------------")

def fit(self, T, X, y):
self.count = len(X)
Expand Down
4 changes: 3 additions & 1 deletion apprentice/planners/NumbaPlanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import numpy as np


logger = logging.getLogger(__name__)

def toFloatIfFloat(x):
try:
x = float(x)
Expand Down Expand Up @@ -166,7 +168,7 @@ def how_search(self,state,

if(not at_least_one and allow_bottomout and
(foci_of_attention == None or len(foci_of_attention) == 0)):
print("Bottomout:", goal)
logger.info("Bottomout: {}".format(goal))
yield goal, {}


Expand Down
73 changes: 41 additions & 32 deletions django/apprentice_learner/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
log = logging.getLogger('al-django')
performance_logger = logging.getLogger('al-performance')

DEFAULT_SAVE_AGENT = False
DEFAULT_STAY_ACTIVE = True


active_agent = None
active_agent_id = None
dont_save = True
save_agent = None


AGENTS = {
Expand All @@ -52,7 +56,7 @@


def get_agent_by_id(id):
global active_agent, active_agent_id, dont_save
global active_agent, active_agent_id
if id == active_agent_id:
agent = active_agent
else:
Expand Down Expand Up @@ -126,30 +130,36 @@ def create(http_request):
traceback.print_exc()
print("Failed to create agent", exp)
return HttpResponseServerError(
"Failed to create agent, " "ensure provided args are " "correct."
"Failed to create agent, ensure provided args are correct."
)

global active_agent, active_agent_id, dont_save
global active_agent, active_agent_id, save_agent
if active_agent is not None:
active_agent = None
active_agent_id = None
dont_save = False
if str(data.get("stay_active", True)).lower() == "true":

if str(data.get("stay_active", DEFAULT_STAY_ACTIVE)).lower() == "true":
active_agent = agent
active_agent_id = str(agent.id)
dont_save = str(data.get("dont_save", True)).lower() == "true"
else:
warns.append(
"Stability Warning: stay_active is set to false. Serialization and"
" deserialization of agents is currently not working for most"
" agent types. Expect Errors.")
# warns.append(
# "Stability Warning: stay_active is set to false. Serialization and"
# " deserialization of agents is currently not working for most"
# " agent types. Expect Errors.")
pass

if "save_agent" in data:
save_agent = str(data["save_agent"]).lower() == "true"
elif "dont_save" in data:
save_agent = not str(data["dont_save"]).lower() == "true"
else:
save_agent = DEFAULT_SAVE_AGENT

if len(warns) > 0:
for warn in warns:
log.warning(warn)
ret_data["warnings"] = warns


last_call_time = time.time_ns()

return HttpResponse(json.dumps(ret_data))
Expand Down Expand Up @@ -180,17 +190,17 @@ def request(http_request, agent_id):
agent.inc_request()

start_t = time.time_ns()
response = agent.instance.request(data["state"],**data.get('kwargs',{}))
response = agent.instance.request(data["state"], **data.get('kwargs', {}))
performance_logger.info("Request Elapse Time: {} ms".format((time.time_ns()-start_t)/(1e6)))

global dont_save
if not dont_save:
log.warning('Agent is being saved! This is probably not working.')
global save_agent
if save_agent:
# log.warning('Agent is being saved! This is probably not working.')
agent.save()

# pr.disable()
# pr.dump_stats("al.cprof")
last_call_time = time.time_ns()
last_call_time = time.time_ns()

if isinstance(response, Sai):
temp = {'selection': response.selection,
Expand All @@ -199,15 +209,14 @@ def request(http_request, agent_id):
'mapping': {"?sel": response.selection},
'how': "n/a",
'skill_label': 'n/a'}

return HttpResponse(
json.dumps({'selection': response.selection,
'action': response.action,
'inputs': response.inputs,
'mapping': {"?sel": response.selection},
'responses': [temp]
}
))
'action': response.action,
'inputs': response.inputs,
'mapping': {"?sel": response.selection},
'responses': [temp]
}))

return HttpResponse(json.dumps(response))

Expand Down Expand Up @@ -240,9 +249,9 @@ def get_skills(http_request, agent_id):
agent.inc_request()
response = agent.instance.get_skills(data["states"])

global dont_save
if not dont_save:
log.warning('Agent is being saved! This is probably not working.')
global save_agent
if save_agent:
# log.warning('Agent is being saved! This is probably not working.')
agent.save()

# pr.disable()
Expand Down Expand Up @@ -331,17 +340,17 @@ def train(http_request, agent_id):
response = agent.instance.train(**data)
performance_logger.info("Train Elapse Time: {} ms".format((time.time_ns()-start_t)/(1e6)))

global dont_save
if not dont_save:
log.warning('Agent is being saved! This is probably not working.')
global save_agent
if save_agent:
# log.warning('Agent is being saved! This is probably not working.')
agent.save()

# pr.disable()
# pr.dump_stats("al.cprof")
last_call_time = time.time_ns()
last_call_time = time.time_ns()

if(response is not None):
return HttpResponse(json.dumps(response))
return HttpResponse(json.dumps(response))
else:
return HttpResponse("OK")

Expand Down
Loading