-
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.
tests: Add various struct linearity and field access tests (#293)
See #295 for context
- Loading branch information
Showing
58 changed files
with
994 additions
and
0 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
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], s: MyStruct) -> linst[MyStruct]: | ||
18: return [s for x in xs] | ||
^ | ||
GuppyTypeError: Field `s.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 guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit | ||
from guppylang.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(xs: list[int], s: MyStruct) -> linst[MyStruct]: | ||
return [s 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], s: MyStruct) -> linst[qubit]: | ||
18: return [s.q for x in xs] | ||
^^^ | ||
GuppyTypeError: Field `s.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 guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit | ||
from guppylang.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(xs: list[int], s: MyStruct) -> linst[qubit]: | ||
return [s.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:24 | ||
|
||
22: @guppy(module) | ||
23: def foo(qs: linst[MyStruct]) -> linst[qubit]: | ||
24: return [s.q2 for s in qs if bar(s.q1)] | ||
^ | ||
GuppyTypeError: Field `s.q2` 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,27 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit | ||
from guppylang.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q1: qubit | ||
q2: qubit | ||
|
||
|
||
@guppy.declare(module) | ||
def bar(q: qubit) -> bool: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def foo(qs: linst[MyStruct]) -> linst[qubit]: | ||
return [s.q2 for s in qs if bar(s.q1)] | ||
|
||
|
||
module.compile() |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Guppy compilation failed. Error in file $FILE:19 | ||
|
||
17: @guppy(module) | ||
18: def foo(ss: linst[MyStruct]) -> linst[qubit]: | ||
19: return [s.q1 for s in ss] | ||
^ | ||
GuppyTypeError: Field `s.q2` 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,22 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit | ||
from guppylang.prelude.builtins import linst | ||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q1: qubit | ||
q2: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(ss: linst[MyStruct]) -> linst[qubit]: | ||
return [s.q1 for s in ss] | ||
|
||
|
||
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(b: bool) -> bool: | ||
18: s = MyStruct(qubit()) | ||
^ | ||
GuppyError: Field `s.q` with linear type `qubit` is not used on all control-flow paths |
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,24 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit, measure | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(b: bool) -> bool: | ||
s = MyStruct(qubit()) | ||
if b: | ||
return measure(s.q) | ||
return False | ||
|
||
|
||
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:21 | ||
|
||
19: if b: | ||
20: measure(s.q2) | ||
21: return s | ||
^ | ||
GuppyError: Field `s.q2` with linear type `qubit` was already used (at 20:16) |
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,24 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit, measure | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q1: qubit | ||
q2: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(b: bool, s: MyStruct) -> MyStruct: | ||
if b: | ||
measure(s.q2) | ||
return s | ||
|
||
|
||
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:24 | ||
|
||
22: @guppy(module) | ||
23: def bar() -> qubit: | ||
24: return foo().q1 | ||
^^^^^ | ||
GuppyTypeError: Linear field `q2` of expression with type `MyStruct` 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,27 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q1: qubit | ||
q2: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo() -> MyStruct: | ||
return MyStruct(qubit(), qubit()) | ||
|
||
|
||
@guppy(module) | ||
def bar() -> qubit: | ||
return foo().q1 | ||
|
||
|
||
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:19 | ||
|
||
17: def foo(s: MyStruct) -> tuple[qubit, qubit]: | ||
18: t = s | ||
19: return s.q, t.q | ||
^^^ | ||
GuppyError: Field `s.q` with linear type `qubit` was already used (at 18:8) |
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,22 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(s: MyStruct) -> tuple[qubit, qubit]: | ||
t = s | ||
return s.q, t.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:17 | ||
|
||
15: @guppy(module) | ||
16: def foo(s: MyStruct) -> tuple[MyStruct, qubit]: | ||
17: return s, s.q | ||
^^^ | ||
GuppyError: Field `s.q` with linear type `qubit` was already used (at 17:11) |
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,20 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(s: MyStruct) -> tuple[MyStruct, qubit]: | ||
return s, s.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:17 | ||
|
||
15: @guppy(module) | ||
16: def foo(s: MyStruct) -> tuple[qubit, MyStruct]: | ||
17: return s.q, s | ||
^ | ||
GuppyError: Field `s.q` with linear type `qubit` was already used (at 17:11) |
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,20 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
@guppy.struct(module) | ||
class MyStruct: | ||
q: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(s: MyStruct) -> tuple[qubit, MyStruct]: | ||
return s.q, s | ||
|
||
|
||
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:26 | ||
|
||
24: measure(s.q) | ||
25: s.q = s.x.q | ||
26: return s | ||
^ | ||
GuppyError: Field `s.x.q` with linear type `qubit` was already used (at 25:10) |
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,29 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit, measure | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct1: | ||
q: qubit | ||
x: "MyStruct2" | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct2: | ||
q: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(s: MyStruct1) -> MyStruct1: | ||
measure(s.q) | ||
s.q = s.x.q | ||
return s | ||
|
||
|
||
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:25 | ||
|
||
23: def foo(s: MyStruct1) -> MyStruct1: | ||
24: measure(s.x.q1) | ||
25: return MyStruct1(s.x) | ||
^^^ | ||
GuppyError: Field `s.x.q1` with linear type `qubit` was already used (at 24:12) |
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,28 @@ | ||
import guppylang.prelude.quantum as quantum | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.prelude.quantum import qubit, measure | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct1: | ||
x: "MyStruct2" | ||
|
||
|
||
@guppy.struct(module) | ||
class MyStruct2: | ||
q1: qubit | ||
q2: qubit | ||
|
||
|
||
@guppy(module) | ||
def foo(s: MyStruct1) -> MyStruct1: | ||
measure(s.x.q1) | ||
return MyStruct1(s.x) | ||
|
||
|
||
module.compile() |
Oops, something went wrong.