Package openmdao.main

This package contains the openmdao framework infrastructure code.

arch.py

class openmdao.main.arch.Architecture(parent=None, param_types=None, constraint_types=None, num_allowed_objectives=None, has_coupling_vars=False, has_global_des_vars=False)[source]

Bases: openmdao.main.container.Container

Base class for classes that auto-configure an ArchitectureAssembly given a problem formulation based on parameters, constraints, objectives, and a model.

List data_recorders

Case recorders for iteration data.

  • default: ‘[]’
  • copy: ‘deep’
check_config()[source]

Check the current configuration and raise an exception if something’s not right.

configure()[source]

Setup the architecture inside of the assembly.

constraint_types[source]

Types of constraints allowed by this Architecture.

param_types[source]

Types of parameters allowed by this Architecture.

array_helpers.py

Some functions for dealing with array bookkeeping. Mostly flatteners.

openmdao.main.array_helpers.flatten_slice(index, shape, name='flat_index', offset=0)[source]

Return a string index that flattens an arbitrary slice denoted by ‘index’ into an matrix of shape ‘shape’.

index: string
OpenMDAO string index
shape: tuple
Numpy style shape tuple
name: string
Name for the returned var in the string, default is ‘ix’
offset: int
Starting index for target flat slice
openmdao.main.array_helpers.flattened_size(name, val, scope=None)[source]

Return size of val flattened to a 1D float array.

openmdao.main.array_helpers.flattened_value(name, val)[source]

Return val as a 1D float array.

openmdao.main.array_helpers.is_differentiable_val(val)[source]
openmdao.main.array_helpers.is_differentiable_var(name, scope)[source]

assembly.py

Class definition for Assembly.

class openmdao.main.assembly.Assembly[source]

Bases: openmdao.main.component.Component

This is a container of Components. It understands how to connect inputs and outputs between its children. When executed, it runs the top level Driver called ‘driver’.

Slot (IDriver) driver

The top level Driver that manages execution of this Assembly.

  • default: None
  • copy: ‘deep’
  • vartypename: ‘Slot’
check_gradient(name=None, inputs=None, outputs=None, stream=None, mode='auto', fd_form='forward', fd_step=1e-06, fd_step_type='absolute')[source]

Compare the OpenMDAO-calculated gradient with one calculated by straight finite-difference. This provides the user with a way to validate his derivative functions (apply_deriv and provideJ.) Note that fake finite difference is turned off so that we are doing a straight comparison.

name: (optional) str
If provided, specifies the name of a Driver or Component to calculate the gradient for. If name specifies a Driver, the inputs used to calculate the gradient will be generated from the parameters of the Driver, and the outputs will be generated from the constraints and objectives of the Driver. If name specifies a Component, the inputs and outputs of that Component will be used to calculate the gradient.
inputs: (optional) iter of str or None
Names of input variables. The calculated gradient will be the matrix of values of the output variables with respect to these input variables. If no value is provided for inputs, they will be determined based on the ‘name’ argument. If the inputs are not specified and name is not specified, then they will be generated from the parameters of the object named ‘driver’.
outputs: (optional) iter of str or None
Names of output variables. The calculated gradient will be the matrix of values of these output variables with respect to the input variables. If no value is provided for outputs, they will be determined based on the ‘name’ argument. If the outputs are not specified and name is not specified, then they will be generated from the objectives and constraints of the object named ‘driver’.
stream: (optional) file-like object, str, or None
Where to write to, default stdout. If a string is supplied, that is used as a filename. If None, no output is written.
mode: (optional) str or None
Set to ‘forward’ for forward mode, ‘adjoint’ for adjoint mode, or ‘auto’ to let OpenMDAO determine the correct mode. Defaults to ‘auto’.
fd_form: str
Finite difference mode. Valid choices are ‘forward’, ‘adjoint’ , ‘central’. Default is ‘forward’
fd_step: float
Default step_size for finite difference. Default is 1.0e-6.
fd_step_type: str
Finite difference step type. Set to ‘absolute’ or ‘relative’. Default is ‘absolute’.

Returns the finite difference gradient, the OpenMDAO-calculated gradient, a list of the gradient names, and a list of suspect inputs/outputs.

child_invalidated(childname, vnames=None, iotype='out')[source]

Invalidate all variables that depend on the variable provided by the child that has been invalidated.

child_run_finished(childname, outs=None)[source]

Called by a child when it completes its run() function.

config_changed(update_parent=True)[source]

Call this whenever the configuration of this Component changes, for example, children are added or removed, connections are made or removed, etc.

connect(src, dest)[source]

Connect one src expression to one destination expression. This could be a normal connection between variables from two internal Components, or it could be a passthrough connection, which connects across the scope boundary of this object. When a pathname begins with ‘parent.’, that indicates it is referring to a Variable outside of this object’s scope.

src: str
Source expression string.
dest: str or list(str)
Destination expression string(s).
create_passthrough(pathname, alias=None)[source]

Creates a PassthroughTrait that uses the trait indicated by pathname for validation, adds it to self, and creates a connection between the two. If alias is None, the name of the alias trait will be the last entry in its pathname. The trait specified by pathname must exist.

disconnect(varpath, varpath2=None)[source]

If varpath2 is supplied, remove the connection between varpath and varpath2. Otherwise, if varpath is the name of a trait, remove all connections to/from varpath in the current scope. If varpath is the name of a Component, remove all connections from all of its inputs and outputs.

exec_counts(compnames)[source]
execute()[source]

Runs driver and updates our boundary variables.

find_in_workflows(name)[source]

Returns a list of tuples of the form (workflow, index) for all workflows in the scope of this Assembly that contain the given component name.

find_referring_connections(name)[source]

Returns a list of connections where the given name is referred to either in the source or the destination.

get_connections(src_name, dst_name)[source]

Get a list of the outputs from the component src_name (sources), the inputs to the component dst_name (destinations) and the connections between them.

get_dataflow()[source]

Get a dictionary of components and the connections between them that make up the data flow for the assembly; also includes parameter, constraint, and objective flows.

get_passthroughs()[source]

Get all the inputs and outputs of the assembly’s child components and indicate for each whether or not it is a passthrough variable. If it is a passthrough, provide the assembly’s name for the variable.

get_valid(names)[source]

Get the value of the validity flag for the specified variables. Returns a list of bools.

names: iterator of str
Names of variables whose validity is requested.
has_partial_validation()[source]
invalidate_deps(varnames=None)[source]

Mark all Variables invalid that depend on varnames. Returns a list of our newly invalidated boundary outputs.

varnames: iter of str (optional)
An iterator of names of destination variables.
list_components()[source]

List the components in the assembly.

list_connections(show_passthrough=True, visible_only=False, show_expressions=False)[source]

Return a list of tuples of the form (outvarname, invarname).

list_deriv_vars()[source]
provideJ(required_inputs, required_outputs, check_only=False)[source]

An assembly calculates its Jacobian by calling the calc_gradient method on its base driver. Note, derivatives are only calculated for floats and iterable items containing floats.

remove(name)[source]

Remove the named container object from this assembly and remove it from its workflow(s) if it’s a Component or pseudo component.

rename(oldname, newname)[source]

Renames a child of this object from oldname to newname.

replace(target_name, newobj)[source]

Replace one object with another, attempting to mimic the inputs and connections of the replaced object as much as possible.

set_itername(itername, seqno=0)[source]

Set current ‘iteration coordinates’. Overrides Component to propagate to driver, and optionally set the initial count in the driver’s workflow. Setting the initial count is typically done by CaseIterDriverBase on a remote top level assembly.

itername: string
Iteration coordinates.
seqno: int
Initial execution count for driver’s workflow.
set_valid(names, valid)[source]

Mark the io traits with the given names as valid or invalid.

step()[source]

Execute a single child component and return.

stop()[source]

Stop the calculation.

update_inputs(compname)[source]

Transfer input data to input expressions on the specified component. The inputs iterator is assumed to contain strings that reference component variables relative to the component, e.g., ‘abc[3][1]’ rather than ‘comp1.abc[3][1]’.

update_outputs(outnames)[source]

Execute any necessary internal or predecessor components in order to make the specified output variables valid.

openmdao.main.assembly.set_as_top(cont, first_only=False)[source]

Specifies that the given Container is the top of a Container hierarchy. If first_only is True, then only set it as a top if a global top doesn’t already exist.

attrwrapper.py

class openmdao.main.attrwrapper.AttrWrapper(value=None, **metadata)[source]

Bases: object

A class that encapsulates a value and any metadata necessary for validation of that value. For example, an AttrWrapper for a Float object would include ‘units’ metadata to allow for unit compatability checking and conversion.

case.py

class openmdao.main.case.Case(inputs=None, outputs=None, max_retries=None, retries=None, label='', case_uuid=None, parent_uuid='', msg=None)[source]

Bases: object

Contains all information necessary to specify an input case, i.e., a list of names for all inputs to the case and their values. The case names may contain indexing into containers, attribute access, and/or function calls, as long as the full expression is valid as the left-hand side of an assignment. Outputs to be collected may also be added to the Case, and they can be more general expressions, i.e., they do not have to refer to a single variable. After the Case is executed, it will contain an indicator of the exit status of the case, a string containing error messages associated with the running of the case (if any), and a unique case identifier.

add_input(name, value)[source]

Adds an input and its value to this case.

name: str
Name of the input to be added. May contain an expression as long as it is valid when placed on the left-hand side of an assignment.
value:
Value that the input will be assigned to.
add_inputs(inp_iter)[source]

Adds multiple inputs to this case.

inp_iter: Iterator returning (name,value)
Iterator of input names and values.
add_output(name, value=<object object at 0x106ad5850>)[source]

Adds an output to this case.

name: str
Name of output to be added.
add_outputs(outputs)[source]

Adds outputs to this case.

outputs: iterator returning names or tuples of the form (name,value)
outputs to be added
apply_inputs(scope)[source]

Take the values of all of the inputs in this case and apply them to the specified scope.

get_input(name)[source]
get_inputs(flatten=False)[source]
get_output(name)[source]
get_outputs(flatten=False)[source]
items(iotype=None, flatten=False)[source]

Return a list of (name,value) tuples for variables/expressions in this Case.

iotype: str or None
If ‘in’, only inputs are returned. If ‘out’, only outputs are returned. If None (the default), inputs and outputs are returned.
flatten: bool
If True, split multi-part Variables (like VariableTrees and Arrays) into their constituents.
keys(iotype=None, flatten=False)[source]

Return a list of name/expression strings for this Case.

iotype: str or None
If ‘in’, only inputs are returned. If ‘out’, only outputs are returned. If None (the default), inputs and outputs are returned.
reset()[source]

Remove any saved output values, set retries to None, get a new uuid and reset the parent_uuid. Essentially this Case becomes like a new Case with the same set of inputs and outputs that hasn’t been executed yet.

subcase(names)[source]

Return a new Case having a specified subset of this Case’s inputs and outputs.

update_outputs(scope, msg=None)[source]

Update the value of all outputs in this Case, using the given scope.

values(iotype=None, flatten=False)[source]

Return a list of values for this Case.

iotype: str or None
If ‘in’, only inputs are returned. If ‘out’, only outputs are returned If None (the default), inputs and outputs are returned

caseiter.py

openmdao.main.caseiter.caseiter_to_dict(caseiter, varnames, include_errors=False)[source]

Retrieve the values of specified variables from cases in a CaseIterator.

Returns a dict containing a list of values for each entry, keyed on variable name.

Only data from cases containing ALL of the specified variables will be returned so that all data values with the same index will correspond to the same case.

caseiter: CaseIterator
A CaseIterator containing the cases of interest.
varnames: list[str]
Iterator of names of variables to be retrieved.
include_errors: bool (optional) [False]
If True, include data from cases that reported an error.

cli.py

OpenMDAO Command Line Interface stuff.

openmdao.main.cli.list_testhosts(parser, options, args=None)[source]
openmdao.main.cli.openmdao()[source]
openmdao.main.cli.openmdao_docs(parser, options, args=None)[source]
openmdao.main.cli.test_openmdao(parser, options, args)[source]

component.py

Class definition for Component.

class openmdao.main.component.Component[source]

Bases: openmdao.main.container.Container

This is the base class for all objects containing Traits that are accessible to the OpenMDAO framework and are “runnable.”

Str directory

If non-blank, the directory to execute in.

  • default: ‘’
  • iotype: ‘in’
  • deriv_ignore: True
  • vartypename: ‘Str’
  • framework_var: True
Bool force_execute

If True, always execute even if all IO traits are valid.

  • default: ‘False’
  • iotype: ‘in’
  • deriv_ignore: True
  • framework_var: True
  • vartypename: ‘Bool’
  • assumed_default: False
Bool force_fd

If True, always finite difference this component.

  • default: ‘False’
  • iotype: ‘in’
  • deriv_ignore: True
  • framework_var: True
  • vartypename: ‘Bool’
  • assumed_default: False
Enum missing_deriv_policy

Determines behavior when some analytical derivatives are provided but some are missing

  • default: ‘error’
  • iotype: ‘in’
  • deriv_ignore: True
  • framework_var: True
  • vartypename: ‘Enum’
  • values: [‘error’, ‘assume_zero’]
  • assumed_default: False
Int derivative_exec_count

Number of times this Component’s derivative function has been executed.

  • default: ‘0’
  • iotype: ‘out’
Int exec_count

Number of times this Component has been executed.

  • default: ‘0’
  • iotype: ‘out’
Str itername

Iteration coordinates.

  • default: ‘’
  • iotype: ‘out’
  • deriv_ignore: True
  • vartypename: ‘Str’
  • framework_var: True
Bool create_instance_dir
  • default: ‘False’
  • vartypename: ‘Bool’
  • assumed_default: False
List external_files

FileMetadata objects for external files used by this component.

  • default: ‘[]’
  • copy: ‘deep’
  • deriv_ignore: True
add(name, obj)[source]

Override of base class version to force call to check_config after any child containers are added. The base class version is still called.

Returns the added Container object.

add_trait(name, trait, refresh=True)[source]

Overrides base definition of add_trait in order to force call to check_config prior to execution when new traits are added.

calc_derivatives(first=False, second=False, savebase=False, required_inputs=None, required_outputs=None)[source]

Prepare for Fake Finite Difference runs by calculating all needed derivatives, and saving the current state as the baseline if requested. The user must supply provideJ and list_deriv_vars in the component.

This function should not be overriden.

first: Bool
Set to True to calculate first derivatives.
second: Bool
Set to True to calculate second derivatives.
savebase: Bool
If set to true, then we save our baseline state for fake finite difference.
required_inputs:
Not needed by Component
required_outputs
Not needed by Component
check_config()[source]

Override this function to perform configuration checks specific to your class. Bad configurations should raise an exception.

check_configuration()[source]

Verify that this component and all of its children are properly configured to execute. This function is called prior to each component execution, but is a no-op unless self._call_check_config is True.

Do not override this function.

This function calls check_config(), which may be overridden by inheriting classes to perform more specific configuration checks.

check_gradient(inputs=None, outputs=None, stream=<open file '<stdout>', mode 'w' at 0x1002841e0>, mode='auto', fd_form='forward', fd_step=1e-06, fd_step_type='absolute')[source]

Compare the OpenMDAO-calculated gradient with one calculated by straight finite-difference. This provides the user with a way to validate his derivative functions (apply_deriv and provideJ.) Note that fake finite difference is turned off so that we are doing a straight comparison.

inputs: (optional) iter of str or None
Names of input variables. The calculated gradient will be the matrix of values of the output variables with respect to these input variables. If no value is provided for inputs, they will be determined based on the inputs of this component.
outputs: (optional) iter of str or None
Names of output variables. The calculated gradient will be the matrix of values of these output variables with respect to the input variables. If no value is provided for outputs, they will be determined based on the outputs of this component.
stream: (optional) file-like object, str, or None
Where to write to, default stdout. If a string is supplied, that is used as a filename. If None, no output is written.
mode: (optional) str or None
Set to ‘forward’ for forward mode, ‘adjoint’ for adjoint mode, or ‘auto’ to let OpenMDAO determine the correct mode. Defaults to ‘auto’.
fd_form: str
Finite difference mode. Valid choices are ‘forward’, ‘adjoint’, ‘central’. Default is ‘forward’
fd_step: float
Default step_size for finite difference. Default is 1.0e-6.
fd_step_type: str
Finite difference step type. Set to ‘absolute’ or ‘relative’. Default is ‘absolute’.

Returns the finite difference gradient, the OpenMDAO-calculated gradient, a list of the gradient names, and a list of suspect inputs/outputs.

check_path(path, check_dir=False)[source]

Verify that the given path is a directory and is located within the allowed area (somewhere within the simulation root path).

checkpoint(outstream, fmt=4)[source]

Save sufficient information for a restart. By default, this just calls save().

config_changed(update_parent=True)[source]

Call this whenever the configuration of this Component changes, for example, children are added or removed.

connect(srcexpr, destexpr)[source]

Connects one source expression to one destination expression. When a name begins with ‘parent.’, that indicates it is referring to a variable outside of this object’s scope.

srcexpr: str or ExprEvaluator
Source expression object or expression string.
destexpr: str or ExprEvaluator
Destination expression object or expression string.
cpath_updated()[source]

Calls the base class version of cpath_updated(), checks our directory for validity, and creates the directory if it doesn’t exist.

disconnect(srcpath, destpath)[source]

Removes the connection between one source variable and one destination variable.

execute()[source]

Perform calculations or other actions, assuming that inputs have already been set. This must be overridden in derived classes.

get_abs_directory()[source]

Return absolute path of execution directory.

get_attributes(io_only=True)[source]

Get attributes of component. Includes inputs and ouputs and, if io_only is not true, a dictionary of attributes for each interface implemented by the component.

io_only: Bool
Set to true if we only want to populate the input and output fields of the attributes dictionary.
get_expr_depends()[source]

Return a list of tuples of the form (src_comp_name, dest_comp_name) for each dependency resulting from ExprEvaluators in this Component.

get_expr_sources()[source]

Return a list of tuples containing the names of all upstream components that are referenced in any of our ExprEvaluators, along with an initial exec_count of 0.

get_file_vars()[source]

Return list of (filevarname,filevarvalue,file trait) owned by this component.

get_invalidation_type()[source]
get_itername()[source]

Return current ‘iteration coordinates’.

get_valid(names)[source]

Get the value of the validity flag for the specified variables. Returns a list of bools.

names: iterator of str
Names of variables whose validity is requested.
invalidate_deps(varnames=None)[source]

Invalidate all of our outputs if they’re not invalid already. For a typical Component, this will always be all or nothing, meaning there will never be partial validation of outputs.

NOTE: Components supporting partial output validation must override this function.

Returns None, indicating that all outputs are newly invalidated, or [], indicating that no outputs are newly invalidated.

is_valid()[source]

Return False if any of our variables is invalid.

list_containers()[source]

Return a list of names of child Containers.

list_deriv_vars()[source]
list_inputs(connected=None)[source]

Return a list of names of input values.

connected: bool (optional)
If connected is not None, the list will contain names of inputs with matching external connectivity status.
list_outputs(connected=None)[source]

Return a list of names of output values.

connected: bool (optional)
If connected is not None, the list will contain names of outputs with matching external connectivity status.
static load(instream, fmt=4, package=None, call_post_load=True, top_obj=True, name='', observer=None)[source]

Load object(s) from instream. If instream is an installed package name, then any external files referenced in the object(s) are copied from the package installation to appropriate directories. If an external file has metadata attribute ‘constant’ == True and the machine supports it, a symlink is used rather than a file copy. The package and top_obj arguments are normally used by a loader script (generated by save_to_egg()) to load a sub-component from the egg. name is set when creating an instance via a factory. In this case, external files are copied to a name directory and the component’s directory attribute set accordingly. Existing files are not overwritten. Returns the root object.

instream: file or string
Stream to load from.
fmt: int
Format of state data.
package: string
Name of package to look for instream if instream is a string that is not an existing file.
call_post_load: bool
If True, call post_load().
top_obj: bool
Set True if loading the default entry, False if loading a child entry point object.
name: string
Name for the root object.
observer: callable
Will be called via an EggObserver.
mimic(target)[source]

Initialize what we can from the given target object. Copy any inputs that we share with the target and initialize our delegates with any matching delegates from the target.

pop_dir()[source]

Return to previous directory saved by push_dir().

publish_vars()[source]
push_dir(directory=None)[source]

Change directory to dir, remembering the current directory for a later pop_dir(). Returns the new absolute directory path.

register_published_vars(names, publish=True)[source]
remove(name)[source]

Override of base class version to force call to check_config after any child containers are removed.

remove_trait(name)[source]

Overrides base definition of add_trait in order to force call to check_config prior to execution when a trait is removed.

replace(target_name, newobj)[source]

Replace one object with another, attempting to mimic the replaced object as much as possible.

restart(instream)[source]

Restore state using a checkpoint file. The checkpoint file is typically a delta from a full saved state file. If checkpoint is overridden, this should also be overridden.

run(force=False, ffd_order=0, case_id='')[source]

Run this object. This should include fetching input variables (if necessary), executing, and updating output variables. Do not override this function.

force: bool
If True, force component to execute even if inputs have not changed. (Default is False.)
ffd_order: int
Order of the derivatives to be used during Fake Finite Difference (typically 1 or 2). During regular execution, ffd_order should be 0. (Default is 0.)
case_id: str
Identifier for the Case that is associated with this run. (Default is ‘’.) If applied to the top-level assembly, this will be prepended to all iteration coordinates.
save_to_egg(name, version, py_dir=None, require_relpaths=True, child_objs=None, dst_dir=None, observer=None, need_requirements=True)[source]

Save state and other files to an egg. Typically used to copy all or part of a simulation to another user or machine. By specifying child components in child_objs, it will be possible to create instances of just those components from the installed egg. Child component names should be specified relative to this component.

name: string
Name for egg; must be an alphanumeric string.
version: string
Version for egg; must be an alphanumeric string.
py_dir: string
The (root) directory for local Python files. It defaults to the current directory.
require_relpaths: bool
If True, any path (directory attribute, external file, or file trait) which cannot be made relative to this component’s directory will raise ValueError. Otherwise, such paths generate a warning and the file is skipped.
child_objs: list
List of child objects for additional entry points.
dst_dir: string
The directory to write the egg in.
observer: callable
Will be called via an EggObserver.
need_requirements: bool
Passed to eggsaver.save_to_egg().

After collecting files and possibly modifying their paths, this calls container.save_to_egg(). Returns (egg_filename, required_distributions, orphan_modules).

set_itername(itername)[source]

Set current ‘iteration coordinates’. Typically called by the current workflow just before running the component.

itername: string
Iteration coordinates.
step()[source]

For Components that run other components (e.g., Assembly or Drivers), this will run one Component and return. For simple components, it is the same as run().

stop()[source]

Stop this component.

update_outputs(outnames)[source]

Do what is necessary to make the specified output Variables valid. For a simple Component, this will result in a run().

dir_context[source]

The DirectoryContext for this component.

class openmdao.main.component.SimulationRoot[source]

Bases: object

Singleton object used to hold root directory.

static chroot(path)[source]

Change to directory path and set the singleton’s root. Normally not called but useful in special situations.

path: string
Path to move to.
static get_root()[source]

Return this simulation’s root directory path.

static legal_path(path)[source]

Return True if path is legal (descendant of our root).

path: string
Path to check.

component_with_derivatives.py

A component with derivatives. Derived from Component. This is presently DEPRECATED.

class openmdao.main.component_with_derivatives.ComponentWithDerivatives(*args, **kwargs)[source]

Bases: openmdao.main.component.Component

This is Deprecated.

configinfo.py

constants.py

Package containing various constants/enumerations.

Currently it only includes: SAVE_PICKLE, SAVE_CPICKLE.

container.py

The Container class.

class openmdao.main.container.Container[source]

Bases: openmdao.main.container.SafeHasTraits

Base class for all objects having Traits that are visible to the framework

add(name, obj)[source]

Add an object to this Container. Returns the added object.

classmethod add_class_trait(name, *trait)[source]

Overrides HasTraits definition of add_class_trait to try to keep from clobbering framework stuff.

add_trait(name, trait, refresh=True)[source]

Overrides HasTraits definition of add_trait in order to keep track of dynamically added traits for serialization.

build_trait(ref_name, iotype=None, trait=None)[source]

Build a trait referring to ref_name. This is called by create_io_traits(). This must be overridden.

iotype: str or dict
If iotype is a string it specifies the trait’s iotype. If it’s a dictionary, it provides metadata.
trait: Trait
If trait is not None, use that trait rather than building one.
configure()[source]
connect(srcexpr, destexpr)[source]

Connects one source expression to one destination expression. When a name begins with “parent.”, that indicates it is referring to a variable outside of this object’s scope.

srcexpr: str or ExprEvaluator
Source expression object or expression string.
destexpr: str or ExprEvaluator
Destination expression object or expression string.
contains(path)[source]

Return True if the child specified by the given dotted path name is contained in this Container.

copy()[source]

Returns a deep copy without deepcopying the parent.

cpath_updated()[source]

Called after the hierarchy containing this Container has been defined back to the root. This does not guarantee that all sibling Containers have been defined. It also does not guarantee that this component is fully configured to execute. Classes that override this function must call their base class version.

This version calls cpath_updated() on all of its child Containers.

disconnect(srcpath, destpath)[source]

Removes the connection between one source variable and one destination variable.

get(path, index=None)[source]

Return the object specified by the given path, which may contain ‘.’ characters. index, if not None, should be either a list of non-tuple hashable objects (at most one for each array dimension of the target value) or a list of tuples of the form (operation_id, stuff).

The forms of the various tuples are:

INDEX:   (0, idx)
    where idx is some hashable value
ATTR:    (1, name)
    where name is the attribute name
CALL:    (2, args, kwargs)
    where args is a list of values and kwargs is a list of
    tuples of the form (keyword,value).
    kwargs can be left out if empty.  args can be left out
    if empty as long as kwargs are also empty, for example,
    (2,) and (2,[],[('foo',1)]) are valid but (2,[('foo',1)]) is not.
SLICE:   (3, lower, upper, step)
    All members must be present and should have a value
    of None if not set.

If you want to use a tuple as a key into a dict, you’ll have to nest your key tuple inside of an INDEX tuple to avoid ambiguity, for example, (0, my_tuple).

get_attr(path, index=None)[source]

Same as the ‘get’ method, except that the value will be copied if the variable has a ‘copy’ metadata attribute that is not None. Possible values for ‘copy’ are ‘shallow’ and ‘deep’. Raises an exception if the variable cannot be found.

get_attributes(io_only=True)[source]

Get attributes of this container. Includes all variables (‘Inputs’) and, if io_only is not true, attributes for all slots as well.

Arguments:
io_only: if True then only ‘Inputs’ are included
get_dyn_trait(pathname, iotype=None, trait=None)[source]

Returns a trait if a trait with the given pathname exists, possibly creating it “on-the-fly” and adding its Container. If an attribute exists with the given pathname but no trait is found or can be created, or if pathname references a trait in a parent scope, None will be returned. If no attribute exists with the given pathname within this scope, an AttributeError will be raised.

pathname: str
Pathname of the desired trait. May contain dots.
iotype: str (optional)
Expected iotype of the trait.
trait: TraitType (optional)
Trait to be used for validation.
get_iotype(name)[source]
get_metadata(traitpath, metaname=None)[source]

Retrieve the metadata associated with the trait found using traitpath. If metaname is None, return the entire metadata dictionary for the specified trait. Otherwise, just return the specified piece of metadata. If the specified piece of metadata is not part of the trait, None is returned.

get_pathname(rel_to_scope=None)[source]

Return full path name to this container, relative to scope rel_to_scope. If rel_to_scope is None, return the full pathname.

get_trait(name, copy=False)[source]

Returns the trait indicated by name, or None if not found. No recursive search is performed if name contains dots. This is a replacement for the trait() method on HasTraits objects because that method can return traits that shouldn’t exist. DO NOT use the trait() function as a way to determine the existence of a trait.

get_trait_typenames(pathname, iotype=None)[source]

Return names of the ‘final’ type (bypassing passthrough traits) for pathname using get_dyn_trait(). Used by dynamic wrappers to determine the type of variable to wrap. The returned list is a depth-first traversal of the class hierarchy.

pathname: str
Pathname of the desired trait. May contain dots.
iotype: str (optional)
Expected iotype of the trait.
is_valid()[source]
items(recurse=False, **metadata)[source]

Return a list of tuples of the form (rel_pathname, obj) for each trait of this Container that matches the given metadata. If recurse is True, also iterate through all child Containers of each Container found.

list_containers()[source]

Return a list of names of child Containers.

list_vars()[source]

Return a list of Variables in this Container.

static load(instream, fmt=4, package=None, call_post_load=True, name=None)[source]

Load object(s) from the input stream. Pure Python classes generally won’t need to override this, but extensions will. The format can be supplied in case something other than cPickle is needed.

instream: file or string
Stream to load from.
fmt: int
Format of state data.
package: string
Name of package to look for instream, if instream is a string that is not an existing file.
call_post_load: bool
If True, call post_load().
name: string
Name for root object.

Returns the root object.

static load_from_eggfile(filename, observer=None, log=None)[source]

Extract files in egg to a subdirectory matching the saved object name and then load object graph state.

filename: string
Name of egg file to be loaded.
observer: callable
Will be called via an EggObserver.
log: logging.Logger
Used for logging progress, default is root logger.

Returns the root object.

static load_from_eggpkg(package, entry_name=None, instance_name=None, observer=None)[source]

Load object graph state by invoking the given package entry point. If specified, the root object is renamed to instance_name.

package: string
Package name.
entry_name: string
Name of entry point.
instance_name: string
Name for root object.
observer: callable
Will be called via an EggObserver.

Returns the root object.

post_load()[source]

Perform any required operations after the model has been loaded. At this point the local configuration of the Component is valid, but ‘remote’ traits may need ‘repairing’ which can’t be done until the remote environment is ready. Components with remote environments should override this and restore the remote environment first, then call the superclass.

pre_delete()[source]

Perform any required operations before the model is deleted.

raise_exception(msg, exception_class=<type 'exceptions.Exception'>)[source]

Raise an exception.

remove(name)[source]

Remove the specified child from this container and remove any public trait objects that reference that child. Notify any observers.

remove_trait(name)[source]

Overrides HasTraits definition of remove_trait in order to keep track of dynamically added traits for serialization.

rename(oldname, newname)[source]

Renames a child of this object from oldname to newname.

reraise_exception(msg='')[source]

Re-raise an exception with updated message and original traceback.

revert_to_defaults(recurse=True)[source]

Sets the values of all of the inputs to their default values.

save(outstream, fmt=4, proto=-1)[source]

Save the state of this object and its children to the given output stream. Pure Python classes generally won’t need to override this because the base class version will suffice, but Python extension classes will have to override. The format can be supplied in case something other than cPickle is needed.

outstream: file or string
Stream to save to.
fmt: int
Format for saved data.
proto: int
Protocol used.
save_to_egg(name, version, py_dir=None, src_dir=None, src_files=None, child_objs=None, dst_dir=None, observer=None, need_requirements=True)[source]

Save state and other files to an egg. Typically used to copy all or part of a simulation to another user or machine. By specifying child containers in child_objs, it will be possible to create instances of just those containers from the installed egg. Child container names should be specified relative to this container.

name: string
Name for egg; must be an alphanumeric string.
version: string
Version for egg; must be an alphanumeric string.
py_dir: string
The (root) directory for local Python files. It defaults to the current directory.
src_dir: string
The root of all (relative) src_files.
src_files: list
List of paths to files to be included in the egg.
child_objs: list
List of child objects for additional entry points.
dst_dir: string
The directory to write the egg in.
observer: callable
Will be called via an EggObserver.
need_requirements: bool
Passed to eggsaver.save_to_egg().

After collecting entry point information, calls eggsaver.save_to_egg(). Returns (egg_filename, required_distributions, orphan_modules).

set(path, value, index=None, src=None, force=False)[source]

Set the value of the Variable specified by the given path, which may contain ‘.’ characters. The Variable will be set to the given value, subject to validation and constraints. index, if not None, should be either a list of non-tuple hashable objects, at most one for each array dimension of the target value, or a list of tuples of the form (operation_id, stuff).

The forms of the various tuples are:

INDEX:   (0, idx)
    where idx is some hashable value
ATTR:    (1, name)
    where name is the attribute name
CALL:    (2, args, kwargs)
    where args is a list of values, and kwargs is a list of
    tuples of the form (keyword,value).
    kwargs can be left out if empty.  args can be left out
    if empty as long as kwargs are also empty, for example,
    (2,) and (2,[],[('foo',1)]) are valid but (2,[('foo',1)]) is not.
SLICE:   (3, lower, upper, step)
    All members must be present and should have a value
    of None if not set.

If you want to use a tuple as a key into a dict, you’ll have to nest your key tuple inside of an INDEX tuple to avoid ambiguity, for example, (0, my_tuple)

name[source]

The name of this Container.

parent[source]

The parent Container of this Container.

class openmdao.main.container.SafeHasTraits[source]

Bases: traits.has_traits.HasTraits

Special HasTraits which is configured such that the class is checked for any Variable which might override an existing attribute in any base class.

openmdao.main.container.build_container_hierarchy(dct)[source]

Create a hierarchy of Containers based on the contents of a nested dict. There will always be a single top level scoping Container regardless of the contents of dct.

openmdao.main.container.create_io_traits(cont, obj_info, iotype='in')[source]

Create io trait(s) specified by the contents of obj_info. Calls build_trait() on Container cont, which can be overridden by subclasses, to create each trait. One use of this is to provide traits mapping to variables inside a Component implemented as a Python extension module.

obj_info is assumed to be either a string, a tuple, or a list that contains strings and/or tuples. The information is used to specify the “internal” and “external” names of the variable. The “internal” name uses the naming scheme within the Container. The “external” name is the one that will be used to access the trait from outside the Container; it must not contain any ‘.’ characters.

A string specifies the “internal” name for the variable. The “external” name will be the “internal” name with any ‘.’ characters replaced by ‘_’.

Tuples must contain the “internal” name followed by the “external” name and may optionally contain an iotype and a validation trait. If the iotype is a dictionary rather than a string, it is used for trait metadata (it may include the iotype key but does not have to).

iotype is the default I/O type to be used.

The newly created traits are added to the specified Container.

For example, the following are valid calls:

# Create an input trait 'foo' referring to 'foo' on 'obj'.
create_io_traits(obj, 'foo')

# Create an input trait 'inputs_foo' referring to 'inputs.foo'.
create_io_traits(obj, 'inputs.foo')

# Create outputs 'foo', 'bar', and 'baz'.
create_io_traits(obj, ['foo','bar','baz'], iotype='out')

# Use Bool trait named 'foo_alias' to refer to 'foo', and create 'bar'.
create_io_traits(obj, ('foo', 'foo_alias', 'in', Bool()), 'bar')

# Create inputs 'fooa' and 'bazz', and output 'barb'.
# 'fooa' will have the specified metadata.
create_io_traits(obj, [('foo', 'fooa', {low=-1, high=10}),
                       ('bar', 'barb', 'out'),
                       ('baz', 'bazz')])
openmdao.main.container.dump(cont, recurse=False, stream=None, **metadata)[source]

Print all items having specified metadata and their corresponding values to the given stream. If the stream is not supplied, it defaults to sys.stdout.

openmdao.main.container.find_name(parent, obj)[source]

Find the given object in the specified parent and return its name in the parent’s __dict__. There could be multiple names bound to a given object. Only the first name found is returned.

Return ‘’ if not found.

openmdao.main.container.find_trait_and_value(obj, pathname)[source]

Return a tuple of the form (trait, value) for the given dotted pathname. Raises an exception if the value indicated by the pathname is not found in obj. If the value is found but has no trait, then (None, value) is returned.

openmdao.main.container.get_closest_proxy(start_scope, pathname)[source]

Resolve down to the closest in-process parent object of the object indicated by pathname. Returns a tuple containing (proxy_or_parent, rest_of_pathname)

openmdao.main.container.get_default_name(obj, scope)[source]

Return a unique name for the given object in the given scope.

cyclicflow.py

A workflow that contains cyclic graphs. Note that a special solver is required to converge this workflow in order to execute it.

class openmdao.main.cyclicflow.CyclicWorkflow(parent=None, scope=None, members=None)[source]

Bases: openmdao.main.sequentialflow.SequentialWorkflow

A CyclicWorkflow consists of a collection of Components that contains loops in the graph.

config_changed()[source]

Notifies the Workflow that its configuration (dependencies, etc.) has changed.

derivative_graph(inputs=None, outputs=None, fd=False, group_nondif=True)[source]

Returns the local graph that we use for derivatives. For cyclic flows, we need to sever edges and use them as inputs/outputs.

edge_list()[source]

Return the list of edges for the derivatives of this workflow.

get_dependents(fixed_point=False)[source]

Returns a list of current values of the dependents. This includes both constraints and severed sources.

fixed_point: bool
Set to True if we are doing fixed-point iteration instead of a more general solve. In such a case, we need to swap the order of the constraints to match the parameter order. We also may need to swap signs on the constraints.
get_independents()[source]

Returns a list of current values of the dependents. This includes both parameters and severed targets.

initialize_residual()[source]

Creates the array that stores the residual. Also returns the number of edges.

set_independents(val)[source]

Sets all dependent variables to the values in the input array val. This includes both parameters and severed targets.

dataflow.py

A workflow where the execution order is automatically inferred from the data connections.

class openmdao.main.dataflow.Dataflow(parent=None, scope=None, members=None)[source]

Bases: openmdao.main.sequentialflow.SequentialWorkflow

A Dataflow consists of a collection of Components which are executed in data flow order.

check_config()[source]

Check for cyclic graph.

config_changed()[source]

Notifies the Workflow that its configuration (dependencies, etc.) has changed.

depgraph.py

class openmdao.main.depgraph.DependencyGraph[source]

Bases: networkx.classes.digraph.DiGraph

add_boundary_var(obj, name, **kwargs)[source]

Add a boundary variable, i.e., one not associated with any component in the graph.

add_component(cname, obj, **kwargs)[source]

Create nodes in the graph for the component and all of its input and output variables. Any other named args that are passed will be placed in the metadata for the component node.

add_edge(u, v, attr_dict=None, **attr)[source]
add_edges_from(ebunch, attr_dict=None, **attr)[source]
add_node(n, attr_dict=None, **attr)[source]
add_nodes_from(nodes, **attr)[source]
add_subvar(subvar)[source]

Adds a subvar node for a model input. This node is used to represent parameters that are array slices, mainly for metadata storage and for defining edge iterators, but not for workflow execution. Subvars created using this function will be labeled as ‘fake’ in their metadata.

all_comps()[source]

Returns a list of all component and PseudoComponent nodes.

base_var(node)[source]

Returns the name of the variable node that is the ‘base’ for the given node name. For example, for the node A.b[4], the base variable is A.b. For the node d.x.y, the base variable is d if d is a boundary variable node, or d.x otherwise.

basevar_iter(nodes, reverse=False)[source]

Given a group of nodes, return an iterator over all base variable nodes that are nearest in one direction.

check_connect(srcpath, destpath)[source]

Raise an exception if the specified destination is already connected.

child_config_changed(child, adding=True, removing=True)[source]

A child has changed its input lists and/or output lists, so we need to update the graph.

child_run_finished(childname, outs=None)[source]

Called by a child when it completes its run() function.

component_graph()[source]

Return a subgraph containing only Components and PseudoComponents and edges between them.

config_changed()[source]
connect(scope, srcpath, destpath, check=True, invalidate=True)[source]

Create a connection between srcpath and destpath, and create any necessary additional subvars with connections to base variable nodes. For example, connecting A.b[3] to B.c.x will create an edge between A.b[3] and B.c.x, and will also add an edge from base variable A.b to A.b[3], and another edge from B.c.x to base variable B.c.

connections_to(path, direction=None)[source]
disconnect(srcpath, destpath=None)[source]
edge_dict_to_comp_list(edges, implicit_edges=None)[source]

Converts inner edge dict into an ordered dict whose keys are component names, and whose values are lists of relevant (in the graph) inputs and outputs.

find_prefixed_nodes(nodes, data=False)[source]

Returns a list of nodes including the given nodes and any node that is prefixed with the name of any of those nodes. This is useful for retrieving all variable and subvar nodes associated with a component node.

full_subgraph(nodes)[source]

Returns the subgraph specified by the given component or pseudocomp nodes and any variable or expr nodes corresponding to those nodes.

get_boundary_inputs(connected=False)[source]

Returns inputs that are on the component boundary. If connected is True, return a list of only those nodes that are connected externally.

get_boundary_outputs(connected=False)[source]

Returns outputs that are on the component boundary. If connected is True, return a list of only those nodes that are connected externally.

get_directional_interior_edges(comp1, comp2)[source]

Behaves like get_interior_edges, except that it only returns interior edges that originate in comp1 and and end in comp2.

comp1: str
Source component name
comp2: str
Dest component name
get_extern_dests()[source]

Returns destinations that are external to our parent component that are connected to our boundary outputs.

get_extern_srcs()[source]

Returns sources from external to our parent component that are connected to our boundary inputs.

get_loops()[source]
get_sources(name)[source]

Return the node that’s actually a source for the named node (as opposed to just a connected subvar). This should only be called for destination nodes (inputs or output boundary vars).

invalidate_deps(scope, vnames)[source]

Walk through all dependent nodes in the graph, invalidating all variables that depend on the given variable names.

scope: object
Scoping object where the components objects referred to by name in the graph are found.
vnames: list or set of str
Names of var nodes.
list_autopassthroughs()[source]

Returns a list of autopassthrough connections as (src, dest) tuples. Autopassthroughs are connections directly from a variable external to this graph to an internal (non-boundary) variable.

list_connections(show_passthrough=True, show_external=False)[source]
list_input_outputs(cname)[source]

Return a list of names of input or state nodes that are used as outputs.

list_inputs(cname, connected=False, invalid=False)[source]

Return a list of names of input nodes to a component. If connected is True, return only connected inputs. If invalid is True, return only invalid inputs.

list_outputs(cname, connected=False)[source]

Return a list of names of output, state or residual nodes for a component. If connected is True, return only connected outputs.

order_components(comps)[source]

Return a list of the given components, sorted in dataflow order.

remove(name)[source]

Remove the named node and all nodes prefixed by the given name plus a dot, e.g., for name C1, remove all nodes prefixed by ‘C1.’ or ‘C1[‘.

remove_edge(u, v)[source]
remove_edges_from(ebunch)[source]
remove_node(n)[source]
remove_nodes_from(nbunch)[source]
sever_edges(edges)[source]

Temporarily remove the specified edges but save them and their metadata for later restoration.

subvars(node)[source]
unsever_edges(scope)[source]

Restore previously severed edges.

update_boundary_outputs(scope)[source]

Update destination vars on our boundary.

update_destvar(scope, vname)[source]

Update the value of the given variable in the given scope using upstream variables.

validate_boundary_vars()[source]

Mark extern and boundary vars and their subvars as valid.

var_edge_iter(source, reverse=False)[source]

Iterater over edges from the given source to the nearest basevars.

openmdao.main.depgraph.find_all_connecting(graph, start, end)[source]

Return the set of all component nodes along all paths between start and end. The start and end nodes are included in the set if they’re connected.

Return a set of pseudocomponent nodes not driver related and are attached to the given set of component nodes.

openmdao.main.depgraph.get_missing_derivs(obj, recurse=True)[source]

Return a list of missing derivatives found in the given object.

openmdao.main.depgraph.get_subdriver_graph(graph, inputs, outputs, wflow, full_fd=False)[source]

Update the given graph to replace non-solver subdrivers with PseudoAssemblies and promote edges up from sub-Solvers. Returns a list of names of drivers that were replaced, the set of additional inputs from subsolvers, and the set of additional outputs from subsolvers.

openmdao.main.depgraph.is_basevar_node(graph, node)[source]

Returns True if this node represents an actual input or output variable.

openmdao.main.depgraph.is_boundary_input_node(graph, node)[source]
openmdao.main.depgraph.is_boundary_node(graph, node)[source]
openmdao.main.depgraph.is_boundary_output_node(graph, node)[source]
openmdao.main.depgraph.is_comp_node(graph, node)[source]

Returns True for Component or PseudoComponent nodes.

openmdao.main.depgraph.is_connection(graph, src, dest)[source]
openmdao.main.depgraph.is_driver_node(graph, node)[source]
openmdao.main.depgraph.is_extern_dest(graph, node)[source]
openmdao.main.depgraph.is_extern_node(graph, node)[source]
openmdao.main.depgraph.is_extern_src(graph, node)[source]
openmdao.main.depgraph.is_fake_node(graph, node)[source]
openmdao.main.depgraph.is_input_base_node(graph, node)[source]
openmdao.main.depgraph.is_input_node(graph, node)[source]
openmdao.main.depgraph.is_multivar_expr_node(graph, node)[source]
openmdao.main.depgraph.is_nested_node(graph, node)[source]

Returns True if the given node refers to an attribute that is nested within the child of a Component in our scope, or within a boundary variable in our scope. For example, if a Component ‘comp1’ is within our scope, a variable node referring to ‘comp1.child.x’ would be a nested node while a ‘comp1.y’ node would not. If we had a boundary var called ‘b’, then ‘b.x’ would be a nested node.

openmdao.main.depgraph.is_non_driver_pseudo_node(graph, node)[source]
openmdao.main.depgraph.is_objective_node(graph, node)[source]
openmdao.main.depgraph.is_output_base_node(graph, node)[source]
openmdao.main.depgraph.is_output_node(graph, node)[source]
openmdao.main.depgraph.is_pseudo_node(graph, node)[source]
openmdao.main.depgraph.is_pseudo_output_node(graph, node)[source]
openmdao.main.depgraph.is_subvar_node(graph, node)[source]

Returns True if this node represents some subdivision of an input or output variable, e.g., an array index - comp_1.x[2]

openmdao.main.depgraph.is_unit_node(graph, node)[source]
openmdao.main.depgraph.is_valid_node(graph, node)[source]
openmdao.main.depgraph.is_var_node(graph, node)[source]

Return True for all basevar and subvar nodes.

openmdao.main.depgraph.is_var_node_with_solution_bounds(graph, node)[source]

Returns True if this variable node stores metadata for calculating the gradient. The metadata whose keys are driver iternames, and whose values are a tuple containing the start and end index where this var’s values get poked into the solution vector.

openmdao.main.depgraph.mod_for_derivs(graph, inputs, outputs, wflow, full_fd=False)[source]

Adds needed nodes and connections to the given graph for use in derivative calculations.

openmdao.main.depgraph.unique(seq)[source]

Return a list of unique values, preserving order

derivatives.py

Some functions and objects that provide the backbone to OpenMDAO’s differentiation capability.

class openmdao.main.derivatives.FiniteDifference(pa)[source]

Bases: object

Helper object for performing finite difference on a portion of a model.

calculate()[source]

Return Jacobian for all inputs and outputs.

get_inputs(x)[source]

Return matrix of flattened values from input edges.

get_outputs(x)[source]

Return matrix of flattened values from output edges.

get_value(src, i1, i2, index)[source]

Get a value from the model. We only need this function for determining the relative stepsize to take.

set_value(srcs, val, i1, i2, index)[source]

Set a value in the model

openmdao.main.derivatives.applyJ(obj, arg, result, residual, shape_cache, J=None)[source]

Multiply an input vector by the Jacobian. For an Explicit Component, this automatically forms the “fake” residual, and calls into the function hook “apply_deriv”.

openmdao.main.derivatives.applyJT(obj, arg, result, residual, shape_cache, J=None)[source]

Multiply an input vector by the transposed Jacobian. For an Explicit Component, this automatically forms the “fake” residual, and calls into the function hook “apply_derivT”.

openmdao.main.derivatives.applyMinv(obj, inputs)[source]

Simple wrapper around a component’s applyMinv where we can reshape the arrays for each input and expand any needed array elements into full arrays.

openmdao.main.derivatives.applyMinvT(obj, inputs, shape_cache)[source]

Simple wrapper around a component’s applyMinvT where we can reshape the arrays for each input and expand any needed array elements into full arrays.

openmdao.main.derivatives.calc_gradient(wflow, inputs, outputs, n_edge, shape)[source]

Returns the gradient of the passed outputs with respect to all passed inputs.

openmdao.main.derivatives.calc_gradient_adjoint(wflow, inputs, outputs, n_edge, shape)[source]

Returns the gradient of the passed outputs with respect to all passed inputs. Calculation is done in adjoint mode.

openmdao.main.derivatives.get_bounds(obj, input_keys, output_keys, J)[source]

Returns a pair of dictionaries that contain the stop and end index for each input and output in a pair of lists.

openmdao.main.derivatives.post_process_dicts(key, result)[source]

Once we’ve called apply_deriv or appyMinv (or their adjoint counterparts, we need to restore them to their expected format, so basically flatten and poke array elements.

openmdao.main.derivatives.pre_process_dicts(obj, key, arg_or_result, shape_cache)[source]

If the component supplies apply_deriv or applyMinv or their adjoint counterparts, it expects the contents to be shaped like the original variables. Also, it doesn’t know how to handle array elements, so we need to do a fair amount of preparation on the way in.

openmdao.main.derivatives.reduce_jacobian(J, i1, i2, idx, ish, o1, o2, odx, osh)[source]

Return the subportion of the Jacobian that is valid for a particular input and output slice.

J: 2D ndarray
Full Jacobian
i1, i2: int, int
Start and end index for the input variable
o1, o2: int, int
Start and end index for the output variable
idx, odx: str, str
Index strings for the input and output, if they are arrays. These are None if the entries in the Jacobian have already sliced the array for us (this can happen with pseudoAssemblies), in which case we need to do no work.
ish, osh: tuples
Shapes of the original input and output variables before being flattened.

driver.py

Driver class definition

class openmdao.main.driver.Driver[source]

Bases: openmdao.main.component.Component

A Driver iterates over a workflow of Components until some condition is met.

Slot (Workflow) workflow
  • default: Dataflow()
  • hidden: True
  • required: True
  • copy: ‘deep’
  • vartypename: ‘Slot’
VarTree gradient_options
  • default: ‘<openmdao.main.driver.GradientOptions object at 0x109abca70>’
  • iotype: ‘in’
  • copy: ‘deep’
  • vartypename: ‘VarTree’
  • framework_var: True
List printvars

List of extra variables to output in the recorders.

  • default: ‘[]’
  • iotype: ‘in’
  • copy: ‘deep’
  • framework_var: True
List recorders

Case recorders for iteration data.

  • default: ‘[]’
  • copy: ‘deep’
add_event(name)

Adds an event variable to be set by the driver.

name: string
Name of the event variable the driver should set during execution.
calc_derivatives(first=False, second=False, savebase=False, required_inputs=None, required_outputs=None)[source]

Calculate derivatives and save baseline states for all components in this workflow.

calc_gradient(inputs=None, outputs=None)[source]

Returns the gradient of the passed outputs with respect to all passed inputs. The basic driver behavior is to call calc_gradient on its workflow. However, some driver (optimizers in particular) may want to define their own behavior.

check_config()[source]

Verify that our workflow is able to resolve all of its components.

clear_events()

Remove all event variables from the driver’s list.

config_changed(update_parent=True)[source]

Call this whenever the configuration of this Component changes, for example, children are added or removed or dependencies may have changed.

continue_iteration()[source]

Return False to stop iterating.

execute()[source]

Iterate over a workflow of Components until some condition is met. If you don’t want to structure your driver to use pre_iteration, post_iteration, etc., just override this function. As a result, none of the <start/pre/post/continue>_iteration() functions will be called.

get_events()

Return the list of event variables to be set by this driver.

get_expr_depends()[source]

Returns a list of tuples of the form (src_comp_name, dest_comp_name) for each dependency introduced by any ExprEvaluators in this Driver, ignoring any dependencies on components that are inside of this Driver’s iteration set.

get_expr_scope()[source]

Return the scope to be used to evaluate ExprEvaluators.

get_expr_var_depends(recurse=True)[source]

Returns a tuple of sets of the form (src_set, dest_set) containing all dependencies introduced by any parameters, objectives, or constraints in this Driver. If recurse is True, include any refs from subdrivers.

get_references(name)[source]

Return a dict of parameter, constraint, and objective references to component name in preparation for subsequent restore_references() call.

name: string
Name of component being referenced.
get_workflow()[source]

Get the driver info and the list of components that make up the driver’s workflow; recurse on nested drivers.

is_valid()[source]

Return False if any Component in our workflow(s) is invalid, if any of our variables is invalid, or if the parameters, constraints, or objectives have changed.

iteration_set(solver_only=False)[source]

Return a set of all Components in our workflow and recursively in any workflow in any Driver in our workflow.

solver_only: Bool
Only recurse into solver drivers. These are the only kinds of drivers whose derivatives get absorbed into the parent driver’s graph.
list_available_events()

Return a list of all available events in the driver’s workflow.

list_pseudocomps()[source]

Return a list of names of pseudocomps resulting from our objectives, and constraints.

post_iteration()[source]

Called after each iteration.

pre_iteration()[source]

Called prior to each iteration. This is where iteration events are set.

record_case()[source]

A driver can call this function to record the current state of the current iteration as a Case into all slotted case recorders. Generally, the driver should call this function once per iteration and may also need to call it at the conclusion.

All parameters, objectives, and constraints are included in the Case output, along with all extra variables listed in self.printvars.

remove_event(name)

Remove the name of the specified event variable from the driver’s list of event variables to be set during execution.

remove_references(name)[source]

Remove parameter, constraint, objective and workflow references to component name.

name: string
Name of component being removed.
restore_references(refs)[source]

Restore parameter, constraint, and objective references to component name from refs.

refs: object
Value returned by get_references().
run(force=False, ffd_order=0, case_id='')[source]

Run this object. This should include fetching input variables if necessary, executing, and updating output variables. Do not override this function.

force: bool
If True, force component to execute even if inputs have not changed. (Default is False)
ffd_order: int
Order of the derivatives to be used when finite differencing (1 for first derivatives, 2 for second derivatives). During regular execution, ffd_order should be 0. (Default is 0)
case_id: str
Identifier for the Case that is associated with this run. If applied to the top-level assembly, this will be prepended to all iteration coordinates. (Default is ‘’)
run_iteration()[source]

Runs workflow.

set_events()

Set all events in the event list.

start_iteration()[source]

Called just prior to the beginning of an iteration loop. This can be overridden by inherited classes. It can be used to perform any necessary pre-iteration initialization.

step()[source]

Similar to the ‘execute’ function, but this one only executes a single Component from the workflow each time it’s called.

stop()[source]

Stop the workflow.

subdrivers()[source]

Returns a generator of of subdrivers of this driver.

update_parameters()[source]

driver_uses_derivatives.py

A driver with derivatives. Derived from Driver. Inherit from this if your driver requires gradients or Hessians.

From a driver’s perspective, derivatives are needed from its parameters to its objective(s) and constraints.

class openmdao.main.driver_uses_derivatives.DriverUsesDerivatives(*args, **kwargs)[source]

Bases: openmdao.main.driver.Driver

This is Deprecated.

eggchecker.py

openmdao.main.eggchecker.check_save_load(comp, py_dir=None, test_dir='test_dir', cleanup=True, logfile=None)[source]

Convenience routine to check that saving & reloading comp works.

comp: Component
The component to check.
py_dir: string or None
The directory in which to find local Python modules.
test_dir: string
Name of a scratch directory to unpack in.
cleanup: bool
If True, the scratch directory will be removed after the test.
logfile: string or None
Name of file for logging progress.

Creates an egg in the current directory, unpacks it in test_dir via a separate process, and then loads and runs the component in another subprocess. Returns the first non-zero subprocess exit code, or zero if everything succeeded.

exceptions.py

Exception classes for OpenMDAO.

exception openmdao.main.exceptions.CircularDependencyError[source]

Bases: exceptions.RuntimeError

Raised when a circular dependency occurs.

exception openmdao.main.exceptions.ConstraintError[source]

Bases: exceptions.ValueError

Raised when a constraint is violated.

exception openmdao.main.exceptions.RunInterrupted[source]

Bases: exceptions.RuntimeError

Raised when run() was interrupted, implying an inconsistent state.

exception openmdao.main.exceptions.RunStopped[source]

Bases: exceptions.RuntimeError

Raised when run() was stopped, implying a consistent state but not necessarily reflecting input values.

exception openmdao.main.exceptions.TracedError(orig_exc, tback=None)[source]

Bases: exceptions.Exception

An exception that encapsulates another exception and its traceback.

reraise(with_traceback=True)[source]
openmdao.main.exceptions.traceback_str(exc)[source]

Call this to get the traceback string associated with the given exception. Returns the exception string if there is no traceback.

expreval.py

class openmdao.main.expreval.ExprEvaluator(text, scope=None, getter='get')[source]

Bases: object

A class that translates an expression string into a new string containing any necessary framework access functions, e.g., set, get. The compiled bytecode is stored within the object so that it doesn’t have to be reparsed during later evaluations. A scoping object is required at construction time or evaluation time, and that object determines the form of the translated expression. Array entry access, ‘downstream’ attribute access, and function invocation are also translated in a similar way. For a description of the format of the ‘index’ arg of set/get that is generated by ExprEvaluator, see the doc string for the openmdao.main.index.process_index_entry function.

check_resolve()[source]

Return True if all variables referenced by our expression can be resolved.

evaluate(scope=None)[source]

Return the value of the scoped string, evaluated using the eval() function.

evaluate_gradient(stepsize=1e-06, wrt=None, scope=None)[source]

Return a dict containing the gradient of the expression with respect to each of the referenced varpaths. The gradient is calculated by 1st order central difference for now.

stepsize: float
Step size for finite difference.
wrt: list of varpaths
Varpaths for which we want to calculate the gradient.
get_metadata(metaname=None, scope=None)[source]

Return the specified piece of metadata if metaname is provided. Otherwise return the whole metadata dictionary. If metaname is supplied but does not exist for a given variable, None will be returned for the variable.

Returns a list of tuples containing (varname, metadata) corresponding to each variable referenced by this expression.

get_referenced_compnames()[source]

Return a set of Component names based on the pathnames of Variables referenced in our expression string. No checking is performed to verify that a given name refers to an actual Component.

get_referenced_varpaths(copy=True)[source]

Return a set of pathnames relative to scope.parent and based on the names of Variables referenced in our expression string.

get_unresolved()[source]

Return a list of all variables that cannot be resolved.

is_valid_assignee()[source]

Returns True if the syntax of our expression is valid to be on the left-hand side of an assignment. No check is performed to see if the variable(s) in the expression actually exist.

refers_to(name)[source]

Returns True if this expression refers to the given variable or component.

refs(copy=True)[source]

Returns a list of all variables referenced, including any array indices.

refs_parent()[source]

Return True if this expression references a variable in parent.

scope_transform(scope, new_scope, parent=None)[source]

Return a transformed version of our text string where the attribute names are changed based on a change in scope to the given object.

set(val, scope=None, src=None, force=False)[source]

Set the value of the referenced object to the specified value.

scope[source]

The scoping object used to evaluate the expression.

text[source]

The expression string.

exprmapper.py

class openmdao.main.exprmapper.ExprMapper(scope)[source]

Bases: object

A mapping between source expressions and destination expressions

check_connect(src, dest, scope)[source]

Check validity of connecting a source expression to a destination expression, and determine if we need to create links to pseudocomps.

connect(srcexpr, destexpr, scope, pseudocomp=None)[source]
disconnect(srcpath, destpath=None)[source]

Disconnect the given expressions/variables/components. Returns a list of edges to remove and a list of pseudocomponents to remove.

find_referring_exprs(name)[source]

Returns a list of expression strings that reference the given name, which can refer to either a variable or a component.

get_dests(src_expr)[source]

Returns the list of destination expressions that are connected to the given source expression.

get_expr(text)[source]
get_output_exprs()[source]

Return all destination expressions at the output boundary

get_source(dest_expr)[source]

Returns the text of the source expression that is connected to the given destination expression.

list_connections(show_passthrough=True, visible_only=False)[source]

Return a list of tuples of the form (outvarname, invarname).

list_pseudocomps()[source]
remove(compname)[source]

Remove any connections referring to the given component

factory.py

class openmdao.main.factory.Factory[source]

Bases: object

Base class for objects that know how to create other objects based on a type argument and several optional arguments (version, server id, and resource description).

create(typname, version=None, server=None, res_desc=None, **ctor_args)[source]

Return an object of type typname (or a proxy to it if it resides in another process) using the specified package version, server location, and resource description. Returns None if this factory is unable to create the specified type.

static form_signature()[source]

Return constructor signature for class cls.

get_available_types(groups=None)[source]

Return a set of tuples of the form (typename, metadata_dict), one for each available plugin type in the given entry point groups. If groups is None, return the set for all openmdao entry point groups.

get_signature(typname, version=None)[source]

Return constructor argument signature for typname, using the specified package version. The return value is a dictionary:

args: list
List of 1 or 2-element lists. The first element is the argument name; the second element is the default value.
varargs: string
The name of the ‘*’ argument.
kwargs: string
The name of the ‘**’ argument.

factorymanager.py

Manages the creation of framework objects, either locally or remotely.

openmdao.main.factorymanager.create(typname, version=None, server=None, res_desc=None, **ctor_args)[source]

Create and return an object specified by the given type, version, etc.

openmdao.main.factorymanager.register_class_factory(factory)[source]

Add a Factory to the factory list.

openmdao.main.factorymanager.get_available_types(groups=None)[source]

Return a set of tuples of the form (typename, dist_version), one for each available plugin type in the given entry point groups. If groups is None, return the set for all openmdao entry point groups.

file_supp.py

Support for files, either as File or external files.

class openmdao.main.file_supp.FileMetadata(path, **metadata)[source]

Bases: object

Metadata related to a file, specified by keyword arguments (except for ‘path’). By default, the metadata includes:

  • ‘path’ – a string, no default value. It may be a glob-style pattern in the case of an external file description. Non-absolute paths are relative to their owning component’s directory.
  • ‘desc’ – a string, default null.
  • ‘content_type’ – a string, default null.
  • ‘platform’ – string, default is the value of sys.platform.
  • ‘binary’ – boolean, default False.
  • ‘big_endian’ – boolean, default set from sys.byteorder. Only meaningful if binary.
  • ‘single_precision’ – boolean, default False. Only meaningful if binary.
  • ‘integer_8’ – boolean, default False. Only meaningful if binary.
  • ‘unformatted’ – boolean, default False. Only meaningful if binary.
  • ‘recordmark_8’ – boolean, default False. Only meaningful if unformatted.

In addition, external files have defined behavior for:

  • ‘input’, boolean, default False. If True, the file(s) should exist before execution.
  • ‘output’, boolean, default False. If True, the file(s) should exist after execution.
  • ‘constant’, boolean, default False. If True, the file(s) may be safely symlinked.

Arbitrary additional metadata may be assigned.

get(attr, default)[source]

Return attr value, or default if attr has not been defined.

class openmdao.main.file_supp.RemoteFile(fileobj)[source]

Bases: object

Wraps a file with remote-access annotations such that only role ‘owner’ may access the file.

close()[source]

Close the file.

flush()[source]

Flush any buffered output.

next()[source]

Return next input line or raise StopIteration.

read(size=-1)[source]

Read up to size bytes.

readline(size=-1)[source]

Read one line.

readlines(sizehint=-1)[source]

Read until EOF.

write(data)[source]

Write data to the file.

closed[source]

True if file is not open.

geom.py

class openmdao.main.geom.ParametricGeometry[source]

Bases: object

A base class for objects implementing the IParametricGeometry interface.

get_attributes(io_only=True)[source]

Return an attribute dict for use by the openmdao GUI. You only need to override this if you have inputs that the user must set directly into your ParametricGeometry object. For example, GEMParametricGeometry has a model_file input that the user can set in the GUI to change the .csm file that supplies the geometry.

get_parameters(names)[source]

Return a list of values of the named parameters.

get_static_geometry()[source]

Return a ‘static’ instance of this geometry.

invoke_callbacks()[source]

Invokes any callbacks that have been registered via register_param_list_changedCB.

list_parameters()[source]

Return a list of (name, meta) where name is the name of the parameter and meta is a metadata dict.

regen_model()[source]

Rebuid the geometry based on the current values of the input parameters.

register_param_list_changedCB(callback)[source]

Register a callback that will be called when self.invoke_callbacks() is called. self.invoke_callbacks() should be called from the inheriting class whenever any parameters are added, removed, or change their type.

set_parameter(name, value)[source]

Set the value of the named input parameter.

grid_engine.py

GridEngine resource allocator and object server.

By adding the allocator to the resource allocation manager, resource requests will interrogate the allocator to see if it could be used. This would typically be done by ExternalCode to execute a compute-intensive or parallel application.

class openmdao.main.grid_engine.GridEngineAllocator(name='GridEngine', pattern='*', authkey=None, allow_shell=True)[source]

Bases: openmdao.main.resource.FactoryAllocator

Knows about GridEngine cluster resources (via qhost). Uses GridEngineServer instead of ObjServer when deploying.

name: string
Name of allocator; used in log messages, etc.
pattern: string
fnmatch-style pattern used to select hosts from qhost output.
authkey: string
Authorization key for this allocator and any deployed servers.
allow_shell: bool
If True, execute_command() and load_model() are allowed in created servers. Since execute_command() is required, this is defaulted to be True.

Warning

There is a security risk with allow_shell True. Be careful to limit factory servers to the intended set of users!

Resource configuration file entry equivalent to defaults:

[GridEngine]
classname: openmdao.main.grid_engine.GridEngineAllocator
pattern: *
authkey: PublicKey
allow_shell: True
MPICH2: mpich
OpenMPI: ompi

The last two entries provide a mapping between DRMAA job category names and the configured GridEngine parallel environment names. Additional categories may be configured, and the above configuration is site-specific.

check_compatibility(resource_desc)[source]

Check compatibility with resource attributes.

resource_desc: dict
Description of required resources.

Returns (retcode, info). If Compatible, then retcode is zero and info is empty. Otherwise, retcode will be -2 and info will be a single-entry dictionary whose key is the incompatible key in resource_desc and whose value provides data regarding the incompatibility.

configure(cfg)[source]

Configure allocator from ConfigParser instance. Normally only called during manager initialization.

cfg: ConfigParser
Configuration data is located under the section matching this allocator’s name.

Allows modifying factory options, pattern and the job category map.

deploy(name, resource_desc, criteria)[source]

Deploy a server suitable for resource_desc. Returns a proxy to the deployed server. Overrides superclass to pass category_map to server.

name: string
Name for server.
resource_desc: dict
Description of required resources.
criteria: dict
The dictionary returned by time_estimate().
max_servers(resource_desc)[source]

Return the maximum number of servers which could be deployed for resource_desc. The value needn’t be exact, but performance may suffer if it overestimates. The value is used to limit the number of concurrent evaluations.

resource_desc: dict
Description of required resources.
time_estimate(resource_desc)[source]

Return (estimate, criteria) indicating how well this resource allocator can satisfy the resource_desc request. The estimate will be:

  • >0 for an estimate of walltime (seconds).
  • 0 for no estimate.
  • -1 for no resource at this time.
  • -2 for no support for resource_desc.

The returned criteria is a dictionary containing information related to the estimate, such as hostnames, load averages, unsupported resources, etc.

resource_desc: dict
Description of required resources.
class openmdao.main.grid_engine.GridEngineServer(name='', allow_shell=False, allowed_types=None)[source]

Bases: openmdao.main.objserverfactory.ObjServer

Knows about executing a command via qsub.

configure(category_map)[source]

Configure parallel environment category map.

category_map: dict
Maps from ‘job_category’ to parallel environment name.
execute_command(resource_desc)[source]

Submit command based on resource_desc.

resource_desc: dict
Description of command and required resources.

The ‘-V’ qsub option is always used to export the current environment to the job. This environment is first updated with any ‘job_environment’ data. The ‘-sync yes’ qsub option is used to wait for job completion.

Other job resource keys are processed as follows:

Resource Key Translation
submit_as_hold -h
rerunnable -r yes|no
working_directory -wd value
job_category Sets parallel environment
min_cpus Sets parallel environment
max_cpus Sets parallel environment
min_phys_memory Ignored
email -M value
email_on_started -m b
email_on_terminated -m e
job_name -N value
input_path -i value
output_path -o value
error_path -e value
join_files -j yes|no
reservation_id -ar value
queue_name -q value
priority -p value
start_time -a value
deadline_time Ignored
accounting_id -A value

Where value is the corresponding resource value.

If ‘working_directory’ is not specified, add -cwd. If ‘input_path’ is not specified, add -i /dev/null. If ‘output_path’ is not specified, add -o <remote_command>.stdout. If ‘error_path’ is not specified, add -j yes.

If ‘native_specification’ is specified, it is added to the qsub command just before ‘remote_command’ and ‘args’.

If specified, ‘job_category’ is used to index into the category map set up during allocator configuration. The mapped category name as well as the ‘min_cpus’ and ‘max_cpus’ values are used with the -pe qsub option.

Some resource limits are also handled:

Resource Key Translation
core_file_size Ignored
data_seg_size Ignored
file_size Ignored
open_files Ignored
stack_size Ignored
virtual_memory Ignored
cpu_time -l h_cpu= value
wallclock_time -l h_rt= value

Output from qsub itself is routed to qsub.out.

hasconstraints.py

Functions in the HasConstraints, HasEqConstraints, and HasIneqConstraints interfaces.

class openmdao.main.hasconstraints.Constraint(lhs, comparator, rhs, scope)[source]

Bases: object

Object that stores info for a single constraint.

activate()[source]

Make this constraint active by creating the appropriate connections in the dependency graph.

copy()[source]
deactivate()[source]

Remove this constraint from the dependency graph and remove its pseudocomp from the scoping object.

evaluate(scope)[source]

Returns the value of the constraint as a sequence.

evaluate_gradient(scope, stepsize=1e-06, wrt=None)[source]

Returns the gradient of the constraint eq/ineq as a tuple of the form (lhs, rhs, comparator, is_violated).

get_referenced_compnames()[source]

Returns a set of names of each component referenced by this constraint.

get_referenced_varpaths(copy=True)[source]

Returns a set of names of each component referenced by this constraint.

size[source]

Total scalar items in this constraint.

class openmdao.main.hasconstraints.HasConstraints(parent)[source]

Bases: object

Add this class as a delegate if your Driver supports both equality and inequality constraints. For methods related to both equality and inequality constraints (such as eval_constraints()), data for the equality constraints comes first.

add_constraint(expr_string, name=None, scope=None)[source]

Adds a constraint in the form of a boolean expression string to the driver.

expr_string: str
Expression string containing the constraint.
name: str (optional)
Name to be used to refer to the constraint rather than its expression string.
scope: object (optional)
The object to be used as the scope when evaluating the expression.
add_existing_constraint(scope, constraint, name=None)[source]

Adds an existing Constraint object to the driver.

scope: container object where constraint expression will
be evaluated.

constraint: Constraint object

name: str (optional)
Name to be used to refer to the constraint rather than its expression string.
clear_constraints()[source]

Removes all constraints.

copy_constraints()[source]
eval_constraints(scope=None)[source]

Returns a list of constraint values.

eval_eq_constraints(scope=None)[source]

Returns a list of constraint values.

eval_ineq_constraints(scope=None)[source]

Returns a list of constraint values.

get_constraints()[source]

Returns an ordered dict of constraint objects

get_eq_constraints()[source]

Returns an ordered dict of equality constraint objects.

get_expr_depends()[source]

Returns a list of tuples of the form (src_comp_name, dest_comp_name) for each dependency introduced by a constraint.

get_ineq_constraints()[source]

Returns an ordered dict of inequality constraint objects.

get_referenced_compnames()[source]

Returns a set of names of each component referenced by a constraint.

get_referenced_varpaths()[source]

Returns a set of names of each component referenced by a constraint.

get_references(name)[source]

Return references to component name in preparation for subsequent restore_references() call.

name: string
Name of component being removed.
list_constraint_targets()[source]

Returns a list of outputs suitable for calc_gradient().

list_constraints()[source]

Return a list of strings containing constraint expressions.

list_eq_constraint_targets()[source]

Returns a list of outputs suitable for calc_gradient().

list_ineq_constraint_targets()[source]

Returns a list of outputs suitable for calc_gradient().

list_pseudocomps()[source]

Returns a list of pseudocomponent names associated with our constraints.

mimic(target)[source]

Tries to mimic the target object’s constraints. Target constraints that are incompatible with raise an exception.

remove_constraint(expr_string)[source]

Removes the constraint with the given string.

remove_references(name)[source]

Remove references to component name.

name: string
Name of component being removed.
restore_references(refs)[source]

Restore references to component name from refs.

refs: dict
References returned by get_references().
total_constraints()[source]

Returns the total number of constraint values.

total_eq_constraints()[source]

Returns the total number of equality constraint values.

total_ineq_constraints()[source]

Returns the total number of inequality constraint values.

class openmdao.main.hasconstraints.HasEqConstraints(parent, allowed_types=None)[source]

Bases: openmdao.main.hasconstraints._HasConstraintsBase

Add this class as a delegate if your Driver supports equality constraints but does not support inequality constraints.

add_constraint(expr_string, name=None, scope=None)[source]

Adds a constraint in the form of a boolean expression string to the driver.

expr_string: str
Expression string containing the constraint.
name: str (optional)
Name to be used to refer to the constraint rather than its expression string.
scope: object (optional)
The object to be used as the scope when evaluating the expression.
add_existing_constraint(scope, constraint, name=None)[source]

Adds an existing Constraint object to the driver.

scope: container object where constraint expression will
be evaluated.

constraint: Constraint object

name: str (optional)
Name to be used to refer to the constraint rather than its expression string.
eval_eq_constraints(scope=None)[source]

Returns a list of constraint values.

get_constraints()[source]

Returns an ordered dict of constraint objects

get_eq_constraints()[source]

Returns an ordered dict of constraint objects.

list_eq_constraint_targets()[source]

Returns a list of outputs suitable for calc_gradient().

total_eq_constraints()[source]

Returns the total number of constraint values.

class openmdao.main.hasconstraints.HasIneqConstraints(parent, allowed_types=None)[source]

Bases: openmdao.main.hasconstraints._HasConstraintsBase

Add this class as a delegate if your Driver supports inequality constraints but does not support equality constraints.

add_constraint(expr_string, name=None, scope=None)[source]

Adds a constraint in the form of a boolean expression string to the driver.

expr_string: str
Expression string containing the constraint.
name: str (optional)
Name to be used to refer to the constraint rather than its expression string.
scope: object (optional)
The object to be used as the scope when evaluating the expression.
add_existing_constraint(scope, constraint, name=None)[source]

Adds an existing Constraint object to the driver.

scope: container object where constraint expression will
be evaluated.

constraint: Constraint object

name: str (optional)
Name to be used to refer to the constraint rather than its expression string.
eval_ineq_constraints(scope=None)[source]

Returns a list of constraint values.

get_constraints()[source]

Returns an ordered dict of constraint objects

get_ineq_constraints()[source]

Returns an ordered dict of inequality constraint objects.

list_ineq_constraint_targets()[source]

Returns a list of outputs suitable for calc_gradient().

total_ineq_constraints()[source]

Returns the total number of inequality constraint values.

hasevents.py

class openmdao.main.hasevents.HasEvents(parent)[source]

Bases: object

This class provides an implementation of the IHasEvents interface.

add_event(name)[source]

Adds an event variable to be set by the driver.

name: string
Name of the event variable the driver should set during execution.
clear_events()[source]

Remove all event variables from the driver’s list.

get_events()[source]

Return the list of event variables to be set by this driver.

list_available_events()[source]

Return a list of all available events in the driver’s workflow.

mimic(target)[source]

Mimic the target HasEvents by copying its event list.

remove_event(name)[source]

Remove the name of the specified event variable from the driver’s list of event variables to be set during execution.

set_events()[source]

Set all events in the event list.

hasobjective.py

class openmdao.main.hasobjective.HasObjective(parent)[source]

Bases: openmdao.main.hasobjective.HasObjectives

eval_objective()[source]

Returns a list of values of the evaluated objectives.

class openmdao.main.hasobjective.HasObjectives(parent, max_objectives=0)[source]

Bases: object

This class provides an implementation of the IHasObjectives interface.

add_objective(expr, name=None, scope=None)[source]

Adds an objective to the driver.

expr: string
String containing the objective expression.
name: string (optional)
Name to be used to refer to the objective in place of the expression string.
scope: object (optional)
The object to be used as the scope when evaluating the expression.
add_objectives(obj_iter, scope=None)[source]

Takes an iterator of objective strings and creates objectives for them in the driver.

clear_objectives()[source]

Removes all objectives.

eval_objectives()[source]

Returns a list of values of the evaluated objectives.

get_expr_depends()[source]

Returns a list of tuples of the form (comp_name, parent_name) for each component referenced by our objectives. Note that this does not include pseudo-components.

get_objectives()[source]

Returns an OrderedDict of objective expressions.

get_referenced_compnames()[source]

Returns the names of components referenced by the objectives.

get_referenced_varpaths()[source]

Returns the names of variables referenced by the objectives.

get_references(name)[source]

Return references to component name in preparation for subsequent restore_references() call.

name: string
Name of component being removed.
list_objective_targets()[source]

Returns a list of outputs suitable for calc_gradient().

list_pseudocomps()[source]

Returns a list of pseudocomponent names associated with our parameters.

mimic(target)[source]

Copy what objectives we can from the target.

remove_objective(expr)[source]

Removes the specified objective expression. Spaces within the expression are ignored.

remove_references(name)[source]

Remove references to component name.

name: string
Name of component being removed.
restore_references(refs)[source]

Restore references to component name from refs.

refs: object
Value returned by get_references().
class openmdao.main.hasobjective.Objective(*args, **kwargs)[source]

Bases: openmdao.main.expreval.ConnectedExprEvaluator

activate()[source]

Make this constraint active by creating the appropriate connections in the dependency graph.

deactivate()[source]

Remove this objective from the dependency graph and remove its pseudocomp from the scoping object.

hasparameters.py

class openmdao.main.hasparameters.ArrayParameter(target, high=None, low=None, scaler=None, adder=None, start=None, fd_step=None, scope=None, name=None, _expreval=None, _val=None)[source]

Bases: openmdao.main.hasparameters.ParameterBase

A parameter whose target is an array. If scaler and/or adder are not None, then high, low, and start, if not None, are assumed to be expressed in unscaled form. If high and low are not supplied, then their values will be pulled from the target variable (along with a start value), and are assumed to be in scaled form, so their values will be unscaled prior to being stored in the ArrayParameter.

configure()[source]

Reconfigure from potentially changed target.

copy()[source]

Return a copy of this parameter.

evaluate(scope=None)[source]

Returns the value of this parameter as a sequence.

get_fd_step()[source]

Returns finite difference step size as a sequence.

get_high()[source]

Returns upper limits as a sequence.

get_low()[source]

Returns lower limits as a sequence.

override(low=None, high=None, scaler=None, adder=None, start=None, fd_step=None, name=None)[source]

Called by add_parameter() when the target is this ArrayParameter.

set(value, scope=None)[source]

Assigns the given value to the array referenced by this parameter.

names[source]

A list containing the names of this parameter’s scalar items.

size[source]

Total scalar items in this parameter.

class openmdao.main.hasparameters.HasParameters(parent)[source]

Bases: object

This class provides an implementation of the IHasParameters interface.

add_parameter(target, low=None, high=None, scaler=None, adder=None, start=None, fd_step=None, name=None, scope=None)[source]

Adds a parameter or group of parameters to the driver.

target: string or iter of strings or Parameter
What the driver should vary during execution. A target is an expression that can reside on the left-hand side of an assignment statement, so typically it will be the name of a variable or possibly a subscript expression indicating an entry within an array variable, e.g., x[3]. If an iterator of targets is given, then the driver will set all targets given to the same value whenever it varies this parameter during execution. If a Parameter instance is given, then that instance is copied into the driver with any other arguments specified, overiding the values in the given parameter.
low: float (optional)
Minimum allowed value of the parameter. If scaler and/or adder is supplied, use the transformed value here. If target is an array, this may also be an array, but must have the same size.
high: float (optional)
Maximum allowed value of the parameter. If scaler and/or adder is supplied, use the transformed value here. If target is an array, this may also be an array, but must have the same size.
scaler: float (optional)
Value to multiply the possibly offset parameter value by. If target is an array, this may also be an array, but must have the same size.
adder: float (optional)
Value to add to parameter prior to possible scaling. If target is an array, this may also be an array, but must have the same size.
start: any (optional)
Value to set into the target or targets of a parameter before starting any executions. If not given, analysis will start with whatever values are in the target or targets at that time. If target is an array, this may also be an array, but must have the same size.
fd_step: float (optional)
Step-size to use for finite difference calculation. If no value is given, the differentiator will use its own default. If target is an array, this may also be an array, but must have the same size.
name: str (optional)
Name used to refer to the parameter in place of the name of the variable referred to in the parameter string. This is sometimes useful if, for example, multiple entries in the same array variable are declared as parameters.
scope: object (optional)
The object to be used as the scope when evaluating the expression.

If neither “low” nor “high” is specified, the min and max will default to the values in the metadata of the variable being referenced. If they are not specified in the metadata and not provided as arguments, a ValueError is raised.

clear_parameters()[source]

Removes all parameters.

config_parameters()[source]

Reconfigure parameters from potentially changed targets.

eval_parameters(scope=None, dtype='d')[source]

Return evaluated parameter values.

dtype: string or None
If not None, return an array of this dtype. Otherwise just return a list (useful if parameters may be of different types).
get_expr_depends()[source]

Returns a list of tuples of the form (src_comp_name, dest_comp_name) for each dependency introduced by a parameter.

get_fd_steps(dtype='d')[source]

Return fd_step values, they may include None.

dtype: string or None
If not None, return an array of this dtype. Otherwise just return a list (useful if it’s valid to have None for a step size).
get_lower_bounds(dtype='d')[source]

Return lower bound values.

dtype: string or None
If not None, return an array of this dtype. Otherwise just return a list (useful if parameters may be of different types).
get_parameters()[source]

Returns an ordered dict of parameter objects.

get_referenced_compnames()[source]

Return a set of Component names based on the pathnames of Variables referenced in our target strings.

get_referenced_varpaths()[source]

Return a set of Variable names referenced in our target strings.

get_references(name)[source]

Return references to component name in preparation for subsequent restore_references() call.

name: string
Name of component being removed.
get_upper_bounds(dtype='d')[source]

Return upper bound values.

dtype: string or None
If not None, return an array of this dtype. Otherwise just return a list (useful if parameters may be of different types).
init_parameters()[source]

Sets all parameters to their start value if a start value is given

list_param_group_targets()[source]

Returns a list of tuples that contain the targets for each parameter group.

list_param_targets()[source]

Returns a list of parameter targets. Note that this list may contain more entries than the list of Parameter, ParameterGroup, and ArrayParameter objects since ParameterGroup instances have multiple targets.

mimic(target)[source]
remove_parameter(name)[source]

Removes the parameter with the given name.

remove_references(name)[source]

Remove references to component name.

name: string
Name of component being removed.
restore_references(refs)[source]

Restore references to component name from refs.

refs: object
Value returned by get_references().
set_parameter_by_name(name, value, case=None, scope=None)[source]

Sets a single parameter by its name attribute.

name: str
Name of the parameter. This is either the name alias given when the parameter was added or the variable path of the parameter’s target if no name was given.
value: object (typically a float)
Value of the parameter to be set.
case: Case (optional)
If supplied, the values will be associated with their corresponding targets and added as inputs to the Case instead of being set directly into the model.
set_parameters(values, case=None, scope=None)[source]

Pushes the values in the iterator ‘values’ into the corresponding variables in the model. If the ‘case’ arg is supplied, the values will be set into the case and not into the model.

values: iterator
Iterator of input values with an order defined to match the order of parameters returned by the get_parameters method. All ‘values’ must support the len() function.
case: Case (optional)
If supplied, the values will be associated with their corresponding targets and added as inputs to the Case instead of being set directly into the model.
total_parameters()[source]

Returns the total number of values to be set.

class openmdao.main.hasparameters.Parameter(target, high=None, low=None, scaler=None, adder=None, start=None, fd_step=None, scope=None, name=None, _expreval=None, _val=None)[source]

Bases: openmdao.main.hasparameters.ParameterBase

A scalar parameter.

configure()[source]

Reconfigure from potentially changed target.

copy()[source]

Return a copy of this Parameter.

evaluate(scope=None)[source]

Returns the value of this parameter as a sequence.

get_fd_step()[source]

Returns finite difference step size as a sequence.

get_high()[source]

Returns upper limits as a sequence.

get_low()[source]

Returns lower limits as a sequence.

override(low=None, high=None, scaler=None, adder=None, start=None, fd_step=None, name=None)[source]

Called by add_parameter() when the target is this Parameter.

set(val, scope=None)[source]

Assigns the given value to the target of this parameter.

names[source]

A one element list containing the name of this parameter.

size[source]

Total scalar items in this parameter.

class openmdao.main.hasparameters.ParameterBase(target, high=None, low=None, scaler=None, adder=None, start=None, fd_step=None, scope=None, name=None, _expreval=None)[source]

Bases: object

Abstract base class for parameters.

get_config()[source]

Return configuration arguments.

get_metadata(metaname=None)[source]

Returns a list of tuples of the form (varname, metadata), with one entry for each variable referenced by the parameter expression. The metadata value found in the tuple will be either the specified piece of metadata, if metaname is provided, or the whole metadata dictionary for that variable if it is not.

get_referenced_compnames()[source]

Return a set of Component names based on the pathnames of Variables referenced in our target string.

get_referenced_varpaths()[source]

Return a set of Variable names referenced in our target string.

initialize(scope)[source]

Set parameter to initial value.

set(value, scope=None)[source]

Assigns the given value to the target referenced by this parameter, must be overridden.

target[source]

The target of this parameter.

targets[source]

A one element list containing the target of this parameter.

class openmdao.main.hasparameters.ParameterGroup(params)[source]

Bases: object

A group of Parameters that are treated as one, i.e., they are all set to the same value.

configure()[source]

Reconfigure from potentially changed target.

copy()[source]

Return a copy of this ParameterGroup.

evaluate(scope=None)[source]

Return the value of the first parameter in our target list as a sequence. Values of all of our targets are assumed to be the same.

get_config()[source]

Return list of configuration argument tuples.

get_fd_step()[source]

Returns finite difference step size as a sequence.

get_high()[source]

Returns upper limits as a sequence.

get_low()[source]

Returns lower limits as a sequence.

get_metadata(metaname=None)[source]

Returns a list of tuples of the form (varname, metadata), with one entry for each variable referenced by a target expression. The metadata value found in the tuple will be either the specified piece of metadata, if metaname is provided, or the whole metadata dictionary for that variable if it is not.

get_referenced_compnames()[source]

Return a set of Component names based on the pathnames of Variables referenced in our target strings.

get_referenced_varpaths()[source]

Return a set of Variable names referenced in our target strings.

get_referenced_vars_by_compname()[source]

Return a mapping from component name to referencing parameters.

initialize(scope)[source]

Set parameter to initial value.

override(low=None, high=None, scaler=None, adder=None, start=None, fd_step=None, name=None)[source]

Called by add_parameter() when the target is this ParameterGroup.

set(value, scope=None)[source]

Set all targets to the given value.

names[source]

A one element list containing the name of this parameter.

size[source]

Total scalar items in this parameter.

target[source]

The target of the first parameter in the group.

targets[source]

A list containing the targets of this parameter.

hasstopcond.py

class openmdao.main.hasstopcond.HasStopConditions(parent)[source]

Bases: object

A delegate that adds handling of stop conditions that are supplied as expression strings.

add_stop_condition(exprstr)[source]
clear_stop_conditions()[source]

Removes all stop conditions.

eval_stop_conditions()[source]

Returns a list of evaluated stop conditions.

get_stop_conditions()[source]

Returns a list of stop condition strings.

mimic(target)[source]

Copy stop conditions from the target.

remove_stop_condition(expr_string)[source]

Removes the stop condition matching the given string.

should_stop()[source]

Return True if any of the stopping conditions evaluate to True.

implicitcomp.py

Class definition for an Implicit Component.

class openmdao.main.implicitcomp.ImplicitComponent[source]

Bases: openmdao.main.component.Component

This is the base class for a component that represents an implicit function

Bool eval_only

Set to True to have this comp perform a single evaluate when execute() is called.

  • default: ‘False’
  • iotype: ‘in’
  • framework_var: True
  • vartypename: ‘Bool’
  • assumed_default: False
check_config()[source]

Override this function to perform configuration checks specific to your class. Bad configurations should raise an exception.

config_changed(update_parent=True)[source]

Reset internally cached values.

evaluate()[source]

run a single step to calculate the residual values for the given state var values. This must be overridden in derived classes.

execute()[source]

Performs either an internal solver or a single evaluation. Do not override this function.

get_residuals()[source]

Return a vector of residual values.

get_state()[source]

Return the current flattened state vector.

list_residuals()[source]

Return a list of names of residual variables in alphabetical order. This specifies the order the residual vector, so if you use a different order internally, override this function to return the residuals in the desired order.

list_states()[source]

Return a list of names of state variables in alphabetical order. This specifies the order the state vector, so if you use a different ordering internally, override this function to return the states in the desired order.

set_state(X)[source]

Take the given state vector and set its values into the correct state variables.

solve()[source]

Calculates the states that satisfy residuals using scipy.fsolve. You can override this function to provide your own internal solve.

importfactory.py

class openmdao.main.importfactory.ImportFactory[source]

Bases: openmdao.main.factory.Factory

Creates objects using the standard Python __import__ mechanism. The object must have a ctor with the same name as the module, minus the file extension. For example, to create a MyComp object, the module must be named MyComp.py (or .pyc or .pyo). This factory does not support specific version creation or creation on a remote server.

create(typ, version=None, server=None, res_desc=None, **ctor_args)[source]

Tries to import the given named module and return a factory function from it. The factory function or constructor must have the same name as the module. The module must be importable in the current Python environment.

get_available_types(groups=None)[source]

Does nothing but is included to adhere to the Factory interface.

get_signature(typname, version=None)[source]

Return constructor argument signature for typname, using the specified package version. The return value is a dictionary.

index.py

openmdao.main.index.deep_getattr(obj, pathname)[source]

Returns the attrbute indicated by the given pathname or raises an exception if it doesn’t exist.

openmdao.main.index.deep_hasattr(obj, pathname)[source]

Returns True if the attrbute indicated by the given pathname exists; False otherwise.

openmdao.main.index.get_indexed_value(obj, name, index=None)[source]
openmdao.main.index.index_retains_metadata(index)[source]
openmdao.main.index.index_to_text(index)[source]

Returns a string representation of the given index. Doesn’t work for functions

openmdao.main.index.process_index_entry(obj, idx)[source]

Return a new object based on a starting object and some operation indicated by idx that can be either an index into a container, an attribute access, or a function call. idx can be a non-tuple hashable object, which will be interpreted as an index to a container, or it can be a tuple of the form (operation_id, stuff) where operation_id is as follows (the named constants are defined in expreval.py):

INDEX = 0
ATTR = 1
CALL = 2
SLICE = 3
EXTSLICE = 4

On the off chance that you want to use a tuple as a key into a dict, you’ll have to nest your key tuple inside of an INDEX tuple to avoid ambiguity, e.g., (INDEX, my_tuple)

The forms of the various tuples are:

INDEX:   (0, idx)  where idx is some hashable value
ATTR:    (1, name) where name is the attribute name
CALL:    (2, args, kwargs) where args is a list of values, and kwargs is a list
         of tuples of the form (keyword,value). kwargs can be left out if
         empty.  args can be left out if empty as long as kwargs are also
         empty, for example, (2,) and  (2,[],[('foo',1)]) are valid but
         (2,[('foo',1)]) is not.
SLICE:   (3, lower, upper, step) All members must be present and should have a
         value of None if not set.
EXTSLICE:  (4, plus a combination of (lower,upper,step) tuples and indexes)
           For example, (4, (None,None,None), 2)

interfaces.py

Interfaces for the OpenMDAO project.

openmdao.main.interfaces.obj_has_interface(obj, *ifaces)[source]

Returns True if the specified object implements one of the interfaces specified.

mp_distributing.py

This module is based on the distributing.py file example which was (temporarily) posted with the multiprocessing module documentation.

This code uses ssh (or plink on Windows) to access remote hosts and assumes authorization has been set up on all hosts in such a way that no user intervention for passwords or passphrases is required.

Also, it’s assumed that connections to remote hosts will access a UNIX-like shell. Remote Windows hosts will need to be configured for cygwin or something similar.

class openmdao.main.mp_distributing.Cluster(hostlist, modules=None, authkey=None, allow_shell=False, hostname=None)[source]

Bases: openmdao.main.mp_support.OpenMDAO_Manager

Represents a collection of hosts.

hostlist: list(Host)
Hosts which are to be members of the cluster.
modules: list(string)
Names of modules to be sent to each host.
authkey: string
Authorization key; passed to OpenMDAO_Manager.
allow_shell: bool
If True, execute_command() and load_model() are allowed in created servers. Use with caution!
hostname: string
Fully qualified domain name for this host. Normally :meth:socket.getfqdn is used, but on some systems it doesn’t report an externally usable address. This is the address remote hosts will use to connect back to.

Once started, available hosts may be accessed via sequence operations.

openmdao_main_resource_LocalAllocator(*args, **kwds)
shutdown()[source]

Shut down all remote managers and then this one.

start()[source]

Start this manager and all remote managers. If some managers fail to start, errors are logged and the corresponding host’s state is set to failed. You can use len(cluster) to determine how many remote managers are available.

A RuntimeError will be raised if no managers were successfully started.

class openmdao.main.mp_distributing.Host(hostname, python=None, tunnel_incoming=False, tunnel_outgoing=False, identity_filename=None)[source]

Bases: object

Represents a host to use as a node in a cluster.

hostname: string
Name of the host. ssh is used to log into the host. To log in as a different user, use a host name of the form: “username@somewhere.org”.
python: string
Path to the Python command to be used on hostname.
tunnel_incoming: bool
True if we need to set up a tunnel for hostname to connect to us. This is the case when a local firewall blocks connections.
tunnel_outgoing: bool
True if we need to set up a tunnel to connect to hostname. This is the case when a remote firewall blocks connections.
identity_filename: string
Path to optional identity file to pass to ssh.
poll()[source]

Poll for process status.

register(cls)[source]

Register proxy info to be sent to remote server.

cls: class
Class to be registered.
start_manager(index, authkey, address, files, allow_shell=False)[source]

Launch remote manager process via ssh. The environment variable OPENMDAO_KEEPDIRS can be used to avoid removal of the temporary directory used on the host.

index: int
Index in parent cluster.
authkey: string
Authorization key used to connect to host server.
address: (ip_addr, port) or string referring to pipe.
Address to use to connect back to parent.
files: list(string)
Files to be sent to support server startup.
allow_shell: bool
If True, execute_command() and load_model() are allowed in created servers. Use with caution!
class openmdao.main.mp_distributing.HostManager(address, authkey)[source]

Bases: openmdao.main.mp_support.OpenMDAO_Manager

Manager used for spawning processes on a remote host.

address: (ip_addr, port) or string referring to pipe.
Address to use to connect back to parent.
authkey: string
Authorization key, passed to OpenMDAO_Manager.
classmethod from_address(address, authkey, host)[source]

Return manager given an address.

address: (ip_addr, port) or string referring to pipe.
Address to connect to.
authkey: string
Authorization key.
host: Host
Host we’re managing.
openmdao_main_resource_LocalAllocator(*args, **kwds)
openmdao.main.mp_distributing.main()[source]

Code which runs a host manager. Expects configuration data from parent on stdin. Replies with address and optionally public key. The environment variable OPENMDAO_KEEPDIRS can be used to avoid removal of the temporary directory used here.

mp_support.py

This module defines modified versions of some classes and functions defined in multiprocessing.managers to support OpenMDAO distributed simulations.

Channel communication can be secured by setting authkey to ‘PublicKey’. When authkey is ‘PublicKey’, an additional session establishment protocol is used between the Proxy and Server:

  1. Proxy sends session request containing the proxy’s public key, encrypted with the server’s public key (obtained when told what server to connect to).
  2. Server responds with random session key, encrypted with proxy’s public key.
  3. Subsequent communication is encrypted with the session key (which presumably is quicker than public/private key encryption).

If authkey is not ‘PublicKey’, then the above session protocol is not used, and channel data is in the clear.

Public methods of an object are determined by a role-based access control attribute associated with the method. The server will verify that the current role is allowed access. The current role is determined by an AccessController based on a Credentials object received from the proxy.

Assuming the credentials check passes, the server will set its credentials to those specified by the AccessController during the execution of the method.

class openmdao.main.mp_support.ObjectManager(obj, address=None, serializer='pickle', authkey=None, name=None, allowed_hosts=None, allowed_users=None)[source]

Bases: object

Provides a multiprocessing interface for an existing object.

obj: object
Object to provide remote access to.
address: tuple or string
A multiprocessing address specifying an Internet address or a pipe.
serializer: string
Which serialization method to use.
authkey: string
Authorization key. Inherited from the current Process object if not specified.
name: string
Name for server, used in log files, etc.
allowed_hosts: list(string)
Host address patterns to check against.
allowed_users: dict
Dictionary of users and corresponding public keys allowed access. If None, any user may access. If empty, no user may access.
proxy[source]

Proxy for our object server.

class openmdao.main.mp_support.OpenMDAO_Manager(address=None, authkey=None, serializer='pickle', pubkey=None, name=None, allowed_hosts=None, allowed_users=None, allow_tunneling=False)[source]

Bases: multiprocessing.managers.BaseManager

Uses OpenMDAO_Server, retains the public key, and puts some slack in shutdown timing.

address: tuple or string
A multiprocessing address specifying an Internet address or a pipe.
authkey: string
Authorization key. Inherited from the current Process object if not specified.
serializer: string
Which serialization method to use.
pubkey: public key
Public portion of server’s public/private key pair. Needed for client/proxy side.
name: string
Name for server, used in log files, etc.
allowed_hosts: list(string)
Host address patterns to check against.
allowed_users: dict
Dictionary of users and corresponding public keys allowed access. If None, any user may access. If empty, no user may access.
allow_tunneling: bool
If True, allow connections from 127.0.0.1 (localhost), even if not listed otherwise.
get_server()[source]

Return a server object with serve_forever() and address attribute.

start(cwd=None, log_level=10)[source]

Spawn a server process for this manager object.

cwd: string
Directory to start in.
log_level: int
Initial root logging level for the server process.

This version retrieves the server’s public key.

class openmdao.main.mp_support.OpenMDAO_Proxy(*args, **kwds)[source]

Bases: multiprocessing.managers.BaseProxy

Proxy for a remote object.

args: tuple
Passed to BaseProxy.
kwds: dict
If it contains pubkey, then that value is used for the remote public key, and the entry is removed before being passed to BaseProxy.

This version sends credentials and provides dynamic result proxy generation.

Note

BaseProxy.__str__() (used by str() and the %s format) will return __repr__() of the remote object. To avoid the network round-trip delay, use repr() or the %r format.

static manager_is_alive(address)[source]

Check whether manager is still alive.

address: tuple or string
A multiprocessing address specifying an Internet address or a pipe.
class openmdao.main.mp_support.OpenMDAO_Server(registry, address, authkey, serializer, name=None, allowed_hosts=None, allowed_users=None, allow_tunneling=False)[source]

Bases: multiprocessing.managers.Server

A Server that supports dynamic proxy generation and credential checking.

registry: dict
Manager’s proxy registry.
address: tuple or string
A multiprocessing address specifying an Internet address or a pipe.
authkey: string
Authorization key. Inherited from the current Process object if not specified.
serializer: string
Which serialization method to use.
name: string
Name for server, used in log files, etc.
allowed_hosts: list(string)
Host address patterns to check against. Optional if allowed_users is specified.
allowed_users: dict
Dictionary of users and corresponding public keys allowed access. If None, any user may access. If empty, no user may access. The host portions of user strings are used for address patterns.
allow_tunneling: bool
If True, allow connections from the local host, even if not listed otherwise.
create(conn, typeid, *args, **kwds)[source]

Create a new shared object and return its id.

conn: socket or pipe
Connection to process.
typeid: string
Identifier string for type of object to be created.

This version uses public_methods().

debug_info(conn)[source]

Return string representing state of id_to_obj mapping.

conn: socket or pipe
Unused.

This version handles proxies in a special manner.

handle_request(conn)[source]

Handle a new connection.

conn: socket or pipe
Connection to process.

This version filters host connections and avoids getting upset if it can’t deliver a challenge. This is to deal with immediately closed connections caused by manager_is_alive() which are used to avoid getting hung trying to connect to a manager which is no longer there.

serve_client(conn)[source]

Handle requests from the proxies in a particular process/thread.

conn: socket or pipe
Connection to process.

This version supports dynamic proxy generation and credential checking.

serve_forever()[source]

Run the server forever. This version supports host connection filtering. Connection filtering allows for PublicKey servers which aren’t accessible by just any host.

shutdown(conn)[source]

Shutdown this process.

public_key[source]

Public key for session establishment.

public_key_text[source]

Text representation of public key.

openmdao.main.mp_support.has_interface(obj, *ifaces)[source]

obj_has_interface() replacement for when obj might be a proxy.

obj: object
Object to be tested.
ifaces: list[Interface]
Interfaces to be tested against.

Returns True if obj or the object obj refers to supports at least one Interface in ifaces.

openmdao.main.mp_support.is_instance(obj, type_info)[source]

isinstance() replacement for when obj might be a proxy.

obj: object
Object to be tested.
type_info: class or tuple of classes
Class(es) to be tested against.

Returns True if obj is an instance of type_info or the object obj refers to is an instance of type_info.

openmdao.main.mp_support.register(cls, manager, module=None)[source]

Register class cls proxy info with manager. The class will be registered under it’s full path, with ‘.’ replaced by ‘_’. Not typically called by user code.

cls: class
Class to be registered.
manager: OpenMDAO_Manager
Manager to register with.
module: string
Module name for registration. Necessary if cls might be defined by module ‘__main__’.

mp_util.py

Multiprocessing support utilities.

openmdao.main.mp_util.decrypt(msg, session_key)[source]

If session_key is specified, returns object from encrypted pickled data contained in msg. Otherwise msg is returned.

msg: string
Encrypted text of pickled object.
session_key: string
Key used for encryption. Should be at least 16 bytes long.
openmdao.main.mp_util.encrypt(obj, session_key)[source]

If session_key is specified, returns (length, data) of encrypted, pickled, obj. Otherwise obj is returned.

obj: object
Object to be pickled and encrypted.
session_key: string
Key used for encryption. Should be at least 16 bytes long.

Return True if address is from an allowed host.

address: string
Connection address to be checked.
allowed_hosts: list(string)
IPv4 address patterns to check against. If a pattern ends with ‘.’ (a domain) then the host address must begin with the pattern. Otherwise the host address must completely match the pattern.
logger: logging.Logger
Used to output warnings about rejected connections.
openmdao.main.mp_util.keytype(authkey)[source]

Just returns a string showing the type of authkey.

authkey: string
Key to report type of.
openmdao.main.mp_util.make_typeid(obj)[source]

Returns a type ID string from obj‘s module and class names by replacing ‘.’ with ‘_’.

openmdao.main.mp_util.public_methods(obj)[source]

Returns a list of names of the methods of obj to be exposed. Supports attribute access in addition to RBAC decorated methods.

obj: object
Object to be scanned.
openmdao.main.mp_util.read_allowed_hosts(path)[source]

Return allowed hosts data read from path.

path: string
Path to allowed hosts file (typically ‘hosts.allow’).

The file should contain IPv4 host addresses, IPv4 domain addresses, or hostnames, one per line. Blank lines are ignored, and ‘#’ marks the start of a comment which continues to the end of the line.

openmdao.main.mp_util.read_server_config(filename)[source]

Read a server’s configuration information.

filename: string
Path to file to be read.

Returns a dictionary containing ‘address’, ‘port’, ‘tunnel’, ‘key’, and ‘logfile’ information.

openmdao.main.mp_util.register_tunnel(remote, local)[source]

Register local as the address to use to access remote.

openmdao.main.mp_util.setup_reverse_tunnel(remote_address, local_address, port, user=None, identity=None)[source]

Setup reverse tunnel to local_address:port from remote_address assuming:

  • ‘plink’ is available on Windows, ‘ssh’ on other platforms.
  • No user interaction is required to connect via ‘plink’/’ssh’.
remote_address: string
IPv4 address connecting to tunnel.
local_address: string
IPv4 address of tunnel.
port: int
Local port.
user: string
Remote username, if different than local name. Not needed if remote_address is of the form user@host.
identity: string
Path to optional identity file.

Returns (('localhost', remote_port), (cleanup-info)) where cleanup-info contains a cleanup function and its arguments.

openmdao.main.mp_util.setup_tunnel(address, port, user=None, identity=None)[source]

Setup tunnel to address and port assuming:

  • port is available on the local host.
  • ‘plink’ is available on Windows, ‘ssh’ on other platforms.
  • No user interaction is required to connect via ‘plink’/’ssh’.
address: string
IPv4 address to tunnel to.
port: int
Port at address to tunnel to.
user: string
Remote username, if different than local name. Not needed if address is of the form user@host.
identity: string
Path to optional identity file.

Returns ((local_address, local_port), (cleanup-info)), where cleanup-info contains a cleanup function and its arguments.

openmdao.main.mp_util.tunnel_address(remote)[source]

Return address to use to access remote.

openmdao.main.mp_util.write_server_config(server, filename, real_ip=None)[source]

Write server configuration information.

server: OpenMDAO_Server
Server to be recorded.
filename: string
Path to file to be written.
real_ip: string
If specified, the IP address to report (rather than possible tunnel).

Connection information including IP address, port, and public key is written using ConfigParser.

numpy_fallback.py

This is intended to be a simple drop-in replacement for numpy in those cases where numpy fails to import and only very basic numpy functionality is being used.

objserverfactory.py

Support for an OpenMDAO ‘object service’, a factory that can create servers which support various operations such as creating objects, loading models via egg files, remote execution, and remote file access.

class openmdao.main.objserverfactory.ObjServer(name='', allow_shell=False, allowed_types=None)[source]

Bases: object

An object which knows how to create other objects, load a model, etc. All remote file accesses must be within the tree rooted in the current directory at startup.

name: string
Name of server; used in log messages, etc.
allow_shell: bool
If True, execute_command() and load_model() are allowed. Use with caution!
allowed_types: list(string)
Names of types which may be created. If None, then allow types listed by factorymanager.get_available_types(). If empty, no types are allowed.
chmod(path, mode)[source]

Returns os.chmod(path, mode) if path is legal.

path: string
Path to file to modify.
mode: int
New mode bits (permissions).
config_ram(filename)[source]

Configure the ResourceAllocationManager instance from filename. Used to define resources needed for model execution.

create(typname, version=None, server=None, res_desc=None, **ctor_args)[source]

If typname is an allowed type, returns an object of type typname, using the specified package version, server location, and resource description. All arguments are passed to factorymanager.create().

echo(*args)[source]

Simply return the arguments. This can be useful for latency/thruput masurements, connectivity testing, firewall keepalives, etc.

execute_command(resource_desc)[source]

Run command described by resource_desc in a subprocess if this server’s allow_shell attribute is True.

resource_desc: dict
Contains job description.

The current environment, along with any ‘job_environment’ specification, is in effect while running ‘remote_command’.

If ‘input_path’ is not specified, /dev/null or nul: is used. If ‘output_path’ is not specified, <remote_command>.stdout is used. If neither ‘error_path’ nor ‘join_files’ are specified, <remote_command>.stderr is used.

If specified in the ‘resource_limits’ dictionary, ‘wallclock_time’ is used as a timeout.

All other queuing resource keys are ignored.

The HOME_DIRECTORY and WORKING_DIRECTORY placeholders are ignored.

isdir(path)[source]

Returns os.path.isdir(path) if path is legal.

path: string
Path to check.
listdir(path)[source]

Returns os.listdir(path) if path is legal.

path: string
Path to directory to list.
load_model(egg_filename)[source]

Load model from egg and return top-level object if this server’s allow_shell attribute is True.

egg_filename: string
Filename of egg to be loaded.
open(filename, mode='r', bufsize=-1)[source]

Returns open(filename, mode, bufsize) if filename is legal.

filename: string
Name of file to open.
mode: string
Access mode.
bufsize: int
Size of buffer to use.
pack_zipfile(patterns, filename)[source]

Create ZipFile of files matching patterns if filename is legal.

patterns: list
List of glob-style patterns.
filename: string
Name of ZipFile to create.
remove(path)[source]

Remove path if path is legal.

path: string
Path to file to remove.
set_log_level(level)[source]

Set logging level to level.

stat(path)[source]

Returns os.stat(path) if path is legal.

path: string
Path to file to interrogate.
unpack_zipfile(filename, textfiles=None)[source]

Unpack ZipFile filename if filename is legal.

filename: string
Name of ZipFile to unpack.
textfiles: list
List of fnmatch style patterns specifying which unpacked files are text files possibly needing newline translation. If not supplied, the first 4KB of each is scanned for a zero byte. If none is found, then the file is assumed to be a text file.
class openmdao.main.objserverfactory.ObjServerFactory(name='ObjServerFactory', authkey=None, allow_shell=False, allowed_types=None, address=None)[source]

Bases: openmdao.main.factory.Factory

An ObjServerFactory creates ObjServers and objects within those servers.

name: string
Name of factory; used in log messages, etc.
authkey: string
Passed to created ObjServer servers.
allow_shell: bool
Passed to created ObjServer servers.
allowed_types: list(string)
Passed to created ObjServer servers.
address: tuple or string
A multiprocessing address specifying an Internet address or a pipe (default). Created ObjServer servers will use the same form of address.

The environment variable OPENMDAO_KEEPDIRS can be used to avoid having server directory trees removed when servers are shut down.

cleanup()[source]

Shut-down all remaining ObjServers.

create(typname, version=None, server=None, res_desc=None, **ctor_args)[source]

Create a new typname object in server or a new ObjectServer. Returns a proxy for for the new object. Starts servers in a subdirectory of the current directory.

typname: string
Type of object to create. If null, then a proxy for the new ObjServer is returned.
version: string or None
Version of typname to create.
server: proxy
ObjServer on which to create typname. If none, then a new server is created.
res_desc: dict or None
Required resources. Currently not used.
ctor_args: dict
Other constructor arguments. If name or allowed_users are specified, they are used when creating the ObjServer. If no allowed_users are specified, the server is private to the current user.
echo(*args)[source]

Simply return the arguments. This can be useful for latency/thruput masurements, connectivity testing, firewall keepalives, etc.

get_available_types(groups=None)[source]

Returns a set of tuples of the form (typename, metadata), one for each available plugin type in the given entry point groups. If groups is None, return the set for all openmdao entry point groups.

get_ram()[source]

Returns the ResourceAllocationManager instance. Used by ResourceAllocationManager.add_remotes().

get_signature(typname, version=None)[source]

Return constructor argument signature for typname, using the specified package version. The return value is a dictionary.

typname: string
Type of object to constructor to inspect.
version: string or None
Version of typname to create.
release(server)[source]

Shut-down ObjServer server.

server: ObjServer
Server to be shut down.
openmdao.main.objserverfactory.connect(address, port, tunnel=False, authkey='PublicKey', pubkey=None, logfile=None)[source]

Connects to the server at address and port using key and returns a (shared) proxy for the associated ObjServerFactory.

address: string
IP address for server or pipe filename.
port: int
Server port. If < 0, address is a pipe filename.
tunnel: bool
Connect via SSH tunnel.
authkey:
Server authorization key.
pubkey:
Server public key; required if authkey is ‘PublicKey’.
logfile:
Location of server’s log file, if known.
openmdao.main.objserverfactory.connect_to_server(config_filename)[source]

Connects to the the server specified by config_filename and returns a (shared) proxy for the associated ObjServerFactory.

config_filename: string:
Name of server configuration file.
openmdao.main.objserverfactory.main()[source]

OpenMDAO factory service process.

Usage: python objserverfactory.py [–allow-public][–allow-shell][–hosts=filename][–types=filename][–users=filename][–address=address][–port=number][–prefix=name][–tunnel][–resources=filename][–log-host=hostname][–log-port=number][–log-prefix=string]

–allow-public:
Allows access by anyone from any allowed host. Use with care!
–allow-shell:
Allows access to execute_command() and load_model(). Use with care!
–hosts: string
Filename for allowed hosts specification. Default hosts.allow. Ignored if ‘–users’ is specified. The file should contain IPv4 host addresses, IPv4 domain addresses, or hostnames, one per line. Blank lines are ignored, and ‘#’ marks the start of a comment which continues to the end of the line. For security reasons this file must be accessible only by the user running this server.
–types: string
Filename for allowed types specification. If not specified then allow types listed by factorymanager.get_available_types(). The file should contain one type name per line.
–users: string
Filename for allowed users specification. Ignored if ‘–allow-public’ is specified. Default is ~/.ssh/authorized_keys, other files should be of the same format: each line has key-type public-key-data user@host, where user is the username on host. host will be translated to an IPv4 address and included in the allowed hosts list. Note that this user@host form is not necessarily enforced by programs which generate keys. For security reasons this file must be accessible only by the user running this server.
–address: string
IPv4 address, hostname, or pipe name. Default is the host’s default IPv4 address.
–port: int
Server port (default of 0 implies next available port). Note that ports below 1024 typically require special privileges. If port is negative, then a local pipe is used for communication.
–prefix: string
Prefix for configuration and stdout/stderr files (default server).
–tunnel:
Report host IP address but listen for connections from a local SSH tunnel.
–resources: string
Filename for resource configuration. If not specified then the default of ~/.openmdao/resources.cfg will be used.
–log-host: string
Hostname to send remote log messages to.
–log-port: int
Port on log-host to send remote log messages to.
–log-prefix: string
Prefix to apply to remote log messages. Default is pid@host.

If prefix.key exists, it is read for an authorization key string. Otherwise, public key authorization and encryption is used.

Allowed hosts must be specified if port is >= 0. Only allowed hosts may connect to the server.

Once initialized prefix.cfg is written with address, port, and public key information.

openmdao.main.objserverfactory.start_server(authkey='PublicKey', address=None, port=0, prefix='server', allowed_hosts=None, allowed_users=None, allow_shell=False, allowed_types=None, timeout=None, tunnel=False, resources=None, log_prefix=None)[source]

Start an ObjServerFactory service in a separate process in the current directory.

authkey: string
Authorization key; must be matched by clients.
address: string
IPv4 address, hostname, or pipe name. Default is the host’s default IPv4 address.
port: int
Server port (default of 0 implies next available port). Note that ports below 1024 typically require special privileges. If port is negative, then a local pipe is used for communication.
prefix: string
Prefix for server config file and stdout/stderr file.
allowed_hosts: list(string)
Host address patterns to check against. Required if port >= 0. Ignored if allowed_users is specified.
allowed_users: dict
Dictionary of users and corresponding public keys allowed access. If None, any user may access. If empty, no user may access. The host portions of user strings are used for address patterns.
allow_shell: bool
If True, execute_command() and load_model() are allowed. Use with caution!
allowed_types: list(string)
Names of types which may be created. If None, then allow types listed by get_available_types(). If empty, no types are allowed.
timeout: int
Seconds to wait for server to start. Note that public key generation can take a while. The default value of None will use an internally computed value based on host type (and for Windows, the availability of pyWin32).
tunnel: bool
If True, report host IP address but listen for connections from a local SSH tunnel.
resources: string
Filename for resource configuration.
log_prefix: string
Name used to identify remote remote logging messages from server. Implies that the local process will be receiving the messages.

Returns (server_proc, config_filename).

openmdao.main.objserverfactory.stop_server(server, config_filename)[source]

Shutdown ObjServerFactory specified by config_filename and terminate its process server.

server: ShellProc
Server process returned by start_server().
config_filename: string:
Name of server configuration file.

pbs.py

PBS resource allocator and object server.

By adding the allocator to the resource allocation manager, resource requests will interrogate the allocator to see if it could be used. This would typically be done by ExternalCode to execute a compute-intensive or parallel application.

class openmdao.main.pbs.PBS_Allocator(name='PBS', accounting_id='no-default-set', authkey=None, allow_shell=True)[source]

Bases: openmdao.main.resource.FactoryAllocator

Uses PBS_Server instead of ObjServer when deploying.

name: string
Name of allocator; used in log messages, etc.
accounting_id: string
Default value for the accounting_id resource key.
authkey: string
Authorization key for this allocator and any deployed servers.
allow_shell: bool
If True, execute_command() and load_model() are allowed in created servers. Since execute_command() is required, this defaults to be True.

Warning

There is a security risk with allow_shell True. Be careful to limit factory servers to the intended set of users!

Resource configuration file entry equivalent to defaults:

[PBS]
classname: openmdao.main.pbs.PBS_Allocator
accounting_id: no-default-set
authkey: PublicKey
allow_shell: True
check_compatibility(resource_desc)[source]

Check compatibility with resource attributes.

resource_desc: dict
Description of required resources.

Returns (retcode, info). If Compatible, then retcode is zero and info is empty. Otherwise, retcode will be -2 and info will be a single-entry dictionary whose key is the incompatible key in resource_desc and whose value provides data regarding the incompatibility.

configure(cfg)[source]

Configure allocator from ConfigParser instance. Normally only called during manager initialization.

cfg: ConfigParser
Configuration data is located under the section matching this allocator’s name.

Allows modifying accounting_id and factory options.

deploy(name, resource_desc, criteria)[source]

Deploy a server suitable for resource_desc. Returns a proxy to the deployed server. Overrides superclass to pass accounting_id to server.

name: string
Name for server.
resource_desc: dict
Description of required resources.
criteria: dict
The dictionary returned by time_estimate().
max_servers(resource_desc)[source]

Return the maximum number of servers which could be deployed for resource_desc. The value needn’t be exact, but performance may suffer if it overestimates. The value is used to limit the number of concurrent evaluations.

resource_desc: dict
Description of required resources.
time_estimate(resource_desc)[source]

Return (estimate, criteria) indicating how well this resource allocator can satisfy the resource_desc request. The estimate will be:

  • >0 for an estimate of walltime (seconds).
  • 0 for no estimate.
  • -1 for no resource at this time.
  • -2 for no support for resource_desc.

The returned criteria is a dictionary containing information related to the estimate, such as hostnames, load averages, unsupported resources, etc.

resource_desc: dict
Description of required resources.
class openmdao.main.pbs.PBS_Server(name='', allow_shell=False, allowed_types=None)[source]

Bases: openmdao.main.objserverfactory.ObjServer

Knows about executing a command via qsub.

configure(accounting_id)[source]

Configure default accounting id.

accounting_id: string
Used as default accounting_id value.
execute_command(resource_desc)[source]

Submit command based on resource_desc.

resource_desc: dict
Description of command and required resources.

The ‘-V’ qsub option is always used to export the current environment to the job. This environment is first updated with any ‘job_environment’ data. The ‘-W block=true’ qsub option is used to wait for job completion.

Other job resource keys are processed as follows:

Resource Key Translation
submit_as_hold -h
rerunnable -r y|n
working_directory Handled in generated script
job_category Ignored
min_cpus -l select= value :ncpus=1
max_cpus Ignored
min_phys_memory Ignored
email -M value
email_on_started -m b
email_on_terminated -m e
job_name -N value
input_path Handled in generated script
output_path Handled in generated script
error_path Handled in generated script
join_files Handled in generated script
reservation_id Ignored
queue_name -q value
priority -p value
start_time -a value
deadline_time Ignored
accounting_id -W group_list= value

Where value is the corresponding resource value.

To support a working directory other than HOME or a PBS-generated scratch directory, a short script is written with PBS directives in the header. The script will change to the working directory and then run the command.

If ‘working_directory’ is not specified, use current server directory. If ‘input_path’ is not specified, use /dev/null. If ‘output_path’ is not specified, use <remote_command>.stdout. If ‘error_path’ is not specified, use stdout.

If ‘native_specification’ is specified, it is added to the qsub command just before the name of the generated script. If it contains a select clause, then that will prevent generation of a select clause related to ‘min_cpus’.

Some resource limits are also handled:

Resource Key Translation
core_file_size Ignored
data_seg_size Ignored
file_size Ignored
open_files Ignored
stack_size Ignored
virtual_memory Ignored
cpu_time Ignored
wallclock_time -l walltime= value

Output from qsub itself is routed to qsub.out. If the job reports an error, qsub.out will be appended to either error_path, or if that was not specified, stdout.

pkg_res_factory.py

class openmdao.main.pkg_res_factory.PkgResourcesFactory(groups=['openmdao.caserecorder', 'openmdao.container', 'openmdao.caseiterator', 'openmdao.optproblem', 'openmdao.driver', 'openmdao.surrogatemodel', 'openmdao.parametric_geometry', 'openmdao.doegenerator', 'openmdao.component', 'openmdao.architecture', 'openmdao.casefilter', 'openmdao.variable'], search_path=None)[source]

Bases: openmdao.main.factory.Factory

A Factory that loads plugins using the pkg_resources API, which means it searches through egg info of distributions in order to find any entry point groups corresponding to openmdao plugin types, e.g., openmdao.component, openmdao.variable, etc.

create(typ, version=None, server=None, res_desc=None, **ctor_args)[source]

Create and return an object of the given type, with optional name, version, server id, and resource description.

get_available_types(groups=None)[source]

Return a set of tuples of the form (typename, dist_version), one for each available plugin type in the given entry point groups. If groups is None, return the set for all openmdao entry point groups.

get_signature(typname, version=None)[source]

Return constructor argument signature for typname, using the specified package version. The return value is a dictionary.

plugin.py

openmdao.main.plugin.build_docs_and_install(name, version, findlinks)[source]
openmdao.main.plugin.find_all_plugins(searchdir)[source]

Return a dict containing lists of each plugin type found, keyed by plugin group name, e.g., openmdao.component, openmdao.variable, etc.

openmdao.main.plugin.find_docs_url(plugin_name=None, build_if_needed=True)[source]

Returns a url for the Sphinx docs for the named plugin. The plugin must be importable in the current environment.

plugin_name: str
Name of the plugin distribution, module, or class.
openmdao.main.plugin.plugin()[source]
openmdao.main.plugin.plugin_build_docs(parser, options, args=None)[source]

A command-line script (plugin build_docs) points to this. It builds the Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed.

usage: plugin build_docs [dist_dir_path]

openmdao.main.plugin.plugin_docs(parser, options, args=None)[source]

A command-line script (plugin docs) points to this. It brings up the Sphinx documentation for the named plugin in a browser.

openmdao.main.plugin.plugin_install(parser, options, args=None, capture=None)[source]

A command-line script (plugin install) points to this. It installs the specified plugin distribution into the current environment.

openmdao.main.plugin.plugin_list(parser, options, args=None)[source]

List GitHub/external/built-in plugins.

openmdao.main.plugin.plugin_makedist(parser, options, args=None, capture=None, srcdir='src')[source]

A command-line script (plugin makedist) points to this. It creates a source distribution containing Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed.

usage: plugin makedist [dist_dir_path]

openmdao.main.plugin.plugin_quickstart(parser, options, args=None)[source]

A command-line script (plugin quickstart) points to this. It generates a directory structure for an openmdao plugin package along with Sphinx docs.

usage: plugin quickstart <dist_name> [-v <version>] [-d <dest_dir>] [-g <plugin_group>] [-c class_name]

openmdao.main.plugin.print_sub_help(parser, subname)[source]

Prints a usage message for the given subparser name.

printexpr.py

class openmdao.main.printexpr.ExprNameTransformer(mapping)[source]

Bases: ast.NodeTransformer

visit_Attribute(node)[source]
visit_Name(node)[source]
visit_Subscript(node)[source]
class openmdao.main.printexpr.ExprPrinter[source]

Bases: ast.NodeVisitor

A NodeVisitor that gets the Python text of an expression or assignment statement defined by an AST.

generic_visit(node)[source]
get_text()[source]
visit_Add(node)[source]
visit_And(node)[source]
visit_Assign(node)[source]
visit_Attribute(node)[source]
visit_BinOp(node)[source]
visit_BitAnd(node)[source]
visit_BitOr(node)[source]
visit_BitXor(node)[source]
visit_Call(node)[source]
visit_Compare(node)
visit_Dict(node)[source]
visit_Div(node)[source]
visit_Eq(node)[source]
visit_Expr(node)
visit_Expression(node)
visit_FloorDiv(node)[source]
visit_Gt(node)[source]
visit_GtE(node)[source]
visit_IfExp(node)[source]
visit_In(node)[source]
visit_Index(node)[source]
visit_Is(node)[source]
visit_IsNot(node)[source]
visit_LShift(node)[source]
visit_List(node)[source]
visit_Load(node)
visit_Lt(node)[source]
visit_LtE(node)[source]
visit_Mod(node)[source]
visit_Module(node)
visit_Mult(node)[source]
visit_Name(node)[source]
visit_NotEq(node)[source]
visit_NotIn(node)[source]
visit_Num(node)[source]
visit_Or(node)[source]
visit_Pow(node)[source]
visit_Rshift(node)[source]
visit_Slice(node)[source]
visit_Store(node)
visit_Str(node)[source]
visit_Sub(node)[source]
visit_Subscript(node)
visit_Tuple(node)[source]
visit_UAdd(node)[source]
visit_USub(node)[source]
visit_UnaryOp(node)[source]
visit_keyword(node)[source]
openmdao.main.printexpr.eliminate_expr_ws(expr)[source]

Return the expression string with whitespace removed, except for whitespace within string literals passed as function args.

openmdao.main.printexpr.print_node(node)[source]
openmdao.main.printexpr.transform_expression(expr, mapping)[source]

Returns a new expression string with the names transformed based on the value of the mapping dict. Note that this transforms only “complete” names (dotted or not), not sub-names within a larger dotted name.

problem_formulation.py

class openmdao.main.problem_formulation.ArchitectureAssembly[source]

Bases: openmdao.main.assembly.Assembly

Slot (IArchitecture) architecture

Slot for automatic architecture configurations.

  • default: None
  • copy: ‘deep’
  • vartypename: ‘Slot’
add_constraint(expr_string, name=None, scope=None)

Adds a constraint in the form of a boolean expression string to the driver.

expr_string: str
Expression string containing the constraint.
name: str (optional)
Name to be used to refer to the constraint rather than its expression string.
scope: object (optional)
The object to be used as the scope when evaluating the expression.
add_coupling_var(indep_dep, name=None, start=None)

Adds a new coupling var to the assembly.

indep_dep: 2-tuple (str,str)
2-tuple of (indep,dep) where indep is the name of the independent variable, or the variable that should be varied, to meet the coupling constraint, and dep is the name of the dependent variable, or the variable that needs to be consistent with the independent.
name: str (optional)
Short name used to identify the coupling variable.
start: float (optional)
Initial value to set to the independent part of the coupling constraint.
add_existing_constraint(scope, constraint, name=None)

Adds an existing Constraint object to the driver.

scope: container object where constraint expression will
be evaluated.

constraint: Constraint object

name: str (optional)
Name to be used to refer to the constraint rather than its expression string.
add_objective(expr, name=None, scope=None)

Adds an objective to the driver.

expr: string
String containing the objective expression.
name: string (optional)
Name to be used to refer to the objective in place of the expression string.
scope: object (optional)
The object to be used as the scope when evaluating the expression.
add_objectives(obj_iter, scope=None)

Takes an iterator of objective strings and creates objectives for them in the driver.

add_parameter(target, low=None, high=None, scaler=None, adder=None, start=None, fd_step=None, name=None, scope=None)

Adds a parameter or group of parameters to the driver.

target: string or iter of strings or Parameter
What the driver should vary during execution. A target is an expression that can reside on the left-hand side of an assignment statement, so typically it will be the name of a variable or possibly a subscript expression indicating an entry within an array variable, e.g., x[3]. If an iterator of targets is given, then the driver will set all targets given to the same value whenever it varies this parameter during execution. If a Parameter instance is given, then that instance is copied into the driver with any other arguments specified, overiding the values in the given parameter.
low: float (optional)
Minimum allowed value of the parameter. If scaler and/or adder is supplied, use the transformed value here. If target is an array, this may also be an array, but must have the same size.
high: float (optional)
Maximum allowed value of the parameter. If scaler and/or adder is supplied, use the transformed value here. If target is an array, this may also be an array, but must have the same size.
scaler: float (optional)
Value to multiply the possibly offset parameter value by. If target is an array, this may also be an array, but must have the same size.
adder: float (optional)
Value to add to parameter prior to possible scaling. If target is an array, this may also be an array, but must have the same size.
start: any (optional)
Value to set into the target or targets of a parameter before starting any executions. If not given, analysis will start with whatever values are in the target or targets at that time. If target is an array, this may also be an array, but must have the same size.
fd_step: float (optional)
Step-size to use for finite difference calculation. If no value is given, the differentiator will use its own default. If target is an array, this may also be an array, but must have the same size.
name: str (optional)
Name used to refer to the parameter in place of the name of the variable referred to in the parameter string. This is sometimes useful if, for example, multiple entries in the same array variable are declared as parameters.
scope: object (optional)
The object to be used as the scope when evaluating the expression.

If neither “low” nor “high” is specified, the min and max will default to the values in the metadata of the variable being referenced. If they are not specified in the metadata and not provided as arguments, a ValueError is raised.

check_config()[source]

Checks the configuration of the assembly to make sure it’s compatible with the architecture. Then initializes all the values in the parameters and coupling vars and configures the architecture if it hasn’t been done already.

clear_constraints()

Removes all constraints.

clear_coupling_vars()

Removes all coupling variables from the assembly.

clear_objectives()

Removes all objectives.

clear_parameters()

Removes all parameters.

config_parameters()

Reconfigure parameters from potentially changed targets.

copy_constraints()
eval_constraints(scope=None)

Returns a list of constraint values.

eval_eq_constraints(scope=None)

Returns a list of constraint values.

eval_ineq_constraints(scope=None)

Returns a list of constraint values.

eval_objectives()

Returns a list of values of the evaluated objectives.

eval_parameters(scope=None, dtype='d')

Return evaluated parameter values.

dtype: string or None
If not None, return an array of this dtype. Otherwise just return a list (useful if parameters may be of different types).
get_constraints()

Returns an ordered dict of constraint objects

get_constraints_by_comp()[source]
get_coupling_deps_by_comp()[source]

Returns a dictionary of coupling var dependents keyed to the component they are part of.

get_coupling_indeps_by_comp()[source]

Returns a dictionary of coupling var independent parameter objects, keyed to the component they are part of.

get_des_vars_by_comp()[source]

Return a dictionary of component names/list of parameters (global and local).

get_eq_constraints()

Returns an ordered dict of equality constraint objects.

get_expr_scope()[source]

Return the scope to be used to evaluate ExprEvaluators.

get_fd_steps(dtype='d')

Return fd_step values, they may include None.

dtype: string or None
If not None, return an array of this dtype. Otherwise just return a list (useful if it’s valid to have None for a step size).
get_global_des_vars()[source]

Return a list of multi-target Parameters.

get_global_des_vars_by_comp()[source]

Return a dictionary of component names/list of parameters for all multi-target parameters.

get_ineq_constraints()

Returns an ordered dict of inequality constraint objects.

get_local_des_vars()[source]

Return a list of single-target Parameters.

get_local_des_vars_by_comp()[source]

Return a dictionary of component names/list of parameters for all single-target parameters.

get_lower_bounds(dtype='d')

Return lower bound values.

dtype: string or None
If not None, return an array of this dtype. Otherwise just return a list (useful if parameters may be of different types).
get_objectives()

Returns an OrderedDict of objective expressions.

get_parameters()

Returns an ordered dict of parameter objects.

get_references(name)

Return references to component name in preparation for subsequent restore_references() call.

name: string
Name of component being removed.
get_upper_bounds(dtype='d')

Return upper bound values.

dtype: string or None
If not None, return an array of this dtype. Otherwise just return a list (useful if parameters may be of different types).
init_coupling_vars()
init_parameters()

Sets all parameters to their start value if a start value is given

initialize()[source]

Sets all des_vars and coupling_vars to the start values, if specified.

list_constraint_targets()

Returns a list of outputs suitable for calc_gradient().

list_constraints()

Return a list of strings containing constraint expressions.

list_coupling_vars()

Returns an OrderDict of CouplingVar instances keys to the names of (indep,dep) in the assembly.

list_eq_constraint_targets()

Returns a list of outputs suitable for calc_gradient().

list_ineq_constraint_targets()

Returns a list of outputs suitable for calc_gradient().

list_objective_targets()

Returns a list of outputs suitable for calc_gradient().

list_param_group_targets()

Returns a list of tuples that contain the targets for each parameter group.

list_param_targets()

Returns a list of parameter targets. Note that this list may contain more entries than the list of Parameter, ParameterGroup, and ArrayParameter objects since ParameterGroup instances have multiple targets.

list_pseudocomps()

Returns a list of pseudocomponent names associated with our constraints.

remove_constraint(expr_string)

Removes the constraint with the given string.

remove_coupling_var(indep_dep)

Removes the coupling var, indep/dep, pair from the assembly.

indep_dep: tuple of str
Two tuple of (<indep>,<dep>) to be removed.
remove_objective(expr)

Removes the specified objective expression. Spaces within the expression are ignored.

remove_parameter(name)

Removes the parameter with the given name.

remove_references(name)

Remove references to component name.

name: string
Name of component being removed.
restore_references(refs)

Restore references to component name from refs.

refs: dict
References returned by get_references().
set_parameter_by_name(name, value, case=None, scope=None)

Sets a single parameter by its name attribute.

name: str
Name of the parameter. This is either the name alias given when the parameter was added or the variable path of the parameter’s target if no name was given.
value: object (typically a float)
Value of the parameter to be set.
case: Case (optional)
If supplied, the values will be associated with their corresponding targets and added as inputs to the Case instead of being set directly into the model.
set_parameters(values, case=None, scope=None)

Pushes the values in the iterator ‘values’ into the corresponding variables in the model. If the ‘case’ arg is supplied, the values will be set into the case and not into the model.

values: iterator
Iterator of input values with an order defined to match the order of parameters returned by the get_parameters method. All ‘values’ must support the len() function.
case: Case (optional)
If supplied, the values will be associated with their corresponding targets and added as inputs to the Case instead of being set directly into the model.
total_constraints()

Returns the total number of constraint values.

total_eq_constraints()

Returns the total number of equality constraint values.

total_ineq_constraints()

Returns the total number of inequality constraint values.

total_parameters()

Returns the total number of values to be set.

class openmdao.main.problem_formulation.Couple(indep, dep, name=None, start=None)[source]

Bases: object

copy()[source]
indep_dep[source]
class openmdao.main.problem_formulation.CouplingVar(text, scope=None, getter='get')[source]

Bases: openmdao.main.expreval.ExprEvaluator

high[source]
low[source]
target[source]
targets[source]
class openmdao.main.problem_formulation.HasCouplingVars(parent)[source]

Bases: object

This class provides an implementation of the IHasCouplingVar interface.

parent: Assembly
Assembly object that this object belongs to.
add_coupling_var(indep_dep, name=None, start=None)[source]

Adds a new coupling var to the assembly.

indep_dep: 2-tuple (str,str)
2-tuple of (indep,dep) where indep is the name of the independent variable, or the variable that should be varied, to meet the coupling constraint, and dep is the name of the dependent variable, or the variable that needs to be consistent with the independent.
name: str (optional)
Short name used to identify the coupling variable.
start: float (optional)
Initial value to set to the independent part of the coupling constraint.
clear_coupling_vars()[source]

Removes all coupling variables from the assembly.

init_coupling_vars()[source]
list_coupling_vars()[source]

Returns an OrderDict of CouplingVar instances keys to the names of (indep,dep) in the assembly.

mimic(target)[source]
remove_coupling_var(indep_dep)[source]

Removes the coupling var, indep/dep, pair from the assembly.

indep_dep: tuple of str
Two tuple of (<indep>,<dep>) to be removed.
class openmdao.main.problem_formulation.OptProblem[source]

Bases: openmdao.main.problem_formulation.ArchitectureAssembly

Class for specifying test problems for optimization algorithms and architectures.

Dict solution

Dictionary of expected values for all des_vars and coupling_vars.

  • default: ‘{}’
  • iotype: ‘in’
check_solution(strict=False)[source]

Return dictionary errors (actual-expected) of all des_vars, coupling_vars, and objectives.

strict: Boolean (optional)
If True, then an error will be raised for any des_var, coupling_var, or objective where no solution is provided. If False, missing items are ignored. Defaults to False.

project.py

Routines for handling ‘Projects’ in Python.

class openmdao.main.project.ProjFinder(path_entry)[source]

Bases: object

A finder class for custom imports from an OpenMDAO project. For this to work, an entry must be added to sys.path of the form top_dir+PROJ_DIR_EXT, where top_dir is the top directory of the project where Python files are kept.

find_module(modpath, path=None)[source]

This looks within the project for the specified module, returning a loader if the module is found and None if it isn’t.

class openmdao.main.project.ProjLoader(path_entry)[source]

Bases: object

This is the import loader for files within an OpenMDAO project. We use it to instrument the imported files so we can keep track of what classes have been instantiated so we know when a project must be reloaded.

get_code(modpath)[source]

Opens the file, compiles it into an AST, and then translates it into the instrumented version before compiling that into bytecode.

get_source(modpath)[source]
is_package(modpath)[source]
load_module(modpath)[source]

Creates a new module if one doesn’t exist already and then updates the dict of that module based on the contents of the instrumented module file.

class openmdao.main.project.Project(projpath, gui=True, globals_dict=None)[source]

Bases: object

activate()[source]

Make this project active by putting its directory on sys.path and executing its macro.

add_to_path()[source]

Puts this project’s directory on sys.path so that imports from it will be processed by our special loader.

command(cmd, save=True)[source]
create(typname, version=None, server=None, res_desc=None, **ctor_args)[source]
deactivate()[source]

Removes this project’s directory from sys.path.

execfile(fname, digest=None)[source]
export(projname=None, destdir='.')[source]

Creates an archive of the current project for export.

projname: str (optional)
The name that the project in the archive will have. Defaults to the current project name.
destdir: str (optional)
The directory where the project archive will be placed. Defaults to the current directory.
get(pathname)[source]
get_info()[source]

Return settings ‘info’ section as a dictionary.

items()[source]
load_macro(macro_name)[source]
set_info(info)[source]

Set settings ‘info’ section from info dictionary.

name[source]
openmdao.main.project.list_projects()[source]

Return a list of available projects.

openmdao.main.project.load_project(pname, globals_dict=None)[source]

Load the model from the named project into the current globals dict so that the model can be used as part of a python script outside of the GUI. pname can either be an absolute or relative path to a project directory, or just a project name. If it’s a project name, the project directory will be searched for in PATH, and if not found there will be searched for in $HOME/.openmdao/gui/projects.

openmdao.main.project.parse_archive_name(pathname)[source]

Return the name of the project given the pathname of a project archive file.

openmdao.main.project.project_from_archive(archive_name, proj_name=None, dest_dir=None, create=True, overwrite=False)[source]

Expand the given project archive file in the specified destination directory and return a Project object that points to the newly expanded project.

archive_name: str
Path to the project archive to be expanded.
proj_name: str (optional)
Name of the new project. Defaults to the name of the project contained in the name of the archive.
dest_dir: str (optional)
Directory where the project directory for the expanded archive will reside. Defaults to the directory where the archive is located.
create: bool (optional)
If True, create and return a Project object. Otherwise, just unpack the project directory.

pseudoassembly.py

The PseudoAssembly is used to aggregate blocks of components that cannot provide derivatives, and thus must be finite differenced.

class openmdao.main.pseudoassembly.PseudoAssembly(name, comps, graph, wflow, fd=False, drv_name=None, boundary_params=())[source]

Bases: object

The PseudoAssembly is used to aggregate blocks of components that cannot provide derivatives, and thus must be finite differenced. It is not a real assembly, and should never be used in an OpenMDAO model.

add_to_graph(startgraph, dgraph, excludes=())[source]

Add this PseudoAssembly to the given graph, absorbing nodes that represent components contained in this PA.

calc_derivatives(first=False, second=False, savebase=True, required_inputs=None, required_outputs=None)[source]

Calculate the derivatives for this non-differentiable block using Finite Difference.

clean_graph(startgraph, dgraph, excludes=())[source]

Clean up the old nodes in the graph, leaving out ones that are excluded because they’re used by ancestor drivers.

get(varname)[source]

Return the value of a variable in the Pseudoassembly. Used when sizing variables in the Jacobian.

list_deriv_vars()[source]

Derivative inputs and outputs for this block

provideJ()[source]

Jacobian for this block

run(ffd_order=0, case_id='')[source]

Run all components contained in this assy. Used by finite difference.

set_itername(name)[source]

Comp API compatibility; allows iteration coord to be set in components.

openmdao.main.pseudoassembly.from_PA_var(name)[source]

Converts a pseudoassembly input name back to the real input.

openmdao.main.pseudoassembly.to_PA_var(name, pa_name)[source]

Converts an input to a unique input name on a pseudoassembly.

pseudocomp.py

class openmdao.main.pseudocomp.DummyExpr[source]

Bases: object

get_metadata()[source]
refs()[source]
class openmdao.main.pseudocomp.PseudoComponent(parent, srcexpr, destexpr=None, translate=True, pseudo_type=None)[source]

Bases: object

A ‘fake’ component that is constructed from an ExprEvaluator. This fake component can be added to a dependency graph and executed along with ‘real’ components.

calc_derivatives(first=False, second=False, savebase=False, required_inputs=None, required_outputs=None)[source]
check_configuration()[source]
connect(src, dest)[source]
contains(name)[source]
cpath_updated()[source]
get(name, index=None)[source]
get_invalidation_type()[source]
get_metadata(traitpath, metaname=None)[source]
get_pathname(rel_to_scope=None)[source]

Return full pathname to this object, relative to scope rel_to_scope. If rel_to_scope is None, return the full pathname.

invalidate_deps(varnames=None, force=False)[source]
is_valid()[source]
list_comp_connections()[source]

Return a list of connections between our pseudocomp and parent components of our sources/destinations.

list_connections(is_hidden=False, show_expressions=False)[source]

list all of the inputs and output connections of this PseudoComponent. If is_hidden is True, list the connections that a user would see if this PseudoComponent is hidden. If show_expressions is True (and only if is_hidden is also True) then list the connection expression that resulted in the creation of this PseudoComponent.

list_deriv_vars()[source]
list_inputs()[source]
list_outputs()[source]
make_connections(scope)[source]

Connect all of the inputs and outputs of this comp to the appropriate nodes in the dependency graph.

provideJ()[source]

Calculate analytical first derivatives.

remove_connections(scope)[source]

Disconnect all of the inputs and outputs of this comp from other nodes in the dependency graph.

run(ffd_order=0, case_id='')[source]
set(path, value, index=None, src=None, force=False)[source]
set_itername(itername)[source]
update_inputs(inputs=None)[source]
update_outputs(names)[source]
openmdao.main.pseudocomp.do_nothing_xform(node)[source]
openmdao.main.pseudocomp.scaler_adder_xform(node, scaler, adder)[source]

Returns an ast for the form (node+adder)*scaler

openmdao.main.pseudocomp.unit_xform(node, in_units, out_units)[source]

Transforms an ast into expr*scaler+adder where scaler and adder are from units conversion.

publisher.py

class openmdao.main.publisher.Pub_WV_Wrapper(name)[source]

Bases: pyV3D._pyV3D.WV_Wrapper

A wrapper for the wv library that is used by a Sender to send updates to the Publisher.

send(first=False)[source]
send_binary_data(wsi, buf, ibuf)[source]

This is called multiple times during the sending of a set of graphics primitives.

class openmdao.main.publisher.Publisher(context, url, use_stream=True)[source]

Bases: object

static disable()[source]
static enable()[source]
static get_instance()[source]
static init(context, url, use_stream=True)[source]
publish(topic, value, lock=True, binary=False)[source]
publish_list(items)[source]
static register(topic, obj)[source]

Associates a given topic with a binary publisher based on the corresponding object type. If no binpub type exists for that object type, nothing happens.

static unregister(topic)[source]

Removes an association between a ‘sender’ and a topic.

silent = False
openmdao.main.publisher.load_binpubs()[source]

Loads all binpubs entry points.

openmdao.main.publisher.publish(topic, msg, binary=False)[source]

rbac.py

Support for Role-Based Access Control (RBAC).

Remote access to methods is determined by a role-based access control attribute attached to the method. This attribute contains a sequence of role patterns, an optional proxy role to be used while executing the method, and a list of return types which are to be proxied. The rbac decorator is available for assigning this access control attribute to methods.

Remote access to attributes is checked based on role, accessing method, object, and attribute.

These access checks are mediated by an AccessController. A default controller is assigned to each OpenMDAO_Server. The server will check for an object-specific controller by trying to invoke get_access_controller() on the object before using the default.

The current role is determined from a Credentials object which is attached to the current thread. Mapping from credentials to roles can become fairly involved in a real system, typically with site-specific configuration. The default role mapping here just returns the roles ‘owner’ or ‘user’ based on whether the credentials match those in effect when the controller object was created.

Warning

Credentials as currently defined are quite weak unless the receiver has a list of known client keys. This access control scheme should not be relied upon unless the receiving server verifies that the Credentials public key matches what is expected.

exception openmdao.main.rbac.CredentialsError[source]

Bases: exceptions.Exception

Raised when decoding/verifying received credentials.

exception openmdao.main.rbac.RoleError[source]

Bases: exceptions.Exception

Raised when the current role is not allowed to invoke the requested method. Also raised when encountering some internal problems.

class openmdao.main.rbac.AccessController[source]

Bases: object

Responsible for mapping Credentials to roles and optionally getting different credentials for executing a method.

Also responsible for determining which attributes and classes require a proxy to be returned rather than the value.

attr_proxy_required(obj, attr, required=True)[source]

Record that a proxy is/is not required for obj.attr.

obj: object
Object whose attribute is to be recorded.
attr: string
Name of attribute to be recorded.
required: bool
If True, a proxy must be created.
check_access(role, methodname, obj, attr)[source]

Verify that role is allowed to invoke methodname of obj for attr.

role: string
Current role.
methodname: string
Name of method to be invoked.
obj: object
Object whose attribute is to be accessed.
attr: string
Name of attribute to be accessed.

Used for access control on getattr(), setattr(), and delattr() operations. This default version requires a non-null role, and only ‘owner’ may delete attributes.

class_proxy_required(cls)[source]

Record that a proxy is required for cls or any subclasses.

cls: class
Class to be recorded.
get_proxy_credentials(meth, credentials)[source]

If special credentials are needed while executing meth, return them, else return credentials.

meth: method
Method to be invoked.
credentials: Credentials
Current credentials in effect.
get_role(credentials)[source]

Trivial Credentials-to-role mapping.

credentials: Credentials
Credentials to obtain role for.

Returns the role associated with credentials.

This version returns a null string for no credentials, ‘owner’ if credentials matches the credentials in effect when we were created, and ‘user’ otherwise.

need_proxy(obj, attr, res)[source]

Returns True if attr of obj whose value is res requires a proxy.

obj: object
Object whose attribute is to be returned.
attr: string
Name of attribute accessed.
res: object
Result to be returned.

Checks res against registered classes to be proxied as well as the proxy registry for obj.attr.

set_proxy_credentials(proxy_role, credentials)[source]

Set credentials to be used for proxy_role to credentials.

proxy_role: string
Role to assign credentials to.
credentials: Credentials
Credentials to be assigned.
class openmdao.main.rbac.Credentials(encoded=None)[source]

Bases: object

Credentials are used to certify that a message is from a particular user on a particular host. The scheme here is quite weak unless the receiver has a list of known client keys.

Essentially all we can prove here is that someone somewhere created a correctly formed credential. Without known client keys at the receiving end, the best we can do is detect when more than one client claims the same identity.

If the receiver does keep a list of known client keys, then the information here will support strict authorization.

The client_creds attribute is simply used to trace back to the original user; it is not part of the credentials signature. It is carried along for auditing purposes when proxy credentials are used to allow a publicly accessible proprietary method to invoke other restricted methods on behalf of an ordinary user.

encoded: tuple
If specified, data used to recreate a remote Credentials object.
encode()[source]

Return object to be sent: (data, signature, client_creds).

static verify(encoded, allowed_users)[source]

Verify that encoded is a valid encoded credentials object and that its public key matches the public key we’ve already seen, if any.

encoded: tuple
Encoded credentials.
allowed_users: dict
Dictionary of users and corresponding public keys allowed access. If None, any user may access. If empty, no user may access.

Returns Credentials object from encoded.

err = gaierror(8, 'nodename nor servname provided, or not known')
user_host = 'kmarstel@GRSLA40016878'
class openmdao.main.rbac.rbac(roles, proxy_role='', proxy_types=None)[source]

Bases: object

Decorator for specifying RBAC roles for a method.

roles: string or sequence[string]
Role name patterns which are allowed access.
proxy_role: string
Role to use during execution of method. A null string implies that the current role is used.
proxy_types: list[class]
Types of return values that must be proxied.
openmdao.main.rbac.check_role(role, meth)[source]

Verifies that role is matched by at least one fnmatch-style pattern in meth‘s RBAC. Raises RoleError if no match is found.

role: string
Role to be checked.
meth: method.
Method to be checked.
openmdao.main.rbac.get_credentials()[source]

Get the current thread’s credentials.

openmdao.main.rbac.need_proxy(meth, result, access_controller)[source]

Returns True if result from meth requires a proxy. If no proxy types have been explicitly defined for meth, then access_controller provides a default set.

meth: method.
Method to be checked.
result: object
Result value to be checked.
access_controller: AccessController
Provides default proxy type information.
openmdao.main.rbac.rbac_decorate(method, roles, proxy_role='', proxy_types=None)[source]

Post-definition decorator for specifying RBAC roles for a method. Not typically used but needed if proxy_types must include the class currently being defined, since the normal decorator won’t see the class yet.

method: instancemethod
Method to be decorated.
roles: string or sequence[string]
Role name patterns which are allowed access.
proxy_role: string
Role to use during execution of method. A null string implies that the current role is used.
proxy_types: list[class]
Types of return values that must be proxied.
openmdao.main.rbac.rbac_methods(obj)[source]

Returns a list of names of the methods of obj to be exposed.

obj: object
Object to be scanned.
openmdao.main.rbac.remote_access()[source]

Return True if the current thread is providing remote access.

openmdao.main.rbac.set_credentials(credentials)[source]

Set the current thread’s credentials.

repo.py

class openmdao.main.repo.BzrRepo(dirpath='.')[source]

Bases: openmdao.main.repo.RepositoryBase

An object to interface with Bazaar repositories.

commit(*args, **kwargs)[source]
create_ignore_file(*args, **kwargs)[source]
init_repo(*args, **kwargs)[source]
static is_present()[source]
revert(*args, **kwargs)[source]
class openmdao.main.repo.DumbRepo(dirpath='.')[source]

Bases: openmdao.main.repo.RepositoryBase

A really simple repository that’s used as a fallback if git, hg, bzr are not present. It simply keeps an exported copy of the project in a .projrepo directory and, therefore, only allows one level of ‘revert’. A commit just replaces the project copy.

commit(*args, **kwargs)[source]
init_repo(*args, **kwargs)[source]
static is_present()[source]
revert(*args, **kwargs)[source]
repodir = '.projrepo'
class openmdao.main.repo.GitRepo(dirpath='.')[source]

Bases: openmdao.main.repo.RepositoryBase

An object to interface with Git repositories.

commit(*args, **kwargs)[source]
create_ignore_file(*args, **kwargs)[source]
init_repo(*args, **kwargs)[source]
static is_present()[source]
revert(*args, **kwargs)[source]
class openmdao.main.repo.HgRepo(dirpath='.')[source]

Bases: openmdao.main.repo.RepositoryBase

An object to interface with Mercurial repositories.

commit(*args, **kwargs)[source]
create_ignore_file(*args, **kwargs)[source]
init_repo(*args, **kwargs)[source]
static is_present()[source]
revert(*args, **kwargs)[source]
class openmdao.main.repo.RepositoryBase(dirpath='.')[source]

Bases: object

classmethod name()[source]
openmdao.main.repo.find_vcs()[source]

Return Repository objects based on what version control systems are installed.

openmdao.main.repo.get_repo(path)[source]

Return the appropriate type of Repository object given the specified directory.

openmdao.main.repo.in_dir(f)[source]

Go to a specified directory before executing the function and then return to the original directory.

resource.py

Support for allocation of servers from one or more resources (i.e., the local host, a cluster of remote hosts, etc.).

class openmdao.main.resource.ClusterAllocator(name, machines=None, authkey=None, allow_shell=False, method='load-average')[source]

Bases: openmdao.main.resource.ResourceAllocator

Cluster-based resource allocator. This allocator manages a collection of LocalAllocator, one for each machine in the cluster.

name: string
Name of allocator; used in log messages, etc.
machines: list(ClusterHost)
Hosts to allocate from.
authkey: string
Authorization key to be passed-on to remote servers.
allow_shell: bool
If True, execute_command() and load_model() are allowed in created servers. Use with caution!
method: string
Must be one of load-average, greedy, or round-robin.

load-average uses the load averages reported by each machine’s local allocator to determine the least-loaded machine(s) and allocates on those. We assume that machines in the cluster are similar enough that ranking by load average is reasonable.

greedy allocates N1 servers from the first machine, then N2 from the second machine, etc. where N is the number of cpus on a machine.

round-robin allocates one server from the first machine, then 1 server from the second machine, etc. Note that this can result in an unbalanced load if the machines have different numbers of cpus.

The greedy and round-robin methods have lower overhead but may allocate a server on a mchine that is already overloaded based on other user’s activity. They do however avoid problems where load averages don’t reflect loads added by previous allocations quickly enough.

configure(cfg)[source]

Configure a cluster consisting of hosts with node-numbered hostnames all using the same Python executable. Hostnames are generated from origin to nhosts`+`origin from format (origin defaults to 0). The Python executable is specified by the python option. It defaults to the currently executing Python.

Resource configuration file entry for a cluster named HX consisting of 19 hosts with the first host named hx00 and using the current OpenMDAO Python:

[HX]
classname: openmdao.main.resource.ClusterAllocator
nhosts: 19
origin: 0
format: hx%02d
authkey: PublicKey
allow_shell: True
method: load-average
tunnel_incoming: False
tunnel_outgoing: False
identity_filename: ~/.ssh/example.pem

An example entry for an ‘ad-hoc’ cluster where the names don’t have a particular pattern or the configuration of hosts is not uniform:

[Ad_hoc_cluster]
classname: openmdao.main.resource.ClusterAllocator
authkey: PublicKey
allow_shell: True
method: load-average
hosts: havoc.grc.nasa.gov viper.grc.nasa.gov

[havoc.grc.nasa.gov]
python: /OpenMDAO/dev/setowns1/OpenMDAO-Framework/devenv/bin/python

[viper.grc.nasa.gov]
python: OpenMDAO-Framework/devenv/bin/python
tunnel_incoming: True
tunnel_outgoing: True
deploy(name, resource_desc, criteria)[source]

Deploy a server suitable for resource_desc. Uses the host saved in criteria. Returns a proxy to the deployed server.

name: string
Name for server.
resource_desc: dict
Description of required resources.
criteria: dict
The dictionary returned by time_estimate().
max_servers(resource_desc)[source]

Returns the total of max_servers() across all LocalAllocator in the cluster.

resource_desc: dict
Description of required resources.
release(server)[source]

Release a server (proxy).

server: OpenMDAO_Proxy
Server to be released.
shutdown()[source]

Shutdown, releasing resources.

time_estimate(resource_desc)[source]

Returns (estimate, criteria) indicating how well this allocator can satisfy the resource_desc request. The estimate will be:

  • >0 for an estimate of walltime (seconds).
  • 0 for no estimate.
  • -1 for no resource at this time.
  • -2 for no support for resource_desc.

The returned criteria is a dictionary containing information related to the estimate, such as hostnames, load averages, unsupported resources, etc.

This allocator polls each LocalAllocator in the cluster to find the best match and returns that. The best allocator is saved in the returned criteria for a subsequent deploy().

resource_desc: dict
Description of required resources.
class openmdao.main.resource.ClusterHost(hostname, python=None, tunnel_incoming=False, tunnel_outgoing=False, identity_filename=None)[source]

Bases: openmdao.main.mp_distributing.Host

Represents a host to use as a node in a cluster.

hostname: string
Name of the host. ssh is used to log into the host. To log in as a different user, use a host name of the form: “username@somewhere.org”.
python: string
Path to the Python command to be used on hostname.
tunnel_incoming: bool
True if we need to set up a tunnel for hostname to connect to us. This is the case when a local firewall blocks connections.
tunnel_outgoing: bool
True if we need to set up a tunnel to connect to hostname. This is the case when a remote firewall blocks connections.
identity_filename: string
Path to optional identity file to pass to ssh.
class openmdao.main.resource.FactoryAllocator(name, authkey=None, allow_shell=False)[source]

Bases: openmdao.main.resource.ResourceAllocator

Base class for allocators using ObjServerFactory.

name: string
Name of allocator; used in log messages, etc.
authkey: string
Authorization key for this allocator and any deployed servers.
allow_shell: bool
If True, execute_command() and load_model() are allowed in created servers. Use with caution!
configure(cfg)[source]

Configure allocator from ConfigParser instance. Normally only called during manager initialization.

cfg: ConfigParser
Configuration data is located under the section matching this allocator’s name.

Allows modifying auth_key and allow_shell.

deploy(name, resource_desc, criteria)[source]

Deploy a server suitable for resource_desc. Returns a proxy to the deployed server.

name: string
Name for server.
resource_desc: dict
Description of required resources.
criteria: dict
The dictionary returned by time_estimate().
release(server)[source]

Release server.

server: typically ObjServer
Previously deployed server to be shut down.
class openmdao.main.resource.LocalAllocator(name='LocalAllocator', total_cpus=0, max_load=1.0, authkey=None, allow_shell=False)[source]

Bases: openmdao.main.resource.FactoryAllocator

Purely local resource allocator.

name: string
Name of allocator; used in log messages, etc.
total_cpus: int
If >0, then that is taken as the number of cpus/cores available. Otherwise, the number is taken from multiprocessing.cpu_count().
max_load: float
Specifies the maximum cpu-adjusted load (obtained from os.getloadavg()) allowed when reporting max_servers() and when determining if another server may be started in time_estimate().
authkey: string
Authorization key for this allocator and any deployed servers.
allow_shell: bool
If True, execute_command() and load_model() are allowed in created servers. Use with caution!

Resource configuration file entry equivalent to the default LocalHost allocator:

[LocalHost]
classname: openmdao.main.resource.LocalAllocator
total_cpus: 1
max_load: 1.0
authkey: PublicKey
allow_shell: True
check_compatibility(resource_desc)[source]

Check compatibility with resource attributes.

resource_desc: dict
Description of required resources.

Returns (retcode, info). If Compatible, then retcode is zero and info is empty. Otherwise, retcode will be -2 and info will be a single-entry dictionary whose key is the incompatible key in resource_desc and whose value provides data regarding the incompatibility.

configure(cfg)[source]

Configure allocator from ConfigParser instance. Normally only called during manager initialization.

cfg: ConfigParser
Configuration data is located under the section matching this allocator’s name.

Allows modifying factory options, total_cpus, and max_load.

max_servers(resource_desc, load_adjusted=False)[source]

Returns total_cpus * max_load if resource_desc is supported; otherwise, zero.

resource_desc: dict
Description of required resources.
load_adjusted: bool
If True, then the returned number of servers is adjusted for current host loading.
time_estimate(resource_desc)[source]

Returns (estimate, criteria) indicating how well this allocator can satisfy the resource_desc request. The estimate will be:

  • >0 for an estimate of walltime (seconds).
  • 0 for no estimate.
  • -1 for no resource at this time.
  • -2 for no support for resource_desc.

The returned criteria is a dictionary containing information related to the estimate, such as hostnames, load averages, unsupported resources, etc.

resource_desc: dict
Description of required resources.
host[source]

Allocator hostname.

pid[source]

Allocator process ID.

class openmdao.main.resource.RemoteAllocator(name, remote)[source]

Bases: openmdao.main.resource.ResourceAllocator

Allocator which delegates to a remote allocator. Configuration of remote allocators is not allowed.

name: string
Local name for allocator.
remote: proxy
Proxy for remote allocator.
deploy(name, resource_desc, criteria)[source]

Deploy on the remote allocator.

max_servers(resource_desc)[source]

Return maximum number of servers for remote allocator.

release(server)[source]

Release a remotely allocated server.

time_estimate(resource_desc)[source]

Return the time estimate from the remote allocator.

class openmdao.main.resource.ResourceAllocationManager(config_filename=None)[source]

Bases: object

The allocation manager maintains a list of ResourceAllocator which are used to select the “best fit” for a particular resource request. The manager is initialized with a LocalAllocator for the local host, using authkey of ‘PublicKey’, and allowing ‘shell’ access.

By default ~/.openmdao/resources.cfg will be used for additional configuration information. To avoid this, call configure() before any other allocation routines, or set the OPENMDAO_RAMFILE environment variable to the path to be used (a null path is legal and avoids any additional configuration).

static add_allocator(allocator)[source]

Add an allocator to the list of resource allocators.

allocator: ResourceAllocator
The allocator to be added.
static add_remotes(server, prefix='')[source]

Add allocators from a remote server to the list of resource allocators.

server: proxy for a remote server
The server whose allocators are to be added. It must support get_ram(), which should return the server’s ResourceAllocationManager and a host attribute.
prefix: string
Prefix for the local names of the remote allocators. The default is the remote hostname.
static allocate(resource_desc)[source]

Determine best resource for resource_desc and deploy. In the case of a tie, the first allocator in the allocators list wins. Returns (proxy-object, server-dict).

resource_desc: dict
Description of required resources.
static configure(config_filename)[source]

Configure allocators. This must be called before any other accesses if you want to avoid getting the default configuration as specified by ~/.openmdao/resources.cfg.

config_filename: string
Name of configuration file. If null, no additional configuration is performed.
static get_allocator(selector)[source]

Return allocator at selector or whose name is selector.

selector: int or string
List index or name of allocator to be returned.
get_allocator_proxy(index)[source]

Return allocator for remote use.

index: int
Index of the allocator to return.
static get_hostnames(resource_desc)[source]

Determine best resource for resource_desc and return hostnames. In the case of a tie, the first allocator in the allocators list wins. Typically used by parallel code wrappers which have MPI or something similar for process deployment.

resource_desc: dict
Description of required resources.
get_total_allocators()[source]

Return number of allocators for remote use.

static insert_allocator(index, allocator)[source]

Insert an allocator into the list of resource allocators.

index: int
List index for the insertion point.
allocator: ResourceAllocator
The allocator to be inserted.
static list_allocators()[source]

Return list of allocators.

static max_request(assembly)[source]

Determine the maximum resources requested by assembly.

Resource descriptions are assumed to be attributes named resources. Scans the assembly’s components for resources and determines a ‘peak’ value of requested CPUs and resource limits. This can be used to ensure an allocated server can support the maximum of any resources requested by an assembly’s components.

Returns a resource description for the maximum.

assembly: Assembly
Assembly containing components requesting resources.
static max_servers(resource_desc)[source]

Returns the maximum number of servers compatible with ‘resource_desc`. This should be considered an upper limit on the number of concurrent allocations attempted.

resource_desc: dict
Description of required resources.
static release(server)[source]

Release a server (proxy).

server: OpenMDAO_Proxy
Server to be released.
static remove_allocator(selector)[source]

Remove allocator at selector or whose name is selector.

selector: int or string
List index or name of allocator to be removed.
static total_request(assembly)[source]

Determine the total resources requested by assembly.

Resource descriptions are assumed to be attributes named resources. Scans the assembly’s components for resources and determines a total value of requested run time. The descriptions are first processed by max_request() to set peak values. Then the descriptions are also checked for queuing compatibility (accounting id, job category, etc). This can be used to obtain a resource description for running assembly as a batch job.

Returns a resource description for the total.

assembly: Assembly
Assembly containing components requesting resources.
static validate_resources(resource_desc)[source]

Validate that resource_desc is legal.

resource_desc: dict
Description of required resources.
class openmdao.main.resource.ResourceAllocator(name)[source]

Bases: object

Base class for allocators. Allocators estimate the suitability of a resource and can deploy on that resource.

name: string
Name of allocator; used in log messages, etc. Must be alphanumeric (underscore also allowed).
check_compatibility(resource_desc)[source]

Check compatibility with common resource attributes.

resource_desc: dict
Description of required resources.

Returns (retcode, info). If retcode is zero, then info is a list of keys in recource_desc that have not been processed. Otherwise, retcode will be -2 and info will be a single-entry dictionary whose key is the incompatible key in resource_desc and whose value provides data regarding the incompatibility.

check_orphan_modules(resource_value)[source]

Returns a list of ‘orphan’ modules that are not available.

resource_value: list
List of ‘orphan’ module names.
check_required_distributions(resource_value)[source]

Returns a list of distributions that are not available.

resource_value: list
List of Distributions or Requirements.
configure(cfg)[source]

Configure allocator from ConfigParser instance. Normally only called during manager initialization.

cfg: ConfigParser
Configuration data is located under the section matching this allocator’s name.

The default implementation does nothing.

deploy(name, resource_desc, criteria)[source]

Deploy a server suitable for resource_desc. Returns a proxy to the deployed server.

name: string
Name for server.
resource_desc: dict
Description of required resources.
criteria: dict
The dictionary returned by time_estimate().
invalidate()[source]

Invalidate this allocator. This will be called by the manager when it detects that its allocators are copies due to a process fork. The default implementation does nothing.

max_servers(resource_desc)[source]

Return the maximum number of servers which could be deployed for resource_desc. The value needn’t be exact, but performance may suffer if it overestimates. The value is used to limit the number of concurrent evaluations.

resource_desc: dict
Description of required resources.
release(server)[source]

Shut-down server.

Note

Unlike other methods which are protected from multithreaded access by the manager, release() must be multithread-safe.

server: ObjServer
Server to be shut down.
time_estimate(resource_desc)[source]

Return (estimate, criteria) indicating how well this resource allocator can satisfy the resource_desc request. The estimate will be:

  • >0 for an estimate of walltime (seconds).
  • 0 for no estimate.
  • -1 for no resource at this time.
  • -2 for no support for resource_desc.

The returned criteria is a dictionary containing information related to the estimate, such as hostnames, load averages, unsupported resources, etc.

resource_desc: dict
Description of required resources.
name[source]

This allocator’s name.

sequentialflow.py

A workflow that allows the user to explicitly specify the execution order. This workflow serves as the immediate base class for the two most important workflows: Dataflow and CyclicWorkflow.

class openmdao.main.sequentialflow.SequentialWorkflow(parent=None, scope=None, members=None)[source]

Bases: openmdao.main.workflow.Workflow

A Workflow that is a simple sequence of components.

add(compnames, index=None, check=False)[source]

Add new component(s) to the end of the workflow by name.

calc_derivatives(first=False, second=False, savebase=False, required_inputs=None, required_outputs=None)[source]

Calculate derivatives and save baseline states for all components in this workflow.

calc_gradient(inputs=None, outputs=None, upscope=False, mode='auto')[source]

Returns the gradient of the passed outputs with respect to all passed inputs.

inputs: list of strings or tuples of strings
List of input variables that we are taking derivatives with respect to. They must be within this workflow’s scope. If no inputs are given, the parent driver’s parameters are used. A tuple can be used to link inputs together.
outputs: list of strings
List of output variables that we are taking derivatives of. They must be within this workflow’s scope. If no outputs are given, the parent driver’s objectives and constraints are used.
upscope: boolean
This is set to True when our workflow is part of a subassembly that lies in a workflow that needs a gradient with respect to variables outside of this workflow, so that the caches can be reset.
mode: string
Set to ‘forward’ for forward mode, ‘adjoint’ for adjoint mode, ‘fd’ for full-model finite difference (with fake finite difference disabled), or ‘auto’ to let OpenMDAO determine the correct mode.
check_gradient(inputs=None, outputs=None, stream=<open file '<stdout>', mode 'w' at 0x1002841e0>, mode='auto')[source]

Compare the OpenMDAO-calculated gradient with one calculated by straight finite-difference. This provides the user with a way to validate his derivative functions (apply_deriv and provideJ.) Note that fake finite difference is turned off so that we are doing a straight comparison.

inputs: (optional) iter of str or None
Names of input variables. The calculated gradient will be the matrix of values of the output variables with respect to these input variables. If no value is provided for inputs, they will be determined based on the parameters of the Driver corresponding to this workflow.
outputs: (optional) iter of str or None
Names of output variables. The calculated gradient will be the matrix of values of these output variables with respect to the input variables. If no value is provided for outputs, they will be determined based on the objectives and constraints of the Driver corresponding to this workflow.
stream: (optional) file-like object or str
Where to write to, default stdout. If a string is supplied, that is used as a filename. If None, no output is written.
mode: (optional) str
Set to ‘forward’ for forward mode, ‘adjoint’ for adjoint mode, or ‘auto’ to let OpenMDAO determine the correct mode. Defaults to ‘auto’.

Returns the finite difference gradient, the OpenMDAO-calculated gradient, and a list of suspect inputs/outputs.

clear()[source]

Remove all components from this workflow.

config_changed()[source]

Notifies the Workflow that its configuration (dependencies, etc.) has changed.

derivative_graph(inputs=None, outputs=None, fd=False, severed=None, group_nondif=True)[source]

Returns the local graph that we use for derivatives.

inputs: list of strings or tuples of strings
List of input variables that we are taking derivatives with respect to. They must be within this workflow’s scope. If no inputs are given, the parent driver’s parameters are used. A tuple can be used to link inputs together.
outputs: list of strings
List of output variables that we are taking derivatives of. They must be within this workflow’s scope. If no outputs are given, the parent driver’s objectives and constraints are used.
fd: boolean
set to True to finite difference the whole model together with fake finite difference turned off. This is mainly for checking your model’s analytic derivatives.
severed: list
If a workflow has a cylic connection, some edges must be severed. When a cyclic workflow calls this function, it passes a list of edges so that they can be severed prior to the topological sort.
group_nondif: bool
If True, collapse parts of the graph into PseudoAssemblies when necessary.
edge_list()[source]

Return the list of edges for the derivatives of this workflow.

get_bounds(node)[source]

Return a tuple containing the start and end indices into the residual vector that correspond to a given variable name in this workflow.

get_implicit_info()[source]

Return a dict of the form {(residuals) : [states]}

get_names(full=False)[source]

Return a list of component names in this workflow. If full is True, include hidden pseudo-components in the list.

index(comp)[source]

Return index number for a component in this workflow.

initialize_residual()[source]

Creates the array that stores the residual. Also returns the number of edges.

matvecFWD(arg)[source]

Callback function for performing the matrix vector product of the workflow’s full Jacobian with an incoming vector arg.

matvecREV(arg)[source]

Callback function for performing the matrix vector product of the workflow’s full Jacobian with an incoming vector arg.

mimic(src)[source]
remove(compname)[source]

Remove a component from the workflow by name. Do not report an error if the specified component is not found.

set_bounds(node, bounds)[source]

Set a tuple containing the start and end indices into the residual vector that correspond to a given variable name in this workflow.

sever_edges(edges)[source]

Temporarily remove the specified edges but save them and their metadata for later restoration.

unsever_edges()[source]

sym.py

exception openmdao.main.sym.SymbolicDerivativeError(value)[source]

Bases: exceptions.Exception

openmdao.main.sym.SymGrad(ex, vars)[source]

Symbolic gradient.

treeproxy.py

class openmdao.main.treeproxy.TreeProxy(root, path)[source]

Bases: object

Acts as a proxy object for objects within an opaque, hierarchically structured local object so that normal Python attribute access will work to access objects inside of the opaque object’s tree.

The opaque object must implement the following interface, which is checked only via duck typing:

def get(pathname, index=None)
def set(pathname, value, index=None)
def call(pathname, *args, **kwargs)
def __contains__(pathname)

where pathname is a dot-separated name, and index is a list of element indices or attribute names, e.g., [2,1], [‘mykey’] or [2,1,[‘attrname’]]. Attribute names are buried inside of a nested list to avoid confusion with strings used to index into a container. Also, nested tuples are not used to avoid confusion for the same reason, i.e., they are hashable and therefore could be used to index into a container.

openmdao.main.treeproxy.all_tree_names(pathnames)[source]

Returns the set of all names, including intermediate names, given a list of pathnames. For example, given the pathname ‘a.b.c’, it would return set([‘a’, ‘a.b’, ‘a.b.c’])

uncertain_distributions.py

class openmdao.main.uncertain_distributions.NormalDistribution(mu=0.0, sigma=1.0)[source]

Bases: openmdao.main.uncertain_distributions.UncertainDistribution

An UncertainDistribution which represents a quantity with a normal distribution of uncertainty.

mu: float
mean value
sigma: float
standard deviation
expected()[source]
sample()[source]
class openmdao.main.uncertain_distributions.TriangularDistribution(max=0.0, min=1.0, mode=0.5, *args, **kwargs)[source]

Bases: openmdao.main.uncertain_distributions.UncertainDistribution

An UncertainDistribution which represents a quantity with a triangular distribution of uncertainty.

min: float
minimum value
max: float
maximum value
mode: float
mode
expected()[source]
sample()[source]
class openmdao.main.uncertain_distributions.UncertainDistribution(valmethod=None)[source]

Bases: object

Base class for uncertain variables.

expected()[source]
getvalue()[source]
sample()[source]
default_val_method = 'expected'
class openmdao.main.uncertain_distributions.UniformDistribution(max=0.0, min=1.0, *args, **kwargs)[source]

Bases: openmdao.main.uncertain_distributions.UncertainDistribution

An UncertainDistribution which represents a quantity with a uniform distribution of uncertainty.

min: float
minimum value
max: float
maximum value
expected()[source]
sample()[source]
class openmdao.main.uncertain_distributions.WeibullDistribution(alpha=1.0, beta=2.0, *args, **kwargs)[source]

Bases: openmdao.main.uncertain_distributions.UncertainDistribution

An UncertainDistribution which represents a quantity with a Weibull distribution of uncertainty.

alpha: float
scale parameter
beta: float
shape parameter
expected()[source]
sample()[source]

variable.py

Base class for all OpenMDAO variables

class openmdao.main.variable.Variable(default_value=<traits.trait_handlers.NoDefaultSpecified object at 0x106e29bd0>, **metadata)[source]

Bases: traits.trait_handlers.TraitType

An OpenMDAO-specific trait type that serves as a common base class for framework visible inputs and outputs.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI. The basic functionality that most variables need is provided here; you can overload this for special cases, like lists and dictionaries, or custom datatypes.

name: str
Name of variable.
value: object
The value of the variable.
trait: CTrait
The variable’s trait.
meta: dict
Dictionary of metadata for this variable.

vartree.py

VariableTree class definition

class openmdao.main.vartree.VariableTree(iotype='')[source]

Bases: openmdao.main.container.Container

A tree of variables having the same input or output sense.

Str _iotype
  • default: ‘’
  • vartypename: ‘Str’
add(name, obj)[source]
add_trait(name, trait, refresh=True)[source]
copy()[source]

Returns a deep copy of this VariableTree, without deepcopying its parent. Also installs necessary trait callbacks.

cpath_updated()[source]
get_attributes(io_only=True, indent=0, parent='', valid='false')[source]

Get attributes for this variable tree. Used by the GUI.

io_only: bool
Set to True if we only want to populate the input and output fields of the attributes dictionary.
indent: int
Recursion level (for collapsing tables).
parent: str
ID name of parent table line.
valid: str
Validity state of the parent table.
get_iotype(name)[source]

Return the iotype of the Variable with the given name

get_metadata(traitpath, metaname=None)[source]
install_callbacks()[source]

Install trait callbacks on deep-copied VariableTree.

invalidate_deps(varnames=None, force=False)[source]
list_vars()[source]

Return a list of Variables in this VariableTree.

remove_trait(name)[source]
iotype[source]

workflow.py

Base class for all workflows.

class openmdao.main.workflow.Workflow(parent=None, scope=None, members=None)[source]

Bases: object

A Workflow consists of a collection of Components which are to be executed in some order.

add(compnames, index=None, check=False)[source]

Add new component(s) to the workflow by name.

check_config()[source]

Perform any checks that we need prior to run. Specific workflows should override this.

config_changed()[source]

Notifies the Workflow that workflow configuration (dependencies, etc.) has changed.

get_components(full=False)[source]

Returns a list of all component objects in the workflow. No ordering is assumed.

get_names(full=False)[source]

Return a list of component names in this workflow.

remove(comp)[source]

Remove a component from this Workflow by name.

reset()[source]

Reset execution count.

run(ffd_order=0, case_id='')[source]

Run the Components in this Workflow.

set_initial_count(count)[source]

Set initial value for execution count. Only needed if the iteration coordinates must be initialized, such as for CaseIterDriverBase.

count: int
Initial value for workflow execution count.
step(ffd_order=0, case_id='')[source]

Run a single component in this Workflow.

stop()[source]

Stop all Components in this Workflow. We assume it’s OK to to call stop() on something that isn’t running.

itername[source]
scope[source]

The scoping Component that is used to resolve the Component names in this Workflow.

DATATYPES

any.py

Trait for a generic variable that has no validation.

class openmdao.main.datatypes.any.Any(default_value=None, iotype=None, desc=None, **metadata)[source]

Bases: openmdao.main.variable.Variable

A variable wrapper for a generic variable that has no validation..

array.py

Trait for numpy array variables, with optional units.

class openmdao.main.datatypes.array.Array(default_value=None, dtype=None, shape=None, iotype=None, desc=None, units=None, **metadata)[source]

Bases: traits.trait_numeric.Array

A variable wrapper for a numpy array with optional units. The unit applies to the entire array.

error(obj, name, value)[source]

Returns an informative and descriptive error string.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI.

name: str
Name of variable
value: object
The value of the variable
value: object
Value of variable
meta: dict
Dictionary of metadata for this variable
get_val_wrapper(value, index=None)[source]

Return a UnitsAttrWrapper object. Its value attribute will be filled in by the caller.

validate(obj, name, value)[source]

Validates that a specified value is valid for this trait. Units are converted as needed.

bool.py

Trait for boolean variables.

class openmdao.main.datatypes.bool.Bool(default_value=False, iotype=None, desc=None, **metadata)[source]

Bases: openmdao.main.variable.Variable

A variable wrapper for a boolean variable.

create_editor()[source]

User the one in the Enthought trait.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI. Bools need to turn their value into a string for compatibility.

name: str
Name of variable
value: object
The value of the variable
trait: CTrait
The variable’s trait
meta: dict
Dictionary of metadata for this variable
validate(obj, name, value)[source]

Use the Enthought trait’s validate.

complex.py

Trait for complex variables.

class openmdao.main.datatypes.complex.Complex(default_value=0j, iotype=None, desc=None, **metadata)[source]

Bases: openmdao.main.variable.Variable

A variable wrapper for a complex variable.

create_editor()[source]

User the one in the Enthought trait.

validate(obj, name, value)[source]

Use the Enthought trait’s validate.

dict.py

Trait for dictionary variables.

class openmdao.main.datatypes.dict.Dict(key_trait=None, value_trait=None, value=None, items=True, iotype=None, desc=None, **metadata)[source]

Bases: traits.trait_types.Dict

Variable wrapper for dictionary variables.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI. Dicts are containers that have a key trait and a value trait.

name: str
Name of variable
value: object
The value of the variable
trait: CTrait
The variable’s trait
meta: dict
Dictionary of metadata for this variable

enum.py

Trait for enumerations, with optional alias list.

class openmdao.main.datatypes.enum.Enum(default_value=None, values=(), iotype=None, aliases=(), desc=None, **metadata)[source]

Bases: openmdao.main.variable.Variable

A variable wrapper for an enumeration, which is a variable that can assume one value from a set of specified values.

error(obj, name, value)[source]

Returns a general error string for Enum.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI.

name: str
Name of variable
value: object
The value of the variable
trait: CTrait
The variable’s trait
meta: dict
Dictionary of metadata for this variable
validate(obj, name, value)[source]

Validates that a specified value is valid for this trait.

event.py

Trait for Events

class openmdao.main.datatypes.event.Event(trait=None, **metadata)[source]

Bases: traits.trait_types.Event

Variable wrapper for events.

get_attribute(name, meta)[source]

Return the attribute dictionaries for this variable. This dict is used by the GUI to populate the object editor pane.

name: str
Name of variable
meta: dict
Dictionary of metadata for this variable

file.py

Support for file variables.

class openmdao.main.datatypes.file.File(default_value=None, iotype=None, **metadata)[source]

Bases: openmdao.main.variable.Variable

A trait wrapper for a FileRef object.

If default_value is a string, then a FileRef will be created using that for the path.

If default_value is a file object, then a FileRef will be created for the file’s name, if the named file exists.

For input files legal_types may be set to a list of expected ‘content_type’ strings. Then upon assignment the actual ‘content_type’ must match one of the legal_types strings. Also, if local_path is set, then upon assignent the associated file will be copied to that path.

post_setattr(obj, name, value)[source]

If ‘local_path’ is set on an input, then copy the source FileRef’s file to that path.

validate(obj, name, value)[source]

Verify that value is a FileRef of a legal type.

class openmdao.main.datatypes.file.FileRef(path, owner=None, **metadata)[source]

Bases: openmdao.main.file_supp.FileMetadata

A reference to a file on disk. As well as containing metadata information, it supports open() to read the file’s contents. Before open() is called, ‘owner’ must be set to an object supporting check_path() and get_abs_directory() (typically a Component or one of its child Container objects).

abspath()[source]

Return absolute path to file.

copy(owner)[source]

Return a copy of ourselves, owned by owner.

owner: Component
The component used to determine the root for relative paths and checking the legality of absolute paths.
open()[source]

Open file for reading.

float.py

Trait for floating point variables, with optional min, max, and units.

class openmdao.main.datatypes.float.Float(default_value=None, iotype=None, desc=None, low=None, high=None, exclude_low=False, exclude_high=False, units=None, **metadata)[source]

Bases: openmdao.main.variable.Variable

A Variable wrapper for floating point number valid within a specified range of values.

error(obj, name, value)[source]

Returns a descriptive error string.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI. The basic functionality that most variables need is provided here; you can overload this for special cases, like lists and dictionaries, or custom datatypes.

name: str
Name of variable
value: object
The value of the variable
trait: CTrait
The variable’s trait
meta: dict
Dictionary of metadata for this variable
get_val_wrapper(value, index=None)[source]

Return a UnitsAttrWrapper object. Its value attribute will be filled in by the caller.

validate(obj, name, value)[source]

Validates that a specified value is valid for this trait. Units are converted as needed.

geom.py

OpenMDAO variable type for a geometry object that can be passed between components and queried.

class openmdao.main.datatypes.geom.Geom(default_value=None, iotype=None, **metadata)[source]

Bases: openmdao.main.variable.Variable

OpenMDAO variable type for a geometry object that can be passed between components and queried. The geometry object must conform to IStaticGeometry.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI. Geometries don’t return much (yet.)

name: str
Name of variable
value: object
The value of the variable
trait: CTrait
The variable’s trait
meta: dict
Dictionary of metadata for this variable
validate(obj, name, value)[source]

Just check for interface

instance.py

Trait for a Slot meant to contain an object of a particular type or having a particular interface (either a Traits interface or a zope.interface).

class openmdao.main.datatypes.instance.Instance(klass=<type 'object'>, allow_none=True, factory=None, args=None, kw=None, **metadata)[source]

Bases: openmdao.main.datatypes.instance.Base

A trait for an object of a particular type or implementing a particular interface. Both Traits Interfaces and zope.interface.Interfaces are supported.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI. Slots also return an attribute dictionary for the slot pane.

name: str
Name of variable
value: object
The value of the variable
trait: CTrait
The variable’s trait
meta: dict
Dictionary of metadata for this variable

int.py

Trait for integer variables, with optional high and low.

class openmdao.main.datatypes.int.Int(default_value=None, iotype=None, desc=None, low=None, high=None, exclude_low=False, exclude_high=False, **metadata)[source]

Bases: openmdao.main.variable.Variable

A variable wrapper for an integer valid within a specified range of values.

error(obj, name, value)[source]

Returns a descriptive error string.

validate(obj, name, value)[source]

Validates that a specified value is valid for this trait.

list.py

Trait for list variables.

class openmdao.main.datatypes.list.List(trait=None, value=None, minlen=0, maxlen=9223372036854775807, items=True, **metadata)[source]

Bases: traits.trait_types.List

Variable wrapper for list variables.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI. Lists are containers and can have slots.

name: str
Name of variable
value: object
The value of the variable
trait: CTrait
The variable’s trait
meta: dict
Dictionary of metadata for this variable

slot.py

Trait for a Slot meant to contain an object of a particular type or having a particular interface (either a Traits interface or a zope.interface).

class openmdao.main.datatypes.slot.Slot(klass=<type 'object'>, allow_none=True, factory=None, args=None, kw=None, **metadata)[source]

Bases: openmdao.main.datatypes.instance.Base

A trait for an object of a particular type or implementing a particular interface. Both Traits Interfaces and zope.interface.Interfaces are supported.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI. Slots also return an attribute dictionary for the slot pane.

name: str
Name of variable
value: object
The value of the variable
trait: CTrait
The variable’s trait
meta: dict
Dictionary of metadata for this variable

str.py

Trait for string variables.

class openmdao.main.datatypes.str.Str(default_value='', iotype=None, desc=None, **metadata)[source]

Bases: openmdao.main.variable.Variable

A variable wrapper for a string variable.

create_editor()[source]

User the one in the Enthought trait.

validate(obj, name, value)[source]

Use the Enthought trait’s validate.

uncertaindist.py

class openmdao.main.datatypes.uncertaindist.UncertainDistVar(default_value=None, iotype=None, desc=None, **metadata)[source]

Bases: openmdao.main.variable.Variable

A variable wrapper for an UncertainDistribution variable.

get_val_wrapper(value, index=None)[source]

Return a UnitsAttrWrapper object. Its value attribute will be filled in by the caller.

validate(obj, name, value)[source]

Use the Enthought trait’s validate.

vtree.py

Variable meant to contain a VariableTree of a particular type.

class openmdao.main.datatypes.vtree.VarTree(default_value, allow_none=True, **metadata)[source]

Bases: openmdao.main.variable.Variable

A Variable for a VariableTree of a particular type.

get_attribute(name, value, trait, meta)[source]

Return the attribute dictionary for this variable. This dict is used by the GUI to populate the edit UI. Slots also return an attribute dictionary for the slot pane.

name: str
Name of variable
value: object
The value of the variable
trait: CTrait
The variable’s trait
meta: dict
Dictionary of metadata for this variable
post_setattr(obj, name, value)[source]

VariableTrees must know their place within the hierarchy, so set their parent here. This keeps side effects out of validate().

validate(obj, name, value)[source]

Validates that a specified value is valid for this trait.