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

HasCompositeOptions()

HasOptions()

Base class to handle options as OptionsDictionary.

OptionsDictionary([read_only])

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

Exceptions

OptionError

Raised if an option-related error is encountered.

class cosapp.utils.options_dictionary.HasCompositeOptions[source]

Bases: HasOptions

set_options() None[source]

Sets options from the current state.

class cosapp.utils.options_dictionary.HasOptions[source]

Bases: object

Base class to handle options as OptionsDictionary.

set_options() None[source]

Sets options from the current state.

exception cosapp.utils.options_dictionary.OptionError[source]

Bases: Exception

Raised if an option-related error is encountered.

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, tag=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 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.

  • tag (Optional[str]) – Specify a tag to allow later filtering of options.

get(key: str, fallback: ~typing.Any = <object object>, /) Any[source]

Return the value associated with key, if any, or a fallback value.

Parameters:
  • [str] (- key)

  • [Any (- fallback)

  • optional] (fallback value if key does not exist)

Returns:

Any

Return type:

the value associated to key, or fallback, if prescribed.

Raises:

KeyError

items(tags: Container[str] = ())[source]

Return an iterator over dict keys and values, as tuples.

The items can be filtered by tags if provided.

Raises OptionError if a required option is undefined.

Parameters:

tags (Container[str]) – tags to filter

Returns:

iterator to the filtered items.

Return type:

items

keys()[source]

Return an iterator over dict keys.

merge(other: OptionsDictionary) None[source]
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(dictionary: dict) None[source]

Update the internal dictionary with the given one.

Parameters:

dictionary (dict) – The incoming dictionary to add to the internal one.

values()[source]

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

cosapp.utils.options_dictionary.object__getstate__(self, /)

Helper for pickle.