# options_dictionary.py¶

Define the OptionsDictionary class.

class openmdao.utils.options_dictionary.OptionsDictionary(parent_name=None, read_only=False)[source]

Bases: object

Dictionary with pre-declaration of keys for value-checking and default values.

This class is instantiated for:
1. the options attribute in solvers, drivers, and processor allocators

2. the supports attribute in drivers

3. the options attribute in systems

Parameters
parent_namestr

Name or class name of System that owns this OptionsDictionary.

If True, setting (via __setitem__ or update) is not permitted.

Attributes
_dictdict of dict

Dictionary of entries. Each entry is a dictionary consisting of value, values, types, desc, lower, and upper.

_parent_namestr or None

If defined, prepend this name to beginning of all exceptions.

If True, no options can be set after declaration.

_all_recordablebool

Flag to determine if all options in UserOptions are recordable.

_deprecation_warning_issuedlist

Option names that are deprecated and a warning has been issued for their use.

__contains__(key)[source]

Check if the key is in the local dictionary.

Parameters
keystr

name of the option.

Returns
bool

whether key is in the local dict.

__getitem__(name)[source]

Get an option from the dict or declared default.

Parameters
namestr

name of the option.

Returns
value-

value of the option.

__init__(parent_name=None, read_only=False)[source]

Initialize all attributes.

__iter__()[source]

Provide an iterator.

Returns
iterable

iterator over the keys in the dictionary.

__setitem__(name, value)[source]

Set an option in the local dictionary.

Parameters
namestr

name of the option.

value-

value of the option to be value- and type-checked if declared.

declare(name, default=UNDEFINED, values=None, types=None, desc='', upper=None, lower=None, check_valid=None, allow_none=False, recordable=True, deprecation=None)[source]

Declare an option.

The value of the option must satisfy the following: 1. If values only was given when declaring, value must be in values. 2. If types only was given when declaring, value must satisfy isinstance(value, types). 3. It is an error if both values and types are given.

Parameters
namestr

Name of the option.

defaultobject or Null

Optional default value that must be valid under the above 3 conditions.

valuesset or list or tuple or None

Optional list of acceptable option values.

typestype or tuple of types or None

Optional type or list of acceptable option types.

descstr

Optional description of the option.

upperfloat or None

Maximum allowable value.

lowerfloat or None

Minimum allowable value.

check_validfunction or None

User-supplied function with arguments (name, value) that raises an exception if the value is not valid.

allow_nonebool

If True, allow None as a value regardless of values or types.

recordablebool

deprecationstr or None

If None, it is not deprecated. If a str, use as a DeprecationWarning during __setitem__ and __getitem__.

items()[source]

Yield name and value of options.

Yields
keystr

Name of option.

valueint or bool or float or string

Value of the option.

to_table(fmt='github', missingval='N/A')[source]

Get a table representation of this OptionsDictionary as a table in the requested format.

Parameters
fmtstr

The formatting of the requested table. Options are the same as those available to the tabulate package. See tabulate.tabulate_formats for a complete list. Default value of ‘github’ produces a table in GitHub-flavored markdown.

missingvalstr

The value to be displayed in place of None.

Returns
str

A string representation of the table in the requested format.

undeclare(name)[source]

Remove entry from the OptionsDictionary, for classes that don’t use that option.

Parameters
namestr

The name of a key, the entry of which will be removed from the internal dictionary.

update(in_dict)[source]

Update the internal dictionary with the given one.

Parameters
in_dictdict

The incoming dictionary to add to the internal one.

openmdao.utils.options_dictionary.check_valid(name, value)[source]

Check the validity of value for the option with name.

Parameters
namestr

Name of the option.

valueany

Value for the option.

Raises
ValueError

If value is not valid for option.