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

__contains__(key)[source]

Check if the key is in the local dictionary.

Parameters
keystr

name of the option.

Returns
boolean

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.

Parameters
parent_namestr

Name or class name of System that owns this OptionsDictionary

read_onlybool

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

__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

If True, add to recorder

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.

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