-
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.
feat: Update linearity checker to handle subscripts (#421)
- Loading branch information
Showing
9 changed files
with
173 additions
and
12 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
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 main(qs: array[qubit, 42]) -> array[qubit, 42]: | ||
18: return foo(qs, qs[0]) | ||
^^ | ||
GuppyError: Variable `qs` with linear type `array[qubit, 42]` was already used (at 18:15) |
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.builtins import array, inout | ||
from guppylang.prelude.quantum import qubit | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.declare(module) | ||
def foo(qs: array[qubit, 42], q: qubit @inout) -> array[qubit, 42]: ... | ||
|
||
|
||
@guppy(module) | ||
def main(qs: array[qubit, 42]) -> array[qubit, 42]: | ||
return foo(qs, 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:18 | ||
|
||
16: @guppy(module) | ||
17: def main() -> qubit: | ||
18: return foo()[0] | ||
^^^^^^^^ | ||
GuppyTypeError: Remaining linear items with type `qubit` are 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,21 @@ | ||
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.declare(module) | ||
def foo() -> array[qubit, 10]: ... | ||
|
||
|
||
@guppy(module) | ||
def main() -> qubit: | ||
return foo()[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]) -> tuple[qubit, array[qubit, 42]]: | ||
14: q = qs[0] | ||
^^^^^ | ||
GuppyError: Subscripting on expression with linear type `array[qubit, 42]` is only allowed in `@inout` position |
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,18 @@ | ||
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]) -> tuple[qubit, array[qubit, 42]]: | ||
q = qs[0] | ||
return q, 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 main(qs: array[qubit, 42]) -> array[qubit, 42]: | ||
18: return foo(qs[0], qs) | ||
^^^^^ | ||
GuppyError: Variable `qs` with linear type `array[qubit, 42]` was already used (at 18:22) |
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.builtins import array, inout | ||
from guppylang.prelude.quantum import qubit | ||
|
||
|
||
module = GuppyModule("test") | ||
module.load(quantum) | ||
|
||
|
||
@guppy.declare(module) | ||
def foo(q: qubit @inout, qs: array[qubit, 42]) -> array[qubit, 42]: ... | ||
|
||
|
||
@guppy(module) | ||
def main(qs: array[qubit, 42]) -> array[qubit, 42]: | ||
return foo(qs[0], qs) | ||
|
||
|
||
module.compile() |