-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from qupsy.language import Pgm | ||
from qupsy.spec import Spec | ||
from qupsy.transition import next | ||
from qupsy.utils import logger | ||
from qupsy.verify import verify | ||
from qupsy.worklist import Worklist | ||
|
||
|
||
def search(spec: Spec, *, initial_pgm: Pgm | None = None, n: str = "n") -> Pgm: | ||
worklist = Worklist() | ||
worklist.put(initial_pgm or Pgm(n)) | ||
while worklist.notEmpty(): | ||
current_pgm = worklist.get() | ||
logger.debug(f"Current program: {current_pgm}") | ||
verified: list[bool] = [] | ||
for testcase in spec.testcases: | ||
if current_pgm.terminated: | ||
if verify(testcase, current_pgm): | ||
verified.append(True) | ||
if len(verified) == len(spec.testcases): | ||
return current_pgm | ||
else: | ||
break | ||
else: | ||
worklist.put(*next(current_pgm, spec.gates)) | ||
raise ValueError("No solution found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters