Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Dec 12, 2023
2 parents 0eb482e + dceac5f commit 38d2534
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 150 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/consistency-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
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]
git clone https://github.com/Mathics3/mathics-core
(cd mathics-core && make)
(cd mathics-core && python -m pip install -e .[full])
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
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]
(cd src/mathics3 && bash ./admin-tools/make-op-tables.sh)
# python -m pip install Mathics3[full]
python -m pip install -e .
- name: install pymathics graph
run: |
make develop
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*~
/.hypothesis
/.python-version
/ChangeLog
/build
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pytest:

#: Run tests that appear in docstring in the code.
doctest:
MATHICS_CHARACTER_ENCODING="ASCII" $(PYTHON) -m mathics.docpipeline -l pymathics.graph $o
MATHICS_CHARACTER_ENCODING="ASCII" $(PYTHON) -m mathics.docpipeline -l pymathics.graph -c 'Graphs - Vertices and Edges' $o

# #: Make Mathics PDF manual
# doc mathics.pdf: mathics/doc/tex/data
Expand Down
19 changes: 19 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
6.0.0
-----

Revise for 6.0.0 Mathics3 API and current Mathics3 builtin standards
described in [Guidelines for Writing
Documentation](https://mathics-development-guide.readthedocs.io/en/latest/extending/developing-code/extending/documentation-markup.html#guidelines-for-writing-documentation).

This package has undergone a major overhaul. Modules have been split out along into logical groups following the documentation structure.

We have gradually been rolling in more Python type annotations and
have been using current Python practices. Tools such as using
``isort``, ``black`` and ``flake8`` are used as well.

Evaluation methods of built-in functions start ``eval_`` not
``apply_``.

There is more refactoring more to do here, Upgrade to NetworkX is also
desirable.

5.0.0.alpha0
------------

Expand Down
2 changes: 1 addition & 1 deletion admin-tools/pyenv-versions
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ if [[ $0 == ${BASH_SOURCE[0]} ]] ; then
echo "This script should be *sourced* rather than run directly through bash"
exit 1
fi
export PYVERSIONS='3.6.13 3.7.13 3.8.13 3.9.13 3.10.5'
export PYVERSIONS='3.6.15 3.7.16 3.8.16 3.9.16 3.10.10'
70 changes: 30 additions & 40 deletions pymathics/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from mathics.core.convert.expression import ListExpression, from_python, to_mathics_list
from mathics.core.element import BaseElement
from mathics.core.expression import Expression
from mathics.core.pattern import pattern_objects
from mathics.core.symbols import Symbol, SymbolList, SymbolTrue
from mathics.core.systemsymbols import (
SymbolBlank,
Expand Down Expand Up @@ -81,7 +82,7 @@ def graph_helper(
graph_generator_func: Callable,
options: dict,
can_digraph: bool,
graph_layout: str,
graph_layout: Optional[str],
evaluation,
root: Optional[int] = None,
*args,
Expand Down Expand Up @@ -124,7 +125,7 @@ def graph_helper(


def has_directed_option(options: dict) -> bool:
return options.get("System`DirectedEdges", False).to_python()
return options.get("System`DirectedEdges", False)


def _process_graph_options(g, options: dict) -> None:
Expand Down Expand Up @@ -173,15 +174,15 @@ def _process_graph_options(g, options: dict) -> None:


def _circular_layout(G):
return nx.drawing.circular_layout(G, scale=1.5)
return nx.drawing.circular_layout(G, scale=1)


def _spectral_layout(G):
return nx.drawing.spectral_layout(G, scale=2.0)
return nx.drawing.spectral_layout(G, scale=2)


def _shell_layout(G):
return nx.drawing.shell_layout(G, scale=2.0)
return nx.drawing.shell_layout(G, scale=2)


def _generic_layout(G, warn):
Expand Down Expand Up @@ -840,7 +841,6 @@ class AdjacencyList(_NetworkXBuiltin):
matching $pattern$.
</dl>
>> LoadModule["pymathics.graph"];
>> AdjacencyList[{1 -> 2, 2 -> 3}, 3]
= {2}
Expand All @@ -854,8 +854,6 @@ class AdjacencyList(_NetworkXBuiltin):
summary_text = "list the adjacent vertices"

def _retrieve(self, graph, what, neighbors, expression, evaluation):
from mathics.core.pattern import pattern_objects

if what.get_head_name() in pattern_objects:
collected = set()
match = Matcher(what).match
Expand Down Expand Up @@ -897,12 +895,11 @@ def neighbors(v):

class DirectedEdge(Builtin):
"""
<url>
:Directed edge:
Edge of a <url>
:Directed graph:
https://en.wikipedia.org/wiki/Directed_graph</url> (<url>
:NetworkX:
https://networkx.org/documentation/networkx-2.8.8/reference/classes/digraph.html</url>,
<url>
https://networkx.org/documentation/networkx-2.8.8/reference/classes/digraph.html</url>, <url>
:WMA:
https://reference.wolfram.com/language/ref/DirectedEdge.html</url>)
Expand All @@ -920,11 +917,10 @@ class EdgeConnectivity(_NetworkXBuiltin):
"""
<url>
:Edge connectivity:
https://en.wikipedia.org/wiki/Directed_graph</url> (<url>
https://en.wikipedia.org/wiki/Directed_graph#Directed_graph_connectivity</url> (<url>
:NetworkX:
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms/\
generated/networkx.algorithms.connectivity.connectivity.edge_connectivity.html</url>,
<url>
generated/networkx.algorithms.connectivity.connectivity.edge_connectivity.html</url>, <url>
:WMA:
https://reference.wolfram.com/language/ref/EdgeConnectivity.html</url>)
Expand Down Expand Up @@ -970,7 +966,7 @@ def eval_st(self, graph, s, t, expression, evaluation, options):
class EdgeIndex(_NetworkXBuiltin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/EdgeIndex.html</url>
<dl>
Expand Down Expand Up @@ -998,7 +994,7 @@ def eval(self, graph, v, expression, evaluation, options):
class EdgeList(_PatternList):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/EdgeList.html</url>
<dl>
Expand All @@ -1016,7 +1012,7 @@ def _items(self, graph):
class EdgeRules(_NetworkXBuiltin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/EdgeRules.html</url>
<dl>
Expand Down Expand Up @@ -1048,8 +1044,7 @@ class FindShortestPath(_NetworkXBuiltin):
https://en.wikipedia.org/wiki/Shortest_path_problem</url> (<url>
:NetworkX:
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms\
/generated/networkx.algorithms.shortest_paths.generic.shortest_path.html</url>,
<url>
/generated/networkx.algorithms.shortest_paths.generic.shortest_path.html</url>, <url>
:WMA:
https://reference.wolfram.com/language/ref/FindShortestPath.html</url>)
Expand Down Expand Up @@ -1083,7 +1078,7 @@ class FindShortestPath(_NetworkXBuiltin):
summary_text = "find the shortest path between two vertices"

def eval_s_t(self, graph, s, t, expression, evaluation, options):
"%(name)s[graph_, s_, t_, OptionsPattern[%(name)s]]"
"FindShortestPath[graph_, s_, t_, OptionsPattern[FindShortestPath]]"
graph = self._build_graph(graph, evaluation, options, expression)
if not graph:
return
Expand Down Expand Up @@ -1169,8 +1164,7 @@ def eval_st(self, graph, s, t, expression, evaluation, options):

class GraphAtom(AtomBuiltin):
"""
<url>:Graph:https://en.wikipedia.org/wiki/graph</url> (
<url>:WMA:
<url>:Graph:https://en.wikipedia.org/wiki/graph</url> (<url>:WMA:
https://reference.wolfram.com/language/ref/Graph.html</url>)
<dl>
<dt>'Graph[{$e1, $e2, ...}]'
Expand Down Expand Up @@ -1224,7 +1218,7 @@ def eval_1(self, vertices, edges, evaluation, options):
class HighlightGraph(_NetworkXBuiltin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/HighlightGraph.html</url>
<dl>
Expand Down Expand Up @@ -1264,7 +1258,7 @@ def parse(item):
class Property(Builtin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/Property.html</url>
<dl>
Expand All @@ -1280,7 +1274,7 @@ class Property(Builtin):
class PropertyValue(Builtin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/PropertyValue.html</url>
<dl>
Expand Down Expand Up @@ -1323,7 +1317,7 @@ def eval(self, graph, item, name, evaluation):
class VertexAdd(_NetworkXBuiltin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/VertexAdd.html</url>
<dl>
Expand All @@ -1343,7 +1337,7 @@ class VertexAdd(_NetworkXBuiltin):
summary_text = "add a vertex"

def eval(self, graph: Expression, what, expression, evaluation, options):
"%(name)s[graph_, what_, OptionsPattern[%(name)s]]"
"VertexAdd[graph_, what_, OptionsPattern[VertexAdd]]"
mathics_graph = self._build_graph(graph, evaluation, options, expression)
if mathics_graph:
if what.get_head_name() == "System`List":
Expand All @@ -1357,7 +1351,7 @@ def eval(self, graph: Expression, what, expression, evaluation, options):
class VertexConnectivity(_NetworkXBuiltin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/VertexConnectivity.html</url>
<dl>
Expand Down Expand Up @@ -1408,7 +1402,7 @@ def eval_st(self, graph, s, t, expression, evaluation, options):
class VertexDelete(_NetworkXBuiltin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/VertexDelete.html</url>
<dl>
Expand All @@ -1431,8 +1425,6 @@ def eval(self, graph, what, expression, evaluation, options) -> Optional[Graph]:
"VertexDelete[graph_, what_, OptionsPattern[VertexDelete]]"
graph = self._build_graph(graph, evaluation, options, expression)
if graph:
from mathics.core.pattern import pattern_objects

head_name = what.get_head_name()
if head_name in pattern_objects:
cases = Expression(
Expand All @@ -1449,7 +1441,7 @@ def eval(self, graph, what, expression, evaluation, options) -> Optional[Graph]:
class VertexIndex(_NetworkXBuiltin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/VertexIndex.html</url>
<dl>
<dt>'VertexIndex'['g', 'v']
Expand Down Expand Up @@ -1477,7 +1469,7 @@ def eval(self, graph, v, expression, evaluation, options):
class VertexList(_PatternList):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/VertexList.html</url>
<dl>
<dt>'VertexList[$edgelist$]'
Expand All @@ -1495,7 +1487,7 @@ class VertexList(_PatternList):
= {10}
"""

summary_text = "list the vertex"
summary_text = "list the vertices of a graph"

def _items(self, graph):
return graph.vertices
Expand All @@ -1504,7 +1496,7 @@ def _items(self, graph):
class UndirectedEdge(Builtin):
"""
<url>
:WMA:
:WMA link:
https://reference.wolfram.com/language/ref/UndirectedEdge.html</url>
<dl>
Expand Down Expand Up @@ -1544,9 +1536,9 @@ class UndirectedEdge(Builtin):

class EdgeDelete(_NetworkXBuiltin):
"""
<url>
Delete an Edge (<url>
:WMA:
https://reference.wolfram.com/language/ref/EdgeDelete.html</url>
https://reference.wolfram.com/language/ref/EdgeDelete.html</url>)
<dl>
<dt>'EdgeDelete'[$g$, $edge$]
Expand All @@ -1572,8 +1564,6 @@ def eval(self, graph, what, expression, evaluation, options) -> Optional[Graph]:
"EdgeDelete[graph_, what_, OptionsPattern[EdgeDelete]]"
graph = self._build_graph(graph, evaluation, options, expression)
if graph:
from mathics.core.pattern import pattern_objects

head_name = what.get_head_name()
if head_name in pattern_objects:
cases = Expression(
Expand Down
3 changes: 3 additions & 0 deletions pymathics/graph/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

from pymathics.graph.graphsymbols import SymbolDirectedEdge

# There is no user-facing documentation here.
no_doc = True


def _count_edges(counts, edges, sign):
n_directed, n_undirected = counts
Expand Down
Loading

0 comments on commit 38d2534

Please sign in to comment.