Skip to content

Commit ba69592

Browse files
authored
Merge pull request #8 from Mathics3/mathics-6.0.0
Mathics 6.0.0
2 parents 438c872 + af55110 commit ba69592

15 files changed

Lines changed: 1437 additions & 1078 deletions

.pre-commit-config.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ repos:
99
stages: [commit]
1010
- id: end-of-file-fixer
1111
stages: [commit]
12-
- id: trailing-whitespace
12+
# - repo: https://github.com/pycqa/isort
13+
# rev: 5.10.1
14+
# hooks:
15+
# - id: isort
16+
# stages: [commit]
1317
- repo: https://github.com/psf/black
1418
rev: 22.3.0
1519
hooks:
1620
- id: black
1721
language_version: python3
1822
exclude: 'pymathics/graph/version.py'
19-
- repo: https://github.com/pycqa/flake8
20-
rev: 3.9.2
21-
hooks:
22-
- id: flake8
23-
stages: [commit]
23+
stages: [commit]
24+
# - repo: https://github.com/pycqa/flake8
25+
# rev: 3.9.2
26+
# hooks:
27+
# - id: flake8
28+
# stages: [commit]

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# remake --tasks to shows the targets and the comments
66

77
GIT2CL ?= admin-tools/git2cl
8-
PYTHON ?= python3
9-
PIP ?= pip3
8+
PYTHON ?= python
9+
PIP ?= $(PYTHON) -m pip
1010
RM ?= rm
1111

1212
.PHONY: all build \
@@ -40,7 +40,7 @@ install: pypi-setup
4040
$(PYTHON) setup.py install
4141

4242
# Run tests
43-
check: pytest doctest
43+
test check: pytest
4444

4545
#: Remove derived files
4646
clean: clean-pyc
@@ -51,7 +51,7 @@ clean-pyc:
5151

5252
#: Run py.test tests. Use environment variable "o" for pytest options
5353
pytest:
54-
py.test test $o
54+
$(PYTHON) -m pytest test $o
5555

5656

5757
# #: Create data that is used to in Django docs and to build TeX PDF

README.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Example Session
88
::
99

1010
$ mathicsscript
11-
Mathicscript: 5.0.0, Mathics 5.0.0
11+
Mathicscript: 5.0.0, Mathics 6.0.0
1212
on CPython 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
1313
using SymPy 1.9, mpmath 1.2.1, numpy 1.21.5
1414
matplotlib 3.5.2,
1515
Asymptote version 2.81
1616

17-
Copyright (C) 2011-2022 The Mathics Team.
17+
Copyright (C) 2011-2023 The Mathics3 Team.
1818
This program comes with ABSOLUTELY NO WARRANTY.
1919
This is free software, and you are welcome to redistribute it
2020
under certain conditions.
@@ -23,7 +23,6 @@ Example Session
2323
Quit by pressing CONTROL-D
2424

2525
In[1]:= LoadModule["pymathics.graph"]
26-
2726
Out[1]= pymathics.graph
2827
In[2]:= BinomialTree[3]
2928
In[3]:= BinomialTree[6]

pymathics/graph/__init__.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,64 @@
1-
"""Pymathics Graph - Working with Graphs (Vertices and Edges)
1+
"""
2+
Graphs - Vertices and Edges
23
3-
This module provides functions and variables for workting with
4-
graphs.
4+
A Pymathics module that provides functions and variables for working with graphs.
55
66
Example:
77
In[1]:= LoadModule["pymathics.graph"]
88
Out[1]= pymathics.graph
99
In[2]:= BinomialTree[3]
1010
In[3]:= BinomialTree[6]
1111
In[4]:= CompleteKaryTree[3, VertexLabels->True]
12+
13+
Networkx does the heavy lifting here.
1214
"""
1315

14-
from pymathics.graph.__main__ import * # noqa
16+
from pymathics.graph.base import (
17+
AcyclicGraphQ,
18+
BetweennessCentrality,
19+
ClosenessCentrality,
20+
ConnectedGraphQ,
21+
DegreeCentrality,
22+
DirectedEdge,
23+
DirectedGraphQ,
24+
EdgeConnectivity,
25+
EdgeIndex,
26+
EdgeList,
27+
EdgeRules,
28+
EigenvectorCentrality,
29+
FindShortestPath,
30+
FindVertexCut,
31+
Graph,
32+
GraphBox,
33+
HITSCentrality,
34+
HighlightGraph,
35+
KatzCentrality,
36+
LoopFreeGraphQ,
37+
MixedGraphQ,
38+
MultigraphQ,
39+
PageRankCentrality,
40+
PlanarGraphQ,
41+
PathGraphQ,
42+
Property,
43+
PropertyValue,
44+
SimpleGraphQ,
45+
UndirectedEdge,
46+
VertexAdd,
47+
VertexConnectivity,
48+
VertexDelete,
49+
VertexIndex,
50+
VertexList,
51+
)
52+
53+
from pymathics.graph.measures_and_metrics import EdgeCount, VertexCount, VertexDegree
54+
1555
from pymathics.graph.algorithms import * # noqa
1656
from pymathics.graph.generators import * # noqa
1757
from pymathics.graph.tree import * # noqa
1858
from pymathics.graph.version import __version__ # noqa
1959

2060
pymathics_version_data = {
21-
"author": "The Mathics Team",
61+
"author": "The Mathics3 Team",
2262
"version": __version__,
2363
"name": "Graph",
2464
"requires": ["networkx"],

pymathics/graph/algorithms.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
Algorithms on Graphs.
4-
5-
networkx does all the heavy lifting.
3+
Algorithms on Graphs
64
"""
75

6+
from typing import Optional
7+
88
from mathics.core.convert.expression import to_mathics_list
99
from mathics.core.convert.python import from_python
10+
from mathics.core.evaluation import Evaluation
1011
from mathics.core.expression import Expression
1112
from mathics.core.list import ListExpression
1213
from mathics.core.symbols import SymbolFalse
1314
from mathics.core.systemsymbols import SymbolDirectedInfinity
1415

15-
from pymathics.graph.__main__ import (
16+
from pymathics.graph.base import (
1617
DEFAULT_GRAPH_OPTIONS,
1718
SymbolDirectedEdge,
1819
SymbolUndirectedEdge,
@@ -25,7 +26,7 @@
2526
class ConnectedComponents(_NetworkXBuiltin):
2627
"""
2728
## >> g = Graph[{1 -> 2, 2 -> 3, 3 <-> 4}]; ConnectedComponents[g]
28-
## = {{4, 3}, {2}, {1}}
29+
## = {{3, 4}, {2}, {1}}
2930
3031
## >> g = Graph[{1 -> 2, 2 -> 3, 3 -> 1}]; ConnectedComponents[g]
3132
## = {{1, 2, 3}}
@@ -34,7 +35,9 @@ class ConnectedComponents(_NetworkXBuiltin):
3435
## = {{4, 5}, {1, 2, 3}}
3536
"""
3637

37-
def apply(self, graph, expression, evaluation, options):
38+
def eval(
39+
self, graph, expression, evaluation: Evaluation, options: dict
40+
) -> Optional[ListExpression]:
3841
"ConnectedComponents[graph_, OptionsPattern[%(name)s]]"
3942
graph = self._build_graph(graph, evaluation, options, expression)
4043
if graph:
@@ -54,10 +57,10 @@ def apply(self, graph, expression, evaluation, options):
5457
# <dd>returns a Hamiltonian path in the given tournament graph.
5558
# </dl>
5659
# """
57-
# def apply_(self, graph, expression, evaluation, options):
58-
# "%(name)s[graph_, OptionsPattern[%(name)s]]"
60+
# def eval_(self, graph, expression, evaluation: Evaluation, options):
61+
# "FindHamiltonianPath[graph_, OptionsPattern[FindHamiltonPath]]"
5962

60-
# graph = self._build_graph(graph, evaluation, options, expression)
63+
# graph = self._build_graph(graph, evaluation: Evaluation, options, expression)
6164
# if graph:
6265
# # FIXME: for this to work we need to fill in all O(n^2) edges as an adjacency matrix?
6366
# path = nx.algorithms.tournament.hamiltonian_path(graph.G)
@@ -106,17 +109,19 @@ class GraphDistance(_NetworkXBuiltin):
106109
= GraphDistance[{1 -> 2}, 3, 4]
107110
"""
108111

109-
def apply_s(self, graph, s, expression, evaluation, options):
110-
"%(name)s[graph_, s_, OptionsPattern[%(name)s]]"
112+
def eval_s(
113+
self, graph, s, expression, evaluation: Evaluation, options: dict
114+
) -> Optional[ListExpression]:
115+
"GraphDistance[graph_, s_, OptionsPattern[GraphDistance]]"
111116
graph = self._build_graph(graph, evaluation, options, expression)
112117
if graph:
113118
weight = graph.update_weights(evaluation)
114119
d = nx.shortest_path_length(graph.G, source=s, weight=weight)
115120
inf = Expression(SymbolDirectedInfinity, 1)
116121
return to_mathics_list(*[d.get(v, inf) for v in graph.vertices])
117122

118-
def apply_s_t(self, graph, s, t, expression, evaluation, options):
119-
"%(name)s[graph_, s_, t_, OptionsPattern[%(name)s]]"
123+
def eval_s_t(self, graph, s, t, expression, evaluation: Evaluation, options: dict):
124+
"GraphDistance[graph_, s_, t_, OptionsPattern[GraphDistance]]"
120125
graph = self._build_graph(graph, evaluation, options, expression)
121126
if not graph:
122127
return
@@ -147,7 +152,7 @@ class FindSpanningTree(_NetworkXBuiltin):
147152

148153
options = DEFAULT_GRAPH_OPTIONS
149154

150-
def apply(self, graph, expression, evaluation, options):
155+
def eval(self, graph, expression, evaluation: Evaluation, options: dict):
151156
"%(name)s[graph_, OptionsPattern[%(name)s]]"
152157
graph = self._build_graph(graph, evaluation, options, expression)
153158
if graph:
@@ -182,8 +187,8 @@ class PlanarGraphQ(_NetworkXBuiltin):
182187

183188
options = DEFAULT_GRAPH_OPTIONS
184189

185-
def apply(self, graph, expression, evaluation, options):
186-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
190+
def eval(self, graph, expression, evaluation: Evaluation, options: dict):
191+
"PlanarGraphQ[graph_, OptionsPattern[PlanarGraphQ]]"
187192
graph = self._build_graph(graph, evaluation, options, expression)
188193
if not graph:
189194
return SymbolFalse
@@ -203,8 +208,8 @@ class WeaklyConnectedComponents(_NetworkXBuiltin):
203208
= {{1, 2, 3, 4, 5}, {6, 7, 8}}
204209
"""
205210

206-
def apply(self, graph, expression, evaluation, options):
207-
"WeaklyConnectedComponents[graph_, OptionsPattern[%(name)s]]"
211+
def eval(self, graph, expression, evaluation: Evaluation, options):
212+
"WeaklyConnectedComponents[graph_, OptionsPattern[WeaklyConnectedComponents]]"
208213
graph = self._build_graph(graph, evaluation, options, expression)
209214
if graph:
210215
components = nx.connected_components(graph.G.to_undirected())

0 commit comments

Comments
 (0)