Skip to content

Commit

Permalink
Arrays + typeguard
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranra committed Jan 10, 2025
1 parent 5982e51 commit 0220fd6
Show file tree
Hide file tree
Showing 11 changed files with 1,286 additions and 22 deletions.
1 change: 1 addition & 0 deletions python/quantum-pecos/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [
"scipy>=1.1.0",
"networkx>=2.1.0",
"matplotlib>=2.2.0",
"typeguard>=4.0",
]
classifiers = [
"Development Status :: 4 - Beta",
Expand Down
19 changes: 17 additions & 2 deletions python/quantum-pecos/src/pecos/slr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@
from pecos.slr.cond_block import If, Repeat
from pecos.slr.main import Main
from pecos.slr.main import Main as SLR # noqa: N814
from pecos.slr.misc import Barrier, Comment, Permute
from pecos.slr.vars import Bit, CReg, QReg, Qubit, Vars
from pecos.slr.misc import Barrier, Comment, Permute, Reorder
from pecos.slr.vars import (
Bit,
BitArray,
BitSlice,
CReg,
QReg,
Qubit,
QubitArray,
QubitSlice,
Vars,
)

__all__ = [
"SLR",
"Barrier",
"Bit",
"BitArray",
"BitSlice",
"Block",
"CReg",
"Comment",
Expand All @@ -28,6 +40,9 @@
"Permute",
"QReg",
"Qubit",
"QubitArray",
"QubitSlice",
"Reorder",
"Repeat",
"Vars",
]
3 changes: 2 additions & 1 deletion python/quantum-pecos/src/pecos/slr/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

from pecos.slr.fund import Node
from pecos.slr.gen_codes.gen_qasm import QASMGenerator
from pecos.slr.typechecking import TypeCheckedMeta
from pecos.slr.vars import Var, Vars


class Block(Node):
class Block(Node, metaclass=TypeCheckedMeta):
"""A collection of other operations and blocks."""

def __init__(self, *args, ops=None, vargs=None, allow_no_ops=True):
Expand Down
16 changes: 14 additions & 2 deletions python/quantum-pecos/src/pecos/slr/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pecos.slr.vars import Elem, QReg, Qubit, Reg
from collections.abc import Sequence

from pecos.slr.vars import Elem, Qubit, QubitArray, Reg, RegSlice

from dataclasses import dataclass

from pecos.slr.fund import Statement


class Barrier(Statement):
def __init__(self, *qregs: QReg | tuple[QReg] | Qubit):
def __init__(self, *qregs: QubitArray | tuple[QubitArray] | Qubit):
self.qregs = qregs


Expand All @@ -45,3 +49,11 @@ def __init__(
self.elems_i = elems_i
self.elems_f = elems_f
self.comment = comment


@dataclass
class Reorder(Statement):
"""Command to reorder elements of a slice."""

slice: RegSlice
permutation: Sequence[int]
Loading

0 comments on commit 0220fd6

Please sign in to comment.