Skip to content

Commit

Permalink
Remove greedy recursion (#537)
Browse files Browse the repository at this point in the history
* Initiate greedy recursion removal

* Remove notebook from diff

* white spaces

* refactor while loop

* Remove redundant lines from while loop

---------

Co-authored-by: Jim Garrison <garrison@ibm.com>
  • Loading branch information
ibrahim-shehzad and garrison committed Apr 12, 2024
1 parent 8b1dc17 commit 4ab172a
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions circuit_knitting/cutting/cut_finding/cco_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,20 @@ def greedy_best_first_search(
Callable, search_space_funcs.next_state_func
)

if search_space_funcs.goal_state_func(state, *args):
return state

best = min(
[
(search_space_funcs.cost_func(next_state, *args), k, next_state)
for k, next_state in enumerate(
search_space_funcs.next_state_func(state, *args)
)
],
default=(None, None, None),
)

if best[-1] is None: # pragma: no cover
# This covers a rare edge case.
# We have so far found no circuit that triggers it.
# Excluding from test coverage for now.
return None

return greedy_best_first_search(best[-1], search_space_funcs, *args)
while not search_space_funcs.goal_state_func(state, *args):
best = min(
[
(search_space_funcs.cost_func(next_state, *args), k, next_state)
for k, next_state in enumerate(
search_space_funcs.next_state_func(state, *args)
)
],
default=(None, None, None),
)
if best[-1] is None: # pragma: no cover
# This covers a rare edge case.
# We have so far found no circuit that triggers it.
# Excluding from test coverage for now.
return None
state = best[-1]
return state

0 comments on commit 4ab172a

Please sign in to comment.