def construct_channel(self, **kwargs):

        if self.compatibility_mode:

            config.LOGGER.info("Populating channel... ")
            channel = self.chef_module.construct_channel(**kwargs)
            return channel
        else:
            raise NotImplementedError('Your chef class must overrride the construct_channel method')

Calls chef script's construct_channel method. Used only in compatibility mode.
Args:
kwargs (dict): additional keyword arguments that `uploadchannel` received
Returns: channel populated from construct_channel method


def _SetAllFieldTypes(self, package, desc_proto, scope):

    package = _PrefixWithDot(package)

    main_desc = self._GetTypeFromScope(package, desc_proto.name, scope)

    if package == '.':
      nested_package = _PrefixWithDot(desc_proto.name)
    else:
      nested_package = '.'.join([package, desc_proto.name])

    for field_proto, field_desc in zip(desc_proto.field, main_desc.fields):
      self._SetFieldType(field_proto, field_desc, nested_package, scope)

    for extension_proto, extension_desc in (
        zip(desc_proto.extension, main_desc.extensions)):
      extension_desc.containing_type = self._GetTypeFromScope(
          nested_package, extension_proto.extendee, scope)
      self._SetFieldType(extension_proto, extension_desc, nested_package, scope)

    for nested_type in desc_proto.nested_type:
      self._SetAllFieldTypes(nested_package, nested_type, scope)

Sets all the descriptor's fields's types.

This method also sets the containing types on any extensions.

Args:
package: The current package of desc_proto.
desc_proto: The message descriptor to update.
scope: Enclosing scope of available types.


def stop_batch_gradient(cls, x: 'TensorFluent', stop_batch: tf.Tensor) -> 'TensorFluent':

        scope = x.scope.as_list()
        batch = x.batch
        tensor = tf.where(stop_batch, tf.stop_gradient(x.tensor), x.tensor)
        return TensorFluent(tensor, scope, batch)

Returns a copy of the inputs fluent with stop_gradient applied at batch level.

Args:
x: The input fluent.
stop_batch: A boolean tf.Tensor with shape=(batch_size, ...)

Returns:
A TensorFluent that conditionally stops backpropagation of gradient computations.


def last_updated(self, path):
    if not self.exists(path):
        raise BeamIOError('Path does not exist: %s' % path)
    return os.path.getmtime(path)

Get UNIX Epoch time in seconds on the FileSystem.

Args:
path: string path of file.

Returns: float UNIX Epoch time

Raises:
``BeamIOError``: if path doesn't exist.


def from_config(cls, config: dict):
    timestamp = config.get('timestamp', None)
    return cls(config.get('id'), config.get('type'), config.get('data', dict()), config.get('origin', None), timestamp, config.get('object_type', None), config.get('object_id', None), config.get('object_key', None))

Create an event object from an event dictionary object.

Args:
config (dict): Event Configuration dictionary.


def get_input_at(self, node_index):
    return self._get_node_attribute_at_index(node_index, 'input_tensors', 'input')

Retrieves the input tensor(s) of a layer at a given node.

Args:
node_index: Integer, index of the node
from which to retrieve the attribute.
E.g. `node_index=0` will correspond to the
first input node of the layer.

Returns:
A tensor (or list of tensors if the layer has multiple inputs).

Raises:
RuntimeError: If called in Eager mode.


def regression_errors(y, y_hat, smoothing_window=0.01, smooth=True):
    errors = np.abs((y - y_hat))[(:, 0)]
    if (not smooth):
        return errors
    smoothing_window = int((smoothing_window * len(y)))
    return pd.Series(errors).ewm(span=smoothing_window).mean().values

Compute an array of absolute errors comparing predictions and expected output.

If smooth is True, apply EWMA to the resulting array of errors.

Args:
y (array): Ground truth.
y_hat (array): Predictions array.
smoothing_window (float): Size of the smoothing window, expressed as a proportion
of the total length of y.
smooth (bool): whether the returned errors should be smoothed with EWMA.

Returns:
(array): errors


def __init__(self, sess, thread_name_filter=None, pass_through_operrors=False):
    _check_type(sess, (session.BaseSession, monitored_session.MonitoredSession))
    self._sess = sess
    self._thread_name_filter_pattern = re.compile(thread_name_filter) if thread_name_filter else None
    self._pass_through_operrors = pass_through_operrors
    self._run_call_count = 0
    response = self.on_session_init(OnSessionInitRequest(self._sess))
    _check_type(response, OnSessionInitResponse)
    if response.action == OnSessionInitAction.PROCEED:
        pass
    elif response.action == OnSessionInitAction.REMOTE_INSTR_LOOP:
        raise NotImplementedError('OnSessionInitAction REMOTE_INSTR_LOOP has not been implemented.')
    else:
        raise ValueError('Invalid OnSessionInitAction value: %s' % response.action)
    self._default_session_context_manager = None
    self._cached_callables_from_options = {}

Constructor of `BaseDebugWrapperSession`.

Args:
sess: An (unwrapped) TensorFlow session instance. It should be a subtype
of `BaseSession` or `tf.MonitoredSession`.
thread_name_filter: Regular-expression filter (allowlist) for name(s) of
thread(s) on which the wrapper session will be active. This regular
expression is used in a start-anchored fashion on the thread name, i.e.,
by applying the `match` method of the compiled pattern. The default
`None` means that the wrapper session will be active on all threads.
E.g., r"MainThread$", r"QueueRunnerThread.*".
pass_through_operrors: If True, all captured OpErrors will be
propagated.  By default this captures all OpErrors.

Raises:
ValueError: On invalid `OnSessionInitAction` value.
NotImplementedError: If a non-DirectSession sess object is received.


def GetPathInfo(self, timestamp=None):

    path_info_timestamp = self._LastEntryTimestamp(self._path_infos, timestamp)
    try:
      result = self._path_infos[path_info_timestamp].Copy()
    except KeyError:
      result = rdf_objects.PathInfo(
          path_type=self._path_type, components=self._components)

    stat_entry_timestamp = self._LastEntryTimestamp(self._stat_entries,
                                                    timestamp)
    result.last_stat_entry_timestamp = stat_entry_timestamp
    result.stat_entry = self._stat_entries.get(stat_entry_timestamp)

    hash_entry_timestamp = self._LastEntryTimestamp(self._hash_entries,
                                                    timestamp)
    result.last_hash_entry_timestamp = hash_entry_timestamp
    result.hash_entry = self._hash_entries.get(hash_entry_timestamp)

    return result

Generates a summary about the path record.

Args:
timestamp: A point in time from which the data should be retrieved.

Returns:
A `rdf_objects.PathInfo` instance.


def _ReadSupportedOS(self, definition_values, definition_object, name):

    supported_os = definition_values.get('supported_os', [])
    if not isinstance(supported_os, list):
      raise errors.FormatError(
          'Invalid supported_os type: {0!s}'.format(type(supported_os)))

    undefined_supported_os = set(supported_os).difference(self.supported_os)
    if undefined_supported_os:
      error_string = (
          'Artifact definition: {0:s} undefined supported operating system: '
          '{1:s}.').format(name, ', '.join(undefined_supported_os))
      raise errors.FormatError(error_string)

    definition_object.supported_os = supported_os

Reads the optional artifact or source type supported OS.

Args:
definition_values (dict[str, object]): artifact definition values.
definition_object (ArtifactDefinition|SourceType): the definition object.
name (str): name of the artifact definition.

Raises:
FormatError: if there are undefined supported operating systems.


def page(title, description, element_list=None, tab_list=None):
    _page = {'Type': 'Page', 'Title': title, 'Description': description, 'Data': {}}
    if (element_list is not None):
        if isinstance(element_list, list):
            _page['Data']['Elements'] = element_list
        else:
            _page['Data']['Elements'] = [element_list]
    if (tab_list is not None):
        if isinstance(tab_list, list):
            _page['Data']['Tabs'] = tab_list
        else:
            _page['Data']['Tabs'] = [tab_list]
    return _page

Returns a dictionary representing a new page to display elements.
This can be thought of as a simple container for displaying multiple
types of information. The ``section`` method can be used to create
separate tabs.

Args:
title: The title to display
description: A description of the section
element_list: The list of elements to display. If a single element is
given it will be wrapped in a list.
tab_list: A list of tabs to display.

Returns:
A dictionary with metadata specifying that it is to be rendered
as a page containing multiple elements and/or tabs.


def reindex(self, kdims=None, vdims=None):
    gridded = self.interface.gridded
    scalars = []
    if gridded:
        coords = [(d, self.interface.coords(self, d.name)) for d in self.kdims]
        scalars = [d for (d, vs) in coords if (len(vs) == 1)]
    if (kdims is None):
        key_dims = [d for d in self.kdims if (((not vdims) or (d not in vdims)) and (not (d in scalars)))]
    elif (not isinstance(kdims, list)):
        key_dims = [self.get_dimension(kdims, strict=True)]
    else:
        key_dims = [self.get_dimension(k, strict=True) for k in kdims]
    dropped = [d for d in self.kdims if ((not (d in key_dims)) and (not (d in scalars)))]
    new_type = None
    if (vdims is None):
        val_dims = [d for d in self.vdims if ((not kdims) or (d not in kdims))]
    else:
        val_dims = [self.get_dimension(v, strict=True) for v in vdims]
        new_type = self._vdim_reductions.get(len(val_dims), type(self))
    data = self.interface.reindex(self, key_dims, val_dims)
    datatype = self.datatype
    if (gridded and dropped):
        interfaces = self.interface.interfaces
        datatype = [dt for dt in datatype if (not getattr(interfaces.get(dt, None), 'gridded', True))]
    return self.clone(data, kdims=key_dims, vdims=val_dims, new_type=new_type, datatype=datatype)

Reindexes Dataset dropping static or supplied kdims

Creates a new object with a reordered or reduced set of key
dimensions. By default drops all non-varying key dimensions.x

Args:
kdims (optional): New list of key dimensionsx
vdims (optional): New list of value dimensions

Returns:
Reindexed object


def AddInformationalOptions(self, argument_group):

    argument_group.add_argument(
        '-d', '--debug', dest='debug', action='store_true', default=False,
        help='Enable debug output.')

    argument_group.add_argument(
        '-q', '--quiet', dest='quiet', action='store_true', default=False,
        help='Disable informational output.')

Adds the informational options to the argument group.

Args:
argument_group (argparse._ArgumentGroup): argparse argument group.


def get_category(self, column):

        result = pd.Series(index=column.index)

        for category, stats in self.probability_map.items():
            start, end = stats[0]
            result[(start < column) & (column < end)] = category

        return result

Returns categories for the specified numeric values

Args:
column(pandas.Series): Values to transform into categories

Returns:
pandas.Series


def dump(self, file, payload):

        json.dump(payload, file, indent=2, ensure_ascii=False)

Dump json oject to open file output.

Writes json with 2 spaces indentation.

Args:
file: Open file-like object. Must be open for writing.
payload: The Json object to write to file.

Returns:
None.


def ignore(wrapped):

    @functools.wraps(wrapped)
    def _ignore(*args, **kwargs):
        return wrapped(*args, **kwargs)
    _ignore._splpy_optype = _OperatorType.Ignore
    _ignore._splpy_file = inspect.getsourcefile(wrapped)
    return _ignore

Decorator to ignore a Python function.

If a Python callable is decorated with ``@spl.ignore``
then function is ignored by ``spl-python-extract.py``.

Args:
wrapped: Function that will be ignored.


def parse_newsgroup(line):

    parts = line.split()
    try:
        group = parts[0]
        low = int(parts[1])
        high = int(parts[2])
        status = parts[3]
    except (IndexError, ValueError):
        raise ValueError("Invalid newsgroup info")
    return group, low, high, status

Parse a newsgroup info line to python types.

Args:
line: An info response line containing newsgroup info.

Returns:
A tuple of group name, low-water as integer, high-water as integer and
posting status.

Raises:
ValueError: If the newsgroup info cannot be parsed.

Note:
Posting status is a character is one of (but not limited to):
"y" posting allowed
"n" posting not allowed
"m" posting is moderated


def get_by_name(self, name):

        try:
            spec = self._dom.get('templates', {})[name]
        except KeyError:
            raise LagoMissingTemplateError(name, self._path)

        return Template(
            name=name,
            versions={
                ver_name: TemplateVersion(
                    name='%s:%s:%s' % (self.name, name, ver_name),
                    source=self._providers[ver_spec['source']],
                    handle=ver_spec['handle'],
                    timestamp=ver_spec['timestamp'],
                )
                for ver_name, ver_spec in spec['versions'].items()
            },
        )

Retrieve a template by it's name

Args:
name (str): Name of the template to retrieve

Raises:
LagoMissingTemplateError: if no template is found


def extend(self, name, opts, info):
    tifo = self.info.copy()
    tifo.update(info)
    topt = self.opts.copy()
    topt.update(opts)
    tobj = self.__class__(self.modl, name, tifo, topt)
    tobj.subof = self.name
    return tobj

Extend this type to construct a sub-type.

Args:
name (str): The name of the new sub-type.
opts (dict): The type options for the sub-type.
info (dict): The type info for the sub-type.

Returns:
(synapse.types.Type): A new sub-type instance.


def plot_to_svg(plot, width, height, unit=''):

    flipped_plot = [(x, -y) for x, y in plot]
    aspect_ratio = height / width
    view_box = calculate_view_box(flipped_plot, aspect_ratio=aspect_ratio)
    view_box_str = '{} {} {} {}'.format(*view_box)
    stroke_thickness = STROKE_THICKNESS * (view_box[2])

    svg = ET.Element('svg', attrib={
        'xmlns': 'http:
        'xmlns:inkscape': 'http:
        'width': '{}{}'.format(width, unit),
        'height': '{}{}'.format(height, unit),
        'viewBox': view_box_str})

    for i, layer in enumerate(flipped_plot):
        group = ET.SubElement(svg, 'g', attrib={
            'inkscape:label': '{}-layer'.format(i),
            'inkscape:groupmode': 'layer',
        })

        color = PLOT_COLORS[i % len(PLOT_COLORS)]
        ET.SubElement(group, 'path', attrib={
            'style': 'stroke-width: {}; stroke: {};'.format(stroke_thickness, color),
            'fill': 'none',
            'd': layer_to_path(layer)
        })

    try:
        return ET.tostring(svg, encoding='unicode')
    except LookupError:

        return ET.tostring(svg)

Converts a plot (list of layers) into an SVG document.

Args:
plot (list): list of layers that make up the plot
width (float): the width of the resulting image
height (float): the height of the resulting image
unit (str): the units of the resulting image if not pixels

Returns:
str: A stringified XML document representing the image


def _locate_element(dom, el_content, transformer=None):
    return dom.find(None, fn=utils.content_matchs(el_content, transformer))

Find element containing `el_content` in `dom`. Use `transformer` function
to content of all elements in `dom` in order to correctly transforming them
to match them with `el_content`.

Args:
dom (obj): HTMLElement tree.
el_content (str): Content of element will be picked from `dom`.
transformer (fn, default None): Transforming function.

Note:
`transformer` parameter can be for example simple lambda::

lambda x: x.strip()

Returns:
list: Matching HTMLElements.


def _parse_alt_title(html_chunk):

    title = html_chunk.find("img", fn=has_param("alt"))

    if not title:
        raise UserWarning("Can't find alternative title source!")

    return title[0].params["alt"].strip()

Parse title from alternative location if not found where it should be.

Args:
html_chunk (obj): HTMLElement containing slice of the page with details.

Returns:
str: Book's title.


def _set_default_torch_dtype(cls, dtype: torch.dtype) -> torch.dtype:
    if not dtype.is_floating_point:
        raise ValueError(f"Can't instantiate {cls.__name__} model under dtype={dtype} since it is not a floating point dtype")
    logger.info(f'Instantiating {cls.__name__} model under default dtype {dtype}.')
    dtype_orig = torch.get_default_dtype()
    torch.set_default_dtype(dtype)
    return dtype_orig

Change the default dtype and return the previous one. This is needed when wanting to instantiate the model
under specific dtype.

Args:
dtype (`torch.dtype`):
a floating dtype to set to.

Returns:
`torch.dtype`: the original `dtype` that can be used to restore `torch.set_default_dtype(dtype)` if it was
modified. If it wasn't, returns `None`.

Note `set_default_dtype` currently only works with floating-point types and asserts if for example,
`torch.int64` is passed. So if a non-float `dtype` is passed this functions will throw an exception.


def _ParseRecord(self, parser_mediator, file_object):
    header_record_offset = file_object.tell()
    token_type = self._ParseTokenType(file_object, header_record_offset)
    if (token_type not in self._HEADER_TOKEN_TYPES):
        raise errors.ParseError('Unsupported header token type: 0x{0:02x}'.format(token_type))
    (token_type, token_data) = self._ParseToken(file_object, header_record_offset)
    if (token_data.format_version != 11):
        raise errors.ParseError('Unsupported format version type: {0:d}'.format(token_data.format_version))
    timestamp = (token_data.microseconds + (token_data.timestamp * definitions.MICROSECONDS_PER_SECOND))
    event_type = token_data.event_type
    header_record_size = token_data.record_size
    record_end_offset = (header_record_offset + header_record_size)
    event_tokens = []
    return_token_values = None
    file_offset = file_object.tell()
    while (file_offset < record_end_offset):
        (token_type, token_data) = self._ParseToken(file_object, file_offset)
        if (not token_data):
            raise errors.ParseError('Unsupported token type: 0x{0:02x}'.format(token_type))
        file_offset = file_object.tell()
        if (token_type == self._TOKEN_TYPE_AUT_TRAILER):
            break
        token_type_string = self._TOKEN_TYPES.get(token_type, 'UNKNOWN')
        token_values = self._FormatTokenData(token_type, token_data)
        event_tokens.append({token_type_string: token_values})
        if (token_type in (self._TOKEN_TYPE_AUT_RETURN32, self._TOKEN_TYPE_AUT_RETURN64)):
            return_token_values = token_values
    if (token_data.signature != self._TRAILER_TOKEN_SIGNATURE):
        raise errors.ParseError('Unsupported signature in trailer token.')
    if (token_data.record_size != header_record_size):
        raise errors.ParseError('Mismatch of event record size between header and trailer token.')
    event_data = BSMEventData()
    event_data.event_type = event_type
    event_data.extra_tokens = event_tokens
    event_data.offset = header_record_offset
    event_data.record_length = header_record_size
    event_data.return_value = return_token_values
    date_time = dfdatetime_posix_time.PosixTimeInMicroseconds(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_CREATION)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses an event record.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): file-like object.

Raises:
ParseError: if the event record cannot be read.


def AllTypes():
    return [AssetType.CreditFlag, AssetType.DutyFlag, AssetType.GoverningToken, AssetType.UtilityToken, AssetType.Currency, AssetType.Share, AssetType.Invoice, AssetType.Token]

Get a list of all available asset types.

Returns:
list: of AssetType items.


def IsCompatible(self, allow_py3=False, raise_exception=False):
    error = None
    if not self.version:
        error = 'ERROR: Your current version of Python is not compatible with the Google Cloud SDK. {0}\n'.format(self.SupportedVersionMessage(allow_py3))
    elif self.version[0] < 3:
        if self.version < PythonVersion.MIN_REQUIRED_PY2_VERSION:
            error = 'ERROR: Python {0}.{1} is not compatible with the Google Cloud SDK. {2}\n'.format(self.version[0], self.version[1], self.SupportedVersionMessage(allow_py3))
    elif not allow_py3:
        error = 'ERROR: Python 3 and later is not compatible with the Google Cloud SDK. {0}\n'.format(self.SupportedVersionMessage(allow_py3))
    elif self.version < PythonVersion.MIN_SUPPORTED_PY3_VERSION:
        error = 'ERROR: Python {0}.{1} is not compatible with the Google Cloud SDK. {2}\n'.format(self.version[0], self.version[1], self.SupportedVersionMessage(allow_py3))
    if error:
        if raise_exception:
            raise Error(error)
        sys.stderr.write(error)
        sys.stderr.write(PythonVersion.ENV_VAR_MESSAGE)
        return False
    if self.version >= self.MIN_REQUIRED_PY2_VERSION and self.version < self.MIN_SUPPORTED_PY2_VERSION:
        sys.stderr.write('WARNING:  Python 2.6.x is no longer officially supported by the Google Cloud SDK\nand may not function correctly.  {0}\n{1}'.format(self.SupportedVersionMessage(allow_py3), PythonVersion.ENV_VAR_MESSAGE))
    return True

Ensure that the Python version we are using is compatible.

This will print an error message if not compatible.

Compatible versions are 2.6 and 2.7 and > 3.4 if allow_py3 is True.
We don't guarantee support for 2.6 so we want to warn about it.

Args:
allow_py3: bool, True if we should allow a Python 3 interpreter to run
gcloud. If False, this returns an error for Python 3.
raise_exception: bool, True to raise an exception rather than printing
the error and exiting.

Raises:
Error: If not compatible and raise_exception is True.

Returns:
bool, True if the version is valid, False otherwise.


def __init__(self, sbi_id: str):

        SchedulingObject.__init__(self, SBI_KEY, sbi_id)
        self._check_object_exists()

Create a SBI object.

Args:
sbi_id (str): SBI Identifier

Raises:
KeyError, if the specified SBI does not exist.


def reduce_sum(x,
               disable_positional_args=None,
               output_shape=None,
               reduced_dim=None,
               name=None):

  output_shape = convert_to_shape(output_shape)
  reduced_dim = convert_to_dimension(reduced_dim)
  assert disable_positional_args is None
  output_shape = _reduction_output_shape(x, output_shape, reduced_dim)
  if output_shape == x.shape:
    return x
  return ReduceOperation(x, output_shape, "SUM", name=name).outputs[0]

Reduction on 1 or more axes.

If reduced_dim is present, then only that dimension is reduced out.
Alternatively, specify output_shape.
Do not specify both reduced_dim and output_shape.
If neither is specified, then all dimensions are reduced out.

Args:
x: a Tensor
disable_positional_args: None
output_shape: an optional Shape.  Must be a subsequence of x.shape.
reduced_dim: a mtf.Dimension
name: an optional string
Returns:
a Tensor


def inspect(logdir='', event_file='', tag=''):
    print(((PRINT_SEPARATOR + 'Processing event files... (this can take a few minutes)\n') + PRINT_SEPARATOR))
    inspection_units = get_inspection_units(logdir, event_file, tag)
    for unit in inspection_units:
        if tag:
            print('Event statistics for tag {} in {}:'.format(tag, unit.name))
        else:
            print('These tags are in {}:'.format(unit.name))
            print_dict(get_unique_tags(unit.field_to_obs))
            print(PRINT_SEPARATOR)
            print('Event statistics for {}:'.format(unit.name))
        print_dict(get_dict_to_print(unit.field_to_obs), show_missing=(not tag))
        print(PRINT_SEPARATOR)

Main function for inspector that prints out a digest of event files.

Args:
logdir: A log directory that contains event files.
event_file: Or, a particular event file path.
tag: An optional tag name to query for.

Raises:
ValueError: If neither logdir and event_file are given, or both are given.


def generate_test_run_log_path(self):
    self._logger_start_time = logger.get_log_file_timestamp()
    self.root_output_path = os.path.join(self._log_dir, self._testbed_name, self._logger_start_time)
    return self.root_output_path

Geneartes the log path for a test run.

The log path includes a timestamp that is set in this call.

There is usually a minor difference between this timestamp and the actual
starting point of the test run. This is because the log path must be set
up *before* the test run actually starts, so all information of a test
run can be properly captured.

The generated value can be accessed via `self.root_output_path`.

Returns:
String, the generated log path.


def data_parallelism_from_flags(daisy_chain_variables=True, all_workers=False):
    dp_arg_names = inspect.getargspec(data_parallelism).args
    blacklist = ['daisy_chain_variables', 'all_workers']
    kwargs = {}
    for arg in dp_arg_names:
        if (arg in blacklist):
            continue
        kwargs[arg] = getattr(tf.flags.FLAGS, arg)
    return data_parallelism(daisy_chain_variables=daisy_chain_variables, all_workers=all_workers, **kwargs)

Over which devices do we split each training batch.

In old-fashioned async mode, we split the batch over all GPUs on the
current worker.

In sync mode, we split the batch over all the parameter server GPUs.

This function returns an expert_utils.Parallelism object, which can be used
to build the model.  It is configured in a way that any variables created
by `tf.get_variable` will be assigned to the parameter servers and shared
between datashards.

Args:
daisy_chain_variables: whether to copy variables in a daisy chain on GPUs.
all_workers: whether the devices are all async workers or just this one.

Returns:
a expert_utils.Parallelism.


def _parse_apps_to_ignore(self):
    apps_to_ignore = set()
    section_title = 'applications_to_ignore'
    if self._parser.has_section(section_title):
        apps_to_ignore = set(self._parser.options(section_title))
    return apps_to_ignore

Parse the applications to ignore in the config.

Returns:
set


def generate_workflow_description(self):

        if not self.tasks:
            raise WorkflowError('Workflow contains no tasks, and cannot be executed.')

        self.definition = self.workflow_skeleton()

        if self.batch_values:
            self.definition["batch_values"] = self.batch_values

        all_input_port_values = [t.inputs.__getattribute__(input_port_name).value for t in self.tasks for
                                 input_port_name in t.inputs._portnames]
        for task in self.tasks:

            output_multiplex_ports_to_exclude = []
            multiplex_output_port_names = [portname for portname in task.outputs._portnames if
                                           task.outputs.__getattribute__(portname).is_multiplex]
            for p in multiplex_output_port_names:
                output_port_reference = 'source:' + task.name + ':' + p
                if output_port_reference not in all_input_port_values:
                    output_multiplex_ports_to_exclude.append(p)

            task_def = task.generate_task_workflow_json(
                output_multiplex_ports_to_exclude=output_multiplex_ports_to_exclude)
            self.definition['tasks'].append(task_def)

        if self.callback:
            self.definition['callback'] = self.callback

        return self.definition

Generate workflow json for launching the workflow against the gbdx api

Args:
None

Returns:
json string


def MakePartialStat(self, fd):
    is_dir = ('Container' in fd.behaviours)
    return {'pathspec': fd.Get(fd.Schema.PATHSPEC, ''), 'st_atime': fd.Get(fd.Schema.LAST, 0), 'st_blksize': 0, 'st_blocks': 0, 'st_ctime': 0, 'st_dev': 0, 'st_gid': 0, 'st_ino': 0, 'st_mode': (self.default_dir_mode if is_dir else self.default_file_mode), 'st_mtime': 0, 'st_nlink': 0, 'st_rdev': 0, 'st_size': fd.Get(fd.Schema.SIZE, 0), 'st_uid': 0}

Try and give a 'stat' for something not in the data store.

Args:
fd: The object with no stat.

Returns:
A dictionary corresponding to what we'll say the 'stat' is
for objects which are not actually files, so have no OS level stat.


def db996(self, value=None):

        if value is not None:
            try:
                value = float(value)
            except ValueError:
                raise ValueError('value {} need to be of type float '
                                 'for field `db996`'.format(value))

        self._db996 = value

Corresponds to IDD Field `db996`
Dry-bulb temperature corresponding to 99.6% annual cumulative
frequency of occurrence (cold conditions)

Args:
value (float): value for IDD Field `db996`
Unit: C
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

Raises:
ValueError: if `value` is not a valid value


def assert_integer(x, message=None, name=None):
    with ops.name_scope(name, 'assert_integer', [x]):
        x = ops.convert_to_tensor(x, name='x')
        if not x.dtype.is_integer:
            if context.executing_eagerly():
                name = 'tensor'
            else:
                name = x.name
            err_msg = '%sExpected "x" to be integer type.  Found: %s of dtype %s' % (_message_prefix(message), name, x.dtype)
            raise TypeError(err_msg)
        return control_flow_ops.no_op('statically_determined_was_integer')

Assert that `x` is of integer dtype.

Example of adding a dependency to an operation:

```python
with tf.control_dependencies([tf.compat.v1.assert_integer(x)]):
output = tf.reduce_sum(x)
```

Args:
x: `Tensor` whose basetype is integer and is not quantized.
message: A string to prefix to the default message.
name: A name for this operation (optional).  Defaults to "assert_integer".

Raises:
TypeError:  If `x.dtype` is anything other than non-quantized integer.

Returns:
A `no_op` that does nothing.  Type can be determined statically.


def delete(self, paths):
    results = self._blobstorageIO().delete_paths(paths)
    exceptions = {path: error for path, error in results.items() if error is not None}
    if exceptions:
        raise BeamIOError('Delete operation failed', exceptions)

Deletes files or directories at the provided paths.
Directories will be deleted recursively.

Args:
paths: list of paths that give the file objects to be deleted

Raises:
``BeamIOError``: if any of the delete operations fail


def _make_token_async(scopes, service_account_id):
    rpc = app_identity.create_rpc()
    app_identity.make_get_access_token_call(rpc, scopes, service_account_id)
    (token, expires_at) = (yield rpc)
    raise ndb.Return((token, expires_at))

Get a fresh authentication token.

Args:
scopes: A list of scopes.
service_account_id: Internal-use only.

Raises:
An ndb.Return with a tuple (token, expiration_time) where expiration_time is
seconds since the epoch.


def FindCheckMacro(line):
    for macro in _CHECK_MACROS:
        i = line.find(macro)
        if (i >= 0):
            matched = Match((('^(.*\\b' + macro) + '\\s*)\\('), line)
            if (not matched):
                continue
            return (macro, len(matched.group(1)))
    return (None, (- 1))

Find a replaceable CHECK-like macro.

Args:
line: line to search on.
Returns:
(macro name, start position), or (None, -1) if no replaceable
macro is found.


def set_approvers(self, approver_ids=[], approver_group_ids=[], **kwargs):
    path = ('%s/%s/approvers' % (self._parent.manager.path, self._parent.get_id()))
    data = {'approver_ids': approver_ids, 'approver_group_ids': approver_group_ids}
    self.gitlab.http_put(path, post_data=data, **kwargs)

Change MR-level allowed approvers and approver groups.

Args:
approver_ids (list): User IDs that can approve MRs
approver_group_ids (list): Group IDs whose members can approve MRs

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabUpdateError: If the server failed to perform the request


def is_feature_enabled(self, feature_key, user_id, attributes=None):
    if (not self.is_valid):
        self.logger.error(enums.Errors.INVALID_DATAFILE.format('is_feature_enabled'))
        return False
    if (not validator.is_non_empty_string(feature_key)):
        self.logger.error(enums.Errors.INVALID_INPUT_ERROR.format('feature_key'))
        return False
    if (not isinstance(user_id, string_types)):
        self.logger.error(enums.Errors.INVALID_INPUT_ERROR.format('user_id'))
        return False
    if (not self._validate_user_inputs(attributes)):
        return False
    feature = self.config.get_feature_from_key(feature_key)
    if (not feature):
        return False
    feature_enabled = False
    source_info = {}
    decision = self.decision_service.get_variation_for_feature(feature, user_id, attributes)
    is_source_experiment = (decision.source == enums.DecisionSources.FEATURE_TEST)
    if decision.variation:
        if (decision.variation.featureEnabled is True):
            feature_enabled = True
        if is_source_experiment:
            source_info = {'experiment_key': decision.experiment.key, 'variation_key': decision.variation.key}
            self._send_impression_event(decision.experiment, decision.variation, user_id, attributes)
    if feature_enabled:
        self.logger.info(('Feature "%s" is enabled for user "%s".' % (feature_key, user_id)))
    else:
        self.logger.info(('Feature "%s" is not enabled for user "%s".' % (feature_key, user_id)))
    self.notification_center.send_notifications(enums.NotificationTypes.DECISION, enums.DecisionNotificationTypes.FEATURE, user_id, (attributes or {}), {'feature_key': feature_key, 'feature_enabled': feature_enabled, 'source': decision.source, 'source_info': source_info})
    return feature_enabled

Returns true if the feature is enabled for the given user.

Args:
feature_key: The key of the feature for which we are determining if it is enabled or not for the given user.
user_id: ID for user.
attributes: Dict representing user attributes.

Returns:
True if the feature is enabled for the user. False otherwise.


def add_c_function(self, c_func):
    self.ensure_initialized()
    pywrap_tfe.TFE_ContextAddFunction(self._handle, c_func)

Add a C API TF_Function to the context.

Once added, the function (identified by its name) can be executed like any
other operation.

Args:
c_func: A wrapped TF_Function (returned from TF_GraphToFunction_wrapper).


def _handle_emailauth(maildomain='', message=''):

        print('SteamGuard requires email authentication...')
        emailauth = input('Please enter the code sent to your mail address at "%s": ' % maildomain)
        emailauth.upper()
        return emailauth

Called when SteamGuard requires authentication via e-mail.
Asks the user to enter the code.

Args:
maildomain: Optional. The mail domain of the e-mail address the SteamGuard
code is send to.
message: Optional. A message from Steam service.

Returns:
A string containing the code.


def plot_tcoords(array, coords, scantypes=None, ax=None, **kwargs):

    if ax is None:
        ax = plt.gca()

    if scantypes is None:
        ax.plot(array[coords[0]], array[coords[1]], label='ALL', **kwargs)
    else:
        for scantype in scantypes:
            ax.plot(array[coords[0]][array.scantype == scantype],
                    array[coords[1]][array.scantype == scantype], label=scantype, **kwargs)
    ax.set_xlabel(coords[0])
    ax.set_ylabel(coords[1])
    ax.set_title('{} vs {}'.format(coords[1], coords[0]))
    ax.legend()

    logger.info('{} vs {} has been plotted.'.format(coords[1], coords[0]))

Plot coordinates related to the time axis.

Args:
array (xarray.DataArray): Array which the coodinate information is included.
coords (list): Name of x axis and y axis.
scantypes (list): Scantypes. If None, all scantypes are used.
ax (matplotlib.axes): Axis you want to plot on.
kwargs (optional): Plot options passed to ax.plot().


def cctop_submit(seq_str):

    url = 'http:
    r = requests.post(url)
    jobid = r.text.split('ID: ')[1]

    return jobid

Submit a protein sequence string to CCTOP and return the job ID.

Args:
seq_str (str): Protein sequence as a string

Returns:
dict: Job ID on the CCTOP server


def Uninstall(self, package_name, keep_data=False, timeout_ms=None):

        cmd = ['pm uninstall']
        if keep_data:
            cmd.append('-k')
        cmd.append('"%s"' % package_name)

        return self.Shell(' '.join(cmd), timeout_ms=timeout_ms)

Removes a package from the device.

Args:
package_name: Package name of target package.
keep_data: whether to keep the data and cache directories
timeout_ms: Expected timeout for pushing and installing.

Returns:
The pm uninstall output.


def latest_vcf_filename(build):

    ftp = FTP('ftp.ncbi.nlm.nih.gov')
    ftp.login()
    nav_to_vcf_dir(ftp, build=build)
    clinvar_datestamped = [f for f in ftp.nlst() if
                           re.match('^clinvar_[0-9]{8}.vcf.gz$', f)]
    if len(clinvar_datestamped) == 1:
        return clinvar_datestamped[0]
    raise IOError("Unable to determine the most recent ClinVar VCF file on " +
                  "NCBI's FTP site.")

Determine the filename for the most recent comprehensive ClinVar VCF.

Args:
build: (type: string) genome build, either 'b37' or 'b38'

Returns:
(type: string) Filename of the most recent comprehensive ClinVar VCF.


def __init__(self, report_job_id):

    super(AdManagerReportError, self).__init__(
        'Ad Manager report job failed. The ID of the failed report is: %s'
        % report_job_id)
    self.report_job_id = report_job_id

Initializes a AdManagerReportError.

Args:
report_job_id: The ID of the report job which failed.


def summarize_dist_params(dist, name, name_scope='dist_params'):
    with tf.compat.v1.name_scope(name_scope):
        tf.compat.v2.summary.histogram(name='{}/{}'.format(name, 'mean'), data=dist.mean(), step=tf.compat.v1.train.get_or_create_global_step())
        tf.compat.v2.summary.histogram(name='{}/{}'.format(name, 'stddev'), data=dist.stddev(), step=tf.compat.v1.train.get_or_create_global_step())

Summarize the parameters of a distribution.

Args:
dist: A Distribution object with mean and standard deviation
parameters.
name: The name of the distribution.
name_scope: The name scope of this summary.


def LateBind(self, target=None):

    if not issubclass(target, RDFProtoStruct):
      raise TypeError("Field %s expects a protobuf, but target is %s" %
                      (self, target))

    self.late_bound = False

    self.type = target

    self.owner.AddDescriptor(self)

Late binding callback.

This method is called on this field descriptor when the target RDFValue
class is finally defined. It gives the field descriptor an opportunity to
initialize after the point of definition.

Args:
target: The target nested class.

Raises:
TypeError: If the target class is not of the expected type.


def _original_path(self, path):

        def components_to_path():
            if len(path_components) > len(normalized_components):
                normalized_components.extend(
                    path_components[len(normalized_components):])
            sep = self._path_separator(path)
            normalized_path = sep.join(normalized_components)
            if path.startswith(sep) and not normalized_path.startswith(sep):
                normalized_path = sep + normalized_path
            return normalized_path

        if self.is_case_sensitive or not path:
            return path
        path_components = self._path_components(path)
        normalized_components = []
        current_dir = self.root
        for component in path_components:
            if not isinstance(current_dir, FakeDirectory):
                return components_to_path()
            dir_name, current_dir = self._directory_content(
                current_dir, component)
            if current_dir is None or (
                            isinstance(current_dir, FakeDirectory) and
                            current_dir._byte_contents is None and
                            current_dir.st_size == 0):
                return components_to_path()
            normalized_components.append(dir_name)
        return components_to_path()

Return a normalized case version of the given path for
case-insensitive file systems. For case-sensitive file systems,
return path unchanged.

Args:
path: the file path to be transformed

Returns:
A version of path matching the case of existing path elements.


def _read_marcxml(xml):

    marc_xml = _read_content_or_path(xml)

    marc_xml = _oai_to_xml(marc_xml)
    marc_xml = _add_namespace(marc_xml)

    file_obj = StringIO.StringIO(marc_xml)

    return ET.parse(file_obj)

Read MARC XML or OAI file, convert, add namespace and return XML in
required format with all necessities.

Args:
xml (str): Filename or XML string. Don't use ``\\n`` in case of
filename.

Returns:
obj: Required XML parsed with ``lxml.etree``.


def sg_max(tensor, opt):
    return tf.reduce_max(tensor, axis=opt.axis, keep_dims=opt.keep_dims, name=opt.name)

r"""Computes the maximum of elements across axis of a tensor.

See `tf.reduce_max()` in tensorflow.

Args:
tensor: A `Tensor` (automatically given by chain).
opt:
axis : A tuple/list of integers or an integer. The axis to reduce.
keep_dims: If true, retains reduced dimensions with length 1.
name: If provided, replace current tensor's name.

Returns:
A `Tensor`.


def get_permissions(self, namespace, explicit=False):

        if not isinstance(namespace, Namespace):
            namespace = Namespace(namespace)
        keys = namespace.keys
        p, _ = self._check(keys, self.index, explicit=explicit)
        return p

Returns the permissions level for the specified namespace

Arguments:

namespace -- permissioning namespace (str)
explicit -- require explicitly set permissions to the provided namespace

Returns:

int -- permissioning flags


def entry_point(__func: Callable) -> Callable:
    if (__func.__module__ == '__main__'):
        import sys
        sys.exit(__func())
    else:
        return __func

Execute function when module is run directly.

Note:
This allows fall through for importing modules that use it.

Args:
__func: Function to run


def _format_value(value):

  literal = repr(value)
  try:
    if parse_value(literal) == value:
      return literal
  except SyntaxError:
    pass
  return None

Returns `value` in a format parseable by `parse_value`, or `None`.

Simply put, This function ensures that when it returns a string value, the
following will hold:

parse_value(_format_value(value)) == value

Args:
value: The value to format.

Returns:
A string representation of `value` when `value` is literally representable,
or `None`.


def json(self, ondemand=False):

        self._request_entity = 'indicator'
        self._request_uri = '{}/{}'.format(self._api_uri, 'json')
        self._stream = True
        if ondemand:
            self._request.add_payload('runNow', True)

Update request URI to return JSON data.

For onDemand bulk generation to work it must first be enabled in the
ThreatConnect platform under System settings.

Args:
ondemand (boolean): Enable on demand bulk generation.


def get(self, accountID, **kwargs):
    request = Request('GET', '/v3/accounts/{accountID}/pricing')
    request.set_path_param('accountID', accountID)
    request.set_param('instruments', kwargs.get('instruments'))
    request.set_param('since', kwargs.get('since'))
    request.set_param('includeUnitsAvailable', kwargs.get('includeUnitsAvailable'))
    request.set_param('includeHomeConversions', kwargs.get('includeHomeConversions'))
    response = self.ctx.request(request)
    if (response.content_type is None):
        return response
    if (not response.content_type.startswith('application/json')):
        return response
    jbody = json.loads(response.raw_body)
    parsed_body = {}
    if (str(response.status) == '200'):
        if (jbody.get('prices') is not None):
            parsed_body['prices'] = [self.ctx.pricing.ClientPrice.from_dict(d, self.ctx) for d in jbody.get('prices')]
        if (jbody.get('homeConversions') is not None):
            parsed_body['homeConversions'] = [self.ctx.pricing.HomeConversions.from_dict(d, self.ctx) for d in jbody.get('homeConversions')]
        if (jbody.get('time') is not None):
            parsed_body['time'] = jbody.get('time')
    elif (str(response.status) == '400'):
        if (jbody.get('errorCode') is not None):
            parsed_body['errorCode'] = jbody.get('errorCode')
        if (jbody.get('errorMessage') is not None):
            parsed_body['errorMessage'] = jbody.get('errorMessage')
    elif (str(response.status) == '401'):
        if (jbody.get('errorCode') is not None):
            parsed_body['errorCode'] = jbody.get('errorCode')
        if (jbody.get('errorMessage') is not None):
            parsed_body['errorMessage'] = jbody.get('errorMessage')
    elif (str(response.status) == '404'):
        if (jbody.get('errorCode') is not None):
            parsed_body['errorCode'] = jbody.get('errorCode')
        if (jbody.get('errorMessage') is not None):
            parsed_body['errorMessage'] = jbody.get('errorMessage')
    elif (str(response.status) == '405'):
        if (jbody.get('errorCode') is not None):
            parsed_body['errorCode'] = jbody.get('errorCode')
        if (jbody.get('errorMessage') is not None):
            parsed_body['errorMessage'] = jbody.get('errorMessage')
    else:
        parsed_body = jbody
    response.body = parsed_body
    return response

Get pricing information for a specified list of Instruments within an
Account.

Args:
accountID:
Account Identifier
instruments:
List of Instruments to get pricing for.
since:
Date/Time filter to apply to the response. Only prices and home
conversions (if requested) with a time later than this filter
(i.e. the price has changed after the since time) will be
provided, and are filtered independently.
includeUnitsAvailable:
Flag that enables the inclusion of the unitsAvailable field in
the returned Price objects.
includeHomeConversions:
Flag that enables the inclusion of the homeConversions field in
the returned response. An entry will be returned for each
currency in the set of all base and quote currencies present in
the requested instruments list.

Returns:
v20.response.Response containing the results from submitting the
request


def recursepath(path, reverse=False):
    if (path in '/'):
        return ['/']
    path = (abspath(normpath(path)) + '/')
    paths = ['/']
    find = path.find
    append = paths.append
    pos = 1
    len_path = len(path)
    while (pos < len_path):
        pos = find('/', pos)
        append(path[:pos])
        pos += 1
    if reverse:
        return paths[::(- 1)]
    return paths

Get intermediate paths from the root to the given path.

Arguments:
path (str): A PyFilesystem path
reverse (bool): Reverses the order of the paths
(default `False`).

Returns:
list: A list of paths.

Example:
>>> recursepath('a/b/c')
['/', '/a', '/a/b', '/a/b/c']


def dispatch(op, args, kwargs):
    for dispatcher in getattr(op, FALLBACK_DISPATCH_ATTR):
        result = dispatcher.handle(args, kwargs)
        if result is not OpDispatcher.NOT_SUPPORTED:
            return result
    for dispatcher in _GLOBAL_DISPATCHERS:
        result = dispatcher.handle(op, args, kwargs)
        if result is not OpDispatcher.NOT_SUPPORTED:
            return result
    return OpDispatcher.NOT_SUPPORTED

Returns the result from the first successful dispatcher for a given op.

Calls the `handle` method of each `OpDispatcher` that has been registered
to handle `op`, and returns the value from the first successful handler.

Args:
op: Python function: the operation to dispatch for.
args: The arguments to the operation.
kwargs: They keyword arguments to the operation.

Returns:
The result of the operation, or `NOT_SUPPORTED` if no registered
dispatcher can handle the given arguments.


def DeregisterHelper(cls, analyzer_helper):
    if (analyzer_helper.type_indicator not in cls._analyzer_helpers):
        raise KeyError('Analyzer helper object not set for type indicator: {0:s}.'.format(analyzer_helper.type_indicator))
    analyzer_helper = cls._analyzer_helpers[analyzer_helper.type_indicator]
    cls._FlushCache(analyzer_helper.format_categories)
    del cls._analyzer_helpers[analyzer_helper.type_indicator]

Deregisters a format analyzer helper.

Args:
analyzer_helper (AnalyzerHelper): analyzer helper.

Raises:
KeyError: if analyzer helper object is not set for the corresponding
type indicator.


def Set(self, name, value):
    if (self.writeback is None):
        logging.warning('Attempting to modify a read only config object for %s.', name)
    if (name in self.constants):
        raise ConstModificationError(('Attempting to modify constant value %s' % name))
    writeback_data = self.writeback_data
    if (value is not None):
        if isinstance(value, Text):
            value = self.EscapeString(value)
    writeback_data[name] = value
    self.FlushCache()

Update the configuration option with a new value.

Note that this forces the value to be set for all contexts. The value is
written to the writeback location if Save() is later called.

Args:
name: The name of the parameter to set.
value: The value to set it to. The value will be validated against the
option's type descriptor.

Raises:
ConstModificationError: When attempting to change a constant option.


def set_log_prefix(self, prefix: str) -> None:
    self.debug('Setting the log prefix to "%s".', prefix)
    self.extra[PrefixLoggerAdapter.EXTRA_KEY_LOG_PREFIX] = prefix

Sets the log prefix to the given string.

Args:
prefix: The new log prefix.


def move_to_destination(source, destination, job_name, sagemaker_session):

    parsed_uri = urlparse(destination)
    if parsed_uri.scheme == 'file':
        recursive_copy(source, parsed_uri.path)
        final_uri = destination
    elif parsed_uri.scheme == 's3':
        bucket = parsed_uri.netloc
        path = "%s%s" % (parsed_uri.path.lstrip('/'), job_name)
        final_uri = 's3:
        sagemaker_session.upload_data(source, bucket, path)
    else:
        raise ValueError('Invalid destination URI, must be s3:

    shutil.rmtree(source)
    return final_uri

move source to destination. Can handle uploading to S3

Args:
source (str): root directory to move
destination (str): file:// or s3:// URI that source will be moved to.
job_name (str): SageMaker job name.
sagemaker_session (sagemaker.Session): a sagemaker_session to interact with S3 if needed

Returns:
(str): destination URI


def _has_connection(hostname, port):

    try:
        host = socket.gethostbyname(hostname)
        socket.create_connection((host, port), 2)
        return True
    except Exception:
        return False

Checks if internet connection exists to host via specified port.

If any exception is raised while trying to open a socket this will return
false.

Args:
hostname (str): Hostname to connect to.
port (int): Port to connect to

Returns:
bool: Has connection or not


def output(self, original_filename):

        for contract in self.contracts:
            for function in contract.functions + contract.modifiers:
                filename = "{}-{}-{}.dot".format(original_filename, contract.name, function.full_name)
                self.info('Export {}'.format(filename))
                function.slithir_cfg_to_dot(filename)

_filename is not used
Args:
_filename(string)


def save_yaml(dictionary, path, pretty=False, sortkeys=False):
    if sortkeys:
        dictionary = dict(dictionary)
    with open(path, 'w') as f:
        if pretty:
            pyaml.dump(dictionary, f)
        else:
            yaml.dump(dictionary, f, default_flow_style=None, Dumper=yamlloader.ordereddict.CDumper)

Save dictionary to YAML file preserving order if it is an OrderedDict

Args:
dictionary (Dict): Python dictionary to save
path (str): Path to YAML file
pretty (bool): Whether to pretty print. Defaults to False.
sortkeys (bool): Whether to sort dictionary keys. Defaults to False.

Returns:
None


def relative_probability( self, l1, l2, c1, c2 ):

        if self.site_energies:
            site_delta_E = self.site_energies[ l2 ] - self.site_energies[ l1 ]
        else:
            site_delta_E = 0.0
        if self.nn_energy:
            delta_nn = c2 - c1 - 1
            site_delta_E += delta_nn * self.nn_energy
        return metropolis( site_delta_E )

The relative probability for a jump between two sites with specific site types and coordination numbers.

Args:
l1 (Str): Site label for the initial site.
l2 (Str): Site label for the final site.
c1 (Int): Coordination number for the initial site.
c2 (Int): Coordination number for the final site.

Returns:
(Float): The relative probability of this jump occurring.


def from_numbers(cls, dna_values: List[Union[int, float, str]], dna_spec: DNASpec) -> 'DNA':
    context = dict(index=0)

    def _next_decision():
        if context['index'] >= len(dna_values):
            raise ValueError(f'The input {dna_values!r} is too short for {dna_spec!r}.')
        decision = dna_values[context['index']]
        context['index'] += 1
        return decision

    def _bind_decisions(dna_spec):
        value = None
        children = None
        if dna_spec.is_space:
            children = [_bind_decisions(elem) for elem in dna_spec.elements]
        elif dna_spec.is_categorical:
            if dna_spec.num_choices == 1:
                value = _next_decision()
                if value < 0 or value >= len(dna_spec.candidates):
                    raise ValueError(f"Candidate index out of range at choice '{dna_spec.name or dna_spec.id}'. Index={value}, Number of candidates={len(dna_spec.candidates)}.")
                children = [_bind_decisions(dna_spec.candidates[value])]
            else:
                children = [_bind_decisions(spec) for spec in dna_spec.choice_specs]
        else:
            value = _next_decision()
        return DNA(value, children, spec=dna_spec)
    dna = _bind_decisions(dna_spec)
    if context['index'] != len(dna_values):
        end_pos = context['index']
        raise ValueError(f'The input {dna_values!r} is too long for {dna_spec!r}. Remaining: {dna_values[end_pos:]!r}.')
    return dna

Create a DNA from a flattened list of dna values.

Args:
dna_values: A list of DNA values.
dna_spec: DNASpec that interprets the dna values.

Returns:
A DNA object.


def set_control_scheme(self, agent_name, control_scheme):

        if agent_name not in self.agents:
            print("No such agent %s" % agent_name)
        else:
            self.agents[agent_name].set_control_scheme(control_scheme)

Set the control scheme for a specific agent.

Args:
agent_name (str): The name of the agent to set the control scheme for.
control_scheme (int): A control scheme value (see :obj:`holodeck.agents.ControlSchemes`)


def _get_flags_defined_by_module(self, module):

    if not isinstance(module, str):
      module = module.__name__

    return list(self.flags_by_module_dict().get(module, []))

Returns the list of flags defined by a module.

Args:
module: module|str, the module to get flags from.

Returns:
[Flag], a new list of Flag instances.  Caller may update this list as
desired: none of those changes will affect the internals of this
FlagValue instance.


def create_alias(target_path, alias_path):
    if platform.system() == 'Windows' and (not alias_path.endswith('.lnk')):
        alias_path += '.lnk'
    if os.path.lexists(alias_path):
        os.remove(alias_path)
    if platform.system() == 'Windows':
        from win32com import client
        shell = client.Dispatch('WScript.Shell')
        shortcut = shell.CreateShortCut(alias_path)
        shortcut.Targetpath = target_path
        shortcut.save()
    else:
        os.symlink(target_path, alias_path)

Creates an alias at 'alias_path' pointing to the file 'target_path'.

On Unix, this is implemented via symlink. On Windows, this is done by
creating a Windows shortcut file.

Args:
target_path: Destination path that the alias should point to.
alias_path: Path at which to create the new alias.


def point_probability(self, threshold):
    point_prob = np.zeros(self.data.shape[1:])
    for t in range(self.data.shape[1]):
        point_prob[t] = np.where((self.data[(:, t)] >= threshold), 1.0, 0.0).mean(axis=0)
    return EnsembleConsensus(point_prob, 'point_probability', self.ensemble_name, self.run_date, (self.variable + '_{0:0.2f}_{1}'.format(threshold, self.units.replace(' ', '_'))), self.start_date, self.end_date, '')

Determine the probability of exceeding a threshold at a grid point based on the ensemble forecasts at
that point.

Args:
threshold: If >= threshold assigns a 1 to member, otherwise 0.

Returns:
EnsembleConsensus


def get_forced_variation(self, experiment, user_id):
    forced_variations = experiment.forcedVariations
    if (forced_variations and (user_id in forced_variations)):
        variation_key = forced_variations.get(user_id)
        variation = self.config.get_variation_from_key(experiment.key, variation_key)
        if variation:
            self.logger.info(('User "%s" is forced in variation "%s".' % (user_id, variation_key)))
        return variation
    return None

Determine if a user is forced into a variation for the given experiment and return that variation.

Args:
experiment: Object representing the experiment for which user is to be bucketed.
user_id: ID for the user.

Returns:
Variation in which the user with ID user_id is forced into. None if no variation.


def run(self, fn, args=(), kwargs=None, options=None):
    return super(CentralStorageStrategy, self).run(fn, args, kwargs, options)

Run `fn` on each replica, with the given arguments.

In `CentralStorageStrategy`, `fn` is  called on each of the compute
replicas, with the provided "per replica" arguments specific to that device.

Args:
fn: The function to run. The output must be a `tf.nest` of `Tensor`s.
args: (Optional) Positional arguments to `fn`.
kwargs: (Optional) Keyword arguments to `fn`.
options: (Optional) An instance of `tf.distribute.RunOptions` specifying
the options to run `fn`.

Returns:
Return value from running `fn`.


def get_if_not_set(self, addresses):

        with self._lock:
            results = []
            for add in addresses:
                results.append(self._get_if_not_set(add))
            return results

Returns the value at an address if it was an input to the txn but
never set. It returns None if that address was never set in the
merkle database, or if the address is not within the context.

Args:
addresses (list of str): The full 70 character addresses.

Returns:
(list): bytes at that address but not set within the context


def _OpenFileObject(self, path_spec):

    if not path_spec.HasParent():
      raise errors.PathSpecError(
          'Unsupported path specification without parent.')

    resolver.Resolver.key_chain.ExtractCredentialsFromPathSpec(path_spec)

    file_object = resolver.Resolver.OpenFileObject(
        path_spec.parent, resolver_context=self._resolver_context)
    bde_volume = pybde.volume()

    bde.BDEVolumeOpen(
        bde_volume, path_spec, file_object, resolver.Resolver.key_chain)
    return bde_volume

Opens the file-like object defined by path specification.

Args:
path_spec (PathSpec): path specification.

Returns:
pyvde.volume: BDE volume file-like object.

Raises:
PathSpecError: if the path specification is incorrect.


def generate_output_newline(self, line='0', colorize=True):

        return generate_output(
            line=line,
            is_parent=True,
            colorize=colorize
        )

The function for generating a CLI output new line.

Args:
line (:obj:`str`): The line number (0-4). Determines indentation.
Defaults to '0'.
colorize (:obj:`bool`): Colorize the console output with ANSI
colors. Defaults to True.

Returns:
str: The generated output.


def _fix(node):
    pri_cfg = cfg.CFG.build_cfg(node.body[0])
    defined = cfg.Defined()
    defined.visit(pri_cfg.entry)
    reaching = cfg.ReachingDefinitions()
    reaching.visit(pri_cfg.entry)
    cfg.forward(node.body[1], cfg.Defined())
    cfg.forward(node.body[1], cfg.ReachingDefinitions())
    fixes.CleanStack().visit(node)
    fixes.FixStack().visit(node.body[0])
    fixes.CleanGrad().visit(node.body[1])
    fixes.FixGrad().visit(node.body[1])
    return (node, defined.exit, reaching.exit)

Fix the naive construction of the adjont.

See `fixes.py` for details.

This function also returns the result of reaching definitions analysis so
that `split` mode can use this to carry over the state from primal to
adjoint.

Args:
node: A module with the primal and adjoint function definitions as returned
by `reverse_ad`.

Returns:
node: A module with the primal and adjoint function with additional
variable definitions and such added so that pushes onto the stack and
gradient accumulations are all valid.
defined: The variables defined at the end of the primal.
reaching: The variable definitions that reach the end of the primal.


def dump(self):
    reading = self.reading
    if (reading is not None):
        reading = reading.asdict()
    return {u'selector': str(self.selector), u'reading': reading}

Serialize the state of this stream walker.

Returns:
dict: The serialized state.


def can_fetch(self, request: Request, file=None) -> bool:

        try:
            return self.can_fetch_pool(request)
        except NotInPoolError:
            pass

        yield from self.fetch_robots_txt(request, file=file)

        return self.can_fetch_pool(request)

Return whether the request can fetched.

Args:
request: Request.
file: A file object to where the robots.txt contents are written.

Coroutine.


def __init__(self, code, error, content, message=None):

    super(AdWordsReportError, self).__init__(
        message if message else ('AdWords report download failed with HTTP '
                                 'status code: %s' % code))
    self.code = code
    self.error = error
    self.content = content

Initializes an AdWordsReportError.

Args:
code: The HTTP status code number that was returned.
error: The urllib2.HTTPError (Python 2) or urllib.error.HTTPError
(Python 3) describing the failure.
content: The HTTP response body as a string.
[optional]
message: A user-friendly error message string. If one is not provided, a
default message will be used.


def wait_for_notification(self, notification_class=BaseNotification):
    if notification_class:
        if (notification_class is BaseNotification):
            message = 'No notification was shown.'
        else:
            message = '{0} was not shown.'.format(notification_class.__name__)
        self.wait.until((lambda _: isinstance(self.notification, notification_class)), message=message)
        return self.notification
    else:
        self.wait.until((lambda _: (self.notification is None)), message='Unexpected notification shown.')

Wait for the specified notification to be displayed.

Args:
notification_class (:py:class:`BaseNotification`, optional):
The notification class to wait for. If `None` is specified it
will wait for any notification to be closed. Defaults to
`BaseNotification`.

Returns:
:py:class:`BaseNotification`: Firefox notification.


def rescale_data(data, data_min, data_max, out_min=0.0, out_max=100.0):
    return ((((out_max - out_min) / (data_max - data_min)) * (data - data_min)) + out_min)

Rescale your input data so that is ranges over integer values, which will perform better in the watershed.

Args:
data: 2D or 3D ndarray being rescaled
data_min: minimum value of input data for scaling purposes
data_max: maximum value of input data for scaling purposes
out_min: minimum value of scaled data
out_max: maximum value of scaled data

Returns:
Linearly scaled ndarray


Collects the analyses cases to be run and launches processes for each of
them.

Args:
run_type: A string representation of the run type (eg. verification)
module: The module corresponding to the run.  Must have a run_suite function
config: The configuration for the module


def _feed_to_dict(self, parse=True):
    if not self.raw_feed:
        return None
    result = []
    header = self.raw_feed[0]
    for line in self.raw_feed[1:]:
        if line and ''.join(line):
            i = 0
            item = {}
            for index, column_header in enumerate(header):
                if index < len(line):
                    item[column_header] = self._parse_value(line[index].strip()) if parse else line[index].strip()
                else:
                    item[column_header] = ''
            result.append(item)
        else:
            break
    return result

Turns a raw feed from Google Sheets into a list of dictionaries.

Args:
raw_feed: List of list of strings representing the feed from Google
Sheets.

Returns:
List of dictionaries with the data from the feed


def _add_to_schema(self, field_name, schema):

        super(ForeignKeyField, self)._add_to_schema(field_name, schema)

        if self.get_field_value('convert_fks', default=True):
            self.attribute = field_name.replace('_id', '')

Set the ``attribute`` attr to the field in question so this always
gets deserialzed into the field name without ``_id``.

Args:
field_name (str): The name of the field (the attribute name being
set in the schema).
schema (marshmallow.Schema): The actual parent schema this field
belongs to.


def write_entry_to_file(file_descriptor, entry_comment, entry_key):
    escaped_key = re.sub('([^\\\\])"', '\\1\\"', entry_key)
    file_descriptor.write((u'\n' % entry_comment))
    file_descriptor.write((u'"%s" = "%s";\n' % (escaped_key, escaped_key)))

Writes a localization entry to the file

Args:
file_descriptor (file, instance): The file to write the entry to.
entry_comment (str): The entry's comment.
entry_key (str): The entry's key.


def _validate_config(config):
    required_keys = [KEY_ADDRESS, KEY_MODEL, KEY_PORT, KEY_PATHS]
    for key in required_keys:
        if key not in config:
            raise Error('Required key %s missing from config %s', (key, config))

Verifies that a config dict for an attenuator device is valid.

Args:
config: A dict that is the configuration for an attenuator device.

Raises:
attenuator.Error: A config is not valid.


def checkCoordinatedReadGroups(self, results, num_consumers):
    groups = [results[start:start + num_consumers] for start in range(0, len(results), num_consumers)]
    incorrect_groups = []
    for group in groups:
        for offset in range(1, len(group)):
            if group[0] + offset != group[offset]:
                incorrect_groups.append(group)
                break
    self.assertEmpty(incorrect_groups, 'Incorrect groups: {}.\nAll groups: {}'.format(incorrect_groups, groups))

Validates results from a `make_coordinted_read_dataset` dataset.

Each group of `num_consumers` results should be consecutive, indicating that
they were produced by the same worker.

Args:
results: The elements produced by the dataset.
num_consumers: The number of consumers.


def task_ids(self):

        if not self.id:
            raise WorkflowError('Workflow is not running.  Cannot get task IDs.')

        if self.batch_values:
            raise NotImplementedError("Query Each Workflow Id within the Batch Workflow for task IDs.")

        wf = self.workflow.get(self.id)

        return [task['id'] for task in wf['tasks']]

Get the task IDs of a running workflow

Args:
None

Returns:
List of task IDs


def module_help(self, module):

    helplist = []
    self._render_our_module_key_flags(module, helplist)
    return '\n'.join(helplist)

Describes the key flags of a module.

Args:
module: module|str, the module to describe the key flags for.

Returns:
str, describing the key flags of a module.


def _get_nan_block_id(partition_class, n_row=1, n_col=1, transpose=False):

    global _NAN_BLOCKS
    if transpose:
        n_row, n_col = n_col, n_row
    shape = (n_row, n_col)
    if shape not in _NAN_BLOCKS:
        arr = np.tile(np.array(np.NaN), shape)

        _NAN_BLOCKS[shape] = partition_class.put(pandas.DataFrame(data=arr))
    return _NAN_BLOCKS[shape]

A memory efficient way to get a block of NaNs.

Args:
partition_class (BaseFramePartition): The class to use to put the object
in the remote format.
n_row(int): The number of rows.
n_col(int): The number of columns.
transpose(bool): If true, swap rows and columns.
Returns:
ObjectID of the NaN block.


def forward(self, input):

        sl,bs = input.size()
        if bs!=self.bs:
            self.bs=bs
            self.reset()
        with set_grad_enabled(self.training):
            emb = self.encoder_with_dropout(input, dropout=self.dropoute if self.training else 0)
            emb = self.dropouti(emb)
            raw_output = emb
            new_hidden,raw_outputs,outputs = [],[],[]
            for l, (rnn,drop) in enumerate(zip(self.rnns, self.dropouths)):
                current_input = raw_output
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    raw_output, new_h = rnn(raw_output, self.hidden[l])
                new_hidden.append(new_h)
                raw_outputs.append(raw_output)
                if l != self.n_layers - 1: raw_output = drop(raw_output)
                outputs.append(raw_output)

            self.hidden = repackage_var(new_hidden)
        return raw_outputs, outputs

Invoked during the forward propagation of the RNN_Encoder module.
Args:
input (Tensor): input of shape (sentence length x batch_size)

Returns:
raw_outputs (tuple(list (Tensor), list(Tensor)): list of tensors evaluated from each RNN layer without using
dropouth, list of tensors evaluated from each RNN layer using dropouth,


def _get_value(self, scalar_data_blob, dtype_enum):

    tensorflow_dtype = tf.DType(dtype_enum)
    buf = np.frombuffer(scalar_data_blob, dtype=tensorflow_dtype.as_numpy_dtype)
    return np.asscalar(buf)

Obtains value for scalar event given blob and dtype enum.

Args:
scalar_data_blob: The blob obtained from the database.
dtype_enum: The enum representing the dtype.

Returns:
The scalar value.


def cache_json(filename):

    def cache_decorator(cacheable_function):
        @wraps(cacheable_function)
        def cache_wrapper(*args, **kwargs):
            path = CACHE_DIRECTORY + filename
            check_create_folder(path)
            if os.path.exists(path):
                with open(path) as infile:
                    return json.load(infile)
            else:
                function_output = cacheable_function(*args, **kwargs)
                with open(path, 'w') as outfile:
                    json.dump(function_output, outfile)
                return function_output
        return cache_wrapper
    return cache_decorator

Caches the JSON-serializable output of the function to a given file

Args:
filename (str) The filename (sans directory) to store the output

Returns: decorator, applicable to a function that produces JSON-serializable output


def imread(img_or_path, flag='color'):

    if isinstance(img_or_path, np.ndarray):
        return img_or_path
    elif is_str(img_or_path):
        flag = imread_flags[flag] if is_str(flag) else flag
        check_file_exist(img_or_path,
                         'img file does not exist: {}'.format(img_or_path))
        return cv2.imread(img_or_path, flag)
    else:
        raise TypeError('"img" must be a numpy array or a filename')

Read an image.

Args:
img_or_path (ndarray or str): Either a numpy array or image path.
If it is a numpy array (loaded image), then it will be returned
as is.
flag (str): Flags specifying the color type of a loaded image,
candidates are `color`, `grayscale` and `unchanged`.

Returns:
ndarray: Loaded image array.


def get_unique_directives(ast):

    if not ast.directives:
        return dict()

    result = dict()
    for directive_obj in ast.directives:
        directive_name = directive_obj.name.value
        if directive_name in ALLOWED_DUPLICATED_DIRECTIVES:
            pass
        elif directive_name in result:
            raise GraphQLCompilationError(u'Directive was unexpectedly applied twice in the same '
                                          u'location: {} {}'.format(directive_name, ast.directives))
        else:
            result[directive_name] = directive_obj

    return result

Return a dict of directive name to directive object for the given AST node.

Any directives that are allowed to exist more than once on any AST node are ignored.
For any directives that can only exist up to once, we verify that they are not duplicated
raising GraphQLCompilationError in case we find them more than once on the AST node.

Args:
ast: GraphQL AST node, obtained from the graphql library

Returns:
dict of string to directive object


def do_put(endpoint, body, access_token):

    headers = {"content-type": "application/json", "Authorization": 'Bearer ' + access_token}
    headers['User-Agent'] = get_user_agent()
    return requests.put(endpoint, data=body, headers=headers)

Do an HTTP PUT request and return JSON.

Args:
endpoint (str): Azure Resource Manager management endpoint.
body (str): JSON body of information to put.
access_token (str): A valid Azure authentication token.

Returns:
HTTP response. JSON body.


def get_quats(self) -> torch.Tensor:
    if self._rot_mats is not None:
        return rot_to_quat(self._rot_mats)
    elif self._quats is not None:
        return self._quats
    else:
        raise ValueError('Both rotations are None')

Returns the underlying rotation as a quaternion tensor.

Depending on whether the Rotation was initialized with a quaternion, this function may call torch.linalg.eigh.

Returns:
The rotation as a quaternion tensor.


def __call__(self, context):

    context._counters.increment(self.counter_name, self.delta)

Execute operation.

Args:
context: mapreduce context as context.Context.


def instance_default(self, obj):
    return self.property.themed_default(obj.__class__, self.name, obj.themed_values())

Get the default value that will be used for a specific instance.

Args:
obj (HasProps) : The instance to get the default value for.

Returns:
object


def create(self, subject, displayName, issuerToken, expiration, secret):
    check_type(subject, basestring)
    check_type(displayName, basestring)
    check_type(issuerToken, basestring)
    check_type(expiration, basestring)
    check_type(secret, basestring)
    payload = {'sub': subject, 'name': displayName, 'iss': issuerToken, 'exp': expiration}
    key = base64.b64decode(secret)
    jwt_token = jwt.encode(payload, key, algorithm='HS256')
    url = (((self._session.base_url + API_ENDPOINT) + '/') + 'login')
    headers = {'Authorization': ('Bearer ' + jwt_token.decode('utf-8'))}
    response = requests.post(url, headers=headers)
    check_response_code(response, EXPECTED_RESPONSE_CODE['GET'])
    return self._object_factory(OBJECT_TYPE, response.json())

Create a new guest issuer using the provided issuer token.

This function returns a guest issuer with an api access token.

Args:
subject(basestring): Unique and public identifier
displayName(basestring): Display Name of the guest user
issuerToken(basestring): Issuer token from developer hub
expiration(basestring): Expiration time as a unix timestamp
secret(basestring): The secret used to sign your guest issuers

Returns:
GuestIssuerToken: A Guest Issuer with a valid access token.

Raises:
TypeError: If the parameter types are incorrect
ApiError: If the webex teams cloud returns an error.


def register_read_multiple(self, register_indices):

        num_regs = len(register_indices)
        buf = (ctypes.c_uint32 * num_regs)(*register_indices)
        data = (ctypes.c_uint32 * num_regs)(0)

        statuses = (ctypes.c_uint8 * num_regs)(0)

        res = self._dll.JLINKARM_ReadRegs(buf, data, statuses, num_regs)
        if res < 0:
            raise errors.JLinkException(res)

        return list(data)

Retrieves the values from the registers specified.

Args:
self (JLink): the ``JLink`` instance
register_indices (list): list of registers to read

Returns:
A list of values corresponding one-to-one for each of the given
register indices.  The returned list of values are the values in
order of which the indices were specified.

Raises:
JLinkException: if a given register is invalid or an error occurs.


def _VerifyGradient(self, pool_func, pool_grad_func, input_sizes, ksize, strides, padding, pool_grad_grad_func=None):
    ksize = [1] + ksize + [1]
    strides = [1] + strides + [1]
    total_size = np.prod(input_sizes)
    x = np.arange(1, total_size + 1, dtype=np.float32).reshape(input_sizes)
    with self.session() as sess:
        with ops.device('CPU'):
            inputs = array_ops.placeholder(dtypes.float32, shape=input_sizes)
            outputs = pool_func(inputs, ksize=ksize, strides=strides, padding=padding)
        output_vals = np.array(sess.run(outputs, {inputs: x}))
        output_gradient_vals = np.arange(1, output_vals.size + 1, dtype=np.float32)
        output_gradient_vals = output_gradient_vals.reshape(output_vals.shape)
        output_grad_grad_vals = np.arange(1, x.size + 1, dtype=np.float32)
        output_grad_grad_vals = output_grad_grad_vals.reshape(x.shape)
        with ops.device('CPU'):
            output_gradients = array_ops.placeholder(dtypes.float32, shape=output_vals.shape)
            expected_input_gradients = pool_grad_func(inputs, outputs, output_gradients, ksize=ksize, strides=strides, padding=padding)
            expected_input_gradient_vals = sess.run(expected_input_gradients, {inputs: x, output_gradients: output_gradient_vals})
            output_grad_gradients = array_ops.placeholder(dtypes.float32, shape=expected_input_gradient_vals.shape)
            if pool_grad_grad_func is not None:
                expected_grad_gradients = pool_grad_grad_func(inputs, outputs, output_grad_gradients, ksize=ksize, strides=strides, padding=padding, data_format='NDHWC')
                expected_grad_gradients_vals = sess.run(expected_grad_gradients, {inputs: x, output_grad_gradients: output_grad_grad_vals})
        with self.test_scope():
            outputs = array_ops.placeholder(dtypes.float32, shape=output_vals.shape)
            actual_input_gradients = pool_grad_func(inputs, outputs, output_gradients, ksize=ksize, strides=strides, padding=padding)
            if pool_grad_grad_func is not None:
                actual_grad_gradients = pool_grad_grad_func(inputs, outputs, output_grad_gradients, ksize=ksize, strides=strides, padding=padding, data_format='NDHWC')
        actual = sess.run(actual_input_gradients, {inputs: x, outputs: output_vals, output_gradients: output_gradient_vals})
        self.assertAllClose(expected_input_gradient_vals.flatten(), actual.flatten(), rtol=1e-05, atol=1e-06)
        self.assertShapeEqual(actual, inputs)
        if pool_grad_grad_func is not None:
            actual_grad_gradients_vals = sess.run(actual_grad_gradients, {inputs: x, outputs: output_vals, output_grad_gradients: output_grad_grad_vals})
            self.assertAllClose(expected_grad_gradients_vals, actual_grad_gradients_vals, rtol=0.0001, atol=1e-06)
            self.assertShapeEqual(actual_grad_gradients_vals, outputs)

Verifies the output values of the pooling gradient function.

Args:
pool_func: Forward pooling function
pool_grad_func: Pooling gradient function for pool_grad_func
input_sizes: Input tensor dimensions.
ksize: The kernel size dimensions
strides: The stride dimensions
padding: Padding type.
pool_grad_grad_func: Second-order gradient function, if available.


def render(self, time: float, frame_time: float):

        self.example.render(time, frame_time)

Renders the assigned example

Args:
time (float): Current time in seconds
frame_time (float): Delta time from last frame in seconds


def median(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs):

        axis = self._get_axis_number(axis) if axis is not None else 0
        if numeric_only is not None and not numeric_only:
            self._validate_dtypes(numeric_only=True)
        return self._reduce_dimension(
            self._query_compiler.median(
                axis=axis,
                skipna=skipna,
                level=level,
                numeric_only=numeric_only,
                **kwargs
            )
        )

Computes median across the DataFrame.

Args:
axis (int): The axis to take the median on.
skipna (bool): True to skip NA values, false otherwise.

Returns:
The median of the DataFrame. (Pandas series)


def parse_row(schema, data):

    def parse_value(data_type, value):

      if value is not None:
        if value == 'null':
          value = None
        elif data_type == 'INTEGER':
          value = int(value)
        elif data_type == 'FLOAT':
          value = float(value)
        elif data_type == 'TIMESTAMP':
          value = datetime.datetime.utcfromtimestamp(float(value))
        elif data_type == 'BOOLEAN':
          value = value == 'true'
        elif (type(value) != str):

          value = str(value)
      return value

    row = {}
    if data is None:
      return row

    for i, (field, schema_field) in enumerate(zip(data['f'], schema)):
      val = field['v']
      name = schema_field['name']
      data_type = schema_field['type']
      repeated = True if 'mode' in schema_field and schema_field['mode'] == 'REPEATED' else False

      if repeated and val is None:
        row[name] = []
      elif data_type == 'RECORD':
        sub_schema = schema_field['fields']
        if repeated:
          row[name] = [Parser.parse_row(sub_schema, v['v']) for v in val]
        else:
          row[name] = Parser.parse_row(sub_schema, val)
      elif repeated:
        row[name] = [parse_value(data_type, v['v']) for v in val]
      else:
        row[name] = parse_value(data_type, val)

    return row

Parses a row from query results into an equivalent object.

Args:
schema: the array of fields defining the schema of the data.
data: the JSON row from a query result.
Returns:
The parsed row object.


def PrintExtractionStatusHeader(self, processing_status):

    self._output_writer.Write(
        'Source path\t\t: {0:s}\n'.format(self._source_path))
    self._output_writer.Write(
        'Source type\t\t: {0:s}\n'.format(self._source_type))

    if self._artifact_filters:
      artifacts_string = ', '.join(self._artifact_filters)
      self._output_writer.Write('Artifact filters\t: {0:s}\n'.format(
          artifacts_string))
    if self._filter_file:
      self._output_writer.Write('Filter file\t\t: {0:s}\n'.format(
          self._filter_file))

    self._PrintProcessingTime(processing_status)
    self._PrintTasksStatus(processing_status)
    self._output_writer.Write('\n')

Prints the extraction status header.

Args:
processing_status (ProcessingStatus): processing status.


def populate_native_libraries(version):

    with open(BINARY_EXT_TEMPLATE, "r") as file_obj:
        template = file_obj.read()
    contents = template.format(revision=version)
    with open(BINARY_EXT_FILE, "w") as file_obj:
        file_obj.write(contents)

Populates ``binary-extension.rst`` with release-specific data.

Args:
version (str): The current version.


def _wait_for_and_process_task(self, task):
    function_descriptor = FunctionDescriptor.from_bytes_list(task.function_descriptor_list())
    driver_id = task.driver_id()
    if (not task.actor_creation_id().is_nil()):
        assert self.actor_id.is_nil()
        self.actor_id = task.actor_creation_id()
        self.actor_creation_task_id = task.task_id()
        actor_class = self.function_actor_manager.load_actor_class(driver_id, function_descriptor)
        self.actors[self.actor_id] = actor_class.__new__(actor_class)
        self.actor_checkpoint_info[self.actor_id] = ActorCheckpointInfo(num_tasks_since_last_checkpoint=0, last_checkpoint_timestamp=int((1000 * time.time())), checkpoint_ids=[])
    execution_info = self.function_actor_manager.get_execution_info(driver_id, function_descriptor)
    function_name = execution_info.function_name
    extra_data = {'name': function_name, 'task_id': task.task_id().hex()}
    if task.actor_id().is_nil():
        if task.actor_creation_id().is_nil():
            title = 'ray_worker:{}()'.format(function_name)
            next_title = 'ray_worker'
        else:
            actor = self.actors[task.actor_creation_id()]
            title = 'ray_{}:{}()'.format(actor.__class__.__name__, function_name)
            next_title = 'ray_{}'.format(actor.__class__.__name__)
    else:
        actor = self.actors[task.actor_id()]
        title = 'ray_{}:{}()'.format(actor.__class__.__name__, function_name)
        next_title = 'ray_{}'.format(actor.__class__.__name__)
    with profiling.profile('task', extra_data=extra_data):
        with _changeproctitle(title, next_title):
            self._process_task(task, execution_info)
        self.task_context.current_task_id = TaskID.nil()
        self.task_context.task_index = 0
        self.task_context.put_index = 1
        if self.actor_id.is_nil():
            self.task_driver_id = DriverID.nil()
            ray_signal.reset()
    self.function_actor_manager.increase_task_counter(driver_id, function_descriptor)
    reached_max_executions = (self.function_actor_manager.get_task_counter(driver_id, function_descriptor) == execution_info.max_calls)
    if reached_max_executions:
        self.raylet_client.disconnect()
        sys.exit(0)

Wait for a task to be ready and process the task.

Args:
task: The task to execute.


def split_arg_into_blocks(block_dims, block_dims_fn, arg, axis=-1):
    block_sizes = [dim.value for dim in block_dims]
    if any((d is None for d in block_sizes)):
        block_sizes = block_dims_fn()
    return array_ops.split(arg, block_sizes, axis=axis)

Split `x` into blocks matching `operators`'s `domain_dimension`.

Specifically, if we have a blockwise lower-triangular matrix, with block
sizes along the diagonal `[M_j, M_j] j = 0,1,2..J`,  this method splits `arg`
on `axis` into `J` tensors, whose shape at `axis` is `M_j`.

Args:
block_dims: Iterable of `TensorShapes`.
block_dims_fn: Callable returning an iterable of `Tensor`s.
arg: `Tensor`. `arg` is split into `J` tensors.
axis: Python `Integer` representing the axis to split `arg` on.

Returns:
A list of `Tensor`s.


def __get__(self, instance, owner):

        if not instance and owner:
            return self

        value = self._cache.get(instance) if self._cache.get(instance) is not None else self.default

        if hasattr(instance, 'prepare_' + self.alias):
            return getattr(instance, 'prepare_' + self.alias)(value)

        return value

Python descriptor protocol `__get__` magic method.

Args:
instance(object): The instance with descriptor attribute.
owner(object): Instance class.

Returns:
The cached value for the class instance or None.


def annotate(self, records, **kwargs):
    self.annotator_params.update(**kwargs)
    chunk_size = self.annotator_params.get('chunk_size', self.CHUNK_SIZE)
    chunk = []
    for (i, record) in enumerate(records):
        chunk.append(record)
        if (((i + 1) % chunk_size) == 0):
            for r in self._execute(chunk):
                (yield r)
            chunk = []
    if chunk:
        for r in self._execute(chunk):
            (yield r)
        chunk = []

Annotate a set of records with stored fields.

Args:
records: A list or iterator (can be a Query object)
chunk_size: The number of records to annotate at once (max 500).

Returns:
A generator that yields one annotated record at a time.


def get_jwt_dict(jwt_bu64):

    jwt_tup = get_jwt_tup(jwt_bu64)
    try:
        jwt_dict = json.loads(jwt_tup[0].decode('utf-8'))
        jwt_dict.update(json.loads(jwt_tup[1].decode('utf-8')))
        jwt_dict['_sig_sha1'] = hashlib.sha1(jwt_tup[2]).hexdigest()
    except TypeError as e:
        raise JwtException('Decode failed. error="{}"'.format(e))
    return jwt_dict

Parse Base64 encoded JWT and return as a dict.

- JWTs contain a set of values serialized to a JSON dict. This decodes the JWT and
returns it as a dict containing Unicode strings.
- In addition, a SHA1 hash is added to the dict for convenience.

Args:
jwt_bu64: bytes
JWT, encoded using a a URL safe flavor of Base64.

Returns:
dict: Values embedded in and derived from the JWT.


def _release(self, lease):
    if lease.exist:
        os.unlink(lease.path)
        LOGGER.debug('Removed subnet lease {}'.format(lease.path))

Free the given lease

Args:
lease (lago.subnet_lease.Lease): The lease to free


def _MergeSameId(self):
    a_not_merged = []
    b_not_merged = []
    for a in self._GetIter(self.feed_merger.a_schedule):
        try:
            b = self._GetById(self.feed_merger.b_schedule, self._GetId(a))
        except KeyError:
            a_not_merged.append(a)
            continue
        try:
            self._Add(a, b, self._MergeEntities(a, b))
            self._num_merged += 1
        except MergeError as merge_error:
            a_not_merged.append(a)
            b_not_merged.append(b)
            self._ReportSameIdButNotMerged(self._GetId(a), merge_error)
    for b in self._GetIter(self.feed_merger.b_schedule):
        try:
            a = self._GetById(self.feed_merger.a_schedule, self._GetId(b))
        except KeyError:
            b_not_merged.append(b)
    for a in a_not_merged:
        newid = self._HasId(self.feed_merger.b_schedule, self._GetId(a))
        self._Add(a, None, self._Migrate(a, self.feed_merger.a_schedule, newid))
    for b in b_not_merged:
        newid = self._HasId(self.feed_merger.a_schedule, self._GetId(b))
        self._Add(None, b, self._Migrate(b, self.feed_merger.b_schedule, newid))
    self._num_not_merged_a = len(a_not_merged)
    self._num_not_merged_b = len(b_not_merged)
    return self._num_merged

Tries to merge entities based on their ids.

This tries to merge only the entities from the old and new schedules which
have the same id. These are added into the merged schedule. Entities which
do not merge or do not have the same id as another entity in the other
schedule are simply migrated into the merged schedule.

This method is less flexible than _MergeDifferentId since it only tries
to merge entities which have the same id while _MergeDifferentId tries to
merge everything. However, it is faster and so should be used whenever
possible.

This method makes use of various methods like _Merge and _Migrate which
are not implemented in the abstract DataSetMerger class. These method
should be overwritten in a subclass to allow _MergeSameId to work with
different entity types.

Returns:
The number of merged entities.


def op(scalars_layout, collections=None):

  import tensorflow.compat.v1 as tf

  assert isinstance(scalars_layout, layout_pb2.Layout)
  summary_metadata = metadata.create_summary_metadata()
  return tf.summary.tensor_summary(name=metadata.CONFIG_SUMMARY_TAG,
                                   tensor=tf.constant(
                                       scalars_layout.SerializeToString(),
                                       dtype=tf.string),
                                   collections=collections,
                                   summary_metadata=summary_metadata)

Creates a summary that contains a layout.

When users navigate to the custom scalars dashboard, they will see a layout
based on the proto provided to this function.

Args:
scalars_layout: The scalars_layout_pb2.Layout proto that specifies the
layout.
collections: Optional list of graph collections keys. The new
summary op is added to these collections. Defaults to
`[Graph Keys.SUMMARIES]`.

Returns:
A tensor summary op that writes the layout to disk.


def RegisterDecompressor(cls, decompressor):
    compression_method = decompressor.COMPRESSION_METHOD.lower()
    if (compression_method in cls._decompressors):
        raise KeyError('Decompressor for compression method: {0:s} already set.'.format(decompressor.COMPRESSION_METHOD))
    cls._decompressors[compression_method] = decompressor

Registers a decompressor for a specific compression method.

Args:
decompressor (type): decompressor class.

Raises:
KeyError: if the corresponding decompressor is already set.


def add(reader, writer, column, start, stop, value):

  for i, row in enumerate(reader):
    if i >= start and i <= stop:
      row[column] = type(value)(row[column]) + value
    writer.appendRecord(row)

Adds a value over a range of rows.

Args:
reader: A FileRecordStream object with input data.
writer: A FileRecordStream object to write output data to.
column: The column of data to modify.
start: The first row in the range to modify.
end: The last row in the range to modify.
value: The value to add.


def setValues(self, values):
    if isinstance(values, (list, set)):
        if any((isinstance(value, basestring) for value in values)):
            values = list(map(str, values))
            self._impl.setValuesStr(values, len(values))
        elif all((isinstance(value, Real) for value in values)):
            values = list(map(float, values))
            self._impl.setValuesDbl(values, len(values))
        elif all((isinstance(value, tuple) for value in values)):
            self._impl.setValues(Utils.toTupleArray(values), len(values))
        else:
            raise TypeError
    else:
        if ((np is not None) and isinstance(values, np.ndarray)):
            self.setValues(DataFrame.fromNumpy(values).toList())
            return
        Entity.setValues(self, values)

Set the tuples in this set. Valid only for non-indexed sets.

Args:
values: A list of tuples or a :class:`~amplpy.DataFrame`.

In the case of a :class:`~amplpy.DataFrame`, the number of indexing
columns of the must be equal to the arity of the set. In the case of
a list of tuples, the arity of each tuple must be equal to the arity
of the set.

For example, considering the following AMPL entities and corresponding
Python objects:

.. code-block:: ampl

set A := 1..2;
param p{i in A} := i+10;
set AA;

The following is valid:

.. code-block:: python

A, AA = ampl.getSet('A'), ampl.getSet('AA')
AA.setValues(A.getValues())  # AA has now the members {1, 2}


def _rename_if_arg_found_and_add_loss_reduction_transformer(parent, node, full_name, name, logs, arg_names=None, arg_ok_predicate=None, remove_if_ok=False, message=None):
    for arg_name in arg_names:
        rename_node = _rename_if_arg_found_transformer(parent, node, full_name, name, logs, arg_name, arg_ok_predicate, remove_if_ok, message)
        node = rename_node if rename_node else node
    return node

Combination of _rename_if_arg_found and _add_loss_reduction transformers.

Args:
parent: Parent of node.
node: ast.Call node to maybe modify.
full_name: full name of function to modify
name: name of function to modify
logs: list of logs to append to
arg_names: list of names of the argument to look for
arg_ok_predicate: predicate callable with the ast of the argument value,
returns whether the argument value is allowed.
remove_if_ok: remove the argument if present and ok as determined by
arg_ok_predicate.
message: message to print if a non-ok arg is found (and hence, the function
is renamed to its compat.v1 version).

Returns:
node, if it was modified, else None.


def locked_put(self, credentials):
    (entity, _) = self.model_class.objects.get_or_create(**{self.key_name: self.key_value})
    setattr(entity, self.property_name, credentials)
    entity.save()

Write a Credentials to the Django datastore.

Args:
credentials: Credentials, the credentials to store.


def tool(self):
    htablettool = self._libinput.libinput_event_tablet_tool_get_tool(self._handle)
    return TabletTool(htablettool, self._libinput)

The tool that was in use during this event.

If the caller keeps a reference to a tool, the tool object will
compare equal to the previously obtained tool object.

Note:
Physical tool tracking requires hardware support. If unavailable,
libinput creates one tool per type per tablet. See
`Tracking unique tools`_ for more details.
Returns:
~libinput.define.TabletTool: The new tool triggering this event.


def __init__(self, parent=None, range_offset=None, range_size=None, **kwargs):

    if not range_offset or not range_size or not parent:
      raise ValueError('Missing range offset, range size or parent value.')

    super(DataRangePathSpec, self).__init__(parent=parent, **kwargs)
    self.range_offset = range_offset
    self.range_size = range_size

Initializes a path specification.

Note that the data range path specification must have a parent.

Args:
parent (Optional[PathSpec]): parent path specification.
range_offset (Optional[int]): start offset of the data range.
range_size (Optional[int]): size of the data range.

Raises:
ValueError: when range offset, range offset or parent are not set.


def get_chunk_size(path):
    filesystem = FileSystems.get_filesystem(path)
    return filesystem.CHUNK_SIZE

Get the correct chunk size for the FileSystem.

Args:
path: string path that needs to be checked.

Returns: integer size for parallelization in the FS operations.


def CreateBudget(client):
    budget_service = client.GetService('BudgetService', version='v201809')
    budget = {'name': ('Interplanetary Cruise App Budget
    budget_operations = [{'operator': 'ADD', 'operand': budget}]
    budget_id = budget_service.mutate(budget_operations)['value'][0]['budgetId']
    return budget_id

Creates a budget and returns its budgetId.

Args:
client: An AdWordsClient instance.

Returns:
An int budgetId for the created Budget.


def parse_document(text, options=0):

    encoded_text = text.encode('utf-8')
    return _cmark.lib.cmark_parse_document(
        encoded_text, len(encoded_text), options)

Parse a document and return the root node.

Args:
text (str): The text to parse.
options (int): The cmark options.

Returns:
Any: Opaque reference to the root node of the parsed syntax tree.


def _extractBoldNumbers(self, out, start_line):
    floats = []
    for i in range(start_line, len(out.lines)):
        if i not in out.font_attr_segs:
            continue
        line_attrs = out.font_attr_segs[i]
        for begin, end, attr_value in line_attrs:
            if attr_value == 'bold':
                floats.append(float(out.lines[i][begin:end]))
    return floats

Extract all numbers that have the bold font attribute.

Args:
out: An instance of RichTextLines.
start_line: 0-based index to start from.

Returns:
A list of floats.