Skip to content

Commit

Permalink
refactor!: rename prelude to std (#642)
Browse files Browse the repository at this point in the history
Closes #430 

The following is for release-please

Release-As: 0.13.0

BREAKING CHANGE: `prelude` module renamed to `std`
  • Loading branch information
ss2165 authored Nov 12, 2024
1 parent bd6011c commit 1a68e8e
Show file tree
Hide file tree
Showing 130 changed files with 316 additions and 319 deletions.
16 changes: 8 additions & 8 deletions examples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"id": "2150bc3a",
"metadata": {},
"source": [
"Guppy provides a special `qubit` type that quantum operations act on. Quantum operations become available once we import and load the `guppylang.prelude.quantum` module."
"Guppy provides a special `qubit` type that quantum operations act on. Quantum operations become available once we import and load the `guppylang.std.quantum` module."
]
},
{
Expand All @@ -86,8 +86,8 @@
"metadata": {},
"outputs": [],
"source": [
"from guppylang.prelude.builtins import owned\n",
"from guppylang.prelude.quantum import qubit, measure, h, cx\n",
"from guppylang.std.builtins import owned\n",
"from guppylang.std.quantum import qubit, measure, h, cx\n",
"\n",
"module.load(qubit, h, cx, measure)\n",
"\n",
Expand Down Expand Up @@ -324,7 +324,7 @@
],
"source": [
"bad_module = GuppyModule(name=\"bad_module\")\n",
"bad_module.load_all(guppylang.prelude.quantum)\n",
"bad_module.load_all(guppylang.std.quantum)\n",
"\n",
"@guppy(bad_module)\n",
"def bad(q: qubit @owned) -> qubit:\n",
Expand Down Expand Up @@ -371,7 +371,7 @@
],
"source": [
"bad_module = GuppyModule(name=\"bad_module\")\n",
"bad_module.load_all(guppylang.prelude.quantum)\n",
"bad_module.load_all(guppylang.std.quantum)\n",
"\n",
"@guppy(bad_module)\n",
"def bad(q: qubit @owned) -> qubit:\n",
Expand Down Expand Up @@ -435,7 +435,7 @@
"outputs": [],
"source": [
"module = GuppyModule(\"structs\")\n",
"module.load_all(guppylang.prelude.quantum)\n",
"module.load_all(guppylang.std.quantum)\n",
"\n",
"@guppy.struct(module)\n",
"class QubitPair:\n",
Expand Down Expand Up @@ -570,7 +570,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand All @@ -584,7 +584,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.12.5"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions examples/random_walk_qpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

from guppylang.decorator import guppy
from guppylang.module import GuppyModule
from guppylang.prelude.angles import angle
from guppylang.prelude.builtins import owned, py, result
from guppylang.prelude.quantum import discard, measure, qubit
from guppylang.prelude.quantum_functional import cx, h, rz, x
from guppylang.std.angles import angle
from guppylang.std.builtins import owned, py, result
from guppylang.std.quantum import discard, measure, qubit
from guppylang.std.quantum_functional import cx, h, rz, x


sqrt_e = math.sqrt(math.e)
Expand Down
8 changes: 4 additions & 4 deletions examples/t_factory.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import numpy as np

from guppylang.decorator import guppy
from guppylang.prelude.angles import angle, pi
from guppylang.prelude.builtins import owned, py
from guppylang.prelude.quantum import (
from guppylang.std.angles import angle, pi
from guppylang.std.builtins import owned, py
from guppylang.std.quantum import (
discard,
measure,
qubit,
)
from guppylang.prelude.quantum_functional import (
from guppylang.std.quantum_functional import (
cz,
h,
rx,
Expand Down
6 changes: 3 additions & 3 deletions guppylang/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from guppylang.decorator import guppy
from guppylang.experimental import enable_experimental_features
from guppylang.module import GuppyModule
from guppylang.prelude import builtins, quantum
from guppylang.prelude.builtins import Bool, Float, Int, List, py
from guppylang.prelude.quantum import qubit
from guppylang.std import builtins, quantum
from guppylang.std.builtins import Bool, Float, Int, List, py
from guppylang.std.quantum import qubit

# This is updated by our release-please workflow, triggered by this
# annotation: x-release-please-version
Expand Down
2 changes: 1 addition & 1 deletion guppylang/compiler/expr_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
TensorCall,
TypeApply,
)
from guppylang.prelude._internal.compiler.list import (
from guppylang.std._internal.compiler.list import (
list_new,
list_push,
)
Expand Down
4 changes: 2 additions & 2 deletions guppylang/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, name: str, import_builtins: bool = True):

# Import builtin module
if import_builtins:
import guppylang.prelude.builtins as builtins
import guppylang.std.builtins as builtins

# Std lib is allowed to use experimental features
with enable_experimental_features():
Expand Down Expand Up @@ -348,7 +348,7 @@ def compile(self) -> ModulePointer:
# compute this dynamically from the imported dependencies instead.
#
# The hugr prelude and std_extensions are implicit.
from guppylang.prelude._internal.compiler.quantum import TKET2_EXTENSIONS
from guppylang.std._internal.compiler.quantum import TKET2_EXTENSIONS

extensions = [*TKET2_EXTENSIONS, guppylang.compiler.hugr_extension.EXTENSION]

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def synthesize(self, args: list[ast.expr]) -> tuple[ast.expr, Type]:
return range_iter, range_ty

def range_ty(self) -> StructType:
from guppylang.prelude.builtins import Range
from guppylang.std.builtins import Range

def_id = cast(RawStructDef, Range).id
range_type_def = self.ctx.globals.defs[def_id]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class NatTruedivCompiler(CustomCallCompiler):
"""Compiler for the `nat.__truediv__` method."""

def compile(self, args: list[Wire]) -> list[Wire]:
from guppylang.prelude.builtins import Float, Nat
from guppylang.std.builtins import Float, Nat

# Compile `truediv` using float arithmetic
[left, right] = args
Expand Down Expand Up @@ -138,7 +138,7 @@ class IntTruedivCompiler(CustomCallCompiler):
"""Compiler for the `int.__truediv__` method."""

def compile(self, args: list[Wire]) -> list[Wire]:
from guppylang.prelude.builtins import Float, Int
from guppylang.std.builtins import Float, Int

# Compile `truediv` using float arithmetic
[left, right] = args
Expand Down Expand Up @@ -173,7 +173,7 @@ class FloatBoolCompiler(CustomCallCompiler):
"""Compiler for the `float.__bool__` method."""

def compile(self, args: list[Wire]) -> list[Wire]:
from guppylang.prelude.builtins import Float
from guppylang.std.builtins import Float

# We have: bool(x) = (x != 0.0)
zero = self.builder.load(hugr.std.float.FloatVal(0.0))
Expand All @@ -192,7 +192,7 @@ class FloatFloordivCompiler(CustomCallCompiler):
"""Compiler for the `float.__floordiv__` method."""

def compile(self, args: list[Wire]) -> list[Wire]:
from guppylang.prelude.builtins import Float
from guppylang.std.builtins import Float

# We have: floordiv(x, y) = floor(truediv(x, y))
[div] = Float.__truediv__.compile_call(
Expand All @@ -218,7 +218,7 @@ class FloatModCompiler(CustomCallCompiler):
"""Compiler for the `float.__mod__` method."""

def compile(self, args: list[Wire]) -> list[Wire]:
from guppylang.prelude.builtins import Float
from guppylang.std.builtins import Float

# We have: mod(x, y) = x - (x // y) * y
[div] = Float.__floordiv__.compile_call(
Expand Down Expand Up @@ -252,7 +252,7 @@ class FloatDivmodCompiler(CustomCallCompiler):
"""Compiler for the `__divmod__` method."""

def compile(self, args: list[Wire]) -> list[Wire]:
from guppylang.prelude.builtins import Float
from guppylang.std.builtins import Float

# We have: divmod(x, y) = (div(x, y), mod(x, y))
[div] = Float.__truediv__.compile_call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from guppylang.definition.custom import CustomCallCompiler
from guppylang.definition.value import CallReturnWires
from guppylang.error import InternalGuppyError
from guppylang.prelude._internal.compiler.arithmetic import convert_itousize
from guppylang.prelude._internal.compiler.prelude import (
from guppylang.std._internal.compiler.arithmetic import convert_itousize
from guppylang.std._internal.compiler.prelude import (
build_unwrap,
build_unwrap_left,
build_unwrap_right,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
from guppylang.definition.custom import CustomCallCompiler
from guppylang.definition.value import CallReturnWires
from guppylang.error import InternalGuppyError
from guppylang.prelude._internal.compiler.arithmetic import (
from guppylang.std._internal.compiler.arithmetic import (
convert_ifromusize,
convert_itousize,
)
from guppylang.prelude._internal.compiler.prelude import (
from guppylang.std._internal.compiler.prelude import (
build_unwrap,
build_unwrap_left,
build_unwrap_right,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MeasureReturnCompiler(CustomInoutCallCompiler):
"""Compiler for the `measure_return` function."""

def compile_with_inouts(self, args: list[Wire]) -> CallReturnWires:
from guppylang.prelude._internal.util import quantum_op
from guppylang.std._internal.util import quantum_op

[q] = args
[q, bit] = self.builder.add_op(
Expand All @@ -67,7 +67,7 @@ def __init__(self, opname: str):
self.opname = opname

def compile_with_inouts(self, args: list[Wire]) -> CallReturnWires:
from guppylang.prelude._internal.util import quantum_op
from guppylang.std._internal.util import quantum_op

[*qs, angle] = args
[halfturns] = self.builder.add_op(ops.UnpackTuple([FLOAT_T]), angle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from hugr import tys as ht

from guppylang.compiler.hugr_extension import UnsupportedOp
from guppylang.prelude._internal.compiler.quantum import QUANTUM_EXTENSION
from guppylang.std._internal.compiler.quantum import QUANTUM_EXTENSION
from guppylang.tys.subst import Inst
from guppylang.tys.ty import NumericType

Expand Down
2 changes: 1 addition & 1 deletion guppylang/prelude/angles.py → guppylang/std/angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from guppylang.decorator import guppy
from guppylang.module import GuppyModule
from guppylang.prelude.builtins import py
from guppylang.std.builtins import py

angles = GuppyModule("angles")

Expand Down
10 changes: 5 additions & 5 deletions guppylang/prelude/builtins.py → guppylang/std/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from guppylang.decorator import guppy
from guppylang.definition.custom import DefaultCallChecker, NoopCompiler
from guppylang.prelude._internal.checker import (
from guppylang.std._internal.checker import (
ArrayLenChecker,
CallableChecker,
CoercingChecker,
Expand All @@ -19,7 +19,7 @@
ReversingChecker,
UnsupportedChecker,
)
from guppylang.prelude._internal.compiler.arithmetic import (
from guppylang.std._internal.compiler.arithmetic import (
FloatBoolCompiler,
FloatDivmodCompiler,
FloatFloordivCompiler,
Expand All @@ -29,19 +29,19 @@
IToBoolCompiler,
NatTruedivCompiler,
)
from guppylang.prelude._internal.compiler.array import (
from guppylang.std._internal.compiler.array import (
ArrayGetitemCompiler,
ArraySetitemCompiler,
NewArrayCompiler,
)
from guppylang.prelude._internal.compiler.list import (
from guppylang.std._internal.compiler.list import (
ListGetitemCompiler,
ListLengthCompiler,
ListPopCompiler,
ListPushCompiler,
ListSetitemCompiler,
)
from guppylang.prelude._internal.util import (
from guppylang.std._internal.util import (
float_op,
int_op,
logic_op,
Expand Down
8 changes: 4 additions & 4 deletions guppylang/prelude/quantum.py → guppylang/std/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from hugr import tys as ht

from guppylang.decorator import guppy
from guppylang.prelude._internal.compiler.quantum import (
from guppylang.std._internal.compiler.quantum import (
HSERIES_EXTENSION,
MeasureReturnCompiler,
RotationCompiler,
)
from guppylang.prelude._internal.util import quantum_op
from guppylang.prelude.angles import angle
from guppylang.prelude.builtins import owned
from guppylang.std._internal.util import quantum_op
from guppylang.std.angles import angle
from guppylang.std.builtins import owned


@guppy.type(ht.Qubit, linear=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from typing import no_type_check

import guppylang.prelude.angles as angles
import guppylang.prelude.quantum as quantum
import guppylang.std.angles as angles
import guppylang.std.quantum as quantum
from guppylang.decorator import guppy

# mypy: disable-error-code="empty-body, misc, valid-type"
from guppylang.module import GuppyModule
from guppylang.prelude.angles import angle
from guppylang.prelude.builtins import owned
from guppylang.prelude.quantum import qubit
from guppylang.std.angles import angle
from guppylang.std.builtins import owned
from guppylang.std.quantum import qubit

quantum_functional = GuppyModule("quantum_functional")

Expand Down
4 changes: 2 additions & 2 deletions tests/error/array_errors/new_array_cannot_infer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import guppylang.prelude.quantum as quantum
import guppylang.std.quantum as quantum
from guppylang.decorator import guppy
from guppylang.module import GuppyModule
from guppylang.prelude.builtins import array
from guppylang.std.builtins import array


module = GuppyModule("test")
Expand Down
4 changes: 2 additions & 2 deletions tests/error/array_errors/new_array_check_fail.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import guppylang.prelude.quantum as quantum
import guppylang.std.quantum as quantum
from guppylang.decorator import guppy
from guppylang.module import GuppyModule
from guppylang.prelude.builtins import array
from guppylang.std.builtins import array


module = GuppyModule("test")
Expand Down
4 changes: 2 additions & 2 deletions tests/error/array_errors/new_array_elem_mismatch1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import guppylang.prelude.quantum as quantum
import guppylang.std.quantum as quantum
from guppylang.decorator import guppy
from guppylang.module import GuppyModule
from guppylang.prelude.builtins import array
from guppylang.std.builtins import array


module = GuppyModule("test")
Expand Down
4 changes: 2 additions & 2 deletions tests/error/array_errors/new_array_elem_mismatch2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import guppylang.prelude.quantum as quantum
import guppylang.std.quantum as quantum
from guppylang.decorator import guppy
from guppylang.module import GuppyModule
from guppylang.prelude.builtins import array
from guppylang.std.builtins import array


module = GuppyModule("test")
Expand Down
4 changes: 2 additions & 2 deletions tests/error/array_errors/new_array_wrong_length.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import guppylang.prelude.quantum as quantum
import guppylang.std.quantum as quantum
from guppylang.decorator import guppy
from guppylang.module import GuppyModule
from guppylang.prelude.builtins import array
from guppylang.std.builtins import array


module = GuppyModule("test")
Expand Down
Loading

0 comments on commit 1a68e8e

Please sign in to comment.