def parse_ensembl_line(line, header):
    line = line.rstrip().split('\t')
    header = [head.lower() for head in header]
    raw_info = dict(zip(header, line))
    ensembl_info = {}
    for word in raw_info:
        value = raw_info[word]
        if (not value):
            continue
        if ('chromosome' in word):
            ensembl_info['chrom'] = value
        if ('gene' in word):
            if ('id' in word):
                ensembl_info['ensembl_gene_id'] = value
            elif ('start' in word):
                ensembl_info['gene_start'] = int(value)
            elif ('end' in word):
                ensembl_info['gene_end'] = int(value)
        if ('hgnc symbol' in word):
            ensembl_info['hgnc_symbol'] = value
        if ('gene name' in word):
            ensembl_info['hgnc_symbol'] = value
        if ('hgnc id' in word):
            ensembl_info['hgnc_id'] = int(value.split(':')[(- 1)])
        if ('transcript' in word):
            if ('id' in word):
                ensembl_info['ensembl_transcript_id'] = value
            elif ('start' in word):
                ensembl_info['transcript_start'] = int(value)
            elif ('end' in word):
                ensembl_info['transcript_end'] = int(value)
        if ('exon' in word):
            if ('start' in word):
                ensembl_info['exon_start'] = int(value)
            elif ('end' in word):
                ensembl_info['exon_end'] = int(value)
            elif ('rank' in word):
                ensembl_info['exon_rank'] = int(value)
        if ('utr' in word):
            if ('start' in word):
                if ('5' in word):
                    ensembl_info['utr_5_start'] = int(value)
                elif ('3' in word):
                    ensembl_info['utr_3_start'] = int(value)
            elif ('end' in word):
                if ('5' in word):
                    ensembl_info['utr_5_end'] = int(value)
                elif ('3' in word):
                    ensembl_info['utr_3_end'] = int(value)
        if ('strand' in word):
            ensembl_info['strand'] = int(value)
        if ('refseq' in word):
            if ('mrna' in word):
                if ('predicted' in word):
                    ensembl_info['refseq_mrna_predicted'] = value
                else:
                    ensembl_info['refseq_mrna'] = value
            if ('ncrna' in word):
                ensembl_info['refseq_ncrna'] = value
    return ensembl_info

Parse an ensembl formated line

Args:
line(list): A list with ensembl gene info
header(list): A list with the header info

Returns:
ensembl_info(dict): A dictionary with the relevant info


def _PecoffHeaderParser(self):
    extents = {}
    self.file.seek(0, os.SEEK_SET)
    buf = self.file.read(2)
    if (buf != b'MZ'):
        return None
    self.file.seek(60, os.SEEK_SET)
    buf = self.file.read(4)
    pecoff_sig_offset = struct.unpack('<I', buf)[0]
    if (pecoff_sig_offset >= self.filelength):
        return None
    self.file.seek(pecoff_sig_offset, os.SEEK_SET)
    buf = self.file.read(4)
    if (buf != b'PE\x00\x00'):
        return None
    self.file.seek((pecoff_sig_offset + 20), os.SEEK_SET)
    buf = self.file.read(2)
    optional_header_size = struct.unpack('<H', buf)[0]
    optional_header_offset = ((pecoff_sig_offset + 4) + 20)
    if ((optional_header_size + optional_header_offset) > self.filelength):
        return None
    if (optional_header_size < 68):
        return None
    self.file.seek(optional_header_offset, os.SEEK_SET)
    buf = self.file.read(2)
    image_magic = struct.unpack('<H', buf)[0]
    if (image_magic == 267):
        rva_base = (optional_header_offset + 92)
        cert_base = (optional_header_offset + 128)
    elif (image_magic == 523):
        rva_base = (optional_header_offset + 108)
        cert_base = (optional_header_offset + 144)
    else:
        return None
    extents['CheckSum'] = RelRange((optional_header_offset + 64), 4)
    self.file.seek(rva_base, os.SEEK_SET)
    buf = self.file.read(4)
    number_of_rva = struct.unpack('<I', buf)[0]
    if ((number_of_rva < 5) or ((optional_header_offset + optional_header_size) < (cert_base + 8))):
        return extents
    extents['CertTable'] = RelRange(cert_base, 8)
    self.file.seek(cert_base, os.SEEK_SET)
    buf = self.file.read(8)
    (start, length) = struct.unpack('<II', buf)
    if ((length == 0) or (start < (optional_header_offset + optional_header_size)) or ((start + length) > self.filelength)):
        return extents
    extents['SignedData'] = RelRange(start, length)
    return extents

Parses PECOFF headers.

Reads header magic and some data structures in a file to determine if
it is a valid PECOFF header, and figure out the offsets at which
relevant data is stored.
While this code contains multiple seeks and small reads, that is
compensated by the underlying libc buffering mechanism.

Returns:
None if the parsed file is not PECOFF.
A dict with offsets and lengths for CheckSum, CertTable, and SignedData
fields in the PECOFF binary, for those that are present.


def _merge_retry_options(retry_options, overrides):

    if overrides is None:
        return None

    if overrides.retry_codes is None and overrides.backoff_settings is None:
        return retry_options

    codes = retry_options.retry_codes
    if overrides.retry_codes is not None:
        codes = overrides.retry_codes
    backoff_settings = retry_options.backoff_settings
    if overrides.backoff_settings is not None:
        backoff_settings = overrides.backoff_settings

    return gax.RetryOptions(
        backoff_settings=backoff_settings,
        retry_codes=codes,
    )

Helper for ``construct_settings()``.

Takes two retry options, and merges them into a single RetryOption instance.

Args:
retry_options (RetryOptions): The base RetryOptions.
overrides (RetryOptions): The RetryOptions used for overriding ``retry``.
Use the values if it is not None. If entire ``overrides`` is None,
ignore the base retry and return None.

Returns:
RetryOptions: The merged options, or None if it will be canceled.


def clean(self, value):

		if value is None and self._optional:
			return None

		if self._type == 'any':
			pass

		elif self._type in ['base64', 'ip', 'string', 'uuid']:

			if not isinstance(value, basestring):
				value = str(value)

		elif self._type == 'bool':

			if isinstance(value, basestring):
				value = (value in ('true', 'True', 'TRUE', 't', 'T', 'yes', 'Yes', 'YES', 'y', 'Y', 'x', '1') and True or False);

			else:
				value = (value and True or False)

		elif self._type == 'date':

			if isinstance(value, (datetime.date, datetime.datetime)):
				value = value.strftime('%Y-%m-%d')

			elif isinstance(value, basestring):
				pass

			else:
				value = str(value)

		elif self._type == 'datetime':

			if isinstance(value, datetime.datetime):
				value = value.strftime('%Y-%m-%d %H:%M:%S')
			elif isinstance(value, datetime.date):
				value = '%s 00:00:00' % value.strftime('%Y-%m-%d')

			elif isinstance(value, basestring):
				pass

			else:
				value = str(value)

		elif self._type == 'decimal':

			if not isinstance(value, Decimal):
				value = Decimal(value)

			value = '{0:f}'.format(value)

		elif self._type == 'float':
			value = float(value)

		elif self._type in ['int', 'timestamp', 'uint']:

			if isinstance(value, basestring):

				if value[0] == '0' and len(value) > 1:

					if value[1] in ['x', 'X'] and len(value) > 2:
						value = int(value, 16)

					else:
						value = int(value, 8)

				else:
					value = int(value)

			elif not isinstance(value, int):
				value = int(value)

		elif self._type == 'json':

			if isinstance(value, basestring):
				pass

			else:
				value = JSON.encode(value)

		elif self._type == 'md5':

			if isinstance(value, _MD5_TYPE):
				value = value.hexdigest()

			elif isinstance(value, basestring):
				pass

			else:
				value = str(value)

		elif self._type == 'price':

			if not isinstance(value, Decimal):
				value = Decimal(value)

			value = "{0:f}".format(value.quantize(Decimal('1.00')))

		elif self._type == 'time':

			if isinstance(value, (datetime.time, datetime.datetime)):
				value = value.strftime('%H:%M:%S')

			elif isinstance(value, basestring):
				pass

			else:
				value = str(value)

		else:
			raise Exception('%s has not been added to .clean()' % self._type)

		return value

Clean

Cleans and returns the new value

Arguments:
value {mixed} -- The value to clean

Returns:
mixed


def find_and_replace(self, node):

    if isinstance(node, nodes.reference) and 'refuri' in node:
      reference_uri = node['refuri']
      if reference_uri.endswith('.md') and not reference_uri.startswith('http'):
        reference_uri = reference_uri[:-3] + '.html'
        node['refuri'] = reference_uri
      else:
        match = self.ANCHOR_REGEX.match(reference_uri)
        if match:
          node['refuri'] = '{0:s}.html
              match.group('uri'), match.group('anchor'))
    return node

Parses URIs containing .md and replaces them with their HTML page.

Args:
node(node): docutils node.

Returns:
node: docutils node.


def guid(valu=None):
    if (valu is None):
        return binascii.hexlify(os.urandom(16)).decode('utf8')
    byts = s_msgpack.en(valu)
    return hashlib.md5(byts).hexdigest()

Get a 16 byte guid value.

By default, this is a random guid value.

Args:
valu: Object used to construct the guid valu from.  This must be able
to be msgpack'd.

Returns:
str: 32 character, lowercase ascii string.


def dna_generator(func: Callable[[DNASpec], Iterator[DNA]]):

    class SimpleDNAGenerator(DNAGenerator):

        def _setup(self):
            self._iterator = func(self.dna_spec)
            self._error = None

        def _propose(self) -> DNA:
            if self._error is not None:
                raise ValueError(f'Error happened earlier: {self._error}') from self._error
            try:
                return next(self._iterator)
            except Exception as e:
                if not isinstance(e, StopIteration):
                    self._error = e
                raise
    return SimpleDNAGenerator

Decorator that converts a generation function to a DNAGenerator class.

Example::

# A DNA generator that reads DNA from file.

def from_file(filepath):
@pg.geno.dna_generator
def file_based_dna_generator(dna_spec):
dna_list = pg.load(filepath)
for dna in dna_list:
dna.use_spec(dna_spec)
yield dna

return file_based_dna_generator

See also: :class:`pyglove.DNAGenerator`

Args:
func: the generation function in signature:
`(DNASpec) -> Iterator[DNA]`

Returns:
A DNAGenerator class.


def PathToComponents(path):
    precondition.AssertType(path, Text)
    if (path and (not path.startswith('/'))):
        raise ValueError("Path '{}' is not absolute".format(path))
    if path:
        return tuple(path.split('/')[1:])
    else:
        return ()

Converts a canonical path representation to a list of components.

Args:
path: A canonical MySQL path representation.

Returns:
A sequence of path components.


def compile(self, model):
    log = SensorLog(InMemoryStorageEngine(model), model)
    self.sensor_graph = SensorGraph(log, model)
    allocator = StreamAllocator(self.sensor_graph, model)
    self._scope_stack = []
    root = RootScope(self.sensor_graph, allocator)
    self._scope_stack.append(root)
    for statement in self.statements:
        statement.execute(self.sensor_graph, self._scope_stack)
    self.sensor_graph.initialize_remaining_constants()
    self.sensor_graph.sort_nodes()

Compile this file into a SensorGraph.

You must have preivously called parse_file to parse a
sensor graph file into statements that are then executed
by this command to build a sensor graph.

The results are stored in self.sensor_graph and can be
inspected before running optimization passes.

Args:
model (DeviceModel): The device model that we should compile
this sensor graph for.


def set_shutter_level(self, level=0.0):
    data = {'channelIndex': 1, 'deviceId': self.id, 'shutterLevel': level}
    return self._restCall('device/control/setShutterLevel', body=json.dumps(data))

sets the shutter level

Args:
level(float): the new level of the shutter. 0.0 = open, 1.0 = closed
Returns:
the result of the _restCall


def get_individual_positions(individuals):
    ind_pos = {}
    if individuals:
        for (i, ind) in enumerate(individuals):
            ind_pos[ind] = i
    return ind_pos

Return a dictionary with individual positions

Args:
individuals(list): A list with vcf individuals in correct order

Returns:
ind_pos(dict): Map from ind_id -> index position


def _apply_base_theme(app):
    if (QT_VERSION < (5,)):
        app.setStyle('plastique')
    else:
        app.setStyle('Fusion')
    with open(_STYLESHEET) as stylesheet:
        app.setStyleSheet(stylesheet.read())

Apply base theme to the application.

Args:
app (QApplication): QApplication instance.


def _LogSoftmaxGrad(op: ops.Operation, grad):
    softmax = math_ops.exp(op.outputs[0])
    return grad - math_ops.reduce_sum(grad, -1, keepdims=True) * softmax

The gradient for log_softmax.

log_softmax = input - log(sum(exp(input))
dlog_softmax/dinput = diag - softmax(input)

Args:
op: The log softmax op.
grad: The tensor representing the gradient w.r.t. the output.

Returns:
The gradients w.r.t. the input.


def exp(vector):
    weld_type = None
    if isinstance(vector, LazyOpResult):
        weld_type = vector.weld_type
        vector = vector.expr
    elif isinstance(vector, np.ndarray):
        weld_type = numpy_weld_impl.numpy_to_weld_type_mapping[str(vector.dtype)]
    return NumpyArrayWeld(numpy_weld_impl.exp(vector, weld_type), WeldDouble())

Computes a per-element exponent of the passed-in vector.

Args:
vector (TYPE): Description


def EWFGlobPathSpec(file_system, path_spec):

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

  parent_path_spec = path_spec.parent

  parent_location = getattr(parent_path_spec, 'location', None)
  if not parent_location:
    raise errors.PathSpecError(
        'Unsupported parent path specification without location.')

  parent_location, _, segment_extension = parent_location.rpartition('.')
  segment_extension_start = segment_extension[0]
  segment_extension_length = len(segment_extension)

  if (segment_extension_length not in [3, 4] or
      not segment_extension.endswith('01') or (
          segment_extension_length == 3 and
          segment_extension_start not in ['E', 'e', 's']) or (
              segment_extension_length == 4 and
              not segment_extension.startswith('Ex'))):
    raise errors.PathSpecError((
        'Unsupported parent path specification invalid segment file '
        'extension: {0:s}').format(segment_extension))

  segment_number = 1
  segment_files = []
  while True:
    segment_location = '{0:s}.{1:s}'.format(parent_location, segment_extension)

    kwargs = path_spec_factory.Factory.GetProperties(parent_path_spec)

    kwargs['location'] = segment_location
    if parent_path_spec.parent is not None:
      kwargs['parent'] = parent_path_spec.parent

    segment_path_spec = path_spec_factory.Factory.NewPathSpec(
        parent_path_spec.type_indicator, **kwargs)

    if not file_system.FileEntryExistsByPathSpec(segment_path_spec):
      break

    segment_files.append(segment_path_spec)

    segment_number += 1
    if segment_number <= 99:
      if segment_extension_length == 3:
        segment_extension = '{0:s}{1:02d}'.format(
            segment_extension_start, segment_number)
      elif segment_extension_length == 4:
        segment_extension = '{0:s}x{1:02d}'.format(
            segment_extension_start, segment_number)

    else:
      segment_index = segment_number - 100

      if segment_extension_start in ['e', 's']:
        letter_offset = ord('a')
      else:
        letter_offset = ord('A')

      segment_index, remainder = divmod(segment_index, 26)
      third_letter = chr(letter_offset + remainder)

      segment_index, remainder = divmod(segment_index, 26)
      second_letter = chr(letter_offset + remainder)

      first_letter = chr(ord(segment_extension_start) + segment_index)
      if first_letter in ['[', '{']:
        raise RuntimeError('Unsupported number of segment files.')

      if segment_extension_length == 3:
        segment_extension = '{0:s}{1:s}{2:s}'.format(
            first_letter, second_letter, third_letter)
      elif segment_extension_length == 4:
        segment_extension = '{0:s}x{1:s}{2:s}'.format(
            first_letter, second_letter, third_letter)

  return segment_files

Globs for path specifications according to the EWF naming schema.

Args:
file_system (FileSystem): file system.
path_spec (PathSpec): path specification.

Returns:
list[PathSpec]: path specifications that match the glob.

Raises:
PathSpecError: if the path specification is invalid.
RuntimeError: if the maximum number of supported segment files is
reached.


def on_test_batch_begin(self, batch, logs=None):
    if self._should_call_test_batch_hooks:
        self._call_batch_hook(ModeKeys.TEST, 'begin', batch, logs=logs)

Calls the `on_test_batch_begin` methods of its callbacks.

Args:
batch: Integer, index of batch within the current epoch.
logs: Dict, contains the return value of `model.test_step`. Typically,
the values of the `Model`'s metrics are returned.  Example:
`{'loss': 0.2, 'accuracy': 0.7}`.


def _ParseOrMerge(self, lines, message):
    tokenizer = _Tokenizer(lines)
    while (not tokenizer.AtEnd()):
        self._MergeField(tokenizer, message)

Converts an text representation of a protocol message into a message.

Args:
lines: Lines of a message's text representation.
message: A protocol buffer message to merge into.

Raises:
ParseError: On text parsing problems.


def boot(self):
    if (not self.responsive):
        type(self)._ports[self.port_key] = self.port
        init_func = capybara.servers[capybara.server_name]
        init_args = (self.middleware, self.port, self.host)
        self.server_thread = Thread(target=init_func, args=init_args)
        self.server_thread.daemon = True
        self.server_thread.start()
        timer = Timer(60)
        while (not self.responsive):
            if timer.expired:
                raise RuntimeError('WSGI application timed out during boot')
            self.server_thread.join(0.1)
    return self

Boots a server for the app, if it isn't already booted.

Returns:
Server: This server.


async def delete(self, name: str, *, force: bool=False, noprune: bool=False) -> List:
    params = {'force': force, 'noprune': noprune}
    response = (await self.docker._query_json('images/{name}'.format(name=name), 'DELETE', params=params))
    return response

Remove an image along with any untagged parent
images that were referenced by that image

Args:
name: name/id of the image to delete
force: remove the image even if it is being used
by stopped containers or has other tags
noprune: don't delete untagged parent images

Returns:
List of deleted images


def chi_squared(source_frequency, target_frequency):
    target_prob = frequency_to_probability(target_frequency)
    source_len = sum((v for (k, v) in source_frequency.items() if (k in target_frequency)))
    result = 0
    for (symbol, prob) in target_prob.items():
        symbol_frequency = source_frequency.get(symbol, 0)
        result += _calculate_chi_squared(symbol_frequency, prob, source_len)
    return result

Calculate the Chi Squared statistic by comparing ``source_frequency`` with ``target_frequency``.

Example:
>>> chi_squared({'a': 2, 'b': 3}, {'a': 1, 'b': 2})
0.1

Args:
source_frequency (dict): Frequency map of the text you are analyzing
target_frequency (dict): Frequency map of the target language to compare with

Returns:
Decimal value of the chi-squared statistic


def __call__(self, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]], text_pair: Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]]=None, xpaths: Optional[Union[List[List[int]], List[List[List[int]]]]]=None, node_labels: Optional[Union[List[int], List[List[int]]]]=None, add_special_tokens: bool=True, padding: Union[bool, str, PaddingStrategy]=False, truncation: Union[bool, str, TruncationStrategy]=None, max_length: Optional[int]=None, stride: int=0, pad_to_multiple_of: Optional[int]=None, padding_side: Optional[str]=None, return_tensors: Optional[Union[str, TensorType]]=None, return_token_type_ids: Optional[bool]=None, return_attention_mask: Optional[bool]=None, return_overflowing_tokens: bool=False, return_special_tokens_mask: bool=False, return_offsets_mapping: bool=False, return_length: bool=False, verbose: bool=True, **kwargs) -> BatchEncoding:

    def _is_valid_text_input(t):
        if isinstance(t, str):
            return True
        elif isinstance(t, (list, tuple)):
            if len(t) == 0:
                return True
            elif isinstance(t[0], str):
                return True
            elif isinstance(t[0], (list, tuple)):
                return len(t[0]) == 0 or isinstance(t[0][0], str)
            else:
                return False
        else:
            return False
    if text_pair is not None:
        if not _is_valid_text_input(text):
            raise ValueError('text input must of type `str` (single example) or `List[str]` (batch of examples). ')
        if not isinstance(text_pair, (list, tuple)):
            raise ValueError('Nodes must be of type `List[str]` (single pretokenized example), or `List[List[str]]` (batch of pretokenized examples).')
    elif not isinstance(text, (list, tuple)):
        raise ValueError('Nodes must be of type `List[str]` (single pretokenized example), or `List[List[str]]` (batch of pretokenized examples).')
    if text_pair is not None:
        is_batched = isinstance(text, (list, tuple))
    else:
        is_batched = isinstance(text, (list, tuple)) and text and isinstance(text[0], (list, tuple))
    nodes = text if text_pair is None else text_pair
    assert xpaths is not None, 'You must provide corresponding xpaths'
    if is_batched:
        assert len(nodes) == len(xpaths), 'You must provide nodes and xpaths for an equal amount of examples'
        for nodes_example, xpaths_example in zip(nodes, xpaths):
            assert len(nodes_example) == len(xpaths_example), 'You must provide as many nodes as there are xpaths'
    else:
        assert len(nodes) == len(xpaths), 'You must provide as many nodes as there are xpaths'
    if is_batched:
        if text_pair is not None and len(text) != len(text_pair):
            raise ValueError(f'batch length of `text`: {len(text)} does not match batch length of `text_pair`: {len(text_pair)}.')
        batch_text_or_text_pairs = list(zip(text, text_pair)) if text_pair is not None else text
        is_pair = bool(text_pair is not None)
        return self.batch_encode_plus(batch_text_or_text_pairs=batch_text_or_text_pairs, is_pair=is_pair, xpaths=xpaths, node_labels=node_labels, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, stride=stride, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)
    else:
        return self.encode_plus(text=text, text_pair=text_pair, xpaths=xpaths, node_labels=node_labels, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, stride=stride, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)

Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
sequences with node-level xpaths and optional labels.

Args:
text (`str`, `List[str]`, `List[List[str]]`):
The sequence or batch of sequences to be encoded. Each sequence can be a string, a list of strings
(nodes of a single example or questions of a batch of examples) or a list of list of strings (batch of
nodes).
text_pair (`List[str]`, `List[List[str]]`):
The sequence or batch of sequences to be encoded. Each sequence should be a list of strings
(pretokenized string).
xpaths (`List[List[int]]`, `List[List[List[int]]]`):
Node-level xpaths.
node_labels (`List[int]`, `List[List[int]]`, *optional*):
Node-level integer labels (for token classification tasks).


def optimal_set_cover(universe, subsets, costs):

    pset = powerset(subsets.keys())
    best_set = None
    best_cost = float("inf")
    for subset in pset:
        covered = set()
        cost = 0
        for s in subset:
            covered.update(subsets[s])
            cost += costs[s]
        if len(covered) == len(universe) and cost < best_cost:
            best_set = subset
            best_cost = cost
    return best_set

Optimal algorithm - DONT USE ON BIG INPUTS - O(2^n) complexity!
Finds the minimum cost subcollection os S that covers all elements of U

Args:
universe (list): Universe of elements
subsets (dict): Subsets of U {S1:elements,S2:elements}
costs (dict): Costs of each subset in S - {S1:cost, S2:cost...}


def parse_requires(__fname: str) -> List[str]:
    deps = []
    with open(__fname) as req_file:
        entries = [s.split('
        for dep in entries:
            if (not dep):
                continue
            elif dep.startswith('-r '):
                include = dep.split()[1]
                if ('/' not in include):
                    include = path.join(path.dirname(__fname), include)
                deps.extend(parse_requires(include))
                continue
            elif (';' in dep):
                (dep, marker) = [s.strip() for s in dep.split(';')]
                match = re.fullmatch('\n                        (?:python_version)
                if (not match):
                    raise ValueError('Invalid marker {!r}'.format(marker))
                env = {'__builtins__': {}, 'python_version': '{}.{}'.format(*version_info[:2])}
                if (not eval(marker, env)):
                    continue
            deps.append(dep)
    return deps

Parse ``pip``-style requirements files.

This is a *very* naïve parser, but very few packages make use of the more
advanced features.  Support for other features will be added only when
packages in the wild depend on them.

Args:
__fname: Base file to pass
Returns:
Parsed dependencies


def _contextualise_connection(self, connection):

        ctx = stack.top
        if ctx is not None:
            if not hasattr(ctx, 'ldap3_manager_connections'):
                ctx.ldap3_manager_connections = [connection]
            else:
                ctx.ldap3_manager_connections.append(connection)

Add a connection to the appcontext so it can be freed/unbound at
a later time if an exception occured and it was not freed.

Args:
connection (ldap3.Connection): Connection to add to the appcontext


def save(self, path="speech"):

        if self._data is None:
            raise Exception("There's nothing to save")

        extension = "." + self.__params["format"]
        if os.path.splitext(path)[1] != extension:
            path += extension

        with open(path, "wb") as f:
            for d in self._data:
                f.write(d)

        return path

Save data in file.

Args:
path (optional): A path to save file. Defaults to "speech".
File extension is optional. Absolute path is allowed.

Returns:
The path to the saved file.


def remove_sites_from_neighbours(self, remove_labels):
    if (type(remove_labels) is str):
        remove_labels = [remove_labels]
    self.neighbours = set((n for n in self.neighbours if (n.label not in remove_labels)))

Removes sites from the set of neighbouring sites if these have labels in remove_labels.

Args:
Remove_labels (List) or (Str): List of Site labels to be removed from the cluster neighbour set.

Returns:
None


def download(self, url, destination_path):

    self._pbar_url.update_total(1)
    future = self._executor.submit(self._sync_download, url, destination_path)
    return promise.Promise.resolve(future)

Download url to given path.

Returns Promise -> sha256 of downloaded file.

Args:
url: address of resource to download.
destination_path: `str`, path to directory where to download the resource.

Returns:
Promise obj -> (`str`, int): (downloaded object checksum, size in bytes).


def _SchemedMerge(self, scheme, a, b):
    migrated = self._Migrate(b, self.feed_merger.b_schedule, False)
    for (attr, merger) in scheme.items():
        a_attr = getattr(a, attr, None)
        b_attr = getattr(b, attr, None)
        try:
            merged_attr = merger(a_attr, b_attr)
        except MergeError as merge_error:
            raise MergeError(("Attribute '%s' could not be merged: %s." % (attr, merge_error)))
        setattr(migrated, attr, merged_attr)
    return migrated

Tries to merge two entities according to a merge scheme.

A scheme is specified by a map where the keys are entity attributes and the
values are merge functions like Merger._MergeIdentical or
Merger._MergeOptional. The entity is first migrated to the merged schedule.
Then the attributes are individually merged as specified by the scheme.

Args:
scheme: The merge scheme, a map from entity attributes to merge
functions.
a: The entity from the old schedule.
b: The entity from the new schedule.

Returns:
The migrated and merged entity.

Raises:
MergeError: One of the attributes was not able to be merged.


def build_graph(device, dtype, data_format, input_shape, filter_shape, strides, padding, num_iters, warmup_iters):
    with ops.device('/%s:0' % device):
        inp = variable_v1.VariableV1(random_ops.truncated_normal(input_shape, dtype=dtype))
        filt = variable_v1.VariableV1(random_ops.truncated_normal(filter_shape, dtype=dtype))
        outputs = []
        conv2d_op = nn_ops.conv2d(inp, filt, strides, padding, data_format=data_format)
        outputs.append(conv2d_op)
        for _ in range(1, num_iters):
            with ops.control_dependencies([conv2d_op]):
                conv2d_op = nn_ops.conv2d(inp, filt, strides, padding, data_format=data_format)
                outputs.append(conv2d_op)
        warmup_groups = []
        warmup_conv2d_op = nn_ops.conv2d(inp, filt, strides, padding, data_format=data_format)
        warmup_groups.append(warmup_conv2d_op)
        for _ in range(1, warmup_iters):
            with ops.control_dependencies([warmup_conv2d_op]):
                warmup_conv2d_op = nn_ops.conv2d(inp, filt, strides, padding, data_format=data_format)
                warmup_groups.append(warmup_conv2d_op)
        return (control_flow_ops.group(*warmup_groups), control_flow_ops.group(*outputs))

builds a graph containing a sequence of conv2d operations.

Args:
device: String, the device to run on.
dtype: Data type for the convolution.
data_format: A string from: "NHWC" or "NCHW". Data format for input and
output data.
input_shape: Shape of the input tensor.
filter_shape: Shape of the filter tensor.
strides: A list of ints. 1-D of length 4. The stride of sliding
window for each dimension of input.
padding: A string from: "SAME", "VALID". The type of padding
algorithm to use.
num_iters: number of iterations to run conv2d.
warmup_iters: number of iterations for warmup runs.

Returns:
An array of tensors to run()


def zero_state(self, sample_batch_shape=()):

    h0 = tf.zeros([1, self.hidden_size])
    c0 = tf.zeros([1, self.hidden_size])
    combined_shape = tf.concat((tf.convert_to_tensor(
        value=sample_batch_shape, dtype=tf.int32), [self.dimensions]),
                               axis=-1)
    previous_output = tf.zeros(combined_shape)
    return previous_output, (h0, c0)

Returns an initial state for the LSTM cell.

Args:
sample_batch_shape: A 0D or 1D tensor of the combined sample and
batch shape.

Returns:
A tuple of the initial previous output at timestep 0 of shape
[sample_batch_shape, dimensions], and the cell state.


def initialize(self, prefix_name='default', *args, **kwargs):

        if self.loaded:
            raise WorkdirError('Workdir %s already initialized' % self.path)

        if not os.path.exists(self.path):
            LOGGER.debug('Creating workdir %s', self.path)
            os.makedirs(self.path)

        self.prefixes[prefix_name] = self.prefix_class(
            self.join(prefix_name), *args, **kwargs
        )
        self.prefixes[prefix_name].initialize()
        if self.current is None:
            self._set_current(prefix_name)

        self.load()

        return self.prefixes[prefix_name]

Initializes a workdir by adding a new prefix to the workdir.

Args:
prefix_name(str): Name of the new prefix to add
*args: args to pass along to the prefix constructor
*kwargs: kwargs to pass along to the prefix constructor

Returns:
The newly created prefix

Raises:
PrefixAlreadyExists: if the prefix name already exists in the
workdir


def allocate(self, manager=None):

        for i, task in enumerate(self):

            if not hasattr(task, "manager"):

                if manager is not None:
                    task.set_manager(manager)
                else:

                    if hasattr(self, "manager"):
                        task.set_manager(self.manager)
                    else:
                        task.set_manager(self.flow.manager)

            task_workdir = os.path.join(self.workdir, "t" + str(i))

            if not hasattr(task, "workdir"):
                task.set_workdir(task_workdir)
            else:
                if task.workdir != task_workdir:
                    raise ValueError("task.workdir != task_workdir: %s, %s" % (task.workdir, task_workdir))

This function is called once we have completed the initialization
of the :class:`Work`. It sets the manager of each task (if not already done)
and defines the working directories of the tasks.

Args:
manager: :class:`TaskManager` object or None


def set_column(self, X, column, value):

        if isinstance(X, pd.DataFrame):
            X.loc[:, column] = value

        else:
            X[:, column] = value

        return X

Sets a column on the matrix X with the given value.

Args:
X: `numpy.ndarray` or `pandas.DataFrame`.
column: `int` or `str`.
value: `np.ndarray` with shape (1,)

Returns:
`np.ndarray` or `pandas.DataFrame` with the inserted column.


def get_updates(self, display_all_distributions=False, verbose=False):
    if verbose:
        logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(message)s')
        logging.info('Checking installed packages for updates...')
    updates = self._get_environment_updates(display_all_distributions=display_all_distributions)
    if updates:
        for update in updates:
            logging.info(update)
    if (updates and self._csv_file_name):
        self.write_updates_to_csv(updates)
    if (updates and self._new_config):
        self.write_new_config(updates)
    return updates

When called, get the environment updates and write updates to a CSV
file and if a new config has been provided, write a new configuration
file.

Args:
display_all_distributions (bool): Return distribution even if it is
up-to-date.
verbose (bool): If ``True``, log to terminal to terminal.


def report_proto(self):
    if self._report_proto:
        return self._report_proto
    else:
        raise ValueError('Call to report_proto must be done after tracing.Report proto only exists for trace_mode=[summary|full_tensor_summary]')

Getter for tensor_tracer.proto object for summary and full_tensor_summary modes.

Returns:
A tensor_tracer.proto object.
Raises:
ValueError if called before tracing happens, or when trace mode is not
summary or full_tensor_summary.


def recipe_hello(config, auth_read, say_first, say_second, error, sleep):
    hello(config, {'auth': auth_read, 'say': say_first, 'error': error, 'sleep': sleep})
    hello(config, {'auth': auth_read, 'say': say_second, 'sleep': sleep})

Recipe template for say hello.

Args:
auth_read (authentication) - Credentials used for reading data.
say_first (string) - Type in a greeting.
say_second (string) - Type in a greeting.
error (string) - Optional error for testing.
sleep (integer) - Seconds to sleep.


def fixminimized(self, alphabet):

        insymbols = fst.SymbolTable()
        outsymbols = fst.SymbolTable()
        num = 1
        for char in self.alphabet:
            self.isyms.__setitem__(char, num)
            self.osyms.__setitem__(char, num)
            insymbols.add_symbol(char, num)
            outsymbols.add_symbol(char, num)
            num = num + 1
        self.automaton.set_input_symbols(insymbols)
        self.automaton.set_output_symbols(outsymbols)
        endstate = self.add_state()
        for state in self.states:
            for char in alphabet:
                found = 0
                for arc in state.arcs:
                    if self.isyms.find(arc.ilabel) == char:
                        found = 1
                        break
                if found == 0:
                    self.add_arc(state.stateid, endstate, char)
        self[endstate].final = False

        for char in alphabet:
            self.add_arc(endstate, endstate, char)

After pyfst minimization,
all unused arcs are removed,
and all sink states are removed.
However this may break compatibility.
Args:
alphabet (list): The input alphabet
Returns:
None


def patch(self, id, name=None, description=None, private=None, runs_executable_tasks=None, runs_docker_container_tasks=None, runs_singularity_container_tasks=None, active=None, whitelists=None):
    request_url = (self._client.base_api_url + self.detail_url.format(id=id))
    data_to_patch = {}
    if (name is not None):
        data_to_patch['name'] = name
    if (description is not None):
        data_to_patch['description'] = description
    if (private is not None):
        data_to_patch['private'] = private
    if (runs_executable_tasks is not None):
        data_to_patch['runs_executable_tasks'] = runs_executable_tasks
    if (runs_docker_container_tasks is not None):
        data_to_patch['runs_docker_container_tasks'] = runs_docker_container_tasks
    if (runs_singularity_container_tasks is not None):
        data_to_patch['runs_singularity_container_tasks'] = runs_singularity_container_tasks
    if (active is not None):
        data_to_patch['active'] = active
    if (whitelists is not None):
        data_to_patch['whitelists'] = whitelists
    response = self._client.session.patch(request_url, data=data_to_patch)
    self.validate_request_success(response_text=response.text, request_url=request_url, status_code=response.status_code, expected_status_code=HTTP_200_OK)
    return self.response_data_to_model_instance(response.json())

Partially updates a task queue on the saltant server.

Args:
id (int): The ID of the task queue.
name (str, optional): The name of the task queue.
description (str, optional): The description of the task
queue.
private (bool, optional): A Booleon signalling whether the
queue can only be used by its associated user.
runs_executable_tasks (bool, optional): A Boolean specifying
whether the queue runs executable tasks.
runs_docker_container_tasks (bool, optional): A Boolean
specifying whether the queue runs container tasks that
run in Docker containers.
runs_singularity_container_tasks (bool, optional): A Boolean
specifying whether the queue runs container tasks that
run in Singularity containers.
active (bool, optional): A Booleon signalling whether the
queue is active.
whitelists (list, optional): A list of task whitelist IDs.

Returns:
:class:`saltant.models.task_queue.TaskQueue`:
A task queue model instance representing the task queue
just updated.


def escalatee(self, escalatee_id, action='ADD'):

        if not self.can_update():
            self._tcex.handle_error(910, [self.type])

        return self.tc_requests.escalatee(
            self.api_type, self.api_sub_type, self.unique_id, escalatee_id, action=action
        )

Adds a assignee to the task

Args:
escalatee_id: The id of the escalatee to be added
action:


def _build_shuffle_hybrid(input_tensors, gather_devices, red_op, upper_level_f):
    input_tensors, shape = _flatten_tensors(input_tensors)
    devices = [t.device for t in input_tensors]
    per_worker_devices, per_worker_values = _split_by_task(devices, input_tensors)
    num_workers = len(per_worker_devices)
    up_values = []
    if len(gather_devices) != num_workers:
        raise ValueError('For shuffle hybrid, gather_devices must contain one device per worker. ')
    for w in range(0, num_workers):
        reduced_shards = _build_shuffle_gather(per_worker_values[w], [gather_devices[w]], red_op)
        up_values.append(reduced_shards[0])
    level_2_output = upper_level_f(up_values)
    output_tensors = []
    for w in range(0, num_workers):
        output_tensors += _build_shuffle_scatter([level_2_output[w]], per_worker_devices[w])
    if len(shape) != 1:
        output_tensors = _reshape_tensors(output_tensors, shape)
    return output_tensors

Construct a subgraph for Shuffle hybrid all-reduce.

Args:
input_tensors: list of `tf.Tensor` of same-shape and type values to
be reduced.
gather_devices: list of device names on which to host gather shards.
red_op: binary elementwise reduction operator.
upper_level_f: function for reducing one value per worker, across
workers.

Returns:
list of `tf.Tensor` of reduced values.

Raises:
ValueError: inputs not well-formed.


def __delattr__(self, __key: Hashable) -> None:

        try:
            del self[__key]
        except TypeError as err:
            raise AttributeError(str(err))

Support item deletion via dot notation.

Args:
__key: Key to delete