-
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.
test: Add list, loop, and comprehension tests
- Loading branch information
Showing
75 changed files
with
1,517 additions
and
8 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:13 | ||
|
||
11: @guppy(module) | ||
12: def foo(xs: list[int], q: Qubit) -> linst[Qubit]: | ||
13: return [q for x in xs] | ||
^ | ||
GuppyTypeError: Variable `q` with linear type `Qubit` would be used multiple times when evaluating this comprehension |
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,16 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy(module) | ||
def foo(xs: list[int], q: Qubit) -> linst[Qubit]: | ||
return [q for x in xs] | ||
|
||
|
||
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:18 | ||
|
||
16: @guppy(module) | ||
17: def foo(xs: list[int], q: Qubit) -> list[int]: | ||
18: return [x for x in xs if bar(q)] | ||
^ | ||
GuppyTypeError: Variable `q` with linear type `Qubit` would be used multiple times when evaluating this comprehension |
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,21 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.declare(module) | ||
def bar(q: Qubit) -> bool: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def foo(xs: list[int], q: Qubit) -> list[int]: | ||
return [x for x in xs if bar(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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Guppy compilation failed. Error in file $FILE:13 | ||
|
||
11: @guppy(module) | ||
12: def foo(qs: linst[tuple[bool, Qubit]]) -> linst[Qubit]: | ||
13: return [q for b, q in qs if b] | ||
^ | ||
GuppyTypeError: Variable `q` with linear type `Qubit` is not used on all control-flow paths of the list comprehension |
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,16 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy(module) | ||
def foo(qs: linst[tuple[bool, Qubit]]) -> linst[Qubit]: | ||
return [q for b, q in qs if b] | ||
|
||
|
||
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:18 | ||
|
||
16: @guppy(module) | ||
17: def foo(qs: linst[tuple[bool, Qubit]]) -> list[int]: | ||
18: return [42 for b, q in qs if b if q] | ||
^ | ||
GuppyTypeError: Variable `q` with linear type `Qubit` is not used on all control-flow paths of the list comprehension |
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,21 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.declare(module) | ||
def bar(q: Qubit) -> bool: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def foo(qs: linst[tuple[bool, Qubit]]) -> list[int]: | ||
return [42 for b, q in qs if b if 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Guppy compilation failed. Error in file $FILE:6 | ||
|
||
4: @guppy | ||
5: def foo(xs: list[int]) -> None: | ||
6: [x for x in xs if x < 5 and x != 6] | ||
^^^^^^^^^^^^^^^^ | ||
GuppyError: Expression is not supported inside a list comprehension |
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,6 @@ | ||
from guppy.decorator import guppy | ||
|
||
|
||
@guppy | ||
def foo(xs: list[int]) -> None: | ||
[x for x in xs if x < 5 and x != 6] |
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:6 | ||
|
||
4: @guppy | ||
5: def foo(xs: list[int], ys: list[int], b: bool) -> None: | ||
6: [x for x in (xs if b else ys)] | ||
^^^^^^^^^^^^^^^ | ||
GuppyError: Expression is not supported inside a list comprehension |
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,6 @@ | ||
from guppy.decorator import guppy | ||
|
||
|
||
@guppy | ||
def foo(xs: list[int], ys: list[int], b: bool) -> None: | ||
[x for x in (xs if b else ys)] |
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:6 | ||
|
||
4: @guppy | ||
5: def foo(xs: list[int]) -> None: | ||
6: [y := x for x in xs] | ||
^^^^^^ | ||
GuppyError: Expression is not supported inside a list comprehension |
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,6 @@ | ||
from guppy.decorator import guppy | ||
|
||
|
||
@guppy | ||
def foo(xs: list[int]) -> None: | ||
[y := x for x in xs] |
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:13 | ||
|
||
11: @guppy(module) | ||
12: def foo(qs: linst[Qubit], xs: list[int]) -> linst[Qubit]: | ||
13: return [q for q in qs for x in xs] | ||
^ | ||
GuppyTypeError: Variable `q` with linear type `Qubit` would be used multiple times when evaluating this comprehension |
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,16 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy(module) | ||
def foo(qs: linst[Qubit], xs: list[int]) -> linst[Qubit]: | ||
return [q for q in qs for x in xs] | ||
|
||
|
||
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:13 | ||
|
||
11: @guppy(module) | ||
12: def foo(qs: linst[Qubit], xs: list[int]) -> linst[Qubit]: | ||
13: return [q for x in xs for q in qs] | ||
^^ | ||
GuppyTypeError: Variable `qs` with linear type `linst[Qubit]` would be used multiple times when evaluating this comprehension |
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,16 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy(module) | ||
def foo(qs: linst[Qubit], xs: list[int]) -> linst[Qubit]: | ||
return [q for x in xs for q in 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Guppy compilation failed. Error in file $FILE:18 | ||
|
||
16: @guppy(module) | ||
17: def foo(qs: linst[Qubit], xs: list[int]) -> list[int]: | ||
18: return [x for q in qs for x in xs if bar(q)] | ||
^ | ||
GuppyTypeError: Variable `q` with linear type `Qubit` would be used multiple times when evaluating this comprehension |
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,21 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.declare(module) | ||
def bar(q: Qubit) -> bool: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def foo(qs: linst[Qubit], xs: list[int]) -> list[int]: | ||
return [x for q in qs for x in xs if bar(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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Guppy compilation failed. Error in file $FILE:13 | ||
|
||
11: @guppy(module) | ||
12: def foo(qs: linst[Qubit]) -> list[int]: | ||
13: return [42 for q in qs] | ||
^ | ||
GuppyTypeError: Variable `q` with linear type `Qubit` is not used |
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,16 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy(module) | ||
def foo(qs: linst[Qubit]) -> list[int]: | ||
return [42 for q in 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Guppy compilation failed. Error in file $FILE:13 | ||
|
||
11: @guppy(module) | ||
12: def foo(qs: linst[tuple[Qubit, Qubit]]) -> linst[Qubit]: | ||
13: return [q for q, q in qs] | ||
^ | ||
GuppyError: Variable `q` with linear type `Qubit` is not used |
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,16 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy(module) | ||
def foo(qs: linst[tuple[Qubit, Qubit]]) -> linst[Qubit]: | ||
return [q for q, q in 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Guppy compilation failed. Error in file $FILE:13 | ||
|
||
11: @guppy(module) | ||
12: def foo(qs: linst[Qubit], xs: list[int]) -> linst[Qubit]: | ||
13: return [q for q in qs for q in xs] | ||
^ | ||
GuppyError: Variable `q` with linear type `Qubit` is not used |
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,16 @@ | ||
import guppy.prelude.quantum as quantum | ||
from guppy.decorator import guppy | ||
from guppy.module import GuppyModule | ||
from guppy.hugr.tys import Qubit | ||
from guppy.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy(module) | ||
def foo(qs: linst[Qubit], xs: list[int]) -> linst[Qubit]: | ||
return [q for q in qs for q in xs] | ||
|
||
|
||
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:13 | ||
|
||
11: @guppy(module) | ||
12: def foo(qs: linst[Qubit]) -> linst[tuple[Qubit, Qubit]]: | ||
13: return [(q, q) for q in qs] | ||
^ | ||
GuppyError: Variable `q` with linear type `Qubit` was already used (at 13:13) |
Oops, something went wrong.