Skip to content

Commit

Permalink
style: Format with later version of ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
croyzor committed Mar 6, 2024
1 parent 5d2f576 commit c16a7fd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 128 deletions.
63 changes: 21 additions & 42 deletions guppylang/prelude/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,105 +26,84 @@ class qubit:


@guppy.hugr_op(quantum, quantum_op("H"))
def h(q: qubit) -> qubit:
...
def h(q: qubit) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("CZ"))
def cz(control: qubit, target: qubit) -> tuple[qubit, qubit]:
...
def cz(control: qubit, target: qubit) -> tuple[qubit, qubit]: ...


@guppy.hugr_op(quantum, quantum_op("CX"))
def cx(control: qubit, target: qubit) -> tuple[qubit, qubit]:
...
def cx(control: qubit, target: qubit) -> tuple[qubit, qubit]: ...


@guppy.hugr_op(quantum, quantum_op("T"))
def t(q: qubit) -> qubit:
...
def t(q: qubit) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("S"))
def s(q: qubit) -> qubit:
...
def s(q: qubit) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("X"))
def x(q: qubit) -> qubit:
...
def x(q: qubit) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("Y"))
def y(q: qubit) -> qubit:
...
def y(q: qubit) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("Z"))
def z(q: qubit) -> qubit:
...
def z(q: qubit) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("Tdg"))
def tdg(q: qubit) -> qubit:
...
def tdg(q: qubit) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("Sdg"))
def sdg(q: qubit) -> qubit:
...
def sdg(q: qubit) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("ZZMax"))
def zz_max(q: qubit) -> qubit:
...
def zz_max(q: qubit) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("Measure"))
def measure_return(q: qubit) -> tuple[qubit, bool]:
...
def measure_return(q: qubit) -> tuple[qubit, bool]: ...


@guppy.hugr_op(quantum, quantum_op("RzF64"))
def rz(q: qubit, angle: float) -> qubit:
...
def rz(q: qubit, angle: float) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("RxF64"))
def rx(q: qubit, angle: float) -> qubit:
...
def rx(q: qubit, angle: float) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("RzF64"))
def phased_x(q: qubit, angle1: float, angle2: float) -> qubit:
...
def phased_x(q: qubit, angle1: float, angle2: float) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("RzF64"))
def zz_phase(q1: qubit, q2: qubit, angle: float) -> tuple[qubit, qubit]:
...
def zz_phase(q1: qubit, q2: qubit, angle: float) -> tuple[qubit, qubit]: ...


@guppy.hugr_op(quantum, quantum_op("RzF64"))
def tk1(q: qubit, angle1: float, angle2: float, angle3: float) -> qubit:
...
def tk1(q: qubit, angle1: float, angle2: float, angle3: float) -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("QAlloc"), name="qubit")
def _qubit() -> qubit:
...
def _qubit() -> qubit: ...


@guppy.hugr_op(quantum, quantum_op("QFree"))
def discard(q: qubit) -> None:
...
def discard(q: qubit) -> None: ...


@guppy.hugr_op(quantum, quantum_op("Reset"))
def reset(q: qubit) -> qubit:
...
def reset(q: qubit) -> qubit: ...


@guppy.custom(quantum, MeasureCompiler())
def measure(q: qubit) -> bool:
...
def measure(q: qubit) -> bool: ...
36 changes: 12 additions & 24 deletions tests/integration/test_comprehension.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def test_dependent(validate):
module = GuppyModule("test")

@guppy.declare(module)
def process(x: float) -> list[int]:
...
def process(x: float) -> list[int]: ...

@guppy(module)
def test(xs: list[float]) -> list[float]:
Expand Down Expand Up @@ -145,8 +144,7 @@ def test_linear_discard(validate):
module.load(quantum)

@guppy.declare(module)
def discard(q: qubit) -> None:
...
def discard(q: qubit) -> None: ...

@guppy(module)
def test(qs: linst[qubit]) -> list[None]:
Expand All @@ -160,8 +158,7 @@ def test_linear_consume_in_guard(validate):
module.load(quantum)

@guppy.declare(module)
def cond(q: qubit) -> bool:
...
def cond(q: qubit) -> bool: ...

@guppy(module)
def test(qs: linst[tuple[int, qubit]]) -> list[int]:
Expand All @@ -175,8 +172,7 @@ def test_linear_consume_in_iter(validate):
module.load(quantum)

@guppy.declare(module)
def make_list(q: qubit) -> list[int]:
...
def make_list(q: qubit) -> list[int]: ...

@guppy(module)
def test(qs: linst[qubit]) -> list[int]:
Expand All @@ -194,24 +190,20 @@ class MyIter:
"""An iterator that yields linear values but is not linear itself."""

@guppy.declare(module)
def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]:
...
def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]: ...

@guppy.declare(module)
def __next__(self: "MyIter") -> tuple[qubit, "MyIter"]:
...
def __next__(self: "MyIter") -> tuple[qubit, "MyIter"]: ...

@guppy.declare(module)
def __end__(self: "MyIter") -> None:
...
def __end__(self: "MyIter") -> None: ...

@guppy.type(module, tys.TupleType(inner=[]))
class MyType:
"""Type that produces the iterator above."""

@guppy.declare(module)
def __iter__(self: "MyType") -> MyIter:
...
def __iter__(self: "MyType") -> MyIter: ...

@guppy(module)
def test(mt: MyType, xs: list[int]) -> linst[tuple[int, qubit]]:
Expand All @@ -234,24 +226,20 @@ class MyIter:
"""A linear iterator that yields non-linear values."""

@guppy.declare(module)
def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]:
...
def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]: ...

@guppy.declare(module)
def __next__(self: "MyIter") -> tuple[int, "MyIter"]:
...
def __next__(self: "MyIter") -> tuple[int, "MyIter"]: ...

@guppy.declare(module)
def __end__(self: "MyIter") -> None:
...
def __end__(self: "MyIter") -> None: ...

@guppy.type(module, tys.TupleType(inner=[]))
class MyType:
"""Type that produces the iterator above."""

@guppy.declare(module)
def __iter__(self: "MyType") -> MyIter:
...
def __iter__(self: "MyType") -> MyIter: ...

@guppy(module)
def test(mt: MyType, xs: list[int]) -> linst[tuple[int, int]]:
Expand Down
24 changes: 8 additions & 16 deletions tests/integration/test_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ def test_interleave(validate):
module.load(quantum)

@guppy.declare(module)
def f(q1: qubit, q2: qubit) -> tuple[qubit, qubit]:
...
def f(q1: qubit, q2: qubit) -> tuple[qubit, qubit]: ...

@guppy.declare(module)
def g(q1: qubit, q2: qubit) -> tuple[qubit, qubit]:
...
def g(q1: qubit, q2: qubit) -> tuple[qubit, qubit]: ...

@guppy(module)
def test(
Expand Down Expand Up @@ -117,8 +115,7 @@ def test_return_call(validate):
module.load(quantum)

@guppy.declare(module)
def op(q: qubit) -> qubit:
...
def op(q: qubit) -> qubit: ...

@guppy(module)
def test(q: qubit) -> qubit:
Expand Down Expand Up @@ -243,28 +240,23 @@ class MyIter:
"""An iterator that yields linear values but is not linear itself."""

@guppy.declare(module)
def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]:
...
def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]: ...

@guppy.declare(module)
def __next__(self: "MyIter") -> tuple[qubit, "MyIter"]:
...
def __next__(self: "MyIter") -> tuple[qubit, "MyIter"]: ...

@guppy.declare(module)
def __end__(self: "MyIter") -> None:
...
def __end__(self: "MyIter") -> None: ...

@guppy.type(module, tys.TupleType(inner=[]))
class MyType:
"""Type that produces the iterator above."""

@guppy.declare(module)
def __iter__(self: "MyType") -> MyIter:
...
def __iter__(self: "MyType") -> MyIter: ...

@guppy.declare(module)
def measure(q: qubit) -> bool:
...
def measure(q: qubit) -> bool: ...

@guppy(module)
def test(mt: MyType, xs: list[int]) -> None:
Expand Down
Loading

0 comments on commit c16a7fd

Please sign in to comment.