def apply_grad_processors(opt, gradprocs):

    assert isinstance(gradprocs, (list, tuple)), gradprocs
    for gp in gradprocs:
        assert isinstance(gp, GradientProcessor), gp

    class _ApplyGradientProcessor(ProxyOptimizer):
        def __init__(self, opt, gradprocs):
            self._gradprocs = gradprocs[:]
            super(_ApplyGradientProcessor, self).__init__(opt)

        def apply_gradients(self, grads_and_vars,
                            global_step=None, name=None):
            g = self._apply(grads_and_vars)
            return self._opt.apply_gradients(g, global_step, name)

        def _apply(self, g):
            for proc in self._gradprocs:
                g = proc.process(g)
            return g

    return _ApplyGradientProcessor(opt, gradprocs)

Wrapper around optimizers to apply gradient processors.

Args:
        opt (tf.train.Optimizer):
        gradprocs (list[GradientProcessor]): gradient processors to add to the
            optimizer.

Returns:
        a :class:`tf.train.Optimizer` instance which runs the gradient
        processors before updating the variables.


def get_corrections_dict(self, entry):

        corrections = {}
        for c in self.corrections:
            val = c.get_correction(entry)
            if val != 0:
                corrections[str(c)] = val
        return corrections

Returns the corrections applied to a particular entry.

Args:
        entry: A ComputedEntry object.

Returns:
        ({correction_name: value})


def semantic_eq(node1, node2):

        # For barriers, qarg order is not significant so compare as sets
        if 'barrier' == node1.name == node2.name:
            return set(node1.qargs) == set(node2.qargs)
        return node1.data_dict == node2.data_dict

Check if DAG nodes are considered equivalent, e.g. as a node_match for nx.is_isomorphic.

Args:
        node1 (DAGNode): A node to compare.
        node2 (DAGNode): The other node to compare.

Returns:
        Bool: If node1 == node2


def _convert_oauth2_credentials(credentials):

    new_credentials = google.oauth2.credentials.Credentials(
        token=credentials.access_token,
        refresh_token=credentials.refresh_token,
        token_uri=credentials.token_uri,
        client_id=credentials.client_id,
        client_secret=credentials.client_secret,
        scopes=credentials.scopes)

    new_credentials._expires = credentials.token_expiry

    return new_credentials

Converts to :class:`google.oauth2.credentials.Credentials`.

Args:
        credentials (Union[oauth2client.client.OAuth2Credentials,
            oauth2client.client.GoogleCredentials]): The credentials to
            convert.

Returns:
        google.oauth2.credentials.Credentials: The converted credentials.


def post_build(self, p, pay):

    p += pay
    if self.type in [0, 0x31, 0x32, 0x22]:   # for these, field is reserved (0)
      p = p[:1]+chr(0)+p[2:]
    if self.chksum is None:
      ck = checksum(p[:2]+p[4:])
      p = p[:2]+ck.to_bytes(2, 'big')+p[4:]
    return p

Called implicitly before a packet is sent to compute and place IGMPv3 checksum.

    Parameters:
        self    The instantiation of an IGMPv3 class
        p       The IGMPv3 message in hex in network byte order
        pay     Additional payload for the IGMPv3 message


def bulk_get_or_create(self, data_list):

        items_to_create = dict()
        for record_key, record_config in data_list.items():
            if record_key not in items_to_create:
                record = self.get_instance(record_key)
                if not record:
                    items_to_create[record_key] = self.model_cls(**record_config)
        if items_to_create:

            self.model_cls.objects.bulk_create(items_to_create.values())
            self.set_record_lookup(True)
        return self.record_lookup

data_list is the data to get or create
    We generate the query and set all the record keys based on passed in queryset
    Then we loop over each item in the data_list, which has the keys already! No need to generate them.  Should save a lot of time
    Use values instead of the whole object, much faster

Args:
        data_list:

    Returns:


def __mutate_parameter(value, param, mut_rate, max_mut_amt):

        if uniform(0, 1) < mut_rate:
            mut_amt = uniform(0, max_mut_amt)
            op = choice((add, sub))
            new_val = op(value, param.dtype(
                (param.max_val - param.min_val) * mut_amt
            ))
            if new_val > param.max_val:
                return param.max_val
            elif new_val < param.min_val:
                return param.min_val
            else:
                return new_val
        else:
            return value

Private, static method: mutates parameter

Args:
        value (int or float): current value for Member's parameter
        param (Parameter): parameter object
        mut_rate (float): mutation rate of the value
        max_mut_amt (float): maximum mutation amount of the value

Returns:
        int or float: mutated value


def largestTradesDF(symbol, token='', version=''):

    df = pd.DataFrame(largestTrades(symbol, token, version))
    _toDatetime(df)
    _reindex(df, 'time')
    return df

This returns 15 minute delayed, last sale eligible trades.

    https://iexcloud.io/docs/api/#largest-trades
    9:30-4pm ET M-F during regular market hours

Args:
        symbol (string); Ticker to request
        token (string); Access token
        version (string); API version

Returns:
        DataFrame: result


def apply_pairwise(self, function, symmetric=True, diagonal=False, block=None, **kwargs):

    steps = self.index
    r = pd.DataFrame(index=steps, columns=steps)
    for i, s1 in enumerate(steps):
        j = range(i+1 if symmetric else len(steps))
        if not diagonal:
            j.remove(i)
        other = set(steps[j])
        if block is not None:
            df = self.reset_index()
            df = df.merge(df, on=block)
            other &= set(df[df.index_x == s1].index_y)

        for s2 in other:
            r.ix[s1, s2] = function(s1, s2, **kwargs)
    return r

Helper function for pairwise apply.

Args:
        steps: an ordered collection of steps
        function: function to apply, first two positional arguments are steps
        symmetric: whether function is symmetric in the two steps
        diagonal: whether to apply on the diagonal
        block: apply only when the given columns match
        kwargs: keyword arguments to pass to the function

Returns:
        DataFrame with index and columns equal to the steps argument


def __call__(self, utterances_batch: list, utterances_ids: Optional[list] = None) -> list:

        responses_batch = self._call(utterances_batch, utterances_ids)

        batch_size = len(utterances_batch)
        ids = utterances_ids or list(range(batch_size))

        for utt_batch_idx, utt_id in enumerate(ids):
            self.history[utt_id].append(str(utterances_batch[utt_batch_idx]))
            self.dialog_logger.log_in(utterances_batch[utt_batch_idx], utt_id)

            self.history[utt_id].append(str(responses_batch[utt_batch_idx]))
            self.dialog_logger.log_out(responses_batch[utt_batch_idx], utt_id)

        return responses_batch

Wraps _call method and updates utterances history.

Args:
        utterances_batch: Batch of incoming utterances.
        utterances_ids: Batch of dialog IDs corresponding to incoming utterances.

Returns:
        responses: A batch of responses corresponding to the
            utterance batch received by agent.


def add_segment(self, address, data, overwrite=False):

        seg_type = self._classify_segment(address, len(data))
        if not isinstance(seg_type, DisjointSegment):
            raise ArgumentError("Unsupported segment type")

        segment = MemorySegment(address, address+len(data)-1, len(data), bytearray(data))
        self._segments.append(segment)

Add a contiguous segment of data to this memory map

    If the segment overlaps with a segment already added , an
    ArgumentError is raised unless the overwrite flag is True.

    Params:
        address (int): The starting address for this segment
        data (bytearray): The data to add
        overwrite (bool): Overwrite data if this segment overlaps
            with one previously added.


def open(self, **params):

        logger.info('opening telnet')
        self.port = params['port']
        self.ip = params['ip']
        self.tn = None
        self._init()

Open telnet connection

Args:
        params (dict), must contain two parameters "ip" - ip address or hostname and "port" - port number

Example:
        params = {'port': 23, 'ip': 'localhost'}


def create_checksum_object_from_iterator(
    itr, algorithm=d1_common.const.DEFAULT_CHECKSUM_ALGORITHM
):

    checksum_str = calculate_checksum_on_iterator(itr, algorithm)
    checksum_pyxb = d1_common.types.dataoneTypes.checksum(checksum_str)
    checksum_pyxb.algorithm = algorithm
    return checksum_pyxb

Calculate the checksum of an iterator.

Args:
        itr: iterable
        Object which supports the iterator protocol.

        algorithm: str
        Checksum algorithm, ``MD5`` or ``SHA1`` / ``SHA-1``.

Returns:
        Populated Checksum PyXB object.


def __init__(self, action_type=None, nw_addr=None):

        super().__init__(action_type, length=8)
        self.nw_addr = nw_addr

Create an ActionNWAddr with the optional parameters below.

Args:
        action_type (:class:`~pyof.v0x01.common.action.ActionType`):
            :attr:`~ActionType.OFPAT_SET_NW_SRC` or
            :attr:`~ActionType.OFPAT_SET_NW_DST`.
        nw_addr (int): IP Address.


def _Open(self, path_spec, mode='rb'):

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

    range_offset = getattr(path_spec, 'range_offset', None)
    if range_offset is None:
      raise errors.PathSpecError(
          'Unsupported path specification without encoding method.')

    range_size = getattr(path_spec, 'range_size', None)
    if range_size is None:
      raise errors.PathSpecError(
          'Unsupported path specification without encoding method.')

    self._range_offset = range_offset
    self._range_size = range_size

Opens the file system defined by path specification.

Args:
        path_spec (PathSpec): a path specification.
        mode (Optional[str]): file access mode. The default is 'rb' which
        represents read-only binary.

Raises:
        AccessError: if the access to open the file was denied.
        IOError: if the file system could not be opened.
        PathSpecError: if the path specification is incorrect.
        ValueError: if the path specification is invalid.


def split_folder_and_path(filepath):

    dirname = op.dirname(filepath)
    filename = op.basename(filepath)
    splitext = op.splitext(filename)
    filename_without_extension = splitext[0]
    extension = splitext[1]

    return dirname, filename_without_extension, extension

Split a file path into its folder, filename, and extension

Args:
        path (str): Path to a file

Returns:
        tuple: of (folder, filename (without extension), extension)


def empty(shape, dtype=None, **kwargs):

    data = np.empty(shape, dtype)
    return dc.array(data, **kwargs)

Create an array of given shape and type, without initializing entries.

Args:
        shape (sequence of ints): 2D shape of the array.
        dtype (data-type, optional): Desired data-type for the array.
        kwargs (optional): Other arguments of the array (*coords, attrs, and name).

Returns:
        array (decode.array): Decode array without initializing entries.


def start(self, on_done):

        genesis_file = os.path.join(self._data_dir, 'genesis.batch')
        try:
            with open(genesis_file, 'rb') as batch_file:
                genesis_data = genesis_pb2.GenesisData()
                genesis_data.ParseFromString(batch_file.read())
            LOGGER.info('Producing genesis block from %s', genesis_file)
        except IOError:
            raise InvalidGenesisStateError(
                "Genesis File {} specified, but unreadable".format(
                    genesis_file))

        initial_state_root = self._context_manager.get_first_root()

        genesis_batches = [batch for batch in genesis_data.batches]
        if genesis_batches:
            scheduler = SerialScheduler(
                self._context_manager.get_squash_handler(),
                initial_state_root,
                always_persist=True)

            LOGGER.debug('Adding %s batches', len(genesis_data.batches))
            for batch in genesis_data.batches:
                scheduler.add_batch(batch)

            self._transaction_executor.execute(scheduler)

            scheduler.finalize()
            scheduler.complete(block=True)

        txn_receipts = []
        state_hash = initial_state_root
        for batch in genesis_batches:
            result = scheduler.get_batch_execution_result(
                batch.header_signature)
            if result is None or not result.is_valid:
                raise InvalidGenesisStateError(
                    'Unable to create genesis block, due to batch {}'
                    .format(batch.header_signature))
            if result.state_hash is not None:
                state_hash = result.state_hash

            txn_results = scheduler.get_transaction_execution_results(
                batch.header_signature)
            txn_receipts += self._make_receipts(txn_results)

        settings_view = SettingsView(
            self._state_view_factory.create_view(state_hash))
        name = settings_view.get_setting('sawtooth.consensus.algorithm.name')
        version = settings_view.get_setting(
            'sawtooth.consensus.algorithm.version')
        if name is None or version is None:
            raise LocalConfigurationError(
                'Unable to start validator; sawtooth.consensus.algorithm.name '
                'and sawtooth.consensus.algorithm.version must be set in the '
                'genesis block.')

        LOGGER.debug('Produced state hash %s for genesis block.', state_hash)

        block_builder = self._generate_genesis_block()
        block_builder.add_batches(genesis_batches)
        block_builder.set_state_hash(state_hash)

        block_publisher = self._get_block_publisher(initial_state_root)
        if not block_publisher.initialize_block(block_builder.block_header):
            LOGGER.error('Consensus refused to initialize consensus block.')
            raise InvalidGenesisConsensusError(
                'Consensus refused to initialize genesis block.')

        if not block_publisher.finalize_block(block_builder.block_header):
            LOGGER.error('Consensus refused to finalize genesis block.')
            raise InvalidGenesisConsensusError(
                'Consensus refused to finalize genesis block.')

        self._sign_block(block_builder)

        block = block_builder.build_block()

        blkw = BlockWrapper(block=block)

        LOGGER.info('Genesis block created: %s', blkw)

        self._block_manager.put([blkw.block])
        self._block_manager.persist(blkw.identifier, "commit_store")

        self._txn_receipt_store.chain_update(block, txn_receipts)
        self._chain_id_manager.save_block_chain_id(block.header_signature)

        LOGGER.debug('Deleting genesis data.')
        os.remove(genesis_file)

        if on_done is not None:
            on_done()

Starts the genesis block creation process.  Will call the given
    `on_done` callback on successful completion.

Args:
        on_done (function): a function called on completion

Raises:
        InvalidGenesisStateError: raises this error if a genesis block is
            unable to be produced, or the resulting block-chain-id saved.


def scope(self, framebuffer, enable_only=None, *, textures=(), uniform_buffers=(), storage_buffers=()) -> 'Scope':

        textures = tuple((tex.mglo, idx) for tex, idx in textures)
        uniform_buffers = tuple((buf.mglo, idx) for buf, idx in uniform_buffers)
        storage_buffers = tuple((buf.mglo, idx) for buf, idx in storage_buffers)

        res = Scope.__new__(Scope)
        res.mglo = self.mglo.scope(framebuffer.mglo, enable_only, textures, uniform_buffers, storage_buffers)
        res.ctx = self
        res.extra = None
        return res

Create a :py:class:`Scope` object.

Args:
        framebuffer (Framebuffer): The framebuffer to use when entering.
        enable_only (int): The enable_only flags to set when entering.

    Keyword Args:
        textures (list): List of (texture, binding) tuples.
        uniform_buffers (list): List of (buffer, binding) tuples.
        storage_buffers (list): List of (buffer, binding) tuples.


def _clean_isbn(isbn):

    if isinstance(isbn, basestring):
        isbn = list(isbn.lower())

        # filter digits and "x"
        isbn = filter(lambda x: x.isdigit() or x == "x", isbn)

    # convert ISBN to numbers
    return map(lambda x: 10 if x == "x" else int(x), isbn)

Remove all non-digit and non "x" characters from given string.

Args:
        isbn (str): isbn string, which will be cleaned.

Returns:
        list: array of numbers (if "x" is found, it is converted to 10).


def tradesDF(symbol=None, token='', version=''):

    x = trades(symbol, token, version)
    data = []
    for key in x:
        dat = x[key]
        for d in dat:
            d['symbol'] = key
            data.append(d)
    df = pd.DataFrame(data)
    _toDatetime(df)
    return df

Trade report messages are sent when an order on the IEX Order Book is executed in whole or in part. DEEP sends a Trade report message for every individual fill.

    https://iexcloud.io/docs/api/#deep-trades

Args:
        symbol (string); Ticker to request
        token (string); Access token
        version (string); API version

Returns:
        DataFrame: result


def _assign_udf_desc_extents(descs, start_extent):
    # type: (PyCdlib._UDFDescriptors, int) -> None

    current_extent = start_extent

    descs.pvd.set_extent_location(current_extent)
    current_extent += 1

    descs.impl_use.set_extent_location(current_extent)
    current_extent += 1

    descs.partition.set_extent_location(current_extent)
    current_extent += 1

    descs.logical_volume.set_extent_location(current_extent)
    current_extent += 1

    descs.unallocated_space.set_extent_location(current_extent)
    current_extent += 1

    descs.terminator.set_extent_location(current_extent)
    current_extent += 1

An internal function to assign a consecutive sequence of extents for the
    given set of UDF Descriptors, starting at the given extent.

    Parameters:
    descs - The PyCdlib._UDFDescriptors object to assign extents for.
    start_extent - The starting extent to assign from.

Returns:
    Nothing.


def remove_send_message(self, connection):

        if connection in self._send_message:
            del self._send_message[connection]
            LOGGER.debug("Removed send_message function "
                         "for connection %s", connection)
        else:
            LOGGER.warning("Attempted to remove send_message "
                           "function for connection %s, but no "
                           "send_message function was registered",
                           connection)

Removes a send_message function previously registered
    with the Dispatcher.

Args:
        connection (str): A locally unique identifier provided
            by the receiver of messages.


def find_replace(obj, find, replace):

    try:
        if isinstance(obj, dict):
            return {find_replace(key,find,replace): find_replace(value,find,replace) for key, value in obj.items()}
        elif isinstance(obj, list):
            return [find_replace(element,find,replace) for element in obj]
        elif obj == find:
            return unicode_convert(replace)
        else:
            try:
                return unicode_convert(find_replace_string(obj, find, replace))
                #obj = unicode_convert(json.loads(obj))
                #return find_replace(obj,find,replace)
            except:
                return unicode_convert(obj)
    except:
        line, filename, synerror = trace()
        raise ArcRestHelperError({
                    "function": "find_replace",
                    "line": line,
                    "filename":  filename,
                    "synerror": synerror,
                                    }
                                    )
    finally:
        pass

Searches an object and performs a find and replace.

Args:
        obj (object): The object to iterate and find/replace.
        find (str): The string to search for.
        replace (str): The string to replace with.

Returns:
        object: The object with replaced strings.


def downsampled_mesh(self, step):

        from lace.mesh import Mesh

        if self.f is not None:
            raise ValueError(
                'Function `downsampled_mesh` does not support faces.')

        low = Mesh()
        if self.v is not None:
            low.v = self.v[::step]
        if self.vc is not None:
            low.vc = self.vc[::step]
        return low

Returns a downsampled copy of this mesh.

Args:
        step: the step size for the sampling

Returns:
        a new, downsampled Mesh object.

Raises:
        ValueError if this Mesh has faces.


def find_elements_by_name(self, name, update=False) -> Elements:

        return self.find_elements(by=By.NAME, value=name, update=update)

Finds multiple elements by name.

Args:
        name: The name of the elements to be found.
        update: If the interface has changed, this option should be True.

Returns:
        A list with elements if any was found. An empty list if not.

Raises:
        NoSuchElementException - If the element wasn't found.

    Usage:
        elements = driver.find_elements_by_name('foo')


def operate(self, left, right, operation):

        operation = {
            '+': operator.add,
            '-': operator.sub,
            '*': operator.mul,
            '/': operator.truediv
        }.get(operation)
        return operation(left, right)

Do operation on colors

Args:
        left (str): left side
        right (str): right side
        operation (str): Operation

Returns:
        str


def __init__(self, shape, num_actions, probabilities=None, scope='categorical', summary_labels=()):

        self.num_actions = num_actions

        action_size = util.prod(shape) * self.num_actions
        if probabilities is None:
            logits = 0.0
        else:
            logits = [log(prob) for _ in range(util.prod(shape)) for prob in probabilities]
        self.logits = Linear(size=action_size, bias=logits, scope='logits', summary_labels=summary_labels)

        super(Categorical, self).__init__(shape=shape, scope=scope, summary_labels=summary_labels)

Categorical distribution.

Args:
        shape: Action shape.
        num_actions: Number of discrete action alternatives.
        probabilities: Optional distribution bias.


def locked_put(self, credentials):

        self._create_file_if_needed()
        _helpers.validate_file(self._filename)
        f = open(self._filename, 'w')
        f.write(credentials.to_json())
        f.close()

Write Credentials to file.

Args:
        credentials: Credentials, the credentials to store.

Raises:
        IOError if the file is a symbolic link.


def __init__(self, df, grouping_column_names):

        self.df = df
        self.grouping_columns = []
        self.grouping_column_types = []

        if isinstance(grouping_column_names, str):
            grouping_column_names = [grouping_column_names]
        for column_name in grouping_column_names:
            column = df[column_name]
            if isinstance(column, LazyOpResult):
                self.grouping_column_types.append(column.weld_type)
                self.grouping_columns.append(column.expr)
            elif isinstance(column, np.ndarray):
                column_type = numpyImpl.numpy_to_weld_type_mapping[
                    str(column.dtype)]
                self.grouping_column_types.append(column_type)
                self.grouping_columns.append(column)

        self.grouping_column_names = grouping_column_names
        self.column_names = []
        for x in df._get_column_names():
            if x not in self.grouping_column_names:
                self.column_names.append(x)

        self.columns = []
        self.column_types = []
        for column_name in self.column_names:
            column = df[column_name]
            column_type = None
            if isinstance(column, LazyOpResult):
                column_type = column.weld_type
                column = column.expr
            elif isinstance(column, np.ndarray):
                column_type = numpyImpl.numpy_to_weld_type_mapping[
                    str(column.dtype)]

            self.columns.append(column)
            self.column_types.append(column_type)

Summary

Args:
        df (TYPE): Description
        grouping_column_name (TYPE): Description


def __init__(self, data):

        self._coord = data['NODE_COORD_SECTION']
        self._nodes = {i: Node(i, data['DEMAND'][i]) for i in data['MATRIX']}
        self._matrix = {}
        self._depot = None
        self._branch_kind = data['BRANCH_KIND']
        self._branch_type = data['BRANCH_TYPE']
        self._v_level = data['V_LEVEL']
        self._is_aggregated = data['IS_AGGREGATED']

        for i in data['MATRIX']:

            x = self._nodes[i]
            self._matrix[x] = {}

            if i == data['DEPOT']:
                self._depot = x # x, not i!!

            for j in data['MATRIX']:
                y = self._nodes[j]

                self._matrix[x][y] = data['MATRIX'][i][j]

        if self._depot is None:
            raise Exception('Depot not found')

Class constructor

    Initialize all nodes, edges and depot

    Parameters:
        data: TSPLIB parsed data


def angle(self, deg=False):

        if self.dtype.str[1] != 'c':
            warnings.warn('angle() is intended for complex-valued timeseries',
                          RuntimeWarning, 1)
        return Timeseries(np.angle(self, deg=deg), self.tspan, self.labels)

Return the angle of the complex argument.

Args:
        deg (bool, optional):
        Return angle in degrees if True, radians if False (default).

Returns:
        angle (Timeseries):
        The counterclockwise angle from the positive real axis on
        the complex plane, with dtype as numpy.float64.


def add_showcases(self, showcases, showcases_to_check=None):
        # type: (List[Union[hdx.data.showcase.Showcase,Dict,str]], List[hdx.data.showcase.Showcase]) -> bool

        if showcases_to_check is None:
            showcases_to_check = self.get_showcases()
        allshowcasesadded = True
        for showcase in showcases:
            if not self.add_showcase(showcase, showcases_to_check=showcases_to_check):
                allshowcasesadded = False
        return allshowcasesadded

Add dataset to multiple showcases

Args:
        showcases (List[Union[Showcase,Dict,str]]): A list of either showcase ids or showcase metadata from Showcase objects or dictionaries
        showcases_to_check (List[Showcase]): list of showcases against which to check existence of showcase. Defaults to showcases containing dataset.

Returns:
        bool: True if all showcases added or False if any already present


def playlist(self, playlist_id, *, include_songs=False):

		playlist_info = next(
			(
				playlist
				for playlist in self.playlists(include_songs=include_songs)
				if playlist['id'] == playlist_id
			),
			None
		)

		return playlist_info

Get information about a playlist.

    Parameters:
    playlist_id (str): A playlist ID.
    include_songs (bool, Optional): Include songs from
        the playlist in the returned dict.
        Default: ``False``

Returns:
    dict: Playlist information.


def add_deps(self, deps):

        if isinstance(deps, collections.Mapping):
            # Convert dictionary into list of dependencies.
            deps = [Dependency(node, exts) for node, exts in deps.items()]

        # We want a list
        if not isinstance(deps, (list, tuple)):
            deps = [deps]

        assert all(isinstance(d, Dependency) for d in deps)

        # Add the dependencies to the node
        self._deps.extend(deps)

        if self.is_work:
            # The task in the work should inherit the same dependency.
            for task in self:
                task.add_deps(deps)

        # If we have a FileNode as dependency, add self to its children
        # Node.get_parents will use this list if node.is_isfile.
        for dep in (d for d in deps if d.node.is_file):
            dep.node.add_filechild(self)

Add a list of dependencies to the :class:`Node`.

Args:
        deps: List of :class:`Dependency` objects specifying the dependencies of the node.
            or dictionary mapping nodes to file extensions e.g. {task: "DEN"}


def __setDeviceMode(self, mode):

        print 'call __setDeviceMode'

        try:
            cmd = WPANCTL_CMD + 'setprop Thread:DeviceMode %d' % mode
            return self.__sendCommand(cmd)[0] != 'Fail'
        except Exception, e:
            ModuleHelper.WriteIntoDebugLogger('setDeviceMode() Error: ' + str(e))

set thread device mode:

Args:
        mode: thread device mode. 15=rsdn, 13=rsn, 4=s
        r: rx-on-when-idle
        s: secure IEEE 802.15.4 data request
        d: full thread device
        n: full network data

Returns:
        True: successful to set the device mode
        False: fail to set the device mode


def get_developer_package(path, format=None):

    from rez.developer_package import DeveloperPackage
    return DeveloperPackage.from_path(path, format=format)

Create a developer package.

Args:
        path (str): Path to dir containing package definition file.
        format (str): Package definition file format, detected if None.

Returns:
        `DeveloperPackage`.


def grid_destroy_from_ids(oargrid_jobids):

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

Destroy all the jobs with corresponding ids

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


def __init__(self, app=None, env=None, region=None, prop_path=None):

        self.app_name = app
        self.env = env
        self.region = region
        self.prop_path = prop_path
        self.properties = get_properties(properties_file=prop_path, env=env, region=region)

Lambda event object.

Args:
        app (str): Application name
        env (str): Environment/Account
        region (str): AWS Region
        prop_path (str): Path of environment property file


def __init__(self, client, user_list, conversation, events=[],
                 event_cont_token=None):
        # pylint: disable=dangerous-default-value
        self._client = client  # Client
        self._user_list = user_list  # UserList
        self._conversation = conversation  # hangouts_pb2.Conversation
        self._events = []  # [hangouts_pb2.Event]
        self._events_dict = {}  # {event_id: ConversationEvent}
        self._send_message_lock = asyncio.Lock()
        self._watermarks = {}  # {UserID: datetime.datetime}
        self._event_cont_token = event_cont_token
        for event_ in events:
            # Workaround to ignore observed events returned from
            # syncrecentconversations.
            if event_.event_type != hangouts_pb2.EVENT_TYPE_OBSERVED_EVENT:
                self.add_event(event_)

        self.on_event = event.Event('Conversation.on_event')

        self.on_typing = event.Event('Conversation.on_typing')

        self.on_watermark_notification = event.Event(
            'Conversation.on_watermark_notification'
        )

        self.on_watermark_notification.add_observer(
            self._on_watermark_notification
        )

:class:`.Event` fired when an event occurs in this conversation.

Args:
        conv_event: :class:`.ConversationEvent` that occurred.


def get_cmd_handler(self, cmd):

        cmd = cmd.replace('-', '_')
        handler = getattr(self, cmd, None)
        if not handler:
            raise BuildException(
                'Command {} is not supported as a '
                'build command'.format(cmd)
            )
        return handler

Return an handler for cmd.
    The handler and the command should have the same name.
    See class description for more info about handlers.

Args:
        cmd (str): The name of the command

Returns:
        callable: which handles cmd

Raises:
        lago.build.BuildException: If an handler for cmd doesn't exist


def add_status_parser(subparsers, parent_parser):

    parser = subparsers.add_parser(
        'status',
        help='Displays information about validator status',
        description="Provides a subcommand to show a validator\'s status")

    grand_parsers = parser.add_subparsers(title='subcommands',
                                          dest='subcommand')
    grand_parsers.required = True
    add_status_show_parser(grand_parsers, parent_parser)

Adds argument parser for the status command

Args:
        subparsers: Add parsers to this subparser object
        parent_parser: The parent argparse.ArgumentParser object


def mset(self, values):

        for key, value in values.items():
            self.set(key, value)

Set the value of several keys at once.

Args:
        values (dict): maps a key to its value.


def _read_from_hdx(self, object_type, value, fieldname='id',
                       action=None, **kwargs):
        # type: (str, str, str, Optional[str], Any) -> Tuple[bool, Union[Dict, str]]

        if not fieldname:
            raise HDXError('Empty %s field name!' % object_type)
        if action is None:
            action = self.actions()['show']
        data = {fieldname: value}
        data.update(kwargs)
        try:
            result = self.configuration.call_remoteckan(action, data)
            return True, result
        except NotFound:
            return False, '%s=%s: not found!' % (fieldname, value)
        except Exception as e:
            raisefrom(HDXError, 'Failed when trying to read: %s=%s! (POST)' % (fieldname, value), e)

Makes a read call to HDX passing in given parameter.

Args:
        object_type (str): Description of HDX object type (for messages)
        value (str): Value of HDX field
        fieldname (str): HDX field name. Defaults to id.
        action (Optional[str]): Replacement CKAN action url to use. Defaults to None.
        **kwargs: Other fields to pass to CKAN.

Returns:
        Tuple[bool, Union[Dict, str]]: (True/False, HDX object metadata/Error)


def _get_subset_matches(self, query):

        for field_name, db_index in self._get_db_fields(query):
            attr = getattr(query, field_name)

            if attr is None:  # don't use unset attributes
                continue

            results = db_index.get(attr, OOTreeSet())

            if results:
                yield results

Yield publications, at indexes defined by `query` property values.

Args:
        query (obj): Object implementing proper interface.

Yields:
        list: List of matching publications.


def check_index(self, key, *, index):

        self.append({
            "Verb": "check-index",
            "Key": key,
            "Index": extract_attr(index, keys=["ModifyIndex", "Index"])
        })
        return self

Fails the transaction if Key does not have a modify index equal to
    Index

    Parameters:
        key (str): Key to check
        index (ObjectIndex): Index ID


def _rapply(input_layer, operation, *op_args, **op_kwargs):

  op_args = list(op_args)
  op_args.append(input_layer.tensor)
  return input_layer.with_tensor(operation(*op_args, **op_kwargs))

Applies the given operation to this after expanding op_args.

Args:
        input_layer: The input layer for this op.
        operation: An operation that takes a tensor and the supplied args.
        *op_args: Extra arguments for operation.
        **op_kwargs: Keyword arguments for the operation.

Returns:
        A new layer with operation applied.


def __init__(self, **kwds):

        self.code_objs = dict()
        self._codes = []
        self._functions = []
        self._executables = []
        self.dry_run = None
        self.encoding = 'utf-8'
        self.newline = None
        if 'module' in kwds:
            self.import_module(kwds['module'])
        if 'code' in kwds:
            self.append_code_expr(kwds['code'])
        if 'function' in kwds:
            self.append_function(kwds['function'])
        if 'executable' in kwds:
            self.append_executable(kwds['executable'])
        if 'dry_run' in kwds:
            self.dry_run = kwds['dry_run']
        if 'encoding' in kwds:
            self.encoding = kwds['encoding']
        if 'newline' in kwds:
            self.newline = kwds['newline']

Initialize MassEdit object.

Args:
        - code (byte code object): code to execute on input file.
        - function (str or callable): function to call on input file.
        - module (str): module name where to find the function.
        - executable (str): executable file name to execute on input file.
        - dry_run (bool): skip actual modification of input file if True.


def i4_sobol_generate_std_normal(dim_num, n, skip=1):

    sobols = i4_sobol_generate(dim_num, n, skip)

    normals = norm.ppf(sobols)

    return normals

Generates multivariate standard normal quasi-random variables.

    Parameters:
        Input, integer dim_num, the spatial dimension.
        Input, integer n, the number of points to generate.
        Input, integer SKIP, the number of initial points to skip.

        Output, real np array of shape (n, dim_num).


def min_max_normalize(img):

    min_img = img.min()
    max_img = img.max()

    return (img - min_img) / (max_img - min_img)

Centre and normalize a given array.

    Parameters:
    ----------
    img: np.ndarray


def files_info(self, *, id: str, **kwargs) -> SlackResponse:

        kwargs.update({"id": id})
        return self.api_call("files.info", http_verb="GET", params=kwargs)

Gets information about a team file.

Args:
        id (str): The file id. e.g. 'F1234467890'


def empty(cls, labels=None):

        warnings.warn("Table.empty(labels) is deprecated. Use Table(labels)", FutureWarning)
        if labels is None:
            return cls()
        values = [[] for label in labels]
        return cls(values, labels)

Creates an empty table. Column labels are optional. [Deprecated]

Args:
        ``labels`` (None or list): If ``None``, a table with 0
            columns is created.
            If a list, each element is a column label in a table with
            0 rows.

Returns:
        A new instance of ``Table``.


def __init__(self, xid=None, body_type=None, flags=0, body=b''):

        super().__init__(xid)
        self.body_type = body_type
        self.flags = flags
        self.body = body

Create a StatsRequest with the optional parameters below.

Args:
        xid (int): xid to be used on the message header.
        body_type (StatsType): One of the OFPST_* constants.
        flags (int): OFPSF_REQ_* flags (none yet defined).
        body (BinaryData): Body of the request.


def __init__(
      self, resolver_context, file_system, path_spec, file_entry_type=None,
      is_root=False):

    super(FakeFileEntry, self).__init__(
        resolver_context, file_system, path_spec, is_root=is_root,
        is_virtual=True)
    self._date_time = dfdatetime_fake_time.FakeTime()
    self._name = None
    self.entry_type = file_entry_type

Initializes a file entry.

Args:
        resolver_context (Context): resolver context.
        file_system (FileSystem): file system.
        path_spec (PathSpec): path specification.
        file_entry_type (Optional[str]): file entry type.
        is_root (Optional[bool]): True if the file entry is the root file entry
        of the corresponding file system.


def bin_hash160Bytes(bts):

    intermed = hashlib.sha256(bts).digest()
    return hashlib.new('ripemd160', intermed).digest()

Get a hash of the provided message using the ripemd160 algorithm.

Args:
        bts (str): message to hash.

Returns:
        bytes: hash.


def add_url_rule(self, route, endpoint, handler):

        self.app.add_url_rule(route, endpoint, handler)

Add a new url route.

Args:
        See flask.Flask.add_url_route().


def chip_as_adjacency_list(device: 'cirq.google.XmonDevice',
                           ) -> Dict[GridQubit, List[GridQubit]]:

    c_set = set(device.qubits)
    c_adj = {} # type: Dict[GridQubit, List[GridQubit]]
    for n in device.qubits:
        c_adj[n] = []
        for m in [above(n), left_of(n), below(n), right_of(n)]:
            if m in c_set:
                c_adj[n].append(m)
    return c_adj

Gives adjacency list representation of a chip.

    The adjacency list is constructed in order of above, left_of, below and
    right_of consecutively.

Args:
        device: Chip to be converted.

Returns:
        Map from nodes to list of qubits which represent all the neighbours of
        given qubit.


def send_batches(self, batch_list):

        if isinstance(batch_list, BaseMessage):
            batch_list = batch_list.SerializeToString()

        return self._post('/batches', batch_list)

Sends a list of batches to the validator.

Args:
        batch_list (:obj:`BatchList`): the list of batches

Returns:
        dict: the json result data, as a dict


def get_pending_users_queryset(self, search_keyword, customer_uuid):

        queryset = PendingEnterpriseCustomerUser.objects.filter(
            enterprise_customer__uuid=customer_uuid
        )

        if search_keyword is not None:
            queryset = queryset.filter(user_email__icontains=search_keyword)

        return queryset

Get the list of PendingEnterpriseCustomerUsers we want to render.

Args:
        search_keyword (str): The keyword to search for in pending users' email addresses.
        customer_uuid (str): A unique identifier to filter down to only pending users
        linked to a particular EnterpriseCustomer.


def set_aws_clients(self, clients):

    if type(clients) is not dict:
      raise TypeError("clients must be a dict")
    self._aws_clients = clients

Stash a dictionary of AWS clients in the context object

Args:
        clients: dictionary of clients


def convert(isbn, code='978'):

    isbn = _isbn_cleanse(isbn)
    if len(isbn) == 10:
        isbn = code + isbn[:-1]
        return isbn + calculate_checksum(isbn)
    else:
        if isbn.startswith('978'):
            return isbn[3:-1] + calculate_checksum(isbn[3:-1])
        else:
            raise IsbnError('Only ISBN-13s with 978 Bookland code can be '
                            'converted to ISBN-10.')

Convert ISBNs between ISBN-10 and ISBN-13.

Note:
        No attempt to hyphenate converted ISBNs is made, because the
        specification requires that *any* hyphenation must be correct but
        allows ISBNs without hyphenation.

Args:
        isbn (str): SBN, ISBN-10 or ISBN-13
        code (str): EAN Bookland code

Returns:
        ``str``: Converted ISBN-10 or ISBN-13

Raises:
        IsbnError: When ISBN-13 isn't convertible to an ISBN-10


def mtr_tr_dense(sz):

  n = 2 ** sz
  hparams = mtf_bitransformer_base()
  hparams.d_model = 1024
  hparams.max_length = 256
  hparams.batch_size = 128
  hparams.d_ff = int(4096 * n)
  hparams.d_kv = 128
  hparams.encoder_num_heads = int(8 * n)
  hparams.decoder_num_heads = int(8 * n)
  # one epoch for translate_enfr_wmt32k_packed = 51400 steps
  hparams.learning_rate_decay_steps = 51400
  hparams.layout = "batch:batch;vocab:model;d_ff:model;heads:model"
  hparams.mesh_shape = "batch:32"
  hparams.label_smoothing = 0.1
  hparams.layer_prepostprocess_dropout = 0.1
  hparams.attention_dropout = 0.1
  hparams.relu_dropout = 0.1
  return hparams

Series of machine translation models.

    All models are trained on sequences of 256 tokens.

    You can use the dataset translate_enfr_wmt32k_packed.
    154000 steps = 3 epochs.

Args:
        sz: an integer

Returns:
        a hparams


def wwpn_free_if_allocated(self, wwpn):

        wwpn_int = int(wwpn[-4:], 16)
        self._wwpn_pool.free_if_allocated(wwpn_int)

Free a WWPN allocated with :meth:`wwpn_alloc`.

    If the WWPN is not currently allocated or not in the pool
    range, nothing happens.

    Parameters:
        WWPN (string): The WWPN as 16 hexadecimal digits.


def ExpandPath(path, opts=None):

  precondition.AssertType(path, Text)

  for grouped_path in ExpandGroups(path):
    for globbed_path in ExpandGlobs(grouped_path, opts):
      yield globbed_path

Applies all expansion mechanisms to the given path.

Args:
        path: A path to expand.
        opts: A `PathOpts` object.

Yields:
        All paths possible to obtain from a given path by performing expansions.


def get_results(self, job_id):

        url = self._url('%s/results' % job_id)
        return self.client.get(url)

Get results of a job

Args:
        job_id (str): The ID of the job.

    See: https://auth0.com/docs/api/management/v2#!/Jobs/get_results


def expand_by_device(original_parallelism, device_parallelism, data):

  device_to_datum = {
      device_parallelism.devices[i]: data[i]
      for i in range(device_parallelism.n)}
  return [device_to_datum[d] for d in original_parallelism.devices]

Opposite of reduce_by_device().

Args:
        original_parallelism: a expert_utils.Parallelism object.
        device_parallelism: a expert_utils.Parallelism object.
        data: a list of tensors with length device_parallelism.n

Returns:
        a list of Tensors with length original_parallelism.n


def candidates(self, word):

        if self.known([word]):  # short-cut if word is correct already
            return {word}
        # get edit distance 1...
        res = [x for x in self.edit_distance_1(word)]
        tmp = self.known(res)
        if tmp:
            return tmp
        # if still not found, use the edit distance 1 to calc edit distance 2
        if self._distance == 2:
            tmp = self.known([x for x in self.__edit_distance_alt(res)])
            if tmp:
                return tmp
        return {word}

Generate possible spelling corrections for the provided word up to
    an edit distance of two, if and only when needed

Args:
        word (str): The word for which to calculate candidate spellings

Returns:
        set: The set of words that are possible candidates


def onepara(R):

    import numpy as np
    import warnings

    d = R.shape[0]

    if d < 2:
        raise Exception((
            "More than one variable is required."
            "Supply at least a 2x2 matrix."))

    # the explicit solution
    x = (np.sum(R) + np.trace(R)) / (d**2 - d)

    if x < (-1. / (d - 1)) or x > 1:
        warnings.warn("No analytic solution found x={:.8f}".format(x))
        return None
    else:
        C = np.eye(d)
        C[np.logical_not(C)] = x
        return C

Converts an ill-conditioned correlation matrix
    into well-conditioned matrix with one common
    correlation coefficient

    Parameters:
    -----------
    R : ndarray
    an illconditioned correlation matrix,
    e.g. oxyba.illcond_corrmat

Returns:
    -------
    cmat : ndarray
    DxD matrix with +1 as diagonal elements
    and 1 common coefficient for all other
    relations.


def set_energy(self, spins, target_energy):

        spin_energy = self.energy(spins)
        self.assertions.add(Equals(spin_energy, limitReal(target_energy)))

Set the energy of Theta with spins fixed to target_energy.

Args:
        spins (dict): Spin values for a subset of the variables in Theta.
        target_energy (float): The desired energy for Theta with spins fixed.

Note:
        Add equality constraint to assertions.


def populate(self, filename):

        if os.path.isfile(filename):
            fid_st = os.stat(filename)
            self.name = os.path.abspath(filename)
            self.full_name = filename
            self.size = fid_st.st_size
            self.last_modified = fid_st.st_mtime
            self.last_accessed = fid_st.st_atime
            self.last_info_changed = fid_st.st_ctime
            self.location = os.path.dirname(filename)

Finds the file-stats and populates the class with stat values.

Args:
        filename (str): name of the file.


def list_load_balancers(access_token, subscription_id):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/providers/Microsoft.Network/',
                        '/loadBalancers?api-version=', NETWORK_API])
    return do_get(endpoint, access_token)

List the load balancers in a subscription.

Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.

Returns:
        HTTP response. JSON body of load balancer list with properties.


def parse_document(text, options=0):

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

Parse a document and return the root node.

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

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


def join(self, *data: Iterable[MaybeBytes]) -> bytes:

        return self.how.join([bytes(item) for item in chain(*data)])

Iterable join on a delimiter.

Args:
        data: Iterable of items to join.

Example:
        ::

            BytesFormat(b' ').join([b'one', b'two', b'three'])


def latest_malicious(self, ips):

        api_name = 'opendns-latest_malicious'
        fmt_url_path = u'ips/{0}/latest_domains'
        return self._multi_get(api_name, fmt_url_path, ips)

Get the a list of malicious domains related to input ips.

Args:
        ips: an enumerable of strings as ips

Returns:
        An enumerable of strings for the malicious domains


def set_xlim(self, xlims, dx, xscale, reverse=False):

        self._set_axis_limits('x', xlims, dx, xscale, reverse)
        return

Set x limits for plot.

    This will set the limits for the x axis
    for the specific plot.

Args:
        xlims (len-2 list of floats): The limits for the axis.
        dx (float): Amount to increment by between the limits.
        xscale (str): Scale of the axis. Either `log` or `lin`.
        reverse (bool, optional): If True, reverse the axis tick marks. Default is False.


def get_kwdefaults(func, parse_source=False):
    r
    #import utool as ut
    #with ut.embed_on_exception_context:
    argspec = inspect.getargspec(func)
    kwdefaults = {}
    if argspec.args is None or argspec.defaults is None:
        pass
    else:
        args = argspec.args
        defaults = argspec.defaults
        #kwdefaults = OrderedDict(zip(argspec.args[::-1], argspec.defaults[::-1]))
        kwpos = len(args) - len(defaults)
        kwdefaults = OrderedDict(zip(args[kwpos:], defaults))
    if parse_source and argspec.keywords:
        # TODO parse for kwargs.get/pop
        keyword_defaults = parse_func_kwarg_keys(func, with_vals=True)
        for key, val in keyword_defaults:
            assert key not in kwdefaults, 'parsing error'
            kwdefaults[key] = val
    return kwdefaults

r"""

Args:
        func (func):

Returns:
        dict:

    CommandLine:
        python -m utool.util_inspect get_kwdefaults

Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_inspect import *  # NOQA
        >>> import utool as ut
        >>> func = dummy_func
        >>> parse_source = True
        >>> kwdefaults = get_kwdefaults(func, parse_source)
        >>> print('kwdefaults = %s' % (ut.repr4(kwdefaults),))


def child_link_extent(self):
        # type: () -> int

        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized')

        if self.dr_entries.cl_record is not None:
            return self.dr_entries.cl_record.child_log_block_num
        if self.ce_entries.cl_record is not None:
            return self.ce_entries.cl_record.child_log_block_num

        raise pycdlibexception.PyCdlibInternalError('Asked for child extent for non-existent parent record')

Get the extent of the child of this entry if it has one.

    Parameters:
    None.

Returns:
    The logical block number of the child if it exists.


def prep_gate(self, circuit, qreg, op):

        if self.prep_fun is None:
            pass
        else:
            self.prep_fun(circuit, qreg, op)

Add state preparation gates to a circuit.

Args:
        circuit (QuantumCircuit): circuit to add a preparation to.
        qreg (tuple(QuantumRegister,int)): quantum register to apply
        preparation to.
        op (tuple(str, int)): the basis label and index for the
        preparation op.


def AnalyzeClient(self, client):

    # Start with a universal keyword, used to find all clients.
    #
    # TODO(user): Remove the universal keyword once we have a better way
    # to do this, i.e., once we have a storage library which can list all
    # clients directly.

    keywords = set(["."])

    def TryAppend(prefix, keyword):
      precondition.AssertType(prefix, Text)
      precondition.AssertType(keyword, Text)
      if keyword:
        keyword_string = self._NormalizeKeyword(keyword)
        keywords.add(keyword_string)
        if prefix:
          keywords.add(prefix + ":" + keyword_string)

    def TryAppendPrefixes(prefix, keyword, delimiter):
      TryAppend(prefix, keyword)
      segments = keyword.split(delimiter)
      for i in range(1, len(segments)):
        TryAppend(prefix, delimiter.join(segments[0:i]))
      return len(segments)

    def TryAppendIP(ip):
      TryAppend("ip", ip)
      # IP4v?
      if TryAppendPrefixes("ip", Text(ip), ".") == 4:
        return
      # IP6v?
      TryAppendPrefixes("ip", Text(ip), ":")

    def TryAppendMac(mac):
      TryAppend("mac", mac)
      if len(mac) == 12:
        # If looks like a mac address without ":" symbols, also add the keyword
        # with them.
        TryAppend("mac", ":".join([mac[i:i + 2] for i in range(0, 12, 2)]))

    TryAppend("host", client.knowledge_base.fqdn)
    host = client.knowledge_base.fqdn.split(".", 1)[0]
    TryAppendPrefixes("host", host, "-")
    TryAppendPrefixes("host", client.knowledge_base.fqdn, ".")
    TryAppend("", client.knowledge_base.os)
    TryAppend("", client.Uname())
    TryAppend("", client.os_release)
    TryAppend("", client.os_version)
    TryAppend("", client.kernel)
    TryAppend("", client.arch)

    kb = client.knowledge_base
    if kb:
      for user in kb.users:
        TryAppend("user", user.username)
        TryAppend("", user.full_name)
        if user.full_name:
          for name in user.full_name.split():
            # full_name often includes nicknames and similar, wrapped in
            # punctuation, e.g. "Thomas 'TJ' Jones". We remove the most common
            # wrapping characters.
            TryAppend("", name.strip("\"'()"))

    for ip in client.GetIPAddresses():
      TryAppendIP(ip)
    for mac in client.GetMacAddresses():
      TryAppendMac(mac)

    client_info = client.startup_info.client_info
    if client_info:
      TryAppend("client", client_info.client_name)
      TryAppend("client", Text(client_info.client_version))
      if client_info.labels:
        for label in client_info.labels:
          TryAppend("label", label)

    return keywords

Finds the client_id and keywords for a client.

Args:
        client: A Client object record to find keywords for.

Returns:
        A list of keywords related to client.


def obtain(self, dest):
        # type: (str) -> None

        url, rev_options = self.get_url_rev_options(self.url)

        if not os.path.exists(dest):
            self.fetch_new(dest, url, rev_options)
            return

        rev_display = rev_options.to_display()
        if self.is_repository_directory(dest):
            existing_url = self.get_remote_url(dest)
            if self.compare_urls(existing_url, url):
                logger.debug(
                    '%s in %s exists, and has correct URL (%s)',
                    self.repo_name.title(),
                    display_path(dest),
                    url,
                )
                if not self.is_commit_id_equal(dest, rev_options.rev):
                    logger.info(
                        'Updating %s %s%s',
                        display_path(dest),
                        self.repo_name,
                        rev_display,
                    )
                    self.update(dest, url, rev_options)
                else:
                    logger.info('Skipping because already up-to-date.')
                return

            logger.warning(
                '%s %s in %s exists with URL %s',
                self.name,
                self.repo_name,
                display_path(dest),
                existing_url,
            )
            prompt = ('(s)witch, (i)gnore, (w)ipe, (b)ackup ',
                      ('s', 'i', 'w', 'b'))
        else:
            logger.warning(
                'Directory %s already exists, and is not a %s %s.',
                dest,
                self.name,
                self.repo_name,
            )
            # https://github.com/python/mypy/issues/1174
            prompt = ('(i)gnore, (w)ipe, (b)ackup ',  # type: ignore
                      ('i', 'w', 'b'))

        logger.warning(
            'The plan is to install the %s repository %s',
            self.name,
            url,
        )
        response = ask_path_exists('What to do?  %s' % prompt[0], prompt[1])

        if response == 'a':
            sys.exit(-1)

        if response == 'w':
            logger.warning('Deleting %s', display_path(dest))
            rmtree(dest)
            self.fetch_new(dest, url, rev_options)
            return

        if response == 'b':
            dest_dir = backup_dir(dest)
            logger.warning(
                'Backing up %s to %s', display_path(dest), dest_dir,
            )
            shutil.move(dest, dest_dir)
            self.fetch_new(dest, url, rev_options)
            return

        # Do nothing if the response is "i".
        if response == 's':
            logger.info(
                'Switching %s %s to %s%s',
                self.repo_name,
                display_path(dest),
                url,
                rev_display,
            )
            self.switch(dest, url, rev_options)

Install or update in editable mode the package represented by this
    VersionControl object.

Args:
        dest: the repository directory in which to install or update.


def remove_flow_controller(cls, name):

        if name not in cls.registered_controllers:
            raise KeyError("Flow controller not found: %s" % name)
        del cls.registered_controllers[name]

Removes a flow controller.

Args:
        name (string): Name of the controller to remove.

Raises:
        KeyError: If the controller to remove was not registered.


def _ReadRecordSchemaIndexes(self, tables, file_object, record_offset):

    _ = self._ReadRecordHeader(file_object, record_offset)

    attribute_value_offsets = self._ReadRecordAttributeValueOffset(
        file_object, record_offset + 24, 5)

    if attribute_value_offsets != (0x2d, 0x31, 0x35, 0x39, 0x3d):
      raise errors.ParseError('Unsupported record attribute value offsets')

    file_offset = file_object.tell()
    data_type_map = self._GetDataTypeMap('keychain_record_schema_indexes')

    record_values, _ = self._ReadStructureFromFileObject(
        file_object, file_offset, data_type_map)

    if record_values.relation_identifier not in tables:
      raise errors.ParseError(
          'CSSM_DL_DB_SCHEMA_INDEXES defines relation identifier not defined '
          'in CSSM_DL_DB_SCHEMA_INFO.')

    table = tables.get(self._RECORD_TYPE_CSSM_DL_DB_SCHEMA_INDEXES, None)
    if not table:
      raise errors.ParseError('Missing CSSM_DL_DB_SCHEMA_INDEXES table.')

    record = collections.OrderedDict({
        'RelationID': record_values.relation_identifier,
        'IndexID': record_values.index_identifier,
        'AttributeID': record_values.attribute_identifier,
        'IndexType': record_values.index_type,
        'IndexedDataLocation': record_values.index_data_location})

    table.records.append(record)

Reads a schema indexes (CSSM_DL_DB_SCHEMA_INDEXES) record.

Args:
        tables (dict[int, KeychainDatabaseTable]): tables per identifier.
        file_object (file): file-like object.
        record_offset (int): offset of the record relative to the start of
        the file.

Raises:
        ParseError: if the record cannot be read.


def script_dir_plus_file(filename, pyobject, follow_symlinks=True):

    return join(script_dir(pyobject, follow_symlinks), filename)

Get current script's directory and then append a filename

Args:
        filename (str): Filename to append to directory path
        pyobject (Any): Any Python object in the script
        follow_symlinks (Optional[bool]): Follow symlinks or not. Defaults to True.

Returns:
        str: Current script's directory and with filename appended


def raster_statistics(raster_file):

        ds = gdal_Open(raster_file)
        band = ds.GetRasterBand(1)
        minv, maxv, meanv, std = band.ComputeStatistics(False)
        return minv, maxv, meanv, std

Get basic statistics of raster data.

Args:
        raster_file: raster file path.

Returns:
        min, max, mean, std.


def __init__(self, data=None, **kwargs):

    if data not in _DATA_OPTIONS:
      raise ValueError("data must be one of %s" % _DATA_OPTIONS)

    super(CycleGANConfig, self).__init__(**kwargs)
    self.data = data

Constructs a CycleGANConfig.

Args:
        data: `str`, one of `_DATA_OPTIONS`.
        **kwargs: keyword arguments forwarded to super.


def check_schema_transforms_match(schema, inverted_features):

  num_target_transforms = 0

  for col_schema in schema:
    col_name = col_schema['name']
    col_type = col_schema['type'].lower()

    # Check each transform and schema are compatible
    if col_name in inverted_features:
      for transform in inverted_features[col_name]:
        transform_name = transform['transform']
        if transform_name == constant.TARGET_TRANSFORM:
          num_target_transforms += 1
          continue

        elif col_type in constant.NUMERIC_SCHEMA:
          if transform_name not in constant.NUMERIC_TRANSFORMS:
            raise ValueError(
                'Transform %s not supported by schema %s' % (transform_name, col_type))
        elif col_type == constant.STRING_SCHEMA:
          if (transform_name not in constant.CATEGORICAL_TRANSFORMS + constant.TEXT_TRANSFORMS and
             transform_name != constant.IMAGE_TRANSFORM):
            raise ValueError(
                'Transform %s not supported by schema %s' % (transform_name, col_type))
        else:
          raise ValueError('Unsupported schema type %s' % col_type)

    # Check each transform is compatible for the same source column.
    # inverted_features[col_name] should belong to exactly 1 of the 5 groups.
    if col_name in inverted_features:
      transform_set = {x['transform'] for x in inverted_features[col_name]}
      if 1 != sum([transform_set.issubset(set(constant.NUMERIC_TRANSFORMS)),
                   transform_set.issubset(set(constant.CATEGORICAL_TRANSFORMS)),
                   transform_set.issubset(set(constant.TEXT_TRANSFORMS)),
                   transform_set.issubset(set([constant.IMAGE_TRANSFORM])),
                   transform_set.issubset(set([constant.TARGET_TRANSFORM]))]):
        message =  % (str(constant.TEXT_TRANSFORMS),
                 str(constant.CATEGORICAL_TRANSFORMS),
                 str(constant.NUMERIC_TRANSFORMS),
                 constant.IMAGE_TRANSFORM,
                 constant.TARGET_TRANSFORM,
                 col_name,
                 str(transform_set))
        raise ValueError(message)

  if num_target_transforms != 1:
    raise ValueError('Must have exactly one target transform')

Checks that the transform and schema do not conflict.

Args:
        schema: schema list
        inverted_features: inverted_features dict

Raises:
        ValueError if transform cannot be applied given schema type.


def __mod__(self, other: Union[_FormatArg, Iterable[_FormatArg]]) -> bytes:

        if isinstance(other, bytes):
            return self.format([other])
        elif hasattr(other, '__bytes__'):
            supports_bytes = cast(SupportsBytes, other)
            return self.format([bytes(supports_bytes)])
        elif hasattr(other, '__iter__'):
            items = cast(Iterable[_FormatArg], other)
            return self.format(items)
        return NotImplemented

String interpolation, shortcut for :meth:`.format`.

Args:
        other: The data interpolated into the format string.


def DNN(input_shape,
           dense_layers,
           output_layer=[1, 'sigmoid'],
           optimizer='adam',
           loss='binary_crossentropy'):

    inputs = Input(shape=input_shape)

    dense = inputs

    for i, d in enumerate(dense_layers):
        dense = Dense(d, activation='relu')(dense)
        dense = BatchNormalization()(dense)
        dense = Dropout(0.3)(dense)

    output = Dense(output_layer[0], activation=output_layer[1])(dense)

    model = Model(inputs=inputs, outputs=output)
    model.compile(loss=loss, optimizer=optimizer, metrics=['accuracy'])

    return model

Summary

Args:
        input_shape (list): The shape of the input layer
        targets (int): Number of targets
        dense_layers (list): Dense layer descriptor [fully_connected]
        optimizer (str or object optional): Keras optimizer as string or keras optimizer

Returns:
        TYPE: model, build_arguments


def TerminateAFF4Flow(cls, flow_id, reason=None, status=None, token=None):

    flow_obj = aff4.FACTORY.Open(
        flow_id, aff4_type=GRRFlow, mode="rw", token=token)

    if not flow_obj:
      raise FlowError("Could not terminate flow %s" % flow_id)

    with flow_obj:
      runner = flow_obj.GetRunner()
      if not runner.IsRunning():
        return

      if token is None:
        token = access_control.ACLToken()

      if reason is None:
        reason = "Manual termination by console."

      # This calls runner.Terminate to kill the flow
      runner.Error(reason, status_code=status)

      flow_obj.Log("Terminated by user {0}. Reason: {1}".format(
          token.username, reason))

      # From now on we run with supervisor access
      super_token = token.SetUID()

      # Also terminate its children
      children_to_kill = aff4.FACTORY.MultiOpen(
          flow_obj.ListChildren(), token=super_token, aff4_type=GRRFlow)

      for child_obj in children_to_kill:
        cls.TerminateAFF4Flow(
            child_obj.urn, reason="Parent flow terminated.", token=super_token)

Terminate a flow.

Args:
        flow_id: The flow session_id to terminate.
        reason: A reason to log.
        status: Status code used in the generated status message.
        token: The access token to be used for this request.

Raises:
        FlowError: If the flow can not be found.


def call_rpc(self, rpc_id, payload=bytes()):

        # If we define the RPC locally, call that one.  We use this for reporting
        # our status
        if super(ServiceDelegateTile, self).has_rpc(rpc_id):
            return super(ServiceDelegateTile, self).call_rpc(rpc_id, payload)

        async def _awaitable_wrapper():

            # FIXME: We set the timeout here to a very large number since we don't
            # know what an appropriate timeout is and don't want to restrict the
            # run time of RPCs that could be long running.  The caller of the RPC
            # through the tile will know what an appropriate timeout is for the
            # RPC that they are trying to call.
            resp = await self._client.send_rpc(self._service, rpc_id, payload, timeout=120.0)
            result = resp['result']

            if result == 'success':
                return resp['response']
            elif result == 'service_not_found':
                raise TileNotFoundError("Could not find service by name", name=self._service)
            elif result == 'rpc_not_found':
                raise RPCNotFoundError("Could not find RPC on service", name=self._service, rpc_id=rpc_id)
            elif result == 'invalid_arguments':
                raise RPCInvalidArgumentsError("Invalid arguments to RPC", name=self._service, rpc_id=rpc_id)
            elif result == 'invalid_response':
                raise RPCInvalidReturnValueError("Invalid response from RPC", name=self._service, rpc_id=rpc_id)
            elif result == 'execution_exception':
                raise InternalError("Exception raised during processing RPC", name=self._service, rpc_id=rpc_id)
            else:
                raise InternalError("Unknown response received from delegated RPC", name=self._service, rpc_id=rpc_id, result=result)

        return _awaitable_wrapper()

Call an RPC by its ID.

Args:
        rpc_id (int): The number of the RPC
        payload (bytes): A byte string of payload parameters up to 20 bytes

Returns:
        str: The response payload from the RPC


def save(self, revision=True, *args, **kwargs):

        if revision:
            # If this is a revision, set it to be the head of the list and increment the revision id
            self.head = True
            self.revision_id += 1

            previous_revision = self.get_previous_revision()

            if not self.is_parent():
                # If this is a revision, delete the old head of the list.
                type(self).objects \
                    .filter(parent=self.parent, head=True) \
                    .update(head=None)

                # Clear the instance id to force Django to save a new instance.
                # Both fields (pk, id) required for this to work -- something to do with model inheritance
                self.pk = None
                self.id = None

                # New version is unpublished by default
                self.is_published = None

        # Set created_at to current time, but only for first version
        if not self.created_at:
            self.created_at = timezone.now()
            self.updated_at = timezone.now()

        if revision:
            self.updated_at = timezone.now()

        super(Publishable, self).save(*args, **kwargs)

        # Update the parent foreign key
        if not self.parent:
            self.parent = self
            super(Publishable, self).save(update_fields=['parent'])

        if revision:
            # Set latest version for all articles
            type(self).objects \
                .filter(parent=self.parent) \
                .update(latest_version=self.revision_id)

            self.latest_version = self.revision_id

        return self

Handles the saving/updating of a Publishable instance.

Args:
    revision - if True, a new version of this Publishable will be created.


def remove_son(self, son):

        self._sons = [x for x in self._sons if x.node_id != son.node_id]

Remove the son node. Do nothing if the node is not a son

Args:
        fathers: list of fathers to add


def record_padding(self, iso_size):
        # type: (int) -> bytes

        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized')

        return b'\x00' * self._calc_cc(iso_size)[1]

A method to record padding for the ISO hybridization.

    Parameters:
    iso_size - The size of the ISO, excluding the hybridization.

Returns:
    A string of zeros the right size to pad the ISO.


def _normalize_angle(angle, range, step):

    while angle <= range[0]:
        angle += step
    while angle >= range[1]:
        angle -= step
    return angle

Finds an angle that matches the given one modulo step.

    Increments and decrements the given value with a given step.

Args:
        range: a 2-tuple of min and max target values.
        step: tuning step.

Returns:
        Normalized value within a given range.


def from_ddy_file(cls, file_path):

        # check that the file is there
        if not os.path.isfile(file_path):
            raise ValueError(
                'Cannot find a .ddy file at {}'.format(file_path))
        if not file_path.lower().endswith('.ddy'):
            raise ValueError(
                'DDY file does not have a .ddy extension.')

        # check the python version and open the file
        try:
            iron_python = True if platform.python_implementation() == 'IronPython' \
                else False
        except Exception:
            iron_python = True

        if iron_python:
            ddywin = codecs.open(file_path, 'r')
        else:
            ddywin = codecs.open(file_path, 'r', encoding='utf-8', errors='ignore')

        try:
            ddytxt = ddywin.read()
            location_format = re.compile(
                r"(Site:Location,(.|\n)*?((;\s*!)|(;\s*\n)|(;\n)))")
            design_day_format = re.compile(
                r"(SizingPeriod:DesignDay,(.|\n)*?((;\s*!)|(;\s*\n)|(;\n)))")
            location_matches = location_format.findall(ddytxt)
            des_day_matches = design_day_format.findall(ddytxt)
        except Exception as e:
            import traceback
            raise Exception('{}\n{}'.format(e, traceback.format_exc()))
        else:
            # check to be sure location was found
            assert len(location_matches) > 0, 'No location objects found ' \
                'in .ddy file.'

            # build design day and location objects
            location = Location.from_location(location_matches[0][0])
            design_days = [DesignDay.from_ep_string(
                match[0], location) for match in des_day_matches]
        finally:
            ddywin.close()

        cls_ = cls(location, design_days)
        cls_._file_path = os.path.normpath(file_path)
        return cls_

Initalize from a ddy file object from an existing ddy file.

Args:
        file_path: A string representing a complete path to the .ddy file.


def _kl_bernoulli_bernoulli(a, b, name=None):

  with tf.name_scope(name or "kl_bernoulli_bernoulli"):
    delta_probs0 = tf.nn.softplus(-b.logits) - tf.nn.softplus(-a.logits)
    delta_probs1 = tf.nn.softplus(b.logits) - tf.nn.softplus(a.logits)
    return (tf.sigmoid(a.logits) * delta_probs0
            + tf.sigmoid(-a.logits) * delta_probs1)

Calculate the batched KL divergence KL(a || b) with a and b Bernoulli.

Args:
        a: instance of a Bernoulli distribution object.
        b: instance of a Bernoulli distribution object.
        name: (optional) Name to use for created operations.
        default is "kl_bernoulli_bernoulli".

Returns:
        Batchwise KL(a || b)


def __is_noncopyable_single(class_, already_visited_cls_vars=None):

    # It is not enough to check base classes, we should also to check
    # member variables.
    logger = utils.loggers.cxx_parser

    if has_copy_constructor(class_) \
       and has_public_constructor(class_) \
       and has_public_assign(class_) \
       and has_public_destructor(class_):
        msg = os.linesep.join([
            "__is_noncopyable_single - %s - COPYABLE:" % class_.decl_string,
            "    trivial copy constructor: yes",
            "    public constructor: yes",
            "    public assign: yes",
            "    public destructor: yes"])
        logger.debug(msg)
        return False

    if already_visited_cls_vars is None:
        already_visited_cls_vars = []

    if find_noncopyable_vars(class_, already_visited_cls_vars):
        logger.debug(
            ("__is_noncopyable_single(TRUE) - %s - contains noncopyable " +
             "members"), class_.decl_string)
        return True

    logger.debug((
        "__is_noncopyable_single(FALSE) - %s - COPYABLE, because is " +
        "doesn't contains noncopyable members"), class_.decl_string)
    return False

Implementation detail.

    Checks if the class is non copyable, without considering the base classes.

Args:
        class_ (declarations.class_t): the class to be checked
        already_visited_cls_vars (list): optional list of vars that should not
            be checked a second time, to prevent infinite recursions.

Returns:
        bool: if the class is non copyable


def to_text_diagram(
            self,
            *,
            use_unicode_characters: bool = True,
            transpose: bool = False,
            precision: Optional[int] = 3,
            qubit_order: ops.QubitOrderOrList = ops.QubitOrder.DEFAULT) -> str:

        diagram = self.to_text_diagram_drawer(
            use_unicode_characters=use_unicode_characters,
            precision=precision,
            qubit_order=qubit_order,
            transpose=transpose)

        return diagram.render(
            crossing_char=(None
                           if use_unicode_characters
                           else ('-' if transpose else '|')),
            horizontal_spacing=1 if transpose else 3,
            use_unicode_characters=use_unicode_characters)

Returns text containing a diagram describing the circuit.

Args:
        use_unicode_characters: Determines if unicode characters are
            allowed (as opposed to ascii-only diagrams).
        transpose: Arranges qubit wires vertically instead of horizontally.
        precision: Number of digits to display in text diagram
        qubit_order: Determines how qubits are ordered in the diagram.

Returns:
        The text diagram.


def kill_proc_tree(pid: int,
                   including_parent: bool = True,
                   timeout_s: float = 5) \
        -> Tuple[Set[psutil.Process], Set[psutil.Process]]:
      # noqa
    parent = psutil.Process(pid)
    to_kill = parent.children(recursive=True)  # type: List[psutil.Process]
    if including_parent:
        to_kill.append(parent)
    for proc in to_kill:
        proc.kill()  # SIGKILL
    gone, still_alive = psutil.wait_procs(to_kill, timeout=timeout_s)
    return gone, still_alive

Kills a tree of processes, starting with the parent. Slightly modified from
    https://stackoverflow.com/questions/1230669/subprocess-deleting-child-processes-in-windows.

Args:
        pid: process ID of the parent
        including_parent: kill the parent too?
        timeout_s: timeout to wait for processes to close

Returns:
        tuple: ``(gone, still_alive)``, where both are sets of
        :class:`psutil.Process` objects


def add_rect(self, width, height, rid=None):

        assert(width > 0 and height >0)

        # Search best position and orientation
        rect, _ = self._select_position(width, height)
        if not rect:
            return None

        # Subdivide all the max rectangles intersecting with the selected
        # rectangle.
        self._split(rect)

        # Remove any max_rect contained by another
        self._remove_duplicates()

        # Store and return rectangle position.
        rect.rid = rid
        self.rectangles.append(rect)
        return rect

Add rectangle of widthxheight dimensions.

Args:
        width (int, float): Rectangle width
        height (int, float): Rectangle height
        rid: Optional rectangle user id

Returns:
        Rectangle: Rectangle with placemente coordinates
        None: If the rectangle couldn be placed.


def has_current_path(self, path, **kwargs):

        try:
            return self.assert_current_path(path, **kwargs)
        except ExpectationNotMet:
            return False

Checks if the page has the given path.

Args:
        path (str | RegexObject): The string or regex that the current "path" should match.
        **kwargs: Arbitrary keyword arguments for :class:`CurrentPathQuery`.

Returns:
        bool: Whether it matches.


def global_horizontal_radiation(self, value=9999.0):

        if value is not None:
            try:
                value = float(value)
            except ValueError:
                raise ValueError(
                    'value {} need to be of type float '
                    'for field `global_horizontal_radiation`'.format(value))
            if value < 0.0:
                raise ValueError('value need to be greater or equal 0.0 '
                                 'for field `global_horizontal_radiation`')

        self._global_horizontal_radiation = value

Corresponds to IDD Field `global_horizontal_radiation`

Args:
        value (float): value for IDD Field `global_horizontal_radiation`
            Unit: Wh/m2
            value >= 0.0
            Missing value: 9999.0
            if `value` is None it will not be checked against the
            specification and is assumed to be a missing value

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


def sub_escapes(sval):

    sval = sval.replace('\\a', '\a')
    sval = sval.replace('\\b', '\x00')
    sval = sval.replace('\\f', '\f')
    sval = sval.replace('\\n', '\n')
    sval = sval.replace('\\r', '\r')
    sval = sval.replace('\\t', '\t')
    sval = sval.replace('\\v', '\v')
    sval = sval.replace('\\\\', '\\')
    return sval

Process escaped characters in ``sval``.

Args:
    - `sval`:


def parse_compounds(compound_info, case_id, variant_type):

    # We need the case to construct the correct id
    compounds = []
    if compound_info:
        for family_info in compound_info.split(','):
            splitted_entry = family_info.split(':')
            # This is the family id
            if splitted_entry[0] == case_id:
                for compound in splitted_entry[1].split('|'):
                    splitted_compound = compound.split('>')
                    compound_obj = {}
                    compound_name = splitted_compound[0]
                    compound_obj['variant'] = generate_md5_key(compound_name.split('_') +
                                                               [variant_type, case_id])

                    try:
                        compound_score = float(splitted_compound[1])
                    except (TypeError, IndexError):
                        compound_score = 0.0

                    compound_obj['score'] = compound_score
                    compound_obj['display_name'] = compound_name

                    compounds.append(compound_obj)

    return compounds

Get a list with compounds objects for this variant.

Args:
        compound_info(str): A Variant dictionary
        case_id (str): unique family id
        variant_type(str): 'research' or 'clinical'

Returns:
        compounds(list(dict)): A list of compounds


def transform(self, input_df):

        # Shallow copy the dataframe (we'll be making changes to some columns)
        _df = input_df.copy(deep=False)

        # Convert all columns that are/should be categorical
        for column in self.cat_columns:

            # Sanity check
            if column not in _df:
                raise RuntimeError('Required column {:s} not found'.format(column))

            # If the column isn't already a category then change it
            if _df[column].dtype == 'object':
                print('Changing column {:s} to category'.format(column))
                _df[column] = pd.Categorical(_df[column])

        # Remove any columns that aren't bool/int/float/category
        _df = _df.select_dtypes(include=['bool', 'int', 'float', 'category'])

        # Normalize any numeric columns if normalize specified
        if self.normalize:
            for column in list(_df.select_dtypes(include=[np.number]).columns.values):
                print('Normalizing column {:s}...'.format(column))
                smin, smax = self.norm_map[column]
                _df[column] = (_df[column] - smin) / (smax - smin)

        # Now that categorical columns are setup call the dummy_encoder
        return self.dummy_encoder.transform(_df)

Convert the dataframe to a matrix (numpy ndarray)

Args:
        input_df (dataframe): The dataframe to convert


def search_messages(self, *, query: str, **kwargs) -> SlackResponse:

        self._validate_xoxp_token()
        kwargs.update({"query": query})
        return self.api_call("search.messages", http_verb="GET", params=kwargs)

Searches for messages matching a query.

Args:
        query (str): Search query. May contains booleans, etc.
            e.g. 'pickleface'


def get_params_and_defaults(param_list, db):

    return [[p, d] for p, d in db.get_all_values_of_all_params().items()]

Deduce [parameter, default] pairs from simulations available in the db.

Args:
        param_list (list): List of parameters to query for.
        db (DatabaseManager): Database where to query for defaults.


def show_plot(plot, width=PREVIEW_WIDTH, height=PREVIEW_HEIGHT):

    return SVG(data=plot_to_svg(plot, width, height))

Preview a plot in a jupyter notebook.

Args:
        plot (list): the plot to display (list of layers)
        width (int): the width of the preview
        height (int): the height of the preview

Returns:
        An object that renders in Jupyter as the provided plot


def do_patch(endpoint, body, access_token):

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

Do an HTTP PATCH request and return JSON.

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

Returns:
        HTTP response. JSON body.


def add_dicts(one_dict, other_dict):

    result = other_dict.copy()
    for k, v in one_dict.items():
        if v is None:
            v = 0

        if isinstance(v, dict):
            result[k] = add_dicts(v, other_dict.get(k, {}))
        else:
            other_value = result.get(k, 0)
            if other_value is None:
                other_value = 0
            result[k] = other_value + v

    return result

Suma clave a clave los dos diccionarios. Si algún valor es un
    diccionario, llama recursivamente a la función. Ambos diccionarios deben
    tener exactamente las mismas claves, y los valores asociados deben ser
    sumables, o diccionarios.

Args:
        one_dict (dict)
        other_dict (dict)

Returns:
        dict: resultado de la suma


def create_reset_score(cls, student_item):

        # By setting the "reset" flag, we ensure that the "highest"
        # score in the score summary will point to this score.
        # By setting points earned and points possible to 0,
        # we ensure that this score will be hidden from the user.
        return cls.objects.create(
            student_item=student_item,
            submission=None,
            points_earned=0,
            points_possible=0,
            reset=True,
        )

Create a "reset" score (a score with a null submission).

    Only scores created after the most recent "reset" score
    should be used to determine a student's effective score.

Args:
        student_item (StudentItem): The student item model.

Returns:
        Score: The newly created "reset" score.

Raises:
        DatabaseError: An error occurred while creating the score


def new(self):
        # type: () -> None

        if self._initialized:
            raise pycdlibexception.PyCdlibInternalError('UDF Logical Volume Header Descriptor already initialized')

        self.unique_id = 261

        self._initialized = True

A method to create a new UDF Logical Volume Header Descriptor.

    Parameters:
    None.

Returns:
    Nothing.


def loads(string, triples=False, cls=PENMANCodec, **kwargs):

    codec = cls(**kwargs)
    return list(codec.iterdecode(string, triples=triples))

Deserialize a list of PENMAN-encoded graphs from *string*.

Args:
        string: a string containing graph data
        triples: if True, read graphs as triples instead of as PENMAN
        cls: serialization codec class
        kwargs: keyword arguments passed to the constructor of *cls*

Returns:
        a list of Graph objects


def _PrintTasksInformation(self, storage_reader):

    table_view = views.ViewsFactory.GetTableView(
        self._views_format_type, title='Tasks')

    for task_start, _ in storage_reader.GetSessions():
      start_time = timelib.Timestamp.CopyToIsoFormat(
          task_start.timestamp)
      task_identifier = uuid.UUID(hex=task_start.identifier)
      task_identifier = '{0!s}'.format(task_identifier)
      table_view.AddRow([task_identifier, start_time])

    table_view.Write(self._output_writer)

Prints information about the tasks.

Args:
        storage_reader (StorageReader): storage reader.


def load_panel_app(adapter, panel_id=None, institute='cust000'):

    base_url = 'https://panelapp.genomicsengland.co.uk/WebServices/{0}/'

    hgnc_map = adapter.genes_by_alias()

    if panel_id:
        panel_ids = [panel_id]

    if not panel_id:

        LOG.info("Fetching all panel app panels")
        data = get_request(base_url.format('list_panels'))

        json_lines = json.loads(data)

        panel_ids = [panel_info['Panel_Id'] for panel_info in json_lines['result']]

    for panel_id in panel_ids:
        panel_data = get_request(base_url.format('get_panel') + panel_id)

        parsed_panel = parse_panel_app_panel(
            panel_info = json.loads(panel_data)['result'],
            hgnc_map=hgnc_map,
            institute=institute
        )
        parsed_panel['panel_id'] = panel_id

        if len(parsed_panel['genes']) == 0:
            LOG.warning("Panel {} is missing genes. Skipping.".format(parsed_panel['display_name']))
            continue

        try:
            adapter.load_panel(parsed_panel=parsed_panel)
        except Exception as err:
            raise err

Load PanelApp panels into scout database

    If no panel_id load all PanelApp panels

Args:
        adapter(scout.adapter.MongoAdapter)
        panel_id(str): The panel app panel id


def mimic_adam_with_adafactor(hparams):

  assert "adam" in hparams.optimizer
  hparams.optimizer = "adafactor"
  hparams.optimizer_adafactor_beta1 = hparams.optimizer_adam_beta1
  hparams.optimizer_adafactor_beta2 = hparams.optimizer_adam_beta2
  hparams.optimizer_adafactor_multiply_by_parameter_scale = False
  hparams.optimizer_adafactor_factored = False
  hparams.optimizer_adafactor_clipping_threshold = None
  hparams.optimizer_adafactor_decay_type = "adam"

Switch from Adam to Adafactor, approximating the behavior of Adam.

    Some minor things may be different, like epsilon and beta1 correction.

Args:
        hparams: model hyperparameters where "adam" in hparams.optimizer


def get_data(self, label: str) -> Any:

        return self._get_resource(label, self._data, "data")

Get a data resource by label

Args:
        label (str): The labvel for the data resource to fetch

Returns:
        The requeted data object


def pmap(f, iterable, n=None, dummy=False, p=None):

    # make it easier to debug.
    if n == 1:
        for r in it.starmap(f, iterable):
            yield r
        raise StopIteration

    if p is None:
        po = pool(n, dummy)
    else:
        po = p
    assert hasattr(po, 'imap')
    f = _func_star(f)

    try:
        for r in po.imap(f, iterable):
            yield r

    # explicitly clean up created pool
    finally:
        if p is None:
            try:
                po.close()
                po.join()
            except:
                pass

parallel map of a function to an iterable
    if each item in iterable is itself an iterable, then
    automatically call f(*item) instead of f(item)

Args:
        f: function
        iterable: any iterable where each item is sent to f
        n: number of cpus (default is number on machine)
        dummy: use dummy pool.
        p: existing pool to re-use


def evaluate_stacked_ensemble(path, ensemble_id):

    with functions.DBContextManager(path) as session:
        stacked_ensemble = session.query(models.StackedEnsemble).filter_by(
            id=ensemble_id).first()
        if not stacked_ensemble:
            raise exceptions.UserError('Stacked ensemble {} '
                                       'does not exist'.format(ensemble_id))

        stacked_ensemble.job_id = get_current_job().id
        stacked_ensemble.job_status = 'started'

        session.add(stacked_ensemble)
        session.commit()

        try:
            meta_features_list = []
            for base_learner in stacked_ensemble.base_learners:
                mf = np.load(base_learner.meta_features_path(path))
                if len(mf.shape) == 1:
                    mf = mf.reshape(-1, 1)
                meta_features_list.append(mf)

            secondary_features = np.concatenate(meta_features_list, axis=1)

            # Get data
            extraction = session.query(models.Extraction).first()
            return_splits_iterable = functions.import_object_from_string_code(
                extraction.meta_feature_generation['source'],
                'return_splits_iterable'
            )
            X, y = extraction.return_train_dataset()

            #  We need to retrieve original order of meta-features
            indices_list = [test_index for train_index, test_index in return_splits_iterable(X, y)]
            indices = np.concatenate(indices_list)
            X, y = X[indices], y[indices]

            est = stacked_ensemble.return_secondary_learner()

            return_splits_iterable_stacked_ensemble = functions.import_object_from_string_code(
                extraction.stacked_ensemble_cv['source'],
                'return_splits_iterable'
            )
            preds = []
            trues_list = []
            for train_index, test_index in return_splits_iterable_stacked_ensemble(secondary_features, y):
                X_train, X_test = secondary_features[train_index], secondary_features[test_index]
                y_train, y_test = y[train_index], y[test_index]
                est = est.fit(X_train, y_train)
                preds.append(
                    getattr(est, stacked_ensemble.base_learner_origin.
                            meta_feature_generator)(X_test)
                )
                trues_list.append(y_test)
            preds = np.concatenate(preds, axis=0)
            y_true = np.concatenate(trues_list)

            for key in stacked_ensemble.base_learner_origin.metric_generators:
                metric_generator = functions.import_object_from_string_code(
                    stacked_ensemble.base_learner_origin.metric_generators[key],
                    'metric_generator'
                )
                stacked_ensemble.individual_score[key] = metric_generator(y_true, preds)

            stacked_ensemble.job_status = 'finished'
            session.add(stacked_ensemble)
            session.commit()

        except:
            session.rollback()
            stacked_ensemble.job_status = 'errored'
            stacked_ensemble.description['error_type'] = repr(sys.exc_info()[0])
            stacked_ensemble.description['error_value'] = repr(sys.exc_info()[1])
            stacked_ensemble.description['error_traceback'] = \
                traceback.format_exception(*sys.exc_info())
            session.add(stacked_ensemble)
            session.commit()
            raise

Evaluates the ensemble and updates the database when finished/

Args:
        path (str): Path to Xcessiv notebook

        ensemble_id (str): Ensemble ID


def median(series):

    if np.issubdtype(series.dtype, np.number):
        return series.median()
    else:
        return np.nan

Returns the median value of a series.

Args:
        series (pandas.Series): column to summarize.


def sg_parallel(func):
    r
    @wraps(func)
    def wrapper(**kwargs):
        r
        # parse option
        opt = tf.sg_opt(kwargs)

        # loop for all available GPUs
        res = []
        for i in range(sg_gpus()):
            # specify device
            with tf.device('/gpu:%d' % i):
                # give new scope only to operation
                with tf.name_scope('gpu_%d' % i):
                    # save reuse flag
                    with sg_context(reuse=(True if i > 0 else False)):
                        # call function
                        res.append(func(opt * tf.sg_opt(gpu_index=i)))

        return res

    return wrapper

r"""Decorates function as multiple gpu support towers.

Args:
        func: function to decorate


def populate_native_libraries(version):

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

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

Args:
        version (str): The current version.


def get_service_health(service_id: str) -> str:

        # Check if the current and actual replica levels are the same
        if DC.get_replicas(service_id) != DC.get_actual_replica(service_id):
            health_status = "Unhealthy"
        else:
            health_status = "Healthy"

        return health_status

Get the health of a service using service_id.

Args:
        service_id

Returns:
        str, health status


def get_user(self, user):

        self.project_service.set_auth(self._token_project)
        return self.project_service.get_user(user)

Get user's data (first and last name, email, etc).

Args:
        user (string): User name.

Returns:
        (dictionary): User's data encoded in a dictionary.

Raises:
        requests.HTTPError on failure.


def fixminimized(self, alphabet):

        endstate = len(list(self.states))
        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 = TropicalWeight(float('inf'))

        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