name_maps.py#
Maps between promoted/relative/absolute names.
- class openmdao.utils.name_maps.NameResolver(pathname, msginfo='', check_dups=False)[source]
Bases:
object
Resolve names between absolute and promoted names.
- Parameters:
- pathnamestr
The pathname of the system.
- msginfostr
The message information for the system.
- check_dupsbool
If True, check for duplicate names.
- Attributes:
- _pathnamestr
The pathname of the system.
- _prefixstr
The prefix of the system.
- _pathlenint
The length of the pathname.
- _abs2promdict
A dictionary of absolute to promoted names.
- _abs2prom_indict
A dictionary of absolute to promoted names for inputs.
- _abs2prom_outdict
A dictionary of absolute to promoted names for outputs.
- _prom2absdict
A dictionary of promoted to absolute names.
- _prom2abs_indict
A dictionary of promoted to absolute names for inputs.
- _prom2abs_outdict
A dictionary of promoted to absolute names for outputs.
- _prom_no_multi_absbool
If True, all promoted names map to a single absolute name.
- _connsdict or None
The connections dictionary.
- msginfostr
The message information for the system.
- has_remotebool
If True, the name resolver has remote variables.
- __init__(pathname, msginfo='', check_dups=False)[source]
Initialize the name resolver.
- Parameters:
- pathnamestr
The pathname of the system.
- msginfostr
The message information for the system.
- check_dupsbool
If True, check for duplicate names.
- abs2prom(absname, iotype=None)[source]
Convert an absolute name to a promoted name.
- Parameters:
- absnamestr
The absolute name to convert.
- iotypestr
Either ‘input’, ‘output’, or None to check all iotypes.
- Returns:
- str
The promoted name corresponding to the absolute name.
- abs2prom_iter(iotype=None, local=None, continuous=None, distributed=None)[source]
Yield absolute names and their promoted names.
- Parameters:
- iotypestr
Either ‘input’, ‘output’, or None to yield all iotypes.
- localbool or None
If True, yield only local names. If False, yield only non-local names. If None, yield all names.
- continuousbool or None
If True, yield only continuous names. If False, yield only discrete names. If None, yield all names.
- distributedbool or None
If True, yield only distributed names. If False, yield only non-distributed names. If None, yield all names.
- Yields:
- absnamestr
Absolute name.
- promnamestr
Promoted name.
- abs2rel(absname, iotype=None, check=False)[source]
Convert an absolute name to a relative name.
- Parameters:
- absnamestr
The absolute name to convert.
- iotypestr
Either ‘input’, ‘output’, or None to allow all iotypes.
- checkbool
If True, check if the absolute name is found.
- Returns:
- str or None
The relative name corresponding to the absolute name or None if check is True and the absolute name is not found.
- abs_iter(iotype=None, local=None, continuous=None, distributed=None)[source]
Yield absolute names.
- Parameters:
- iotypestr
Either ‘input’, ‘output’, or None to yield all iotypes.
- localbool or None
If True, yield only local names. If False, yield only non-local names. If None, yield all names.
- continuousbool or None
If True, yield only continuous names. If False, yield only discrete names. If None, yield all names.
- distributedbool or None
If True, yield only distributed names. If False, yield only non-distributed names. If None, yield all names.
- Yields:
- absnamestr
Absolute name.
- absnames(promname, iotype=None, report_error=True)[source]
Get the absolute names corresponding to a promoted name.
- Parameters:
- promnamestr
The promoted name to get the absolute names of.
- iotypestr
Either ‘input’, ‘output’, or None to check all iotypes.
- report_errorbool
If True, raise an error if the promoted name is not found.
- Returns:
- list of str or None
The absolute names corresponding to the promoted name, or None if report_error is False and the promoted name is not found.
- add_mapping(absname, promname, iotype, local=True, continuous=True, distributed=False)[source]
Add a mapping between an absolute name and a promoted name.
- Parameters:
- absnamestr
Absolute name.
- promnamestr
Promoted name.
- iotypestr
Either ‘input’ or ‘output’.
- localbool
If True, the variable is local.
- continuousbool
If True, the variable is continuous.
- distributedbool
If True, the variable is distributed.
- any2abs(name, iotype=None, default=None)[source]
Convert any name to a unique absolute name.
- Parameters:
- namestr
Promoted or relative name.
- iotypestr or None
Either ‘input’, ‘output’, or None to check all iotypes.
- defaultstr or None
The value to return if the name is not found. Default is None.
- Returns:
- str
Absolute name.
- any2abs_key(key)[source]
Convert any jacobian key to an absolute key.
- Parameters:
- key(str, str)
The jacobian key to convert.
- Returns:
- (str, str) or None
The absolute key or None if the key is not found.
- any2prom(name, iotype=None, default=None)[source]
Convert any name to a promoted name.
- Parameters:
- namestr
Promoted or relative name.
- iotypestr or None
Either ‘input’, ‘output’, or None to check all iotypes.
- defaultstr or None
The value to return if the name is not found. Default is None.
- Returns:
- str
Promoted name.
- check_flags(absname, iotype=None, local=None, continuous=None, distributed=None)[source]
Check if an absolute name has the specified flag values.
- Parameters:
- absnamestr
The absolute name to check.
- iotypestr
Either ‘input’, ‘output’, or None to check all iotypes.
- localbool or None
If True, checked flag must be local. If False, checked flag must be remote. If None, this part of the flag is ignored.
- continuousbool or None
If True, checked flag must be continuous. If False, checked flag must be discrete. If None, this part of the flag is ignored.
- distributedbool or None
If True, checked flag must be distributed. If False, checked flag must be non-distributed. If None, this part of the flag is ignored.
- Returns:
- bool
True if the absolute name has the specified flag values, False otherwise.
- contains(name, iotype=None)[source]
Check if the name resolver contains the given name.
- Parameters:
- namestr
The name to check.
- iotypestr
Either ‘input’, ‘output’, or None to check all iotypes.
- Returns:
- bool
True if the name resolver contains the given name, False otherwise.
- flags(absname, iotype=None)[source]
Get the flags for a variable.
- Parameters:
- absnamestr
The absolute name of the variable.
- iotypestr
Either ‘input’, ‘output’, or None to check all iotypes.
- Returns:
- tuple
Tuple of the form (promoted_name, int).
- flags_iter(iotype=None)[source]
Yield absolute names and the corresponding flags.
- Parameters:
- iotypestr
Either ‘input’, ‘output’, or None to yield all iotypes.
- Yields:
- absnamestr
Absolute name.
- flagsint
Flags for the variable.
- get_abs_iotype(absname, report_error=False)[source]
Get the iotype of an absolute name.
- Parameters:
- absnamestr
The absolute name to get the iotype of.
- report_errorbool
If True, raise an error if the absolute name is not found.
- Returns:
- str or None
The iotype of the absolute name or None if the absolute name is not found.
- get_iotype(name, report_error=False)[source]
Get the iotype of a name. The name may be an absolute or promoted name.
- Parameters:
- namestr
The name to get the iotype of.
- report_errorbool
If True, raise an error if the name is not found.
- Returns:
- str
The iotype of the variable.
- get_prom_iotype(promname, report_error=False)[source]
Get the iotype of a promoted name.
If the promoted name is both an input and an output, the returned iotype will be ‘output’, which is always unambiguous.
- Parameters:
- promnamestr
The promoted name to get the iotype of.
- report_errorbool
If True, raise an error if the promoted name is not found.
- Returns:
- str or None
The iotype of the promoted name or None if the promoted name is not found.
- is_abs(absname, iotype=None)[source]
Check if an absolute name exists.
- Parameters:
- absnamestr
The absolute name to check.
- iotypestr
Either ‘input’, ‘output’, or None to check all iotypes.
- Returns:
- bool
True if the absolute name exists, False otherwise.
- is_local(absname, iotype=None)[source]
Check if an absolute name exists.
- Parameters:
- absnamestr
The absolute name to check.
- iotypestr
Either ‘input’, ‘output’, or None to check all iotypes.
- Returns:
- bool
True if the absolute name is local, False otherwise.
- is_prom(promname, iotype=None)[source]
Check if a promoted name exists.
- Parameters:
- promnamestr
The promoted name to check.
- iotypestr
Either ‘input’, ‘output’, or None to check all iotypes.
- Returns:
- bool
True if the promoted name exists, False otherwise.
- num_abs(iotype=None, local=None)[source]
Get the number of absolute names.
- Parameters:
- iotypestr
Either ‘input’, ‘output’, or None to count all iotypes.
- localbool or None
If True, count only local names. If False, count only non-local names. If None, count all names.
- Returns:
- int
The number of absolute names of the specified iotype.
- num_proms(iotype=None)[source]
Get the number of promoted names.
- Parameters:
- iotypestr
Either ‘input’, ‘output’, or None to count all iotypes.
- Returns:
- int
The number of promoted names of the specified iotype.
- prom2abs(promname, iotype=None)[source]
Convert a promoted name to an unique absolute name.
If the promoted name doesn’t correspond to a single absolute name, an error is raised.
- Parameters:
- promnamestr
The promoted name to convert.
- iotypestr or None
Either ‘input’, ‘output’, or None to check all iotypes.
- Returns:
- str
The absolute name corresponding to the promoted name.
- prom2abs_iter(iotype, local=None, continuous=None, distributed=None)[source]
Yield promoted names and their absolute names.
- Parameters:
- iotypestr
Either ‘input’, ‘output’, or None to yield all iotypes.
- localbool or None
If True, yield only local names. If False, yield only non-local names. If None, yield all names.
- continuousbool or None
If True, yield only continuous names. If False, yield only discrete names. If None, yield all names.
- distributedbool or None
If True, yield only distributed names. If False, yield only non-distributed names. If None, yield all names.
- Yields:
- promnamestr
Promoted name.
- absnameslist of str
Absolute names corresponding to the promoted name.
- prom2prom(promname, other, iotype=None)[source]
Convert a promoted name in other to our promoted name.
This requires a matching absolute name between the two NameResolvers.
- Parameters:
- promnamestr
The promoted name to convert.
- otherNameResolver
The other name resolver.
- iotypestr or None
Either ‘input’, ‘output’, or None to check all iotypes.
- Returns:
- str
The promoted name corresponding to the converted promoted name or the original promoted name if no match is found.
- prom_iter(iotype=None, local=None, continuous=None, distributed=None)[source]
Yield promoted names.
- Parameters:
- iotypestr
Either ‘input’, ‘output’, or None to yield all iotypes.
- localbool or None
If True, yield only local names. If False, yield only non-local names. If None, yield all names.
- continuousbool or None
If True, yield only continuous names. If False, yield only discrete names. If None, yield all names.
- distributedbool or None
If True, yield only distributed names. If False, yield only non-distributed names. If None, yield all names.
- Yields:
- promnamestr
Promoted name.
- prom_or_rel2abs(name, iotype=None, report_error=False)[source]
Convert any promoted or relative name to a unique absolute name.
- Parameters:
- namestr
Promoted or relative name.
- iotypestr or None
Either ‘input’, ‘output’, or None to check all iotypes.
- report_errorbool
If True, raise an error if the name is not found.
- Returns:
- str
Absolute name.
- rel2abs(relname, iotype=None, check=False)[source]
Convert a relative name to an absolute name.
- Parameters:
- relnamestr
The relative name to convert.
- iotypestr
Either ‘input’, ‘output’, or None to allow all iotypes.
- checkbool
If True, check if the relative name is found.
- Returns:
- str or None
The absolute name corresponding to the relative name or None if check is True and the absolute name is not found.
- rel2abs_iter(relnames)[source]
Yield absolute names corresponding to a list of relative names.
- Parameters:
- relnameslist of str
The relative names to convert.
- Yields:
- absnamestr
The absolute name corresponding to the relative name.
- source(name, iotype=None, report_error=True)[source]
Get the source of a variable.
If the variable is an input, the source is the connected output. If the variable is an output, the source is the variable itself.
- Parameters:
- namestr
The name to get the source of.
- iotypestr
Either ‘input’, ‘output’, or None to allow all iotypes. If not None, the given name must correspond to the specified iotype.
- report_errorbool
If True, raise an error if the source is not found.
- Returns:
- str
The source corresponding to the name.
- update_from_ranks(myrank, others)[source]
Update the name resolver with name resolvers from multiple ranks.
- Parameters:
- myrankint
The rank of the current process.
- otherslist of NameResolver
The name resolvers to update with.
- openmdao.utils.name_maps.abs_key2rel_key(obj, abs_key)[source]
Map relative variable name pair to absolute variable name pair.
- Parameters:
- objobject
Object to which the given key is relative. The object must have a pathname attribute.
- abs_key(str, str)
Given absolute variable name pair.
- Returns:
- (str, str)
Relative variable name pair.
- openmdao.utils.name_maps.abs_key_iter(system, rel_ofs, rel_wrts)[source]
Return absolute jacobian keys given relative ‘of’ and ‘wrt’ names.
- Parameters:
- systemSystem
The scoping system.
- rel_ofsiter of str
Names of the relative ‘of’ variables.
- rel_wrtsiter of str
Names of the relative ‘wrt’ variables.
- Yields:
- abs_of
Absolute ‘of’ name.
- abs_wrt
Absolute ‘wrt’ name.
- openmdao.utils.name_maps.rel_key2abs_key(obj, rel_key, delim='.')[source]
Map relative variable name pair to absolute variable name pair.
- Parameters:
- objobject
Object to which the given key is relative. The object must have a pathname attribute that is a string delimited by ‘delim’.
- rel_key(str, str)
Given relative variable name pair.
- delimstr
Delimiter between the parts of the object pathname.
- Returns:
- (str, str)
Absolute variable name pair.