def list_outputs(self, explicit=True, implicit=True, values=True, prom_name=False, residuals=False, residuals_tol=None, units=False, shape=False, bounds=False, scaling=False, desc=False, hierarchical=True, print_arrays=False, tags=None, includes=None, excludes=None, out_stream=_DEFAULT_OUT_STREAM): """ Return and optionally log a list of output names and other optional information. Parameters ---------- explicit : bool, optional include outputs from explicit components. Default is True. implicit : bool, optional include outputs from implicit components. Default is True. values : bool, optional When True, display/return output values. Default is True. prom_name : bool, optional When True, display/return the promoted name of the variable. Default is False. residuals : bool, optional When True, display/return residual values. Default is False. residuals_tol : float, optional If set, limits the output of list_outputs to only variables where the norm of the resids array is greater than the given 'residuals_tol'. Default is None. units : bool, optional When True, display/return units. Default is False. shape : bool, optional When True, display/return the shape of the value. Default is False. bounds : bool, optional When True, display/return bounds (lower and upper). Default is False. scaling : bool, optional When True, display/return scaling (ref, ref0, and res_ref). Default is False. desc : bool, optional When True, display/return description. Default is False. hierarchical : bool, optional When True, human readable output shows variables in hierarchical format. print_arrays : bool, optional When False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False. tags : str or list of strs User defined tags that can be used to filter what gets listed. Only outputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags. includes : None or list_like List of glob patterns for pathnames to include in the check. Default is None, which includes all components in the model. excludes : None or list_like List of glob patterns for pathnames to exclude from the check. Default is None, which excludes nothing. out_stream : file-like Where to send human readable output. Default is sys.stdout. Set to None to suppress. Returns ------- list list of output names and other optional information about those outputs """ meta = self._abs2meta expl_outputs = [] impl_outputs = [] for var_name in self.outputs.absolute_names(): # Filter based on tags if tags and not (make_set(tags) & make_set(meta[var_name]['tags'])): continue var_name_prom = self._abs2prom['output'][var_name] if not match_includes_excludes(var_name, var_name_prom, includes, excludes): continue # check if residuals were recorded, skip if within specifed tolerance if self.residuals and var_name in self.residuals.absolute_names(): resids = self.residuals[var_name] if residuals_tol and np.linalg.norm(resids) < residuals_tol: continue else: resids = 'Not Recorded' val = self.outputs[var_name] var_meta = {} if values: var_meta['value'] = val if prom_name: var_meta['prom_name'] = var_name_prom if residuals: var_meta['resids'] = resids if units: var_meta['units'] = meta[var_name]['units'] if shape: var_meta['shape'] = val.shape if bounds: var_meta['lower'] = meta[var_name]['lower'] var_meta['upper'] = meta[var_name]['upper'] if scaling: var_meta['ref'] = meta[var_name]['ref'] var_meta['ref0'] = meta[var_name]['ref0'] var_meta['res_ref'] = meta[var_name]['res_ref'] if desc: var_meta['desc'] = meta[var_name]['desc'] if meta[var_name]['explicit']: expl_outputs.append((var_name, var_meta)) else: impl_outputs.append((var_name, var_meta)) if out_stream is _DEFAULT_OUT_STREAM: out_stream = sys.stdout if out_stream: if self.outputs is None or len(self.outputs) == 0: out_stream.write( 'WARNING: Outputs not recorded. Make sure your recording ' + 'settings have record_outputs set to True\n') if explicit: self._write_table('explicit', expl_outputs, hierarchical, print_arrays, out_stream) if implicit: self._write_table('implicit', impl_outputs, hierarchical, print_arrays, out_stream) if explicit and implicit: return expl_outputs + impl_outputs elif explicit: return expl_outputs elif implicit: return impl_outputs else: raise RuntimeError( 'You have excluded both Explicit and Implicit components.')
def list_inputs(self, values=True, prom_name=False, units=False, shape=False, desc=False, hierarchical=True, print_arrays=False, tags=None, includes=None, excludes=None, out_stream=_DEFAULT_OUT_STREAM): """ Return and optionally log a list of input names and other optional information. Parameters ---------- values : bool, optional When True, display/return input values. Default is True. prom_name : bool, optional When True, display/return the promoted name of the variable. Default is False. units : bool, optional When True, display/return units. Default is False. shape : bool, optional When True, display/return the shape of the value. Default is False. desc : bool, optional When True, display/return description. Default is False. hierarchical : bool, optional When True, human readable output shows variables in hierarchical format. print_arrays : bool, optional When False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False. tags : str or list of strs User defined tags that can be used to filter what gets listed. Only inputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags. includes : None or list_like List of glob patterns for pathnames to include in the check. Default is None, which includes all components in the model. excludes : None or list_like List of glob patterns for pathnames to exclude from the check. Default is None, which excludes nothing. out_stream : file-like object Where to send human readable output. Default is sys.stdout. Set to None to suppress. Returns ------- list list of input names and other optional information about those inputs """ meta = self._abs2meta inputs = [] if self.inputs is not None: for var_name in self.inputs.absolute_names(): # Filter based on tags if tags and not (make_set(tags) & make_set(meta[var_name]['tags'])): continue var_name_prom = self._abs2prom['input'][var_name] if not match_includes_excludes(var_name, var_name_prom, includes, excludes): continue val = self.inputs[var_name] var_meta = {} if values: var_meta['value'] = val if prom_name: var_meta['prom_name'] = var_name_prom if units: var_meta['units'] = meta[var_name]['units'] if shape: var_meta['shape'] = val.shape if desc: var_meta['desc'] = meta[var_name]['desc'] inputs.append((var_name, var_meta)) if out_stream is _DEFAULT_OUT_STREAM: out_stream = sys.stdout if out_stream: if self.inputs is None or len(self.inputs) == 0: out_stream.write( 'WARNING: Inputs not recorded. Make sure your recording ' + 'settings have record_inputs set to True\n') self._write_table('input', inputs, hierarchical, print_arrays, out_stream) return inputs