Skip to content

Commit

Permalink
make run_step_by_step return only state
Browse files Browse the repository at this point in the history
  • Loading branch information
noskill committed Nov 20, 2023
1 parent 8fd2016 commit c9c909d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 4 additions & 8 deletions python/hyperon/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,12 @@ def process_results(self, results, flat=False):
else:
return [[Atom._from_catom(catom) for catom in result] for result in results]

def run_step_by_step(self, program, flat=False):
"""Runs program step by step, yielding state and result"""
def run_step_by_step(self, program):
"""Runs program step by step, yielding state"""
state = RunnerState(self, program)
state.run_step()
results = state.current_results(flat=flat)
yield state, results
while not state.is_complete():
state.run_step()
results = state.current_results(flat=flat)
yield state, results
yield state


class Environment:
Expand Down Expand Up @@ -251,4 +247,4 @@ def custom_env(working_dir = None, config_dir = None, create_config = False, dis
hp.env_builder_set_is_test(True)
for path in reversed(include_paths):
hp.env_builder_add_include_path(builder, path)
return builder
return builder
3 changes: 2 additions & 1 deletion python/tests/test_run_metta.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ def test_run_step_by_step(self):
'''
runner = MeTTa(env_builder=Environment.test_env())
i = 0
for _state, results in runner.run_step_by_step(program):
for state in runner.run_step_by_step(program):
pass
i += 1
print('number of steps ' + str(i))
self.assertLess(i, 600)
results = state.current_results()
self.assertEqual(len(results[0]), 2)

def process_exceptions(self, results):
Expand Down

0 comments on commit c9c909d

Please sign in to comment.