diff --git a/pyzx/gflow.py b/pyzx/gflow.py index 00a9bf13..98d51910 100644 --- a/pyzx/gflow.py +++ b/pyzx/gflow.py @@ -26,7 +26,7 @@ def gflow( g: BaseGraph[VT, ET], focus: bool=False, reverse: bool=False, pauli: bool=False -) -> Optional[Tuple[Dict[VT, int], Dict[VT, Set[VT]], int]]: +) -> Optional[Tuple[Dict[VT, int], Dict[VT, Set[VT]]]]: r"""Compute the gflow of a diagram in graph-like form. :param g: A ZX-graph. @@ -132,7 +132,7 @@ def gflow( if not correct: if len(vertices) == len(processed): - return l, gflow, k + return {v: k - i - 1 for v,i in l.items()}, gflow return None else: processed.update(correct) diff --git a/scratchpads/ak.ipynb b/scratchpads/ak.ipynb index 1868f5ed..28799f03 100644 --- a/scratchpads/ak.ipynb +++ b/scratchpads/ak.ipynb @@ -29,11 +29,26 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, + "outputs": [], + "source": [ + "def transpose(p):\n", + " pt = dict()\n", + " for k,s in p.items():\n", + " for v in s:\n", + " if v not in pt: pt[v] = set()\n", + " pt[v].add(k)\n", + " return pt" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
\n", + "
\n", "" ], @@ -379,30 +394,30 @@ { "data": { "text/plain": [ - "Graph(155 vertices, 185 edges)" + "Graph(274 vertices, 328 edges)" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.seed(1337)\n", - "g = zx.generate.cliffordT(5, 100, p_t=0.1)\n", + "g = zx.generate.cliffordT(4, 200, p_t=0.2)\n", "zx.draw(g)\n", "g" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ @@ -750,25 +765,68 @@ "g1 = g.copy()\n", "zx.full_reduce(g1)\n", "g1.normalize()\n", + "g1 = g1.copy()\n", + "zx.to_rg(g1)\n", + "# g2 = g1.copy()\n", + "# for e in list(g2.edges()): zx.hrules.had_edge_to_hbox(g2, e)\n", "zx.draw(g1, labels=True)" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{66, 68, 134, 137, 95}\n" + "{4: 8, 5: 8, 6: 8, 7: 8, 8: 7, 9: 7, 10: 7, 11: 7, 12: 6, 13: 6, 14: 5, 15: 5, 16: 5, 18: 5, 17: 4, 21: 4, 27: 4, 40: 4, 19: 3, 20: 3, 22: 3, 23: 3, 24: 2, 26: 2, 28: 2, 39: 2, 25: 1, 29: 1, 30: 1, 31: 1, 32: 0, 33: 0, 34: 0}\n" ] + }, + { + "data": { + "text/plain": [ + "{8: {5},\n", + " 9: {4, 5, 6},\n", + " 10: {5, 7},\n", + " 11: {4},\n", + " 12: {4, 7, 8, 9, 10},\n", + " 13: {5, 11},\n", + " 14: {4, 5, 7, 12, 13},\n", + " 15: {6, 7, 13},\n", + " 16: {8, 10, 11, 12, 13},\n", + " 18: {8, 12, 13},\n", + " 17: {6, 7, 8, 9, 10, 14},\n", + " 21: {4, 5, 6, 7, 11, 14, 15, 18},\n", + " 27: {7, 18},\n", + " 40: {4, 5, 7, 9, 12, 13, 15, 20},\n", + " 19: {5, 6, 7, 9, 11, 13, 14, 16, 17, 18},\n", + " 20: {40},\n", + " 22: {7, 8, 9, 10, 11, 12, 13, 15, 17, 18, 21},\n", + " 23: {5, 6, 8, 9, 10, 11, 15, 16, 40},\n", + " 24: {4, 6, 8, 9, 10, 13, 14, 16, 18, 21, 23},\n", + " 26: {6, 8, 9, 10, 14, 18, 19, 22},\n", + " 28: {6, 13, 18, 21, 22, 23, 40},\n", + " 39: {4, 7, 13, 16, 18, 19, 21, 22, 23, 25},\n", + " 25: {39},\n", + " 29: {4, 7, 9, 10, 11, 13, 15, 16, 17, 18, 21, 23, 24, 27},\n", + " 30: {4, 5, 6, 7, 8, 10, 12, 13, 14, 15, 18, 19, 22, 23, 28},\n", + " 31: {5, 6, 12, 13, 16, 17, 21, 24, 26, 40},\n", + " 32: {5, 6, 7, 12, 13, 16, 17, 18, 21, 24, 26, 29, 40},\n", + " 33: {6, 13, 18, 21, 22, 23, 30, 40},\n", + " 34: {5, 9, 11, 14, 16, 17, 18, 21, 22, 23, 26, 29, 39, 40}}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "rank, corr, depth = gflow(g1, delayed=True, pauli=True)\n", - "print(corr[35])" + "o, p = gflow(g1, focus=True, reverse=True, pauli=True)\n", + "print(o)\n", + "p" ] }, { @@ -776,10 +834,45 @@ "execution_count": 9, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{32: 8, 33: 8, 34: 8, 31: 8, 26: 7, 29: 7, 30: 7, 39: 7, 19: 6, 24: 6, 25: 6, 27: 6, 28: 6, 22: 5, 23: 5, 16: 4, 17: 4, 21: 4, 40: 4, 14: 3, 15: 3, 18: 3, 20: 3, 12: 2, 13: 2, 8: 1, 9: 1, 10: 1, 11: 1, 4: 0, 5: 0, 6: 0, 7: 0}\n" + ] + }, { "data": { "text/plain": [ - "{66, 95, 137}" + "{32: {5, 6, 7, 12, 13, 16, 17, 18, 21, 24, 26, 29, 40},\n", + " 34: {5, 9, 11, 14, 16, 17, 18, 21, 22, 23, 26, 29, 39, 40},\n", + " 31: {5, 6, 12, 13, 16, 17, 21, 24, 26, 40},\n", + " 33: {6, 13, 18, 21, 22, 23, 30, 40},\n", + " 25: {39},\n", + " 26: {6, 8, 9, 10, 14, 18, 19, 22},\n", + " 30: {4, 5, 6, 7, 8, 10, 12, 13, 14, 15, 18, 19, 22, 23, 28},\n", + " 39: {4, 7, 13, 16, 18, 19, 21, 22, 23, 25},\n", + " 29: {4, 7, 9, 10, 11, 13, 15, 16, 17, 18, 21, 23, 24, 27},\n", + " 28: {6, 13, 18, 21, 22, 23, 40},\n", + " 24: {4, 6, 8, 9, 10, 13, 14, 16, 18, 21, 23},\n", + " 19: {5, 6, 7, 9, 11, 13, 14, 16, 17, 18},\n", + " 23: {5, 6, 8, 9, 10, 11, 15, 16, 40},\n", + " 22: {7, 8, 9, 10, 11, 12, 13, 15, 17, 18, 21},\n", + " 20: {40},\n", + " 17: {6, 7, 8, 9, 10, 14},\n", + " 21: {4, 5, 6, 7, 11, 14, 15, 18},\n", + " 40: {4, 5, 7, 9, 12, 13, 15, 20},\n", + " 27: {7, 18},\n", + " 14: {4, 5, 7, 12, 13},\n", + " 16: {8, 10, 11, 12, 13},\n", + " 18: {8, 12, 13},\n", + " 15: {6, 7, 13},\n", + " 12: {4, 7, 8, 9, 10},\n", + " 13: {5, 11},\n", + " 9: {4, 5, 6},\n", + " 11: {4},\n", + " 8: {5},\n", + " 10: {5, 7}}" ] }, "execution_count": 9, @@ -788,7 +881,10 @@ } ], "source": [ - "corr[11]" + "o,p = gflow(g1, focus=True, reverse=False, pauli=True)\n", + "pt = transpose(p)\n", + "print(o)\n", + "pt" ] }, {