Skip to content

Commit

Permalink
refactor!: remove any messagepack, leave json
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Jan 19, 2024
1 parent c641cbd commit d184077
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 87 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ poetry run pytest --export-test-cases=guppy-exports

```

which will create a directory `./guppy-exports` populated with hugr modules serialised in msgpack.
which will create a directory `./guppy-exports` populated with hugr modules serialised in JSON.

## Packaging

Expand Down
6 changes: 1 addition & 5 deletions guppylang/hugr/hugr.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,6 @@ def to_raw(self) -> raw.RawHugr:
raise ValueError("Raw Hugr requires a root node")
return raw.RawHugr(nodes=nodes, edges=edges)

def serialize(self) -> bytes:
"""Serialize this Hugr in binary format."""
return self.to_raw().packb()

def serialize_json(self) -> str:
def serialize(self) -> str:
"""Serialize this Hugr in JSON format."""
return self.to_raw().to_json()
9 changes: 0 additions & 9 deletions guppylang/hugr/raw.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any, Literal

import ormsgpack
from pydantic import BaseModel

from guppylang.hugr.ops import NodeID, OpType
Expand All @@ -14,18 +13,10 @@ class RawHugr(BaseModel):
nodes: list[OpType]
edges: list[Edge]

def packb(self) -> bytes:
return ormsgpack.packb(self.model_dump(), option=ormsgpack.OPT_NON_STR_KEYS)

def to_json(self) -> str:
"""Return a JSON representation of the Hugr."""
return self.model_dump_json()

@classmethod
def unpackb(cls, b: bytes) -> "RawHugr":
"""Decode a msgpack-encoded Hugr."""
return cls(**ormsgpack.unpackb(b, option=ormsgpack.OPT_NON_STR_KEYS))

@classmethod
def load_json(cls, json: dict[Any, Any]) -> "RawHugr":
"""Decode a JSON-encoded Hugr."""
Expand Down
32 changes: 1 addition & 31 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repository = "https://github.com/CQCL/guppy"
python = "^3.10"
graphviz = "^0.20.1"
networkx = "^3.2.1"
ormsgpack = "^1.4.1"
pydantic = "^2.5.3"
typing-extensions = "^4.9.0"
pytket = { version = "^1.24.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def validate_json(hugr: str):

def validate_impl(hugr, name=None):
# Validate via the json encoding
js = hugr.serialize_json()
js = hugr.serialize()
validate_json(js)

if export_test_cases_dir:
Expand Down
29 changes: 0 additions & 29 deletions validator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ crate-type = ["cdylib"]
[dependencies]
pyo3 = "0.19.0"
quantinuum-hugr = "0.1.0"
rmp-serde = "1.1.1"
lazy_static = "1.4.0"
serde_json = "1.0.111"
9 changes: 0 additions & 9 deletions validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ lazy_static! {
.unwrap();
}

/// Validate a msgpack-encoded Hugr
#[pyfunction]
fn validate_bytes(hugr: Vec<u8>) -> PyResult<()> {
let hg: hugr::Hugr = rmp_serde::from_slice(&hugr).unwrap();
hg.validate(&REGISTRY).unwrap();
Ok(())
}

/// Validate a json-encoded Hugr
#[pyfunction]
fn validate_json(hugr: String) -> PyResult<()> {
Expand All @@ -36,7 +28,6 @@ fn validate_json(hugr: String) -> PyResult<()> {

#[pymodule]
fn guppyval(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(validate_bytes, m)?)?;
m.add_function(wrap_pyfunction!(validate_json, m)?)?;
Ok(())
}

0 comments on commit d184077

Please sign in to comment.