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.

assembly.py

Class definition for Assembly.

class openmdao.main.assembly.Assembly(doc=None, directory='')[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’
add(name, obj)[source]

Call the base class add. Then, if obj is a Component, add it to the component graph.

Returns the added object.

calc_derivatives(first=False, second=False)[source]

Overides the component’s version of this function. An assembly must initiate the call of calc_derivatives on all components in its driver’s workflow.

check_derivatives(order, driver_inputs, driver_outputs)[source]

An assembly just tells its driver to run check_derivatives on each element in its workflow. Note that an assembly signifies a change of scope, so the driver input and output lists are pared down.

child_invalidated(childname, outs=None, force=False)[source]

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

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 that 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_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_valid(names)[source]

Returns a list of boolean values indicating whether the named variables are valid (True) or invalid (False). Entries in names may specify either direct traits of self or those of children.

invalidate_deps(varnames=None, force=False)[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.
force: bool (optional)
If True, force the invalidation to proceed beyond the boundary even if all outputs were already invalid.
list_connections(show_passthrough=True)[source]

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

remove(name)[source]

Remove the named container object from this assembly and remove it from its workflow(s) if it’s a 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.
step()[source]

Execute a single child component and return.

stop()[source]

Stop the calculation.

update_inputs(compname, exprs)[source]

Transfer input data to input expressions on the specified component. The exprs iterator is assumed to contain expression 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=<class 'openmdao.main.case._Missing'>)[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(doc=None, directory='')[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’
  • vartypename: ‘Str’
Bool force_execute

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

  • default: ‘False’
  • iotype: ‘in’
  • vartypename: ‘Bool’
Bool create_instance_dir
  • default: ‘False’
  • vartypename: ‘Bool’
Int exec_count

Number of times this Component has been executed.

  • default: ‘0’
List external_files

FileMetadata objects for external files used by this component.

  • default: ‘[]’
  • copy: ‘deep’
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)[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)[source]

Prepare for Fake Finite Difference runs by calculating all needed derivatives, and saving the current state as the baseline. The user must supply calculate_first_derivatives() and/or calculate_second_derivatives() in the component.

This function is overridden by ComponentWithDerivatives

first: Bool
Set to True to calculate first derivatives.
second: Bool
Set to True to calculate second derivatives.
check_config()[source]

Verify that this component is fully configured to execute. This function is called once prior to the first execution of this component and may be called explicitly at other times if desired. Classes that override this function must still call the base class version.

check_derivatives(order, driver_inputs, driver_outputs)[source]

ComponentsWithDerivatives overloads this function to check for missing derivatives.

This function is overridden by ComponentWithDerivatives

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. 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.
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_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, force=False)[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_inputs(valid=None, connected=None)[source]

Return a list of names of input values.

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

Return a list of names of output values.

valid: bool (optional)
If valid is not None, the list will contain names of outputs with matching validity.
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.

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.
set_valid(names, valid)[source]

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

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.

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

Bases: openmdao.main.component.Component

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

calc_derivatives(first=False, second=False)[source]

Prepare for Fake Finite Difference runs by calculating all needed derivatives, and saving the current state as the baseline. The user must supply calculate_first_derivatives() and/or calculate_second_derivatives() 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.
check_derivatives(order, driver_inputs, driver_outputs)[source]

Calls the validate method of the derivatives object in order to warn the user about all missing derivatives.

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(doc=None)[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)[source]

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

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.

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_attributes(io_only=True)[source]

We use Container as a base class for objects that have traits that need to be edited, but have no iotype. This method returns a dictionary of information that the GUI can use to build the editors.

The default behavior is to take all traits and put them on the inputs pane. For different behavior, overload this method.

io_only: Bool
Passed in, but not used in the base class.
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.
get_wrapped_attr(name, index=None)[source]

If the variable can return an AttrWrapper, then this function will return that, with the value set to the current value of the variable. Otherwise, it functions like getattr, just returning the value of the variable. Raises an exception if the variable cannot be found. 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’.

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 model has been loaded.

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: enthought.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 the scoping object, which can be overridden by subclasses, to create each trait.

obj_info is assumed to be either a string, a tuple, or a list that contains strings and/or tuples. Tuples must contain a name and an ‘internal’ name, and may optionally contain an iotype and a validation trait. The first name is the one that will be used to access the trait’s attribute in the Container, while the second name represents some alternate naming scheme within the Container.

For example, the following are valid calls:

create_io_traits(obj, ‘foo’) create_io_traits(obj, [‘foo’,’bar’,’baz’]) create_io_traits(obj, (‘foo’, ‘foo_alias’, ‘in’, some_trait), ‘bar’) create_io_traits(obj, [(‘foo’, ‘fooa’, ‘in’),(‘bar’, ‘barb’, ‘out’),(‘baz’, ‘bazz’)])

The newly created traits are added to the specified Container.

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

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

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

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

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.

dataflow.py

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

Bases: openmdao.main.seqentialflow.SequentialWorkflow

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

add(compnames, index=None)[source]

Add new component(s) to the workflow by name.

config_changed()[source]

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

remove(compname)[source]

Remove a component from this Workflow by name.

depgraph.py

Class definition for Dependencygraph, an object for interacting with an Assembly’s network graph.

exception openmdao.main.depgraph.AlreadyConnectedError[source]

Bases: exceptions.RuntimeError

Special exception that is raised when trying to connect to an input that is already connected.

class openmdao.main.depgraph.DependencyGraph[source]

Bases: object

A dependency graph for Components. Each edge contains a _Link object, which maps all connected inputs and outputs between the two Components. Graph nodes starting with ‘@’ are abstract nodes that represent boundary connections.

@xin is external to our input boundary

@bin is our input boundary

@bout is our output boundary

@xout is external to our output boundary

add(name)[source]

Add the name of a Component to the graph.

check_connect(srcpath, destpath)[source]

Raise exception if destpath is already connected

connect(srcpath, destpath)[source]

Add an edge to our Component graph from srccompname to destcompname.

connections_to(path)[source]

Returns a list of tuples of the form (srcpath, destpath) for all connections between the variable or component specified by path.

copy_graph()[source]

Return a copy of the graph without the ‘fake’ boundary edges.

disconnect(srcpath, destpath=None)[source]

Disconnect the given variables.

dump(stream=<open file '<stdout>', mode 'w' at 0x259078>)[source]

Prints out a simple sorted text representation of the graph.

find_all_connecting(start, end)[source]

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

get_connected_inputs()[source]
get_connected_outputs()[source]
get_interior_edges(comps)[source]

Returns the set of all output edges that are interior to the set of components supplied. For example, you may want the set of all outputs in a driver’s workflow that are connected to other comps in that workflow, and hence need derivatives.

comps: list of str
List of component names

Return the link between the two specified nodes. If there is no connection, then None is returned.

get_source(destpath)[source]

Return the source variable path for the given destination path.

Return a list of the form [(compname, link), (compname2, link2)...] containing each incoming link to the given component and the name of the connected component.

invalidate_deps(scope, cnames, varsets, force=False)[source]

Walk through all dependent nodes in the graph, invalidating all variables that depend on output sets for the given component names.

scope: Component
Scoping object containing this dependency graph.
cnames: list of str
Names of starting nodes.
varsets: list of sets of str
Sets of names of outputs from each starting node.
force: bool (optional)
If True, force invalidation to continue even if a component in the dependency chain was already invalid.
list_autopassthroughs()[source]

Returns a list of autopassthrough connections as (src, dest) tuples.

list_connections(show_passthrough=True)[source]

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

Return a list of the form [(compname, link), (compname2, link2)...] containing each outgoing link from the given component and the name of the connected component.

remove(name)[source]

Remove the name of a Component from the graph. It is not an error if the component is not found in the graph.

var_edges(name=None)[source]

Return a list of outgoing edges connecting variables.

var_in_edges(name=None)[source]

Return a list of incoming edges connecting variables.

derivatives.py

Class definition for Derivatives. This object is used by Component to store derivative information and to perform calculations during a Fake Finite Difference.

class openmdao.main.derivatives.Derivatives(parent)[source]

Bases: object

Class for storing derivatives between the inputs and outputs of a component at specified orders.

calculate_output(out_name, order)[source]

Returns the Fake Finite Difference output for the given output name using the stored baseline and derivatives along with the new inputs in the component.

declare_first_derivative(out_name, in_name)[source]

Declares that a component can calculate a first derivative between the given input and output.

out_name: str
Name of component’s output variable.
in_name: str
Name of component’s first input variable for derivative.
declare_second_derivative(out_name, in_name1, in_name2)[source]

Declares that a component can calculate a second derivative between the given input and output.

out_name: str
Name of component’s output variable.
in_name1: str
Name of component’s first input variable for derivative.
in_name2: str
Name of component’s second input variable for derivative.
save_baseline(comp)[source]

Saves the baseline of all inputs and outputs for which derivatives have been specified.

set_first_derivative(out_name, in_name, value)[source]

Stores a single first derivative value.

out_name: str
Name of component’s output variable.
in_name: str
Name of component’s input variable.
value: float
Value of derivative.
set_second_derivative(out_name, in_name1, in_name2, value)[source]

Stores a single second derivative value.

Note cross terms (i.e., df_dxdy) are assumed symmetric so you only have to specify them once.

out_name: str
Name of component’s output variable.
in_name1: str
Name of component’s first input variable for derivative.
in_name2: str
Name of component’s second input variable for derivative.
value: float
Value of derivative.
validate(order, driver_inputs, driver_outputs)[source]

Check the component’s inputs and output and warn about any input- output combinations that are missing a derivative.

openmdao.main.derivatives.derivative_name(input_name, output_name)[source]

Assemble the name string for a derivative output based on its input and output name. This name string is used in several places, and is considered part of the API.

driver.py

Driver class definition

class openmdao.main.driver.Driver(doc=None)[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’
List printvars

List of extra variables to output in the recorders.

  • default: ‘[]’
  • iotype: ‘in’
  • copy: ‘deep’
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)[source]

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

check_config()[source]

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

check_derivatives(order, driver_inputs, driver_outputs)[source]

Check derivatives for all components in this workflow.

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_references(name)[source]

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

name: string
Name of component being removed.
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, or if any of our variables is invalid, or if the parameters, constraints, or objectives have changed.

iteration_set()[source]

Return a set of all Components in our workflow(s), and recursively in any workflow in any Driver in our workflow(s).

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 paramters, 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, and objective references to component name.

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

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

name: string
Name of component being removed.
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 differncing (1 for first derivatives, 2 for second derivativse). 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.
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]

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 class provides an implementation of the derivatives delegates.

Slot (IDifferentiator) differentiator

Slot for a differentiator

  • default: None
  • iotype: ‘in’
  • copy: ‘deep’
  • vartypename: ‘Slot’
check_config()[source]

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

check_gradients()[source]

Run check_derivatives on our workflow.

check_hessians()[source]

Run check_derivatives on our workflow.

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)[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_required_compnames(assembly)[source]

Return the set of all names of Components that evaluation of our expression string depends on, either directly or indirectly.

get_unresolved()[source]

Return a list of all variables that cannot be resolved.

invalid_refs()[source]

Return a list of invalid variables referenced by this expression.

is_local(name)[source]

Return True if the given (dotted) name refers to something in our _expr_dict dict, e.g., math.sin. Raises a KeyError if the name refers to something in _expr_dict that doesn’t exist, e.g., math.foobar. Returns False if the name refers to nothing in _expr_dict, e.g., mycomp.x.

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.

refs_valid()[source]

Return True if all variables referenced by our expression are valid.

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)[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

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 typename, using the specified package version, server location, and resource description.

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.

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.

filevar.py

Support for files, either as File or external files.

class openmdao.main.filevar.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.
  • ‘binary’, boolean, default False.
  • ‘big_endian’, boolean, default False. 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.filevar.FileRef(path, owner=None, **metadata)[source]

Bases: openmdao.main.filevar.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.

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 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, scaler, adder, scope=None)[source]

Bases: object

Object that stores info for a single constraint.

copy()[source]
evaluate(scope)[source]

Returns a tuple of the form (lhs, rhs, comparator, is_violated).

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

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

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

Bases: object

Add this class as a delegate if your Driver supports both equality and inequality constraints.

add_constraint(expr_string, scaler=1.0, adder=0.0, 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.
scaler: float (optional)
Multiplicative scale factor applied to both sides of the constraint’s boolean expression. It should be a positive nonzero value. Default is unity (1.0).
adder: float (optional)
Additive scale factor applied to both sides of the constraint’s boolean expression. Default is no additive shift (0.0).
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(cnst, name=None)[source]

Adds an existing Constraint object to the driver.

cnst: Constraint object

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

Returns True if this Driver supports constraints of the given types.

types: list of str
Types of constraints supported. Valid values are: [‘eq’, ‘ineq’]
clear_constraints()[source]

Removes all constraints.

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

Returns a list of tuples of the form (lhs, rhs, comparator, is_violated) from evalution of equality constraints.

eval_ineq_constraints(scope=None)[source]

Returns a list of tuples of the form (lhs, rhs, comparator, is_violated) from evalution of inequality constraints.

get_constraints()[source]

Return a list 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_constraints()[source]

Return a list of strings containing constraint expressions.

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, name)[source]

Restore references to component name from refs.

name: string
Name of component being removed.
refs: dict
References returned by get_references().
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, scaler=1.0, adder=0.0, name=None, scope=None)[source]

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

Parameters:

expr_string: str
Expression string containing the constraint.
scaler: float (optional)
Multiplicative scale factor applied to both sides of the constraint’s boolean expression. It should be a positive nonzero value. Default is unity (1.0).
adder: float (optional)
Additive scale factor applied to both sides of the constraint’s boolean expression. Default is no additive shift (0.0).
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(cnst, name=None)[source]

Adds an existing Constraint object to the driver.

cnst: Constraint object

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

Returns True if types is [‘eq’].

eval_eq_constraints(scope=None)[source]

Returns a list of tuples of the form (lhs, rhs, comparator, is_violated).

get_eq_constraints()[source]

Returns an ordered dict of constraint objects.

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, scaler=1.0, adder=0.0, 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.
scaler: float (optional)
Multiplicative scale factor applied to both sides of the constraint’s boolean expression. It should be a positive nonzero value. Default is unity (1.0).
adder: float (optional)
Additive scale factor applied to both sides of the constraint’s boolean expression. Default is no additive shift (0.0).
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(cnst, name=None)[source]

Adds an existing Constraint object to the driver.

cnst: Constraint object

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

Returns True if types is [‘ineq’].

eval_ineq_constraints(scope=None)[source]

Returns a list of constraint values

get_ineq_constraints()[source]

Returns an ordered dict of inequality constraint objects.

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.

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.

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.
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, name)[source]

Restore references to component name from refs.

name: string
Name of component being removed.
refs: object
Value returned by get_references().

hasparameters.py

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 are supplied, use the transformed value here.
high: float (optional)
Maximum allowed value of the parameter. If scaler and/or adder are supplied, use the transformed value here.
scaler: float (optional)
Value to multiply the possibly offset parameter value by.
adder: float (optional)
Value to add to parameter prior to possible scaling.
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.
fd_step: float (optional)
Step-size to use for finite difference calculation. If no value is given, the differentitator will use its own default.
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.

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_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.
init_parameters()[source]

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

list_param_targets()[source]

Returns a list of parameter targets. Note that this list may contain more entries than the list of Parameter and ParameterGroup objects since ParameterGroups 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, name)[source]

Restore references to component name from refs.

name: string
Name of component being removed.
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. ‘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.
class openmdao.main.hasparameters.Parameter(target, high=None, low=None, scaler=None, adder=None, start=None, fd_step=None, scope=None, name=None)[source]

Bases: object

copy()[source]

Return a copy of this Parameter.

evaluate(scope=None)[source]

Returns the value of this parameter.

get_config()[source]
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 with 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.

set(val, scope=None)[source]

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

target[source]

Returns the target of this parameter.

targets[source]

Returns 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.

copy()[source]
evaluate(scope=None)[source]

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

get_config()[source]
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 with 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]
set(value, scope=None)[source]

Set all targets to the given value.

target[source]
targets[source]

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.

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.

index.py

openmdao.main.index.get_indexed_value(obj, name, index)[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 fuction call. idx can be 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

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.

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.

logger.py

This is just a wrapper for the logging module so we can switch it out later if needed.

mp_distributing.py

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

This code assumes ssh has been set-up on all hosts such that no user intervention for passwords or passphrases is required.

class openmdao.main.mp_distributing.Cluster(hostlist, modules=None, authkey=None, allow_shell=False)[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!
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.

class openmdao.main.mp_distributing.Host(hostname, python=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 the the Python command to be used on hostname.
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)[source]

Return manager given an address.

address: (ip_addr, port) or string referring to pipe.
Address to connect to.
authkey: string
Authorization key.
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. 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_tunneling: bool
If True, allow connections from 127.0.0.1 (localhost), 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, typ)[source]

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

obj: object
Object to be tested.
typ: class
Class to be tested against.

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

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.setup_tunnel(address, port)[source]

Setup tunnel to address and port assuming:

  • The remote login name matches the local login name.
  • 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.

Returns (local_address, local_port).

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).
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
Accees 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 upnapcked files are text files possibly needing newline translation. If not supplied, the first 4KB of each is scanned for a zero byte. If not 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().

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 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 it’s process server.

server: ShellProc
Server process retured 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 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:

[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 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.

In order 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.

pkg_res_factory.py

class openmdao.main.pkg_res_factory.PkgResourcesFactory(groups=['openmdao.caserecorder', 'openmdao.caseiterator', 'openmdao.optproblem', 'openmdao.driver', 'openmdao.surrogatemodel', 'openmdao.doegenerator', 'openmdao.component', 'openmdao.architecture', 'openmdao.container', 'openmdao.differentiator', '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.

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)[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.

openmdao.main.plugin.update_libpath(options=None)[source]

Find all of the shared libraries in the current virtual environment and modify the activate script to put their directories in LD_LIBRARY_PATH (or its equivalent).

printexpr.py

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

Bases: ast.NodeTransformer

visit_Attribute(node)[source]
visit_Name(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)
visit_keyword(node)[source]
write(txt)[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.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(doc=None, directory='')[source]

Bases: openmdao.main.assembly.Assembly

Slot (IArchitecture) architecture

Slot for automatic architecture configurations.

  • default: None
  • copy: ‘deep’
  • vartypename: ‘Slot’
add_constraint(expr_string, scaler=1.0, adder=0.0, 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.
scaler: float (optional)
Multiplicative scale factor applied to both sides of the constraint’s boolean expression. It should be a positive nonzero value. Default is unity (1.0).
adder: float (optional)
Additive scale factor applied to both sides of the constraint’s boolean expression. Default is no additive shift (0.0).
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 idenfity the coupling variable.
start: float (optional)
Initial value to set to the independent part of the coupling constraint.
add_existing_constraint(cnst, name=None)

Adds an existing Constraint object to the driver.

cnst: 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 are supplied, use the transformed value here.
high: float (optional)
Maximum allowed value of the parameter. If scaler and/or adder are supplied, use the transformed value here.
scaler: float (optional)
Value to multiply the possibly offset parameter value by.
adder: float (optional)
Value to add to parameter prior to possible scaling.
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.
fd_step: float (optional)
Step-size to use for finite difference calculation. If no value is given, the differentitator will use its own default.
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.

allows_constraint_types(types)

Returns True if this Driver supports constraints of the given types.

types: list of str
Types of constraints supported. Valid values are: [‘eq’, ‘ineq’]
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.

copy_constraints()
eval_eq_constraints(scope=None)

Returns a list of tuples of the form (lhs, rhs, comparator, is_violated) from evalution of equality constraints.

eval_ineq_constraints(scope=None)

Returns a list of tuples of the form (lhs, rhs, comparator, is_violated) from evalution of inequality constraints.

eval_objectives()

Returns a list of values of the evaluated objectives.

get_constraints()

Return a list of constraint objects

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

Returns a dictionary of coupling var dependent 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_coupling_vars()

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

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_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_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.
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_constraints()

Return a list of strings containing constraint expressions.

list_param_targets()

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

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, name)

Restore references to component name from refs.

name: string
Name of component being removed.
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. ‘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.
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 idenfity 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.

get_coupling_vars()[source]

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

init_coupling_vars()[source]
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(doc=None, directory='')[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.CtorInstrumenter[source]

Bases: ast.NodeTransformer

All __init__ calls will be replaced with a call to a wrapper function that records the call by calling _register_inst(typename) before creating the instance.

visit_ClassDef(node)[source]
class openmdao.main.project.ProjFinder(path_entry)[source]

Bases: object

A finder class for custom imports from an OpenMDAO project. In order 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 saved and 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)[source]

Bases: object

activate()[source]

Puts this project’s directory on sys.path.

command(cmd)[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]
items()[source]
load_macro(fpath, execute=True)[source]
save()[source]

Save the project model to its project directory.

write_macro()[source]
name[source]
openmdao.main.project.add_init_monitors(node)[source]

Take the specified AST and translate it into the instrumented version, which will record all instances.

openmdao.main.project.add_proj_to_path(path)[source]

Puts this project’s directory on sys.path.

openmdao.main.project.filter_macro(lines)[source]

Removes commands from a macro that are overridden by later commands.

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)[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.
openmdao.main.project.text_to_node(text)[source]

Given a python source string, return the corresponding AST node. The outer Module node is removed so that the node corresponding to the given text can be added to an existing AST.

publisher.py

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)[source]
publish_list(items)[source]
silent = False
openmdao.main.publisher.publish(topic, msg)[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 reponsible 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.

user_host = 'StormBringer@Apocalypse.local'
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.

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)[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(dict)
Dictionaries providing configuration data for each machine in the cluster. At a minimum, each dictionary must specify a host address in ‘hostname’ and the path to the OpenMDAO Python command in ‘python’.
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!

We assume that machines in the cluster are similar enough that ranking by load average is reasonable.

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
deploy(name, resource_desc, criteria)[source]

Deploy a server suitable for resource_desc. Uses the allocator 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.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 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)[source]

Returns total_cpus * max_load if resource_desc is supported, otherwise zero.

resource_desc: dict
Description of required 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.

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.

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 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.

seqentialflow.py

class openmdao.main.seqentialflow.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)[source]

Add new component(s) to the end of the workflow by name.

clear()[source]

Remove all components from this workflow.

get_names()[source]

Return a list of component names in this workflow.

index(comp)[source]
remove(compname)[source]

Remove a component from the workflow by name. Do not report an error if the specified component is not found.

sym.py

exception openmdao.main.sym.SymbolicDerivativeError(value)[source]

Bases: exceptions.Exception

openmdao.main.sym.SymGrad(ex, vars)[source]

Symbolic gradient.

openmdao.main.sym.SymHess(ex, vars)[source]

Symbolic Hessian.

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=<enthought.traits.trait_handlers.NoDefaultSpecified object at 0x168f230>, **metadata)[source]

Bases: enthought.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='', doc=None)[source]

Bases: openmdao.main.container.Container

A container of variables with an input or output sense.

Str _iotype
  • default: ‘’
  • vartypename: ‘Str’
add(name, obj)[source]
add_trait(name, trait)[source]
copy()[source]

Returns a deep copy of this VariableTree.

cpath_updated()[source]
get_attributes(io_only=True)[source]

get attributes for this variable tree. Variables may also include slots. 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.
get_iotype(name)[source]

Return the iotype of the Variable with the given name

get_metadata(traitpath, metaname=None)[source]
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

Workflow class definition

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)[source]

Add new component(s) to the workflow by name.

calc_derivatives(first=False, second=False)[source]

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

check_derivatives(order, driver_inputs, driver_outputs)[source]

Run check_derivatives on all components in workflow.

config_changed()[source]

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

get_components()[source]

Returns a list of all component objects in the workflow. No ordering is assumed.

get_names()[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.

scope[source]

The scoping Component that is used to resolve the Component names in this Workflow.