def notify_program_learners(cls, enterprise_customer, program_details, users):
    program_name = program_details.get('title')
    program_branding = program_details.get('type')
    program_uuid = program_details.get('uuid')
    lms_root_url = get_configuration_value_for_site(enterprise_customer.site, 'LMS_ROOT_URL', settings.LMS_ROOT_URL)
    program_path = urlquote('/dashboard/programs/{program_uuid}/?tpa_hint={tpa_hint}'.format(program_uuid=program_uuid, tpa_hint=enterprise_customer.identity_provider))
    destination_url = '{site}/{login_or_register}?next={program_path}'.format(site=lms_root_url, login_or_register='{login_or_register}', program_path=program_path)
    program_type = 'program'
    program_start = get_earliest_start_date_from_program(program_details)
    with mail.get_connection() as email_conn:
        for user in users:
            login_or_register = ('register' if isinstance(user, PendingEnterpriseCustomerUser) else 'login')
            destination_url = destination_url.format(login_or_register=login_or_register)
            send_email_notification_message(user=user, enrolled_in={'name': program_name, 'url': destination_url, 'type': program_type, 'start': program_start, 'branding': program_branding}, enterprise_customer=enterprise_customer, email_connection=email_conn)

Notify learners about a program in which they've been enrolled.

Args:
enterprise_customer: The EnterpriseCustomer being linked to
program_details: Details about the specific program the learners were enrolled in
users: An iterable of the users or pending users who were enrolled


def format_import(self, source_module_name, source_name, dest_name):
    if self._lazy_loading:
        return "  '%s': ('%s', '%s')," % (dest_name, source_module_name, source_name)
    elif source_module_name:
        if source_name == dest_name:
            return 'from %s import %s' % (source_module_name, source_name)
        else:
            return 'from %s import %s as %s' % (source_module_name, source_name, dest_name)
    elif source_name == dest_name:
        return 'import %s' % source_name
    else:
        return 'import %s as %s' % (source_name, dest_name)

Formats import statement.

Args:
source_module_name: (string) Source module to import from.
source_name: (string) Source symbol name to import.
dest_name: (string) Destination alias name.

Returns:
An import statement string.


def find_customer(cls, session, mailbox, customer):

        return cls(
            '/mailboxes/%d/customers/%s/conversations.json' % (
                mailbox.id, customer.id,
            ),
            session=session,
        )

Return conversations for a specific customer in a mailbox.

Args:
session (requests.sessions.Session): Authenticated session.
mailbox (helpscout.models.Mailbox): Mailbox to search.
customer (helpscout.models.Customer): Customer to search for.

Returns:
RequestPaginator(output_type=helpscout.models.Conversation):
Conversations iterator.


def _GetVisitSource(self, visit_identifier, cache, database):
    sync_cache_results = cache.GetResults('sync')
    if (not sync_cache_results):
        result_set = database.Query(self._SYNC_CACHE_QUERY)
        cache.CacheQueryResults(result_set, 'sync', 'id', ('source',))
        sync_cache_results = cache.GetResults('sync')
    if (sync_cache_results and visit_identifier):
        results = sync_cache_results.get(visit_identifier, None)
        if results:
            return results[0]
    return None

Retrieves a visit source type based on the identifier.

Args:
visit_identifier (str): identifier from the visits table for the
particular record.
cache (SQLiteCache): cache which contains cached results from querying
the visit_source table.
database (SQLiteDatabase): database.

Returns:
int: visit source type or None if no visit source type was found for
the identifier.


def plot(self, event_names, x_axis='step'):

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

    events_list = self.get_events(event_names)
    for event_name, dir_event_dict in zip(event_names, events_list):
      for dir, df in six.iteritems(dir_event_dict):
        label = event_name + ':' + dir
        x_column = df['step'] if x_axis == 'step' else df['time']
        plt.plot(x_column, df['value'], label=label)
    plt.legend(loc='best')
    plt.show()

Plots a list of events. Each event (a dir+event_name) is represetented as a line
in the graph.
Args:
event_names: A list of events to plot. Each event_name may correspond to multiple events,
each in a different directory.
x_axis: whether to use step or time as x axis.


def update_environmental_configuration(self, configuration, timeout=-1):

        uri = '{}/environmentalConfiguration'.format(self.data['uri'])
        return self._helper.do_put(uri, configuration, timeout, None)

Sets the calibrated max power of an unmanaged or unsupported enclosure.

Args:
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:
Settings that describe the environmental configuration.


def is_end_node(node):
    return (isinstance(node, ast.Expr) and isinstance(node.value, ast.Name) and (node.value.id == 'end'))

Checks if a node is the "end" keyword.

Args:
node: AST node.

Returns:
True if the node is the "end" keyword, otherwise False.


def RegisterOutput(cls, output_class, disabled=False):

    output_name = output_class.NAME.lower()

    if disabled:
      class_dict = cls._disabled_output_classes
    else:
      class_dict = cls._output_classes

    if output_name in class_dict:
      raise KeyError((
          'Output class already set for name: {0:s}.').format(
              output_class.NAME))

    class_dict[output_name] = output_class

Registers an output class.

The output classes are identified based on their NAME attribute.

Args:
output_class (type): output module class.
disabled (Optional[bool]): True if the output module is disabled due to
the module not loading correctly or not.

Raises:
KeyError: if output class is already set for the corresponding name.


def __savorize(self, node: yaml.Node, expected_type: Type) -> yaml.Node:

        logger.debug('Savorizing node assuming type {}'.format(
            expected_type.__name__))

        for base_class in expected_type.__bases__:
            if base_class in self._registered_classes.values():
                node = self.__savorize(node, base_class)

        if hasattr(expected_type, 'yatiml_savorize'):
            logger.debug('Calling {}.yatiml_savorize()'.format(
                expected_type.__name__))
            cnode = Node(node)
            expected_type.yatiml_savorize(cnode)
            node = cnode.yaml_node
        return node

Removes syntactic sugar from the node.

This calls yatiml_savorize(), first on the class's base \
classes, then on the class itself.

Args:
node: The node to modify.
expected_type: The type to assume this type is.


def _ListFileEntry(
      self, file_system, file_entry, parent_full_path, output_writer):

    full_path = file_system.JoinPath([parent_full_path, file_entry.name])
    if not self._list_only_files or file_entry.IsFile():
      output_writer.WriteFileEntry(full_path)

    for sub_file_entry in file_entry.sub_file_entries:
      self._ListFileEntry(file_system, sub_file_entry, full_path, output_writer)

Lists a file entry.

Args:
file_system (dfvfs.FileSystem): file system that contains the file entry.
file_entry (dfvfs.FileEntry): file entry to list.
parent_full_path (str): full path of the parent file entry.
output_writer (StdoutWriter): output writer.


def lattice_points_in_supercell(supercell_matrix):

    diagonals = np.array(
        [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1],
         [1, 1, 0], [1, 1, 1]])
    d_points = np.dot(diagonals, supercell_matrix)

    mins = np.min(d_points, axis=0)
    maxes = np.max(d_points, axis=0) + 1

    ar = np.arange(mins[0], maxes[0])[:, None] * \
         np.array([1, 0, 0])[None, :]
    br = np.arange(mins[1], maxes[1])[:, None] * \
         np.array([0, 1, 0])[None, :]
    cr = np.arange(mins[2], maxes[2])[:, None] * \
         np.array([0, 0, 1])[None, :]

    all_points = ar[:, None, None] + br[None, :, None] + cr[None, None, :]
    all_points = all_points.reshape((-1, 3))

    frac_points = np.dot(all_points, np.linalg.inv(supercell_matrix))

    tvects = frac_points[np.all(frac_points < 1 - 1e-10, axis=1)
                         & np.all(frac_points >= -1e-10, axis=1)]
    assert len(tvects) == round(abs(np.linalg.det(supercell_matrix)))
    return tvects

Returns the list of points on the original lattice contained in the
supercell in fractional coordinates (with the supercell basis).
e.g. [[2,0,0],[0,1,0],[0,0,1]] returns [[0,0,0],[0.5,0,0]]

Args:
supercell_matrix: 3x3 matrix describing the supercell

Returns:
numpy array of the fractional coordinates


def pair_wise_sigmoid_cross_entropy_loss(inputs: torch.Tensor, labels: torch.Tensor) -> torch.Tensor:
    height_and_width = inputs.shape[1]
    criterion = nn.BCEWithLogitsLoss(reduction='none')
    cross_entropy_loss_pos = criterion(inputs, torch.ones_like(inputs))
    cross_entropy_loss_neg = criterion(inputs, torch.zeros_like(inputs))
    loss_pos = torch.matmul(cross_entropy_loss_pos / height_and_width, labels.T)
    loss_neg = torch.matmul(cross_entropy_loss_neg / height_and_width, (1 - labels).T)
    loss = loss_pos + loss_neg
    return loss

A pair wise version of the cross entropy loss, see `sigmoid_cross_entropy_loss` for usage.

Args:
inputs (`torch.Tensor`):
A tensor representing a mask.
labels (`torch.Tensor`):
A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
(0 for the negative class and 1 for the positive class).

Returns:
loss (`torch.Tensor`): The computed loss between each pairs.


def get(self, key):
    if key in self._feature_tensors:
        return self._feature_tensors[key]
    if key in self._features:
        feature_tensor = self._get_raw_feature_as_tensor(key)
        self._feature_tensors[key] = feature_tensor
        return feature_tensor
    if isinstance(key, six.string_types):
        raise ValueError('Feature {} is not in features dictionary.'.format(key))
    if not isinstance(key, _FeatureColumn):
        raise TypeError('"key" must be either a "str" or "_FeatureColumn". Provided: {}'.format(key))
    column = key
    logging.debug('Transforming feature_column %s.', column)
    transformed = column._transform_feature(self)
    if transformed is None:
        raise ValueError('Column {} is not supported.'.format(column.name))
    self._feature_tensors[column] = transformed
    return transformed

Returns a `Tensor` for the given key.

A `str` key is used to access a base feature (not-transformed). When a
`_FeatureColumn` is passed, the transformed feature is returned if it
already exists, otherwise the given `_FeatureColumn` is asked to provide its
transformed output, which is then cached.

Args:
key: a `str` or a `_FeatureColumn`.

Returns:
The transformed `Tensor` corresponding to the `key`.

Raises:
ValueError: if key is not found or a transformed `Tensor` cannot be
computed.


def DEFINE_list(name, default, help, flag_values=FLAGS, **args):
    parser = ListParser()
    serializer = CsvListSerializer(',')
    DEFINE(parser, name, default, help, flag_values, serializer, **args)

Registers a flag whose value is a comma-separated list of strings.

The flag value is parsed with a CSV parser.

Args:
name: A string, the flag name.
default: The default value of the flag.
help: A help string.
flag_values: FlagValues object with which the flag will be registered.
**args: Dictionary with extra keyword args that are passed to the
Flag __init__.


def _build_rdf(self, data=None):

		self.rdf = SimpleNamespace()
		self.rdf.data = data
		self.rdf.prefixes = SimpleNamespace()
		self.rdf.uris = SimpleNamespace()

		for prefix,uri in self.repo.context.items():
			setattr(self.rdf.prefixes, prefix, rdflib.Namespace(uri))

		self._parse_graph()

Parse incoming rdf as self.rdf.orig_graph, create copy at self.rdf.graph

Args:
data (): payload from GET request, expected RDF content in various serialization formats

Returns:
None


def LookupClients(self, keywords):

    if isinstance(keywords, string_types):
      raise ValueError(
          "Keywords should be an iterable, not a string (got %s)." % keywords)

    start_time, filtered_keywords = self._AnalyzeKeywords(keywords)

    keyword_map = data_store.REL_DB.ListClientsForKeywords(
        list(map(self._NormalizeKeyword, filtered_keywords)),
        start_time=start_time)

    results = itervalues(keyword_map)
    relevant_set = set(next(results))

    for hits in results:
      relevant_set &= set(hits)

      if not relevant_set:
        return []

    return sorted(relevant_set)

Returns a list of client URNs associated with keywords.

Args:
keywords: The list of keywords to search by.

Returns:
A list of client URNs.

Raises:
ValueError: A string (single keyword) was passed instead of an iterable.


def guess_is_tensorflow_py_library(py_file_path):
    if not is_extension_uncompiled_python_source(py_file_path) and (not is_extension_compiled_python_source(py_file_path)):
        return False
    py_file_path = _norm_abs_path(py_file_path)
    return (py_file_path.startswith(_TENSORFLOW_BASEDIR) or py_file_path.startswith(_ABSL_BASEDIR)) and (not py_file_path.endswith('_test.py')) and (os.path.normpath('tensorflow/python/debug/examples') not in os.path.normpath(py_file_path))

Guess whether a Python source file is a part of the tensorflow library.

Special cases:
1) Returns False for unit-test files in the library (*_test.py),
2) Returns False for files under python/debug/examples.

Args:
py_file_path: full path of the Python source file in question.

Returns:
(`bool`) Whether the file is inferred to be a part of the tensorflow
library.


def reset(self, indices=None):

    if indices is None:
      indices = np.arange(self.trajectories.batch_size)

    if indices.size == 0:
      tf.logging.warning(
          "`reset` called with empty indices array, this is a no-op.")
      return None

    observations = self._reset(indices)
    processed_observations = self.process_observations(observations)

    self.trajectories.reset(indices, observations)

    return processed_observations

Resets environments at given indices.

Subclasses should override _reset to do the actual reset if something other
than the default implementation is desired.

Args:
indices: Indices of environments to reset. If None all envs are reset.

Returns:
Batch of initial observations of reset environments.


def bgr2gray(img, keepdim=False):
    out_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    if keepdim:
        out_img = out_img[(..., None)]
    return out_img

Convert a BGR image to grayscale image.

Args:
img (ndarray): The input image.
keepdim (bool): If False (by default), then return the grayscale image
with 2 dims, otherwise 3 dims.

Returns:
ndarray: The converted grayscale image.


def glu(x, axis=-1):
    if any_symbolic_tensors((x,)):
        return Glu(axis).symbolic_call(x)
    return backend.nn.glu(x, axis=axis)

Gated Linear Unit (GLU) activation function.

It is defined as:

`f(x) = a * sigmoid(b)`
where `x` is split into `a` and `b` along the given axis.

Args:
x: Input tensor.
axis: The axis along which to split the input tensor. Defaults to `-1`.

Returns:
A tensor with the same shape as half of the input.

Example:

>>> x = np.array([-1., 0., 1. , 1.])
>>> x_glu = keras.ops.glu(x)
>>> print(x_glu)
array([-0.73105858, 0. ], shape=(2,), dtype=float64)


def swo_start(self, swo_speed=9600):
    if self.swo_enabled():
        self.swo_stop()
    info = structs.JLinkSWOStartInfo()
    info.Speed = swo_speed
    res = self._dll.JLINKARM_SWO_Control(enums.JLinkSWOCommands.START, ctypes.byref(info))
    if (res < 0):
        raise errors.JLinkException(res)
    self._swo_enabled = True
    return None

Starts collecting SWO data.

Note:
If SWO is already enabled, it will first stop SWO before enabling it
again.

Args:
self (JLink): the ``JLink`` instance
swo_speed (int): the frequency in Hz used by the target to communicate

Returns:
``None``

Raises:
JLinkException: on error


def _fn(arg0, arg1):
    return arg0 + arg1

fn doc.

Args:
arg0: Arg 0.
arg1: Arg 1.

Returns:
Sum of args.


def format(self, record):

    if (not FLAGS['showprefixforinfo'].value and
        FLAGS['verbosity'].value == converter.ABSL_INFO and
        record.levelno == logging.INFO and
        _absl_handler.python_handler.stream == sys.stderr):
      prefix = ''
    else:
      prefix = get_absl_log_prefix(record)
    return prefix + super(PythonFormatter, self).format(record)

Appends the message from the record to the results of the prefix.

Args:
record: logging.LogRecord, the record to be formatted.

Returns:
The formatted string representing the record.


def dvd_lists(self, **kwargs):
    path = self._get_path('dvd_lists')
    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response

Gets the dvd lists available from the API.

Returns:
A dict respresentation of the JSON returned from the API.


def box_draw_character(first: Optional[BoxDrawCharacterSet], second: BoxDrawCharacterSet, *, top: int=0, bottom: int=0, left: int=0, right: int=0) -> Optional[str]:
    if (first is None):
        first = second
    sign = (+ 1)
    combo = None
    if ((first is NORMAL_BOX_CHARS) and (second is BOLD_BOX_CHARS)):
        combo = NORMAL_THEN_BOLD_MIXED_BOX_CHARS
    if ((first is BOLD_BOX_CHARS) and (second is NORMAL_BOX_CHARS)):
        combo = NORMAL_THEN_BOLD_MIXED_BOX_CHARS
        sign = (- 1)
    if (combo is None):
        choice = (second if ((+ 1) in [top, bottom, left, right]) else first)
        return choice.char(top=bool(top), bottom=bool(bottom), left=bool(left), right=bool(right))
    return combo.char(top=(top * sign), bottom=(bottom * sign), left=(left * sign), right=(right * sign))

Finds a box drawing character based on its connectivity.

For example:

box_draw_character(
NORMAL_BOX_CHARS,
BOLD_BOX_CHARS,
top=-1,
right=+1)

evaluates to '┕', which has a normal upward leg and bold rightward leg.

Args:
first: The character set to use for legs set to -1. If set to None,
defaults to the same thing as the second character set.
second: The character set to use for legs set to +1.
top: Whether the upward leg should be present.
bottom: Whether the bottom leg should be present.
left: Whether the left leg should be present.
right: Whether the right leg should be present.

Returns:
A box drawing character approximating the desired properties, or None
if all legs are set to 0.


def get_reference_points(spatial_shapes, valid_ratios, device):
    reference_points_list = []
    for level, (height, width) in enumerate(spatial_shapes):
        ref_y, ref_x = meshgrid(torch.linspace(0.5, height - 0.5, height, dtype=torch.float32, device=device), torch.linspace(0.5, width - 0.5, width, dtype=torch.float32, device=device), indexing='ij')
        ref_y = ref_y.reshape(-1)[None] / (valid_ratios[:, None, level, 1] * height)
        ref_x = ref_x.reshape(-1)[None] / (valid_ratios[:, None, level, 0] * width)
        ref = torch.stack((ref_x, ref_y), -1)
        reference_points_list.append(ref)
    reference_points = torch.cat(reference_points_list, 1)
    reference_points = reference_points[:, :, None] * valid_ratios[:, None]
    return reference_points

Get reference points for each feature map.

Args:
spatial_shapes (`torch.LongTensor` of shape `(num_feature_levels, 2)`):
Spatial shapes of each feature map.
valid_ratios (`torch.FloatTensor` of shape `(batch_size, num_feature_levels, 2)`):
Valid ratios of each feature map.
device (`torch.device`):
Device on which to create the tensors.
Returns:
`torch.FloatTensor` of shape `(batch_size, num_queries, num_feature_levels, 2)`


def read(self, size=-1):

    self._check_open()
    if not self._remaining():
      return ''

    data_list = []
    while True:
      remaining = self._buffer.remaining()
      if size >= 0 and size < remaining:
        data_list.append(self._buffer.read(size))
        self._offset += size
        break
      else:
        size -= remaining
        self._offset += remaining
        data_list.append(self._buffer.read())

        if self._buffer_future is None:
          if size < 0 or size >= self._remaining():
            needs = self._remaining()
          else:
            needs = size
          data_list.extend(self._get_segments(self._offset, needs))
          self._offset += needs
          break

        if self._buffer_future:
          self._buffer.reset(self._buffer_future.get_result())
          self._buffer_future = None

    if self._buffer_future is None:
      self._request_next_buffer()
    return ''.join(data_list)

Read data from RAW file.

Args:
size: Number of bytes to read as integer. Actual number of bytes
read is always equal to size unless EOF is reached. If size is
negative or unspecified, read the entire file.

Returns:
data read as str.

Raises:
IOError: When this buffer is closed.


def startProducing(self, consumer):

        self._consumer = consumer
        self._current_deferred = defer.Deferred()
        self._sent = 0
        self._paused = False

        if not hasattr(self, "_chunk_headers"):
            self._build_chunk_headers()

        if self._data:
            block = ""
            for field in self._data:
                block += self._chunk_headers[field]
                block += self._data[field]
                block += "\r\n"

            self._send_to_consumer(block)

        if self._files:
            self._files_iterator = self._files.iterkeys()
            self._files_sent = 0
            self._files_length = len(self._files)
            self._current_file_path = None
            self._current_file_handle = None
            self._current_file_length = None
            self._current_file_sent = 0

            result = self._produce()
            if result:
                return result
        else:
            return defer.succeed(None)

        return self._current_deferred

Start producing.

Args:
consumer: Consumer


def _hide_parameters(self, file_name):

        try:
            in_data = load_b26_file(file_name)
        except:
            in_data = {}

        def set_item_visible(item, is_visible):
            if isinstance(is_visible, dict):
                for child_id in range(item.childCount()):
                    child = item.child(child_id)
                    if child.name in is_visible:
                        set_item_visible(child, is_visible[child.name])
            else:
                item.visible = is_visible

        if "scripts_hidden_parameters" in in_data:

            if len(list(in_data["scripts_hidden_parameters"].keys())) == self.tree_scripts.topLevelItemCount():

                for index in range(self.tree_scripts.topLevelItemCount()):
                    item = self.tree_scripts.topLevelItem(index)

                    set_item_visible(item, in_data["scripts_hidden_parameters"][item.name])
            else:
                print('WARNING: settings for hiding parameters does\'t seem to match other settings')

hide the parameters that had been hidden
Args:
file_name: config file that has the information about which parameters are hidden


def pick_unused_port():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(('localhost', 0))
    (addr, port) = s.getsockname()
    s.close()
    return port

get an unused port on the VM.

Returns:
An unused port.


def send_offset_commit_request(self, group, payloads=None, fail_on_error=True, callback=None, group_generation_id=(- 1), consumer_id=''):
    group = _coerce_consumer_group(group)
    encoder = partial(KafkaCodec.encode_offset_commit_request, group=group, group_generation_id=group_generation_id, consumer_id=consumer_id)
    decoder = KafkaCodec.decode_offset_commit_response
    resps = (yield self._send_broker_aware_request(payloads, encoder, decoder, consumer_group=group))
    returnValue(self._handle_responses(resps, fail_on_error, callback, group))

Send a list of OffsetCommitRequests to the Kafka broker for the
given consumer group.

Args:
group (str): The consumer group to which to commit the offsets
payloads ([OffsetCommitRequest]): List of topic, partition, offsets
to commit.
fail_on_error (bool): Whether to raise an exception if a response
from the Kafka broker indicates an error
callback (callable): a function to call with each of the responses
before returning the returned value to the caller.
group_generation_id (int): Must currently always be -1
consumer_id (str): Must currently always be empty string
Returns:
[OffsetCommitResponse]: List of OffsetCommitResponse objects.
Will raise KafkaError for failed requests if fail_on_error is True


def HandleInvMessage(self, payload):

        if self.sync_mode != MODE_MAINTAIN:
            return

        inventory = IOHelper.AsSerializableWithType(payload, 'neo.Network.Payloads.InvPayload.InvPayload')
        if not inventory:
            return

        if inventory.Type == InventoryType.BlockInt:

            ok_hashes = []
            for hash in inventory.Hashes:
                hash = hash.encode('utf-8')
                if hash not in self.myblockrequests and hash not in BC.Default().BlockRequests:
                    ok_hashes.append(hash)
                    BC.Default().BlockRequests.add(hash)
                    self.myblockrequests.add(hash)
            if len(ok_hashes):
                message = Message("getdata", InvPayload(InventoryType.Block, ok_hashes))
                self.SendSerializedMessage(message)

        elif inventory.Type == InventoryType.TXInt:
            pass
        elif inventory.Type == InventoryType.ConsensusInt:
            pass

Process a block header inventory payload.

Args:
inventory (neo.Network.Payloads.InvPayload):


def _GetAttributeContainerByIndex(self, container_type, index):

    sequence_number = index + 1
    query = 'SELECT _data FROM {0:s} WHERE rowid = {1:d}'.format(
        container_type, sequence_number)

    try:
      self._cursor.execute(query)
    except sqlite3.OperationalError as exception:
      raise IOError('Unable to query storage file with error: {0!s}'.format(
          exception))

    row = self._cursor.fetchone()
    if row:
      identifier = identifiers.SQLTableIdentifier(
          container_type, sequence_number)

      if self.compression_format == definitions.COMPRESSION_FORMAT_ZLIB:
        serialized_data = zlib.decompress(row[0])
      else:
        serialized_data = row[0]

      if self._storage_profiler:
        self._storage_profiler.Sample(
            'read', container_type, len(serialized_data), len(row[0]))

      attribute_container = self._DeserializeAttributeContainer(
          container_type, serialized_data)
      attribute_container.SetIdentifier(identifier)
      return attribute_container

    count = self._CountStoredAttributeContainers(container_type)
    index -= count

    serialized_data = self._GetSerializedAttributeContainerByIndex(
        container_type, index)
    attribute_container = self._DeserializeAttributeContainer(
        container_type, serialized_data)

    if attribute_container:
      identifier = identifiers.SQLTableIdentifier(
          container_type, sequence_number)
      attribute_container.SetIdentifier(identifier)
    return attribute_container

Retrieves a specific attribute container.

Args:
container_type (str): attribute container type.
index (int): attribute container index.

Returns:
AttributeContainer: attribute container or None if not available.

Raises:
IOError: when there is an error querying the storage file.
OSError: when there is an error querying the storage file.


def render_build_args(options, ns):

    build_args = options.get('buildArgs', {})
    for key, value in build_args.items():
        build_args[key] = value.format(**ns)
    return build_args

Get docker build args dict, rendering any templated args.

Args:
options (dict):
The dictionary for a given image from chartpress.yaml.
Fields in `options['buildArgs']` will be rendered and returned,
if defined.
ns (dict): the namespace used when rendering templated arguments


class PatchMixerBlock(nn.Module):

    def __init__(self, config: PatchTSMixerConfig):
        super().__init__()
        self.norm = PatchTSMixerNormLayer(config)
        self.self_attn = config.self_attn
        self.gated_attn = config.gated_attn
        self.mlp = PatchTSMixerMLP(in_features=config.num_patches, out_features=config.num_patches, config=config)
        if config.gated_attn:
            self.gating_block = PatchTSMixerGatedAttention(in_size=config.num_patches, out_size=config.num_patches)
        if config.self_attn:
            self.self_attn_layer = PatchTSMixerAttention(embed_dim=config.d_model, num_heads=config.self_attn_heads, dropout=config.dropout, config=config)
            self.norm_attn = PatchTSMixerNormLayer(config)

    def forward(self, hidden_state):

        residual = hidden_state
        hidden_state = self.norm(hidden_state)
        if self.self_attn:
            batch_size, n_vars, num_patches, d_model = hidden_state.shape
            hidden_state_reshaped = hidden_state.reshape(batch_size * n_vars, num_patches, d_model)
            x_attn, _, _ = self.self_attn_layer(hidden_state_reshaped, output_attentions=False)
            x_attn = x_attn.reshape(batch_size, n_vars, num_patches, d_model)
        hidden_state = hidden_state.transpose(2, 3)
        hidden_state = self.mlp(hidden_state)
        if self.gated_attn:
            hidden_state = self.gating_block(hidden_state)
        hidden_state = hidden_state.transpose(2, 3)
        if self.self_attn:
            hidden_state = self.norm_attn(hidden_state + x_attn)
        out = hidden_state + residual
        return out

This module mixes the patch dimension.

Args:
config (`PatchTSMixerConfig`):
Configuration.


def build(self, var_list):
    if self.built:
        return
    super().build(var_list)
    self._momentums, self._velocities = self.add_optimizer_variables(var_list, ['momentum', 'velocity'])

Initialize optimizer variables.

Lamb optimizer has 2 types of variables: momentums and velocities

Args:
var_list: list of model variables to build Lamb variables on.


def clusters_sites_obj(clusters):
    result = {}
    all_clusters = get_all_clusters_sites()
    clusters_sites = {c: s for (c, s) in all_clusters.items() if (c in clusters)}
    for (cluster, site) in clusters_sites.items():
        result.update({cluster: get_site_obj(site)})
    return result

Get all the corresponding sites of the passed clusters.

Args:
clusters(list): list of string uid of sites (e.g 'rennes')

Return:
dict corresponding to the mapping cluster uid to python-grid5000 site


def ensure_scheme(url, default_scheme='http'):

    parsed = urlsplit(url, scheme=default_scheme)
    if not parsed.netloc:
        parsed = SplitResult(
            scheme=parsed.scheme,
            netloc=parsed.path,
            path='',
            query=parsed.query,
            fragment=parsed.fragment
        )

    return urlunsplit(parsed)

Adds a scheme to a url if not present.

Args:
url (string): a url, assumed to start with netloc
default_scheme (string): a scheme to be added

Returns:
string: URL with a scheme


def decode(self, codes):
    assert (codes.ndim == 2)
    (N, M) = codes.shape
    assert (M == self.M)
    assert (codes.dtype == self.code_dtype)
    vecs = np.empty((N, (self.Ds * self.M)), dtype=np.float32)
    for m in range(self.M):
        vecs[(:, (m * self.Ds):((m + 1) * self.Ds))] = self.codewords[m][(codes[(:, m)], :)]
    return vecs

Given PQ-codes, reconstruct original D-dimensional vectors
approximately by fetching the codewords.

Args:
codes (np.ndarray): PQ-cdoes with shape=(N, M) and dtype=self.code_dtype.
Each row is a PQ-code

Returns:
np.ndarray: Reconstructed vectors with shape=(N, D) and dtype=np.float32


def getFilesFromAFolder(path):

    from os import listdir
    from os.path import isfile, join

    onlyFiles = []
    for f in listdir(path):
        if isfile(join(path, f)):
            onlyFiles.append(f)
    return onlyFiles

Getting all the files in a folder.

Args:
-----
path: The path in which looking for the files

Returns:
--------
list: The list of filenames found.


def parts(path):
    _path = normpath(path)
    components = _path.strip('/')
    _parts = [('/' if _path.startswith('/') else './')]
    if components:
        _parts += components.split('/')
    return _parts

Split a path in to its component parts.

Arguments:
path (str): Path to split in to parts.

Returns:
list: List of components

Example:
>>> parts('/foo/bar/baz')
['/', 'foo', 'bar', 'baz']


async def run(self, state: ConnectionState) -> None:

        self._print('%d +++| %s', bytes(socket_info.get()))
        bad_commands = 0
        try:
            greeting = await self._exec(state.do_greeting())
        except ResponseError as exc:
            resp = exc.get_response(b'*')
            resp.condition = ResponseBye.condition
            await self.write_response(resp)
            return
        else:
            await self.write_response(greeting)
        while True:
            try:
                cmd = await self.read_command()
            except (ConnectionError, EOFError):
                break
            except CancelledError:
                await self.send_error_disconnect()
                break
            except Exception:
                await self.send_error_disconnect()
                raise
            else:
                prev_cmd = current_command.set(cmd)
                try:
                    if isinstance(cmd, AuthenticateCommand):
                        creds = await self.authenticate(state, cmd.mech_name)
                        response, _ = await self._exec(
                            state.do_authenticate(cmd, creds))
                    elif isinstance(cmd, IdleCommand):
                        response = await self.idle(state, cmd)
                    else:
                        response = await self._exec(state.do_command(cmd))
                except ResponseError as exc:
                    resp = exc.get_response(cmd.tag)
                    await self.write_response(resp)
                    if resp.is_terminal:
                        break
                except AuthenticationError as exc:
                    msg = bytes(str(exc), 'utf-8', 'surrogateescape')
                    resp = ResponseBad(cmd.tag, msg)
                    await self.write_response(resp)
                except TimeoutError:
                    resp = ResponseNo(cmd.tag, b'Operation timed out.',
                                      ResponseCode.of(b'TIMEOUT'))
                    await self.write_response(resp)
                except CancelledError:
                    await self.send_error_disconnect()
                    break
                except Exception:
                    await self.send_error_disconnect()
                    raise
                else:
                    await self.write_response(response)
                    if response.is_bad:
                        bad_commands += 1
                        if self.bad_command_limit \
                                and bad_commands >= self.bad_command_limit:
                            msg = b'Too many errors, disconnecting.'
                            response.add_untagged(ResponseBye(msg))
                    else:
                        bad_commands = 0
                    if response.is_terminal:
                        break
                    if isinstance(cmd, StartTLSCommand) and state.ssl_context \
                            and isinstance(response, ResponseOk):
                        await self.start_tls(state.ssl_context)
                finally:
                    await state.do_cleanup()
                    current_command.reset(prev_cmd)
        self._print('%d ---| %s', b'<disconnected>')

Start the socket communication with the IMAP greeting, and then
enter the command/response cycle.

Args:
state: Defines the interaction with the backend plugin.


async def send_heartbeat(self, short_name):

        if short_name not in self.services:
            raise ArgumentError("Unknown service name", short_name=short_name)

        self.services[short_name]['state'].heartbeat()
        await self._notify_update(short_name, 'heartbeat')

Post a heartbeat for a service.

Args:
short_name (string): The short name of the service to query


def IsInitializerList(clean_lines, linenum):

  for i in xrange(linenum, 1, -1):
    line = clean_lines.elided[i]
    if i == linenum:
      remove_function_body = Match(r'^(.*)\{\s*$', line)
      if remove_function_body:
        line = remove_function_body.group(1)

    if Search(r'\s:\s*\w+[({]', line):

      return True
    if Search(r'\}\s*,\s*$', line):

      return True
    if Search(r'[{};]\s*$', line):

      return False

  return False

Check if current line is inside constructor initializer list.

Args:
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
Returns:
True if current line appears to be inside constructor initializer
list, False otherwise.


def not_found(cls, errors=None):
    if cls.expose_status:
        cls.response.content_type = 'application/json'
        cls.response._status_line = '404 Not Found'
    return cls(404, None, errors).to_json

Shortcut API for HTTP 404 `Not found` response.

Args:
errors (list): Response key/value data.

Returns:
WSResponse Instance.


def read_table(fstream):
    pos = fstream.tell()
    line = fstream.readline().strip()
    fragments = line.split(',')
    fragments = [x for x in fragments if (x is not None)]
    partition = dict()
    if (not (len(fragments) >= 4)):
        return None
    partition['table'] = fragments[0]
    partition['group'] = fragments[1]
    partition['set'] = fragments[2]
    partition['num_lines'] = fragments[3]
    struct = None
    if ((partition is not None) and (partition['table'] == 'TABLE')):
        num_lines = int(partition['num_lines'].strip())
        struct = {}
        header = fetch_cols(fstream)
        struct.update({header[0]: header[1:]})
        for _ in range(num_lines):
            cols = fetch_cols(fstream)
            struct.update({cols[0]: cols[1:]})
    else:
        fstream.seek(pos)
    return struct

Read a likwid table info from the text stream.

Args:
fstream: Likwid's filestream.

Returns (dict(str: str)):
A dict containing likwid's table info as key/value pairs.


def _init_trace_logging(self, app):
    enabled = (not app.config.get(CONF_DISABLE_TRACE_LOGGING, False))
    if (not enabled):
        return
    self._trace_log_handler = LoggingHandler(self._key, telemetry_channel=self._channel)
    app.logger.addHandler(self._trace_log_handler)

Sets up trace logging unless ``APPINSIGHTS_DISABLE_TRACE_LOGGING`` is
set in the Flask config.

Args:
app (flask.Flask). the Flask application for which to initialize the extension.


def from_json_file(cls, json_file: Union[str, os.PathLike]) -> PreTrainedFeatureExtractor:
    with open(json_file, encoding='utf-8') as reader:
        text = reader.read()
    feature_extractor_dict = json.loads(text)
    return cls(**feature_extractor_dict)

Instantiates a feature extractor of type [`~feature_extraction_utils.FeatureExtractionMixin`] from the path to
a JSON file of parameters.

Args:
json_file (`str` or `os.PathLike`):
Path to the JSON file containing the parameters.

Returns:
A feature extractor of type [`~feature_extraction_utils.FeatureExtractionMixin`]: The feature_extractor
object instantiated from that JSON file.


def unpack(self, buff, offset=0):

        header = UBInt16()
        header.unpack(buff[offset:offset+2])
        self.tlv_type = header.value >> 9
        length = header.value & 511
        begin, end = offset + 2, offset + 2 + length
        sub_type = UBInt8()
        sub_type.unpack(buff[begin:begin+1])
        self.sub_type = sub_type.value
        self.sub_value = BinaryData(buff[begin+1:end])

Unpack a binary message into this object's attributes.

Unpack the binary value *buff* and update this object attributes based
on the results.

Args:
buff (bytes): Binary data package to be unpacked.
offset (int): Where to begin unpacking.

Raises:
Exception: If there is a struct unpacking error.


def set_result(self, result):

        if self.done():
            raise RuntimeError("set_result can only be called once.")

        self._result = result
        self._trigger()

Set the result of the future to the provided result.

Args:
result (Any): The result


async def stop_tasks(self, address):
    tasks = self._tasks.get(address, [])
    for task in tasks:
        task.cancel()
    asyncio.gather(*tasks, return_exceptions=True)
    self._tasks[address] = []

Clear all tasks pertaining to a tile.

This coroutine will synchronously cancel all running tasks that were
attached to the given tile and wait for them to stop before returning.

Args:
address (int): The address of the tile we should stop.


def _to_tensor_list(self, value) -> List['core_types.Symbol']:
    return nest.flatten(self._to_components(value), expand_composites=True)

Encodes `value` as a flat list of `tf.Tensor`.

By default, this just flattens `self._to_components(value)` using
`nest.flatten`.  However, subclasses may override this to return a
different tensor encoding for values.  In particular, some subclasses
of `BatchableTypeSpec` override this method to return a "boxed" encoding
for values, which then can be batched or unbatched.  See
`BatchableTypeSpec` for more details.

Args:
value: A value with compatible this `TypeSpec`.  (Caller is responsible
for ensuring compatibility.)

Returns:
A list of `tf.Tensor`, compatible with `self._flat_tensor_specs`, which
can be used to reconstruct `value`.


def create_view(operations, operation):
    operations.execute(('CREATE VIEW %s AS %s' % (operation.target.name, operation.target.sqltext)))

Implements ``CREATE VIEW``.

Args:
operations: instance of ``alembic.operations.base.Operations``
operation: instance of :class:`.ReversibleOp`

Returns:
``None``


def data_group_type(self, group_data):

        if isinstance(group_data, dict):

            file_content = group_data.pop('fileContent', None)
            if file_content is not None:
                self._files[group_data.get('xid')] = {
                    'fileContent': file_content,
                    'type': group_data.get('type'),
                }
        else:
            GROUPS_STRINGS_WITH_FILE_CONTENTS = ['Document', 'Report']

            if group_data.data.get('type') in GROUPS_STRINGS_WITH_FILE_CONTENTS:
                self._files[group_data.data.get('xid')] = group_data.file_data
            group_data = group_data.data
        return group_data

Return dict representation of group data.

Args:
group_data (dict|obj): The group data dict or object.

Returns:
dict: The group data in dict format.


async def get_participants(self, force_update=False) -> list:

        if force_update or self.participants is None:
            res = await self.connection('GET', 'tournaments/{}/participants'.format(self._id))
            self._refresh_participants_from_json(res)
        return self.participants or []

get all participants

|methcoro|

Args:
force_update (default=False): True to force an update to the Challonge API

Returns:
list[Participant]:

Raises:
APIException


def add_state(self, state_name, initial_state, batch_size=None):
    state_shape = initial_state.get_shape().as_list()
    full_shape = ([batch_size] + state_shape)
    if (not batch_size):
        shape_proto = self._as_shape_proto(([0] + state_shape))
        batch_size = 1
    else:
        shape_proto = self._as_shape_proto(([batch_size] + state_shape))
    tiles = ([batch_size] + ([1] * len(initial_state.get_shape())))
    feed_op = tf.placeholder_with_default(tf.tile(tf.expand_dims(initial_state, [0]), tiles), shape=full_shape, name=('%s_feed' % state_name))
    s = {'feed_op': feed_op, 'feed_type': initial_state.dtype, 'feed_shape': shape_proto}
    self._states[state_name] = s

Adds a state to the state saver.

Args:
state_name: The name of this state.
initial_state: The initial state vector. Only zeros are supported.
batch_size: The batch_size or None for unknown.


def apply_configs(config):
    default_enabled = config.get('default_component_enabled', False)
    delegate_keys = sorted(dr.DELEGATES, key=dr.get_name)
    for comp_cfg in config.get('configs', []):
        name = comp_cfg.get('name')
        for c in delegate_keys:
            delegate = dr.DELEGATES[c]
            cname = dr.get_name(c)
            if cname.startswith(name):
                dr.ENABLED[c] = comp_cfg.get('enabled', default_enabled)
                delegate.metadata.update(comp_cfg.get('metadata', {}))
                delegate.tags = set(comp_cfg.get('tags', delegate.tags))
                for (k, v) in delegate.metadata.items():
                    if hasattr(c, k):
                        log.debug('Setting %s.%s to %s', cname, k, v)
                        setattr(c, k, v)
                if hasattr(c, 'timeout'):
                    c.timeout = comp_cfg.get('timeout', c.timeout)
            if (cname == name):
                break

Configures components. They can be enabled or disabled, have timeouts set
if applicable, and have metadata customized. Valid keys are name, enabled,
metadata, and timeout.

Args:
config (list): a list of dictionaries with the following keys:
default_component_enabled (bool): default value for whether compoments
are enable if not specifically declared in the config section

packages (list): a list of packages to be loaded. These will be in
addition to any packages previosly loaded for the `-p` option

configs:
name, enabled, metadata, and timeout. All keys are optional except
name.

name is the prefix or exact name of any loaded component. Any
component starting with name will have the associated configuration
applied.

enabled is whether the matching components will execute even if
their dependencies are met. Defaults to True.

timeout sets the class level timeout attribute of any component so
long as the attribute already exists.

metadata is any dictionary that you want to attach to the
component. The dictionary can be retrieved by the component at
runtime.


def iter_intersecting(self, iterable, key=None, descending=False):
    return _ContainsVersionIterator(self, iterable, key, descending, mode=_ContainsVersionIterator.MODE_INTERSECTING)

Like `iter_intersect_test`, but returns intersections only.

Returns:
An iterator that returns items from `iterable` that intersect.


def parse(input_string, prefix=''):
    tree = parser.parse(input_string)
    visitor = ChatlVisitor(prefix)
    visit_parse_tree(tree, visitor)
    return visitor.parsed

Parses the given DSL string and returns parsed results.

Args:
input_string (str): DSL string
prefix (str): Optional prefix to add to every element name, useful to namespace things

Returns:
dict: Parsed content


def is_field_remote(model, field_name):
    if (not hasattr(model, '_meta')):
        return False
    model_field = get_model_field(model, field_name)
    return isinstance(model_field, (ManyToManyField, RelatedObject))

Check whether a given model field is a remote field.

A remote field is the inverse of a one-to-many or a
many-to-many relationship.

Arguments:
model: a Django model
field_name: the name of a field

Returns:
True if `field_name` is a remote field, False otherwise.


def image_to_tf_summary_value(image, tag):

  curr_image = np.asarray(image, dtype=np.uint8)
  height, width, n_channels = curr_image.shape

  if n_channels == 1:
    curr_image = np.reshape(curr_image, [height, width])
  s = io.BytesIO()
  matplotlib_pyplot().imsave(s, curr_image, format="png")
  img_sum = tf.Summary.Image(encoded_image_string=s.getvalue(),
                             height=height, width=width,
                             colorspace=n_channels)
  return tf.Summary.Value(tag=tag, image=img_sum)

Converts a NumPy image to a tf.Summary.Value object.

Args:
image: 3-D NumPy array.
tag: name for tf.Summary.Value for display in tensorboard.
Returns:
image_summary: A tf.Summary.Value object.


def next_population(self, population, fitnesses):

        self._probability_vec = _adjust_probability_vec_best(
            population, fitnesses, self._probability_vec, self._adjust_rate)

        _mutate_probability_vec(self._probability_vec, self._mutation_chance,
                                self._mutation_adjust_rate)

        return [
            _sample(self._probability_vec)
            for _ in range(self._population_size)
        ]

Make a new population after each optimization iteration.

Args:
population: The population current population of solutions.
fitnesses: The fitness associated with each solution in the population
Returns:
list; a list of solutions.


def asymmetric_depolarize(p_x: float, p_y: float, p_z: float) -> AsymmetricDepolarizingChannel:
    return AsymmetricDepolarizingChannel(p_x, p_y, p_z)

r"""Returns a AsymmetricDepolarizingChannel with given parameter.

This channel evolves a density matrix via

$$
\rho \rightarrow (1 - p_x - p_y - p_z) \rho
+ p_x X \rho X + p_y Y \rho Y + p_z Z \rho Z
$$

Args:
p_x: The probability that a Pauli X and no other gate occurs.
p_y: The probability that a Pauli Y and no other gate occurs.
p_z: The probability that a Pauli Z and no other gate occurs.

Raises:
ValueError: if the args or the sum of the args are not probabilities.


def CreateStorageWriter(cls, storage_format, session, path):
    if (storage_format == definitions.STORAGE_FORMAT_SQLITE):
        return sqlite_writer.SQLiteStorageFileWriter(session, path)
    return None

Creates a storage writer.

Args:
session (Session): session the storage changes are part of.
path (str): path to the storage file.
storage_format (str): storage format.

Returns:
StorageWriter: a storage writer or None if the storage file cannot be
opened or the storage format is not supported.


def remap_variables(fn):

    def custom_getter(getter, *args, **kwargs):
        v = getter(*args, **kwargs)
        return fn(v)
    return custom_getter_scope(custom_getter)

Use fn to map the output of any variable getter.

Args:
fn (tf.Variable -> tf.Tensor)

Returns:
The current variable scope with a custom_getter that maps
all the variables by fn.

Example:
.. code-block:: python

with varreplace.remap_variables(lambda var: quantize(var)):
x = FullyConnected('fc', x, 1000)   # fc/{W,b} will be quantized


def get_provider_uri(self, provider_display_name):

        providers = self._provider_client.get_by('displayName', provider_display_name)
        return providers[0]['uri'] if providers else None

Gets uri for a specific provider.

Args:
provider_display_name: Display name of the provider.

Returns:
uri


def get_product_order_book(self, product_id, level=1):
    params = {'level': level}
    return self._send_message('get', '/products/{}/book'.format(product_id), params=params)

Get a list of open orders for a product.

The amount of detail shown can be customized with the `level`
parameter:
* 1: Only the best bid and ask
* 2: Top 50 bids and asks (aggregated)
* 3: Full order book (non aggregated)

Level 1 and Level 2 are recommended for polling. For the most
up-to-date data, consider using the websocket stream.

**Caution**: Level 3 is only recommended for users wishing to
maintain a full real-time order book using the websocket
stream. Abuse of Level 3 via polling will cause your access to
be limited or blocked.

Args:
product_id (str): Product
level (Optional[int]): Order book level (1, 2, or 3).
Default is 1.

Returns:
dict: Order book. Example for level 1::
{
"sequence": "3",
"bids": [
[ price, size, num-orders ],
],
"asks": [
[ price, size, num-orders ],
]
}


def metadata_path(self, m_path):

        if not m_path:
            self.metadata_dir = None
            self.metadata_file = None

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

            if not op.dirname(m_path):
                self.metadata_dir = '.'
            else:
                self.metadata_dir = op.dirname(m_path)
            self.metadata_file = op.basename(m_path)

Provide pointers to the paths of the metadata file

Args:
m_path: Path to metadata file


def get_mapreduce_yaml(parse=parse_mapreduce_yaml):

  mr_yaml_path = find_mapreduce_yaml()
  if not mr_yaml_path:
    raise errors.MissingYamlError()
  mr_yaml_file = open(mr_yaml_path)
  try:
    return parse(mr_yaml_file.read())
  finally:
    mr_yaml_file.close()

Locates mapreduce.yaml, loads and parses its info.

Args:
parse: Used for testing.

Returns:
MapReduceYaml object.

Raises:
errors.BadYamlError: when contents is not a valid mapreduce.yaml file or the
file is missing.


def set_s3_bucket(self, region, name, bucketName):
    ct = self.session.client('cloudtrail', region_name=region)
    ct.update_trail(Name=name, S3BucketName=bucketName)
    auditlog(event='cloudtrail.set_s3_bucket', actor=self.ns, data={'account': self.account.account_name, 'region': region})
    self.log.info('Updated S3BucketName to {} for {} in {}/{}'.format(bucketName, name, self.account.account_name, region))

Sets the S3 bucket location for logfile delivery

Args:
region (`str`): Name of the AWS region
name (`str`): Name of the CloudTrail Trail
bucketName (`str`): Name of the S3 bucket to deliver log files to

Returns:
`None`


def parent(self):
    if (self._parent is not None):
        return self._parent
    try:
        package = self.repository.get_parent_package(self.resource)
        self._parent = Package(package, context=self.context)
    except AttributeError as e:
        reraise(e, ValueError)
    return self._parent

Get the parent package.

Returns:
`Package`.


def get_image_embeddings(self, pixel_values, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None):
    vision_output = self.vision_encoder(pixel_values=pixel_values, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict)
    image_embeddings = vision_output[0]
    intermediate_embeddings = vision_output[1]
    return (image_embeddings, intermediate_embeddings)

Returns the image embeddings by passing the pixel values through the vision encoder.

Args:
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
Input pixel values
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers.
output_hidden_states (`bool`, *optional*):
Whether or not to return the hidden states of all layers.
return_dict (`bool`, *optional*):
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.


def create_tasks(self, wfk_file, scr_input):
    assert (len(self) == 0)
    wfk_file = self.wfk_file = os.path.abspath(wfk_file)
    shell_manager = self.manager.to_shell_manager(mpi_procs=1)
    w = Work(workdir=self.tmpdir.path_join('_qptdm_run'), manager=shell_manager)
    fake_input = scr_input.deepcopy()
    fake_task = w.register(fake_input)
    w.allocate()
    w.build()
    fake_task.inlink_file(wfk_file)
    fake_task.set_vars({'nqptdm': (- 1)})
    fake_task.start_and_wait()
    with NetcdfReader(fake_task.outdir.has_abiext('qptdms.nc')) as reader:
        qpoints = reader.read_value('reduced_coordinates_of_kpoints')
    for qpoint in qpoints:
        qptdm_input = scr_input.deepcopy()
        qptdm_input.set_vars(nqptdm=1, qptdm=qpoint)
        new_task = self.register_scr_task(qptdm_input, manager=self.manager)
        if (self.flow.gc is not None):
            new_task.set_gc(self.flow.gc)
    self.allocate()

Create the SCR tasks and register them in self.

Args:
wfk_file: Path to the ABINIT WFK file to use for the computation of the screening.
scr_input: Input for the screening calculation.


def install(self, ref, table_name=None, index_columns=None, logger=None):
    try:
        obj_number = ObjectNumber.parse(ref)
        if isinstance(obj_number, TableNumber):
            table = self._library.table(ref)
            connection = self._backend._get_connection()
            return self._backend.install_table(connection, table, logger=logger)
        else:
            raise NotObjectNumberError
    except NotObjectNumberError:
        partition = self._library.partition(ref)
        connection = self._backend._get_connection()
        return self._backend.install(connection, partition, table_name=table_name, index_columns=index_columns, logger=logger)

Finds partition by reference and installs it to warehouse db.

Args:
ref (str): id, vid (versioned id), name or vname (versioned name) of the partition.


def clinsig_query(self, query, mongo_query):

        LOG.debug('clinsig is a query parameter')
        trusted_revision_level = ['mult', 'single', 'exp', 'guideline']
        rank = []
        str_rank = []
        clnsig_query = {}

        for item in query['clinsig']:
            rank.append(int(item))

            rank.append(CLINSIG_MAP[int(item)])
            str_rank.append(CLINSIG_MAP[int(item)])

        if query.get('clinsig_confident_always_returned') == True:
            LOG.debug("add CLINSIG filter with trusted_revision_level")

            clnsig_query = { "clnsig":
                        {
                            '$elemMatch': {
                                '$or' : [
                                    {
                                        '$and' : [
                                             {'value' : { '$in': rank }},
                                             {'revstat': { '$in': trusted_revision_level }}
                                        ]
                                    },
                                    {
                                        '$and': [
                                            {'value' : re.compile('|'.join(str_rank))},
                                            {'revstat' : re.compile('|'.join(trusted_revision_level))}
                                        ]
                                    }
                                ]
                            }
                         }
                    }
        else:
            LOG.debug("add CLINSIG filter for rank: %s" %
                             ', '.join(str(query['clinsig'])))

            clnsig_query = {
                    "clnsig":
                        {
                            '$elemMatch': {
                                '$or' : [
                                    { 'value' : { '$in': rank }},
                                    { 'value' : re.compile('|'.join(str_rank)) }
                                ]
                            }
                        }
                }

        return clnsig_query

Add clinsig filter values to the mongo query object

Args:
query(dict): a dictionary of query filters specified by the users
mongo_query(dict): the query that is going to be submitted to the database

Returns:
clinsig_query(dict): a dictionary with clinsig key-values


def parse(self, data):
    self.binding_var_count = 0
    self.segment_count = 0
    segments = self.parser.parse(data)
    path_wildcard = False
    for segment in segments:
        if ((segment.kind == _TERMINAL) and (segment.literal == '**')):
            if path_wildcard:
                raise ValidationException('validation error: path template cannot contain more than one path wildcard')
            path_wildcard = True
    return segments

Returns a list of path template segments parsed from data.

Args:
data: A path template string.
Returns:
A list of _Segment.


def _trychar(char, fallback, asciimode=None):
    if (asciimode is True):
        return fallback
    if (hasattr(sys.stdout, 'encoding') and sys.stdout.encoding):
        try:
            char.encode(sys.stdout.encoding)
        except Exception:
            pass
        else:
            return char
    return fallback

Logic from IPython timeit to handle terminals that cant show mu

Args:
char (str): character, typically unicode, to try to use
fallback (str): ascii character to use if stdout cannot encode char
asciimode (bool): if True, always use fallback

Example:
>>> char = _trychar('µs', 'us')
>>> print('char = {}'.format(char))
>>> assert _trychar('µs', 'us', asciimode=True) == 'us'


def serialize_to_string(self, name, datas):

        value = datas.get('value', None)

        if value is None:
            msg = ("String reference '{}' lacks of required 'value' variable "
                   "or is empty")
            raise SerializerError(msg.format(name))

        return value

Serialize given datas to a string.

Simply return the value from required variable``value``.

Arguments:
name (string): Name only used inside possible exception message.
datas (dict): Datas to serialize.

Returns:
string: Value.


def eager_run(main=None, argv=None) -> NoReturn:
    enable_eager_execution()
    app.run(main, argv)

Runs the program with an optional main function and argv list.

The program will run with eager execution enabled.

Example:
```python
import tensorflow as tf
# Import subject to future changes:

def main(_):
u = tf.constant(6.0)
v = tf.constant(7.0)
print(u * v)

if __name__ == "__main__":
tfe.run()
```

Args:
main: the main function to run.
argv: the arguments to pass to it.


def boxify(message, border_color=None):

    lines = message.split("\n")
    max_width = max(_visual_width(line) for line in lines)

    padding_horizontal = 5
    padding_vertical = 1

    box_size_horizontal = max_width + (padding_horizontal * 2)

    chars = {"corner": "+", "horizontal": "-", "vertical": "|", "empty": " "}

    margin = "{corner}{line}{corner}\n".format(
        corner=chars["corner"], line=chars["horizontal"] * box_size_horizontal
    )

    padding_lines = [
        "{border}{space}{border}\n".format(
            border=colorize(chars["vertical"], color=border_color),
            space=chars["empty"] * box_size_horizontal,
        )
        * padding_vertical
    ]

    content_lines = [
        "{border}{space}{content}{space}{border}\n".format(
            border=colorize(chars["vertical"], color=border_color),
            space=chars["empty"] * padding_horizontal,
            content=_visual_center(line, max_width),
        )
        for line in lines
    ]

    box_str = "{margin}{padding}{content}{padding}{margin}".format(
        margin=colorize(margin, color=border_color),
        padding="".join(padding_lines),
        content="".join(content_lines),
    )

    return box_str

Put a message inside a box.

Args:
message (unicode): message to decorate.
border_color (unicode): name of the color to outline the box with.


def _construct_operation_id(self, service_name, protorpc_method_name):

    method_name_camel = util.snake_case_to_headless_camel_case(
        protorpc_method_name)

    return '{0}_{1}'.format(service_name, method_name_camel)

Return an operation id for a service method.

Args:
service_name: The name of the service.
protorpc_method_name: The ProtoRPC method name.

Returns:
A string representing the operation id.


def add_object_to_scope(self, obj):

        if isinstance(obj, Computer):
            self.add_object_to_path(obj, "scope/computers")
        elif isinstance(obj, ComputerGroup):
            self.add_object_to_path(obj, "scope/computer_groups")
        elif isinstance(obj, Building):
            self.add_object_to_path(obj, "scope/buildings")
        elif isinstance(obj, Department):
            self.add_object_to_path(obj, "scope/departments")
        else:
            raise TypeError

Add an object to the appropriate scope block.

Args:
obj: JSSObject to add to scope. Accepted subclasses are:
Computer
ComputerGroup
Building
Department

Raises:
TypeError if invalid obj type is provided.


def CreateSitelinkFeedItem(feed_items, feed_item_id):

  site_link_from_feed = feed_items[feed_item_id]
  site_link_feed_item = {
      'sitelinkText': site_link_from_feed['text'],
      'sitelinkLine2': site_link_from_feed['line2'],
      'sitelinkLine3': site_link_from_feed['line3'],
  }

  if 'finalUrls' in site_link_from_feed and site_link_from_feed['finalUrls']:
    site_link_feed_item['sitelinkFinalUrls'] = {
        'urls': site_link_from_feed['finalUrls']
    }

    if 'finalMobileUrls' in site_link_from_feed:
      site_link_feed_item['sitelinkFinalMobileUrls'] = {
          'urls': site_link_from_feed['finalMobileUrls']
      }

    site_link_feed_item['sitelinkTrackingUrlTemplate'] = (
        site_link_from_feed['trackingUrlTemplate'])
  else:
    site_link_feed_item['sitelinkUrl'] = site_link_from_feed['url']

  return site_link_feed_item

Creates a Sitelink Feed Item.

Args:
feed_items: a list of all Feed Items.
feed_item_id: the Id of a specific Feed Item for which a Sitelink Feed Item
should be created.

Returns:
The new Sitelink Feed Item.


def _parse_address(self, val):
    ret = {'type': None, 'value': None}
    try:
        ret['type'] = val[1]['type']
    except (KeyError, ValueError, TypeError):
        pass
    try:
        ret['value'] = val[1]['label']
    except (KeyError, ValueError, TypeError):
        ret['value'] = '\n'.join(val[3]).strip()
    try:
        self.vars['address'].append(ret)
    except AttributeError:
        self.vars['address'] = []
        self.vars['address'].append(ret)

The function for parsing the vcard address.

Args:
val (:obj:`list`): The value to parse.


def ts_to_dt(jwt_dict):
    d = jwt_dict.copy()
    for (k, v) in [v[:2] for v in CLAIM_LIST if v[2]]:
        if (k in jwt_dict):
            d[k] = d1_common.date_time.dt_from_ts(jwt_dict[k])
    return d

Convert timestamps in JWT to datetime objects.

Args:
jwt_dict: dict
JWT with some keys containing timestamps.

Returns:
dict: Copy of input dict where timestamps have been replaced with
datetime.datetime() objects.


def add_parameter(self, name, min_val, max_val):
    self.__parameters.append(Parameter(name, min_val, max_val))

Adds a paramber to the Population

Args:
name (str): name of the parameter
min_val (int or float): minimum value for the parameter
max_val (int or float): maximum value for the parameter


def extract_annotation(data):
    xlabel = None
    xvalues = None
    ylabel = None
    yvalues = None
    if hasattr(data, 'minor_axis'):
        xvalues = data.minor_axis
        if hasattr(data.minor_axis, 'name'):
            xlabel = data.minor_axis.name
    if hasattr(data, 'columns'):
        xvalues = data.columns
        if hasattr(data.columns, 'name'):
            xlabel = data.columns.name
    if hasattr(data, 'major_axis'):
        yvalues = data.major_axis
        if hasattr(data.major_axis, 'name'):
            ylabel = data.major_axis.name
    if hasattr(data, 'index'):
        yvalues = data.index
        if hasattr(data.index, 'name'):
            ylabel = data.index.name
    return (xlabel, xvalues, ylabel, yvalues)

Extract names and values of rows and columns.

Parameter:
data : DataFrame | Panel

Returns:
col_name, col_values, row_name, row_values


def parse_config(file_path):
    if (not os.path.isfile(file_path)):
        return {}
    parser = ConfigParser()
    parser.read(file_path)
    for s in parser._sections:
        for v in six.iterkeys(parser._sections[s]):
            parser._sections[s][v] = parser._sections[s][v].split('
    return parser._sections

Convert the CISM configuration file to a python dictionary

Args:
file_path: absolute path to the configuration file

Returns:
A dictionary representation of the given file


class Poisson(MeanMetricWrapper):

    def __init__(self, name='poisson', dtype=None):
        super(Poisson, self).__init__(poisson, name, dtype=dtype)

Computes the Poisson metric between `y_true` and `y_pred`.

`metric = y_pred - y_true * log(y_pred)`

Args:
name: (Optional) string name of the metric instance.
dtype: (Optional) data type of the metric result.

Standalone usage:

>>> m = tf.keras.metrics.Poisson()
>>> m.update_state([[0, 1], [0, 0]], [[1, 1], [0, 0]])
>>> m.result().numpy()
0.49999997

>>> m.reset_state()
>>> m.update_state([[0, 1], [0, 0]], [[1, 1], [0, 0]],
...                sample_weight=[1, 0])
>>> m.result().numpy()
0.99999994

Usage with `compile()` API:

```python
model.compile(optimizer='sgd',
loss='mse',
metrics=[tf.keras.metrics.Poisson()])
```


def _build_element_shape(shape):
    if isinstance(shape, tensor_lib.Tensor):
        return shape
    if isinstance(shape, tensor_shape.TensorShape):
        shape = shape.as_list() if shape else None
    if shape is None:
        return -1
    if isinstance(shape, (np.ndarray, np.generic)) or not shape:
        return ops.convert_to_tensor(shape, dtype=dtypes.int32)

    def convert(val):
        if val is None:
            return -1
        if isinstance(val, tensor_lib.Tensor):
            return val
        if isinstance(val, tensor_shape.Dimension):
            return val.value if val.value is not None else -1
        return val
    return [convert(d) for d in shape]

Converts shape to a format understood by list_ops for element_shape.

If `shape` is already a `Tensor` it is returned as-is. We do not perform a
type check here.

If shape is None or a TensorShape with unknown rank, -1 is returned.

If shape is a scalar, an int32 tensor with empty list is returned. Note we
do directly return an empty list since ops.convert_to_tensor would conver it
to a float32 which is not a valid type for element_shape.

If shape is a sequence of dims, None's in the list are replaced with -1. We
do not check the dtype of the other dims.

Args:
shape: Could be None, Tensor, TensorShape or a list of dims (each dim could
be a None, scalar or Tensor).

Returns:
A None-free shape that can be converted to a tensor.


def update_headers(self, response):
    if (('expires' in response.headers) and ('cache-control' in response.headers)):
        self.msg = self.server_cache_headers
        return response.headers
    else:
        self.msg = self.default_cache_vars
        date = parsedate(response.headers['date'])
        expires = (datetime(*date[:6]) + timedelta(0, self.expire_after))
        response.headers.update({'expires': formatdate(calendar.timegm(expires.timetuple())), 'cache-control': 'public'})
        return response.headers

Returns the updated caching headers.

Args:
response (HttpResponse): The response from the remote service

Returns:
response:(HttpResponse.Headers): Http caching headers


def event(self, cuuid, host, euuid, event_data, timestamp, priority):
    response = None
    if (host in self.encrypted_hosts):
        logger.debug('Encrypted!')
        client_key = self.registry[cuuid]['encryption']
    else:
        logger.debug('Not encrypted :<')
        client_key = None
    port = host[1]
    host = host[0]
    if (not self.is_registered(cuuid, host)):
        logger.warning(('<%s> Sending BYE EVENT: Client not registered.' % cuuid))
        response = serialize_data({'method': 'BYE EVENT', 'data': 'Not registered'}, self.compression, self.encryption, client_key)
        return response
    if (euuid in self.event_uuids):
        logger.warning(('<%s> Event ID is already being processed: %s' % (cuuid, euuid)))
        return response
    self.event_uuids[euuid] = 0
    logger.debug(('<%s> <euuid:%s> Currently processing events: %s' % (cuuid, euuid, str(self.event_uuids))))
    logger.debug(('<%s> <euuid:%s> New event being processed' % (cuuid, euuid)))
    logger.debug(('<%s> <euuid:%s> Event Data: %s' % (cuuid, euuid, pformat(event_data))))
    if self.middleware.event_legal(cuuid, euuid, event_data):
        logger.debug(('<%s> <euuid:%s> Event LEGAL. Sending judgement to client.' % (cuuid, euuid)))
        response = serialize_data({'method': 'LEGAL', 'euuid': euuid, 'priority': priority}, self.compression, self.encryption, client_key)
        thread = threading.Thread(target=self.middleware.event_execute, args=(cuuid, euuid, event_data))
        thread.start()
    else:
        logger.debug(('<%s> <euuid:%s> Event ILLEGAL. Sending judgement to client.' % (cuuid, euuid)))
        response = serialize_data({'method': 'ILLEGAL', 'euuid': euuid, 'priority': priority}, self.compression, self.encryption, client_key)
    self.listener.call_later(self.timeout, self.retransmit, {'euuid': euuid, 'response': response, 'cuuid': cuuid})
    return response

This function will process event packets and send them to legal
checks.

Args:
cuuid (string): The client uuid that the event came from.
host (tuple): The (address, port) tuple of the client.
euuid (string): The event uuid of the specific event.
event_data (any): The event data that we will be sending to the
middleware to be judged and executed.
timestamp (string): The client provided timestamp of when the event
was created.
priority (string): The priority of the event. This is normally set to
either "normal" or "high". If an event was sent with a high
priority, then the client will not wait for a response from the
server before executing the event locally.

Returns:
A LEGAL/ILLEGAL response to be sent to the client.


def post_process(self, outputs, target_sizes):
    logger.warning_once('`post_process` is deprecated and will be removed in v5 of Transformers, please use `post_process_object_detection` instead, with `threshold=0.` for equivalent results.')
    out_logits, out_bbox = (outputs.logits, outputs.pred_boxes)
    if len(out_logits) != len(target_sizes):
        raise ValueError('Make sure that you pass in as many target sizes as the batch dimension of the logits')
    if target_sizes.shape[1] != 2:
        raise ValueError('Each element of target_sizes must contain the size (h, w) of each image of the batch')
    prob = out_logits.sigmoid()
    topk_values, topk_indexes = torch.topk(prob.view(out_logits.shape[0], -1), 100, dim=1)
    scores = topk_values
    topk_boxes = torch.div(topk_indexes, out_logits.shape[2], rounding_mode='floor')
    labels = topk_indexes % out_logits.shape[2]
    boxes = center_to_corners_format(out_bbox)
    boxes = torch.gather(boxes, 1, topk_boxes.unsqueeze(-1).repeat(1, 1, 4))
    img_h, img_w = target_sizes.unbind(1)
    scale_fct = torch.stack([img_w, img_h, img_w, img_h], dim=1)
    boxes = boxes * scale_fct[:, None, :]
    results = [{'scores': s, 'labels': l, 'boxes': b} for s, l, b in zip(scores, labels, boxes)]
    return results

Converts the raw output of [`DeformableDetrForObjectDetection`] into final bounding boxes in (top_left_x,
top_left_y, bottom_right_x, bottom_right_y) format. Only supports PyTorch.

Args:
outputs ([`DeformableDetrObjectDetectionOutput`]):
Raw outputs of the model.
target_sizes (`torch.Tensor` of shape `(batch_size, 2)`):
Tensor containing the size (height, width) of each image of the batch. For evaluation, this must be the
original image size (before any data augmentation). For visualization, this should be the image size
after data augment, but before padding.
Returns:
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
in the batch as predicted by the model.


def expired(self, cfgstr=None, product=None):

        products = self._rectify_products(product)
        certificate = self._get_certificate(cfgstr=cfgstr)
        if certificate is None:

            is_expired = True
        elif products is None:

            is_expired = False
        elif not all(map(os.path.exists, products)):

            is_expired = True
        else:

            product_file_hash = self._product_file_hash(products)
            certificate_hash = certificate.get('product_file_hash', None)
            is_expired = product_file_hash != certificate_hash
        return is_expired

Check to see if a previously existing stamp is still valid and if the
expected result of that computation still exists.

Args:
cfgstr (str, optional): override the default cfgstr if specified
product (PathLike or Sequence[PathLike], optional): override the
default product if specified


def on_enter(__msg: Optional[Union[Callable, str]] = None) -> Callable:

    def decorator(__func):
        @wraps(__func)
        def wrapper(*args, **kwargs):
            if __msg:
                print(__msg)
            else:
                print('Entering {!r}({!r})'.format(__func.__name__, __func))
            return __func(*args, **kwargs)
        return wrapper
    if callable(__msg):
        return on_enter()(__msg)
    return decorator

Decorator to display a message when entering a function.

Args:
__msg: Message to display
Returns:
Wrapped function


def checkpoints(self):
    return list(self._maybe_delete.keys())

A list of managed checkpoints.

Note that checkpoints saved due to `keep_checkpoint_every_n_hours` will not
show up in this list (to avoid ever-growing filename lists).

Returns:
A list of filenames, sorted from oldest to newest.


def equals(self, other):

        if not isinstance(other, self.__class__):
            return False
        else:
            return self.properties_with_values() == other.properties_with_values()

Structural equality of models.

Args:
other (HasProps) : the other instance to compare to

Returns:
True, if properties are structurally equal, otherwise False


def __init__(self, fail_on_unset: bool = False, default: str = 'none', **_vars: Any):

        self.fail_on_unset = bool(fail_on_unset)
        self.default = str(default)
        self.vars = _vars

Initializer.

Args:
fail_on_unset (bool): If set to True an exception will be raised when the environment
variable is unset; otherwise the default value (see next) will be used instead.
default (str): If a environment variable is unset, it will get this value instead.


def _AddEnumValues(descriptor, cls):

  for enum_type in descriptor.enum_types:
    setattr(cls, enum_type.name, enum_type_wrapper.EnumTypeWrapper(enum_type))
    for enum_value in enum_type.values:
      setattr(cls, enum_value.name, enum_value.number)

Sets class-level attributes for all enum fields defined in this message.

Also exporting a class-level object that can name enum values.

Args:
descriptor: Descriptor object for this message type.
cls: Class we're constructing for this message type.


class Activation(Layer):

    def __init__(self, activation, **kwargs):
        super().__init__(**kwargs)
        self.supports_masking = True
        self.activation = activations.get(activation)
        self._build_at_init()

    def call(self, inputs):
        return self.activation(inputs)

    def compute_output_shape(self, input_shape):
        return input_shape

    def get_config(self):
        config = {'activation': activations.serialize(self.activation)}
        base_config = super().get_config()
        return {**base_config, **config}

Applies an activation function to an output.

Args:
activation: Activation function. It could be a callable, or the name of
an activation from the `keras.activations` namespace.
**kwargs: Base layer keyword arguments, such as `name` and `dtype`.

Example:

>>> layer = keras.layers.Activation('relu')
>>> layer(np.array([-3.0, -1.0, 0.0, 2.0]))
[0.0, 0.0, 0.0, 2.0]
>>> layer = keras.layers.Activation(keras.activations.relu)
>>> layer(np.array([-3.0, -1.0, 0.0, 2.0]))
[0.0, 0.0, 0.0, 2.0]


def compile_reward(self, scope: Dict[str, TensorFluent]) -> TensorFluent:

        reward_expr = self.rddl.domain.reward
        with self.graph.as_default():
            with tf.name_scope('reward'):
                return self._compile_expression(reward_expr, scope)

Compiles the reward function given the fluent `scope`.

Args:
scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): The fluent scope for reward evaluation.

Returns:
A :obj:`rddl2tf.fluent.TensorFluent` representing the reward function.


def download_from_url(path, url):

  filename = url.split("/")[-1]
  found_file = find_file(path, filename, max_depth=0)
  if found_file is None:
    filename = os.path.join(path, filename)
    tf.logging.info("Downloading from %s to %s." % (url, filename))
    inprogress_filepath = filename + ".incomplete"
    inprogress_filepath, _ = urllib.request.urlretrieve(
        url, inprogress_filepath, reporthook=download_report_hook)

    print()
    tf.gfile.Rename(inprogress_filepath, filename)
    return filename
  else:
    tf.logging.info("Already downloaded: %s (at %s)." % (url, found_file))
    return found_file

Download content from a url.

Args:
path: string directory where file will be downloaded
url: string url

Returns:
Full path to downloaded file


def slice_constant(data, batch_size=32, name='constant_data', global_step=None):
    with tf.name_scope(name):
        all_data = tf.convert_to_tensor(data)
        global_step = (global_step or bookkeeper.global_step())
        count = (len(data) / batch_size)
        extra = (len(data) - (count * batch_size))
        if extra:
            offset = tf.mod(global_step, count)
            return tf.slice(all_data, (offset * batch_size), batch_size)
        else:
            offset = tf.mod(global_step, (count + 1))
            return tf.slice(all_data, (offset * batch_size), tf.where(tf.equal(offset, count), extra, batch_size))

Provide a slice based on the global_step.

This is useful when the entire data array can be stored in memory because it
allows you to feed the data very efficiently.

Args:
data: A numpy array or tensor.
batch_size: The batch size for the produced data.
name: An optional name for this data.
global_step: A global step variable that is used to read the data. If None
then the default prettytensor global_step is used.
Returns:
A tensor that produces the given data.


def UpdateMapping(self, filename, mapping_update):

    if filename not in self._file_mapping:
      raise problems.NonexistentMapping(filename)
    mapping = self._file_mapping[filename]
    mapping.update(mapping_update)

Updates an entry in the list of known filenames.
An entry is identified by its filename.

Args:
filename: The filename whose mapping is to be updated
mapping_update: A dictionary containing the fields to update and their
new values.
Raises:
InexistentMapping if the filename does not exist in the mapping


def has_auth_params(self, scheme):
    for (k, v) in iteritems(self.schemes[scheme][u'params']):
        if (not v):
            return False
    return True

Check whether all information required for a given auth scheme have
been supplied.

Args:
scheme (str): Name of the authentication scheme to check. One of
Gem-Identify, Gem-Device, Gem-Application

Returns:
True if all required parameters for the specified scheme are present
or False otherwise.


def load_addon(username, package_name, _globals):

    addon_module = get_or_create_module_r(username)
    package_module = __import__(package_name)
    add_tasks_r(addon_module, package_module, package_name)
    _globals.update({username: addon_module})
    del package_module
    del addon_module

Load an fabsetup addon given by 'package_name' and hook it in the
base task namespace 'username'.

Args:
username(str)
package_name(str)
_globals(dict): the globals() namespace of the fabric script.

Return: None


class PerceiverDecoderOutput(ModelOutput):
    logits: Optional[torch.FloatTensor] = None
    cross_attentions: Optional[Tuple[torch.FloatTensor]] = None

Base class for Perceiver decoder outputs, with potential cross-attentions.

Args:
logits (`torch.FloatTensor` of shape `(batch_size, num_labels)`):
Output of the basic decoder.
cross_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
used to compute the weighted average in the cross-attention heads.


def sendCommand(self, command):
    command_data = [ord(x) for x in buffer(command)]
    self.hid.write(command_data)
    response_data = ''.join((chr(x) for x in self.hid.read(64)))
    response = command.RESPONSE.from_buffer_copy(response_data)
    if (response.status != 0):
        raise CommandException(response.status)
    return response

Sends a Command object to the MCP2210 and returns its response.

Arguments:
A commands.Command instance

Returns:
A commands.Response instance, or raises a CommandException on error.


def spec_filled(self, pos_args, kw_args):

        req_names = self.arg_names
        if len(self.arg_defaults) > 0:
            req_names = req_names[:-len(self.arg_defaults)]

        req = [x for x in req_names if x not in kw_args]
        return len(req) <= len(pos_args)

Check if we have enough arguments to call this function.

Args:
pos_args (list): A list of all the positional values we have.
kw_args (dict): A dict of all of the keyword args we have.

Returns:
bool: True if we have a filled spec, False otherwise.


def my_solid_angle(center, coords):

    o = np.array(center)
    r = [np.array(c) - o for c in coords]
    r.append(r[0])
    n = [np.cross(r[i + 1], r[i]) for i in range(len(r) - 1)]
    n.append(np.cross(r[1], r[0]))
    phi = 0.0
    for i in range(len(n) - 1):
        try:
            value = math.acos(-np.dot(n[i], n[i + 1]) / (np.linalg.norm(n[i]) * np.linalg.norm(n[i + 1])))
        except ValueError:
            mycos = -np.dot(n[i], n[i + 1]) / (np.linalg.norm(n[i]) * np.linalg.norm(n[i + 1]))
            if 0.999999999999 < mycos < 1.000000000001:
                value = math.acos(1.0)
            elif -0.999999999999 > mycos > -1.000000000001:
                value = math.acos(-1.0)
            else:
                raise SolidAngleError(mycos)
        phi += value
    return phi + (3 - len(r)) * math.pi

Helper method to calculate the solid angle of a set of coords from the
center.

Args:
center:
Center to measure solid angle from.
coords:
List of coords to determine solid angle.

Returns:
The solid angle.


def extract_wavs(utterances: List[Utterance], tgt_dir: Path, lazy: bool) -> None:
    tgt_dir.mkdir(parents=True, exist_ok=True)
    for utter in utterances:
        wav_fn = '{}.{}'.format(utter.prefix, 'wav')
        out_wav_path = (tgt_dir / wav_fn)
        if (lazy and out_wav_path.is_file()):
            logger.info('File {} already exists and lazy == {}; not writing.'.format(out_wav_path, lazy))
            continue
        logger.info('File {} does not exist and lazy == {}; creating it.'.format(out_wav_path, lazy))
        trim_wav_ms(utter.org_media_path, out_wav_path, utter.start_time, utter.end_time)

Extracts WAVs from the media files associated with a list of Utterance
objects and stores it in a target directory.

Args:
utterances: A list of Utterance objects, which include information
about the source media file, and the offset of the utterance in the
media_file.
tgt_dir: The directory in which to write the output WAVs.
lazy: If True, then existing WAVs will not be overwritten if they have
the same name


def get_serialization_context(self, driver_id):
    with self.lock:
        if (driver_id not in self.serialization_context_map):
            _initialize_serialization(driver_id)
        return self.serialization_context_map[driver_id]

Get the SerializationContext of the driver that this worker is processing.

Args:
driver_id: The ID of the driver that indicates which driver to get
the serialization context for.

Returns:
The serialization context of the given driver.


def add_citations(voevent, event_ivorns):

    if not voevent.xpath('Citations'):
        etree.SubElement(voevent, 'Citations')
    voevent.Citations.extend(_listify(event_ivorns))

Add citations to other voevents.

The schema mandates that the 'Citations' section must either be entirely
absent, or non-empty - hence we require this wrapper function for its
creation prior to listing the first citation.

Args:
voevent(:class:`Voevent`): Root node of a VOEvent etree.
event_ivorns (:class:`voeventparse.misc.EventIvorn`): List of EventIvorn
elements to add to citation list.


def scatter_sub(self, sparse_delta, use_locking=False, name=None):
    raise NotImplementedError

Subtracts `tf.IndexedSlices` from this variable.

Args:
sparse_delta: `tf.IndexedSlices` to be subtracted from this variable.
use_locking: If `True`, use locking during the operation.
name: the name of the operation.

Returns:
The updated variable.

Raises:
TypeError: if `sparse_delta` is not an `IndexedSlices`.


def getctime(self, path=None, client_kwargs=None, header=None):
    return self._getctime_from_header(self.head(path, client_kwargs, header))

Return the creation time of path.

Args:
path (str): File path or URL.
client_kwargs (dict): Client arguments.
header (dict): Object header.

Returns:
float: The number of seconds since the epoch
(see the time module).


def _key2seed(a):

    def int64_to_int32s(a):

        a = math_ops.cast(a, dtypes.uint64)
        fst = math_ops.cast(a, dtypes.uint32)
        snd = math_ops.cast(gen_bitwise_ops.right_shift(a, constant_op.constant(32, dtypes.uint64)), dtypes.uint32)
        a = [fst, snd]
        a = nest.map_structure(lambda x: math_ops.cast(x, dtypes.int32), a)
        a = array_ops_stack.stack(a)
        return a
    return int64_to_int32s(a)

Converts an RNG key to an RNG seed.

Args:
a: an RNG key, an ndarray of shape [] and dtype `np.int64`.

Returns:
an RNG seed, a tensor of shape [2] and dtype `tf.int32`.


def get_gap(self, tol=0.001, abs_tol=False, spin=None):

        (cbm, vbm) = self.get_cbm_vbm(tol, abs_tol, spin)
        return max(cbm - vbm, 0.0)

Expects a DOS object and finds the gap.

Args:
tol: tolerance in occupations for determining the gap
abs_tol: An absolute tolerance (True) and a relative one (False)
spin: Possible values are None - finds the gap in the summed
densities, Up - finds the gap in the up spin channel,
Down - finds the gap in the down spin channel.

Returns:
gap in eV


def cluster_from_file(filename):

        atoms_string = Atoms.atoms_string_from_file(filename)
        line_list = [l.split() for l in atoms_string.splitlines()[3:]]
        coords = []
        symbols = []
        for l in line_list:
            if l:
                coords.append([float(i) for i in l[:3]])
                symbols.append(l[4])
        return Molecule(symbols, coords)

Parse the feff input file and return the atomic cluster as a Molecule
object.

Args:
filename (str): path the feff input file

Returns:
Molecule: the atomic cluster as Molecule object. The absorbing atom
is the one at the origin.


def reset_partition_offset(self, partition):

        LATEST = -1
        EARLIEST = -2
        if self.auto_offset_reset == 'largest':
            reqs = [OffsetRequestPayload(self.topic, partition, LATEST, 1)]
        elif self.auto_offset_reset == 'smallest':
            reqs = [OffsetRequestPayload(self.topic, partition, EARLIEST, 1)]
        else:

            if sys.exc_info() == (None, None, None):
                raise OffsetOutOfRangeError('Cannot reset partition offsets without a '
                                            'valid auto_offset_reset setting '
                                            '(largest|smallest)')

            raise

        log.info('Resetting topic-partition offset to %s for %s:%d',
                 self.auto_offset_reset, self.topic, partition)
        try:
            (resp, ) = self.client.send_offset_request(reqs)
        except KafkaError as e:
            log.error('%s sending offset request for %s:%d',
                      e.__class__.__name__, self.topic, partition)
        else:
            self.offsets[partition] = resp.offsets[0]
            self.fetch_offsets[partition] = resp.offsets[0]
            return resp.offsets[0]

Update offsets using auto_offset_reset policy (smallest|largest)

Arguments:
partition (int): the partition for which offsets should be updated

Returns: Updated offset on success, None on failure


def read_local_config(cfg):

    try:
        if os.path.exists(cfg):
            config = import_file_object(cfg)
            return config
        else:
            logger.warning(
                '%s: local config file (%s) not found, cannot be read' %
                (inspect.stack()[0][3], str(cfg)))
    except IOError as e:
        logger.warning(
            'import_file_object: %s error opening %s' % (str(e), str(cfg))
        )
    return {}

Parses local config file for override values

Args:
:local_file (str):  filename of local config file

Returns:
dict object of values contained in local config file


def create_app(config=None, config_obj=None):
    app = Flask(__name__)
    configure_app(app, config=config, config_obj=config_obj)
    register_blueprints(app)
    bind_extensions(app)
    return app

Flask app factory function.

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


def form_uri(item_id, service, is_track):
    if is_track:
        uri = service.sonos_uri_from_id(item_id)
    else:
        uri = ('x-rincon-cpcontainer:' + item_id)
    return uri

Form and return a music service item uri

Args:
item_id (str): The item id
service (MusicService): The music service that the item originates from
is_track (bool): Whether the item_id is from a track or not

Returns:
str: The music service item uri


def __init__(self, host: str, port: int, command: Optional[str]=None, batch_size: int=100, embedded_columns: list=[]):
    self._host = host
    self._port = port
    self._command = command
    self._batch_size = batch_size
    self.embedded_columns = embedded_columns

Args:
host (str): The redis host
port (int): The redis port
command (str): command to be executed with redis client
batch_size (int): Number of key, values pairs to write at once
embedded_columns (list): list of column whose embedding needs to be generated

Returns:
:class:`~apache_beam.transforms.ptransform.PTransform`


def create_releasenotes(project_dir=os.curdir, bugtracker_url=''):
    pkg_info_file = os.path.join(project_dir, 'PKG-INFO')
    if os.path.exists(pkg_info_file):
        return
    with open('RELEASE_NOTES', 'wb') as releasenotes_fd:
        releasenotes_fd.write((get_releasenotes(project_dir=project_dir, bugtracker_url=bugtracker_url).encode('utf-8') + b'\n'))

Creates the release notes file, if not in a package.

Args:
project_dir(str): Path to the git repo of the project.
bugtracker_url(str): Url to the bug tracker for the issues.

Returns:
None

Raises:
RuntimeError: If the release notes could not be retrieved


def get_pull_request_number(task, source_env_prefix):

    pull_request = _extract_from_env_in_payload(task, source_env_prefix + '_PULL_REQUEST_NUMBER')
    if pull_request is not None:
        pull_request = int(pull_request)
    return pull_request

Get what Github pull request created the graph.

Args:
obj (ChainOfTrust or LinkOfTrust): the trust object to inspect
source_env_prefix (str): The environment variable prefix that is used
to get repository information.

Returns:
int: the pull request number.
None: if not defined for this task.


def remove_collisions(self, min_dist=0.5):
    vfcoords = [v.frac_coords for v in self.vnodes]
    sfcoords = self.structure.frac_coords
    dist_matrix = self.structure.lattice.get_all_distances(vfcoords, sfcoords)
    all_dist = np.min(dist_matrix, axis=1)
    new_vnodes = []
    for (i, v) in enumerate(self.vnodes):
        if (all_dist[i] > min_dist):
            new_vnodes.append(v)
    self.vnodes = new_vnodes

Remove vnodes that are too close to existing atoms in the structure

Args:
min_dist(float): The minimum distance that a vertex needs to be
from existing atoms.


def _GetParser(self):
    usage = 'nsscache synchronises a local NSS cache against a remote data source.\n\nUsage: nsscache [global options] command [command options]\n\ncommands:\n'
    command_descriptions = []
    for name, cls in list(command.__dict__.items()):
        if name == 'Command':
            continue
        if hasattr(cls, 'Help'):
            short_help = cls().Help(short=True)
            command_descriptions.append('  %-21s %.40s' % (name.lower(), short_help.lower()))
    usage += '\n'.join(command_descriptions)
    version_string = 'nsscache ' + nss_cache.__version__ + '\n\nCopyright (c) 2007 Google, Inc.\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\nWritten by Jamie Wilkinson and Vasilios Hoffman.'
    parser = optparse.OptionParser(usage, version=version_string)
    parser.disable_interspersed_args()
    parser.set_defaults(verbose=False, debug=False)
    parser.add_option('-v', '--verbose', action='store_true', help='enable verbose output')
    parser.add_option('-d', '--debug', action='store_true', help='enable debugging output')
    parser.add_option('-c', '--config-file', type='string', help='read configuration from FILE', metavar='FILE')
    old_get_usage = parser.get_usage

    def get_usage():
        return old_get_usage()[7:]
    parser.get_usage = get_usage
    return parser

Sets up our parser for global options.

Args:  None
Returns:
# OptionParser is from standard python module optparse
OptionParser


def rApply(d, f):
    remainingDicts = [(d, ())]
    while (len(remainingDicts) > 0):
        (current, prevKeys) = remainingDicts.pop()
        for (k, v) in current.iteritems():
            keys = (prevKeys + (k,))
            if isinstance(v, dict):
                remainingDicts.insert(0, (v, keys))
            else:
                f(v, keys)

Recursively applies f to the values in dict d.

Args:
d: The dict to recurse over.
f: A function to apply to values in d that takes the value and a list of
keys from the root of the dict to the value.


def delete(self, paths):
    raise NotImplementedError

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 create_new(mapreduce_id=None,
                 gettime=datetime.datetime.now):

    if not mapreduce_id:
      mapreduce_id = MapreduceState.new_mapreduce_id()
    state = MapreduceState(key_name=mapreduce_id,
                           last_poll_time=gettime())
    state.set_processed_counts([], [])
    return state

Create a new MapreduceState.

Args:
mapreduce_id: Mapreduce id as string.
gettime: Used for testing.