case.py

A Case class.

class openmdao.recorders.case.Case(source, data, prom2abs, abs2prom, abs2meta, var_info, data_format=None)[source]

Bases: object

Case wraps the data from a single iteration of a recording to make it more easily accessible.

Attributes

source

(str) The unique id of the system/solver/driver/problem that did the recording.

name

(str) The unique identifier for this case.

parent

(str) The iteration coordinate of the parent case for this iteration if any, else None.

counter

(int) The unique sequential index of this case in the recording.

timestamp

(float) Time of execution of the case.

success

(str) Success flag for the case.

msg

(str) Message associated with the case.

outputs

(PromAbsDict) Map of outputs to values recorded.

inputs

(PromAbsDict or None) Map of inputs to values recorded, None if not recorded.

residuals

(PromAbsDict or None) Map of outputs to residuals recorded, None if not recorded.

jacobian

(PromAbsDict or None) Map of (output, input) to derivatives recorded, None if not recorded.

parent

(str) The full unique identifier for the parent this iteration.

abs_err

(float or None) Absolute tolerance (None if not recorded).

rel_err

(float or None) Relative tolerance (None if not recorded).

__getitem__(self, name)[source]

Get an output/input variable.

Parameters
namestr

Promoted or relative variable name in the root system’s namespace.

Returns
float or ndarray or any python object

the requested output/input variable.

__init__(self, source, data, prom2abs, abs2prom, abs2meta, var_info, data_format=None)[source]

Initialize.

Parameters
sourcestr

The unique id of the system/solver/driver/problem that did the recording.

datadict-like

Dictionary of data for a case

prom2abs{‘input’: dict, ‘output’: dict}

Dictionary mapping promoted names of all variables to absolute names.

abs2prom{‘input’: dict, ‘output’: dict}

Dictionary mapping absolute names of all variables to promoted names.

abs2metadict

Dictionary mapping absolute names of all variables to variable metadata.

var_infodict

Dictionary with information about variables (scaling, indices, execution order).

data_formatint

A version number specifying the format of array data, if not numpy arrays.

get_constraints(self, scaled=True, use_indices=True)[source]

Get the values of the constraints, as seen by the driver, for this case.

Parameters
scaledbool

If True, then return scaled values.

use_indicesbool

If True, apply indices.

Returns
PromAbsDict

Map of variables to their values.

get_design_vars(self, scaled=True, use_indices=True)[source]

Get the values of the design variables, as seen by the driver, for this case.

Parameters
scaledbool

If True, then return scaled values.

use_indicesbool

If True, apply indices.

Returns
PromAbsDict

Map of variables to their values.

get_objectives(self, scaled=True, use_indices=True)[source]

Get the values of the objectives, as seen by the driver, for this case.

Parameters
scaledbool

If True, then return scaled values.

use_indicesbool

If True, apply indices.

Returns
PromAbsDict

Map of variables to their values.

get_responses(self, scaled=True, use_indices=True)[source]

Get the values of the responses, as seen by the driver, for this case.

Parameters
scaledbool

If True, then return scaled values.

use_indicesbool

If True, apply indices.

Returns
PromAbsDict

Map of variables to their values.

get_val(self, name, units=None, indices=None)[source]

Get an output/input variable.

Function is used if you want to specify display units.

Parameters
namestr

Promoted or relative variable name in the root system’s namespace.

unitsstr, optional

Units to convert to before upon return.

indicesint or list of ints or tuple of ints or int ndarray or Iterable or None, optional

Indices or slice to return.

Returns
float or ndarray

The requested output/input variable.

property iteration_coordinate

Deprecate the ‘iteration_coordinate’ attribute.

Returns
str

The unique identifier for this case.

list_inputs(self, values=True, prom_name=False, units=False, shape=False, hierarchical=True, print_arrays=False, tags=None, out_stream=<object object at 0x7f63fabf29f0>)[source]

Return and optionally log a list of input names and other optional information.

Also optionally logs the information to a user defined output stream.

Parameters
valuesbool, optional

When True, display/return input values. Default is True.

prom_namebool, optional

When True, display/return the promoted name of the variable. Default is False.

unitsbool, optional

When True, display/return units. Default is False.

shapebool, optional

When True, display/return the shape of the value. Default is False.

hierarchicalbool, optional

When True, human readable output shows variables in hierarchical format.

print_arraysbool, optional

When False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False.

tagsstr or list of strs

User defined tags that can be used to filter what gets listed. Only inputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.

out_streamfile-like object

Where to send human readable output. Default is sys.stdout. Set to None to suppress.

Returns
list

list of input names and other optional information about those inputs

list_outputs(self, explicit=True, implicit=True, values=True, prom_name=False, residuals=False, residuals_tol=None, units=False, shape=False, bounds=False, scaling=False, hierarchical=True, print_arrays=False, tags=None, out_stream=<object object at 0x7f63fabf29f0>)[source]

Return and optionally log a list of output names and other optional information.

Also optionally logs the information to a user defined output stream.

Parameters
explicitbool, optional

include outputs from explicit components. Default is True.

implicitbool, optional

include outputs from implicit components. Default is True.

valuesbool, optional

When True, display/return output values. Default is True.

prom_namebool, optional

When True, display/return the promoted name of the variable. Default is False.

residualsbool, optional

When True, display/return residual values. Default is False.

residuals_tolfloat, optional

If set, limits the output of list_outputs to only variables where the norm of the resids array is greater than the given ‘residuals_tol’. Default is None.

unitsbool, optional

When True, display/return units. Default is False.

shapebool, optional

When True, display/return the shape of the value. Default is False.

boundsbool, optional

When True, display/return bounds (lower and upper). Default is False.

scalingbool, optional

When True, display/return scaling (ref, ref0, and res_ref). Default is False.

hierarchicalbool, optional

When True, human readable output shows variables in hierarchical format.

print_arraysbool, optional

When False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False.

tagsstr or list of strs

User defined tags that can be used to filter what gets listed. Only inputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.

out_streamfile-like

Where to send human readable output. Default is sys.stdout. Set to None to suppress.

Returns
list

list of output names and other optional information about those outputs

class openmdao.recorders.case.PromAbsDict(values, prom2abs, abs2prom, output=True)[source]

Bases: dict

A dictionary that enables accessing values via absolute or promoted variable names.

__contains__(self, key, /)

True if D has a key k, else False.

__getitem__(self, key)[source]

Use the variable name to get the corresponding value.

Parameters
keystring

Absolute or promoted variable name.

Returns
array :

An array entry value that corresponds to the given variable name.

__init__(self, values, prom2abs, abs2prom, output=True)[source]

Initialize.

Parameters
valuesarray or dict

Numpy structured array or dictionary of values.

prom2abs{‘input’: dict, ‘output’: dict}

Dictionary mapping promoted names to absolute names.

abs2prom{‘input’: dict, ‘output’: dict}

Dictionary mapping absolute names to promoted names.

outputbool

True if this should map using output variable names, False for input variable names.

__iter__(self, /)

Implement iter(self).

__setitem__(self, key, value)[source]

Set the value for the given key, which may use absolute or promoted names.

Parameters
keystring

Absolute or promoted variable name.

valueany

value for variable

absolute_names(self)[source]

Yield absolute names for variables contained in this dictionary.

Similar to keys() but with absolute variable names instead of promoted names.

clear()
copy()
fromkeys(iterable, value=None, /)

Returns a new dict with keys from iterable and values equal to value.

get()
items()
keys()
pop()

If key is not found, d is returned if given, otherwise KeyError is raised

popitem()

2-tuple; but raise KeyError if D is empty.

setdefault()
update()

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()