def create_in_hdx(self, allow_no_resources=False, update_resources=True, update_resources_by_name=True, remove_additional_resources=False, create_default_views=True, hxl_update=True):
    self.check_required_fields(allow_no_resources=allow_no_resources)
    loadedid = None
    if ('id' in self.data):
        if self._dataset_load_from_hdx(self.data['id']):
            loadedid = self.data['id']
        else:
            logger.warning(('Failed to load dataset with id %s' % self.data['id']))
    if (not loadedid):
        if self._dataset_load_from_hdx(self.data['name']):
            loadedid = self.data['name']
    if loadedid:
        logger.warning(('Dataset exists. Updating %s' % loadedid))
        self._dataset_merge_hdx_update(update_resources=update_resources, update_resources_by_name=update_resources_by_name, remove_additional_resources=remove_additional_resources, create_default_views=create_default_views, hxl_update=hxl_update)
        return
    filestore_resources = list()
    if self.resources:
        ignore_fields = ['package_id']
        for resource in self.resources:
            resource.check_required_fields(ignore_fields=ignore_fields)
            if resource.get_file_to_upload():
                filestore_resources.append(resource)
                resource['url'] = Dataset.temporary_url
        self.data['resources'] = self._convert_hdxobjects(self.resources)
    self._save_to_hdx('create', 'name')
    self._add_filestore_resources(filestore_resources, False, hxl_update)

Check if dataset exists in HDX and if so, update it, otherwise create it

Args:
allow_no_resources (bool): Whether to allow no resources. Defaults to False.
update_resources (bool): Whether to update resources (if updating). Defaults to True.
update_resources_by_name (bool): Compare resource names rather than position in list. Defaults to True.
remove_additional_resources (bool): Remove additional resources found in dataset (if updating). Defaults to False.
create_default_views (bool): Whether to call package_create_default_resource_views (if updating). Defaults to True.
hxl_update (bool): Whether to call package_hxl_update. Defaults to True.

Returns:
None


def get_matrix(self, x1=None, x2=None, include_diagonal=None, include_general=None):
    if ((x1 is None) and (x2 is None)):
        if ((self._t is None) or (not self.computed)):
            raise RuntimeError("you must call 'compute' first")
        K = self.kernel.get_value((self._t[(:, None)] - self._t[(None, :)]))
        if ((include_diagonal is None) or include_diagonal):
            K[np.diag_indices_from(K)] += ((self._yerr ** 2) + self.kernel.jitter)
        if (((include_general is None) or include_general) and len(self._A)):
            K[np.diag_indices_from(K)] += self._A
            K += np.tril(np.dot(self._U.T, self._V), (- 1))
            K += np.triu(np.dot(self._V.T, self._U), 1)
        return K
    incl = False
    x1 = np.ascontiguousarray(x1, dtype=float)
    if (x2 is None):
        x2 = x1
        incl = ((include_diagonal is not None) and include_diagonal)
    K = self.kernel.get_value((x1[(:, None)] - x2[(None, :)]))
    if incl:
        K[np.diag_indices_from(K)] += self.kernel.jitter
    return K

Get the covariance matrix at given independent coordinates

Args:
x1 (Optional[array[n1]]): The first set of independent coordinates.
If this is omitted, ``x1`` will be assumed to be equal to ``x``
from a previous call to :func:`GP.compute`.
x2 (Optional[array[n2]]): The second set of independent
coordinates. If this is omitted, ``x2`` will be assumed to be
``x1``.
include_diagonal (Optional[bool]): Should the white noise and
``yerr`` terms be included on the diagonal?
(default: ``False``)


def get_pipeline_field(self, pipeline_key, field_key = None):

		uri = '/'.join([
						self.api_uri,
						self.pipelines_suffix,
						pipeline_key,
						self.fields_suffix
						])
		if field_key:
			uri = '/'.join([uri, field_key])

		return self._req('get', uri)

Gets one/all field in a pipeline
Args:
pipeline_key 		key for pipeline
field_key 			key for field (default: None i.e. ALL)
returns				status code, field dict or list thereof


def guess_listing_type(lines, threshold=100):
    scores = {'unix': 0, 'msdos': 0, 'nlst': 0}
    for line in lines:
        if (not line):
            continue
        if re.search('---|r--|rw-|rwx', line):
            scores['unix'] += 1
        if (('<DIR>' in line) or re.search('^.{0,4}\\d\\d', line)):
            scores['msdos'] += 1
        words = line.split(' ', 1)
        if (len(words) == 1):
            scores['nlst'] += 1
        if (max(scores.values()) > threshold):
            break
    top = max(scores.items(), key=(lambda item: item[1]))
    if top[1]:
        return top[0]
    else:
        return 'unknown'

Guess the style of directory listing.

Returns:
str: ``unix``, ``msdos``, ``nlst``, ``unknown``.


def __init__(self, cipher_suites=None):

        super(BasicAuthenticationSuite, self).__init__(cipher_suites)
        self._protocol = ssl.PROTOCOL_TLSv1

Create a BasicAuthenticationSuite object.

Args:
cipher_suites (list): A list of strings representing the names of
cipher suites to use. Overrides the default set of cipher
suites. Optional, defaults to None.


def _count_ops(self, graphdef: graph_pb2.GraphDef, op_names: Collection[str], attr_name: str='', attr_val: _AttrValType=None, get_op_name: bool=False) -> int:
    op_count = 0
    for op_name in op_names:
        op_count += self._count_op_with_name_and_attribute(nodes=graphdef.node, op_name=op_name, attr_name=attr_name, attr_val=attr_val, get_op_name=get_op_name)
        for func in graphdef.library.function:
            op_count += self._count_op_with_name_and_attribute(nodes=func.node_def, op_name=op_name, attr_name=attr_name, attr_val=attr_val, get_op_name=get_op_name)
    return op_count

Returns the number of given ops in a graph def.

Args:
graphdef: A GraphDef object.
op_names: Names of the operations to find within the graph.
attr_name: Name of the attribute of the ops to match.
attr_val: Value of the attr_name to check.
get_op_name: If set True, checks node.name rather than node.op.

Returns:
The number of occurrences of the given ops in a graph. The ops will be
counted only if the ops are named 'op_name' and has 'attr_val' if
'attr_name' is specified.


def select_starts_ends(start, end, p_mask, attention_mask, min_null_score=1000000, top_k=1, handle_impossible_answer=False, max_answer_len=15):
    undesired_tokens = np.abs(np.array(p_mask) - 1)
    if attention_mask is not None:
        undesired_tokens = undesired_tokens & attention_mask
    undesired_tokens_mask = undesired_tokens == 0.0
    start = np.where(undesired_tokens_mask, -10000.0, start)
    end = np.where(undesired_tokens_mask, -10000.0, end)
    start = np.exp(start - start.max(axis=-1, keepdims=True))
    start = start / start.sum()
    end = np.exp(end - end.max(axis=-1, keepdims=True))
    end = end / end.sum()
    if handle_impossible_answer:
        min_null_score = min(min_null_score, (start[0, 0] * end[0, 0]).item())
    start[0, 0] = end[0, 0] = 0.0
    starts, ends, scores = decode_spans(start, end, top_k, max_answer_len, undesired_tokens)
    return (starts, ends, scores, min_null_score)

Takes the raw output of any `ModelForQuestionAnswering` and first normalizes its outputs and then uses
`decode_spans()` to generate probabilities for each span to be the actual answer.

Args:
start (`np.ndarray`): Individual start logits for each token.
end (`np.ndarray`): Individual end logits for each token.
p_mask (`np.ndarray`): A mask with 1 for values that cannot be in the answer
attention_mask (`np.ndarray`): The attention mask generated by the tokenizer
min_null_score(`float`): The minimum null (empty) answer score seen so far.
topk (`int`): Indicates how many possible answer span(s) to extract from the model output.
handle_impossible_answer(`bool`): Whether to allow null (empty) answers
max_answer_len (`int`): Maximum size of the answer to extract from the model's output.


def CreateKey(self, prikey=None):
    account = super(UserWallet, self).CreateKey(private_key=prikey)
    self.OnCreateAccount(account)
    contract = WalletContract.CreateSignatureContract(account.PublicKey)
    self.AddContract(contract)
    return account

Create a KeyPair and store it encrypted in the database.

Args:
private_key (iterable_of_ints): (optional) 32 byte private key.

Returns:
KeyPair: a KeyPair instance.


def integer_fractional_parts(number):

    radix_point = number.index(".")
    integer_part = number[:radix_point]
    fractional_part = number[radix_point:]
    return(integer_part, fractional_part)

Returns a tuple of the integer and fractional parts of a number.

Args:
number(iterable container): A number in the following form:
(..., ".", int, int, int, ...)

Returns:
(integer_part, fractional_part): tuple.

Example:
>>> integer_fractional_parts((1,2,3,".",4,5,6))
((1, 2, 3), ('.', 4, 5, 6))


def find_item(self, fq_name):

        names = fq_name.split(self._separator)
        current = self._yapconf_items
        for name in names:
            if isinstance(current, (YapconfDictItem, YapconfListItem)):
                current = current.children

            if name not in current:
                return None
            current = current[name]
        return current

Find an item in the specification by fully qualified name.

Args:
fq_name (str): Fully-qualified name of the item.

Returns:
The item if it is in the specification. None otherwise


def load_sklearn_iris_test_data(data_type: Callable, split: bool=True, seed: int=999) -> list[Union[numpy.array, pandas.DataFrame]]:
    dataset = load_iris()
    _, x_test, _, _ = train_test_split(dataset['data'], dataset['target'], test_size=0.2, random_state=seed)
    if split:
        return [(index, data_type(sample.reshape(1, -1))) for index, sample in enumerate(x_test)]
    return [(0, data_type(x_test))]

Loads test data from the sklearn Iris dataset in a given format,
either in a single or multiple batches.
Args:
data_type: Datatype of the iris test dataset.
split: Split the dataset in different batches or return single batch.
seed: Random state for splitting the train and test set.


def _get_eq_sets(self):
    UNIT = np.eye(3)
    (eq_sets, operations) = (defaultdict(set), defaultdict(dict))
    symm_ops = [op.rotation_matrix for op in generate_full_symmops(self.symmops, self.tol)]

    def get_clustered_indices():
        indices = cluster_sites(self.centered_mol, self.tol, give_only_index=True)
        out = list(indices[1].values())
        if (indices[0] is not None):
            out.append([indices[0]])
        return out
    for index in get_clustered_indices():
        sites = self.centered_mol.cart_coords[index]
        for (i, reference) in zip(index, sites):
            for op in symm_ops:
                rotated = np.dot(op, sites.T).T
                matched_indices = find_in_coord_list(rotated, reference, self.tol)
                matched_indices = {dict(enumerate(index))[i] for i in matched_indices}
                eq_sets[i] |= matched_indices
                if (i not in operations):
                    operations[i] = {j: (op.T if (j != i) else UNIT) for j in matched_indices}
                else:
                    for j in matched_indices:
                        if (j not in operations[i]):
                            operations[i][j] = (op.T if (j != i) else UNIT)
                for j in matched_indices:
                    if (j not in operations):
                        operations[j] = {i: (op if (j != i) else UNIT)}
                    elif (i not in operations[j]):
                        operations[j][i] = (op if (j != i) else UNIT)
    return {'eq_sets': eq_sets, 'sym_ops': operations}

Calculates the dictionary for mapping equivalent atoms onto each other.

Args:
None

Returns:
dict: The returned dictionary has two possible keys:

``eq_sets``:
A dictionary of indices mapping to sets of indices,
each key maps to indices of all equivalent atoms.
The keys are guaranteed to be not equivalent.

``sym_ops``:
Twofold nested dictionary.
``operations[i][j]`` gives the symmetry operation
that maps atom ``i`` unto ``j``.


def get_current_user(with_domain=True):
    try:
        user_name = win32api.GetUserNameEx(win32api.NameSamCompatible)
        if (user_name[(- 1)] == '$'):
            test_user = win32api.GetUserName()
            if (test_user == 'SYSTEM'):
                user_name = 'SYSTEM'
            elif (get_sid_from_name(test_user) == 'S-1-5-18'):
                user_name = 'SYSTEM'
        elif (not with_domain):
            user_name = win32api.GetUserName()
    except pywintypes.error as exc:
        raise CommandExecutionError('Failed to get current user: {0}'.format(exc))
    if (not user_name):
        return False
    return user_name

Gets the user executing the process

Args:

with_domain (bool):
``True`` will prepend the user name with the machine name or domain
separated by a backslash

Returns:
str: The user name


def fetch_local_package(self, config):
    self.update_paths_and_config(config=config, pkg_dir_name=config['source'], pkg_cache_dir=os.getcwd())

Make a local path available to current stacker config.

Args:
config (dict): 'local' path config dictionary


def __setitem__(self, key, value):

        if not fs.exists(value):
            raise ValueError(value)

        path = self.keypath(key)
        fs.mkdir(self.path)
        fs.mv(value, path)

Emplace file in cache.

Arguments:
key: Key.
value (str): Path of file to insert in cache.

Raises:
ValueError: If no "value" does nto exist.


def run_ansible(playbooks, inventory_path=None, roles=None, extra_vars=None, tags=None, on_error_continue=False, basedir='.'):
    (inventory, variable_manager, loader, options) = _load_defaults(inventory_path=inventory_path, roles=roles, extra_vars=extra_vars, tags=tags, basedir=basedir)
    passwords = {}
    for path in playbooks:
        logger.info(('Running playbook %s with vars:\n%s' % (path, extra_vars)))
        pbex = PlaybookExecutor(playbooks=[path], inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=passwords)
        code = pbex.run()
        stats = pbex._tqm._stats
        hosts = stats.processed.keys()
        result = [{h: stats.summarize(h)} for h in hosts]
        results = {'code': code, 'result': result, 'playbook': path}
        print(results)
        failed_hosts = []
        unreachable_hosts = []
        for h in hosts:
            t = stats.summarize(h)
            if (t['failures'] > 0):
                failed_hosts.append(h)
            if (t['unreachable'] > 0):
                unreachable_hosts.append(h)
        if (len(failed_hosts) > 0):
            logger.error(('Failed hosts: %s' % failed_hosts))
            if (not on_error_continue):
                raise EnosFailedHostsError(failed_hosts)
        if (len(unreachable_hosts) > 0):
            logger.error(('Unreachable hosts: %s' % unreachable_hosts))
            if (not on_error_continue):
                raise EnosUnreachableHostsError(unreachable_hosts)

Run Ansible.

Args:
playbooks (list): list of paths to the playbooks to run
inventory_path (str): path to the hosts file (inventory)
extra_var (dict): extra vars to pass
tags (list): list of tags to run
on_error_continue(bool): Don't throw any exception in case a host is
unreachable or the playbooks run with errors

Raises:
:py:class:`enoslib.errors.EnosFailedHostsError`: if a task returns an
error on a host and ``on_error_continue==False``
:py:class:`enoslib.errors.EnosUnreachableHostsError`: if a host is
unreachable (through ssh) and ``on_error_continue==False``


def add_answer(self, vote, rationale):

        self.raw_answers.append({
            VOTE_KEY: vote,
            RATIONALE_KEY: rationale,
        })

Add an answer

Args:
vote (int): the option that student voted for
rationale (str): the reason why the student vote for the option


def _find_best_fit(self, pbin):
    fit = ((pbin.fitness(r[0], r[1]), k) for (k, r) in self._sorted_rect.items())
    fit = (f for f in fit if (f[0] is not None))
    try:
        (_, rect) = min(fit, key=self.first_item)
        return rect
    except ValueError:
        return None

Return best fitness rectangle from rectangles packing _sorted_rect list

Arguments:
pbin (PackingAlgorithm): Packing bin

Returns:
key of the rectangle with best fitness


def add_sources_argument(cls, group, allow_filters=True, prefix=None, add_root_paths=False):

        prefix = prefix or cls.argument_prefix

        group.add_argument("--%s-sources" % prefix,
                           action="store", nargs="+",
                           dest="%s_sources" % prefix.replace('-', '_'),
                           help="%s source files to parse" % prefix)

        if allow_filters:
            group.add_argument("--%s-source-filters" % prefix,
                               action="store", nargs="+",
                               dest="%s_source_filters" % prefix.replace(
                                   '-', '_'),
                               help="%s source files to ignore" % prefix)

        if add_root_paths:
            group.add_argument("--%s-source-roots" % prefix,
                               action="store", nargs="+",
                               dest="%s_source_roots" % prefix.replace(
                                   '-', '_'),
                               help="%s source root directories allowing files "
                                    "to be referenced relatively to those" % prefix)

Subclasses may call this to add sources and source_filters arguments.

Args:
group: arparse.ArgumentGroup, the extension argument group
allow_filters: bool,  Whether the extension wishes to expose a
source_filters argument.
prefix: str, arguments have to be namespaced.


def Create(self, project_id, start_options=None, deadline=10):
    return DatastoreEmulator(self._emulator_cmd, self._working_directory, project_id, deadline, start_options)

Creates an emulator instance.

This method will wait for up to 'deadline' seconds for the emulator to
start.

Args:
project_id: project ID
start_options: a list of additional command-line options to pass to the
emulator 'start' command
deadline: number of seconds to wait for the datastore to respond

Returns:
a DatastoreEmulator

Raises:
IOError: if the emulator could not be started within the deadline


def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, position_bias: torch.Tensor, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, past_key_values: Optional[Tuple[torch.Tensor, torch.Tensor]]=None, use_cache: Optional[bool]=None):
    all_hidden_states = () if output_hidden_states else None
    all_self_attns = () if output_attentions else None
    current_key_values = () if use_cache else None
    for i, layer in enumerate(self.layers):
        if output_hidden_states:
            all_hidden_states += (hidden_states,)
        layer_outputs = layer(hidden_states, attention_mask, position_bias, output_attentions=output_attentions, past_key_values=past_key_values[i] if past_key_values else None, use_cache=use_cache)
        hidden_states, attn_weights, current_key_value = layer_outputs
        if output_attentions:
            all_self_attns += (attn_weights,)
        if current_key_value is not None:
            current_key_values = current_key_values + (current_key_value,)
    hidden_states = self.output_layernorm(hidden_states)
    if output_hidden_states:
        all_hidden_states += (hidden_states,)
    return (hidden_states, current_key_values, all_hidden_states, all_self_attns)

Args:
hidden_states (`torch.Tensor`):
Input to the layer of shape `(batch, seq_len, dim_model)`
attention_mask (`torch.Tensor`):
Avoid invalid areas to participate in the calculation of shape `(batch, seq_len, seq_len)`
position_bias (`torch.Tensor`):
Provides position information to attention mechanism of shape `(num_heads, seq_len, seq_len)`
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers.
output_hidden_states (`bool`, *optional*):
Whether or not to return the hidden states of all layers.
past_key_values (`Tuple[torch.Tensor, torch.Tensor])`, *optional*):
Cached past key and value projection states
use_cache (`bool`, *optional*):
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
(see `past_key_values`).


def GetSshkeyMap(self, since=None):
    return SshkeyUpdateGetter(self.conf).GetUpdates(source=self, search_base=self.conf['base'], search_filter=self.conf['filter'], search_scope=self.conf['scope'], since=since)

Return the sshkey map from this source.

Args:
since: Get data only changed since this timestamp (inclusive) or None
for all data.

Returns:
instance of maps.SshkeyMap


def _build_parser_message(self, column: str, parser: str, error: str, value: Any) -> LogMessage:
    return self._base_log.copy() | LogMessage(log_type=LogType.PARSER.value, column=column, parser=parser, error=error, value=value)

Adds parser error information to base log message.

Args:
* column: column where the rule is applied
* parser: parser function that failed and raises this message
* value: value that fails to parse

Returns:
* log: LogMessage dictionary


def grep(regex, output):
    lines = output.decode('utf-8').strip().splitlines()
    results = []
    for line in lines:
        if re.search(regex, line):
            results.append(line.strip())
    return results

Similar to linux's `grep`, this returns the line in an output stream
that matches a given regex pattern.

It does not rely on the `grep` binary and is not sensitive to line endings,
so it can be used cross-platform.

Args:
regex: string, a regex that matches the expected pattern.
output: byte string, the raw output of the adb cmd.

Returns:
A list of strings, all of which are output lines that matches the
regex pattern.


def get_image_size_for_max_num_patches(image_height: int, image_width: int, patch_size: int, max_num_patches: int, eps: float=1e-05) -> Tuple[int, int]:

    def get_scaled_image_size(scale: float, size: int, patch_size: int) -> int:
        scaled_size = size * scale
        scaled_size = math.ceil(scaled_size / patch_size) * patch_size
        scaled_size = max(patch_size, scaled_size)
        return int(scaled_size)
    scale_min, scale_max = (eps / 10, 100.0)
    while scale_max - scale_min >= eps:
        scale = (scale_min + scale_max) / 2
        target_height = get_scaled_image_size(scale, image_height, patch_size)
        target_width = get_scaled_image_size(scale, image_width, patch_size)
        num_patches = target_height / patch_size * (target_width / patch_size)
        if num_patches <= max_num_patches:
            scale_min = scale
        else:
            scale_max = scale
    scale = scale_min
    target_height = get_scaled_image_size(scale, image_height, patch_size)
    target_width = get_scaled_image_size(scale, image_width, patch_size)
    return (target_height, target_width)

Determine image size based on max number of patches, ensure dimensions are divisible by patch size and image is at least 1 patch.

Args:
image_height (`int`):
Original image height.
image_width (`int`):
Original image width.
patch_size (`int`):
Patch size for processing.
max_num_patches (`int`):
Maximum number of patches.
eps (`float`):
Small threshold for binary search.

Returns:
Tuple: (target_height, target_width)


def lookup_imagenet_labels(indices):

    global _CLASS_INDEX
    if _CLASS_INDEX is None:
        with open(os.path.join(os.path.dirname(__file__), '../../resources/imagenet_class_index.json')) as f:
            _CLASS_INDEX = json.load(f)

    indices = listify(indices)
    return [_CLASS_INDEX[str(idx)][1] for idx in indices]

Utility function to return the image net label for the final `dense` layer output index.

Args:
indices: Could be a single value or an array of indices whose labels should be looked up.

Returns:
Image net label corresponding to the image category.


def _check_status(cls, response_json):

        status = response_json['status']
        msg = response_json['msg']

        if status == 400:
            raise BadRequestException(msg)
        elif status == 403:
            raise PermissionDeniedException(msg)
        elif status == 404:
            raise FileNotFoundException(msg)
        elif status == 451:
            raise UnavailableForLegalReasonsException(msg)
        elif status == 509:
            raise BandwidthUsageExceeded(msg)
        elif status >= 500:
            raise ServerErrorException(msg)

Check the status of the incoming response, raise exception if status is not 200.

Args:
response_json (dict): results of the response of the GET request.

Returns:
None


def remove_handler(self, handler: Handler, group: int=0):
    if isinstance(handler, DisconnectHandler):
        self.disconnect_handler = None
    else:
        self.dispatcher.remove_handler(handler, group)

Removes a previously-added update handler.

Make sure to provide the right group that the handler was added in. You can use
the return value of the :meth:`add_handler` method, a tuple of (handler, group), and
pass it directly.

Args:
handler (``Handler``):
The handler to be removed.

group (``int``, *optional*):
The group identifier, defaults to 0.


def getWindow(title, exact=False):

    titles = getWindows()
    hwnd = titles.get(title, None)
    if not hwnd and not exact:
        for k, v in titles.items():
            if title in k:
                hwnd = v
                break
    if hwnd:
        return Window(hwnd)
    else:
        return None

Return Window object if 'title' or its part found in visible windows titles, else return None

Return only 1 window found first
Args:
title: unicode string
exact (bool): True if search only exact match


def concat(self, second_iterable):

        if self.closed():
            raise ValueError("Attempt to call concat() on a closed Queryable.")

        if not is_iterable(second_iterable):
            raise TypeError("Cannot compute concat() with second_iterable of "
                  "non-iterable {0}".format(str(type(second_iterable))[7: -1]))

        return self._create(itertools.chain(self, second_iterable))

Concatenates two sequences.

Note: This method uses deferred execution.

Args:
second_iterable: The sequence to concatenate on to the sequence.

Returns:
A Queryable over the concatenated sequences.

Raises:
ValueError: If the Queryable is closed().
TypeError: If second_iterable is not in fact iterable.


def ReadFile(self, definitions_registry, path):
    with open(path, 'r') as file_object:
        self.ReadFileObject(definitions_registry, file_object)

Reads data type definitions from a file into the registry.

Args:
definitions_registry (DataTypeDefinitionsRegistry): data type definitions
registry.
path (str): path of the file to read from.


def _DrawHours(self):
    tmpstrs = []
    for i in range(0, self._gwidth, self._min_grid):
        if ((i % self._hour_grid) == 0):
            tmpstrs.append(('<polyline class="FullHour" points="%d,%d, %d,%d" />' % (((i + 0.5) + 20), 20, ((i + 0.5) + 20), self._gheight)))
            tmpstrs.append(('<text class="Label" x="%d" y="%d">%d</text>' % ((i + 20), 20, (((i / self._hour_grid) + self._offset) % 24))))
        else:
            tmpstrs.append(('<polyline class="SubHour" points="%d,%d,%d,%d" />' % (((i + 0.5) + 20), 20, ((i + 0.5) + 20), self._gheight)))
    return ''.join(tmpstrs)

Generates svg to show a vertical hour and sub-hour grid

Returns:
# A string containing a polyline tag for each grid line
" <polyline class="FullHour" points="20,0 ..."


def uninstalled(name):

    ret = {'name': name,
           'changes': {},
           'result': None,
           'comment': ''}

    old = __salt__['flatpak.is_installed'](name)
    if not old:
        ret['comment'] = 'Package {0} is not installed'.format(name)
        ret['result'] = True
        return ret
    else:
        if __opts__['test']:
            ret['comment'] = 'Package {0} would have been uninstalled'.format(name)
            ret['changes']['old'] = old[0]['version']
            ret['changes']['new'] = None
            ret['result'] = None
            return ret

        __salt__['flatpak.uninstall'](name)
        if not __salt__['flatpak.is_installed'](name):
            ret['comment'] = 'Package {0} uninstalled'.format(name)
            ret['changes']['old'] = old[0]['version']
            ret['changes']['new'] = None
            ret['result'] = True
            return ret

Ensure that the named package is not installed.

Args:
name (str): The flatpak package.

Returns:
dict: The ``result`` and ``output``.

Example:

.. code-block:: yaml

uninstall_package:
flatpack.uninstalled:
- name: gimp


def deprecated(msg):

    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            logging.getLogger(__name__).warning(msg)
            return func(*args, **kwargs)

        return wrapper

    return decorator

Marks a function / method as deprecated.

Takes one argument, a message to be logged with information on future usage of the function or alternative methods
to call.

Args:
msg (str): Deprecation message to be logged

Returns:
`callable`


def witness_tx(tx_ins, tx_outs, tx_witnesses, **kwargs):

    deser = [script_ser.deserialize(tx_in.redeem_script) for tx_in in tx_ins
             if tx_in is not None]
    for w in tx_witnesses:
        try:
            deser.append(script_ser.deserialize(w.stack[-1].item))
        except (NotImplementedError, ValueError):
            pass
    version = max([guess_version(d) for d in deser])
    if 'lock_time' in kwargs:
        lock_time = kwargs['lock_time']
    else:
        lock_time = max([guess_locktime(d) for d in deser])

    return tb.make_tx(
        version=version,
        tx_ins=tx_ins,
        tx_outs=tx_outs,
        lock_time=lock_time,
        tx_witnesses=tx_witnesses)

Construct a fully-signed segwit transaction
Args:
tx_ins       list(TxIn instances): list of transaction inputs
tx_outs      list(TxOut instances): list of transaction outputs
tx_witnesses list(TxWitness instances): list of transaction witnsses
**kwargs:
version     (int): transaction version number
locktime    (hex): transaction locktime

Returns:
(Tx instance): signed transaction with witnesses


def defer(self, func: typing.Callable[([], typing.Any)], until: typing.Union[(int, float)]=(- 1)) -> typing.Any:
    raise NotImplementedError()

Defer the execution of a function until some clock value.

Args:
func (typing.Callable[[], typing.Any]): A callable that accepts no
arguments. All return values are ignored.
until (typing.Union[int, float]): A numeric value that represents
the clock time when the callback becomes available for
execution. Values that are less than the current time result in
the function being called at the next opportunity.

Returns:
typing.Any: An opaque identifier that represents the callback
uniquely within the processor. This identifier is used to
modify the callback scheduling.

Note:
The time given should not be considered absolute. It represents
the time when the callback becomes available to execute. It may
be much later than the given time value when the function actually
executes depending on the implementation.


def process_fixed_issues(self, volumes, existing_issues):

        fixed_issues = []
        for issue_id, issue in list(existing_issues.items()):
            if issue_id not in volumes:
                fixed_issues.append(issue)

        return fixed_issues

Provided a list of volumes and existing issues, returns a list of fixed issues to be deleted

Args:
volumes (`dict`): A dictionary keyed on the issue id, with the :obj:`Volume` object as the value
existing_issues (`dict`): A dictionary keyed on the issue id, with the :obj:`EBSVolumeAuditIssue` object as
the value

Returns:
:obj:`list` of :obj:`EBSVolumeAuditIssue`


def inspect_last(self, stream, only_allocated=False):
    if only_allocated:
        found = False
        for walker in self._virtual_walkers:
            if walker.matches(stream):
                found = True
                break
        if (not found):
            raise UnresolvedIdentifierError('inspect_last could not find an allocated virtual streamer for the desired stream', stream=stream)
    if (stream in self._last_values):
        return self._last_values[stream]
    raise StreamEmptyError(u'inspect_last called on stream that has never been written to', stream=stream)

Return the last value pushed into a stream.

This function works even if the stream is virtual and no
virtual walker has been created for it.  It is primarily
useful to aid in debugging sensor graphs.

Args:
stream (DataStream): The stream to inspect.
only_allocated (bool): Optional parameter to only allow inspection
of allocated virtual streams.  This is useful for mimicking the
behavior of an embedded device that does not have a _last_values
array.

Returns:
IOTileReading: The data in the stream

Raises:
StreamEmptyError: if there has never been data written to
the stream.
UnresolvedIdentifierError: if only_allocated is True and there has not
been a virtual stream walker allocated to listen to this stream.


def with_division(self, division):
    if (division is None):
        division = ''
    division = slugify(division)
    self._validate_division(division)
    self.division = division
    return self

Add a division segment

Args:
division (str): Official name of an electoral division.

Returns:
IdBuilder

Raises:
ValueError


def limit_epochs(tensor, num_epochs=None, name=None):
    if num_epochs is None:
        return tensor
    if num_epochs <= 0:
        raise ValueError('num_epochs must be > 0 not %d.' % num_epochs)
    with ops.name_scope(name, 'limit_epochs', [tensor]) as name:
        zero64 = constant_op.constant(0, dtype=dtypes.int64)
        epochs = variable_v1.VariableV1(zero64, name='epochs', trainable=False, collections=[ops.GraphKeys.LOCAL_VARIABLES])
        counter = epochs.count_up_to(num_epochs)
        with ops.control_dependencies([counter]):
            return array_ops.identity(tensor, name=name)

Returns tensor `num_epochs` times and then raises an `OutOfRange` error.

Note: creates local counter `epochs`. Use `local_variables_initializer()` to
initialize local variables.

Args:
tensor: Any `Tensor`.
num_epochs: A positive integer (optional).  If specified, limits the number
of steps the output tensor may be evaluated.
name: A name for the operations (optional).

Returns:
tensor or `OutOfRange`.

Raises:
ValueError: if `num_epochs` is invalid.


def iter_predict(self, X, include_init=False):
    utils.validation.check_is_fitted(self, 'init_estimator_')
    X = utils.check_array(X, accept_sparse=['csr', 'csc'], dtype=None, force_all_finite=False)
    y_pred = self.init_estimator_.predict(X)
    if include_init:
        (yield y_pred)
    for (estimators, line_searchers, cols) in itertools.zip_longest(self.estimators_, self.line_searchers_, self.columns_):
        for (i, (estimator, line_searcher)) in enumerate(itertools.zip_longest(estimators, (line_searchers or []))):
            if (cols is None):
                direction = estimator.predict(X)
            else:
                direction = estimator.predict(X[(:, cols)])
            if line_searcher:
                direction = line_searcher.update(direction)
            y_pred[(:, i)] += (self.learning_rate * direction)
        (yield y_pred)

Returns the predictions for ``X`` at every stage of the boosting procedure.

Args:
X (array-like or sparse matrix of shape (n_samples, n_features): The input samples.
Sparse matrices are accepted only if they are supported by the weak model.
include_init (bool, default=False): If ``True`` then the prediction from
``init_estimator`` will also be returned.
Returns:
iterator of arrays of shape (n_samples,) containing the predicted values at each stage


def groups_invite(self, *, channel: str, user: str, **kwargs) -> SlackResponse:
    self._validate_xoxp_token()
    kwargs.update({'channel': channel, 'user': user})
    return self.api_call('groups.invite', json=kwargs)

Invites a user to a private channel.

Args:
channel (str): The group id. e.g. 'G1234567890'
user (str): The user id. e.g. 'U1234567890'


def add_timing_signal_1d_given_position(x,
                                        position,
                                        min_timescale=1.0,
                                        max_timescale=1.0e4):

  channels = common_layers.shape_list(x)[2]
  num_timescales = channels
  log_timescale_increment = (
      math.log(float(max_timescale) / float(min_timescale)) /
      (tf.to_float(num_timescales) - 1))
  inv_timescales = min_timescale * tf.exp(
      tf.to_float(tf.range(num_timescales)) * -log_timescale_increment)
  scaled_time = (
      tf.expand_dims(tf.to_float(position), 2) * tf.expand_dims(
          tf.expand_dims(inv_timescales, 0), 0))
  signal = tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=2)
  signal = tf.pad(signal, [[0, 0], [0, 0], [0, tf.mod(channels, 2)]])
  signal = common_layers.cast_like(signal, x)
  return x + signal

Adds sinusoids of diff frequencies to a Tensor, with timing position given.

Args:
x: a Tensor with shape [batch, length, channels]
position: a Tensor with shape [batch, length]
min_timescale: a float
max_timescale: a float

Returns:
a Tensor the same shape as x.


def _get_saver_def_or_none(exported_model: exported_model_pb2.ExportedModel) -> Optional[saver_pb2.SaverDef]:
    if exported_model.HasField('saver_def'):
        return exported_model.saver_def
    return None

Returns the SaverDef from ExportedModel, None otherwise.

Args:
exported_model: ExportedModel to take the SaverDef from.

Returns:
SaverDef instance if the field `saver_def` is set. None otherwise.


def range(self, x_data=None):

        if x_data is None:
            try:
                x_data = evaluation.evaluate_inverse(
                    self, numpy.array([[0.5]]*len(self)))
            except StochasticallyDependentError:
                x_data = approximation.find_interior_point(self)
            shape = (len(self),)
            if hasattr(self, "_range"):
                return self._range(x_data, {})
        else:
            x_data = numpy.asfarray(x_data)
            shape = x_data.shape
            x_data = x_data.reshape(len(self), -1)

        q_data = evaluation.evaluate_bound(self, x_data)
        q_data = q_data.reshape((2,)+shape)
        return q_data

Generate the upper and lower bounds of a distribution.

Args:
x_data (numpy.ndarray) :
The bounds might vary over the sample space. By providing
x_data you can specify where in the space the bound should be
taken.  If omitted, a (pseudo-)random sample is used.

Returns:
(numpy.ndarray):
The lower (out[0]) and upper (out[1]) bound where
out.shape=(2,)+x_data.shape


def _ip_int_from_string(self, ip_str):

        if not ip_str:
            raise AddressValueError('Address cannot be empty')

        octets = ip_str.split('.')
        if len(octets) != 4:
            raise AddressValueError("Expected 4 octets in %r" % ip_str)

        try:
            return _int_from_bytes(map(self._parse_octet, octets), 'big')
        except ValueError as exc:
            raise AddressValueError("%s in %r" % (exc, ip_str))

Turn the given IP string into an integer for comparison.

Args:
ip_str: A string, the IP ip_str.

Returns:
The IP ip_str as an integer.

Raises:
AddressValueError: if ip_str isn't a valid IPv4 Address.


def add_ipdu(self, information, timeout=(- 1)):
    uri = (self.URI + '/discover')
    return self._client.create(information, uri=uri, timeout=timeout)

Add an HP iPDU and bring all components under management by discovery of its management module. Bring the
management module under exclusive management by the appliance, configure any management or data collection
settings, and create a private set of administrative credentials to enable ongoing communication and management
of the iPDU. Use "force" to claim the device, even if claimed by another management appliance

Args:
resource: power device information
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: added power device.


def SetExtractionConfiguration(self, configuration):

    self._hasher_file_size_limit = configuration.hasher_file_size_limit
    self._SetHashers(configuration.hasher_names_string)
    self._process_archives = configuration.process_archives
    self._process_compressed_streams = configuration.process_compressed_streams
    self._SetYaraRules(configuration.yara_rules_string)

Sets the extraction configuration settings.

Args:
configuration (ExtractionConfiguration): extraction configuration.


def __init__(self, xid=None, data=None):

        super().__init__(xid)
        self.data = data

Create an EchoReply with the optional parameters below.

Args:
xid (int): xid to be used on the message header.
data (bytes): arbitrary-length data field.


def get_checklist(self, id, name=None):
    return self.create_checklist(dict(id=id, name=name))

Get a checklist

Returns:
Checklist: The checklist with the given `id`


def warn_logging(logger):

    def showwarning(message, category, filename, lineno, file=None, line=None):
        logger.warning(message)
    return showwarning

Create a `showwarning` function that uses the given logger.

Arguments:
logger (~logging.Logger): the logger to use.

Returns:
function: a function that can be used as the `warnings.showwarning`
callback.


def staged_rewards(self):
    cubeA_pos = self.sim.data.body_xpos[self.cubeA_body_id]
    cubeB_pos = self.sim.data.body_xpos[self.cubeB_body_id]
    gripper_site_pos = self.sim.data.site_xpos[self.eef_site_id]
    dist = np.linalg.norm((gripper_site_pos - cubeA_pos))
    r_reach = ((1 - np.tanh((10.0 * dist))) * 0.25)
    touch_left_finger = False
    touch_right_finger = False
    touch_cubeA_cubeB = False
    for i in range(self.sim.data.ncon):
        c = self.sim.data.contact[i]
        if ((c.geom1 in self.l_finger_geom_ids) and (c.geom2 == self.cubeA_geom_id)):
            touch_left_finger = True
        if ((c.geom1 == self.cubeA_geom_id) and (c.geom2 in self.l_finger_geom_ids)):
            touch_left_finger = True
        if ((c.geom1 in self.r_finger_geom_ids) and (c.geom2 == self.cubeA_geom_id)):
            touch_right_finger = True
        if ((c.geom1 == self.cubeA_geom_id) and (c.geom2 in self.r_finger_geom_ids)):
            touch_right_finger = True
        if ((c.geom1 == self.cubeA_geom_id) and (c.geom2 == self.cubeB_geom_id)):
            touch_cubeA_cubeB = True
        if ((c.geom1 == self.cubeB_geom_id) and (c.geom2 == self.cubeA_geom_id)):
            touch_cubeA_cubeB = True
    if (touch_left_finger and touch_right_finger):
        r_reach += 0.25
    cubeA_height = cubeA_pos[2]
    table_height = self.table_full_size[2]
    cubeA_lifted = (cubeA_height > (table_height + 0.04))
    r_lift = (1.0 if cubeA_lifted else 0.0)
    if cubeA_lifted:
        horiz_dist = np.linalg.norm((np.array(cubeA_pos[:2]) - np.array(cubeB_pos[:2])))
        r_lift += (0.5 * (1 - np.tanh(horiz_dist)))
    r_stack = 0
    not_touching = ((not touch_left_finger) and (not touch_right_finger))
    if (not_touching and (r_lift > 0) and touch_cubeA_cubeB):
        r_stack = 2.0
    return (r_reach, r_lift, r_stack)

Helper function to return staged rewards based on current physical states.

Returns:
r_reach (float): reward for reaching and grasping
r_lift (float): reward for lifting and aligning
r_stack (float): reward for stacking


def do_REMOTE(self, target: str, remote_command: str, source: list, *args, **kwargs) -> None:
    if (target == self.messaging._service_name):
        info = 'target for remote command is the bot itself! Returning the function'
        self.logger.info(info)
        return self._handle_command(remote_command, source, *args, **kwargs)
    try:
        target = self.messaging._address_map[target]
    except KeyError:
        warn = ' Target %s, not found in addresses. Are you sure that %s sent an IDENT message?'
        self.logger.warn(warn, target, target)
        return
    self.logger.info(' REMOTE %s, target: %s | %s, %s', remote_command, target, args, kwargs)
    source = (target + source)
    self.messaging.send_command_response(source, remote_command, *args, **kwargs)

Send a remote command to a service. Used

Args:
target: The service that the command gets set to
remote_command: The command to do remotely.
source: the binary source of the zmq_socket. Packed to send to the


def maybe_set_static_shape(tensor, shape):
    if _ENABLE_MAYBE_SET_STATIC_SHAPE and (not context.executing_eagerly()) and ops.get_default_graph().building_function and (not tensor.shape.is_fully_defined()) and tensor_util.is_tensor(shape):
        shape = shape_tensor(shape)
        const_shape = tensor_util.constant_value_as_shape(shape)
        tensor.set_shape(const_shape)

Sets the shape of `tensor` to the `shape`'s constant value, if inferrable.

This is a temporary workaround to fix shape inference across functional op
boundaries. E.g.

```python
shape = tf.constant([3])
@tf.function
def f():
u = tf.random_uniform(shape)
return u
```

If we were to rely solely on C++ shape inference, the shape of `u` inside
`f` would be unknown because C++ shape inference is not aware of the outer
graph and all it sees is a Placeholder node when backtracing the captured
tensor for `shape`. `maybe_set_static_shape` computes the static shape value
of `shape` by traversing the `FuncGraph` boundaries and sets the correct
shape.

A longer term solution would be to fix C++ shape inference.

Args:
tensor: A tensor.
shape: A shape tensor.


def get_page_artid(self, separator='-'):

        publication_info = get_value(
            self.record,
            'publication_info[0]',
            default={}
        )
        return LiteratureReader.get_page_artid_for_publication_info(
            publication_info,
            separator
        )

Return the page range or the article id of a record.

Args:
separator(basestring): optional page range symbol, defaults to a single dash

Returns:
string: the page range or the article id of the record.

Examples:
>>> record = {
...     'publication_info': [
...         {'artid': '054021'},
...     ],
... }
>>> LiteratureReader(record).get_page_artid()
'054021'


def _get_metrics_result_or_logs(self, logs):
    metric_logs = self.get_metrics_result()
    if isinstance(logs, dict) and set(logs.keys()) == set(metric_logs.keys()):
        return metric_logs
    return logs

Returns model metrics as a dict if the keys match with input logs.

When the training / evaluation is performed with an asynchronous steps,
the last scheduled `train / test_step` may not give the latest metrics
because it is not guaranteed to be executed the last. This method gets
metrics from the model directly instead of relying on the return from
last step function.

When the user has custom train / test step functions, the metrics
returned may be different from `Model.metrics`. In those instances,
this function will be no-op and return the logs passed in.

Args:
logs: A `dict` of metrics returned by train / test step function.

Returns:
A `dict` containing values of the metrics listed in `self.metrics`
when logs and model metrics keys match. Otherwise it returns input
`logs`.


def record_kv_cache_memory_metrics(self, cache) -> None:
    if not _has_opentelemetry:
        return
    try:
        num_used_blocks = cache.num_blocks - len(cache._free_blocks)
        num_layers = len(cache.key_cache)
        bytes_per_parameter = 2 if cache.dtype in [torch.float16, torch.bfloat16] else 4
        memory_bytes = num_layers * num_used_blocks * cache.block_size * cache.num_key_value_heads * cache.head_dim * 2 * bytes_per_parameter
        free_memory_bytes = num_layers * len(cache._free_blocks) * cache.block_size * cache.num_key_value_heads * cache.head_dim * 2 * bytes_per_parameter
        self.kv_cache_memory_gauge.set(memory_bytes)
        self.kv_cache_free_memory_gauge.set(free_memory_bytes)
        logger.debug(f'KV Cache memory: {memory_bytes / (1024 * 1024):.2f}MB, Used blocks: {num_used_blocks}/{cache.num_blocks} ({num_used_blocks / cache.num_blocks * 100:.1f}%)')
    except Exception as e:
        logger.warning(f'Failed to record KV cache memory metrics: {e}')

Record memory usage of the PagedAttentionCache without GPU synchronization.

This calculates the theoretical memory usage based on cache configuration
and the number of blocks currently in use.

Args:
cache: The PagedAttentionCache object to measure


def _checkFunctioncode(functioncode, listOfAllowedValues=[]):
    FUNCTIONCODE_MIN = 1
    FUNCTIONCODE_MAX = 127
    _checkInt(functioncode, FUNCTIONCODE_MIN, FUNCTIONCODE_MAX, description='functioncode')
    if (listOfAllowedValues is None):
        return
    if (not isinstance(listOfAllowedValues, list)):
        raise TypeError('The listOfAllowedValues should be a list. Given: {0!r}'.format(listOfAllowedValues))
    for value in listOfAllowedValues:
        _checkInt(value, FUNCTIONCODE_MIN, FUNCTIONCODE_MAX, description='functioncode inside listOfAllowedValues')
    if (functioncode not in listOfAllowedValues):
        raise ValueError('Wrong function code: {0}, allowed values are {1!r}'.format(functioncode, listOfAllowedValues))

Check that the given functioncode is in the listOfAllowedValues.

Also verifies that 1 <= function code <= 127.

Args:
* functioncode (int): The function code
* listOfAllowedValues (list of int): Allowed values. Use *None* to bypass this part of the checking.

Raises:
TypeError, ValueError


def iterator_cycle(variables: VarType, parent: str) -> Iterable[VarMatrix]:

    if isinstance(variables, dict):
        if variables.get("times"):
            times = int(variables["times"])
            del variables["times"]

            yield list(variable_matrix(variables, parent, "product")) * times

        else:
            raise ValueError(f"times is a required keyword for the repeat iterator.")
    else:
        raise ValueError(
            f"The repeat operator only takes a dict as arguments, got {variables} of type {type(variables)}"
        )

Cycle through a list of values a specified number of times

Args:
variables: The input variables for the creation of the range
parent: The variable for which the values are being generated.

Returns: A list of dictionaries mapping the parent to each value.


def by_name(name):

    devices = discover(all_households=True)
    for device in (devices or []):
        if device.player_name == name:
            return device
    return None

Return a device by name.

Args:
name (str): The name of the device to return.

Returns:
:class:`~.SoCo`: The first device encountered among all zone with the
given player name. If none are found `None` is returned.


def rotate_view(self, axis_ind=0, angle=0):

        camera = self.ren.GetActiveCamera()
        if axis_ind == 0:
            camera.Roll(angle)
        elif axis_ind == 1:
            camera.Azimuth(angle)
        else:
            camera.Pitch(angle)
        self.ren_win.Render()

Rotate the camera view.

Args:
axis_ind: Index of axis to rotate. Defaults to 0, i.e., a-axis.
angle: Angle to rotate by. Defaults to 0.


def _get_shards_by_task(self, sharding_callback: sharding_util.ShardingCallback) -> Sequence[tuple[str, Sequence[sharding_util.Shard]]]:

    def wrap_tensor(shardable_tensor):
        tensor_val = shardable_tensor.tensor
        tensor_shape = shardable_tensor.shape
        save_spec = shardable_tensor._tensor_save_spec
        with ops.device(shardable_tensor.device):
            save_spec_tensor = save_spec.tensor
        if tensor_val is None and save_spec_tensor is None:
            return None
        elif save_spec_tensor is not None:
            tensor_val = save_spec_tensor
            tensor_shape = save_spec_tensor.shape
            if isinstance(save_spec.name, tensor_lib.Tensor):
                tensor_val._wrapped_name = save_spec.name
            if isinstance(shardable_tensor.slice_spec, tensor_lib.Tensor):
                tensor_val._wrapped_slice_spec = save_spec.slice_spec
        return dataclasses.replace(shardable_tensor, tensor=tensor_val, shape=tensor_shape)
    shardable_tensors_by_task = {task: [shardable_tensor for shardable_tensor in map(wrap_tensor, shardable_tensors) if shardable_tensor is not None] for task, shardable_tensors in self._shardable_tensors_by_task.items()}
    sharding_callback = sharding_callback or sharding_policies.ShardByTaskPolicy()
    metrics.SetShardingCallbackDescription(description=sharding_callback.description)
    callback_start_time = time.time() * 1000000.0
    shards_by_task = []
    for task, shardable_tensors in shardable_tensors_by_task.items():
        shards_by_task.append((task, sharding_callback(shardable_tensors)))
    callback_end_time = time.time() * 1000000.0
    callback_duration = math.ceil(callback_end_time - callback_start_time)
    metrics.AddShardingCallbackDuration(callback_duration=max(1, callback_duration))
    logging.info('Sharding callback duration: %s microseconds', callback_duration)
    return shards_by_task

Calls the sharding callback with shardable_tensors.

Args:
sharding_callback: ShardingCallback. The callback function wrapper that
splits shardable_tensors into shards.

Returns:
A list of (task, shards) tuples.


def find_stacks(node, strict=False):
    fso = FindStackOps()
    fso.visit(node)
    AnnotateStacks(fso.push_pop_pairs, strict).visit(node)
    return node

Find pushes and pops to the stack and annotate them as such.

Args:
node: An AST node that might contain stack pushes and pops.
strict: A boolean indicating whether to stringently test whether each
push and pop are matched. This is not always possible when taking
higher-order derivatives of code generated in split-motion.

Returns:
node: The node passed in, but with pushes and pops annotated in AST nodes.


def sg_to_sparse(tensor, opt):
    r
    indices = tf.where(tf.not_equal(tensor.sg_float(), 0.))
    return tf.SparseTensor(indices=indices,
                           values=tf.gather_nd(tensor, indices) - 1,
                           dense_shape=tf.shape(tensor).sg_cast(dtype=tf.int64))

r"""Converts a dense tensor into a sparse tensor.

See `tf.SparseTensor()` in tensorflow.

Args:
tensor: A `Tensor` with zero-padding (automatically given by chain).
opt:
name: If provided, replace current tensor's name.

Returns:
A `SparseTensor`.


def infer_inputs_from_restored_call_function(fn):

    def common_spec(x, y):
        common_shape = get_common_shape(x.shape, y.shape)
        if isinstance(x, sparse_tensor.SparseTensorSpec):
            return sparse_tensor.SparseTensorSpec(common_shape, x.dtype)
        elif isinstance(x, ragged_tensor.RaggedTensorSpec):
            return ragged_tensor.RaggedTensorSpec(common_shape, x.dtype)
        return tensor_spec.TensorSpec(common_shape, x.dtype, x.name)
    spec = fn.concrete_functions[0].structured_input_signature[0][0]
    for concrete in fn.concrete_functions[1:]:
        spec2 = concrete.structured_input_signature[0][0]
        spec = nest.map_structure(common_spec, spec, spec2)
    return spec

Returns TensorSpec of inputs from a restored call function.

Args:
fn: Restored layer call function. It is assumed that `fn` has at least
one concrete function and that the inputs are in the first argument.

Returns:
TensorSpec of call function inputs.


def _Lock(self, path=None, force=False):
    if self.lock is None:
        self.lock = lock.PidFile(filename=path)
    return self.lock.Lock(force=force)

Grab a system-wide lock for this command.

Commands wishing to prevent concurrent operation can invoke this
method to acquire a system-wide lock.  The lock will be
automatically released on object destruction, however an optional
Unlock() method is provided for commands wishing a smaller scope
of locking.

Args:
path: optional path to lock file.
force: optional boolean to override existing locks.
Returns:
True if the lock was acquired.
False if the lock was not.


def ProcessLine(filename, file_extension, clean_lines, line, include_state, function_state, nesting_state, error, extra_check_functions=[]):
    raw_lines = clean_lines.raw_lines
    ParseNolintSuppressions(filename, raw_lines[line], line, error)
    nesting_state.Update(filename, clean_lines, line, error)
    CheckForNamespaceIndentation(filename, nesting_state, clean_lines, line, error)
    if nesting_state.InAsmBlock():
        return
    CheckForFunctionLengths(filename, clean_lines, line, function_state, error)
    CheckForMultilineCommentsAndStrings(filename, clean_lines, line, error)
    CheckStyle(filename, clean_lines, line, file_extension, nesting_state, error)
    CheckLanguage(filename, clean_lines, line, file_extension, include_state, nesting_state, error)
    CheckForNonConstReference(filename, clean_lines, line, nesting_state, error)
    CheckForNonStandardConstructs(filename, clean_lines, line, nesting_state, error)
    CheckVlogArguments(filename, clean_lines, line, error)
    CheckPosixThreading(filename, clean_lines, line, error)
    CheckInvalidIncrement(filename, clean_lines, line, error)
    CheckMakePairUsesDeduction(filename, clean_lines, line, error)
    CheckDefaultLambdaCaptures(filename, clean_lines, line, error)
    CheckRedundantVirtual(filename, clean_lines, line, error)
    CheckRedundantOverrideOrFinal(filename, clean_lines, line, error)
    for check_fn in extra_check_functions:
        check_fn(filename, clean_lines, line, error)

Processes a single line in the file.

Args:
filename: Filename of the file that is being processed.
file_extension: The extension (dot not included) of the file.
clean_lines: An array of strings, each representing a line of the file,
with comments stripped.
line: Number of line being processed.
include_state: An _IncludeState instance in which the headers are inserted.
function_state: A _FunctionState instance which counts function lines, etc.
nesting_state: A NestingState instance which maintains information about
the current stack of nested blocks being parsed.
error: A callable to which errors are reported, which takes 4 arguments:
filename, line number, error level, and message
extra_check_functions: An array of additional check functions that will be
run on each source line. Each function takes 4
arguments: filename, clean_lines, line, error


def _ParsePlistKeyValue(self, knowledge_base, name, value):

    if not knowledge_base.GetValue('operating_system_version'):
      if name in self._PLIST_KEYS:
        knowledge_base.SetValue('operating_system_version', value)

Parses a plist key value.

Args:
knowledge_base (KnowledgeBase): to fill with preprocessing information.
name (str): name of the plist key.
value (str): value of the plist key.


def AddKeywordsForName(self, name, keywords):
    data_store.DB.IndexAddKeywordsForName(self.urn, name, keywords)

Associates keywords with name.

Records that keywords are associated with name.

Args:
name: A name which should be associated with some keywords.
keywords: A collection of keywords to associate with name.


def get_class(schema_name):
    global _registry_loaded
    if (not _registry_loaded):
        load_message_classes()
    try:
        return _schema_name_to_class[schema_name]
    except KeyError:
        _log.warning('The schema "%s" is not in the schema registry! Either install the package with its schema definition or define a schema. Falling back to the default schema...', schema_name)
        return Message

Retrieve the message class associated with the schema name.

If no match is found, the default schema is returned and a warning is logged.

Args:
schema_name (six.text_type): The name of the :class:`Message` sub-class;
this is typically the Python path.

Returns:
Message: A sub-class of :class:`Message` to create the message from.


def _ProcessEvent(self, mediator, event):

    try:
      self._analysis_plugin.ExamineEvent(mediator, event)

    except Exception as exception:
      self.SignalAbort()

      if self._debug_output:
        logger.warning('Unhandled exception while processing event object.')
        logger.exception(exception)

Processes an event.

Args:
mediator (AnalysisMediator): mediates interactions between
analysis plugins and other components, such as storage and dfvfs.
event (EventObject): event.


def convert_to_string(self, productions):

    symbols = []
    for production in tf.unstack(productions, axis=1):
      lhs, rhs = self.production_rules[tf.argmax(input=production, axis=-1)]
      if not symbols:
        if lhs != self.start_symbol:
          raise ValueError("`productions` must begin with `self.start_symbol`.")
        symbols = rhs
      else:

        index = symbols.index(lhs)
        symbols = symbols[:index] + rhs + symbols[index + 1:]
    string = "".join(symbols)
    return string

Converts a sequence of productions into a string of terminal symbols.

Args:
productions: Tensor of shape [1, num_productions, num_production_rules].
Slices along the `num_productions` dimension represent one-hot vectors.

Returns:
str that concatenates all terminal symbols from `productions`.

Raises:
ValueError: If the first production rule does not begin with
`self.start_symbol`.


def Page(self, text=None, show_percent=None):
    if (text is not None):
        self._text += text
    if (show_percent is None):
        show_percent = (text is None)
    self._show_percent = show_percent
    text = LineWrap(self._text).splitlines()
    while True:
        self._newlines = text[self._displayed:(self._displayed + self._lines_to_show)]
        for line in self._newlines:
            sys.stdout.write((line + '\n'))
            if (self._delay and (self._lastscroll > 0)):
                time.sleep(0.005)
        self._displayed += len(self._newlines)
        self._currentpagelines += len(self._newlines)
        if (self._currentpagelines >= self._lines_to_show):
            self._currentpagelines = 0
            wish = self._AskUser()
            if (wish == 'q'):
                return False
            elif (wish == 'g'):
                self._Scroll(((len(text) - self._displayed) + 1))
            elif (wish == '\r'):
                self._Scroll(1)
            elif (wish == '\x1b[B'):
                self._Scroll(1)
            elif (wish == '\x1b[A'):
                self._Scroll((- 1))
            elif (wish == 'b'):
                self._Scroll((0 - self._cli_lines))
            else:
                self._Scroll()
        if (self._displayed >= len(text)):
            break
    return True

Page text.

Continues to page through any text supplied in the constructor. Also, any
text supplied to this method will be appended to the total text to be
displayed. The method returns when all available text has been displayed to
the user, or the user quits the pager.

Args:
text: A string, extra text to be paged.
show_percent: A boolean, if True, indicate how much is displayed so far.
If None, this behaviour is 'text is None'.

Returns:
A boolean. If True, more data can be displayed to the user. False
implies that the user has quit the pager.


def _CreateRoutesFolder(self, schedule, doc, route_type=None):

    def GetRouteName(route):
        'Return a placemark name for the route.\n\n      Args:\n        route: The transitfeed.Route instance.\n\n      Returns:\n        The name as a string.\n      '
        name_parts = []
        if route.route_short_name:
            name_parts.append(('%s' % route.route_short_name))
        if route.route_long_name:
            name_parts.append(route.route_long_name)
        return (' - '.join(name_parts) or route.route_id)

    def GetRouteDescription(route):
        'Return a placemark description for the route.\n\n      Args:\n        route: The transitfeed.Route instance.\n\n      Returns:\n        The description as a string.\n      '
        desc_items = []
        if route.route_desc:
            desc_items.append(route.route_desc)
        if route.route_url:
            desc_items.append(('Route info page: %s' % (route.route_url, route.route_url)))
        description = '
'.join(desc_items)
        return (description or None)
    routes = [route for route in schedule.GetRouteList() if ((route_type is None) or (route.route_type == route_type))]
    if (not routes):
        return None
    routes.sort(key=(lambda x: GetRouteName(x)))
    if (route_type is not None):
        route_type_names = {0: 'Tram, Streetcar or Light rail', 1: 'Subway or Metro', 2: 'Rail', 3: 'Bus', 4: 'Ferry', 5: 'Cable car', 6: 'Gondola or suspended cable car', 7: 'Funicular'}
        type_name = route_type_names.get(route_type, str(route_type))
        folder_name = ('Routes - %s' % type_name)
    else:
        folder_name = 'Routes'
    routes_folder = self._CreateFolder(doc, folder_name, visible=False)
    for route in routes:
        style_id = self._CreateStyleForRoute(doc, route)
        route_folder = self._CreateFolder(routes_folder, GetRouteName(route), description=GetRouteDescription(route))
        self._CreateRouteShapesFolder(schedule, route_folder, route, style_id, False)
        self._CreateRoutePatternsFolder(route_folder, route, style_id, False)
        if self.show_trips:
            self._CreateRouteTripsFolder(route_folder, route, style_id, schedule)
    return routes_folder

Create a KML Folder containing routes in a schedule.

The folder contains a subfolder for each route in the schedule of type
route_type. If route_type is None, then all routes are selected. Each
subfolder contains a flattened graph placemark, a route shapes placemark
and, if show_trips is True, a subfolder containing placemarks for each of
the trips in the route.

If there are no routes in the schedule then no folder is created and None
is returned.

Args:
schedule: The transitfeed.Schedule instance.
doc: The KML Document ElementTree.Element instance.
route_type: The route type integer or None.

Returns:
The Folder ElementTree.Element instance or None.


def sequence_path(self, fasta_path):

        if not fasta_path:
            self.sequence_dir = None
            self.sequence_file = None

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

            if not op.dirname(fasta_path):
                self.sequence_dir = '.'
            else:
                self.sequence_dir = op.dirname(fasta_path)
            self.sequence_file = op.basename(fasta_path)

            tmp_sr = SeqIO.read(fasta_path, 'fasta')
            if self.name == '<unknown name>':
                self.name = tmp_sr.name
            if self.description == '<unknown description>':
                self.description = tmp_sr.description
            if not self.dbxrefs:
                self.dbxrefs = tmp_sr.dbxrefs
            if not self.features:
                self.features = tmp_sr.features
            if not self.annotations:
                self.annotations = tmp_sr.annotations
            if not self.letter_annotations:
                self.letter_annotations = tmp_sr.letter_annotations

Provide pointers to the paths of the FASTA file

Args:
fasta_path: Path to FASTA file


def explicit_method_override(method):
    setattr(method, '__explicit_override__', True)
    return method

Decorator that marks a member method as explicitly overridden.

In PyGlove, many methods are managed by the framework - for example -
``pg.Object.__init__``. It's easy for users to override these methods
unconsciously. Therefore, we introduce this decorator to catch error at
the first place when such overrides incidentally take place, while allowing
advanced users to override them.

Usage::

class Foo(pg.Object):

@pg.explicit_method_override
def __init__(self, *args, **kwargs):
...

Args:
method: method to explicitly overriden.

Returns:
The original method with an explicit overriden stamp.


def document(self, name, file_name, **kwargs):
    group_obj = Document(name, file_name, **kwargs)
    return self._group(group_obj)

Add Document data to Batch object.

Args:
name (str): The name for this Group.
file_name (str): The name for the attached file for this Group.
date_added (str, kwargs): The date timestamp the Indicator was created.
file_content (str;method, kwargs): The file contents or callback method to retrieve
file content.
malware (bool, kwargs): If true the file is considered malware.
password (bool, kwargs): If malware is true a password for the zip archive is
xid (str, kwargs): The external id for this Group.

Returns:
obj: An instance of Document.


def rhombohedral(a: float, alpha: float):

        return Lattice.from_parameters(a, a, a, alpha, alpha, alpha)

Convenience constructor for a rhombohedral lattice.

Args:
a (float): *a* lattice parameter of the rhombohedral cell.
alpha (float): Angle for the rhombohedral lattice in degrees.

Returns:
Rhombohedral lattice of dimensions a x a x a.


def setupSerialPort(loopback, port):

    if loopback:

        testSerial = SerialTestClass()
        serialPort = testSerial.serialPort
    else:

        serialPort = serial.Serial(port, 115200, timeout=0)

    return serialPort

Sets up serial port by connecting to phsyical or software port.

Depending on command line options, this function will either connect to a
SerialTestClass() port for loopback testing or to the specified port from
the command line option. If loopback is True it overrides the physical port
specification.

Args:
loopback: argparse option
port: argparse option

Returns:
serialPort: Pyserial serial port instance


def fit(self, volumes, energies):
    eos_fit = self.model(np.array(volumes), np.array(energies))
    eos_fit.fit()
    return eos_fit

Fit energies as function of volumes.

Args:
volumes (list/np.array)
energies (list/np.array)

Returns:
EOSBase: EOSBase object


def _ModifyInterface(
      self, interface_config, config_key, config_value, replace=False):

    config_entry = '%s=%s' % (config_key, config_value)
    if not open(interface_config).read().count(config_key):
      with open(interface_config, 'a') as config:
        config.write('%s\n' % config_entry)
    elif replace:
      for line in fileinput.input(interface_config, inplace=True):
        print(re.sub(r'%s=.*' % config_key, config_entry, line.rstrip()))

Write a value to a config file if not already present.

Args:
interface_config: string, the path to a config file.
config_key: string, the configuration key to set.
config_value: string, the value to set for the configuration key.
replace: bool, replace the configuration option if already present.


def square(duration: int, amp: complex, period: float = None,
           phase: float = 0, name: str = None) -> SamplePulse:

    if period is None:
        period = duration

    return _sampled_square_pulse(duration, amp, period, phase=phase, name=name)

Generates square wave `SamplePulse`.

Applies `left` sampling strategy to generate discrete pulse from continuous function.

Args:
duration: Duration of pulse. Must be greater than zero.
amp: Pulse amplitude. Wave range is [-amp, amp].
period: Pulse period, units of dt. If `None` defaults to single cycle.
phase: Pulse phase.
name: Name of pulse.


def scalar_projection(v1, v2):
    return (np.dot(v1, v2) / np.linalg.norm(v2))

compute the scalar projection of v1 upon v2

Args:
v1, v2: iterable
indices 0, 1, 2 corresponding to cartesian coordinates

Returns:
3-vector of the projection of point p onto the direction of v


class CustomHFIndex(HFIndexBase):

    def __init__(self, vector_size: int, dataset, index_path=None):
        requires_backends(self, ['faiss'])
        super().__init__(vector_size, dataset, index_initialized=index_path is None)
        self.index_path = index_path

    @classmethod
    def load_from_disk(cls, vector_size, dataset_path, index_path):
        logger.info(f'Loading passages from {dataset_path}')
        if dataset_path is None or index_path is None:
            raise ValueError("Please provide `dataset_path` and `index_path` after calling `dataset.save_to_disk(dataset_path)` and `dataset.get_index('embeddings').save(index_path)`.")
        dataset = load_from_disk(dataset_path)
        return cls(vector_size=vector_size, dataset=dataset, index_path=index_path)

    def init_index(self):
        if not self.is_initialized():
            logger.info(f'Loading index from {self.index_path}')
            self.dataset.load_faiss_index('embeddings', file=self.index_path)
            self._index_initialized = True

A wrapper around an instance of [`~datasets.Datasets`]. The dataset and the index are both loaded from the
indicated paths on disk.

Args:
vector_size (`int`): the dimension of the passages embeddings used by the index
dataset_path (`str`):
The path to the serialized dataset on disk. The dataset should have 3 columns: title (str), text (str) and
embeddings (arrays of dimension vector_size)
index_path (`str`)
The path to the serialized faiss index on disk.


def score(self, data, metric='accuracy', break_ties='random', verbose=True, print_confusion_matrix=True, **kwargs):
    (Y_p, Y, Y_s) = self._get_predictions(data, break_ties=break_ties, return_probs=True, **kwargs)
    return_list = isinstance(metric, list)
    metric_list = (metric if isinstance(metric, list) else [metric])
    scores = []
    for metric in metric_list:
        score = metric_score(Y, Y_p, metric, probs=Y_s, ignore_in_gold=[0])
        scores.append(score)
        if verbose:
            print(f'{metric.capitalize()}: {score:.3f}')
    if (print_confusion_matrix and verbose):
        confusion_matrix(Y, Y_p, pretty_print=True)
    if ((len(scores) == 1) and (not return_list)):
        return scores[0]
    else:
        return scores

Scores the predictive performance of the Classifier on all tasks

Args:
data: a Pytorch DataLoader, Dataset, or tuple with Tensors (X,Y):
X: The input for the predict method
Y: An [n] or [n, 1] torch.Tensor or np.ndarray of target labels
in {1,...,k}
metric: A metric (string) with which to score performance or a
list of such metrics
break_ties: A tie-breaking policy (see Classifier._break_ties())
verbose: The verbosity for just this score method; it will not
update the class config.
print_confusion_matrix: Print confusion matrix (overwritten to False if
verbose=False)

Returns:
scores: A (float) score or a list of such scores if kwarg metric
is a list


def add_comment(self, comment):
    if (not comment):
        return
    self.__comments[comment.name] = comment
    self.comment_added_signal(self, comment)

Add a comment to the database.

Args:
comment (hotdoc.core.Comment): comment to add


def from_callable(cls, fn: Callable) -> Optional['IOTypeHints']:
    if _disable_from_callable or getattr(fn, '_beam_no_annotations', False):
        return None
    signature = get_signature(fn)
    if all((param.annotation == param.empty for param in signature.parameters.values())) and signature.return_annotation == signature.empty:
        return None
    input_args = []
    input_kwargs = {}
    for param in signature.parameters.values():
        if param.annotation == param.empty:
            if param.kind == param.VAR_POSITIONAL:
                input_args.append(_ANY_VAR_POSITIONAL)
            elif param.kind == param.VAR_KEYWORD:
                input_kwargs[param.name] = _ANY_VAR_KEYWORD
            elif param.kind == param.KEYWORD_ONLY:
                input_kwargs[param.name] = typehints.Any
            else:
                input_args.append(typehints.Any)
        elif param.kind in [param.KEYWORD_ONLY, param.VAR_KEYWORD]:
            input_kwargs[param.name] = convert_to_beam_type(param.annotation)
        else:
            assert param.kind in [param.POSITIONAL_ONLY, param.POSITIONAL_OR_KEYWORD, param.VAR_POSITIONAL], 'Unsupported Parameter kind: %s' % param.kind
            input_args.append(convert_to_beam_type(param.annotation))
    output_args = []
    if signature.return_annotation != signature.empty:
        output_args.append(convert_to_beam_type(signature.return_annotation))
    else:
        output_args.append(typehints.Any)
    name = getattr(fn, '__name__', '<unknown>')
    msg = ['from_callable(%s)' % name, '  signature: %s' % signature]
    if hasattr(fn, '__code__'):
        msg.append('  File "%s", line %d' % (fn.__code__.co_filename, fn.__code__.co_firstlineno))
    return IOTypeHints(input_types=(tuple(input_args), input_kwargs), output_types=(tuple(output_args), {}), origin=cls._make_origin([], tb=False, msg=msg))

Construct an IOTypeHints object from a callable's signature.

Supports Python 3 annotations. For partial annotations, sets unknown types
to Any, _ANY_VAR_POSITIONAL, or _ANY_VAR_KEYWORD.

Returns:
A new IOTypeHints or None if no annotations found.


def del_hparam(self, name):

    if hasattr(self, name):
      delattr(self, name)
      del self._hparam_types[name]

Removes the hyperparameter with key 'name'.

Does nothing if it isn't present.

Args:
name: Name of the hyperparameter.


def create_magic_packet(macaddress):

    if len(macaddress) == 12:
        pass
    elif len(macaddress) == 17:
        sep = macaddress[2]
        macaddress = macaddress.replace(sep, '')
    else:
        raise ValueError('Incorrect MAC address format')

    data = b'FFFFFFFFFFFF' + (macaddress * 16).encode()
    send_data = b''

    for i in range(0, len(data), 2):
        send_data += struct.pack(b'B', int(data[i: i + 2], 16))
    return send_data

Create a magic packet.

A magic packet is a packet that can be used with the for wake on lan
protocol to wake up a computer. The packet is constructed from the
mac address given as a parameter.

Args:
macaddress (str): the mac address that should be parsed into a
magic packet.


def trim_whitespace(self, text):

        lines = text.split('\n')
        new_lines = [x.lstrip() for x in lines]

        return '\n'.join(new_lines)

Remove leading whitespace from each line of a multiline string

Args:
text (string): The text to be unindented

Returns:
string: The unindented block of text


def MakeJoint(pmf1, pmf2):
    joint = Joint()
    for (v1, p1) in pmf1.Items():
        for (v2, p2) in pmf2.Items():
            joint.Set((v1, v2), (p1 * p2))
    return joint

Joint distribution of values from pmf1 and pmf2.

Args:
pmf1: Pmf object
pmf2: Pmf object

Returns:
Joint pmf of value pairs


def get_snpeff_info(snpeff_string, snpeff_header):

    snpeff_annotations = [
        dict(zip(snpeff_header, snpeff_annotation.split('|')))
        for snpeff_annotation in snpeff_string.split(',')
    ]

    return snpeff_annotations

Make the vep annotations into a dictionaries

A snpeff dictionary will have the snpeff column names as keys and
the vep annotations as values.
The dictionaries are stored in a list.
One dictionary for each transcript.

Args:
snpeff_string (string): A string with the ANN annotation
snpeff_header (list): A list with the vep header

Return:
snpeff_annotations (list): A list of vep dicts


def get_default_settings(sub_scripts, script_order, script_execution_freq, iterator_type):

    def populate_sweep_param(scripts, parameter_list, trace=''):
        "\n\n            Args:\n                scripts: a dict of {'class name': <class object>} pairs\n\n            Returns: A list of all parameters of the input scripts\n\n            "

        def get_parameter_from_dict(trace, dic, parameter_list, valid_values=None):
            '\n                appends keys in the dict to a list in the form trace.key.subkey.subsubkey...\n                Args:\n                    trace: initial prefix (path through scripts and parameters to current location)\n                    dic: dictionary\n                    parameter_list: list to which append the parameters\n\n                    valid_values: valid values of dictionary values if None dic should be a dictionary\n\n                Returns:\n\n                '
            if ((valid_values is None) and isinstance(dic, Parameter)):
                valid_values = dic.valid_values
            for (key, value) in dic.items():
                if isinstance(value, dict):
                    parameter_list = get_parameter_from_dict(((trace + '.') + key), value, parameter_list, dic.valid_values[key])
                elif ((valid_values[key] in (float, int)) or (isinstance(valid_values[key], list) and (valid_values[key][0] in (float, int)))):
                    parameter_list.append(((trace + '.') + key))
                else:
                    print(('ignoring sweep parameter', key))
            return parameter_list
        for script_name in list(scripts.keys()):
            from pylabcontrol.core import ScriptIterator
            script_trace = trace
            if (script_trace == ''):
                script_trace = script_name
            else:
                script_trace = ((script_trace + '->') + script_name)
            if issubclass(scripts[script_name], ScriptIterator):
                populate_sweep_param(vars(scripts[script_name])['_SCRIPTS'], parameter_list=parameter_list, trace=script_trace)
            else:
                for setting in [elem[1] for elem in inspect.getmembers(scripts[script_name]) if (elem[0] == '_DEFAULT_SETTINGS')][0]:
                    parameter_list = get_parameter_from_dict(script_trace, setting, parameter_list)
        return parameter_list
    if (iterator_type == 'loop'):
        script_default_settings = [Parameter('script_order', script_order), Parameter('script_execution_freq', script_execution_freq), Parameter('num_loops', 0, int, 'times the subscripts will be executed'), Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass')]
    elif (iterator_type == 'sweep'):
        sweep_params = populate_sweep_param(sub_scripts, [])
        script_default_settings = [Parameter('script_order', script_order), Parameter('script_execution_freq', script_execution_freq), Parameter('sweep_param', sweep_params[0], sweep_params, 'variable over which to sweep'), Parameter('sweep_range', [Parameter('min_value', 0, float, 'min parameter value'), Parameter('max_value', 0, float, 'max parameter value'), Parameter('N/value_step', 0, float, 'either number of steps or parameter value step, depending on mode')]), Parameter('stepping_mode', 'N', ['N', 'value_step'], 'Switch between number of steps and step amount'), Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass')]
    else:
        print(('unknown iterator type ' + iterator_type))
        raise TypeError(('unknown iterator type ' + iterator_type))
    return script_default_settings

assigning the actual script settings depending on the iterator type

this might be overwritten by classes that inherit form ScriptIterator

Args:
sub_scripts: dictionary with the subscripts
script_order: execution order of subscripts
script_execution_freq: execution frequency of subscripts

Returns:
the default setting for the iterator


def get_ituz(self, callsign, timestamp=timestamp_now):

        return self.get_all(callsign, timestamp)[const.ITUZ]

Returns ITU Zone of a callsign

Args:
callsign (str): Amateur Radio callsign
timestamp (datetime, optional): datetime in UTC (tzinfo=pytz.UTC)

Returns:
int: containing the callsign's CQ Zone

Raises:
KeyError: No ITU Zone found for callsign

Note:
Currently, only Country-files.com lookup database contains ITU Zones


def plot_hall_carriers(self, temp=300):
    import matplotlib.pyplot as plt
    hall_carriers = [abs(i) for i in self._bz.get_hall_carrier_concentration()[temp]]
    plt.semilogy(self._bz.mu_steps, hall_carriers, linewidth=3.0, color='r')
    self._plot_bg_limits()
    self._plot_doping(temp)
    plt.xlim((- 0.5), (self._bz.gap + 0.5))
    plt.ylim(100000000000000.0, 1e+22)
    plt.ylabel('Hall carrier concentration (cm-3)', fontsize=30.0)
    plt.xlabel('E-E$_f$ (eV)', fontsize=30)
    plt.xticks(fontsize=25)
    plt.yticks(fontsize=25)
    return plt

Plot the Hall carrier concentration in function of Fermi level

Args:
temp: the temperature

Returns:
a matplotlib object


def get_sources(self, prefix=''):

        prefix = prefix.replace('-', '_')
        prefixed = '%s_sources' % prefix

        if prefixed in self.__cli:
            sources = self.__cli.get(prefixed)
            from_conf = False
        else:
            sources = self.__config.get(prefixed)
            from_conf = True

        if sources is None:
            return OrderedSet()

        sources = self.__resolve_patterns(sources, from_conf)

        prefixed = '%s_source_filters' % prefix
        if prefixed in self.__cli:
            filters = self.__cli.get(prefixed)
            from_conf = False
        else:
            filters = self.__config.get(prefixed)
            from_conf = True

        if filters is None:
            return sources

        sources -= self.__resolve_patterns(filters, from_conf)

        return sources

Retrieve a set of absolute paths to sources, according to `prefix`

`ConfigParser` will perform wildcard expansion and
filtering.

Args:
prefix: str, the desired prefix.

Returns:
utils.utils.OrderedSet: The set of sources for the given
`prefix`.


def get_memory_growth(device):
    return context.context().get_memory_growth(device)

Get if memory growth is enabled for a `PhysicalDevice`.

If memory growth is enabled for a `PhysicalDevice`, the runtime initialization
will not allocate all memory on the device.

For example:

>>> physical_devices = tf.config.list_physical_devices('GPU')
>>> try:
...   tf.config.experimental.set_memory_growth(physical_devices[0], True)
...   assert tf.config.experimental.get_memory_growth(physical_devices[0])
... except:
...   # Invalid device or cannot modify virtual devices once initialized.
...   pass

Args:
device: `PhysicalDevice` to query

Returns:
A boolean indicating the memory growth setting for the `PhysicalDevice`.

Raises:
ValueError: Invalid `PhysicalDevice` specified.


def seek_to_end(self, *partitions):
    if (not all([isinstance(p, TopicPartition) for p in partitions])):
        raise TypeError('partitions must be TopicPartition namedtuples')
    if (not partitions):
        partitions = self._subscription.assigned_partitions()
        assert partitions, 'No partitions are currently assigned'
    else:
        for p in partitions:
            assert (p in self._subscription.assigned_partitions()), 'Unassigned partition'
    for tp in partitions:
        log.debug('Seeking to end of partition %s', tp)
        self._subscription.need_offset_reset(tp, OffsetResetStrategy.LATEST)

Seek to the most recent available offset for partitions.

Arguments:
*partitions: Optionally provide specific TopicPartitions, otherwise
default to all assigned partitions.

Raises:
AssertionError: If any partition is not currently assigned, or if
no partitions are assigned.


def _get_shoulds(options):

    if options.version == '2.0':
        return shoulds20.list_shoulds(options)
    else:
        return shoulds21.list_shoulds(options)

Return the list of 'SHOULD' validators for the correct version of STIX.

Args:
options: ValidationOptions instance with validation options for this
validation run, including the STIX spec version.


def __init__(
            self,
            input_columns: t.List[Column],
            output_columns: t.List[Column],
            column_transform,) -> None:

        self.input_columns = input_columns
        self.output_columns = output_columns
        self.column_transform = column_transform

Construct a new ``CompoundColumn`` object.

Args:
input_columns (list, Column): A list of ``Column`` objects representing column(s) from the SOURCE table.
output_columns (list, Column): A list of ``Column`` objects representing column(s) from the FINAL table.
column_transform (Callable): Function accepting the table object, performing transformations to it and returning a DataFrame containing the NEW columns only.


def imfrombytes(content, flag='color'):
    img_np = np.frombuffer(content, np.uint8)
    flag = (imread_flags[flag] if is_str(flag) else flag)
    img = cv2.imdecode(img_np, flag)
    return img

Read an image from bytes.

Args:
content (bytes): Image bytes got from files or other streams.
flag (str): Same as :func:`imread`.

Returns:
ndarray: Loaded image array.


def orth_chol(order, dist, normed=True, sort='GR', cross_truncation=1.0, **kws):
    dim = len(dist)
    basis = chaospy.poly.basis(start=1, stop=order, dim=dim, sort=sort, cross_truncation=cross_truncation)
    length = len(basis)
    cholmat = chaospy.chol.gill_king(chaospy.descriptives.Cov(basis, dist))
    cholmat_inv = numpy.linalg.inv(cholmat.T).T
    if (not normed):
        diag_mesh = numpy.repeat(numpy.diag(cholmat_inv), len(cholmat_inv))
        cholmat_inv /= diag_mesh.reshape(cholmat_inv.shape)
    coefs = numpy.empty(((length + 1), (length + 1)))
    coefs[(1:, 1:)] = cholmat_inv
    coefs[(0, 0)] = 1
    coefs[(0, 1:)] = 0
    expected = (- numpy.sum((cholmat_inv * chaospy.descriptives.E(basis, dist, **kws)), (- 1)))
    coefs[(1:, 0)] = expected
    coefs = coefs.T
    out = {}
    out[((0,) * dim)] = coefs[0]
    for idx in range(length):
        index = basis[idx].keys[0]
        out[index] = coefs[(idx + 1)]
    polynomials = chaospy.poly.Poly(out, dim, coefs.shape[1:], float)
    return polynomials

Create orthogonal polynomial expansion from Cholesky decomposition.

Args:
order (int):
Order of polynomial expansion
dist (Dist):
Distribution space where polynomials are orthogonal
normed (bool):
If True orthonormal polynomials will be used instead of monic.
sort (str):
Ordering argument passed to poly.basis.  If custom basis is used,
argument is ignored.
cross_truncation (float):
Use hyperbolic cross truncation scheme to reduce the number of
terms in expansion.

Examples:
>>> Z = chaospy.Normal()
>>> print(chaospy.around(chaospy.orth_chol(3, Z), 4))
[1.0, q0, 0.7071q0^2-0.7071, 0.4082q0^3-1.2247q0]


def as_dict(self):
    return {'@module': self.__class__.__module__, '@class': self.__class__.__name__, 'r': jsanitize(self.r), 'energies': jsanitize(self.energies), 'forces': jsanitize(self.forces), 'structures': [s.as_dict() for s in self.structures]}

Dict representation of NEBAnalysis.

Returns:
JSON serializable dict representation.


def ConvertStringToFilename(name):
    return re.sub('\\W', (lambda x: ('%%%02X' % ord(x.group(0)))), name, flags=re.UNICODE).rstrip('/')

Converts an unicode string to a filesystem safe filename.

For maximum compatibility we escape all chars which are not alphanumeric (in
the unicode sense).

Args:
name: a unicode string that is part of a subject.

Returns:
A safe filename with escaped special chars.


def __init__(self, config_files, use_tc=None, **kwargs):

        super(VIIRSSDRReader, self).__init__(config_files, **kwargs)
        self.use_tc = use_tc

Initialize file reader and adjust geolocation preferences.

Args:
config_files (iterable): yaml config files passed to base class
use_tc (boolean): If `True` use the terrain corrected
files. If `False`, switch to non-TC files. If
`None` (default), use TC if available, non-TC otherwise.


def delete(filething):

    f = FLAC(filething)
    filething.fileobj.seek(0)
    f.delete(filething)

Remove tags from a file.

Args:
filething (filething)
Raises:
mutagen.MutagenError


def __init__(self, config: Dict[str, str], default_level: str):

        self._should_log: Dict[Tuple[str, str], bool] = {}

        self._default_level = config.get('', default_level)
        self._log_rules = [
            (logger.split('.') if logger else list(), level)
            for logger, level in config.items()
        ]

Initializes a new `LogFilter`

Args:
config: Dictionary mapping module names to logging level
default_level: The default logging level


def make_json_formatted_for_single_chart(mutant_features, inference_result_proto, index_to_mutate):
    x_label = 'step'
    y_label = 'scalar'
    if isinstance(inference_result_proto, classification_pb2.ClassificationResponse):
        series = {}
        for (idx, classification) in enumerate(inference_result_proto.result.classifications):
            mutant_feature = mutant_features[(idx % len(mutant_features))]
            for (class_index, classification_class) in enumerate(classification.classes):
                if (classification_class.label == ''):
                    classification_class.label = str(class_index)
                if ((len(classification.classes) == 2) and (classification_class.label == '0')):
                    continue
                key = classification_class.label
                if index_to_mutate:
                    key += (' (index %d)' % index_to_mutate)
                if (not (key in series)):
                    series[key] = {}
                if (not (mutant_feature.mutant_value in series[key])):
                    series[key][mutant_feature.mutant_value] = []
                series[key][mutant_feature.mutant_value].append(classification_class.score)
        return_series = collections.defaultdict(list)
        for (key, mutant_values) in iteritems(series):
            for (value, y_list) in iteritems(mutant_values):
                return_series[key].append({x_label: value, y_label: (sum(y_list) / float(len(y_list)))})
            return_series[key].sort(key=(lambda p: p[x_label]))
        return return_series
    elif isinstance(inference_result_proto, regression_pb2.RegressionResponse):
        points = {}
        for (idx, regression) in enumerate(inference_result_proto.result.regressions):
            mutant_feature = mutant_features[(idx % len(mutant_features))]
            if (not (mutant_feature.mutant_value in points)):
                points[mutant_feature.mutant_value] = []
            points[mutant_feature.mutant_value].append(regression.value)
        key = 'value'
        if (index_to_mutate != 0):
            key += (' (index %d)' % index_to_mutate)
        list_of_points = []
        for (value, y_list) in iteritems(points):
            list_of_points.append({x_label: value, y_label: (sum(y_list) / float(len(y_list)))})
        list_of_points.sort(key=(lambda p: p[x_label]))
        return {key: list_of_points}
    else:
        raise NotImplementedError('Only classification and regression implemented.')

Returns JSON formatted for a single mutant chart.

Args:
mutant_features: An iterable of `MutantFeatureValue`s representing the
X-axis.
inference_result_proto: A ClassificationResponse or RegressionResponse
returned by Servo, representing the Y-axis.
It contains one 'classification' or 'regression' for every Example that
was sent for inference. The length of that field should be the same length
of mutant_features.
index_to_mutate: The index of the feature being mutated for this chart.

Returns:
A JSON-able dict for rendering a single mutant chart, parseable by
`vz-line-chart` or `vz-bar-chart`.


def decode(obj, content_type):

    try:
        decoder = _decoders_map[content_type]
        return decoder(obj)
    except KeyError:
        raise _errors.UnsupportedFormatError(content_type)

Decode an object ton a one of the default content types to a numpy array.

Args:
obj (object): to be decoded.
content_type (str): content type to be used.

Returns:
np.array: decoded object.