diff --git a/examples/kitchen_sink.py b/examples/kitchen_sink.py index c1bd730..eba5e62 100644 --- a/examples/kitchen_sink.py +++ b/examples/kitchen_sink.py @@ -1,4 +1,17 @@ -from pyxdsm.XDSM import XDSM, OPT, SUBOPT, SOLVER, DOE, IFUNC, FUNC, GROUP, IGROUP, METAMODEL +from pyxdsm.XDSM import ( + XDSM, + OPT, + SUBOPT, + SOLVER, + DOE, + IFUNC, + FUNC, + GROUP, + IGROUP, + METAMODEL, + LEFT, + RIGHT, +) x = XDSM() @@ -22,7 +35,10 @@ # stacked can be used to represent multiple instances that can be run in parallel x.add_system("H", FUNC, "H", stack=True) -x.add_process(["opt", "DOE", "MDA", "D1", "D2", "subopt", "G1", "G2", "MM", "F", "H", "opt"], arrow=True) +x.add_process( + ["opt", "DOE", "MDA", "D1", "D2", "subopt", "G1", "G2", "MM", "F", "H", "opt"], + arrow=True, +) x.connect("opt", "D1", ["x", "z", "y_2"], label_width=2) x.connect("opt", "D2", ["z", "y_1"]) @@ -50,12 +66,12 @@ x.add_input("opt", r"x_0", stack=True) # can put outputs on the left or right sides -x.add_output("opt", r"x^*, z^*", side="right") -x.add_output("D1", r"y_1^*", side="left") -x.add_output("D2", r"y_2^*", side="left") -x.add_output("F", r"f^*", side="right") -x.add_output("H", r"h^*", side="right") -x.add_output("opt", r"y^*", side="left") +x.add_output("opt", r"x^*, z^*", side=RIGHT) +x.add_output("D1", r"y_1^*", side=LEFT) +x.add_output("D2", r"y_2^*", side=LEFT) +x.add_output("F", r"f^*", side=RIGHT) +x.add_output("H", r"h^*", side=RIGHT) +x.add_output("opt", r"y^*", side=LEFT) x.add_process(["output_opt", "opt", "left_output_opt"]) diff --git a/examples/mdf.py b/examples/mdf.py index 4817f3d..65c89f1 100644 --- a/examples/mdf.py +++ b/examples/mdf.py @@ -1,4 +1,4 @@ -from pyxdsm.XDSM import XDSM, OPT, SOLVER, FUNC +from pyxdsm.XDSM import XDSM, OPT, SOLVER, FUNC, LEFT # Change `use_sfmath` to False to use computer modern x = XDSM(use_sfmath=True) @@ -23,9 +23,9 @@ x.connect("F", "opt", "f") x.connect("G", "opt", "g") -x.add_output("opt", "x^*, z^*", side="left") -x.add_output("D1", "y_1^*", side="left") -x.add_output("D2", "y_2^*", side="left") -x.add_output("F", "f^*", side="left") -x.add_output("G", "g^*", side="left") +x.add_output("opt", "x^*, z^*", side=LEFT) +x.add_output("D1", "y_1^*", side=LEFT) +x.add_output("D2", "y_2^*", side=LEFT) +x.add_output("F", "f^*", side=LEFT) +x.add_output("G", "g^*", side=LEFT) x.write("mdf") diff --git a/pyxdsm/XDSM.py b/pyxdsm/XDSM.py index 7949bda..392cd66 100644 --- a/pyxdsm/XDSM.py +++ b/pyxdsm/XDSM.py @@ -16,6 +16,8 @@ GROUP = "Group" IGROUP = "ImplicitGroup" METAMODEL = "Metamodel" +LEFT = "left" +RIGHT = "right" tikzpicture_template = r""" %%% Preamble Requirements %%% @@ -126,7 +128,16 @@ def __init__(self, use_sfmath=True): self.use_sfmath = use_sfmath - def add_system(self, node_name, style, label, stack=False, faded=False, label_width=None, spec_name=None): + def add_system( + self, + node_name, + style, + label, + stack=False, + faded=False, + label_width=None, + spec_name=None, + ): """ Add a "system" block, which will be placed on the diagonal of the XDSM diagram. @@ -237,9 +248,18 @@ def add_output(self, name, label, label_width=None, style="DataIO", stack=False, elif side == "right": self.right_outs[name] = Output("right_output_" + name, label, label_width, style, stack, side) else: - raise ValueError("The option 'side' must be given as either 'left' or 'right!'") - - def connect(self, src, target, label, label_width=None, style="DataInter", stack=False, faded=False): + raise ValueError("The option 'side' must be given as either 'left' or 'right'!") + + def connect( + self, + src, + target, + label, + label_width=None, + style="DataInter", + stack=False, + faded=False, + ): """ Connects two components with a data line, and adds a label to indicate the data being transferred. diff --git a/pyxdsm/__init__.py b/pyxdsm/__init__.py index 8a124bf..b19ee4b 100644 --- a/pyxdsm/__init__.py +++ b/pyxdsm/__init__.py @@ -1 +1 @@ -__version__ = "2.2.0" +__version__ = "2.2.1" diff --git a/tests/test_xdsm.py b/tests/test_xdsm.py index cc18fc9..6515712 100644 --- a/tests/test_xdsm.py +++ b/tests/test_xdsm.py @@ -3,7 +3,7 @@ import shutil import tempfile import subprocess -from pyxdsm.XDSM import XDSM, OPT, FUNC, SOLVER +from pyxdsm.XDSM import XDSM, OPT, FUNC, SOLVER, LEFT, RIGHT from numpy.distutils.exec_command import find_executable basedir = os.path.dirname(os.path.abspath(__file__)) @@ -92,10 +92,10 @@ def test_options(self): x.connect("F", "opt", "f") x.connect("G", "opt", "g") - x.add_output("opt", "x^*, z^*", side="right") - x.add_output("D1", "y_1^*", side="left", stack=True) - x.add_output("D2", "y_2^*", side="left") - x.add_output("F", "f^*", side="left") + x.add_output("opt", "x^*, z^*", side=RIGHT) + x.add_output("D1", "y_1^*", side=LEFT, stack=True) + x.add_output("D2", "y_2^*", side=LEFT) + x.add_output("F", "f^*", side=LEFT) x.add_output("G", "g^*") x.write(filename) x.write_sys_specs(spec_dir)