-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Craig Roy <[email protected]>
- Loading branch information
Showing
9 changed files
with
149 additions
and
9 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
Empty file.
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:14 | ||
|
||
12: @guppy(module) | ||
13: def main(qs: array[qubit, 42]) -> int: | ||
14: return qs[0] | ||
^^ | ||
GuppyTypeError: Cannot instantiate non-linear type variable `T` in type `forall n, T: nat. (array[T, n], int) -> T` with linear type `qubit` |
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,17 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.builtins import array | ||
from guppylang.prelude.quantum import qubit | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy(module) | ||
def main(qs: array[qubit, 42]) -> int: | ||
return qs[0] | ||
|
||
|
||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Guppy compilation failed. Error in file $FILE:14 | ||
|
||
12: @guppy(module) | ||
13: def main(qs: array[qubit, 42]) -> int: | ||
14: return len(qs) | ||
^^^^^^^ | ||
GuppyTypeError: Cannot instantiate non-linear type variable `T` in type `forall n, T: nat. array[T, n] -> int` with linear type `qubit` |
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,17 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.builtins import array | ||
from guppylang.prelude.quantum import qubit | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy(module) | ||
def main(qs: array[qubit, 42]) -> int: | ||
return len(qs) | ||
|
||
|
||
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
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,35 @@ | ||
from hugr.serialization import ops | ||
|
||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude._internal import ConstInt | ||
from guppylang.prelude.builtins import array | ||
from tests.util import compile_guppy | ||
|
||
|
||
def test_len(validate): | ||
module = GuppyModule("test") | ||
|
||
@guppy(module) | ||
def main(xs: array[float, 42]) -> int: | ||
return len(xs) | ||
|
||
hg = module.compile() | ||
validate(hg) | ||
|
||
[val] = [ | ||
node.op.root.v.root | ||
for node in hg.nodes() | ||
if isinstance(node.op.root, ops.Const) | ||
] | ||
assert isinstance(val, ops.ExtensionValue) | ||
assert isinstance(val.value.v, ConstInt) | ||
assert val.value.v.value == 42 | ||
|
||
|
||
def test_index(validate): | ||
@compile_guppy | ||
def main(xs: array[int, 5], i: int) -> int: | ||
return xs[0] + xs[i] + xs[xs[2 * i]] | ||
|
||
validate(main) |