Skip to content

Commit

Permalink
Merge branch 'main' into feat/hugr-json
Browse files Browse the repository at this point in the history
  • Loading branch information
qartik authored Jan 12, 2024
2 parents 773e3bd + 6e6e99a commit 8db2a05
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 300 deletions.
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,28 @@ These instructions will get you a copy of the project up and running on your loc

### Installing

Setup your virtual environment and install dependencies:

First make sure poetry [is
installed](https://python-poetry.org/docs/#installation).

Then run the following to setup your virtual environment and install dependencies:

```sh
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
poetry install
```

Install a local development version using:
You can then activate the virtual environment and work within it with:

```sh
pip install -e '.[dev]'
poetry shell
```

Consider using [direnv](https://github.com/direnv/direnv/wiki/Python#poetry) to
automate this when entering and leaving a directory.

To run a single command in the shell, just prefix it with `poetry run`.


### Git blame

You can configure Git to ignore formatting commits when using `git blame` by running
Expand All @@ -51,13 +59,13 @@ maturin develop
Run tests using

```sh
pytest -v
poetry run pytest -v
```

Integration test cases can be exported to a directory using

```sh
pytest --export-test-cases=guppy-exports
poetry run pytest --export-test-cases=guppy-exports

```

Expand All @@ -66,7 +74,7 @@ which will create a directory `./guppy-exports` populated with hugr modules seri
## Packaging

```sh
python -m build -n
poetry build
```

## License
Expand Down
4 changes: 2 additions & 2 deletions guppy/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ def compile(self, args: list[OutPortV]) -> list[OutPortV]:


class OpCompiler(CustomCallCompiler):
op: ops.OpType
op: ops.BaseOp

def __init__(self, op: ops.OpType) -> None:
def __init__(self, op: ops.BaseOp) -> None:
self.op = op

def compile(self, args: list[OutPortV]) -> list[OutPortV]:
Expand Down
4 changes: 2 additions & 2 deletions guppy/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def dec(c: type) -> type:
def type(
self,
module: GuppyModule,
hugr_ty: tys.SimpleType,
hugr_ty: tys.Type,
name: str = "",
linear: bool = False,
) -> ClassDecorator:
Expand Down Expand Up @@ -114,7 +114,7 @@ def type_args(self) -> Iterator[GuppyType]:
def linear(self) -> bool:
return linear

def to_hugr(self) -> tys.SimpleType:
def to_hugr(self) -> tys.Type:
return hugr_ty

def transform(self, transformer: TypeTransformer) -> GuppyType:
Expand Down
18 changes: 9 additions & 9 deletions guppy/gtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def linear(self) -> bool:
pass

@abstractmethod
def to_hugr(self) -> tys.SimpleType:
def to_hugr(self) -> tys.Type:
pass

@abstractmethod
Expand Down Expand Up @@ -106,7 +106,7 @@ def transform(self, transformer: "TypeTransformer") -> GuppyType:
def __str__(self) -> str:
return self.display_name

def to_hugr(self) -> tys.SimpleType:
def to_hugr(self) -> tys.Type:
return tys.Variable(i=self.idx, b=tys.TypeBound.from_linear(self.linear))


Expand Down Expand Up @@ -146,7 +146,7 @@ def __str__(self) -> str:
def __hash__(self) -> int:
return self.id

def to_hugr(self) -> tys.SimpleType:
def to_hugr(self) -> tys.Type:
from guppy.error import InternalGuppyError

raise InternalGuppyError("Tried to convert free type variable to Hugr")
Expand Down Expand Up @@ -195,7 +195,7 @@ def to_hugr(self) -> tys.PolyFuncType:
func_ty = tys.FunctionType(input=ins, output=outs, extension_reqs=[])
return tys.PolyFuncType(
params=[
tys.TypeParam(b=tys.TypeBound.from_linear(v.linear))
tys.TypeTypeParam(b=tys.TypeBound.from_linear(v.linear))
for v in self.quantified
],
body=func_ty,
Expand Down Expand Up @@ -267,9 +267,9 @@ def linear(self) -> bool:
def type_args(self) -> Iterator[GuppyType]:
return iter(self.element_types)

def to_hugr(self) -> tys.SimpleType:
def to_hugr(self) -> tys.Type:
ts = [t.to_hugr() for t in self.element_types]
return tys.Tuple(inner=ts)
return tys.TupleType(inner=ts)

def transform(self, transformer: "TypeTransformer") -> GuppyType:
return transformer.transform(self) or TupleType(
Expand Down Expand Up @@ -300,7 +300,7 @@ def linear(self) -> bool:
def type_args(self) -> Iterator[GuppyType]:
return iter(self.element_types)

def to_hugr(self) -> tys.SimpleType:
def to_hugr(self) -> tys.Type:
if all(
isinstance(e, TupleType) and len(e.element_types) == 0
for e in self.element_types
Expand Down Expand Up @@ -342,8 +342,8 @@ def substitute(self, s: Subst) -> GuppyType:
def __str__(self) -> str:
return "None"

def to_hugr(self) -> tys.SimpleType:
return tys.Tuple(inner=[])
def to_hugr(self) -> tys.Type:
return tys.TupleType(inner=[])

def transform(self, transformer: "TypeTransformer") -> GuppyType:
return transformer.transform(self) or self
Expand Down
6 changes: 3 additions & 3 deletions guppy/hugr/hugr.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Node(ABC):
"""

idx: NodeIdx
op: ops.OpType
op: ops.BaseOp
parent: Optional["Node"]
meta_data: dict[str, Any]

Expand Down Expand Up @@ -301,7 +301,7 @@ def _insert_node(self, node: Node, inputs: list[OutPortV] | None = None) -> None

def add_node(
self,
op: ops.OpType,
op: ops.BaseOp,
input_types: TypeList | None = None,
output_types: TypeList | None = None,
parent: Node | None = None,
Expand Down Expand Up @@ -539,7 +539,7 @@ def add_type_apply(
result_ty = func_port.ty.instantiate(args)
ta = ops.TypeApplication(
input=func_port.ty.to_hugr(),
args=[tys.TypeArg(ty=ty.to_hugr()) for ty in args],
args=[tys.TypeTypeArg(ty=ty.to_hugr()) for ty in args],
output=result_ty.to_hugr(),
)
return self.add_node(
Expand Down
Loading

0 comments on commit 8db2a05

Please sign in to comment.