From ad664d28a17e11b8f963903d9f24a59a20764d9f Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 25 Nov 2024 11:27:04 -0500 Subject: [PATCH 1/2] Redo DirectedEdge and UnirectedEdge as operators --- .github/workflows/ubuntu.yml | 4 ++-- pymathics/graph/base.py | 30 +++++++++++++++++------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index c8cdb0d..fb6f057 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -23,10 +23,10 @@ jobs: python -m pip install --upgrade pip python -m pip install pytest # Can comment out when next Mathics core and Mathics-scanner are released - # python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full] + python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full] python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full] python -m pip install -e . - # (cd src/mathics3 && bash ./admin-tools/make-op-tables.sh) + (cd src/mathics3 && bash ./admin-tools/make-op-tables.sh) - name: install pymathics graph run: | make develop diff --git a/pymathics/graph/base.py b/pymathics/graph/base.py index 59e7daa..211532d 100644 --- a/pymathics/graph/base.py +++ b/pymathics/graph/base.py @@ -10,6 +10,11 @@ from inspect import isgenerator from typing import Callable, Optional, Union +from mathics.builtin.no_meaning import ( + DirectedEdge as GenericDirectedEdge, + UndirectedEdge as GenericUndirectedEdge, +) +from mathics.core.attributes import A_PROTECTED, A_READ_PROTECTED from mathics.core.builtin import AtomBuiltin, Builtin from mathics.core.atoms import Atom, Integer, Integer0, Integer1, Integer2, String from mathics.core.convert.expression import ListExpression, from_python, to_mathics_list @@ -893,8 +898,8 @@ def neighbors(v): return self._retrieve(graph, what, neighbors, expression, evaluation) -class DirectedEdge(Builtin): - """ +class DirectedEdge(GenericDirectedEdge): + r""" Edge of a :Directed graph: https://en.wikipedia.org/wiki/Directed_graph ( @@ -908,9 +913,15 @@ class DirectedEdge(Builtin):
'DirectedEdge[$u$, $v$]'
create a directed edge from $u$ to $v$. + + >> DirectedEdge[x, y, z] + = x → y → z + + >> a \[DirectedEdge] b + = a → b """ - summary_text = "make a directed graph edge" + attributes = A_PROTECTED | A_READ_PROTECTED class EdgeConnectivity(_NetworkXBuiltin): @@ -1494,7 +1505,7 @@ def _items(self, graph): return graph.vertices -class UndirectedEdge(Builtin): +class UndirectedEdge(GenericUndirectedEdge): """ :WMA link: @@ -1506,17 +1517,10 @@ class UndirectedEdge(Builtin): >> a <-> b - = UndirectedEdge[a, b] - - >> (a <-> b) <-> c - = UndirectedEdge[UndirectedEdge[a, b], c] - - >> a <-> (b <-> c) - = UndirectedEdge[a, UndirectedEdge[b, c]] + = ... """ - summary_text = "undirected graph edge" - pass + attributes = A_PROTECTED | A_READ_PROTECTED # class EdgeAdd(_NetworkXBuiltin): From f482ed87a5a3ef80db093ffe5cd34c5a7cfe00b9 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 25 Nov 2024 11:33:03 -0500 Subject: [PATCH 2/2] NetworkX random_tree -> random_labelled_tree random_tree is deprecated in NetworkX --- pymathics/graph/parametric.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pymathics/graph/parametric.py b/pymathics/graph/parametric.py index acb76ca..b28b6dd 100644 --- a/pymathics/graph/parametric.py +++ b/pymathics/graph/parametric.py @@ -579,7 +579,7 @@ class RandomTree(_NetworkXBuiltin): """ :NetworkX: https://networkx.org/documentation/networkx-2.8.8/reference\ -/generated/networkx.generators.trees.random_tree.html, +/generated/networkx.generators.trees.random_labeled_tree.html, :WMA: https://reference.wolfram.com/language/ref/RandomTree.html @@ -610,7 +610,9 @@ def eval( return args = (py_n,) - g = graph_helper(nx.random_tree, options, False, "tree", evaluation, 0, *args) + g = graph_helper( + nx.random_labeled_tree, options, False, "tree", evaluation, 0, *args + ) if not g: return None g.G.n = n