Skip to content

Commit

Permalink
Reformat codebase using 'ruff format'
Browse files Browse the repository at this point in the history
  • Loading branch information
bknueven committed Sep 18, 2024
1 parent 59d807c commit 710da08
Show file tree
Hide file tree
Showing 220 changed files with 20,161 additions and 14,851 deletions.
86 changes: 43 additions & 43 deletions doc/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../../examples/distr'))
sys.path.insert(0, os.path.abspath('../../examples/stoch_distr'))
sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, os.path.abspath("../../examples/distr"))
sys.path.insert(0, os.path.abspath("../../examples/stoch_distr"))


# -- General configuration ------------------------------------------------
Expand All @@ -42,45 +42,47 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx.ext.ifconfig',
'sphinx.ext.inheritance_diagram',
'sphinx.ext.autosummary',
'sphinx.ext.doctest']
#'sphinx.ext.githubpages']
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.coverage",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx.ext.ifconfig",
"sphinx.ext.inheritance_diagram",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
]
#'sphinx.ext.githubpages']

viewcode_import = True
#napoleon_include_private_with_doc = True
# napoleon_include_private_with_doc = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The root toctree document.
root_doc = 'index'
root_doc = "index"

# General information about the project.
project = u'mpi-sppy'
copyright = u'2020-2024'
author = u'mpi-sppy Developers'
project = "mpi-sppy"
copyright = "2020-2024"
author = "mpi-sppy Developers"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.12.2'
version = "0.12.2"
# The full version, including alpha/beta/rc tags.
release = '0.12.2.dev0'
release = "0.12.2.dev0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -92,10 +94,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -107,8 +109,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

html_theme = "sphinx_rtd_theme"


# Theme options are theme-specific and customize the look and feel of a theme
Expand All @@ -120,15 +121,15 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
#html_static_path = ['_static']
# html_static_path = ['_static']

#html_favicon = "../logos/pyomo/favicon.ico"
# html_favicon = "../logos/pyomo/favicon.ico"


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'mpi-sppy'
htmlhelp_basename = "mpi-sppy"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -137,15 +138,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -155,19 +153,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(root_doc, 'mpisppy.tex', 'mpisppy Documentation',
'mpisppy', 'manual'),
(root_doc, "mpisppy.tex", "mpisppy Documentation", "mpisppy", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(root_doc, 'mpisppy', 'mpisppy Documentation',
[author], 1)
]
man_pages = [(root_doc, "mpisppy", "mpisppy Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -176,10 +170,16 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(root_doc, 'mpisppy', 'mpisppy Documentation',
author, 'mpisppy', 'One line description of project.',
'Miscellaneous'),
(
root_doc,
"mpisppy",
"mpisppy Documentation",
author,
"mpisppy",
"One line description of project.",
"Miscellaneous",
),
]

#autodoc_member_order = 'bysource'
#autodoc_member_order = 'groupwise'
# autodoc_member_order = 'bysource'
# autodoc_member_order = 'groupwise'
99 changes: 59 additions & 40 deletions examples/acopf3/ACtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md for
# full copyright and license information.
###############################################################################
#Tree ideas; dlw Fall 2019
# Tree ideas; dlw Fall 2019
# Stage numbers and scenario numbers are one-based, but lists are all zero-based
# Tree node numbers used in node names are zero-based.
# NOTE: we *do* have leaf nodes, but mpisppy just completes the scen with them
Expand All @@ -16,9 +16,11 @@
import numpy as np
import copy


def FixFast(minutes):
return True


"""
At each scenario tree node:
a link can fail and/or
Expand All @@ -28,7 +30,8 @@ def FixFast(minutes):
"""

class ACTree():

class ACTree:
"""
Data for a scenario tree for ACOPF.
Expand All @@ -42,8 +45,18 @@ class ACTree():
Repairer (function with argument t in minutes) returns True for repair
LineList (list of int) All lines in the electric grid
"""
def __init__(self, NumStages, BFs, seed, acstream, FailProb,
StageDurations, Repairer, LineList):

def __init__(
self,
NumStages,
BFs,
seed,
acstream,
FailProb,
StageDurations,
Repairer,
LineList,
):
self.NumStages = NumStages
self.BFs = BFs
self.seed = seed
Expand All @@ -54,45 +67,46 @@ def __init__(self, NumStages, BFs, seed, acstream, FailProb,
self.LineList = LineList

self.numscens = 1
for s in range(self.NumStages-1):
for s in range(self.NumStages - 1):
self.numscens *= self.BFs[s]

# now make the tree by making the root
self.rootnode = TreeNode(None, self,
[i+1 for i in range(self.numscens)],
"ROOT", 1.0, acstream)
self.rootnode = TreeNode(
None, self, [i + 1 for i in range(self.numscens)], "ROOT", 1.0, acstream
)

def Nodes_for_Scenario(self, scen_num):
"""
Return a list of nodes for a given scenario number (one-based)
"""
assert(scen_num <= self.numscens)
assert scen_num <= self.numscens
retlist = [self.rootnode]
# There must be a clever arithmetic way to do this, but...
for stage in range(2, self.NumStages+1):
for stage in range(2, self.NumStages + 1):
for kid in retlist[-1].kids:
if scen_num in kid.ScenarioList:
retlist.append(kid)
break
assert(len(retlist) == self.NumStages)
assert len(retlist) == self.NumStages
return retlist

def All_Nodenames(self):
""" Return a list of all node names"""
"""Return a list of all node names"""

# there is a arithmetic way, but I will use the general tree way
def _progenynames(node):
# return my name and progeny names if they are not leaves
retval = [node.Name]
if node.stage < self.NumStages: # include leaves
if node.stage < self.NumStages: # include leaves
for kid in node.kids:
retval += _progenynames(kid)
return retval

allnames = _progenynames(self.rootnode)
return allnames
class TreeNode():


class TreeNode:
"""
Data for a tree node, but the node creates its own children
Expand All @@ -109,9 +123,9 @@ class TreeNode():
kids (list of nodes) the children of this node
"""
def __init__(self, Parent, TreeInfo, ScenarioList, Name, CondProb, acstream):

self.sn = 1 # to attach serial numbers where needed
def __init__(self, Parent, TreeInfo, ScenarioList, Name, CondProb, acstream):
self.sn = 1 # to attach serial numbers where needed
self.CondProb = CondProb
self.Name = Name
self.Parent = Parent
Expand All @@ -122,7 +136,7 @@ def __init__(self, Parent, TreeInfo, ScenarioList, Name, CondProb, acstream):
self.FailedLines = []
self.LinesUp = copy.deepcopy(TreeInfo.LineList)
else:
self.stage = Parent.stage+1
self.stage = Parent.stage + 1
self.FailedLines = copy.deepcopy(Parent.FailedLines)
self.LinesUp = copy.deepcopy(Parent.LinesUp)
# bring lines up? (mo is minutes out)
Expand All @@ -133,7 +147,7 @@ def __init__(self, Parent, TreeInfo, ScenarioList, Name, CondProb, acstream):
removals.append((line, mo))
self.LinesUp.append(line)
else:
mo += TreeInfo.StageDurations[self.stage-1]
mo += TreeInfo.StageDurations[self.stage - 1]
self.FailedLines[ell] = (line, mo)
for r in removals:
self.FailedLines.remove(r)
Expand All @@ -142,28 +156,32 @@ def __init__(self, Parent, TreeInfo, ScenarioList, Name, CondProb, acstream):
for line in self.LinesUp:
if acstream.rand() < TreeInfo.FailProb:
self.LinesUp.remove(line)
self.FailedLines.append\
((line, TreeInfo.StageDurations[self.stage-1]))
self.FailedLines.append(
(line, TreeInfo.StageDurations[self.stage - 1])
)
if self.stage <= TreeInfo.NumStages:
# spawn children
self.kids = []
if self.stage < TreeInfo.NumStages:
bf = TreeInfo.BFs[self.stage-1]
self.sn += 1 # serial number for non-leaf, non-ROOT nodes
bf = TreeInfo.BFs[self.stage - 1]
self.sn += 1 # serial number for non-leaf, non-ROOT nodes
else:
bf = 1 # leaf node
for b in range(bf):
# divide up the scenario list
plist = self.ScenarioList # typing aid
first = b*len(plist) // bf
last = (b+1)*len(plist) // bf
scenlist = plist[first: last]
plist = self.ScenarioList # typing aid
first = b * len(plist) // bf
last = (b + 1) * len(plist) // bf
scenlist = plist[first:last]
newname = self.Name + "_" + str(b)
if self.stage < TreeInfo.NumStages:
prevbf = TreeInfo.BFs[self.stage-2]
self.kids.append(TreeNode(self, TreeInfo, scenlist,
newname, 1/prevbf, acstream))

prevbf = TreeInfo.BFs[self.stage - 2]
self.kids.append(
TreeNode(
self, TreeInfo, scenlist, newname, 1 / prevbf, acstream
)
)

def pprint(self):
print("Node Name={}, Stage={}".format(self.Name, self.stage))
if self.Parent is not None:
Expand All @@ -172,14 +190,15 @@ def pprint(self):
print(" (no parent)")
print(" FailedLines={}".format(self.FailedLines))

if __name__ == "__main__":

if __name__ == "__main__":
acstream = np.random.RandomState()

testtree = ACTree(3, [2, 2], 1134, acstream,
0.2, [5,15,30], FixFast, [0,1,2,3,4,5])
for sn in range(1,testtree.numscens+1):
print ("nodes in scenario {}".format(sn))

testtree = ACTree(
3, [2, 2], 1134, acstream, 0.2, [5, 15, 30], FixFast, [0, 1, 2, 3, 4, 5]
)
for sn in range(1, testtree.numscens + 1):
print("nodes in scenario {}".format(sn))
for node in testtree.Nodes_for_Scenario(sn):
# print (" ",node.Name)
# print(" ", node.FailedLines)
Expand Down
Loading

0 comments on commit 710da08

Please sign in to comment.