Skip to content

Commit

Permalink
Maintenance update (#32)
Browse files Browse the repository at this point in the history
* added long_description read from README

* black format

* flake8 fixes

* version bump

* removed extra white spaces

* bumped dependency version

* removed PDFs from repo
  • Loading branch information
ewu63 authored Sep 11, 2020
1 parent 199deca commit be1b4c0
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 464 deletions.
Binary file removed examples/kitchen_sink.pdf
Binary file not shown.
94 changes: 41 additions & 53 deletions examples/kitchen_sink.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,63 @@
from pyxdsm.XDSM import (XDSM, OPT, SUBOPT, SOLVER, DOE,
IFUNC, FUNC, GROUP, IGROUP, METAMODEL)

# styling names for the boxes
opt = 'Optimization'
subopt = 'SubOptimization'
solver = 'MDA'
doe = 'DOE'
ifunc = 'ImplicitFunction'
func = 'Function'
group = 'Group'
igroup = 'ImplicitGroup'
metamodel = 'Metamodel'
from pyxdsm.XDSM import XDSM, OPT, SUBOPT, SOLVER, DOE, IFUNC, FUNC, GROUP, IGROUP, METAMODEL

x = XDSM()

x.add_system('opt', opt, r'\text{Optimizer}')
x.add_system('DOE', doe, r'\text{DOE}')
x.add_system('MDA', solver, r'\text{Newton}')
x.add_system('D1', func, 'D_1')
x.add_system("opt", OPT, r"\text{Optimizer}")
x.add_system("DOE", DOE, r"\text{DOE}")
x.add_system("MDA", SOLVER, r"\text{Newton}")
x.add_system("D1", FUNC, "D_1")

# can fade out blocks to allow for emphasis on sub-sections of XDSM
x.add_system('D2', ifunc, 'D_2', faded=True)
x.add_system("D2", IFUNC, "D_2", faded=True)

x.add_system('D3', ifunc, 'D_3')
x.add_system('subopt', subopt, 'SubOpt')
x.add_system('G1', group, 'G_1')
x.add_system('G2', igroup, 'G_2')
x.add_system('MM', metamodel, 'MM')
x.add_system("D3", IFUNC, "D_3")
x.add_system("subopt", SUBOPT, "SubOpt")
x.add_system("G1", GROUP, "G_1")
x.add_system("G2", IGROUP, "G_2")
x.add_system("MM", METAMODEL, "MM")

# if you give the label as a list or tuple, it splits it onto multiple lines
x.add_system('F', func, ('F', r'\text{Functional}'))
x.add_system("F", FUNC, ("F", r"\text{Functional}"))

# stacked can be used to represent multiple instances that can be run in parallel
x.add_system('H', func, 'H', stack=True)
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'])
x.connect('opt', 'D3', 'z, y_1')
x.connect('opt', 'subopt', 'z, y_1')
x.connect('subopt', 'G1', 'z_2')
x.connect('subopt', 'G2', 'z_2')
x.connect('subopt', 'MM', 'z_2')
x.connect('opt', 'G2', 'z')
x.connect('opt', 'F', 'x, z')
x.connect('opt', 'F', 'y_1, y_2')
x.connect("opt", "D1", ["x", "z", "y_2"], label_width=2)
x.connect("opt", "D2", ["z", "y_1"])
x.connect("opt", "D3", "z, y_1")
x.connect("opt", "subopt", "z, y_1")
x.connect("subopt", "G1", "z_2")
x.connect("subopt", "G2", "z_2")
x.connect("subopt", "MM", "z_2")
x.connect("opt", "G2", "z")
x.connect("opt", "F", "x, z")
x.connect("opt", "F", "y_1, y_2")

# you can also stack variables
x.connect('opt', 'H', 'y_1, y_2', stack=True)
x.connect("opt", "H", "y_1, y_2", stack=True)

x.connect('D1', 'opt', r'\mathcal{R}(y_1)')
x.connect('D2', 'opt', r'\mathcal{R}(y_2)')
x.connect("D1", "opt", r"\mathcal{R}(y_1)")
x.connect("D2", "opt", r"\mathcal{R}(y_2)")

x.connect('F', 'opt', 'f')
x.connect('H', 'opt', 'h', stack=True)
x.connect("F", "opt", "f")
x.connect("H", "opt", "h", stack=True)

# can specify inputs to represent external information coming into the XDSM
x.add_input('D1', 'P_1')
x.add_input('D2', 'P_2')
x.add_input('opt', r'x_0', stack=True)
x.add_input("D1", "P_1")
x.add_input("D2", "P_2")
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'])
x.add_process(["output_opt", "opt", "left_output_opt"])

x.write('kitchen_sink', cleanup=False)
x.write_sys_specs('sink_specs')
x.write("kitchen_sink", cleanup=False)
x.write_sys_specs("sink_specs")
33 changes: 16 additions & 17 deletions examples/mat_eqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
lin_system.add_variable(2, size=1, text="b")

lin_system.add_variable(3, size=1, text="c")
lin_system.add_variable(4, size=2, )
lin_system.add_variable(5, size=2, )
lin_system.add_variable(4, size=2)
lin_system.add_variable(5, size=2)

lin_system.add_variable(6, size=1, text="d")
lin_system.add_variable(7, size=2, )
lin_system.add_variable(8, size=2, )
lin_system.add_variable(7, size=2)
lin_system.add_variable(8, size=2)

lin_system.add_variable(9, size=1, text="e")
lin_system.add_variable(10, size=2, )
lin_system.add_variable(11, size=2, )
lin_system.add_variable(10, size=2)
lin_system.add_variable(11, size=2)

# variable identifiers can be any hashable object
lin_system.add_variable('f', size=1, text="f")
lin_system.add_variable("f", size=1, text="f")

lin_system.connect(1, [4, 5, 7, 8, 10, 11])
lin_system.connect(2, [4, 5, 7, 8, 10, 11])
Expand All @@ -39,26 +39,25 @@
lin_system.connect(10, 11)
lin_system.connect(11, 10)

lin_system.connect(11, 'f')
lin_system.connect(11, "f")

################################
# setup the equation
################################
lin_system.jacobian()
lin_system.spacer()
lin_system.vector(base_color='red', highlight=[0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0])
lin_system.vector(base_color="red", highlight=[0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0])
lin_system.spacer()
lin_system.vector(base_color='red', highlight=[0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0])
lin_system.vector(base_color="red", highlight=[0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0])
lin_system.spacer()
lin_system.vector(base_color='red', highlight=[0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2])
lin_system.vector(base_color="red", highlight=[0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2])
lin_system.spacer()
lin_system.operator('=')
lin_system.vector(base_color='green', highlight=[1,1,2,1,1,1,1,1,1,1,1,1])
lin_system.operator("=")
lin_system.vector(base_color="green", highlight=[1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1])
lin_system.spacer()
lin_system.vector(base_color='green', highlight=[1,1,1,1,1,2,1,1,1,1,1,1])
lin_system.vector(base_color="green", highlight=[1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1])
lin_system.spacer()
lin_system.vector(base_color='green', highlight=[1,1,1,1,1,1,1,1,2,1,1,1])
lin_system.vector(base_color="green", highlight=[1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1])
lin_system.spacer()

lin_system.write('mat_eqn_example')

lin_system.write("mat_eqn_example")
Binary file removed examples/mat_eqn_example.pdf
Binary file not shown.
Binary file removed examples/mdf.pdf
Binary file not shown.
46 changes: 23 additions & 23 deletions examples/mdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
# Change `use_sfmath` to False to use computer modern
x = XDSM(use_sfmath=True)

x.add_system('opt', OPT, r'\text{Optimizer}')
x.add_system('solver', SOLVER, r'\text{Newton}')
x.add_system('D1', FUNC, 'D_1')
x.add_system('D2', FUNC, 'D_2')
x.add_system('F', FUNC, 'F')
x.add_system('G', FUNC, 'G')
x.add_system("opt", OPT, r"\text{Optimizer}")
x.add_system("solver", SOLVER, r"\text{Newton}")
x.add_system("D1", FUNC, "D_1")
x.add_system("D2", FUNC, "D_2")
x.add_system("F", FUNC, "F")
x.add_system("G", FUNC, "G")

x.connect('opt', 'D1', 'x, z')
x.connect('opt', 'D2', 'z')
x.connect('opt', 'F', 'x, z')
x.connect('solver', 'D1', 'y_2')
x.connect('solver', 'D2', 'y_1')
x.connect('D1', 'solver', r'\mathcal{R}(y_1)')
x.connect('solver', 'F', 'y_1, y_2')
x.connect('D2', 'solver', r'\mathcal{R}(y_2)')
x.connect('solver', 'G', 'y_1, y_2')
x.connect("opt", "D1", "x, z")
x.connect("opt", "D2", "z")
x.connect("opt", "F", "x, z")
x.connect("solver", "D1", "y_2")
x.connect("solver", "D2", "y_1")
x.connect("D1", "solver", r"\mathcal{R}(y_1)")
x.connect("solver", "F", "y_1, y_2")
x.connect("D2", "solver", r"\mathcal{R}(y_2)")
x.connect("solver", "G", "y_1, y_2")

x.connect('F', 'opt', 'f')
x.connect('G', 'opt', 'g')
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.write('mdf')
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")
Loading

0 comments on commit be1b4c0

Please sign in to comment.