analysis_generator.py#

Provide generators for use with AnalysisDriver.

These generators are pythonic, lazy generators which, when provided with a dictionary of variables and values to be tested, produce some set of sample values to be evaluated.

class openmdao.drivers.analysis_generator.AnalysisGenerator(var_dict)[source]

Bases: Iterator

Provide a generator which provides case data for AnalysisDriver.

Parameters:
var_dictdict

A dictionary whose keys are promoted paths of variables to be set, and whose values are the arguments to set_val.

Attributes:
_iterIterator

The underlying iterator for variable values.

_run_countint

A running count of the samples obtained from the iterator.

_var_dictdict

An internal copy of the var_dict used to create the generator.

__init__(var_dict)[source]

Instantiate the base class for AnalysisGenerators.

Parameters:
var_dictdict

A dictionary mapping a variable name to values to be assumed, as well as optional units and indices specifications.

__iter__()
class openmdao.drivers.analysis_generator.CSVGenerator(filename, has_units=False, has_indices=False)[source]

Bases: AnalysisGenerator

A generator which provides cases for AnalysisDriver by pulling rows from a CSV file.

Parameters:
filenamestr

The filename for the CSV file containing the variable data.

has_unitsbool

If True, the second line of the CSV contains the units of each variable.

has_indicesbool

If True, the line after units (if present) contains the indices being set.

Attributes:
_filenamestr

The filename of the CSV file providing the samples.

_has_unitsbool

True if the CSV file contains a row of the units for each variable.

_has_indicesbool

True if the CSV file contains a row of indices being provided for each variable. If units are present, indices will be on the line following units.

_csv_filefile

The file object for the CSV file.

_csv_readerDictReader

The reader object for the CSV file.

_var_namesset of str

The set of variable names provided by this CSVGenerator.

_ret_valdict

The dict which is returned by each call to __next__.

__init__(filename, has_units=False, has_indices=False)[source]

Instantiate CSVGenerator.

Parameters:
filenamestr

The filename for the CSV file containing the variable data.

has_unitsbool

If True, the second line of the CSV contains the units of each variable.

has_indicesbool

If True, the line after units (if present) contains the indices being set.

__iter__()
class openmdao.drivers.analysis_generator.ProductGenerator(var_dict)[source]

Bases: AnalysisGenerator

A generator which provides full-factorial case data for AnalysisDriver.

Parameters:
var_dictdict

A dictionary which maps promoted path names of variables to be set in each itearation with their values to be assumed (required), units (optional), and indices (optional).

__init__(var_dict)

Instantiate the base class for AnalysisGenerators.

Parameters:
var_dictdict

A dictionary mapping a variable name to values to be assumed, as well as optional units and indices specifications.

__iter__()
class openmdao.drivers.analysis_generator.SequenceGenerator(container)[source]

Bases: object

A generator which provides samples from python lists or tuples.

Internally this generator converts the list or tuple to a deque and then consumes it as it iterates over it.

Parameters:
containercontainer

A python container, excluding strings, bytes, or bytearray.

Raises:
StopIteration

When given list or tuple is exhausted.

Attributes:
_sampled_varslist(str)

A list of the variables in the model being sampled.

_iterIterator

The internal iterator over the users case data.

__init__(container)[source]

Instantiate a SequenceGenerator with the given container of samples.

__iter__()[source]

Provide the python iterator for this instance.

class openmdao.drivers.analysis_generator.ZipGenerator(var_dict)[source]

Bases: AnalysisGenerator

A generator which provides case data for AnalysisDriver by zipping values of each factor.

Parameters:
var_dictdict

A dictionary which maps promoted path names of variables to be set in each itearation with their values to be assumed (required), units (optional), and indices (optional).

__init__(var_dict)

Instantiate the base class for AnalysisGenerators.

Parameters:
var_dictdict

A dictionary mapping a variable name to values to be assumed, as well as optional units and indices specifications.

__iter__()