Skip to content

Commit

Permalink
feat: Brought use_cats and get_nterms into the scope of the python bi…
Browse files Browse the repository at this point in the history
…ndings (#42)

Brought use_cats and get_nterms into the scope of the python bindings
(such that these can now be changed/read within Python when using the
bindings).

Moreover, the Python bindings for simplifying graphs did not work, but a
couple of trivial changes seem to fix it.
  • Loading branch information
mjsutcliffe99 authored Jun 9, 2024
1 parent 55dc269 commit 5c91ab2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
Empty file modified pybindings/build.sh
100755 → 100644
Empty file.
2 changes: 2 additions & 0 deletions pybindings/quizx/_quizx.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Decomposer:
def decomp_top(self) -> None: ...
def decomp_all(self) -> None: ...
def decomp_until_depth(self, depth: int) -> None: ...
def use_cats(self, b: bool) -> None: ...
def get_nterms(self) -> int: ...

def dummy(a: int) -> str: ...
def interior_clifford_simp(g: VecGraph): ...
Expand Down
9 changes: 9 additions & 0 deletions pybindings/quizx/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,19 @@ def decomp_all(self):
def decomp_until_depth(self, depth: int):
self._d.decomp_until_depth(depth)

def use_cats(self, b: bool):
self._d.use_cats(b)

def get_nterms(self):
return self._d.get_nterms()

@property
def scalar(self) -> Scalar:
return to_pyzx_scalar(self._d.scalar)

@scalar.setter
def scalar(self, s: Scalar):
self._d.scalar = from_pyzx_scalar(s)

def is_ground(self, vertex):
return False
5 changes: 4 additions & 1 deletion pybindings/quizx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class VecGraph(BaseGraph[int, Tuple[int, int]]):
# The documentation of what these methods do
# can be found in base.BaseGraph
def __init__(self, rust_graph: Optional[_quizx.VecGraph] = None):
BaseGraph.__init__(self)
if rust_graph:
self._g = rust_graph
else:
self._g = _quizx.VecGraph()
BaseGraph.__init__(self)
self._vdata: Dict[int, Any] = dict()

def get_raw_graph(self) -> _quizx.VecGraph:
Expand Down Expand Up @@ -325,3 +325,6 @@ def scalar(self) -> Scalar:
@scalar.setter
def scalar(self, s: Scalar):
self._g.scalar = from_pyzx_scalar(s)

def is_ground(self, vertex):
return False
2 changes: 1 addition & 1 deletion pybindings/quizx/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def from_pyzx_scalar(s: PyzxScalar) -> QuizxScalar:

def to_pyzx_scalar(s: QuizxScalar) -> PyzxScalar:
"""Convert a `pyzx.Scalar` to a `quizx::Scalar`."""
return PyzxScalar.from_json(s.to_json())
return PyzxScalar().from_json(s.to_json())
6 changes: 6 additions & 0 deletions pybindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,10 @@ impl Decomposer {
fn decomp_until_depth(&mut self, depth: usize) {
self.d.decomp_until_depth(depth);
}
fn use_cats(&mut self, b: bool) {
self.d.use_cats(b);
}
fn get_nterms(&self) -> usize {
self.d.nterms
}
}

0 comments on commit 5c91ab2

Please sign in to comment.