-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: Use latest results extension spec (#370)
Fixes #369 and fixes #365. Make Guppy conform with the latest results spec introduced in CQCL/tket2#494 BREAKING CHANGE: * Result tags are now strings instead of ints * Only numeric values and arrays thereof are allowed as results
- Loading branch information
Showing
17 changed files
with
201 additions
and
63 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
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,7 @@ | ||
Guppy compilation failed. Error in file $FILE:7 | ||
|
||
5: @compile_guppy | ||
6: def foo(x: array[tuple[int, bool], 42]) -> None: | ||
7: result("foo", x) | ||
^ | ||
GuppyError: Expression of type `array[(int, bool), 42]` is not a valid result. Only numeric values or arrays thereof are allowed. |
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,7 @@ | ||
from guppylang.prelude.builtins import result, array | ||
from tests.util import compile_guppy | ||
|
||
|
||
@compile_guppy | ||
def foo(x: array[tuple[int, bool], 42]) -> None: | ||
result("foo", x) |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Guppy compilation failed. Error in file $FILE:7 | ||
|
||
5: @compile_guppy | ||
6: def foo(x: int, y: bool) -> None: | ||
7: result(x, y) | ||
^ | ||
GuppyTypeError: Expected an int literal | ||
6: def foo(y: bool) -> None: | ||
7: result("foo" + "bar", y) | ||
^^^^^^^^^^^^^ | ||
GuppyTypeError: Expected a string literal |
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 |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
|
||
|
||
@compile_guppy | ||
def foo(x: int, y: bool) -> None: | ||
result(x, y) | ||
def foo(y: bool) -> None: | ||
result("foo" + "bar", y) |
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
File renamed without changes.
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
@guppy(module) | ||
def foo(q: qubit) -> None: | ||
result(0, q) | ||
result("foo", q) | ||
|
||
|
||
module.compile() |
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 |
---|---|---|
@@ -1,46 +1,42 @@ | ||
from guppylang.prelude.builtins import result | ||
from guppylang.prelude.builtins import result, nat, array | ||
from tests.util import compile_guppy | ||
|
||
|
||
def test_single(validate): | ||
def test_basic(validate): | ||
@compile_guppy | ||
def main(x: int) -> None: | ||
result(0, x) | ||
result("foo", x) | ||
|
||
validate(main) | ||
|
||
|
||
def test_value(validate): | ||
@compile_guppy | ||
def main(x: int) -> None: | ||
return result(0, x) | ||
|
||
validate(main) | ||
|
||
|
||
def test_nested(validate): | ||
def test_multi(validate): | ||
@compile_guppy | ||
def main(x: int, y: float, z: bool) -> None: | ||
result(42, (x, (y, z))) | ||
def main(w: nat, x: int, y: float, z: bool) -> None: | ||
result("a", w) | ||
result("b", x) | ||
result("c", y) | ||
result("d", z) | ||
|
||
validate(main) | ||
|
||
|
||
def test_multi(validate): | ||
def test_array(validate): | ||
@compile_guppy | ||
def main(x: int, y: float, z: bool) -> None: | ||
result(0, x) | ||
result(1, y) | ||
result(2, z) | ||
def main(w: array[nat, 42], x: array[int, 5], y: array[float, 1], z: array[bool, 0]) -> None: | ||
result("a", w) | ||
result("b", x) | ||
result("c", y) | ||
result("d", z) | ||
|
||
validate(main) | ||
|
||
|
||
def test_same_tag(validate): | ||
@compile_guppy | ||
def main(x: int, y: float, z: bool) -> None: | ||
result(0, x) | ||
result(0, y) | ||
result(0, z) | ||
result("foo", x) | ||
result("foo", y) | ||
result("foo", z) | ||
|
||
validate(main) |
Oops, something went wrong.