Skip to content

Commit

Permalink
sagemathgh-37410: minor fixes in sandpiles
Browse files Browse the repository at this point in the history
Just fixing a few `ruff` warnings in the two modified files, plus some
`pep8` code formatting.

Also a few code simplifications on the way.

I also changed some errors from `UserWarning` to better ones.

and changed one function, used nowhere inside sage, into an iterator

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.

URL: sagemath#37410
Reported by: Frédéric Chapoton
Reviewer(s): Matthias Köppe
  • Loading branch information
Release Manager committed Feb 22, 2024
2 parents 57d4e09 + 73b17c3 commit 0fb793f
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 119 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=0c93ffbc40ee55c429b82c6070817c0133a05013
md5=96e8d0c3aa48cab18b60499c4d303a73
cksum=2523075193
sha1=cebcfe9542c5aa28fd27329786ec7ceb53c4b18b
md5=83b5e5a5ad023e6266626dfde92f5969
cksum=383438152
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
81a374dc4dacba71cf071f981d496ff63b2b2acb
f531179bcd7b18e31291000415f0d076538a0802
30 changes: 16 additions & 14 deletions src/sage/sandpiles/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from sage.sandpiles.sandpile import Sandpile
from sage.graphs.graph_generators import graphs

class SandpileExamples():

class SandpileExamples:
"""
Some examples of sandpiles.
Expand Down Expand Up @@ -92,7 +93,7 @@ def Complete(self, n):
sage: sandpiles.Complete(3) == sandpiles.Cycle(3)
True
"""
return Sandpile(graphs.CompleteGraph(n),0)
return Sandpile(graphs.CompleteGraph(n), 0)

def Cycle(self, n):
"""
Expand All @@ -119,7 +120,7 @@ def Cycle(self, n):
(3, 0, 1),
(3, 2, 1)]
"""
return Sandpile(graphs.CycleGraph(n),0)
return Sandpile(graphs.CycleGraph(n), 0)

def Diamond(self):
"""
Expand Down Expand Up @@ -164,18 +165,18 @@ def Fan(self, n, deg_three_verts=False):
"""
f = graphs.WheelGraph(n)
if n > 2:
f.delete_edge(1,n-1)
f.delete_edge(1, n-1)
if deg_three_verts:
f.allow_multiple_edges(True)
f.add_edges([(0,1),(0,n-1)])
return Sandpile(f,0)
f.add_edges([(0, 1), (0, n-1)])
return Sandpile(f, 0)
elif n == 1:
return Sandpile(f,0)
return Sandpile(f, 0)
elif n == 2:
if deg_three_verts:
return Sandpile({0:{1:3}, 1:{0:3}})
return Sandpile({0: {1: 3}, 1: {0: 3}})
else:
return Sandpile(f,0)
return Sandpile(f, 0)

def Grid(self, m, n):
"""
Expand All @@ -200,11 +201,12 @@ def Grid(self, m, n):
sage: s.dict()
{(0, 0): {(1, 1): 4}, (1, 1): {(0, 0): 4}}
"""
G = graphs.Grid2dGraph(m+2,n+2)
G = graphs.Grid2dGraph(m+2, n+2)
G.allow_multiple_edges(True) # to ensure each vertex ends up with degree 4
V = [(i,j) for i in [0,m+1] for j in range(n+2)] + [(i,j) for j in [0,n+1] for i in range(m+2)]
V = [(i, j) for i in [0, m+1] for j in range(n+2)]
V += [(i, j) for j in [0, n+1] for i in range(m+2)]
G.merge_vertices(V)
return Sandpile(G, (0,0))
return Sandpile(G, (0, 0))

def House(self):
"""
Expand All @@ -224,7 +226,7 @@ def House(self):
sage: s.invariant_factors()
[1, 1, 1, 11]
"""
return Sandpile(graphs.HouseGraph(),0)
return Sandpile(graphs.HouseGraph(), 0)

def Wheel(self, n):
"""
Expand All @@ -244,7 +246,7 @@ def Wheel(self, n):
sage: w.invariant_factors()
[1, 1, 1, 11, 11]
"""
return Sandpile(graphs.WheelGraph(n),0)
return Sandpile(graphs.WheelGraph(n), 0)


sandpiles = SandpileExamples()
Loading

0 comments on commit 0fb793f

Please sign in to comment.