def transfers(self, payment_id, data={}, **kwargs):

        url = "{}/{}/transfers".format(self.base_url, payment_id)
        return self.get_url(url, data, **kwargs)

Fetches all transfer for given Payment Id

Args:
payment_id : Id for which payment object has to be refunded
Amount : Amount for which the payment has to be refunded

Returns:
Payment dict after getting refunded


def _get_log_file(self):
    log_dir: Path = (Path(self.config['log_path']).expanduser().resolve() / self.agent_name)
    log_dir.mkdir(parents=True, exist_ok=True)
    log_file_path = Path(log_dir, f'{self._get_timestamp_utc_str()}_{self.agent_name}.log')
    log_file = open(log_file_path, 'a', buffering=1, encoding='utf8')
    return log_file

Returns opened file object for writing dialog logs.

Returns:
log_file: opened Python file object.


def prepare_create_transaction(*, signers, recipients=None, asset=None, metadata=None):
    if (not isinstance(signers, (list, tuple))):
        signers = [signers]
    elif isinstance(signers, tuple):
        signers = list(signers)
    if (not recipients):
        recipients = [(signers, 1)]
    elif (not isinstance(recipients, (list, tuple))):
        recipients = [([recipients], 1)]
    elif isinstance(recipients, tuple):
        recipients = [(list(recipients), 1)]
    transaction = Transaction.create(signers, recipients, metadata=metadata, asset=(asset['data'] if asset else None))
    return transaction.to_dict()

Prepares a ``"CREATE"`` transaction payload, ready to be
fulfilled.

Args:
signers (:obj:`list` | :obj:`tuple` | :obj:`str`): One
or more public keys representing the issuer(s) of the asset
being created.
recipients (:obj:`list` | :obj:`tuple` | :obj:`str`, optional):
One or more public keys representing the new recipients(s)
of the asset being created. Defaults to ``None``.
asset (:obj:`dict`, optional): The asset to be created.
Defaults to ``None``.
metadata (:obj:`dict`, optional): Metadata associated with the
transaction. Defaults to ``None``.

Returns:
dict: The prepared ``"CREATE"`` transaction.

.. important::

* If ``asset`` is set, it MUST be in the form of::

{
'data': {
...
}
}

* If ``recipients`` is not given, or evaluates to
``False``, it will be set equal to ``signers``::

if not recipients:
recipients = signers


def add_subscription(self, channel, callback_function):
    if (channel not in CHANNELS):
        CHANNELS.append(channel)
        SUBSCRIPTIONS[channel] = [callback_function]
    else:
        SUBSCRIPTIONS[channel].append(callback_function)
    if self._subscribed:
        _LOGGER.info('New channel added after main subscribe call.')
        self._pubnub.subscribe().channels(channel).execute()

Add a channel to subscribe to and a callback function to
run when the channel receives an update.
If channel already exists, create a new "subscription"
and append another callback function.

Args:
channel (str): The channel to add a subscription too.
callback_function (func): The function to run on an
update to the passed in channel.


def split(self):
    self.sort_versions()

    def _split(i_entry, n_variants, common_fams=None):
        result = self.entries[i_entry].split(n_variants)
        if result:
            (entry, next_entry) = result
            entries = (self.entries[:i_entry] + [entry])
            next_entries = ([next_entry] + self.entries[(i_entry + 1):])
        else:
            entries = self.entries[:(i_entry + 1)]
            next_entries = self.entries[(i_entry + 1):]
        slice_ = self._copy(entries)
        next_slice = self._copy(next_entries)
        if self.pr:
            if common_fams:
                if (len(common_fams) == 1):
                    reason_str = iter(common_fams).next()
                else:
                    reason_str = ', '.join(common_fams)
            else:
                reason_str = 'first variant'
            self.pr('split (reason: %s) %s into %s and %s', reason_str, self, slice_, next_slice)
        return (slice_, next_slice)
    if (len(self) > 2):
        fams = (self.first_variant.request_fams - self.extracted_fams)
    else:
        fams = None
    if (not fams):
        return _split(0, 1)
    prev = None
    for (i, entry) in enumerate(self.entries):
        entry.sort()
        for (j, variant) in enumerate(entry.variants):
            fams = (fams & variant.request_fams)
            if (not fams):
                return _split(*prev)
            prev = (i, (j + 1), fams)
    raise RezSystemError(('Unexpected solver error: common family(s) still in slice being split: slice: %s, family(s): %s' % (self, str(fams))))

Split the slice.

Returns:
(`_PackageVariantSlice`, `_PackageVariantSlice`) tuple, where the
first is the preferred slice.


def raw_generate(output_file, source_dir, git_tag_override=None):
    git_version = get_git_version(source_dir, git_tag_override)
    write_version_info(output_file, git_version)

Simple generator used for cmake/make build systems.

This does not create any symlinks. It requires the build system
to build unconditionally.

Args:
output_file: Output filename for the version info cc
source_dir: Base path of the source code
git_tag_override: Override the value for the git tag. This is useful for
releases where we want to build the release before the git tag is
created.


def makedirs(self, dir_name, mode=PERM_DEF, exist_ok=None):
    if (exist_ok is None):
        exist_ok = False
    elif (sys.version_info < (3, 2)):
        raise TypeError("makedir() got an unexpected keyword argument 'exist_ok'")
    self.filesystem.makedirs(dir_name, mode, exist_ok)

Create a leaf Fake directory + create any non-existent parent dirs.

Args:
dir_name: (str) Name of directory to create.
mode: (int) Mode to create directory (and any necessary parent
directories) with. This argument defaults to 0o777.
The umask is applied to this mode.
exist_ok: (boolean) If exist_ok is False (the default), an OSError
is raised if the target directory already exists.
New in Python 3.2.

Raises:
OSError: if the directory already exists and exist_ok=False, or as
per :py:meth:`FakeFilesystem.create_dir`.


def add_all(application, project_id, control_client, loader=service.Loaders.FROM_SERVICE_MANAGEMENT):
    return ConfigFetchWrapper(application, project_id, control_client, loader)

Adds all endpoints middleware to a wsgi application.

Sets up application to use all default endpoints middleware.

Example:

>>> application = MyWsgiApp()  # an existing WSGI application
>>>
>>> # the name of the controlled service
>>> service_name = 'my-service-name'
>>>
>>> # A GCP project  with service control enabled
>>> project_id = 'my-project-id'
>>>
>>> # wrap the app for service control
>>> from endpoints_management.control import wsgi
>>> control_client = client.Loaders.DEFAULT.load(service_name)
>>> control_client.start()
>>> wrapped_app = add_all(application, project_id, control_client)
>>>
>>> # now use wrapped_app in place of app

Args:
application: the wrapped wsgi application
project_id: the project_id thats providing service control support
control_client: the service control client instance
loader (:class:`endpoints_management.control.service.Loader`): loads the service
instance that configures this instance's behaviour


def get_fhir_extensions(msg: message.Message) -> List[message.Message]:
    extension_field = msg.DESCRIPTOR.fields_by_name.get('extension')
    if extension_field is None:
        raise ValueError(f'Message of type {msg.DESCRIPTOR.name} does not have an extension attribute.')
    return proto_utils.get_value_at_field(msg, extension_field)

Returns a list of FHIR extensions from the provided FHIR primitive.

Args:
msg: The Message to extract FHIR extensions from.

Returns:
A list of Extension values found on the instance.

Raises:
ValueError: If the provided FHIR primitive doesn't have an extension
attribute.


def translate_distribution(distribution_update, metric_update_proto):
    dist_update_proto = dataflow.DistributionUpdate()
    dist_update_proto.min = to_split_int(distribution_update.min)
    dist_update_proto.max = to_split_int(distribution_update.max)
    dist_update_proto.count = to_split_int(distribution_update.count)
    dist_update_proto.sum = to_split_int(distribution_update.sum)
    if isinstance(distribution_update, DataflowDistributionCounter):
        dist_update_proto.histogram = dataflow.Histogram()
        distribution_update.translate_to_histogram(dist_update_proto.histogram)
    metric_update_proto.distribution = dist_update_proto

Translate metrics DistributionUpdate to dataflow distribution update.

Args:
distribution_update: Instance of DistributionData,
DistributionInt64Accumulator or DataflowDistributionCounter.
metric_update_proto: Used for report metrics.


def _download_file_from_drive(filename, url):
    confirm_token = None
    confirm_token = None
    session = requests.Session()
    response = session.get(url, stream=True)
    for (k, v) in response.cookies.items():
        if k.startswith('download_warning'):
            confirm_token = v
    if confirm_token:
        url = ((url + '&confirm=') + confirm_token)
    logger.info(('Downloading %s to %s' % (url, filename)))
    response = session.get(url, stream=True)
    chunk_size = (16 * 1024)
    with open(filename, 'wb') as f:
        for chunk in response.iter_content(chunk_size):
            if chunk:
                f.write(chunk)
    statinfo = os.stat(filename)
    logger.info(('Successfully downloaded %s, %s bytes.' % (filename, statinfo.st_size)))

Download filename from google drive unless it's already in directory.

Args:
filename (str): Name of the file to download to (do nothing if it already exists).
url (str): URL to download from.


def index_one(self, instance, force=False):
    if ((not self.is_indexed(instance)) and (not force)):
        doc = self._as_document(instance)
        self._index_document(doc, force=force)
        logger.debug('{} indexed as\n {}'.format(instance.__class__, pformat(doc)))
        return True
    logger.debug('{} already indexed.'.format(instance.__class__))
    return False

Indexes exactly one object of the Ambry system.

Args:
instance (any): instance to index.
force (boolean): if True replace document in the index.

Returns:
boolean: True if document added to index, False if document already exists in the index.


def BatchCreate(self, request, global_params=None):
    config = self.GetMethodConfig('BatchCreate')
    return self._RunMethod(config, request, global_params=global_params)

Batch connecting Bitbucket Server repositories to Cloud Build.

Args:
request: (CloudbuildProjectsLocationsBitbucketServerConfigsConnectedRepositoriesBatchCreateRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(Operation) The response message.


def get_events(self, event_names):

    if isinstance(event_names, six.string_types):
      event_names = [event_names]

    all_events = self.list_events()
    dirs_to_look = set()
    for event, dirs in six.iteritems(all_events):
      if event in event_names:
        dirs_to_look.update(dirs)

    ret_events = [collections.defaultdict(lambda: pd.DataFrame(columns=['time', 'step', 'value']))
                  for i in range(len(event_names))]
    for event_file in self._glob_events_files(dirs_to_look, recursive=False):
      try:
        for record in tf_record.tf_record_iterator(event_file):
          event = event_pb2.Event.FromString(record)
          if event.summary is None or event.wall_time is None or event.summary.value is None:
            continue

          event_time = datetime.datetime.fromtimestamp(event.wall_time)
          for value in event.summary.value:
            if value.tag not in event_names or value.simple_value is None:
              continue

            index = event_names.index(value.tag)
            dir_event_dict = ret_events[index]
            dir = os.path.dirname(event_file)

            df = dir_event_dict[dir]
            df.loc[len(df)] = [event_time, event.step, value.simple_value]
      except tf.errors.DataLossError:

        continue

    for idx, dir_event_dict in enumerate(ret_events):
      for df in dir_event_dict.values():
        df.sort_values(by=['time'], inplace=True)
      ret_events[idx] = dict(dir_event_dict)

    return ret_events

Get all events as pandas DataFrames given a list of names.
Args:
event_names: A list of events to get.
Returns:
A list with the same length and order as event_names. Each element is a dictionary
{dir1: DataFrame1, dir2: DataFrame2, ...}.
Multiple directories may contain events with the same name, but they are different
events (i.e. 'loss' under trains_set/, and 'loss' under eval_set/.)


def format_image_annotations_as_coco(image_id: str, categories: list[int], areas: list[float], bboxes: list[tuple[float]]) -> dict:
    annotations = []
    for category, area, bbox in zip(categories, areas, bboxes):
        formatted_annotation = {'image_id': image_id, 'category_id': category, 'iscrowd': 0, 'area': area, 'bbox': list(bbox)}
        annotations.append(formatted_annotation)
    return {'image_id': image_id, 'annotations': annotations}

Format one set of image annotations to the COCO format

Args:
image_id (str): image id. e.g. "0001"
categories (List[int]): list of categories/class labels corresponding to provided bounding boxes
areas (List[float]): list of corresponding areas to provided bounding boxes
bboxes (List[Tuple[float]]): list of bounding boxes provided in COCO format
([center_x, center_y, width, height] in absolute coordinates)

Returns:
dict: {
"image_id": image id,
"annotations": list of formatted annotations
}


def _notify_progress_sync(self, uuid, client, done_count, total_count):

        conn_data = self._connections.get(uuid, None)
        if conn_data is None:
            return

        last_progress = conn_data['last_progress']

        should_drop = False

        now = monotonic()
        if last_progress is not None and (now - last_progress) < self.throttle_progress:
            should_drop = True

        if should_drop and (done_count != total_count):
            return

        conn_data['last_progress'] = now

        slug = self._build_device_slug(uuid)
        status_msg = {'type': 'notification', 'operation': 'send_script', 'client': client, 'done_count': done_count, 'total_count': total_count}
        self._publish_response(slug, status_msg)

Notify progress reporting on the status of a script download.

This function must be called synchronously inside of the event loop.

Args:
uuid (int): The id of the device that we are talking to
client (string): The client identifier
done_count (int): The number of items that have been finished
total_count (int): The total number of items


def force_string(val=None):

    if val is None:
        return ''
    if isinstance(val, list):
        newval = [str(x) for x in val]
        return ';'.join(newval)
    if isinstance(val, str):
        return val
    else:
        return str(val)

Force a string representation of an object

Args:
val: object to parse into a string

Returns:
str: String representation


def Filter(self, function=None):

    flat = lambda x: x if isinstance(x, str) else ''.join([flat(y) for y in x])
    if function is None:
      function = lambda row: bool(flat(row.values))

    new_table = self.__class__()

    new_table._table = [self.header]
    for row in self:
      if function(row) is True:
        new_table.Append(row)
    return new_table

Construct Textable from the rows of which the function returns true.

Args:
function: A function applied to each row which returns a bool. If
function is None, all rows with empty column values are
removed.
Returns:
A new TextTable()

Raises:
TableError: When an invalid row entry is Append()'d


def _parseDOM(istack):

    ostack = []
    end_tag_index = 0

    def neither_nonpair_or_end_or_comment(el):
        return not (el.isNonPairTag() or el.isEndTag() or el.isComment())

    index = 0
    while index < len(istack):
        el = istack[index]

        end_tag_index = _indexOfEndTag(istack[index:])

        if end_tag_index == 0 and neither_nonpair_or_end_or_comment(el):
            el.isNonPairTag(True)

        if end_tag_index == 0:
            if not el.isEndTag():
                ostack.append(el)
        else:
            el.childs = _parseDOM(istack[index + 1: end_tag_index + index])
            el.endtag = istack[end_tag_index + index]
            el.endtag.openertag = el

            ostack.append(el)
            ostack.append(el.endtag)

            index = end_tag_index + index

        index += 1

    return ostack

Recursively go through element array and create DOM.

Args:
istack (list): List of :class:`.HTMLElement` objects.

Returns:
list: DOM tree as list.


def gather_ops_or_named_saveables(self):
    recorded_registered_saver = self.get_registered_saver_name()
    if not (self.object_proto.attributes or recorded_registered_saver):
        return ([], {}, [], {})
    existing_restore_ops = []
    named_saveables = {}
    python_positions = []
    registered_savers = collections.defaultdict(dict)
    saveable_factories = saveable_object_util.saveable_objects_from_trackable(self.trackable)
    saver_name = registration.get_registered_saver_name(self.trackable)
    if recorded_registered_saver:
        if not self.skip_restore:
            name = self.object_proto.registered_saver.object_name
            registered_savers[recorded_registered_saver][name] = self.trackable
    elif saver_name:
        registered_savers[saver_name] = {self.object_proto.attributes[0].checkpoint_key: self.trackable}
    elif isinstance(self.trackable, python_state.PythonState):
        python_positions.append(self)
    elif saveable_factories.keys() == {trackable_utils.SERIALIZE_TO_TENSORS_NAME}:
        existing_restore_ops, named_saveables = self._create_serialize_to_tensor_saveable(saveable_factories)
    elif saveable_factories:
        existing_restore_ops, named_saveables = self._create_saveables_by_attribute_name(saveable_factories)
    else:
        for serialized_tensor in self.object_proto.attributes:
            self._checkpoint.unused_attributes.setdefault(self._proto_id, []).append(serialized_tensor.name)
    return (existing_restore_ops, named_saveables, python_positions, registered_savers)

Looks up or creates SaveableObjects which don't have cached ops.

Returns:
A tuple of (
existing_restore_ops: list,
named_saveables: dict,
python_positions: list,
registered_savers: dict)


def __init__(self, message):

        super(OperationNotSupported, self).__init__(
            reason=enums.ResultReason.OPERATION_NOT_SUPPORTED,
            message=message
        )

Create an OperationNotSupported exception.

Args:
message (string): A string containing information about the error.


def ProcessEvent(self, event, parser_chain=None, file_entry=None, query=None):
    if ((not getattr(event, 'parser', None)) and parser_chain):
        event.parser = parser_chain
    if ((not getattr(event, 'text_prepend', None)) and self._text_prepend):
        event.text_prepend = self._text_prepend
    if (file_entry is None):
        file_entry = self._file_entry
    display_name = None
    if file_entry:
        event.pathspec = file_entry.path_spec
        if (not getattr(event, 'filename', None)):
            path_spec = getattr(file_entry, 'path_spec', None)
            event.filename = path_helper.PathHelper.GetRelativePathForPathSpec(path_spec, mount_path=self._mount_path)
        if (not display_name):
            display_name = self.GetDisplayName(file_entry)
        stat_object = file_entry.GetStat()
        inode_value = getattr(stat_object, 'ino', None)
        if ((getattr(event, 'inode', None) is None) and (inode_value is not None)):
            event.inode = self._GetInode(inode_value)
    if ((not getattr(event, 'display_name', None)) and display_name):
        event.display_name = display_name
    if ((not getattr(event, 'hostname', None)) and self.hostname):
        event.hostname = self.hostname
    if (not getattr(event, 'username', None)):
        user_sid = getattr(event, 'user_sid', None)
        username = self._knowledge_base.GetUsernameByIdentifier(user_sid)
        if username:
            event.username = username
    if ((not getattr(event, 'query', None)) and query):
        event.query = query
    for (attribute, value) in iter(self._extra_event_attributes.items()):
        if hasattr(event, attribute):
            raise KeyError('Event already has a value for {0:s}'.format(attribute))
        setattr(event, attribute, value)

Processes an event before it written to the storage.

Args:
event (EventObject|EventData): event or event data.
parser_chain (Optional[str]): parsing chain up to this point.
file_entry (Optional[dfvfs.FileEntry]): file entry, where None will
use the current file entry set in the mediator.
query (Optional[str]): query that was used to obtain the event.

Raises:
KeyError: if there's an attempt to add a duplicate attribute value to the
event.


def _find_resource_in_bundle(uri: str, bundle_json: Dict[str, Any]) -> Optional[Dict[str, Any]]:
    for entry in bundle_json.get('entry', ()):
        resource = entry.get('resource', {})
        if resource.get('url') == uri:
            return resource
        elif resource.get('resourceType') == 'Bundle':
            bundled_resource = _find_resource_in_bundle(uri, resource)
            if bundled_resource is not None:
                return bundled_resource
    return None

Finds the JSON object for the resource with `uri` inside `bundle_json`.

Args:
uri: The resource URI to search for.
bundle_json: Parsed JSON object for the bundle to search

Returns:
Parsed JSON object for the resource or `None` if it can not be found.


def depth_october_average_ground_temperature(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 `depth_october_average_ground_temperature`'.format(value))
    self._depth_october_average_ground_temperature = value

Corresponds to IDD Field `depth_october_average_ground_temperature`

Args:
value (float): value for IDD Field `depth_october_average_ground_temperature`
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 update_in_hdx(self, **kwargs):
    self._check_load_existing_object('resource', 'id')
    if (self.file_to_upload and ('url' in self.data)):
        del self.data['url']
    self._merge_hdx_update('resource', 'id', self.file_to_upload, **kwargs)

Check if resource exists in HDX and if so, update it

Args:
**kwargs: See below
operation (string): Operation to perform eg. patch. Defaults to update.

Returns:
None


def register_gpt_plugin(self, fs_guid, plugin):
    key = uuid.UUID(fs_guid.lower())
    self.logger.debug('GPT: {}, GUID: {}'.format(self.__get_plugin_name(plugin), fs_guid))
    self.__gpt_plugins[key].append(plugin)

Used in plugin's registration routine,
to associate it's detection method with given filesystem guid

Args:
fs_guid: filesystem guid that is read from GPT partition entry
plugin: plugin that supports this filesystem


def _set_class_parser(self, init_parser, methods_to_parse, cls):
    top_level_parents = ([init_parser] if init_parser else [])
    description = (self._description or cls.__doc__)
    top_level_parser = argparse.ArgumentParser(description=description, parents=top_level_parents, add_help=False, conflict_handler='resolve')
    top_level_parser.add_argument('-h', '--help', action=FullHelpAction, help='Display this help message')
    parser_to_method = self._add_sub_parsers(top_level_parser, methods_to_parse, cls.__name__)
    if init_parser:
        parser_to_method['__init__'] = '__init__'
    top_level_parser.call = self._get_parser_call_method(parser_to_method)
    cls.parser = top_level_parser

Creates the complete argument parser for the decorated class.

Args:
init_parser: argument parser for the __init__ method or None
methods_to_parse: dict of method name pointing to their associated
argument parser
cls: the class we are decorating

Returns:
The decorated class with an added attribute 'parser'


def write_to_file(self, out_data):

        full_var_name = self.consensus_type + "_" + self.variable
        if "-hour" in self.consensus_type:
            if full_var_name not in out_data.variables.keys():
                var = out_data.createVariable(full_var_name, "f4", ("y", "x"), zlib=True,
                                              least_significant_digit=3, shuffle=True)
            else:
                var = out_data.variables[full_var_name]
            var.coordinates = "y x"
        else:
            if full_var_name not in out_data.variables.keys():
                var = out_data.createVariable(full_var_name, "f4", ("time", "y", "x"), zlib=True,
                                              least_significant_digit=3, shuffle=True)
            else:
                var = out_data.variables[full_var_name]
            var.coordinates = "time y x"
        var[:] = self.data
        var.units = self.units
        var.long_name = self.consensus_type + "_" + self.variable
        return

Outputs data to a netCDF file. If the file does not exist, it will be created. Otherwise, additional variables
are appended to the current file

Args:
out_data: Full-path and name of output netCDF file


def __init__(self, label, left_hand_side, right_hand_side_variables, *, line_number, path):

        super().__init__(label, left_hand_side, None, right_hand_side_variables, line_number=line_number, path=path)

Create a Restore node.

Args:
label(str): The label of the node, describing the expression it represents.
left_hand_side(str): The variable on the left hand side of the assignment. Used for analysis.
right_hand_side_variables(list[str]): A list of variables on the right hand side.
line_number(Optional[int]): The line of the expression the Node represents.
path(string): Current filename.


def get_single_node(self) -> yaml.Node:
    node = super().get_single_node()
    if (node is not None):
        node = self.__process_node(node, type(self).document_type)
    return node

Hook used when loading a single document.

This is the hook we use to hook yatiml into ruamel.yaml. It is \
called by the yaml libray when the user uses load() to load a \
YAML document.

Returns:
A processed node representing the document.


def _GetDataTypeMap(self, name):
    data_type_map = self._data_type_maps.get(name, None)
    if (not data_type_map):
        data_type_map = self._fabric.CreateDataTypeMap(name)
        self._data_type_maps[name] = data_type_map
    return data_type_map

Retrieves a data type map defined by the definition file.

The data type maps are cached for reuse.

Args:
name (str): name of the data type as defined by the definition file.

Returns:
dtfabric.DataTypeMap: data type map which contains a data type definition,
such as a structure, that can be mapped onto binary data.


def _head(self, client_kwargs):

        with _handle_client_exception():

            if 'obj' in client_kwargs:
                return self.client.head_object(**client_kwargs)

            return self.client.head_container(**client_kwargs)

Returns object HTTP header.

Args:
client_kwargs (dict): Client arguments.

Returns:
dict: HTTP header.


def _create_beam_sdk(sdk_remote_location, temp_dir) -> List[beam_runner_api_pb2.ArtifactInformation]:
    sdk_remote_parsed = urlparse(sdk_remote_location)
    sdk_remote_filename = os.path.basename(sdk_remote_parsed.path)
    local_download_file = os.path.join(temp_dir, sdk_remote_filename)
    Stager._download_file(sdk_remote_location, local_download_file)
    staged_name = Stager._desired_sdk_filename_in_staging_location(local_download_file)
    _LOGGER.info('Staging Beam SDK from %s', sdk_remote_location)
    return [Stager._create_file_stage_to_artifact(local_download_file, staged_name)]

Creates a Beam SDK file with the appropriate version.

Args:
sdk_remote_location: A URL from which the file can be downloaded or a
remote file location. The SDK file can be a tarball or a wheel.
temp_dir: path to temporary location where the file should be
downloaded.

Returns:
A list of ArtifactInformation of local files path and SDK files that
will be staged to the staging location.

Raises:
RuntimeError: if staging was not successful.


def exceptions(error_is_fatal=True, error_messages=None):

    def exception_decorator(func):
        nonlocal error_messages

        @functools.wraps(func)
        def exc_wrapper(*args, **kwargs):
            nonlocal error_messages
            try:
                result = func(*args, **kwargs)
            except sa.exc.SQLAlchemyError as err:
                result = None
                details = None
                err_type = err.__class__
                if (error_messages and (err_type in error_messages)):
                    details = error_messages[err_type]
                if details:
                    LOG.error(details)
                LOG.error('For developers: (%s) %s', err.__class__, str(err))
                if error_is_fatal:
                    sys.exit('Abort, SQL operation failed.')
                if (not ui.ask('I can continue at your own risk, do you want that?')):
                    raise err
            return result
        return exc_wrapper
    return exception_decorator

Handle SQLAlchemy exceptions in a sane way.

Args:
func: An arbitrary function to wrap.
error_is_fatal: Should we exit the program on exception?
reraise: Should we reraise the exception, after logging? Only makes sense
if error_is_fatal is False.
error_messages: A dictionary that assigns an exception class to a
customized error message.


def _get_sg_ids(self):
    try:
        lambda_extras = self.settings['security_groups']['lambda_extras']
    except KeyError:
        lambda_extras = []
    security_groups = ([self.app_name] + lambda_extras)
    sg_ids = []
    for security_group in security_groups:
        sg_id = get_security_group_id(name=security_group, env=self.env, region=self.region)
        sg_ids.append(sg_id)
    return sg_ids

Get IDs for all defined security groups.

Returns:
list: security group IDs for all lambda_extras


def sample(self, features):

    logits, losses = self(features)
    if self._target_modality_is_real:
      return logits, logits, losses
    if self.hparams.sampling_method == "argmax":
      samples = tf.argmax(logits, axis=-1)
    else:
      assert self.hparams.sampling_method == "random"

      def multinomial_squeeze(logits, temperature=1.0):
        logits_shape = common_layers.shape_list(logits)
        reshaped_logits = (
            tf.reshape(logits, [-1, logits_shape[-1]]) / temperature)
        choices = tf.multinomial(reshaped_logits, 1)
        choices = tf.reshape(choices, logits_shape[:-1])
        return choices

      samples = multinomial_squeeze(logits, self.hparams.sampling_temp)

    return samples, logits, losses

Run the model and extract samples.

Args:
features: an map of string to `Tensor`.

Returns:
samples: an integer `Tensor`.
logits: a list of `Tensor`s, one per datashard.
losses: a dictionary: {loss-name (string): floating point `Scalar`}.


def __call__(self, environ, start_response):

    with util.StartResponseProxy() as start_response_proxy:
      body_iter = self.service_app(environ, start_response_proxy.Proxy)
      status = start_response_proxy.response_status
      headers = start_response_proxy.response_headers
      exception = start_response_proxy.response_exc_info

      body = start_response_proxy.response_body

      if not body:
        body = ''.join(body_iter)

    headers_dict = dict([(k.lower(), v) for k, v in headers])
    if self.__is_json_error(status, headers_dict):
      status, body = self.protorpc_to_endpoints_error(status, body)

      if 'content-length' in headers_dict:
        for index, (header_name, _) in enumerate(headers):
          if header_name.lower() == 'content-length':
            headers[index] = (header_name, str(len(body)))
            break

    start_response(status, headers, exception)
    return [body]

Wrapper for the Endpoints server app.

Args:
environ: WSGI request environment.
start_response: WSGI start response function.

Returns:
Response from service_app or appropriately transformed error response.


def grid_destroy_from_ids(oargrid_jobids):

    jobs = grid_reload_from_ids(oargrid_jobids)
    for job in jobs:
        job.delete()
        logger.info("Killing the jobs %s" % oargrid_jobids)

Destroy all the jobs with corresponding ids

Args:
oargrid_jobids (list): the ``(site, oar_job_id)`` list of tuple
identifying the jobs for each site.


def create_transcripts_xml(video_id, video_el, resource_fs, static_dir):

    video_transcripts = VideoTranscript.objects.filter(video__edx_video_id=video_id).order_by('language_code')

    if video_transcripts.exists():
        transcripts_el = SubElement(video_el, 'transcripts')

    transcript_files_map = {}
    for video_transcript in video_transcripts:
        language_code = video_transcript.language_code
        file_format = video_transcript.file_format

        try:
            transcript_filename = create_transcript_file(
                video_id=video_id,
                language_code=language_code,
                file_format=file_format,
                resource_fs=resource_fs.delegate_fs(),
                static_dir=combine(u'course', static_dir)
            )
            transcript_files_map[language_code] = transcript_filename
        except TranscriptsGenerationException:

            logger.exception('[VAL] Error while generating "%s" transcript for video["%s"].', language_code, video_id)
            continue

        SubElement(
            transcripts_el,
            'transcript',
            {
                'language_code': language_code,
                'file_format': Transcript.SRT,
                'provider': video_transcript.provider,
            }
        )

    return dict(xml=video_el, transcripts=transcript_files_map)

Creates xml for transcripts.
For each transcript element, an associated transcript file is also created in course OLX.

Arguments:
video_id (str): Video id of the video.
video_el (Element): lxml Element object
static_dir (str): The Directory to store transcript file.
resource_fs (SubFS): The file system to store transcripts.

Returns:
lxml Element object with transcripts information


def has_no_title(self, title, **kwargs):
    try:
        self.assert_no_title(title, **kwargs)
        return True
    except ExpectationNotMet:
        return False

Checks if the page doesn't have the given title.

Args:
title (str | RegexObject): The string that the title should include.
**kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.

Returns:
bool: Whether it doesn't match.


def predict(self, structure, icsd_vol=False):
    std_x = np.std([site.specie.X for site in structure])
    sub_sites = []
    bp_dict = {}
    for sp in list(structure.composition.keys()):
        if sp.atomic_radius:
            sub_sites.extend([site for site in structure if (site.specie == sp)])
        else:
            warnings.warn('VolumePredictor: no atomic radius data for {}'.format(sp))
        if (sp.symbol not in bond_params):
            warnings.warn('VolumePredictor: bond parameters not found, used atomic radii for {}'.format(sp))
        else:
            (r, k) = (bond_params[sp.symbol]['r'], bond_params[sp.symbol]['k'])
            bp_dict[sp] = (float(r) + (float(k) * std_x))
    reduced_structure = Structure.from_sites(sub_sites)
    smallest_ratio = None
    for site1 in reduced_structure:
        sp1 = site1.specie
        neighbors = reduced_structure.get_neighbors(site1, (sp1.atomic_radius + self.cutoff))
        for (site2, dist) in neighbors:
            sp2 = site2.specie
            if ((sp1 in bp_dict) and (sp2 in bp_dict)):
                expected_dist = (bp_dict[sp1] + bp_dict[sp2])
            else:
                expected_dist = (sp1.atomic_radius + sp2.atomic_radius)
            if ((not smallest_ratio) or ((dist / expected_dist) < smallest_ratio)):
                smallest_ratio = (dist / expected_dist)
    if (not smallest_ratio):
        raise ValueError('Could not find any bonds within the given cutoff in this structure.')
    volume_factor = ((1 / smallest_ratio) ** 3)
    if icsd_vol:
        volume_factor *= 1.05
    if self.min_scaling:
        volume_factor = max(self.min_scaling, volume_factor)
    if self.max_scaling:
        volume_factor = min(self.max_scaling, volume_factor)
    return (structure.volume * volume_factor)

Given a structure, returns the predicted volume.

Args:
structure (Structure) : a crystal structure with an unknown volume.
icsd_vol (bool) : True if the input structure's volume comes from
ICSD.

Returns:
a float value of the predicted volume.


def expression(self, previous_precedence=0):

        lhs = self.atom()

        return self.operator(lhs, previous_precedence)

An expression is an atom or an infix expression.

Grammar (sort of, actually a precedence-climbing parser):
expression = atom [ binary_operator expression ] .

Args:
previous_precedence: What operator precedence should we start with?


def conv_block(name, x, mid_channels, dilations=None, activation='relu', dropout=0.0):
    with tf.variable_scope(name, reuse=tf.AUTO_REUSE):
        x_shape = common_layers.shape_list(x)
        is_2d = (len(x_shape) == 4)
        num_steps = x_shape[1]
        if is_2d:
            first_filter = [3, 3]
            second_filter = [1, 1]
        else:
            if (num_steps == 1):
                first_filter = [1, 3, 3]
            else:
                first_filter = [2, 3, 3]
            second_filter = [1, 1, 1]
        x = conv('1_1', x, output_channels=mid_channels, filter_size=first_filter, dilations=dilations)
        x = tf.nn.relu(x)
        x = get_dropout(x, rate=dropout)
        if (activation == 'relu'):
            x = conv('1_2', x, output_channels=mid_channels, filter_size=second_filter, dilations=dilations)
            x = tf.nn.relu(x)
        elif (activation == 'gatu'):
            x_tanh = conv('1_tanh', x, output_channels=mid_channels, filter_size=second_filter, dilations=dilations)
            x_sigm = conv('1_sigm', x, output_channels=mid_channels, filter_size=second_filter, dilations=dilations)
            x = (tf.nn.tanh(x_tanh) * tf.nn.sigmoid(x_sigm))
        x = get_dropout(x, rate=dropout)
        return x

2 layer conv block used in the affine coupling layer.

Args:
name: variable scope.
x: 4-D or 5-D Tensor.
mid_channels: Output channels of the second layer.
dilations: Optional, list of integers.
activation: relu or gatu.
If relu, the second layer is relu(W*x)
If gatu, the second layer is tanh(W1*x) * sigmoid(W2*x)
dropout: Dropout probability.
Returns:
x: 4-D Tensor: Output activations.


def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, layer_head_mask: torch.Tensor, band_mask=None, from_mask=None, to_mask=None, from_blocked_mask=None, to_blocked_mask=None, output_attentions: bool=False):
    residual = hidden_states
    hidden_states = self.self_attn_layer_norm(hidden_states)
    self_attention_outputs = self.self_attn(hidden_states=hidden_states, attention_mask=attention_mask, head_mask=layer_head_mask, output_attentions=output_attentions, band_mask=band_mask, from_mask=from_mask, to_mask=to_mask, from_blocked_mask=from_blocked_mask, to_blocked_mask=to_blocked_mask)
    hidden_states = self_attention_outputs[0]
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    residual = hidden_states
    hidden_states = self.final_layer_norm(hidden_states)
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = self.fc2(hidden_states)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    if hidden_states.dtype == torch.float16 and (torch.isinf(hidden_states).any() or torch.isnan(hidden_states).any()):
        clamp_value = torch.finfo(hidden_states.dtype).max - 1000
        hidden_states = torch.clamp(hidden_states, min=-clamp_value, max=clamp_value)
    outputs = (hidden_states,)
    if output_attentions:
        outputs += (self_attention_outputs[1],)
    return outputs

Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.


def get_attr_value(self, attr_key, el_idx=0):
    return self.get_element_by_attr_key(attr_key, el_idx).attrib[attr_key]

Return the value of the selected attribute in the selected element.

Args:
attr_key : str
Name of attribute for which to search

el_idx : int
Index of element to use in the event that there are multiple sibling
elements with the same name.

Returns:
str : Value of the selected attribute in the selected element.


def Delete(self, request, global_params=None):
    config = self.GetMethodConfig('Delete')
    return self._RunMethod(config, request, global_params=global_params)

Delete a `BitbucketServerConfig`. This API is experimental.

Args:
request: (CloudbuildProjectsLocationsBitbucketServerConfigsDeleteRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(Operation) The response message.


def discriminator(self, frames):
    ndf = self.hparams.num_discriminator_filters
    frames = tf.stack(frames)
    frames = common_video.swap_time_and_batch_axes(frames)
    num_outputs = [ndf, (ndf * 2), (ndf * 2), (ndf * 4), (ndf * 4), (ndf * 8), (ndf * 8)]
    kernel_sizes = [3, 4, 3, 4, 3, 4, 3]
    strides = [[1, 1, 1], [1, 2, 2], [1, 1, 1], [1, 2, 2], [1, 1, 1], [2, 2, 2], [1, 1, 1]]
    names = ['video_sn_conv0_0', 'video_sn_conv0_1', 'video_sn_conv1_0', 'video_sn_conv1_1', 'video_sn_conv2_0', 'video_sn_conv2_1', 'video_sn_conv3_0']
    iterable = zip(num_outputs, kernel_sizes, strides, names)
    activations = frames
    for (num_filters, kernel_size, stride, name) in iterable:
        activations = self.pad_conv3d_lrelu(activations, num_filters, kernel_size, stride, name)
    num_fc_dimensions = self.get_fc_dimensions(strides, kernel_sizes)
    activations = tf.reshape(activations, ((- 1), num_fc_dimensions))
    return tf.squeeze(tf.layers.dense(activations, 1))

3-D SNGAN discriminator.

Args:
frames: a list of batch-major tensors indexed by time.

Returns:
logits: 1-D Tensor with shape=batch_size.
Positive logits imply that the discriminator thinks that it
belongs to the true class.


def load(hdf5_filename):
    hdf5_filename = os.path.expanduser(hdf5_filename)
    try:
        f = h5py.File(hdf5_filename, 'r')
        data_layers = f.get('image').get('CUTOUT')
    except Exception as e:
        raise ValueError('Could not load file {0} for conversion. {}'.format(hdf5_filename, e))
        raise
    return numpy.array(data_layers)

Import a HDF5 file into a numpy array.

Arguments:
hdf5_filename:  A string filename of a HDF5 datafile

Returns:
A numpy array with data from the HDF5 file


def profile(self):
    profiles = {}
    data_generator_func = self._get_profile_data_generator()
    for device_index, device_stats in enumerate(self._run_metadata.step_stats.dev_stats):
        pprof_proto = self._get_pprof_proto(data_generator_func(device_stats))
        if not pprof_proto.sample:
            print('Not enough data to create profile for device %s. Did you pass RunMetadata to session.run call?' % device_stats.device)
            continue
        device_count = len(self._run_metadata.step_stats.dev_stats)
        device_description = 'Device %d of %d: %s' % (device_index + 1, device_count, device_stats.device)
        device_description_str_index = self._string_table.next_index()
        pprof_proto.string_table.append(device_description)
        pprof_proto.comment.append(device_description_str_index)
        profiles[device_stats.device] = pprof_proto
    return profiles

Generates pprof profiles.

Returns:
Dictionary mapping from device name to proto in `profile_pb2.Profile`
format.


def WriteUInt256(self, value):
    if (type(value) is UInt256):
        value.Serialize(self)
    else:
        raise Exception('Cannot write value that is not UInt256')

Write a UInt256 type to the stream.

Args:
value (UInt256):

Raises:
Exception: when `value` is not of neocore.UInt256 type.


def perturb(self, distance):

        def get_rand_vec():

            vector = np.random.randn(3)
            vnorm = np.linalg.norm(vector)
            return vector / vnorm * distance if vnorm != 0 else get_rand_vec()

        for i in range(len(self._sites)):
            self.translate_sites([i], get_rand_vec(), frac_coords=False)

Performs a random perturbation of the sites in a structure to break
symmetries.

Args:
distance (float): Distance in angstroms by which to perturb each
site.


def _get_default_initializer(self, name, shape=None, dtype=dtypes.float32):
    del shape
    if dtype.is_floating:
        initializer = init_ops.glorot_uniform_initializer()
        initializing_from_value = False
    elif dtype.is_integer or dtype.is_unsigned or dtype.is_bool or (dtype == dtypes.string):
        initializer = init_ops.zeros_initializer()
        initializing_from_value = False
    else:
        raise ValueError('An initializer for variable %s of %s is required' % (name, dtype.base_dtype))
    return (initializer, initializing_from_value)

Provide a default initializer and a corresponding value.

Args:
name: see get_variable.
shape: see get_variable.
dtype: see get_variable.

Returns:
initializer and initializing_from_value. See get_variable above.

Raises:
ValueError: When giving unsupported dtype.


def UpdateCacheFromSource(self, cache, source, incremental=False, force_write=False, location=None):
    error_count = 0
    incremental = incremental and self.can_do_incremental
    timestamp = self.GetModifyTimestamp()
    if timestamp is None and incremental is True:
        self.log.info('Missing previous timestamp, defaulting to a full sync.')
        incremental = False
    if incremental:
        source_map = source.GetMap(self.map_name, since=timestamp, location=location)
        try:
            error_count += self._IncrementalUpdateFromMap(cache, source_map)
        except (error.CacheNotFound, error.EmptyMap):
            self.log.warning('Local cache is invalid, faulting to a full sync.')
            incremental = False
    if not incremental:
        source_map = source.GetMap(self.map_name, location=location)
        error_count += self.FullUpdateFromMap(cache, source_map, force_write)
    return error_count

Update a single cache, from a given source.

Args:
cache: A nss_cache.caches.Cache object.
source: A nss_cache.sources.Source object.
incremental: A boolean flag indicating that an incremental update
should be performed if True.
force_write: A boolean flag forcing empty map updates if True.
location: The optional location in the source of this map used by
automount to specify which automount map to get, defaults to None.

Returns:
An int indicating the success of an update (0 == good, fail otherwise).


def repair_broken_bonds(self, slab, bonds):
    for pair in bonds.keys():
        blength = bonds[pair]
        cn_dict = {}
        for (i, el) in enumerate(pair):
            cnlist = []
            for site in self.oriented_unit_cell:
                poly_coord = 0
                if (site.species_string == el):
                    for nn in self.oriented_unit_cell.get_neighbors(site, blength):
                        if (nn[0].species_string == pair[(i - 1)]):
                            poly_coord += 1
                cnlist.append(poly_coord)
            cn_dict[el] = cnlist
        if (max(cn_dict[pair[0]]) > max(cn_dict[pair[1]])):
            (element1, element2) = pair
        else:
            (element2, element1) = pair
        for (i, site) in enumerate(slab):
            if (site.species_string == element1):
                poly_coord = 0
                for neighbor in slab.get_neighbors(site, blength):
                    poly_coord += (1 if (neighbor[0].species_string == element2) else 0)
                if (poly_coord not in cn_dict[element1]):
                    slab = self.move_to_other_side(slab, [i])
                    neighbors = slab.get_neighbors(slab[i], blength, include_index=True)
                    tomove = [nn[2] for nn in neighbors if (nn[0].species_string == element2)]
                    tomove.append(i)
                    slab = self.move_to_other_side(slab, tomove)
    return slab

This method will find undercoordinated atoms due to slab
cleaving specified by the bonds parameter and move them
to the other surface to make sure the bond is kept intact.
In a future release of surface.py, the ghost_sites will be
used to tell us how the repair bonds should look like.

Arg:
slab (structure): A structure object representing a slab.
bonds ({(specie1, specie2): max_bond_dist}: bonds are
specified as a dict of tuples: float of specie1, specie2
and the max bonding distance. For example, PO4 groups may be
defined as {("P", "O"): 3}.

Returns:
(Slab) A Slab object with a particular shifted oriented unit cell.


def set_permissions(filename, uid=None, gid=None, mode=0775):

    if uid is None:
        uid = get_ftp_uid()

    if gid is None:
        gid = -1

    os.chown(filename, uid, gid)
    os.chmod(filename, mode)

Set pemissions for given `filename`.

Args:
filename (str): name of the file/directory
uid (int, default proftpd): user ID - if not set, user ID of `proftpd`
is used
gid (int): group ID, if not set, it is not changed
mode (int, default 0775): unix access mode


def GetEncodedValue(env, name, default=None):
    name = Encode(name)
    value = env.get(name)
    if value is None:
        return default
    return Decode(value)

Returns the decoded value of the env var name.

Args:
env: {str: str}, The env dict.
name: str, The env var name.
default: The value to return if name is not in env.

Returns:
The decoded value of the env var name.


def rebuild(cls, session, tree_id=None):

        trees = session.query(cls).filter_by(parent_id=None)
        if tree_id:
            trees = trees.filter_by(tree_id=tree_id)
        for tree in trees:
            cls.rebuild_tree(session, tree.tree_id)

This function rebuid tree.

Args:
session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session

Kwargs:
tree_id (int or str): id of tree, default None

Example:

* :mod:`sqlalchemy_mptt.tests.TestTree.test_rebuild`


def get_reachable_volume_templates(self, start=0, count=(- 1), filter='', query='', sort='', networks=None, scope_uris='', private_allowed_only=False):
    uri = (self.URI + '/reachable-volume-templates')
    uri += '?networks={}&privateAllowedOnly={}'.format(networks, private_allowed_only)
    get_uri = self._client.build_query_uri(start=start, count=count, filter=filter, query=query, sort=sort, uri=uri, scope_uris=scope_uris)
    return self._client.get(get_uri)

Gets the storage templates that are connected on the specified networks based on the storage system
port's expected network connectivity.

Returns:
list: Storage volume templates.


def generate_meta_features(path, base_learner_id):
    with functions.DBContextManager(path) as session:
        base_learner = session.query(models.BaseLearner).filter_by(id=base_learner_id).first()
        if (not base_learner):
            raise exceptions.UserError('Base learner {} does not exist'.format(base_learner_id))
        base_learner.job_id = get_current_job().id
        base_learner.job_status = 'started'
        session.add(base_learner)
        session.commit()
        try:
            est = base_learner.return_estimator()
            extraction = session.query(models.Extraction).first()
            (X, y) = extraction.return_train_dataset()
            return_splits_iterable = functions.import_object_from_string_code(extraction.meta_feature_generation['source'], 'return_splits_iterable')
            meta_features_list = []
            trues_list = []
            for (train_index, test_index) in return_splits_iterable(X, y):
                (X_train, X_test) = (X[train_index], X[test_index])
                (y_train, y_test) = (y[train_index], y[test_index])
                est = est.fit(X_train, y_train)
                meta_features_list.append(getattr(est, base_learner.base_learner_origin.meta_feature_generator)(X_test))
                trues_list.append(y_test)
            meta_features = np.concatenate(meta_features_list, axis=0)
            y_true = np.concatenate(trues_list)
            for key in base_learner.base_learner_origin.metric_generators:
                metric_generator = functions.import_object_from_string_code(base_learner.base_learner_origin.metric_generators[key], 'metric_generator')
                base_learner.individual_score[key] = metric_generator(y_true, meta_features)
            meta_features_path = base_learner.meta_features_path(path)
            if (not os.path.exists(os.path.dirname(meta_features_path))):
                os.makedirs(os.path.dirname(meta_features_path))
            np.save(meta_features_path, meta_features, allow_pickle=False)
            base_learner.job_status = 'finished'
            base_learner.meta_features_exists = True
            session.add(base_learner)
            session.commit()
        except:
            session.rollback()
            base_learner.job_status = 'errored'
            base_learner.description['error_type'] = repr(sys.exc_info()[0])
            base_learner.description['error_value'] = repr(sys.exc_info()[1])
            base_learner.description['error_traceback'] = traceback.format_exception(*sys.exc_info())
            session.add(base_learner)
            session.commit()
            raise

Generates meta-features for specified base learner

After generation of meta-features, the file is saved into the meta-features folder

Args:
path (str): Path to Xcessiv notebook

base_learner_id (str): Base learner ID


def Open(self, filename):
    if (not super(WinevtResourcesSqlite3DatabaseReader, self).Open(filename)):
        return False
    version = self.GetMetadataAttribute('version')
    if ((not version) or (version != '20150315')):
        raise RuntimeError('Unsupported version: {0:s}'.format(version))
    string_format = self.GetMetadataAttribute('string_format')
    if (not string_format):
        string_format = 'wrc'
    if (string_format not in ('pep3101', 'wrc')):
        raise RuntimeError('Unsupported string format: {0:s}'.format(string_format))
    self._string_format = string_format
    return True

Opens the database reader object.

Args:
filename (str): filename of the database.

Returns:
bool: True if successful.

Raises:
RuntimeError: if the version or string format of the database
is not supported.


def init_cache(self, batch_size, max_length, encoder_outputs):
    decoder_input_ids = jnp.ones((batch_size, max_length), dtype='i4')
    decoder_attention_mask = jnp.ones_like(decoder_input_ids)
    decoder_position_ids = jnp.broadcast_to(jnp.arange(jnp.atleast_2d(decoder_input_ids).shape[-1]), decoder_input_ids.shape)

    def _decoder_forward(module, decoder_input_ids, decoder_attention_mask, decoder_position_ids, **kwargs):
        decoder_module = module._get_decoder_module()
        return decoder_module(input_ids=decoder_input_ids, attention_mask=decoder_attention_mask, position_ids=decoder_position_ids, **kwargs)
    init_variables = self.module.init(jax.random.PRNGKey(0), decoder_input_ids=decoder_input_ids, decoder_attention_mask=decoder_attention_mask, decoder_position_ids=decoder_position_ids, encoder_hidden_states=encoder_outputs[0], init_cache=True, method=_decoder_forward)
    return unfreeze(init_variables['cache'])

Args:
batch_size (`int`):
batch_size used for fast auto-regressive decoding. Defines the batch size of the initialized cache.
max_length (`int`):
maximum possible length for auto-regressive decoding. Defines the sequence length of the initialized
cache.
encoder_outputs (`Union[FlaxBaseModelOutput, tuple(tuple(jnp.ndarray)]`):
`encoder_outputs` consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*:
`attentions`). `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*)
is a sequence of hidden-states at the output of the last layer of the encoder. Used in the
cross-attention of the decoder.


def id_pools(self):
    if (not self.__id_pools):
        self.__id_pools = IdPools(self.__connection)
    return self.__id_pools

Gets the IdPools API client.

Returns:
IdPools:


def reverse(x, axes):
    if isinstance(axes, int):
        axes = [axes]
    return array_ops.reverse(x, axes)

Reverse a tensor along the specified axes.

Args:
x: Tensor to reverse.
axes: Integer or iterable of integers.
Axes to reverse.

Returns:
A tensor.


def __init__(self, ctx):
    self._lineno = 0
    self._col_offset = 0
    self.ctx = ctx
    self.state = _State()

Initialize the transformer.

Subclasses should call this.

Args:
ctx: A Context object.


class DefaultDataCollator(DataCollatorMixin):
    return_tensors: str = 'pt'

    def __call__(self, features: List[Dict[str, Any]], return_tensors=None) -> Dict[str, Any]:
        if return_tensors is None:
            return_tensors = self.return_tensors
        return default_data_collator(features, return_tensors)

Very simple data collator that simply collates batches of dict-like objects and performs special handling for
potential keys named:

- `label`: handles a single value (int or float) per object
- `label_ids`: handles a list of values per object

Does not do any additional preprocessing: property names of the input object will be used as corresponding inputs
to the model. See glue and ner for example of how it's useful.

This is an object (like other data collators) rather than a pure function like default_data_collator. This can be
helpful if you need to set a return_tensors value at initialization.

Args:
return_tensors (`str`, *optional*, defaults to `"pt"`):
The type of Tensor to return. Allowable values are "np", "pt" and "tf".


def _fact_to_tuple(self, fact):

        if fact.category:
            category = fact.category.name
        else:
            category = ''

        description = fact.description or ''

        return FactTuple(
            start=fact.start.strftime(self.datetime_format),
            end=fact.end.strftime(self.datetime_format),
            activity=text_type(fact.activity.name),
            duration=fact.get_string_delta(format='%M'),
            category=text_type(category),
            description=text_type(description),
        )

Convert a ``Fact`` to its normalized tuple.

This is where all type conversion for ``Fact`` attributes to strings as
well as any normalization happens.

Note:
Because different writers may require different types, we need to
do this individually.

Args:
fact (hamster_lib.Fact): Fact to be converted.

Returns:
FactTuple: Tuple representing the original ``Fact``.


def create_secret(self, name, data, labels=None, driver=None):

        if not isinstance(data, bytes):
            data = data.encode('utf-8')

        data = base64.b64encode(data)
        if six.PY3:
            data = data.decode('ascii')
        body = {
            'Data': data,
            'Name': name,
            'Labels': labels
        }

        if driver is not None:
            if utils.version_lt(self._version, '1.31'):
                raise errors.InvalidVersion(
                    'Secret driver is only available for API version > 1.31'
                )

            body['Driver'] = driver

        url = self._url('/secrets/create')
        return self._result(
            self._post_json(url, data=body), True
        )

Create a secret

Args:
name (string): Name of the secret
data (bytes): Secret data to be stored
labels (dict): A mapping of labels to assign to the secret
driver (DriverConfig): A custom driver configuration. If
unspecified, the default ``internal`` driver will be used

Returns (dict): ID of the newly created secret


def normalize_full_name_true(decl):

    if decl.cache.normalized_full_name_true is None:
        decl.cache.normalized_full_name_true = normalize(
            declaration_utils.full_name(decl, with_defaults=True))
    return decl.cache.normalized_full_name_true

Cached variant of normalize

Args:
decl (declaration.declaration_t): the declaration

Returns:
str: normalized name


def enable_store_parameters_in_results(kernel):

  kernel_stack = []
  while hasattr(kernel, 'parameters') and 'inner_kernel' in kernel.parameters:
    kernel_stack.append(kernel)
    kernel = kernel.parameters['inner_kernel']

  def _recreate_kernel(kernel, parameters):
    new_parameters = kernel.parameters.copy()
    new_parameters.update(parameters)
    if 'store_parameters_in_results' in new_parameters:
      new_parameters['store_parameters_in_results'] = True
    with deprecation.silence():
      return type(kernel)(**new_parameters)

  if hasattr(kernel, 'parameters'):
    kernel = _recreate_kernel(kernel, {})

  for outer_kernel in reversed(kernel_stack):
    outer_kernel = _recreate_kernel(outer_kernel, {'inner_kernel': kernel})
    kernel = outer_kernel

  return kernel

Enables the `store_parameters_in_results` parameter in a chain of kernels.

This is a temporary utility for use during the transition period of the
parameter storage methods.

Args:
kernel: A TransitionKernel.

Returns:
kernel: The same kernel, but recreated with `store_parameters_in_results`
recursively set to `True` in its parameters and its inner kernels (as
appropriate).


async def play(self, author, text_channel, query, index=None, stop_current=False, shuffle=False):

        if self.state == 'off':
            self.state = 'starting'
            self.prev_queue = []
            await self.set_topic("")

            await self.msetup(text_channel)

            await self.enqueue(query, index, stop_current, shuffle)

            await self.vsetup(author)

            self.state = 'ready' if self.mready and self.vready else 'off'
        else:

            await self.enqueue(query, index, stop_current, shuffle)

        if self.state == 'ready':
            if self.streamer is None:
                await self.vplay()

The play command

Args:
author (discord.Member): The member that called the command
text_channel (discord.Channel): The channel where the command was called
query (str): The argument that was passed with the command
index (str): Whether to play next or at the end of the queue
stop_current (bool): Whether to stop the currently playing song
shuffle (bool): Whether to shuffle the queue after starting


def is_mergeable_with(self, timeslots: 'TimeslotCollection') -> bool:

        for slot in timeslots.timeslots:
            for interval in self._table[slot.channel]:
                if slot.interval.has_overlap(interval):
                    return False
        return True

Return if self is mergeable with `timeslots`.

Args:
timeslots: TimeslotCollection to be checked


def _prefix_to_checkpoint_path(prefix, format_version):
    if format_version == saver_pb2.SaverDef.V2:
        return prefix + '.index'
    return prefix

Returns the pathname of a checkpoint file, given the checkpoint prefix.

For V1 checkpoint, simply returns the prefix itself (the data file).  For V2,
returns the pathname to the index file.

Args:
prefix: a string, the prefix of a checkpoint.
format_version: the checkpoint format version that corresponds to the
prefix.
Returns:
The pathname of a checkpoint file, taking into account the checkpoint
format version.


def touch(self, edited=False):

        self._dirty = True
        dt = datetime.datetime.utcnow()
        self.timestamps.updated = dt
        if edited:
            self.timestamps.edited = dt

Mark the node as dirty.

Args:
edited (bool): Whether to set the edited time.


def eye(N, M=None, k=0, dtype=None):
    return backend.numpy.eye(N, M=M, k=k, dtype=dtype)

Return a 2-D tensor with ones on the diagonal and zeros elsewhere.

Args:
N: Number of rows in the output.
M: Number of columns in the output. If `None`, defaults to `N`.
k: Index of the diagonal: 0 (the default) refers to the main
diagonal, a positive value refers to an upper diagonal,
and a negative value to a lower diagonal.
dtype: Data type of the returned tensor.

Returns:
Tensor with ones on the k-th diagonal and zeros elsewhere.


class PerceiverProjectionPostprocessor(nn.Module):

    def __init__(self, in_channels: int, out_channels: int) -> None:
        super().__init__()
        self.classifier = nn.Linear(in_channels, out_channels)

    def forward(self, inputs: torch.Tensor, pos: Optional[torch.Tensor]=None, modality_sizes=None) -> torch.Tensor:
        logits = self.classifier(inputs)
        return logits

Projection postprocessing for Perceiver. Can be used to project the channels of the decoder output to a lower
dimension.

Args:
in_channels (`int`):
Number of channels in the input.
out_channels (`int`):
Number of channels in the output.


def confusion_matrix(gold, pred, null_pred=False, null_gold=False, normalize=False, pretty_print=True):
    conf = ConfusionMatrix(null_pred=null_pred, null_gold=null_gold)
    gold = arraylike_to_numpy(gold)
    pred = arraylike_to_numpy(pred)
    conf.add(gold, pred)
    mat = conf.compile()
    if normalize:
        mat = (mat / len(gold))
    if pretty_print:
        conf.display(normalize=normalize)
    return mat

A shortcut method for building a confusion matrix all at once.

Args:
gold: an array-like of gold labels (ints)
pred: an array-like of predictions (ints)
null_pred: If True, include the row corresponding to null predictions
null_gold: If True, include the col corresponding to null gold labels
normalize: if True, divide counts by the total number of items
pretty_print: if True, pretty-print the matrix before returning


def configure_app(app, config=None, config_obj=None):
    app.config.from_object((config_obj or BaseConfig))
    if (config is not None):
        app.config.from_pyfile(config)

Configure application instance.

Args:
app (Flask): initialized Flask app instance
config (Optional[path]): path to a Python module config file
config_obj (Optional[class]): Python config object


def profile_write(self, profile, outfile=None):

        if outfile is None:
            outfile = '{}.json'.format(profile.get('profile_name').replace(' ', '_').lower())
        fqpn = os.path.join(self.profile_dir, outfile)

        if os.path.isfile(fqpn):

            print('Append to File: {}{}{}'.format(c.Style.BRIGHT, c.Fore.CYAN, fqpn))
            with open(fqpn, 'r+') as fh:
                try:
                    data = json.load(fh, object_pairs_hook=OrderedDict)
                except ValueError as e:
                    self.handle_error('Can not parse JSON data ({}).'.format(e))

                data.append(profile)
                fh.seek(0)
                fh.write(json.dumps(data, indent=2, sort_keys=True))
                fh.truncate()
        else:
            print('Create File: {}{}{}'.format(c.Style.BRIGHT, c.Fore.CYAN, fqpn))
            with open(fqpn, 'w') as fh:
                data = [profile]
                fh.write(json.dumps(data, indent=2, sort_keys=True))

Write the profile to the output directory.

Args:
profile (dict): The dictionary containting the profile settings.
outfile (str, optional): Defaults to None. The filename for the profile.


def add_weatherdata(self, data):

        if not isinstance(data, WeatherData):
            raise ValueError('Weather data need to be of type WeatherData')
        self._data["WEATHER DATA"].append(data)

Appends weather data.

Args:
data (WeatherData): weather data object


def load_local_config(filename):

    if not filename:
        return imp.new_module('local_pylint_config')
    module = imp.load_source('local_pylint_config', filename)
    return module

Loads the pylint.config.py file.

Args:
filename (str): The python file containing the local configuration.

Returns:
module: The loaded Python module.


def __init__(self, cell, monitored_section_name=None, avoid_repetitive_counting=False):
    self.cell = cell
    self.monitored_section_name = monitored_section_name
    self._avoid_repetitive_counting = avoid_repetitive_counting
    self._counting = True

Creates a new MonitoredTimer.

Args:
cell: the cell associated with the time metric that will be inremented.
monitored_section_name: name of action being monitored here.
avoid_repetitive_counting: when set to True, if already in a monitored
timer section with the same monitored_section_name, skip counting.


def get_percentile_to_value_dict(self, percentile_list):

        result = {}
        total = 0
        percentile_list_index = 0
        count_at_percentile = 0

        percentile_list = list(set(percentile_list))
        percentile_list.sort()

        for index in range(self.counts_len):
            total += self.get_count_at_index(index)
            while True:

                if not count_at_percentile:
                    if percentile_list_index == len(percentile_list):
                        return result
                    percentile = percentile_list[percentile_list_index]
                    percentile_list_index += 1
                    if percentile > 100:
                        return result
                    count_at_percentile = self.get_target_count_at_percentile(percentile)

                if total >= count_at_percentile:
                    value_at_index = self.get_value_from_index(index)
                    if percentile:
                        result[percentile] = self.get_highest_equivalent_value(value_at_index)
                    else:
                        result[percentile] = self.get_lowest_equivalent_value(value_at_index)
                    count_at_percentile = 0
                else:
                    break
        return result

A faster alternative to query values for a list of percentiles.

Args:
percentile_list: a list of percentiles in any order, dups will be ignored
each element in the list must be a float value in [0.0 .. 100.0]
Returns:
a dict of percentile values indexed by the percentile


def __init__(self, chrome_exe, port=9222, ignore_cert_errors=False):

        self.port = port
        self.chrome_exe = chrome_exe
        self.ignore_cert_errors = ignore_cert_errors
        self._shutdown = threading.Event()
        self.chrome_process = None

Initializes instance of this class.

Doesn't start the browser, start() does that.

Args:
chrome_exe: filesystem path to chrome/chromium executable
port: chrome debugging protocol port (default 9222)
ignore_cert_errors: configure chrome to accept all certs (default
False)


def sleep(self, seconds):
    until = (time.time() + seconds)
    try:
        while True:
            self._service_futures([], until)
    except TimeoutError:
        return

Services all futures while waiting

Args:
seconds (float): Time to wait


def refresh_state(self, id_or_uri, configuration, timeout=(- 1)):
    uri = (self._client.build_uri(id_or_uri) + self.REFRESH_STATE_PATH)
    return self._client.update(resource=configuration, uri=uri, timeout=timeout)

Refreshes a drive enclosure.

Args:
id_or_uri: Can be either the resource ID or the resource URI.
configuration: Configuration
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: Drive Enclosure


def set(self, key, value):

        self._full_config = None
        self._override[key] = value

Set a value in the `Bison` configuration.

Args:
key (str): The configuration key to set a new value for.
value: The value to set.


def get_clinvar_submission(store, institute_id, case_name, variant_id, submission_id):
    (institute_obj, case_obj) = institute_and_case(store, institute_id, case_name)
    pinned = [(store.variant(variant_id) or variant_id) for variant_id in case_obj.get('suspects', [])]
    variant_obj = store.variant(variant_id)
    clinvar_submission_objs = store.clinvars(submission_id=submission_id)
    return dict(today=str(date.today()), institute=institute_obj, case=case_obj, variant=variant_obj, pinned_vars=pinned, clinvars=clinvar_submission_objs)

Collects all variants from the clinvar submission collection with a specific submission_id

Args:
store(scout.adapter.MongoAdapter)
institute_id(str): Institute ID
case_name(str): case ID
variant_id(str): variant._id
submission_id(str): clinvar submission id, i.e. SUB76578

Returns:
A dictionary with all the data to display the clinvar_update.html template page


def get_resize_output_image_size(input_image: np.ndarray, size: Union[int, Tuple[int, int], List[int]], max_size: Optional[int]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> Tuple[int, int]:
    image_size = get_image_size(input_image, input_data_format)
    if isinstance(size, (list, tuple)):
        return size
    return get_size_with_aspect_ratio(image_size, size, max_size)

Computes the output image size given the input image size and the desired output size. If the desired output size
is a tuple or list, the output image size is returned as is. If the desired output size is an integer, the output
image size is computed by keeping the aspect ratio of the input image size.

Args:
input_image (`np.ndarray`):
The image to resize.
size (`int` or `Tuple[int, int]` or `List[int]`):
The desired output size.
max_size (`int`, *optional*):
The maximum allowed output size.
input_data_format (`ChannelDimension` or `str`, *optional*):
The channel dimension format of the input image. If not provided, it will be inferred from the input image.


def get_reachable_from_inputs(inputs, targets=None):
    inputs = nest.flatten(inputs, expand_composites=True)
    reachable = object_identity.ObjectIdentitySet(inputs)
    if targets:
        remaining_targets = object_identity.ObjectIdentitySet(nest.flatten(targets))
    queue = collections.deque(inputs)
    while queue:
        x = queue.pop()
        if isinstance(x, tuple(_user_convertible_tensor_types)):
            continue
        if isinstance(x, ops.Operation):
            outputs = x.outputs[:] or []
            outputs += x._control_outputs
        elif isinstance(x, variables.Variable):
            try:
                outputs = [x.op]
            except AttributeError:
                outputs = []
        elif tensor_util.is_tf_type(x):
            outputs = x.consumers()
        else:
            raise TypeError('Expected Operation, Variable, or Tensor, got ' + str(x))
        for y in outputs:
            if y not in reachable:
                reachable.add(y)
                if targets:
                    remaining_targets.discard(y)
                queue.appendleft(y)
        if targets and (not remaining_targets):
            return reachable
    return reachable

Returns the set of tensors/ops reachable from `inputs`.

Stops if all targets have been found (target is optional).

Only valid in Symbolic mode, not Eager mode.

Args:
inputs: List of tensors.
targets: List of tensors.

Returns:
A set of tensors reachable from the inputs (includes the inputs themselves).


def maybe_zero_out_padding(inputs, kernel_size, nonpadding_mask):

  if (kernel_size != 1 and kernel_size != (1, 1) and
      nonpadding_mask is not None):
    while nonpadding_mask.get_shape().ndims < inputs.get_shape().ndims:
      nonpadding_mask = tf.expand_dims(nonpadding_mask, -1)
    return inputs * nonpadding_mask

  return inputs

If necessary, zero out inputs to a conv for padding positions.

Args:
inputs: a Tensor with shape [batch, length, ...]
kernel_size: an integer or pair of integers
nonpadding_mask: a Tensor with shape [batch, length]

Returns:
Tensor of the same shape as inputs.


def __init__(self, operations: Iterable[raw_types.Operation] = ()) -> None:

        self.operations = tuple(operations)

        affected_qubits = [q for op in self.operations for q in op.qubits]
        self.qubits = frozenset(affected_qubits)
        if len(affected_qubits) != len(self.qubits):
            raise ValueError(
                'Overlapping operations: {}'.format(self.operations))

Constructs a moment with the given operations.

Args:
operations: The operations applied within the moment.
Will be frozen into a tuple before storing.

Raises:
ValueError: A qubit appears more than once.


def delete(self, paths):

    def _delete_path(path):

        try:
            if os.path.isdir(path):
                shutil.rmtree(path)
            else:
                os.remove(path)
        except OSError as err:
            raise IOError(err)
    exceptions = {}

    def try_delete(path):
        try:
            _delete_path(path)
        except Exception as e:
            exceptions[path] = e
    for match_result in self.match(paths):
        metadata_list = match_result.metadata_list
        if not metadata_list:
            exceptions[match_result.pattern] = IOError('No files found to delete under: %s' % match_result.pattern)
        for metadata in match_result.metadata_list:
            try_delete(metadata.path)
    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 construct_graph(sakefile, settings):

    verbose = settings["verbose"]
    sprint = settings["sprint"]
    G = nx.DiGraph()
    sprint("Going to construct Graph", level="verbose")
    for target in sakefile:
        if target == "all":

            continue
        if "formula" not in sakefile[target]:

            for atomtarget in sakefile[target]:
                if atomtarget == "help":
                    continue
                sprint("Adding '{}'".format(atomtarget), level="verbose")
                data_dict = sakefile[target][atomtarget]
                data_dict["parent"] = target
                G.add_node(atomtarget, **data_dict)
        else:
            sprint("Adding '{}'".format(target), level="verbose")
            G.add_node(target, **sakefile[target])
    sprint("Nodes are built\nBuilding connections", level="verbose")
    for node in G.nodes(data=True):
        sprint("checking node {} for dependencies".format(node[0]),
               level="verbose")

        for k, v in node[1].items():
            if v is None: node[1][k] = []
        if "output" in node[1]:
            for index, out in enumerate(node[1]['output']):
                node[1]['output'][index] = clean_path(node[1]['output'][index])
        if "dependencies" not in node[1]:
            continue
        sprint("it has dependencies", level="verbose")
        connects = []

        for index, dep in enumerate(node[1]['dependencies']):
            dep = os.path.normpath(dep)
            shrt = "dependencies"
            node[1]['dependencies'][index] = clean_path(node[1][shrt][index])
    for node in G.nodes(data=True):
        connects = []
        if "dependencies" not in node[1]:
            continue
        for dep in node[1]['dependencies']:
            matches = check_for_dep_in_outputs(dep, verbose, G)
            if not matches:
                continue
            for match in matches:
                sprint("Appending {} to matches".format(match), level="verbose")
                connects.append(match)
        if connects:
            for connect in connects:
                G.add_edge(connect, node[0])
    return G

Takes the sakefile dictionary and builds a NetworkX graph

Args:
A dictionary that is the parsed Sakefile (from sake.py)
The settings dictionary

Returns:
A NetworkX graph


def sorted(field_name, ascending=True, fields=None, count=5):
    if (field_name is None):
        raise Exception('Sort field must be specified')
    direction = ('' if ascending else ' DESC')
    projection = Sampling._create_projection(fields)
    return (lambda sql: ('SELECT %s FROM (%s) ORDER BY %s%s LIMIT %d' % (projection, sql, field_name, direction, count)))

Provides a sampling strategy that picks from an ordered set of rows.

Args:
field_name: the name of the field to sort the rows by.
ascending: whether to sort in ascending direction or not.
fields: an optional list of field names to retrieve.
count: optional number of rows to limit the sampled results to.
Returns:
A sampling function that can be applied to get the initial few rows.


def _gather_saveables_for_checkpoint(self):

    def _saveable_factory(name=self._common_name):
        return _DistributedVariableSaveable(self, self._primary, name)
    return {trackable.VARIABLE_VALUE_KEY: _saveable_factory}

Overrides Trackable method.

This allows both name-based and object-based save and restore of
DistributedVariables.

Returns:
A dictionary mapping attribute names to `SaveableObject` factories.


def from_obj(cls, cls_obj):

        if not cls_obj:
            return None

        typekey = cls.objkey(cls_obj)
        klass   = cls.entity_class(typekey)
        return klass.from_obj(cls_obj)

Parse the generateDS object and return an Entity instance.

This will attempt to extract type information from the input
object and pass it to entity_class to resolve the correct class
for the type.

Args:
cls_obj: A generateDS object.

Returns:
An Entity instance.


def _parse_target(target):
    if (len(target) != 8):
        raise ArgumentError('Invalid targeting data length', expected=8, length=len(target))
    (slot, match_op) = struct.unpack('<B6xB', target)
    if (match_op == _MATCH_CONTROLLER):
        return {'controller': True, 'slot': 0}
    elif (match_op == _MATCH_SLOT):
        return {'controller': False, 'slot': slot}
    raise ArgumentError('Unsupported complex targeting specified', match_op=match_op)

Parse a binary targeting information structure.

This function only supports extracting the slot number or controller from
the target and will raise an ArgumentError if more complicated targeting
is desired.

Args:
target (bytes): The binary targeting data blob.

Returns:
dict: The parsed targeting data


def save_path(self):
    return self._save_path

Return the save path used by the supervisor.

Returns:
A string.


def convert_to_shape(x):

  if x is None:
    return None
  if isinstance(x, Shape):
    return x
  if isinstance(x, str):
    x = _parse_string_to_list_of_pairs(x, seconds_to_int=True)
  return Shape(x)

Converts input to a Shape.

Args:
x: Shape, str, or None.

Returns:
Shape or None.

Raises:
ValueError: If x cannot be converted to a Shape.


def structure_path(self, path):

        if not path:
            self.structure_dir = None
            self.structure_file = None

        else:
            if not op.exists(path):
                raise OSError('{}: file does not exist!'.format(path))

            if not op.dirname(path):
                self.structure_dir = '.'
            else:
                self.structure_dir = op.dirname(path)
            self.structure_file = op.basename(path)

Provide pointers to the paths of the structure file

Args:
path: Path to structure file


def __init__(self, usr_config, req_file):
    self.usr_config = usr_config
    self.req_file = req_file
    self.warning_msg = []
    self.error_msg = []
    reqs_all = self.get_all_reqs()
    self.required = reqs_all['required']
    self.optional = reqs_all['optional']
    self.unsupported = reqs_all['unsupported']
    self.dependency = reqs_all['dependency']
    self.successes = []
    self.failures = []

Initializes a configuration compatibility checker.

Args:
usr_config: Dict of all configuration(s) whose version compatibilities are
to be checked against the rules defined in the `.ini` config
file.
req_file: String that is the full name of the `.ini` config file.
e.g. `config.ini`


def get_id(date=None, project: str='sip', instance_id: int=None) -> str:
    if (date is None):
        date = datetime.datetime.utcnow()
    if isinstance(date, datetime.datetime):
        date = date.strftime('%Y%m%d')
    if (instance_id is None):
        instance_id = randint(0, 9999)
    return 'SBI-{}-{}-{:04d}'.format(date, project, instance_id)

Get a SBI Identifier.

Args:
date (str or datetime.datetime, optional): UTC date of the SBI
project (str, optional ): Project Name
instance_id (int, optional): SBI instance identifier

Returns:
str, Scheduling Block Instance (SBI) ID.


def composite_tensor_from_variant(encoded, type_spec, name=None):
    if not isinstance(encoded, tensor.Tensor):
        raise TypeError(f'Expected `encoded` to be a Tensor, got {encoded!r}.')
    if encoded.dtype != dtypes.variant:
        raise TypeError(f'Expected `encoded` to have dtype=variant, got {encoded!r}.')
    encoded.shape.assert_is_compatible_with(())
    metadata = composite_tensor_variant_pb2.CompositeTensorVariantMetadata()
    metadata.type_spec_proto.CopyFrom(nested_structure_coder.encode_structure(type_spec).type_spec_value)
    component_dtypes = [t.dtype for t in nest.flatten(type_spec, expand_composites=True)]
    components = gen_composite_tensor_ops.CompositeTensorVariantToComponents(encoded=encoded, metadata=metadata.SerializeToString(), Tcomponents=component_dtypes, name=name)
    return nest.pack_sequence_as(type_spec, components, expand_composites=True)

Returns the `ExtensionType` value encoded by a variant scalar tensor.

Args:
encoded: A Tensor returned by `composite_tensor_to_variants`.
type_spec: The `TypeSpec` of the original value.  This is used to determine
the number and types of the component tensors that comprise the decoded
value.  Must be compatible with the `TypeSpec` serilized in `encoded`.
name: Optional name for the operation.

Returns:
An `ExtensionType` value that is compatible with `TypeSpec`.

Raises:
TypeError: If `encoded` is not a Tensor with dtype=variant.
InvalidArgumentError: If `encoded` is not compatible with `type_spec`.


def replace_recursive(spec, vars):
    if isinstance(spec, dict):
        return {key: replace_recursive(value, vars) for key, value in spec.items()}
    elif isinstance(spec, list):
        return [replace_recursive(value, vars) for value in spec]
    elif isinstance(spec, str) and '{' in spec and ('{\n' not in spec) and ('lambda' not in spec):
        try:
            return spec.format(**vars)
        except Exception as exn:
            raise ValueError(f'Error evaluating {spec}: {exn}') from exn
    else:
        return spec

Recursively replaces string placeholders in a spec with values from vars.

Traverses a nested structure (dicts, lists, or other types). If a string
is encountered and contains placeholders in the format '{key}', it attempts
to replace them using the `vars` dictionary.

Args:
spec: The (potentially nested) structure to process.
vars: A dictionary of variable names to their replacement values.

Returns:
The spec with placeholders replaced.

Raises:
ValueError: If a string formatting error occurs.


def __init__(self, data_path, models, encoding=None, markdown_config=None,
            error_context=None):

        self.encoding = encoding
        self.tables = dict()
        self.data_path = data_path
        self.models = models
        self.markdown_config = markdown_config
        self.error_context = error_context or StatikErrorContext()
        self.engine = create_engine('sqlite:
        self.Base = declarative_base()
        self.session = sessionmaker(bind=self.engine)()
        set_global('session', self.session)
        self.find_backrefs()
        self.create_db(models)

Constructor.

Args:
data_path: The full path to where the database files can be found.
models: Loaded model/field data.
encoding: The encoding to load files as ('utf-8', etc). If 'None', will
default to the system-preferred default encoding.
error_context: An optional StatikErrorContext instance for keeping track of
the files to which any exceptions are relevant.


def ctype_to_dtype(cl_type, mot_float_type='float'):

    if is_vector_ctype(cl_type):
        raw_type, vector_length = split_vector_ctype(cl_type)

        if raw_type == 'mot_float_type':
            if is_vector_ctype(mot_float_type):
                raw_type, _ = split_vector_ctype(mot_float_type)
            else:
                raw_type = mot_float_type

        vector_type = raw_type + str(vector_length)
        return getattr(cl_array.vec, vector_type)
    else:
        if cl_type == 'mot_float_type':
            cl_type = mot_float_type

        data_types = [
            ('char', np.int8),
            ('uchar', np.uint8),
            ('short', np.int16),
            ('ushort', np.uint16),
            ('int', np.int32),
            ('uint', np.uint32),
            ('long', np.int64),
            ('ulong', np.uint64),
            ('float', np.float32),
            ('double', np.float64),
        ]
        for ctype, dtype in data_types:
            if ctype == cl_type:
                return dtype

Get the numpy dtype of the given cl_type string.

Args:
cl_type (str): the CL data type to match, for example 'float' or 'float4'.
mot_float_type (str): the C name of the ``mot_float_type``. The dtype will be looked up recursively.

Returns:
dtype: the numpy datatype


def add_element(self, element):

        if isinstance(element, BaseExpression):
            element.set_parent(self._working_fragment)
            self._working_fragment.elements.append(element)
            return self
        else:
            return self.add_operator(element)

Add an element of type ``Operator``, ``Constraint``, or
``Expression`` to the ``Expression``.

Args:
element: ``Constraint``, ``Expression``, or ``Operator``.

Returns:
Expression: ``self``

Raises:
FiqlObjectException: Element is not a valid type.


def draw_circle(self, x, y, r, color):

        check_int_err(lib.circleRGBA(self._ptr, x, y, r, color[0], color[1], color[2], color[3]))

Draw a circle.

Args:
x (int): The x coordinate of the center of the circle.
y (int): The y coordinate of the center of the circle.
r (int): The radius of the circle.
color (Tuple[int, int, int, int]): The color of the circle.

Raises:
SDLError: If an error is encountered.


def WriteConfig(self, config_file=None):
    config_file = (config_file or self.config_file)
    config_name = os.path.splitext(os.path.basename(config_file))[0]
    config_lock = ('%s/lock/google_%s.lock' % (constants.LOCALSTATEDIR, config_name))
    with file_utils.LockFile(config_lock):
        with open(config_file, 'w') as config_fp:
            if self.config_header:
                self._AddHeader(config_fp)
            self.config.write(config_fp)

Write the config values to a given file.

Args:
config_file: string, the file location of the config file to write.


def construct_all(templates, **unbound_var_values):

    def _merge_dicts(src, dst):
        for (k, v) in six.iteritems(src):
            if (dst.get(k, v) != v):
                raise ValueError(('Conflicting values bound for %s: %s and %s' % (k, v, dst[k])))
            else:
                dst[k] = v
    all_unbound_vars = {}
    context = {}
    for x in templates:
        if isinstance(x, _DeferredLayer):
            _merge_unbound_var_dicts(x.unbound_vars, all_unbound_vars)
            _merge_dicts(x._partial_context, context)
        else:
            raise TypeError(('Unexpected type: %s' % type(x)))
    _merge_dicts(_assign_values_to_unbound_vars(all_unbound_vars, unbound_var_values), context)
    result = list(templates)
    for (i, x) in enumerate(result):
        if isinstance(x, _DeferredLayer):
            result[i] = x._construct(context)
    return result

Constructs all the given templates in a single pass without redundancy.

This is useful when the templates have a common substructure and you want the
smallest possible graph.

Args:
templates: A sequence of templates.
**unbound_var_values: The unbound_var values to replace.
Returns:
A list of results corresponding to templates.
Raises:
TypeError: If any value in templates is unsupported.
ValueError: If the unbound_var values specified are not complete or contain
unknown values.


def _on_queue_declareok(self, frame):

        _log.info("Successfully declared the %s queue", frame.method.queue)
        for binding in self._bindings:
            if binding["queue"] == frame.method.queue:
                for key in binding["routing_keys"]:
                    _log.info(
                        "Asserting %s is bound to %s with the %s key",
                        binding["queue"],
                        binding["exchange"],
                        key,
                    )
                    self._channel.queue_bind(
                        callback=None,
                        queue=binding["queue"],
                        exchange=binding["exchange"],
                        routing_key=key,
                    )
                bc_args = dict(queue=frame.method.queue)
                if _pika_version < pkg_resources.parse_version("1.0.0b1"):
                    bc_args["consumer_callback"] = self._on_message
                else:
                    bc_args["on_message_callback"] = self._on_message
                tag = self._channel.basic_consume(**bc_args)
                self._consumers[tag] = binding["queue"]

Callback invoked when a queue is successfully declared.

Args:
frame (pika.frame.Method): The message sent from the server.


def clean_lines(string_list, remove_empty_lines=True):

    for s in string_list:
        clean_s = s
        if '
            ind = s.index('
            clean_s = s[:ind]
        clean_s = clean_s.strip()
        if (not remove_empty_lines) or clean_s != '':
            yield clean_s

Strips whitespace, carriage returns and empty lines from a list of strings.

Args:
string_list: List of strings
remove_empty_lines: Set to True to skip lines which are empty after
stripping.

Returns:
List of clean strings with no whitespaces.


def __init__(self,
                 line: int, prefix_length: int,
                 option_suffix: Text = '') -> None:

        super().__init__(prefix_length, option_suffix)
        self._line = line

Create a new instance.

Args:
line:
the line to extract, counting from zero
prefix_length:
Amount of characters to skip at the beginning of the line
option_suffix:
Suffix for each configuration option


def mpim_open(self, *, users: List[str], **kwargs) -> SlackResponse:
    kwargs.update({'users': users})
    return self.api_call('mpim.open', json=kwargs)

This method opens a multiparty direct message.

Args:
users (list): A lists of user ids. The ordering of the users
is preserved whenever a MPIM group is returned.
e.g. ['W1234567890', 'U2345678901', 'U3456789012']


def export(self, top=True):

        out = []
        if top:
            out.append(self._internal_name)
        out.append(self._to_str(self.title_of_design_condition))
        out.append(self._to_str(self.unkown_field))
        out.append(self._to_str(self.design_stat_heating))
        out.append(self._to_str(self.coldestmonth))
        out.append(self._to_str(self.db996))
        out.append(self._to_str(self.db990))
        out.append(self._to_str(self.dp996))
        out.append(self._to_str(self.hr_dp996))
        out.append(self._to_str(self.db_dp996))
        out.append(self._to_str(self.dp990))
        out.append(self._to_str(self.hr_dp990))
        out.append(self._to_str(self.db_dp990))
        out.append(self._to_str(self.ws004c))
        out.append(self._to_str(self.db_ws004c))
        out.append(self._to_str(self.ws010c))
        out.append(self._to_str(self.db_ws010c))
        out.append(self._to_str(self.ws_db996))
        out.append(self._to_str(self.wd_db996))
        out.append(self._to_str(self.design_stat_cooling))
        out.append(self._to_str(self.hottestmonth))
        out.append(self._to_str(self.dbr))
        out.append(self._to_str(self.db004))
        out.append(self._to_str(self.wb_db004))
        out.append(self._to_str(self.db010))
        out.append(self._to_str(self.wb_db010))
        out.append(self._to_str(self.db020))
        out.append(self._to_str(self.wb_db020))
        out.append(self._to_str(self.wb004))
        out.append(self._to_str(self.db_wb004))
        out.append(self._to_str(self.wb010))
        out.append(self._to_str(self.db_wb010))
        out.append(self._to_str(self.wb020))
        out.append(self._to_str(self.db_wb020))
        out.append(self._to_str(self.ws_db004))
        out.append(self._to_str(self.wd_db004))
        out.append(self._to_str(self.dp004))
        out.append(self._to_str(self.hr_dp004))
        out.append(self._to_str(self.db_dp004))
        out.append(self._to_str(self.dp010))
        out.append(self._to_str(self.hr_dp010))
        out.append(self._to_str(self.db_dp010))
        out.append(self._to_str(self.dp020))
        out.append(self._to_str(self.hr_dp020))
        out.append(self._to_str(self.db_dp020))
        out.append(self._to_str(self.en004))
        out.append(self._to_str(self.db_en004))
        out.append(self._to_str(self.en010))
        out.append(self._to_str(self.db_en010))
        out.append(self._to_str(self.en020))
        out.append(self._to_str(self.db_en020))
        out.append(self._to_str(self.hrs_84_and_db12_8_or_20_6))
        out.append(self._to_str(self.design_stat_extremes))
        out.append(self._to_str(self.ws010))
        out.append(self._to_str(self.ws025))
        out.append(self._to_str(self.ws050))
        out.append(self._to_str(self.wbmax))
        out.append(self._to_str(self.dbmin_mean))
        out.append(self._to_str(self.dbmax_mean))
        out.append(self._to_str(self.dbmin_stddev))
        out.append(self._to_str(self.dbmax_stddev))
        out.append(self._to_str(self.dbmin05years))
        out.append(self._to_str(self.dbmax05years))
        out.append(self._to_str(self.dbmin10years))
        out.append(self._to_str(self.dbmax10years))
        out.append(self._to_str(self.dbmin20years))
        out.append(self._to_str(self.dbmax20years))
        out.append(self._to_str(self.dbmin50years))
        out.append(self._to_str(self.dbmax50years))
        return ",".join(out)

Exports object to its string representation.

Args:
top (bool):  if True appends `internal_name` before values.
All non list objects should be exported with value top=True,
all list objects, that are embedded in as fields inlist objects
should be exported with `top`=False

Returns:
str: The objects string representation