Skip to content

Commit

Permalink
Merge pull request #29 from chiefeu/fix-all-tests
Browse files Browse the repository at this point in the history
Fix all tests
  • Loading branch information
jtoy authored Mar 19, 2024
2 parents 52d3da7 + fb1c1b5 commit 463ec61
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
19 changes: 14 additions & 5 deletions src/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ def ask_meta_questions(self, timestamp):
self.meta_questions.extend(x[1] for x in m if x[1] not in self.meta_questions)

def evaluate_progress(self,opts={}):
relevant_memories = self.getMemories(self.goal, unix_to_strftime(self.matrix.unix_time))
if self.matrix:
relevant_memories = self.getMemories(self.goal, unix_to_strftime(self.matrix.unix_time))
else:
relevant_memories = self.getMemories(self.goal, opts.get("timestamp", ""))

relevant_memories_string = "\n".join(f"Memory {i + 1}:\n{memory}" for i, memory in enumerate(relevant_memories)) if relevant_memories else ""
primer = opts.get("random_prime",False)
variables = {
Expand All @@ -130,7 +134,11 @@ def evaluate_progress(self,opts={}):
score = int(match.group(1)) if match else None

if score and explanation:
self.addMemory("meta", explanation, unix_to_strftime(self.matrix.unix_time) , 10)
if self.matrix:
self.addMemory("meta", explanation, unix_to_strftime(self.matrix.unix_time) , 10)
else:
self.addMemory("meta", explanation, opts.get("timestamp", "") , 10)

if score and int(score) < 3:
#self.meta_cognize(unix_to_strftime(self.matrix.unix_time), True)
pass
Expand Down Expand Up @@ -494,7 +502,7 @@ def perceive(self, other_agents, environment, timestamp):
perceived_agents = []
perceived_areas = []
perceived_directions = []
if (self.matrix is not None and self.matrix.allow_observance_flag == 0) or (self.matrix is None and ALLOW_OBSERVE == 0):
if (self.matrix is not None and self.matrix.allow_observance_flag == 0) or (self.matrix is None and ALLOW_OBSERVANCE == 0):

return perceived_agents, perceived_locations, perceived_areas, perceived_objects

Expand Down Expand Up @@ -584,8 +592,9 @@ def perceive(self, other_agents, environment, timestamp):

perceived_data = (perceived_agents, perceived_locations, perceived_areas, perceived_objects, perceived_directions)
#self.last_perceived_data = perceived_data
self.perceived_data_history[self.matrix.cur_step] = perceived_data
self.cleanup_old_perceived_data(self.matrix.cur_step)
if self.matrix:
self.perceived_data_history[self.matrix.cur_step] = perceived_data
self.cleanup_old_perceived_data(self.matrix.cur_step)

return perceived_agents, perceived_locations, perceived_areas, perceived_objects,perceived_directions

Expand Down
8 changes: 6 additions & 2 deletions src/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ def parse_scenario_file(self, filename):
self.allow_movement = data.get("allow_movement", ALLOW_MOVEMENT)
self.background = data.get("background", "")
self.performance_evals = data.get("performance", {})
self.performance_metrics[self.performance_evals["numerator"]] = 0
self.performance_metrics["denominator"] = self.performance_evals["denominator"]
if not self.performance_evals:
self.performance_metrics["total_alive"] = 0
self.performance_metrics["denominator"] = "total_agents"
else:
self.performance_metrics[self.performance_evals["numerator"]] = 0
self.performance_metrics["denominator"] = self.performance_evals["denominator"]

if self.steps <= 0:
self.steps = data.get("steps", 100)
Expand Down
10 changes: 7 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ def test_fine_move_action_moves_away(self):
self.assertTrue(successful_outcomes >= 2)

def test_matrix_runs_step(self):
matrix = Matrix({"environment":"configs/small.tmj"})
matrix = Matrix({"scenario":"configs/empty.json","environment":"configs/largev2.tmj"})
#run for one step
matrix.steps=1
matrix.boot()
matrix.run_singlethread()
self.assertTrue(len(matrix.agents) > 0)
self.assertEqual(matrix.status,"complete")

def test_memory(self):
Expand Down Expand Up @@ -94,7 +98,7 @@ def test_eval(self):
print(f"Error {e}")

timestamp = datetime.fromtimestamp(unix_time).strftime("%Y-%m-%d %H:%M:%S")
agent1.evaluate_progress(timestamp)
agent1.evaluate_progress({'timestamp':timestamp})

def test_askmetaquestions(self):
agent1_data = {
Expand Down Expand Up @@ -629,7 +633,7 @@ def test_agent_decision_zombie(self):
agent.destination_cache = [(36, 88), (36, 89), (36, 90)]
zombie.destination_cache = [(36, 93), (36, 93), (36, 93)]

agent.addMemory("reflect", f"{matrix.unix_to_strftime(matrix.unix_time)} - {agent} wants to check if the Park is a safe place to go to or no.", matrix.unix_to_strftime(matrix.unix_time), 9)
agent.addMemory("reflect", f"{unix_to_strftime(matrix.unix_time)} - {agent} wants to check if the Park is a safe place to go to or no.", unix_to_strftime(matrix.unix_time), 9)

matrix.agents.append(agent)
matrix.agents.append(zombie)
Expand Down

0 comments on commit 463ec61

Please sign in to comment.