Skip to content

Commit

Permalink
Extend metric output on ConsolePlus. Update comments; remove whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrock4t committed Jan 23, 2024
1 parent 545ab03 commit 799b9d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
5 changes: 2 additions & 3 deletions pynars/ConsolePlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,9 @@ def toggle_silent() -> None:

@cmd_register('cycles')
def cycles(*args: List[str]) -> None:
'''Format: volume [volume:int 0~100]
Set the Output Volume of the console to control its output (same as OpenNARS)'''
'''Prints the "average cycles per second" metric'''
current_NARS_interface.print_output(
type=PrintType.INFO, content=f'''Cycles per second is {current_NARS_interface.reasoner.cycles_per_second}.''')
type=PrintType.INFO, content=f'''Cycles per second is {current_NARS_interface.reasoner.cycles_per_second}. Last cycle took {current_NARS_interface.reasoner.last_cycle_duration:f} seconds.''')

@cmd_register(('volume'), (int, 100))
def volume(vol:int) -> None:
Expand Down
13 changes: 5 additions & 8 deletions pynars/NARS/Control/Reasoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, n_memory, capacity, config='./config.json', nal_rules={1, 2,
self.cycles_per_second_timer = 0
self.cycles_per_second_counter = 0
self.cycles_per_second = 0
self.last_cycle_time = 0
self.last_cycle_duration = 0

def reset(self):
self.memory.reset()
Expand Down Expand Up @@ -115,21 +115,18 @@ def cycle(self):
tasks_derived = [
task for task in tasks_derived if task.term.complexity <= thresh_complexity]


# done with cycle

"""done with cycle"""
# record some metrics
total_cycle_time_in_seconds = time.time() - start_cycle_time_in_seconds
self.last_cycle_time = total_cycle_time_in_seconds
self.cycles_per_second_timer += total_cycle_time_in_seconds
total_cycle_duration_in_seconds = time.time() - start_cycle_time_in_seconds
self.last_cycle_duration = total_cycle_duration_in_seconds
self.cycles_per_second_timer += total_cycle_duration_in_seconds
self.cycles_per_second_counter += 1
if self.cycles_per_second_timer > 1:
# 1 second has passed
self.cycles_per_second = self.cycles_per_second_counter # store the result
self.cycles_per_second_timer = 0 # reset the timer
self.cycles_per_second_counter = 0 # reset the counter


return tasks_derived, judgement_revised, goal_revised, answers_question, answers_quest, (
task_operation_return, task_executed)

Expand Down

0 comments on commit 799b9d9

Please sign in to comment.