cosapp.utils.options_dictionary

Define the OptionsDictionary class.

Copyright (c) 2016-2018, openmdao.org

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this software except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This module comes from OpenMDAO 2.2.0. It was slightly modified for CoSApp integration.

Classes

OptionsDictionary([read_only])

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

class cosapp.utils.options_dictionary.OptionsDictionary(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

_dict

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

Type:

dict of dict

_read_only

If True, no options can be set after declaration.

Type:

bool

clear()[source]
declare(name, default=<object object>, values=None, dtype=None, desc='', upper=None, lower=None, check_valid=None, allow_none=False)[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 dtype only was given when declaring, value must satisfy isinstance(value, dtype). 3. It is an error if both values and dtype are given.

Parameters:
  • name (str) – Name of the option.

  • default (object or Null) – Optional default value that must be valid under the above 3 conditions.

  • values (set or list or tuple or None) – Optional list of acceptable option values.

  • dtype (type or tuple of types or None) – Optional type or list of acceptable optional types.

  • desc (str) – Optional description of the option.

  • upper (float or None) – Maximum allowable value.

  • lower (float or None) – Minimum allowable value.

  • check_valid (function or None) – General check function that raises an exception if value is not valid.

  • allow_none (bool) – If True, allow None as a value regardless of values or dtype.

items()[source]

Return an iterator over dict keys and values, as tuples. Raises RuntimeError if a required option is undefined.

keys()[source]

Return an iterator over dict keys.

undeclare(name)[source]

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

Parameters:

name (str) – 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_dict (dict) – The incoming dictionary to add to the internal one.

values()[source]

Return an iterator over dict values. Raises RuntimeError if a required option is undefined.