pyXDSM API

class pyxdsm.XDSM.XDSM(use_sfmath=True, optional_latex_packages=None, auto_fade=None)[source]

Initialize XDSM object

Parameters:
use_sfmathbool, optional

Whether to use the sfmath latex package, by default True

optional_latex_packagesstring or list of strings, optional

Additional latex packages to use when creating the pdf and tex versions of the diagram, by default None

auto_fadedictionary, optional

Controls the automatic fading of inputs, outputs, connections and processes based on the fading of diagonal blocks. For each key “inputs”, “outputs”, “connections”, and “processes”, the value can be one of: - “all” : fade all blocks - “connected” : fade all components connected to faded blocks (both source and target must be faded for a conncection to be faded) - “none” : do not auto-fade anything For connections there are two additional options: - “incoming” : Fade all connections that are incoming to faded blocks. - “outgoing” : Fade all connections that are outgoing from faded blocks.

add_input(name, label, label_width=None, style='DataIO', stack=False, faded=False)[source]

Add an input, which will appear in the top row of the diagram.

Parameters:
namestr

The unique name given to this component

labelstr or list/tuple of strings

The label to appear on the diagram. There are two options for this: - a single string - a list or tuple of strings, which is used for line breaking In either case, they should probably be enclosed in text{} declarations to make sure the font is upright.

label_widthint or None

If not None, AND if label is given as either a tuple or list, then this parameter controls how many items in the tuple/list will be displayed per line. If None, the label will be printed one item per line if given as a tuple or list, otherwise the string will be printed on a single line.

stylestr

The style given to this component. Can be one of [‘DataInter’, ‘DataIO’]

stackbool

If true, the system will be displayed as several stacked rectangles, indicating the component is executed in parallel.

fadedbool

If true, the component will be faded, in order to highlight some other system.

add_output(name, label, label_width=None, style='DataIO', stack=False, faded=False, side='left')[source]

Add an output, which will appear in the left or right-most column of the diagram.

Parameters:
namestr

The unique name given to this component

labelstr or list/tuple of strings

The label to appear on the diagram. There are two options for this: - a single string - a list or tuple of strings, which is used for line breaking In either case, they should probably be enclosed in text{} declarations to make sure the font is upright.

label_widthint or None

If not None, AND if label is given as either a tuple or list, then this parameter controls how many items in the tuple/list will be displayed per line. If None, the label will be printed one item per line if given as a tuple or list, otherwise the string will be printed on a single line.

stylestr

The style given to this component. Can be one of ['DataInter', 'DataIO']

stackbool

If true, the system will be displayed as several stacked rectangles, indicating the component is executed in parallel.

fadedbool

If true, the component will be faded, in order to highlight some other system.

sidestr

Must be one of ['left', 'right']. This parameter controls whether the output is placed on the left-most column or the right-most column of the diagram.

add_process(systems, arrow=True, faded=False)[source]

Add a process line between a list of systems, to indicate process flow.

Parameters:
systemslist

The names of the components, in the order in which they should be connected. For a complete cycle, repeat the first component as the last component.

arrowbool

If true, arrows will be added to the process lines to indicate the direction of the process flow.

add_system(node_name, style, label, stack=False, faded=False, label_width=None, spec_name=None)[source]

Add a “system” block, which will be placed on the diagonal of the XDSM diagram.

Parameters:
node_namestr

The unique name given to this component

stylestr

The type of the component

labelstr or list/tuple of strings

The label to appear on the diagram. There are two options for this: - a single string - a list or tuple of strings, which is used for line breaking In either case, they should probably be enclosed in text{} declarations to make sure the font is upright.

stackbool

If true, the system will be displayed as several stacked rectangles, indicating the component is executed in parallel.

fadedbool

If true, the component will be faded, in order to highlight some other system.

label_widthint or None

If not None, AND if label is given as either a tuple or list, then this parameter controls how many items in the tuple/list will be displayed per line. If None, the label will be printed one item per line if given as a tuple or list, otherwise the string will be printed on a single line.

spec_namestr

The spec name used for the spec file.

connect(src, target, label, label_width=None, style='DataInter', stack=False, faded=False)[source]

Connects two components with a data line, and adds a label to indicate the data being transferred.

Parameters:
srcstr

The name of the source component.

targetstr

The name of the target component.

labelstr or list/tuple of strings

The label to appear on the diagram. There are two options for this: - a single string - a list or tuple of strings, which is used for line breaking In either case, they should probably be enclosed in text{} declarations to make sure the font is upright.

label_widthint or None

If not None, AND if label is given as either a tuple or list, then this parameter controls how many items in the tuple/list will be displayed per line. If None, the label will be printed one item per line if given as a tuple or list, otherwise the string will be printed on a single line.

stylestr

The style given to this component. Can be one of ['DataInter', 'DataIO']

stackbool

If true, the system will be displayed as several stacked rectangles, indicating the component is executed in parallel.

fadedbool

If true, the component will be faded, in order to highlight some other system.

write(file_name, build=True, cleanup=True, quiet=False, outdir='.')[source]

Write output files for the XDSM diagram. This produces the following:

  • {file_name}.tikz

    A file containing the TikZ definition of the XDSM diagram.

  • {file_name}.tex

    A standalone document wrapped around an include of the TikZ file which can be compiled to a pdf.

  • {file_name}.pdf

    An optional compiled version of the standalone tex file.

Parameters:
file_namestr

The prefix to be used for the output files

buildbool

Flag that determines whether the standalone PDF of the XDSM will be compiled. Default is True.

cleanupbool

Flag that determines if pdflatex build files will be deleted after build is complete

quietbool

Set to True to suppress output from pdflatex.

outdirstr

Path to an existing directory in which to place output files. If a relative path is given, it is interpreted relative to the current working directory.

write_sys_specs(folder_name)[source]

Write I/O spec json files for systems to specified folder

An I/O spec of a system is the collection of all variables going into and out of it. That includes any variables being passed between systems, as well as all inputs and outputs. This information is useful for comparing implementations (such as components and groups in OpenMDAO) to the XDSM diagrams.

The json spec files can be used to write testing utilities that compare the inputs/outputs of an implementation to the XDSM, and thus allow you to verify that your codes match the XDSM diagram precisely. This technique is especially useful when large engineering teams are collaborating on model development. It allows them to use the XDSM as a shared contract between team members so everyone can be sure that their codes will sync up.

Parameters:
folder_name: str

name of the folder, which will be created if it doesn’t exist, to put spec files into