Skip to content

Commit 5c91ab2

Browse files
feat: Brought use_cats and get_nterms into the scope of the python bindings (zxcalc#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.
1 parent 55dc269 commit 5c91ab2

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

pybindings/build.sh

100755100644
File mode changed.

pybindings/quizx/_quizx.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class Decomposer:
100100
def decomp_top(self) -> None: ...
101101
def decomp_all(self) -> None: ...
102102
def decomp_until_depth(self, depth: int) -> None: ...
103+
def use_cats(self, b: bool) -> None: ...
104+
def get_nterms(self) -> int: ...
103105

104106
def dummy(a: int) -> str: ...
105107
def interior_clifford_simp(g: VecGraph): ...

pybindings/quizx/decompose.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,19 @@ def decomp_all(self):
3333
def decomp_until_depth(self, depth: int):
3434
self._d.decomp_until_depth(depth)
3535

36+
def use_cats(self, b: bool):
37+
self._d.use_cats(b)
38+
39+
def get_nterms(self):
40+
return self._d.get_nterms()
41+
3642
@property
3743
def scalar(self) -> Scalar:
3844
return to_pyzx_scalar(self._d.scalar)
3945

4046
@scalar.setter
4147
def scalar(self, s: Scalar):
4248
self._d.scalar = from_pyzx_scalar(s)
49+
50+
def is_ground(self, vertex):
51+
return False

pybindings/quizx/graph.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class VecGraph(BaseGraph[int, Tuple[int, int]]):
3333
# The documentation of what these methods do
3434
# can be found in base.BaseGraph
3535
def __init__(self, rust_graph: Optional[_quizx.VecGraph] = None):
36-
BaseGraph.__init__(self)
3736
if rust_graph:
3837
self._g = rust_graph
3938
else:
4039
self._g = _quizx.VecGraph()
40+
BaseGraph.__init__(self)
4141
self._vdata: Dict[int, Any] = dict()
4242

4343
def get_raw_graph(self) -> _quizx.VecGraph:
@@ -325,3 +325,6 @@ def scalar(self) -> Scalar:
325325
@scalar.setter
326326
def scalar(self, s: Scalar):
327327
self._g.scalar = from_pyzx_scalar(s)
328+
329+
def is_ground(self, vertex):
330+
return False

pybindings/quizx/scalar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ def from_pyzx_scalar(s: PyzxScalar) -> QuizxScalar:
1111

1212
def to_pyzx_scalar(s: QuizxScalar) -> PyzxScalar:
1313
"""Convert a `pyzx.Scalar` to a `quizx::Scalar`."""
14-
return PyzxScalar.from_json(s.to_json())
14+
return PyzxScalar().from_json(s.to_json())

pybindings/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,10 @@ impl Decomposer {
374374
fn decomp_until_depth(&mut self, depth: usize) {
375375
self.d.decomp_until_depth(depth);
376376
}
377+
fn use_cats(&mut self, b: bool) {
378+
self.d.use_cats(b);
379+
}
380+
fn get_nterms(&self) -> usize {
381+
self.d.nterms
382+
}
377383
}

0 commit comments

Comments
 (0)