def _reset_offset(self, partition):
    timestamp = self._subscriptions.assignment[partition].reset_strategy
    if (timestamp is OffsetResetStrategy.EARLIEST):
        strategy = 'earliest'
    elif (timestamp is OffsetResetStrategy.LATEST):
        strategy = 'latest'
    else:
        raise NoOffsetForPartitionError(partition)
    log.debug('Resetting offset for partition %s to %s offset.', partition, strategy)
    offsets = self._retrieve_offsets({partition: timestamp})
    if (partition not in offsets):
        raise NoOffsetForPartitionError(partition)
    offset = offsets[partition][0]
    if self._subscriptions.is_assigned(partition):
        self._subscriptions.seek(partition, offset)

Reset offsets for the given partition using the offset reset strategy.

Arguments:
partition (TopicPartition): the partition that needs reset offset

Raises:
NoOffsetForPartitionError: if no offset reset strategy is defined


def get_highest_values(self, count):
    count = int(count)
    assert (count <= len(self._values)), 'count must be smaller than or equal to values length. {} > {}.'.format(count, len(self._values))
    assert (count > 0), 'count must be greater than 0. Got {}.'.format(count)
    highest_values = sorted(self._values, reverse=True)[0:count]
    highest_values_index = sorted(list(xrange(len(self._values))), key=(lambda k: self._values[k]), reverse=True)[0:count]
    return (highest_values, highest_values_index)

Get a list of the the x highest values of the Data Collection and their indices.

This is useful for situations where one needs to know the times of
the year when the largest values of a data collection occur.  For example,
there is a European dayight code that requires an analysis for the hours
of the year with the greatest exterior illuminance level.  This method
can be used to help build a shcedule for such a study.

Args:
count: Integer representing the number of highest values to account for.

Returns:
highest_values: The n highest values in data list, ordered from
highest to lowest.
highest_values_index: Indicies of the n highest values in data
list, ordered from highest to lowest.


def _validate_testbed_configs(testbed_configs):
    seen_names = set()
    for config in testbed_configs:
        name = config[keys.Config.key_testbed_name.value]
        _validate_testbed_name(name)
        if name in seen_names:
            raise MoblyConfigError('Duplicate testbed name %s found.' % name)
        seen_names.add(name)

Validates the testbed configurations.

Args:
testbed_configs: A list of testbed configuration dicts.

Raises:
MoblyConfigError: Some parts of the configuration is invalid.


def _WriteTimestamp(self, timestamp, filename):
    try:
        os.makedirs(self.timestamp_dir)
    except OSError as e:
        if e.errno == errno.EEXIST and os.path.isdir(self.timestamp_dir):
            pass
        else:
            raise
    filedesc, temp_filename = tempfile.mkstemp(prefix='nsscache-update-', dir=self.timestamp_dir)
    time_string = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(timestamp))
    try:
        os.write(filedesc, b'%s\n' % time_string.encode())
        os.fsync(filedesc)
        os.close(filedesc)
    except OSError:
        os.unlink(temp_filename)
        self.log.warning('writing timestamp failed!')
        return False
    os.chmod(temp_filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
    os.rename(temp_filename, filename)
    self.log.debug('wrote timestamp %s to file %r', time_string, filename)
    return True

Write a given timestamp out to a file, converting to the ISO-8601
format.

We convert internal timestamp format (epoch) to ISO-8601 format, i.e.
YYYY-MM-DDThh:mm:ssZ which is basically UTC time, then write it out to a
file.

Args:
timestamp: A String in nss_cache internal timestamp format, aka time_t.
filename: A String naming the file to write to.

Returns:
A boolean indicating success of write.


def human_timestamp(__timestamp: datetime.datetime) -> str:
    numstr = '. a two three four five six seven eight nine ten'.split()
    matches = [(((60 * 60) * 24) * 365), (((60 * 60) * 24) * 28), (((60 * 60) * 24) * 7), ((60 * 60) * 24), (60 * 60), 60, 1]
    match_names = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second']
    if (__timestamp.tzinfo is None):
        __timestamp = __timestamp.replace(tzinfo=datetime.timezone.utc)
    now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
    delta = int((now - __timestamp).total_seconds())
    for scale in matches:
        i = (delta
        if i:
            name = match_names[matches.index(scale)]
            break
    else:
        i = 0
    if (i == 0):
        result = 'right now'
    elif ((i == 1) and (name in ('year', 'month', 'week'))):
        result = 'last {}'.format(name)
    elif ((i == 1) and (name == 'day')):
        result = 'yesterday'
    elif ((i == 1) and (name == 'hour')):
        result = 'about an hour ago'
    else:
        result = 'about {} {}{} ago'.format((i if (i > 10) else numstr[i]), name, ('s' if (i > 1) else ''))
    return result

Format a relative time.

Args:
__timestamp: Event to generate relative timestamp against
Returns:
Human readable date and time offset


def ParseChat(self, parser_mediator, query, row, **unused_kwargs):
    query_hash = hash(query)
    participants = self._GetRowValue(query_hash, row, 'participants')
    author = self._GetRowValue(query_hash, row, 'author')
    dialog_partner = self._GetRowValue(query_hash, row, 'dialog_partner')
    from_displayname = self._GetRowValue(query_hash, row, 'from_displayname')
    accounts = []
    participants = participants.split(' ')
    for participant in participants:
        if (participant != author):
            accounts.append(participant)
    to_account = ', '.join(accounts)
    if (not to_account):
        to_account = (dialog_partner or 'Unknown User')
    from_account = '{0:s} <{1:s}>'.format(from_displayname, author)
    event_data = SkypeChatEventData()
    event_data.from_account = from_account
    event_data.query = query
    event_data.text = self._GetRowValue(query_hash, row, 'body_xml')
    event_data.title = self._GetRowValue(query_hash, row, 'title')
    event_data.to_account = to_account
    timestamp = self._GetRowValue(query_hash, row, 'timestamp')
    if timestamp:
        date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
        event = time_events.DateTimeValuesEvent(date_time, 'Chat from Skype')
        parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a chat message.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row resulting from query.


def __driver_helper(self, line):
    if (line.strip() == '?'):
        self.stdout.write('\n')
        self.stdout.write(self.doc_string())
    else:
        toks = shlex.split(line[:(- 1)])
        try:
            msg = self.__get_help_message(toks)
        except Exception as e:
            self.stderr.write('\n')
            self.stderr.write(traceback.format_exc())
            self.stderr.flush()
        self.stdout.write('\n')
        self.stdout.write(msg)
    self.stdout.write('\n')
    self.stdout.write(self.prompt)
    self.stdout.write(line)
    self.stdout.flush()

Driver level helper method.

1.  Display help message for the given input. Internally calls
self.__get_help_message() to obtain the help message.
2.  Re-display the prompt and the input line.

Arguments:
line: The input line.

Raises:
Errors from helper methods print stack trace without terminating
this shell. Other exceptions will terminate this shell.


def are_checksums_equal(checksum_a_pyxb, checksum_b_pyxb):
    if (checksum_a_pyxb.algorithm != checksum_b_pyxb.algorithm):
        raise ValueError('Cannot compare checksums calculated with different algorithms. a="{}" b="{}"'.format(checksum_a_pyxb.algorithm, checksum_b_pyxb.algorithm))
    return (checksum_a_pyxb.value().lower() == checksum_b_pyxb.value().lower())

Determine if checksums are equal.

Args:
checksum_a_pyxb, checksum_b_pyxb: PyXB Checksum objects to compare.

Returns:
bool
- **True**: The checksums contain the same hexadecimal values calculated with
the same algorithm. Identical checksums guarantee (for all practical
purposes) that the checksums were calculated from the same sequence of bytes.
- **False**: The checksums were calculated with the same algorithm but the
hexadecimal values are different.

Raises:
ValueError
The checksums were calculated with different algorithms, hence cannot be
compared.


def UpdateIncludeState(filename, include_dict, io=codecs):
    headerfile = None
    try:
        headerfile = io.open(filename, 'r', 'utf8', 'replace')
    except IOError:
        return False
    linenum = 0
    for line in headerfile:
        linenum += 1
        clean_line = CleanseComments(line)
        match = _RE_PATTERN_INCLUDE.search(clean_line)
        if match:
            include = match.group(2)
            include_dict.setdefault(include, linenum)
    return True

Fill up the include_dict with new includes found from the file.

Args:
filename: the name of the header to read.
include_dict: a dictionary in which the headers are inserted.
io: The io factory to use to read the file. Provided for testability.

Returns:
True if a header was successfully added. False otherwise.


def ExtractCredentialsFromPathSpec(self, path_spec):
    credentials = manager.CredentialsManager.GetCredentials(path_spec)
    for identifier in credentials.CREDENTIALS:
        value = getattr(path_spec, identifier, None)
        if (value is None):
            continue
        self.SetCredential(path_spec, identifier, value)

Extracts credentials from a path specification.

Args:
path_spec (PathSpec): path specification to extract credentials from.


def clip_boxes(box, box_size: Tuple[int, int]):
    assert torch.isfinite(box).all(), 'Box tensor contains infinite or NaN!'
    height, width = box_size
    x1 = box[:, 0].clamp(min=0, max=width)
    y1 = box[:, 1].clamp(min=0, max=height)
    x2 = box[:, 2].clamp(min=0, max=width)
    y2 = box[:, 3].clamp(min=0, max=height)
    box = torch.stack((x1, y1, x2, y2), dim=-1)
    return box

Clip the boxes by limiting x coordinates to the range [0, width]
and y coordinates to the range [0, height].

Args:
box (Tensor): The box to be clipped.
box_size (height, width): The clipping box's size.


def get_header_from_ops_and_kernels(ops_and_kernels, include_all_ops_and_kernels):
    ops_and_kernels = sorted(ops_and_kernels)
    ops = set((op for op, _ in ops_and_kernels))
    result_list = []

    def append(s):
        result_list.append(s)
    _, script_name = os.path.split(sys.argv[0])
    append('
    append('
    append('
    if include_all_ops_and_kernels:
        append('
        append('
        append('
    else:
        line = "\n    namespace {\n      constexpr const char* skip(const char* x) {\n        return (*x) ? (*x == ' ' ? skip(x + 1) : x) : x;\n      }\n\n      constexpr bool isequal(const char* x, const char* y) {\n        return (*skip(x) && *skip(y))\n                   ? (*skip(x) == *skip(y) && isequal(skip(x) + 1, skip(y) + 1))\n                   : (!*skip(x) && !*skip(y));\n      }\n\n      template<int N>\n      struct find_in {\n        static constexpr bool f(const char* x, const char* const y[N]) {\n          return isequal(x, y[0]) || find_in<N - 1>::f(x, y + 1);\n        }\n      };\n\n      template<>\n      struct find_in<0> {\n        static constexpr bool f(const char* x, const char* const y[]) {\n          return false;\n        }\n      };\n    }
        line += 'constexpr const char* kNecessaryOpKernelClasses[] = {\n'
        for _, kernel_class in ops_and_kernels:
            if kernel_class is None:
                continue
            line += '"%s",\n' % kernel_class
        line += '};'
        append(line)
        append('
        append('')
        append('constexpr inline bool ShouldRegisterOp(const char op[]) {')
        append('  return false')
        for op in sorted(ops):
            append('     || isequal(op, "%s")' % op)
        append('  ;')
        append('}')
        append('
        append('')
        append('
    append('
    return '\n'.join(result_list)

Returns a header for use with tensorflow SELECTIVE_REGISTRATION.

Args:
ops_and_kernels: a set of (op_name, kernel_class_name) pairs to include.
include_all_ops_and_kernels: if True, ops_and_kernels is ignored and all op
kernels are included.

Returns:
the string of the header that should be written as ops_to_register.h.


def input_fn(filenames, tf_transform_output, batch_size=200):
    transformed_feature_spec = tf_transform_output.transformed_feature_spec().copy()
    transformed_features = tf.contrib.learn.io.read_batch_features(filenames, batch_size, transformed_feature_spec, reader=_gzip_reader_fn)
    return (transformed_features, transformed_features.pop(taxi.transformed_name(taxi.LABEL_KEY)))

Generates features and labels for training or evaluation.

Args:
filenames: [str] list of CSV files to read data from.
tf_transform_output: A TFTransformOutput.
batch_size: int First dimension size of the Tensors returned by input_fn

Returns:
A (features, indices) tuple where features is a dictionary of
Tensors, and indices is a single Tensor of label indices.


def load(self, sess, tags, import_scope=None, **saver_kwargs):
    saved_model_proto = parse_saved_model(self._export_dir)
    metrics.IncrementReadApi(_LOADER_LABEL)
    with sess.graph.as_default():
        saver, _ = self.load_graph(sess.graph, tags, import_scope, **saver_kwargs)
        self.restore_variables(sess, saver, import_scope)
        self.run_init_ops(sess, tags, import_scope)
    meta_graph_def = self.get_meta_graph_def_from_tags(tags)
    if len(saved_model_proto.meta_graphs) == 1 and saved_model_proto.meta_graphs[0].HasField('object_graph_def'):
        metrics.IncrementRead(write_version='2')
    else:
        metrics.IncrementRead(write_version='1')
    return meta_graph_def

Load the MetaGraphDef graph and restore variable values into the session.

Args:
sess: tf.compat.v1.Session to restore variable values.
tags: a set of string tags identifying a MetaGraphDef.
import_scope: Optional `string` -- if specified, prepend this string
followed by '/' to all loaded tensor names. This scope is applied to
tensor instances loaded into the passed session, but it is *not* written
through to the static `MetaGraphDef` protocol buffer that is returned.
**saver_kwargs: keyword arguments to pass to tf.train.import_meta_graph.

Returns:
`MetagraphDef` proto of the graph that was loaded.


def _build_migrated_variables(checkpoint_reader, name_value_fn):
    names_to_shapes = checkpoint_reader.get_variable_to_shape_map()
    new_name_to_variable = {}
    name_to_new_name = {}
    for name in names_to_shapes:
        value = checkpoint_reader.get_tensor(name)
        (new_name, new_value) = name_value_fn(name, value)
        if (new_name is None):
            continue
        name_to_new_name[name] = new_name
        new_name_to_variable[new_name] = tf.Variable(new_value)
    return (new_name_to_variable, name_to_new_name)

Builds the TensorFlow variables of the migrated checkpoint.

Args:
checkpoint_reader: A `tf.train.NewCheckPointReader` of the checkpoint to
be read from.
name_value_fn: Function taking two arguments, `name` and `value`, which
returns the pair of new name and value for that a variable of that name.

Returns:
Tuple of a dictionary with new variable names as keys and `tf.Variable`s as
values, and a dictionary that maps the old variable names to the new
variable names.


def start_of_chunk(prev_tag, tag, prev_type, type_):
    chunk_start = False
    if (tag == 'B'):
        chunk_start = True
    if (tag == 'S'):
        chunk_start = True
    if ((prev_tag == 'E') and (tag == 'E')):
        chunk_start = True
    if ((prev_tag == 'E') and (tag == 'I')):
        chunk_start = True
    if ((prev_tag == 'S') and (tag == 'E')):
        chunk_start = True
    if ((prev_tag == 'S') and (tag == 'I')):
        chunk_start = True
    if ((prev_tag == 'O') and (tag == 'E')):
        chunk_start = True
    if ((prev_tag == 'O') and (tag == 'I')):
        chunk_start = True
    if ((tag != 'O') and (tag != '.') and (prev_type != type_)):
        chunk_start = True
    return chunk_start

Checks if a chunk started between the previous and current word.

Args:
prev_tag: previous chunk tag.
tag: current chunk tag.
prev_type: previous type.
type_: current type.

Returns:
chunk_start: boolean.


def Tensors(self, run, tag):

    accumulator = self.GetAccumulator(run)
    return accumulator.Tensors(tag)

Retrieve the tensor events associated with a run and tag.

Args:
run: A string name of the run for which values are retrieved.
tag: A string name of the tag for which values are retrieved.

Raises:
KeyError: If the run is not found, or the tag is not available for
the given run.

Returns:
An array of `event_accumulator.TensorEvent`s.


def build(self, backend=None):

        n_total = len(self.data.index)
        if len(self.completes):
            completes = [set(x) for x in sum(self.completes, [])]
            completes = set.intersection(*completes)
        else:
            completes = [x for x in range(len(self.data.index))]
        self.clean_data = self.data.iloc[list(completes), :]

        if len(completes) < n_total:
            msg = "Automatically removing {}/{} rows from the dataset."
            msg = msg.format(n_total - len(completes), n_total)
            warnings.warn(msg)

        for term_args in self.added_terms:
            self._add(**term_args)

        self._set_priors(**self._added_priors)

        for name, term in self.terms.items():
            type_ = 'intercept' if name == 'Intercept' else \
                'random' if self.terms[name].random else 'fixed'
            term.prior = self._prepare_prior(term.prior, type_)

        if backend is None:
            if self._backend_name is None:
                raise ValueError("Error: no backend was passed or set in the "
                                 "Model; did you forget to call fit()?")
            backend = self._backend_name

        if self.y is None:
            raise ValueError("No outcome (y) variable is set! Please specify "
                             "an outcome variable using the formula interface "
                             "before build() or fit().")

        terms = [t for t in self.fixed_terms.values() if t.name != 'Intercept']

        if len(self.fixed_terms) > 1:

            X = [pd.DataFrame(x.data, columns=x.levels) for x in terms]
            X = pd.concat(X, axis=1)

            self.dm_statistics = {
                'r2_x': pd.Series({
                    x: sm.OLS(endog=X[x],
                              exog=sm.add_constant(X.drop(x, axis=1))
                              if 'Intercept' in self.term_names
                              else X.drop(x, axis=1)).fit().rsquared
                    for x in list(X.columns)}),
                'sd_x': X.std(),
                'mean_x': X.mean(axis=0)
            }

            mat = X.corr()
            for x in list(mat.columns):
                mat.loc[x, x] = self.dm_statistics['mean_x'][x]
            self._diagnostics = {

                'VIF': 1/(1 - self.dm_statistics['r2_x']),
                'corr_mean_X': mat
            }

            if any(self.dm_statistics['r2_x'] > .999):
                raise ValueError(
                    "There is perfect collinearity among the fixed effects!\n"
                    "Printing some design matrix statistics:\n" +
                    str(self.dm_statistics) + '\n' +
                    str(self._diagnostics))

        num_cats = [x.data.size for x in self.fixed_terms.values()]
        if any(np.array(num_cats) == 0):
            raise ValueError(
                "At least one categorical predictor contains only 1 category!")

        if len(self.terms) > 0:

            if self.taylor is not None:
                taylor = self.taylor
            else:
                taylor = 5 if self.family.name == 'gaussian' else 1
            scaler = PriorScaler(self, taylor=taylor)
            scaler.scale()

        if self.family.name == 'bernoulli' and np.max(self.y.data) < 1.01:
            event = next(
                i for i, x in enumerate(self.y.data.flatten()) if x > .99)
            warnings.warn('Modeling the probability that {}==\'{}\''.format(
                self.y.name, str(self.clean_data[self.y.name].iloc[event])))

        self._set_backend(backend)
        self.backend.build(self)
        self.built = True

Set up the model for sampling/fitting.

Performs any steps that require access to all model terms (e.g., scaling priors
on each term), then calls the BackEnd's build() method.

Args:
backend (str): The name of the backend to use for model fitting.
Currently, 'pymc' and 'stan' are supported. If None, assume
that fit() has already been called (possibly without building),
and look in self._backend_name.


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

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

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


def receiveds_format(receiveds):

    log.debug("Receiveds for this email are parsed")

    output = []
    counter = Counter()

    for i in receiveds[::-1]:

        j = {k: v.strip() for k, v in i.items() if v}

        j["hop"] = counter["hop"] + 1

        if i.get("date"):

            i["date"] = i["date"].split(";")[-1]
            try:
                j["date_utc"], _ = convert_mail_date(i["date"])
            except TypeError:
                j["date_utc"] = None

        size = len(output)
        now = j.get("date_utc")

        if size and now:
            before = output[counter["hop"] - 1].get("date_utc")
            if before:
                j["delay"] = (now - before).total_seconds()
            else:
                j["delay"] = 0
        else:
            j["delay"] = 0

        output.append(j)

        counter["hop"] += 1
    else:
        for i in output:
            if i.get("date_utc"):
                i["date_utc"] = i["date_utc"].isoformat()
        else:
            return output

Given a list of receiveds hop, adds metadata and reformat
field values

Args:
receiveds (list): list of receiveds hops already formatted

Returns:
list of receiveds reformated and with new fields


def users_getPresence(self, *, user: str, **kwargs) -> SlackResponse:

        kwargs.update({"user": user})
        return self.api_call("users.getPresence", http_verb="GET", params=kwargs)

Gets user presence information.

Args:
user (str): User to get presence info on. Defaults to the authed user.
e.g. 'W1234567890'


def chown(self, path, uid, gid, dir_fd=None, follow_symlinks=None):
    if (follow_symlinks is None):
        follow_symlinks = True
    elif (sys.version_info < (3, 3)):
        raise TypeError("chown() got an unexpected keyword argument 'follow_symlinks'")
    path = self._path_with_dir_fd(path, self.chown, dir_fd)
    try:
        file_object = self.filesystem.resolve(path, follow_symlinks, allow_fd=True)
    except IOError as io_error:
        if (io_error.errno == errno.ENOENT):
            self.filesystem.raise_os_error(errno.ENOENT, path)
        raise
    if (not ((is_int_type(uid) or (uid is None)) and (is_int_type(gid) or (gid is None)))):
        raise TypeError('An integer is required')
    if (uid != (- 1)):
        file_object.st_uid = uid
    if (gid != (- 1)):
        file_object.st_gid = gid

Set ownership of a faked file.

Args:
path: (str) Path to the file or directory.
uid: (int) Numeric uid to set the file or directory to.
gid: (int) Numeric gid to set the file or directory to.
dir_fd: (int) If not `None`, the file descriptor of a directory,
with `path` being relative to this directory.
New in Python 3.3.
follow_symlinks: (bool) If `False` and path points to a symlink,
the link itself is changed instead of the linked object.
New in Python 3.3.

Raises:
OSError: if path does not exist.

`None` is also allowed for `uid` and `gid`.  This permits `os.rename`
to use `os.chown` even when the source file `uid` and `gid` are
`None` (unset).


def parse(self, message, schema):

        func = {
            'audit-log': self._parse_audit_log_msg,
            'event': self._parse_event_msg,
        }[schema]
        return func(message)

Parse message according to schema.

`message` should already be validated against the given schema.
See :ref:`schemadef` for more information.

Args:
message (dict): message data to parse.
schema (str): valid message schema.
Returns:
(dict): parsed message


def get_adversary_phone_asset(self, main_type, sub_type, unique_id, asset_id, params=None):

        return self.adversary_phone_asset(main_type, sub_type, unique_id, asset_id, params=params)

Args:
main_type:
sub_type:
unique_id:
asset_id:
params:

Return:


def should_use_network(self, request):
    return (self.networking and all((fn(request) for fn in self.network_filters)))

Verifies if real networking mode should be used for the given
request, passing it to the registered network filters.

Arguments:
request (pook.Request): outgoing HTTP request to test.

Returns:
bool


def _parse_publisher(details):

    publisher = _get_td_or_none(
        details,
        "ctl00_ContentPlaceHolder1_tblRowNakladatel"
    )

    if not publisher:
        return None

    publisher = dhtmlparser.removeTags(publisher).strip()

    if not publisher:
        return None

    return publisher

Parse publisher of the book.

Args:
details (obj): HTMLElement containing slice of the page with details.

Returns:
str/None: Publisher's name as string or None if not found.


def _extract_field_with_regex(self, field):
    matched = re.search(field, self.text)
    if (not matched):
        err_msg = u'Failed to extract data with regex! => {}\n'.format(field)
        err_msg += u'response body: {}\n'.format(self.text)
        logger.log_error(err_msg)
        raise exceptions.ExtractFailure(err_msg)
    return matched.group(1)

extract field from response content with regex.
requests.Response body could be json or html text.

Args:
field (str): regex string that matched r".*\(.*\).*"

Returns:
str: matched content.

Raises:
exceptions.ExtractFailure: If no content matched with regex.

Examples:
>>> # self.text: "LB123abcRB789"
>>> filed = "LB[\d]*(.*)RB[\d]*"
>>> _extract_field_with_regex(field)
abc


def __tf_unflatten__(cls, metadata, components):

Create a user-defined object from (metadata, components).

Args:
metadata: a custom Python object that stands for the static config for
reconstructing a new object of the current class.
components: a `tuple` that contains the dynamic data fields of the current
class, for object reconstruction.

Returns:
The user-defined object, with the same class of the current object.

Implementation Note:
- This method should not invoke any TensorFlow ops.
- This method only needs to unflatten the current level. If the object has
an attribute that also need custom unflattening, nest functions will
utilize this method to do recursive unflattening.


def set_signal_type(self, sig_type):
    if isinstance(sig_type, str):
        sig_type = [sig_type]
    self.snr_input.signal_type = sig_type
    return

Set the signal type of interest.

Sets the signal type for which the SNR is calculated.
This means inspiral, merger, and/or ringdown.

Args:
sig_type (str or list of str): Signal type desired by user.
Choices are `ins`, `mrg`, `rd`, `all` for circular waveforms created with PhenomD.
If eccentric waveforms are used, must be `all`.


def _summarize_eager(tensor, summarize=None):
    if summarize is None:
        summarize = 3
    elif summarize < 0:
        summarize = array_ops.size(tensor)
    if tensor._rank():
        flat = tensor.numpy().reshape((-1,))
        lst = [str(x) for x in flat[:summarize]]
        if len(lst) < flat.size:
            lst.append('...')
    elif gen_math_ops.not_equal(summarize, 0):
        lst = [str(tensor.numpy())]
    else:
        lst = []
    return ', '.join(lst)

Returns a summarized string representation of eager `tensor`.

Args:
tensor: EagerTensor to summarize
summarize: Include these many first elements of `array`


def register_name(self, register_index):
    result = self._dll.JLINKARM_GetRegisterName(register_index)
    return ctypes.cast(result, ctypes.c_char_p).value.decode()

Retrives and returns the name of an ARM CPU register.

Args:
self (JLink): the ``JLink`` instance
register_index (int): index of the register whose name to retrieve

Returns:
Name of the register.


def decode(self, decoder_input_ids, encoder_outputs, encoder_attention_mask: Optional[jnp.ndarray]=None, decoder_attention_mask: Optional[jnp.ndarray]=None, decoder_position_ids: Optional[jnp.ndarray]=None, past_key_values: Optional[dict]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, deterministic: bool=True, params: Optional[dict]=None, dropout_rng: PRNGKey=None):
    output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
    output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
    return_dict = return_dict if return_dict is not None else self.config.return_dict
    encoder_hidden_states = encoder_outputs[0]
    if encoder_attention_mask is None:
        batch_size, sequence_length = encoder_hidden_states.shape[:2]
        encoder_attention_mask = jnp.ones((batch_size, sequence_length))
    batch_size, sequence_length = decoder_input_ids.shape
    if decoder_attention_mask is None:
        decoder_attention_mask = jnp.ones((batch_size, sequence_length))
    if decoder_position_ids is None:
        if past_key_values is not None:
            raise ValueError('Make sure to provide `decoder_position_ids` when passing `past_key_values`.')
        decoder_position_ids = jnp.broadcast_to(jnp.arange(sequence_length)[None, :], (batch_size, sequence_length))
    rngs = {}
    if dropout_rng is not None:
        rngs['dropout'] = dropout_rng
    inputs = {'params': params or self.params}
    if past_key_values:
        inputs['cache'] = past_key_values
        mutable = ['cache']
    else:
        mutable = False

    def _decoder_forward(module, decoder_input_ids, decoder_attention_mask, decoder_position_ids, **kwargs):
        decoder_module = module._get_decoder_module()
        outputs = decoder_module(decoder_input_ids, decoder_attention_mask, decoder_position_ids, **kwargs)
        hidden_states = outputs[0]
        if self.config.tie_word_embeddings:
            shared_embedding = module.model.variables['params']['shared']['embedding']
            lm_logits = module.lm_head.apply({'params': {'kernel': shared_embedding.T}}, hidden_states)
        else:
            lm_logits = module.lm_head(hidden_states)
        lm_logits += module.final_logits_bias.astype(self.dtype)
        return (lm_logits, outputs)
    outputs = self.module.apply(inputs, decoder_input_ids=jnp.array(decoder_input_ids, dtype='i4'), decoder_attention_mask=jnp.array(decoder_attention_mask, dtype='i4'), decoder_position_ids=jnp.array(decoder_position_ids, dtype='i4'), encoder_hidden_states=encoder_hidden_states, encoder_attention_mask=jnp.array(encoder_attention_mask, dtype='i4'), output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, deterministic=deterministic, rngs=rngs, mutable=mutable, method=_decoder_forward)
    if past_key_values is None:
        lm_logits, decoder_outputs = outputs
    else:
        (lm_logits, decoder_outputs), past = outputs
    if return_dict:
        outputs = FlaxCausalLMOutputWithCrossAttentions(logits=lm_logits, hidden_states=decoder_outputs.hidden_states, attentions=decoder_outputs.attentions, cross_attentions=decoder_outputs.cross_attentions)
    else:
        outputs = (lm_logits,) + decoder_outputs[1:]
    if past_key_values is not None and return_dict:
        outputs['past_key_values'] = unfreeze(past['cache'])
        return outputs
    elif past_key_values is not None and (not return_dict):
        outputs = outputs[:1] + (unfreeze(past['cache']),) + outputs[1:]
    return outputs

Returns:

Example:

```python
>>> import jax.numpy as jnp
>>> from transformers import AutoTokenizer, FlaxPegasusForConditionalGeneration

>>> model = FlaxPegasusForConditionalGeneration.from_pretrained("google/pegasus-large")
>>> tokenizer = AutoTokenizer.from_pretrained("google/pegasus-large")

>>> text = "My friends are cool but they eat too many carbs."
>>> inputs = tokenizer(text, max_length=1024, return_tensors="np")
>>> encoder_outputs = model.encode(**inputs)

>>> decoder_start_token_id = model.config.decoder_start_token_id
>>> decoder_input_ids = jnp.ones((inputs.input_ids.shape[0], 1), dtype="i4") * decoder_start_token_id

>>> outputs = model.decode(decoder_input_ids, encoder_outputs)
>>> logits = outputs.logits
```


def spawn_watcher(self, label, target=None, eternal=False):
    if (label not in self._sources):
        raise YapconfSourceError(('Cannot watch %s no source named %s' % (label, label)))
    current_config = self._sources[label].get_data()
    handler = ConfigChangeHandler(current_config, self, target)
    return self._sources[label].watch(handler, eternal)

Spawns a config watcher in a separate daemon thread.

If a particular config value changes, and the item has a
``watch_target`` defined, then that method will be called.

If a ``target`` is passed in, then it will call the ``target``
anytime the config changes.

Args:
label (str): Should match a label added through ``add_source``
target (func): Should be a function that takes two arguments,
the old configuration and the new configuration.
eternal (bool): Determines if watcher threads should be restarted
if they die.

Returns:
The thread that was spawned.


def _DepthwiseConv2dNumpy(x1, x2, strides, padding, data_format, dilations):
    if data_format == 'NCHW':
        x1 = np.transpose(x1, (0, 3, 1, 2))
        strides = [strides[0], strides[3], strides[1], strides[2]]
        if dilations:
            dilations = [dilations[0], dilations[3], dilations[1], dilations[2]]
    if dilations:
        fh, fw, c, o = x2.shape
        new_fh = (fh - 1) * dilations[0] + 1
        new_fw = (fw - 1) * dilations[1] + 1
        new_x2 = np.zeros((new_fh, new_fw, c, o))
        for i in range(fh):
            for j in range(fw):
                new_x2[i * dilations[0], j * dilations[1], :] = x2[i, j, :, :]
        x2 = new_x2
    if padding == 'SAME':

        def PaddingsForDim(input_dim, filter_dim, stride):

            if input_dim % stride == 0:
                total_padding = max(filter_dim - stride, 0)
            else:
                total_padding = max(filter_dim - input_dim % stride, 0)
            pad_before = total_padding
            pad_after = total_padding - pad_before
            return (pad_before, pad_after)
        padding = [(0, 0), PaddingsForDim(x1.shape[1], x2.shape[0], strides[1]), PaddingsForDim(x1.shape[2], x2.shape[1], strides[2]), (0, 0)]
    elif padding == 'VALID':
        padding = [(0, 0)] * 4
    x1 = np.pad(x1, padding, 'constant')
    y = _DepthwiseConv2dNumpyBasic(x1, x2, strides)
    if data_format == 'NCHW':
        y = np.transpose(y, (0, 2, 3, 1))
    return y

Compute depthwise_conv2d using Numpy.

This allows use to test TensorFlow's depthwise_conv2d by comparing to the
Numpy version.

Unlike `_DepthwiseConv2dNumpyBasic`, this supports more advanced features
like padding.

Args:
x1: The input Numpy array.
x2: The filter Numpy array.
strides: A Python list of 4 elements representing the strides.
padding: The padding. "SAME", "VALID", or a list of explicit paddings.
data_format: "NHWC" or "NCHW".
dilations: A list of 2 elements, representing the dilations.

Returns:
The depthwise conv2d as a Numpy array.


def __init__(self, process: Process):

        self.process = process
        self.stopped_due_to_worker_shutdown = False

Constructor.

Args:
process (Process): task process


def fetch(self, subscription_id, data={}, **kwargs):
    return super(Subscription, self).fetch(subscription_id, data, **kwargs)

Fetch Subscription for given Id

Args:
subscription_id : Id for which subscription object is retrieved

Returns:
Subscription dict for given subscription Id


def convert_datetime_array(array):

    if not isinstance(array, np.ndarray):
        return array

    try:
        dt2001 = np.datetime64('2001')
        legacy_datetime64 = (dt2001.astype('int64') ==
                             dt2001.astype('datetime64[ms]').astype('int64'))
    except AttributeError as e:
        if e.args == ("'module' object has no attribute 'datetime64'",):

            if 'PyPy' in sys.version:
                legacy_datetime64 = False
                pass
            else:
                raise e
        else:
            raise e

    if array.dtype.kind == 'M':
        if legacy_datetime64:
            if array.dtype == np.dtype('datetime64[ns]'):
                array = array.astype('int64') / 10**6.0
        else:
            array =  array.astype('datetime64[us]').astype('int64') / 1000.

    elif array.dtype.kind == 'm':
        array = array.astype('timedelta64[us]').astype('int64') / 1000.

    return array

Convert NumPy datetime arrays to arrays to milliseconds since epoch.

Args:
array : (obj)
A NumPy array of datetime to convert

If the value passed in is not a NumPy array, it will be returned as-is.

Returns:
array


def ms_to_frames(ms, fps):

    if fps <= 0:
        raise ValueError("Framerate must be positive number (%f)." % fps)

    return int(round((ms / 1000) * fps))

Convert milliseconds to number of frames.

Arguments:
ms: Number of milliseconds (may be int, float or other numeric class).
fps: Framerate (must be a positive number, eg. 23.976).

Returns:
Number of frames (int).

Raises:
ValueError: fps was negative or zero.


def context(self, name):

        data = self._context(name)
        context = data.get("context")
        if context:
            return context

        assert self.load_path
        context_path = os.path.join(self.load_path, "contexts", "%s.rxt" % name)
        context = ResolvedContext.load(context_path)
        data["context"] = context
        data["loaded"] = True
        return context

Get a context.

Args:
name (str): Name to store the context under.

Returns:
`ResolvedContext` object.


def match(self, message) -> bool:

        if self.to and message.to != self.to:
            return False

        if self.sender and message.sender != self.sender:
            return False

        if self.body and message.body != self.body:
            return False

        if self.thread and message.thread != self.thread:
            return False

        for key, value in self.metadata.items():
            if message.get_metadata(key) != value:
                return False

        logger.debug(f"message matched {self} == {message}")
        return True

Returns wether a message matches with this message or not.
The message can be a Message object or a Template object.

Args:
message (spade.message.Message): the message to match to

Returns:
bool: wether the message matches or not


def _GetCh(self):
    fd = self._tty.fileno()
    old = termios.tcgetattr(fd)
    try:
        tty.setraw(fd)
        ch = self._tty.read(1)
        if (ord(ch) == 27):
            ch += self._tty.read(2)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old)
    return ch

Read a single character from the user.

Returns:
A string, the character read.


def _insert_operations(self, operations: Sequence[ops.Operation], insertion_indices: Sequence[int]) -> None:
    if (len(operations) != len(insertion_indices)):
        raise ValueError('operations and insertion_indices must have thesame length.')
    self._moments += [ops.Moment() for _ in range(((1 + max(insertion_indices)) - len(self)))]
    moment_to_ops = defaultdict(list)
    for (op_index, moment_index) in enumerate(insertion_indices):
        moment_to_ops[moment_index].append(operations[op_index])
    for (moment_index, new_ops) in moment_to_ops.items():
        self._moments[moment_index] = ops.Moment((self._moments[moment_index].operations + tuple(new_ops)))

Inserts operations at the specified moments. Appends new moments if
necessary.

Args:
operations: The operations to insert.
insertion_indices: Where to insert them, i.e. operations[i] is
inserted into moments[insertion_indices[i].

Raises:
ValueError: operations and insert_indices have different lengths.

NB: It's on the caller to ensure that the operations won't conflict
with operations already in the moment or even each other.


class TFCLIPEncoder(keras.layers.Layer):

    def __init__(self, config: CLIPConfig, **kwargs):
        super().__init__(**kwargs)
        self.layers = [TFCLIPEncoderLayer(config, name=f'layers_._{i}') for i in range(config.num_hidden_layers)]

    def call(self, hidden_states: tf.Tensor, attention_mask: tf.Tensor, causal_attention_mask: tf.Tensor, output_attentions: bool, output_hidden_states: bool, return_dict: bool, training: bool=False) -> Union[TFBaseModelOutput, Tuple[tf.Tensor]]:
        all_hidden_states = () if output_hidden_states else None
        all_attentions = () if output_attentions else None
        for i, layer_module in enumerate(self.layers):
            if output_hidden_states:
                all_hidden_states = all_hidden_states + (hidden_states,)
            layer_outputs = layer_module(hidden_states=hidden_states, attention_mask=attention_mask, causal_attention_mask=causal_attention_mask, output_attentions=output_attentions, training=training)
            hidden_states = layer_outputs[0]
            if output_attentions:
                all_attentions = all_attentions + (layer_outputs[1],)
        if output_hidden_states:
            all_hidden_states = all_hidden_states + (hidden_states,)
        if not return_dict:
            return tuple((v for v in [hidden_states, all_hidden_states, all_attentions] if v is not None))
        return TFBaseModelOutput(last_hidden_state=hidden_states, hidden_states=all_hidden_states, attentions=all_attentions)

    def build(self, input_shape=None):
        if self.built:
            return
        self.built = True
        if getattr(self, 'layers', None) is not None:
            for layer in self.layers:
                with tf.name_scope(layer.name):
                    layer.build(None)

Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
[`TFCLIPEncoderLayer`].

Args:
config: CLIPConfig


def serialize_to_xml(root, block):

    root.tag = 'ubcpi'

    if block.rationale_size is not None:
        if block.rationale_size.get('min'):
            root.set('rationale_size_min', unicode(block.rationale_size.get('min')))
        if block.rationale_size.get('max'):
            root.set('rationale_size_max', unicode(block.rationale_size['max']))

    if block.algo:
        if block.algo.get('name'):
            root.set('algorithm', block.algo.get('name'))
        if block.algo.get('num_responses'):
            root.set('num_responses', unicode(block.algo.get('num_responses')))

    display_name = etree.SubElement(root, 'display_name')
    display_name.text = block.display_name

    question = etree.SubElement(root, 'question')
    question_text = etree.SubElement(question, 'text')
    question_text.text = block.question_text['text']
    serialize_image(block.question_text, question)

    options = etree.SubElement(root, 'options')
    serialize_options(options, block)

    seeds = etree.SubElement(root, 'seeds')
    serialize_seeds(seeds, block)

Serialize the Peer Instruction XBlock's content to XML.

Args:
block (PeerInstructionXBlock): The peer instruction block to serialize.
root (etree.Element): The XML root node to update.

Returns:
etree.Element


def __init__(self, project=None, deidentification_template_name=None, deidentification_config=None, inspection_template_name=None, inspection_config=None, timeout=None):
    self.config = {}
    self.project = project
    self.timeout = timeout
    if deidentification_template_name is not None and deidentification_config is not None:
        raise ValueError('Both deidentification_template_name and deidentification_config were specified. Please specify only one of these.')
    elif deidentification_template_name is None and deidentification_config is None:
        raise ValueError('deidentification_template_name or deidentification_config must be specified.')
    elif deidentification_template_name is not None:
        self.config['deidentify_template_name'] = deidentification_template_name
    else:
        self.config['deidentify_config'] = deidentification_config
    if inspection_config is None and inspection_template_name is None:
        raise ValueError('inspection_template_name or inspection_config must be specified')
    if inspection_template_name is not None:
        self.config['inspect_template_name'] = inspection_template_name
    if inspection_config is not None:
        self.config['inspect_config'] = inspection_config

Initializes a :class:`MaskDetectedDetails` transform.

Args:
project: Optional. GCP project name in which inspection will be performed
deidentification_template_name (str): Either this or
`deidentification_config` required. Name of
deidentification template to be used on detected sensitive information
instances in text.
deidentification_config
(``Union[dict, google.cloud.dlp_v2.types.DeidentifyConfig]``):
Configuration for the de-identification of the content item.
If both template name and config are supplied,
config is more important.
inspection_template_name (str): This or `inspection_config` required.
Name of inspection template to be used
to detect sensitive data in text.
inspection_config
(``Union[dict, google.cloud.dlp_v2.types.InspectConfig]``):
Configuration for the inspector used to detect sensitive data in text.
If both template name and config are supplied,
config takes precedence.
timeout (float): Optional. The amount of time, in seconds, to wait for
the request to complete.


def orient_undirected_graph(self, data, umg, alg='HC'):
    warnings.warn('The pairwise GNN model is computed on each edge of the UMG to initialize the model and start CGNN with a DAG')
    gnn = GNN(nh=self.nh, lr=self.lr)
    og = gnn.orient_graph(data, umg, nb_runs=self.nb_runs, nb_max_runs=self.nb_runs, nb_jobs=self.nb_jobs, train_epochs=self.train_epochs, test_epochs=self.test_epochs, verbose=self.verbose, gpu=self.gpu)
    dag = dagify_min_edge(og)
    return self.orient_directed_graph(data, dag, alg=alg)

Orient the undirected graph using GNN and apply CGNN to improve the graph.

Args:
data (pandas.DataFrame): Observational data on which causal
discovery has to be performed.
umg (nx.Graph): Graph that provides the skeleton, on which the GNN
then the CGNN algorithm will be applied.
alg (str): Exploration heuristic to use, among ["HC", "HCr",
"tabu", "EHC"]
Returns:
networkx.DiGraph: Solution given by CGNN.

.. note::
GNN (``cdt.causality.pairwise.GNN``) is first used to orient the
undirected graph and output a DAG before applying CGNN.


def _get_reference(document_path, reference_map):
    try:
        return reference_map[document_path]
    except KeyError:
        msg = _BAD_DOC_TEMPLATE.format(document_path)
        raise ValueError(msg)

Get a document reference from a dictionary.

This just wraps a simple dictionary look-up with a helpful error that is
specific to :meth:`~.firestore.client.Client.get_all`, the
**public** caller of this function.

Args:
document_path (str): A fully-qualified document path.
reference_map (Dict[str, .DocumentReference]): A mapping (produced
by :func:`_reference_info`) of fully-qualified document paths to
document references.

Returns:
.DocumentReference: The matching reference.

Raises:
ValueError: If ``document_path`` has not been encountered.


def OverwriteAndClose(self, compressed_data, size):

    self.Set(self.Schema.CONTENT(compressed_data))
    self.Set(self.Schema.SIZE(size))
    super(AFF4MemoryStreamBase, self).Close()

Directly overwrite the current contents.

Replaces the data currently in the stream with compressed_data,
and closes the object. Makes it possible to avoid recompressing
the data.
Args:
compressed_data: The data to write, must be zlib compressed.
size: The uncompressed size of the data.


def _compile_constant_expression(self,
                                     expr: Expression,
                                     scope: Dict[str, TensorFluent],
                                     batch_size: Optional[int] = None,
                                     noise: Optional[List[tf.Tensor]] = None) -> TensorFluent:

        etype = expr.etype
        args = expr.args
        dtype = utils.python_type_to_dtype(etype[1])
        fluent = TensorFluent.constant(args, dtype=dtype)
        return fluent

Compile a constant expression `expr` into a TensorFluent
in the given `scope` with optional batch size.

Args:
expr (:obj:`rddl2tf.expr.Expression`): A RDDL constant expression.
scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope.
batch_size (Optional[size]): The batch size.

Returns:
:obj:`rddl2tf.fluent.TensorFluent`: The compiled expression as a TensorFluent.


def UploadFilePath(self, filepath, offset=0, amount=None):
    return self._UploadChunkStream(self._streamer.StreamFilePath(filepath, offset=offset, amount=amount))

Uploads chunks of a file on a given path to the transfer store flow.

Args:
filepath: A path to the file to upload.
offset: An integer offset at which the file upload should start on.
amount: An upper bound on number of bytes to stream. If it is `None` then
the whole file is uploaded.

Returns:
A `BlobImageDescriptor` object.


def random_sparse(strategy, prob, obj_reaction, flux_threshold):
    essential = set()
    deleted = set()
    for (entity, deleted_reactions) in strategy.iter_tests():
        if (obj_reaction in deleted_reactions):
            logger.info('Marking entity {} as essential because the objective reaction depends on this entity...'.format(entity))
            essential.add(entity)
            continue
        if (len(deleted_reactions) == 0):
            logger.info('No reactions were removed when entity {} was deleted'.format(entity))
            deleted.add(entity)
            strategy.delete(entity, deleted_reactions)
            continue
        logger.info('Deleted reactions: {}'.format(', '.join(deleted_reactions)))
        constr = []
        for r in deleted_reactions:
            flux_var = prob.get_flux_var(r)
            (c,) = prob.prob.add_linear_constraints((flux_var == 0))
            constr.append(c)
        logger.info('Trying FBA without reactions {}...'.format(', '.join(deleted_reactions)))
        try:
            prob.maximize(obj_reaction)
        except fluxanalysis.FluxBalanceError:
            logger.info('FBA is infeasible, marking {} as essential'.format(entity))
            for c in constr:
                c.delete()
            essential.add(entity)
            continue
        logger.debug('Reaction {} has flux {}'.format(obj_reaction, prob.get_flux(obj_reaction)))
        if (prob.get_flux(obj_reaction) < flux_threshold):
            for c in constr:
                c.delete()
            essential.add(entity)
            logger.info('Entity {} was essential'.format(entity))
        else:
            deleted.add(entity)
            strategy.delete(entity, deleted_reactions)
            logger.info('Entity {} was deleted'.format(entity))
    return (essential, deleted)

Find a random minimal network of model reactions.

Given a reaction to optimize and a threshold, delete entities randomly
until the flux of the reaction to optimize falls under the threshold.
Keep deleting until no more entities can be deleted. It works
with two strategies: deleting reactions or deleting genes (reactions
related to certain genes).

Args:
strategy: :class:`.ReactionDeletionStrategy` or
:class:`.GeneDeletionStrategy`.
prob: :class:`psamm.fluxanalysis.FluxBalanceProblem`.
obj_reaction: objective reactions to optimize.
flux_threshold: threshold of max reaction flux.


def register_controller(self, module, required=True, min_number=1):
    verify_controller_module(module)
    module_ref_name = module.__name__.split('.')[(- 1)]
    if (module_ref_name in self._controller_objects):
        raise signals.ControllerError(('Controller module %s has already been registered. It cannot be registered again.' % module_ref_name))
    module_config_name = module.MOBLY_CONTROLLER_CONFIG_NAME
    if (module_config_name not in self.controller_configs):
        if required:
            raise signals.ControllerError(('No corresponding config found for %s' % module_config_name))
        logging.warning('No corresponding config found for optional controller %s', module_config_name)
        return None
    try:
        original_config = self.controller_configs[module_config_name]
        controller_config = copy.deepcopy(original_config)
        objects = module.create(controller_config)
    except:
        logging.exception('Failed to initialize objects for controller %s, abort!', module_config_name)
        raise
    if (not isinstance(objects, list)):
        raise signals.ControllerError(('Controller module %s did not return a list of objects, abort.' % module_ref_name))
    actual_number = len(objects)
    if (actual_number < min_number):
        module.destroy(objects)
        raise signals.ControllerError(('Expected to get at least %d controller objects, got %d.' % (min_number, actual_number)))
    self._controller_objects[module_ref_name] = copy.copy(objects)
    logging.debug('Found %d objects for controller %s', len(objects), module_config_name)
    self._controller_modules[module_ref_name] = module
    return objects

Loads a controller module and returns its loaded devices.

This is to be used in a mobly test class.

Args:
module: A module that follows the controller module interface.
required: A bool. If True, failing to register the specified
controller module raises exceptions. If False, the objects
failed to instantiate will be skipped.
min_number: An integer that is the minimum number of controller
objects to be created. Default is one, since you should not
register a controller module without expecting at least one
object.

Returns:
A list of controller objects instantiated from controller_module, or
None if no config existed for this controller and it was not a
required controller.

Raises:
ControllerError:
* The controller module has already been registered.
* The actual number of objects instantiated is less than the
* `min_number`.
* `required` is True and no corresponding config can be found.
* Any other error occurred in the registration process.


async def getNodeByBuid(self, buid):

        node = self.livenodes.get(buid)
        if node is not None:
            return node

        props = {}
        proplayr = {}
        for layr in self.layers:
            layerprops = await layr.getBuidProps(buid)
            props.update(layerprops)
            proplayr.update({k: layr for k in layerprops})

        node = s_node.Node(self, buid, props.items(), proplayr=proplayr)

        await asyncio.sleep(0)

        if node.ndef is None:
            return None

        self.buidcache.append(node)
        self.livenodes[buid] = node
        return node

Retrieve a node tuple by binary id.

Args:
buid (bytes): The binary ID for the node.

Returns:
Optional[s_node.Node]: The node object or None.


def _copy_script_migrated(self, filename, id_=(- 1), file_type=SCRIPT_FILE_TYPE):
    basefname = os.path.basename(filename)
    resource = open(filename, 'rb')
    headers = {'DESTINATION': '1', 'OBJECT_ID': str(id_), 'FILE_TYPE': file_type, 'FILE_NAME': basefname}
    response = self.connection['jss'].session.post(url=('%s/%s' % (self.connection['jss'].base_url, 'dbfileupload')), data=resource, headers=headers)
    return response

Upload a script to a migrated JSS's database.

On a "migrated" JSS, scripts are POSTed to the JSS. Pass an id
if you wish to associate the script with an existing Script
object, otherwise, it will create a new Script object.

Args:
filename: Path to script file.
id_: Int ID of Script object to associate this file with.
Default is -1, which creates a new Script.


def __call__(self,
            state: Sequence[tf.Tensor],
            timestep: tf.Tensor) -> Sequence[tf.Tensor]:

        return self._default

Returns the default action fluents regardless of the current `state` and `timestep`.

Args:
state (Sequence[tf.Tensor]): The current state fluents.
timestep (tf.Tensor): The current timestep.

Returns:
Sequence[tf.Tensor]: A tuple of action fluents.


def launch_run(self, command, project=None, entity=None, run_id=None):

        query = gql()
        patch = BytesIO()
        if self.git.dirty:
            self.git.repo.git.execute(['git', 'diff'], output_stream=patch)
            patch.seek(0)
        cwd = "."
        if self.git.enabled:
            cwd = cwd + os.getcwd().replace(self.git.repo.working_dir, "")
        return self.gql(query, variable_values={
            'entity': entity or self.settings('entity'),
            'model': project or self.settings('project'),
            'command': command,
            'runId': run_id,
            'patch': patch.read().decode("utf8"),
            'cwd': cwd
        })

Launch a run in the cloud.

Args:
command (str): The command to run
program (str): The file to run
project (str): The project to scope the runs to
entity (str, optional): The entity to scope this project to.  Defaults to public models
run_id (str, optional): The run_id to scope to

Returns:
[{"podName","status"}]


def abs_path(path):
    return os.path.abspath(os.path.expanduser(path))

Resolve the '.' and '~' in a path to get the absolute path.

Args:
path: The path to expand.

Returns:
The absolute path of the input path.


class InformerFeatureEmbedder(nn.Module):

    def __init__(self, cardinalities: List[int], embedding_dims: List[int]) -> None:
        super().__init__()
        self.num_features = len(cardinalities)
        self.embedders = nn.ModuleList([nn.Embedding(c, d) for c, d in zip(cardinalities, embedding_dims)])

    def forward(self, features: torch.Tensor) -> torch.Tensor:
        if self.num_features > 1:
            cat_feature_slices = torch.chunk(features, self.num_features, dim=-1)
        else:
            cat_feature_slices = [features]
        return torch.cat([embed(cat_feature_slice.squeeze(-1)) for embed, cat_feature_slice in zip(self.embedders, cat_feature_slices)], dim=-1)

Embed a sequence of categorical features.

Args:
cardinalities (`list[int]`):
List of cardinalities of the categorical features.
embedding_dims (`list[int]`):
List of embedding dimensions of the categorical features.


def init_backend(self, phonemizer_lang: str):
    requires_backends(self, 'phonemizer')
    from phonemizer.backend import BACKENDS
    self.backend = BACKENDS[self.phonemizer_backend](phonemizer_lang, language_switch='remove-flags')

Initializes the backend.

Args:
phonemizer_lang (`str`): The language to be used.


def serialCmdPwdAuth(self, password_str):

        result = False
        try:
            req_start = "0150310228" + binascii.hexlify(password_str) + "2903"
            req_crc = self.calc_crc16(req_start[2:].decode("hex"))
            req_str = req_start + req_crc
            self.m_serial_port.write(req_str.decode("hex"))
            if self.m_serial_port.getResponse(self.getContext()).encode("hex") == "06":
                ekm_log("Password accepted (" + self.getContext() + ")")
                result = True
            else:
                ekm_log("Password call failure no 06(" + self.getContext() + ")")
        except:
            ekm_log("Password call failure by exception(" + self.getContext() + ")")

            ekm_log(traceback.format_exc(sys.exc_info()))

        return result

Password step of set commands

This method is normally called within another serial command, so it
does not issue a termination string.  Any default password is set
in the caller parameter list, never here.

Args:
password_str (str): Required password.

Returns:
bool: True on completion and ACK.


def decode_conjure_union_type(cls, obj, conjure_type):
    type_of_union = obj['type']
    for (attr, conjure_field) in conjure_type._options().items():
        if (conjure_field.identifier == type_of_union):
            attribute = attr
            conjure_field_definition = conjure_field
            break
    else:
        raise ValueError('unknown union type {0} for {1}'.format(type_of_union, conjure_type))
    deserialized = {}
    if ((type_of_union not in obj) or (obj[type_of_union] is None)):
        cls.check_null_field(obj, deserialized, conjure_field_definition)
    else:
        value = obj[type_of_union]
        field_type = conjure_field_definition.field_type
        deserialized[attribute] = cls.do_decode(value, field_type)
    return conjure_type(**deserialized)

Decodes json into a conjure union type.

Args:
obj: the json object to decode
conjure_type: a class object which is the union type
we're decoding into
Returns:
An instance of type conjure_type.


def init_config_json(config_file):

    json_data = None
    try:
        if os.path.exists(config_file):

            with open(config_file) as json_file:
                json_data = json.load(json_file)
                return unicode_convert(json_data)
        else:
            return None
    except:
        line, filename, synerror = trace()
        raise ArcRestHelperError({
                    "function": "init_config_json",
                    "line": line,
                    "filename":  filename,
                    "synerror": synerror,
                                    }
                                    )
    finally:
        json_data = None

        del json_data

        gc.collect()

Deserializes a JSON configuration file.

Args:
config_file (str): The path to the JSON file.
Returns:
dict: A dictionary object containing the JSON data. If ``config_file`` does not exist, returns ``None``.


def add_sync_methods(cls):

  for name in cls.__dict__.keys():
    if name.endswith('_async'):
      sync_name = name[:-6]
      if not hasattr(cls, sync_name):
        setattr(cls, sync_name, _make_sync_method(name))
  return cls

Class decorator to add synchronous methods corresponding to async methods.

This modifies the class in place, adding additional methods to it.
If a synchronous method of a given name already exists it is not
replaced.

Args:
cls: A class.

Returns:
The same class, modified in place.


def load_validation_plugin(name=None):

    if not name:
        return BaseValidationRules

    plugin = None
    for entry_point in iter_entry_points('bigchaindb.validation', name):
        plugin = entry_point.load()

    if not plugin:
        raise ResolutionError(
            'No plugin found in group `bigchaindb.validation` with name `{}`'.
            format(name))

    if not issubclass(plugin, (BaseValidationRules,)):
        raise TypeError('object of type "{}" does not implement `bigchaindb.'
                        'validation.BaseValidationRules`'.format(type(plugin)))

    return plugin

Find and load the chosen validation plugin.

Args:
name (string): the name of the entry_point, as advertised in the
setup.py of the providing package.

Returns:
an uninstantiated subclass of ``bigchaindb.validation.AbstractValidationRules``


async def selfplay(state, flagfile='selfplay'):

  output_dir = os.path.join(fsdb.selfplay_dir(), state.output_model_name)
  holdout_dir = os.path.join(fsdb.holdout_dir(), state.output_model_name)

  lines = await run(
      'bazel-bin/cc/selfplay',
      '--flagfile={}.flags'.format(os.path.join(FLAGS.flags_dir, flagfile)),
      '--model={}'.format(state.best_model_path),
      '--output_dir={}'.format(output_dir),
      '--holdout_dir={}'.format(holdout_dir),
      '--seed={}'.format(state.seed))
  result = '\n'.join(lines[-6:])
  logging.info(result)
  stats = parse_win_stats_table(result, 1)[0]
  num_games = stats.total_wins
  logging.info('Black won %0.3f, white won %0.3f',
               stats.black_wins.total / num_games,
               stats.white_wins.total / num_games)

  pattern = os.path.join(output_dir, '*', '*.zz')
  random.seed(state.seed)
  tf.set_random_seed(state.seed)
  np.random.seed(state.seed)

  buffer = example_buffer.ExampleBuffer(sampling_frac=1.0)

  logging.info('Writing golden chunk from "{}"'.format(pattern))
  buffer.parallel_fill(tf.gfile.Glob(pattern))
  buffer.flush(os.path.join(fsdb.golden_chunk_dir(),
                            state.output_model_name + '.tfrecord.zz'))

Run selfplay and write a training chunk to the fsdb golden_chunk_dir.

Args:
state: the RL loop State instance.
flagfile: the name of the flagfile to use for selfplay, either 'selfplay'
(the default) or 'boostrap'.


def _group_and_publish_tasks_statistics(self, result):
    for i in result:
        executor_id = i['executor_id']
        i['executor_id'] = executor_id[:executor_id.rfind('.')]
        i['statistics']['instances_count'] = 1
    r = {}
    for i in result:
        executor_id = i['executor_id']
        r[executor_id] = r.get(executor_id, {})
        r[executor_id]['framework_id'] = i['framework_id']
        r[executor_id]['statistics'] = r[executor_id].get('statistics', {})
        r[executor_id]['statistics'] = self._sum_statistics(i['statistics'], r[executor_id]['statistics'])
    self._add_cpu_usage(r)
    self._add_cpu_percent(r)
    self._add_mem_percent(r)
    self._publish(r)

This function group statistics of same tasks by adding them.
It also add 'instances_count' statistic to get information about
how many instances is running on the server

Args:
result: result of mesos query. List of dictionaries with
'executor_id', 'framework_id' as a strings and 'statistics'
as dictionary of labeled numbers


def find_dependencies(self, dataset_keys, **dfilter):

        unknown_datasets = set()
        for key in dataset_keys.copy():
            n, unknowns = self._find_dependencies(key, **dfilter)

            dataset_keys.discard(key)
            if n is not None:
                dataset_keys.add(n.name)
            if unknowns:
                unknown_datasets.update(unknowns)
                continue

            self.add_child(self, n)

        return unknown_datasets

Create the dependency tree.

Args:
dataset_keys (iterable): Strings or DatasetIDs to find dependencies for
**dfilter (dict): Additional filter parameters. See
`satpy.readers.get_key` for more details.

Returns:
(Node, set): Root node of the dependency tree and a set of unknown datasets


def run_cm(cm, time_scale):
    cm = np.linalg.matrix_power(cm, time_scale)
    cm[(cm > 1)] = 1
    return cm

Iterate a connectivity matrix the specified number of steps.

Args:
cm (np.ndarray): A connectivity matrix.
time_scale (int): The number of steps to run.

Returns:
np.ndarray: The connectivity matrix at the new timescale.


def CheckVlogArguments(filename, clean_lines, linenum, error):

  line = clean_lines.elided[linenum]
  if Search(r'\bVLOG\((INFO|ERROR|WARNING|DFATAL|FATAL)\)', line):
    error(filename, linenum, 'runtime/vlog', 5,
          'VLOG() should be used with numeric verbosity level.  '
          'Use LOG() if you want symbolic severity levels.')

Checks that VLOG() is only used for defining a logging level.

For example, VLOG(2) is correct. VLOG(INFO), VLOG(WARNING), VLOG(ERROR), and
VLOG(FATAL) are not.

Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
error: The function to call with any errors found.


def clean_output_files(self, follow_parents=True):

        paths = []
        if self.status != self.S_OK:
            logger.warning("Calling task.clean_output_files on a task whose status != S_OK")

        self.tmpdir.clean()

        except_exts = set()
        for child in self.get_children():
            if child.status == self.S_OK: continue

            i = [dep.node for dep in child.deps].index(self)
            except_exts.update(child.deps[i].exts)

        exts = self.gc.exts.difference(except_exts)

        paths += self.outdir.remove_exts(exts)
        if not follow_parents: return paths

        for parent in self.get_parents():

            ext2nodes = collections.defaultdict(list)
            for child in parent.get_children():
                if child.status == child.S_OK: continue
                i = [d.node for d in child.deps].index(parent)
                for ext in child.deps[i].exts:
                    ext2nodes[ext].append(child)

            except_exts = [k for k, lst in ext2nodes.items() if lst]
            exts = self.gc.exts.difference(except_exts)

            paths += parent.outdir.remove_exts(exts)

        self.history.info("Removed files: %s" % paths)
        return paths

This method is called when the task reaches S_OK. It removes all the output files
produced by the task that are not needed by its children as well as the output files
produced by its parents if no other node needs them.

Args:
follow_parents: If true, the output files of the parents nodes will be removed if possible.

Return:
list with the absolute paths of the files that have been removed.


def GetSysFeeAmountByHeight(self, height):

        hash = self.GetBlockHash(height)
        return self.GetSysFeeAmount(hash)

Get the system fee for the specified block.

Args:
height (int): block height.

Returns:
int:


def merge_csv(filenames: List[str],
              outfile: TextIO = sys.stdout,
              input_dialect: str = 'excel',
              output_dialect: str = 'excel',
              debug: bool = False,
              headers: bool = True) -> None:

    writer = csv.writer(outfile, dialect=output_dialect)
    written_header = False
    header_items = []
    for filename in filenames:
        log.info("Processing file " + repr(filename))
        with open(filename, 'r') as f:
            reader = csv.reader(f, dialect=input_dialect)
            if headers:
                if not written_header:
                    header_items = next(reader)
                    if debug:
                        log.debug("Header row: {!r}", header_items)
                    writer.writerow(header_items)
                    written_header = True
                else:
                    new_headers = next(reader)
                    if new_headers != header_items:
                        raise ValueError(
                            "Header line in file {filename} doesn't match - "
                            "it was {new} but previous was {old}".format(
                                filename=repr(filename),
                                new=repr(new_headers),
                                old=repr(header_items),
                            ))
                    if debug:
                        log.debug("Header row matches previous")
            else:
                if debug:
                    log.debug("No headers in use")
            for row in reader:
                if debug:
                    log.debug("Data row: {!r}", row)
                writer.writerow(row)

Amalgamate multiple CSV/TSV/similar files into one.

Args:
filenames: list of filenames to process
outfile: file-like object to write output to
input_dialect: dialect of input files, as passed to ``csv.reader``
output_dialect: dialect to write, as passed to ``csv.writer``
debug: be verbose?
headers: do the files have header lines?


def parse_keys(self, sn: 'DataNode') -> Dict[(InstanceName, ScalarValue)]:
    res = {}
    for k in self.keys:
        knod = sn.get_data_child(*k)
        if (knod is None):
            raise NonexistentSchemaNode(sn.qual_name, *k)
        kval = knod.type.parse_value(self.keys[k])
        if (kval is None):
            raise InvalidKeyValue(self.keys[k])
        res[knod.iname()] = kval
    return res

Parse key dictionary in the context of a schema node.

Args:
sn: Schema node corresponding to a list.


def van_enc_2d(x, first_depth, reuse=False):

  with tf.variable_scope('van_enc', reuse=reuse):
    a = 4
    b = 4

    enc = tf.nn.relu(x)
    enc = tf.layers.dense(enc, first_depth * a * b, tf.nn.relu)
    enc = tf.contrib.layers.layer_norm(enc)

    enc = tf.reshape(enc, [-1, a, b, first_depth])

    enc = tf.layers.conv2d_transpose(
        enc, first_depth, 3, padding='same', activation=tf.nn.relu, strides=1)
    enc = tf.contrib.layers.layer_norm(enc)
    enc = tf.layers.conv2d_transpose(
        enc,
        first_depth * 2,
        3,
        padding='same',
        activation=tf.nn.relu,
        strides=2)
    van_higher_level_2 = tf.reshape(enc, [-1, a * 2 * b * 2 * first_depth * 2])

    enc = tf.layers.conv2d_transpose(
        enc,
        first_depth * 2,
        3,
        padding='same',
        activation=tf.nn.relu,
        strides=1)
    enc = tf.contrib.layers.layer_norm(enc)
    enc = tf.layers.conv2d_transpose(
        enc,
        first_depth * 4,
        3,
        padding='same',
        activation=tf.nn.relu,
        strides=1)
    van_higher_level_4 = tf.reshape(enc, [-1, a * 2 * b * 2 * first_depth * 4])

    van_higher_level = tf.concat([x, van_higher_level_2, van_higher_level_4], 1)

    return enc, van_higher_level

The higher level structure encoder for the VAN.

The high level structure is a vector instead of an image.

Args:
x: The higher level structure to encode.
first_depth: The depth of the first layer. Depth is increased in subsequent
layers.
reuse: To reuse in variable scope or not.

Returns:
The encoded image.


def get_descriptor_defaults(self, api_info, hostname=None):

    hostname = (hostname or endpoints_util.get_app_hostname() or
                api_info.hostname)
    protocol = 'http' if ((hostname and hostname.startswith('localhost')) or
                          endpoints_util.is_running_on_devserver()) else 'https'
    base_path = api_info.base_path.strip('/')
    defaults = {
        'extends': 'thirdParty.api',
        'root': '{0}:
        'name': api_info.name,
        'version': api_info.api_version,
        'api_version': api_info.api_version,
        'path_version': api_info.path_version,
        'defaultVersion': True,
        'abstract': False,
        'adapter': {
            'bns': '{0}:
            'type': 'lily',
            'deadline': 10.0
        }
    }
    if api_info.canonical_name:
      defaults['canonicalName'] = api_info.canonical_name
    if api_info.owner_domain:
      defaults['ownerDomain'] = api_info.owner_domain
    if api_info.owner_name:
      defaults['ownerName'] = api_info.owner_name
    if api_info.package_path:
      defaults['packagePath'] = api_info.package_path
    if api_info.title:
      defaults['title'] = api_info.title
    if api_info.documentation:
      defaults['documentation'] = api_info.documentation
    return defaults

Gets a default configuration for a service.

Args:
api_info: _ApiInfo object for this service.
hostname: string, Hostname of the API, to override the value set on the
current service. Defaults to None.

Returns:
A dictionary with the default configuration.


def query_icao(icao: str):

        params = {
            'dataSource': 'metars',
            'requestType': 'retrieve',
            'format': 'csv',
            'hoursBeforeNow': 24,
        }
        AWC._validate_icao(icao)
        params['stationString'] = icao
        try:
            return AWC._query(params)
        except RequestsConnectionError:
            raise AWCRequestFailed('failed to obtain requested data from AWC')

Queries AWC for the METAR of a given station

Args:
icao: station ID as a four letters-digits ICAO code

Returns: AWC result for the station


def recipe_dv360_segmentology(config, auth_read, recipe_timezone, auth_write, recipe_name, date_range, recipe_slug, partners, advertisers):
    dataset(config, {'description': 'Create a dataset for bigquery tables.', 'hour': [4], 'auth': auth_write, 'dataset': recipe_slug})
    bigquery(config, {'auth': auth_write, 'function': 'Pearson Significance Test', 'to': {'dataset': recipe_slug}})
    dbm(config, {'auth': auth_read, 'report': {'filters': {'FILTER_PARTNER': {'values': partners}, 'FILTER_ADVERTISER': {'values': advertisers}}, 'body': {'timezoneCode': recipe_timezone, 'metadata': {'title': recipe_name, 'dataRange': date_range, 'format': 'CSV'}, 'params': {'type': 'TYPE_CROSS_PARTNER', 'groupBys': ['FILTER_PARTNER', 'FILTER_PARTNER_NAME', 'FILTER_ADVERTISER', 'FILTER_ADVERTISER_NAME', 'FILTER_MEDIA_PLAN', 'FILTER_MEDIA_PLAN_NAME', 'FILTER_ZIP_POSTAL_CODE'], 'metrics': ['METRIC_BILLABLE_IMPRESSIONS', 'METRIC_CLICKS', 'METRIC_TOTAL_CONVERSIONS']}, 'schedule': {'frequency': 'WEEKLY'}}}})
    dbm(config, {'auth': auth_read, 'report': {'name': recipe_name}, 'out': {'bigquery': {'auth': auth_write, 'dataset': recipe_slug, 'table': 'DV360_KPI', 'header': True, 'schema': [{'name': 'Partner_Id', 'type': 'INTEGER', 'mode': 'REQUIRED'}, {'name': 'Partner', 'type': 'STRING', 'mode': 'REQUIRED'}, {'name': 'Advertiser_Id', 'type': 'INTEGER', 'mode': 'REQUIRED'}, {'name': 'Advertiser', 'type': 'STRING', 'mode': 'REQUIRED'}, {'name': 'Campaign_Id', 'type': 'INTEGER', 'mode': 'REQUIRED'}, {'name': 'Campaign', 'type': 'STRING', 'mode': 'REQUIRED'}, {'name': 'Zip', 'type': 'STRING', 'mode': 'NULLABLE'}, {'name': 'Impressions', 'type': 'FLOAT', 'mode': 'NULLABLE'}, {'name': 'Clicks', 'type': 'FLOAT', 'mode': 'NULLABLE'}, {'name': 'Conversions', 'type': 'FLOAT', 'mode': 'NULLABLE'}]}}})
    bigquery(config, {'auth': auth_write, 'from': {'query': 'SELECT\n          Partner_Id,\n          Partner,\n          Advertiser_Id,\n          Advertiser,\n          Campaign_Id,\n          Campaign,\n          Zip,\n          SAFE_DIVIDE(Impressions, SUM(Impressions) OVER(PARTITION BY Advertiser_Id)) AS Impression,\n          SAFE_DIVIDE(Clicks, Impressions) AS Click,\n          SAFE_DIVIDE(Conversions, Impressions) AS Conversion,\n          Impressions AS Impressions          FROM\n          `{dataset}.DV360_KPI`;        ', 'parameters': {'dataset': recipe_slug}, 'legacy': False}, 'to': {'dataset': recipe_slug, 'view': 'DV360_KPI_Normalized'}})
    census(config, {'auth': auth_write, 'normalize': {'census_geography': 'zip_codes', 'census_year': '2018', 'census_span': '5yr'}, 'to': {'dataset': recipe_slug, 'type': 'view'}})
    census(config, {'auth': auth_write, 'correlate': {'join': 'Zip', 'pass': ['Partner_Id', 'Partner', 'Advertiser_Id', 'Advertiser', 'Campaign_Id', 'Campaign'], 'sum': ['Impressions'], 'correlate': ['Impression', 'Click', 'Conversion'], 'dataset': recipe_slug, 'table': 'DV360_KPI_Normalized', 'significance': 80}, 'to': {'dataset': recipe_slug, 'type': 'view'}})

DV360 funnel analysis using Census data.

Args:
auth_read (authentication) - Credentials used for reading data.
recipe_timezone (timezone) - Timezone for report dates.
auth_write (authentication) - Authorization used for writing data.
recipe_name (string) - Name of report, not needed if ID used.
date_range (choice) - Timeframe to run the report for.
recipe_slug (string) - Name of Google BigQuery dataset to create.
partners (integer_list) - DV360 partner id.
advertisers (integer_list) - Comma delimited list of DV360 advertiser ids.


def delete(self, *, auto_commit=False):
    try:
        db.session.delete(self.resource)
        if auto_commit:
            db.session.commit()
    except SQLAlchemyError:
        self.log.exception('Failed deleting resource: {}'.format(self.id))
        db.session.rollback()

Removes a resource from the database

Args:
auto_commit (bool): Automatically commit the transaction. Default: `False`

Returns:
`None`


class AriaSharedExpertsMLP(LlamaMLP):

    def __init__(self, config: AriaTextConfig):
        super().__init__(self)
        self.intermediate_size = config.intermediate_size * config.moe_num_shared_experts

Shared Expert MLP for shared experts.

Unlike routed experts, shared experts process all tokens without routing.
This class reconfigures the intermediate size in comparison to the LlamaMLP.

Args:
config (`AriaTextConfig`): Configuration object for the Aria language model.


def take_bug_reports(ads, test_name, begin_time, destination=None):
    begin_time = mobly_logger.normalize_log_line_timestamp(str(begin_time))

    def take_br(test_name, begin_time, ad, destination):
        ad.take_bug_report(test_name, begin_time, destination=destination)
    args = [(test_name, begin_time, ad, destination) for ad in ads]
    utils.concurrent_exec(take_br, args)

Takes bug reports on a list of android devices.

If you want to take a bug report, call this function with a list of
android_device objects in on_fail. But reports will be taken on all the
devices in the list concurrently. Bug report takes a relative long
time to take, so use this cautiously.

Args:
ads: A list of AndroidDevice instances.
test_name: Name of the test method that triggered this bug report.
begin_time: timestamp taken when the test started, can be either
string or int.
destination: string, path to the directory where the bugreport
should be saved.


def setup(options):

        if not options.misc.debug:
            requests.packages.urllib3.disable_warnings(
                requests.packages.urllib3.exceptions.InsecureRequestWarning
            )

Initialize debug/logging in third party libraries correctly.

Args:
options (:class:`nyawc.Options`): The options to use for the current crawling runtime.


def _virtual_molecule(self, mol, ilabels, eq_atoms):
    vmol = ob.OBMol()
    non_unique_atoms = set([a for g in eq_atoms for a in g])
    all_atoms = set(range(1, (len(ilabels) + 1)))
    unique_atom_labels = sorted((all_atoms - non_unique_atoms))
    for i in unique_atom_labels:
        orig_idx = ilabels[(i - 1)]
        oa1 = mol.GetAtom(orig_idx)
        a1 = vmol.NewAtom()
        a1.SetAtomicNum(oa1.GetAtomicNum())
        a1.SetVector(oa1.GetVector())
    if (vmol.NumAtoms() < 3):
        for symm in eq_atoms:
            (c1x, c1y, c1z) = self._group_centroid(mol, ilabels, symm)
            min_distance = float('inf')
            for i in range(1, (vmol.NumAtoms() + 1)):
                va = vmol.GetAtom(i)
                distance = math.sqrt(((((c1x - va.x()) ** 2) + ((c1y - va.y()) ** 2)) + ((c1z - va.z()) ** 2)))
                if (distance < min_distance):
                    min_distance = distance
            if (min_distance > 0.2):
                a1 = vmol.NewAtom()
                a1.SetAtomicNum(9)
                a1.SetVector(c1x, c1y, c1z)
    return vmol

Create a virtual molecule by unique atoms, the centriods of the
equivalent atoms

Args:
mol: The molecule. OpenBabel OBMol object
ilables: inchi label map
eq_atoms: equivalent atom labels
farthest_group_idx: The equivalent atom group index in which
there is the farthest atom to the centroid

Return:
The virtual molecule


def lu_slogdet(LU):
    LU = (asarray(LU[0], float), asarray(LU[1], float))
    adet = _sum(log(_abs(LU[0].diagonal())))
    s = prod(sign(LU[0].diagonal()))
    nrows_exchange = (LU[1].size - _sum((LU[1] == arange(LU[1].size, dtype='int32'))))
    odd = ((nrows_exchange % 2) == 1)
    if odd:
        s *= (- 1.0)
    return (s, adet)

r"""Natural logarithm of a LU decomposition.

Args:
LU (tuple): LU decomposition.

Returns:
tuple: sign and log-determinant.


def save(self, filething=None, padding=None):

        self.to_content_description = {}
        self.to_extended_content_description = {}
        self.to_metadata = {}
        self.to_metadata_library = []
        for name, value in self.tags:
            library_only = (value.data_size() > 0xFFFF or value.TYPE == GUID)
            can_cont_desc = value.TYPE == UNICODE

            if library_only or value.language is not None:
                self.to_metadata_library.append((name, value))
            elif value.stream is not None:
                if name not in self.to_metadata:
                    self.to_metadata[name] = value
                else:
                    self.to_metadata_library.append((name, value))
            elif name in ContentDescriptionObject.NAMES:
                if name not in self.to_content_description and can_cont_desc:
                    self.to_content_description[name] = value
                else:
                    self.to_metadata_library.append((name, value))
            else:
                if name not in self.to_extended_content_description:
                    self.to_extended_content_description[name] = value
                else:
                    self.to_metadata_library.append((name, value))

        header = self._header
        if header.get_child(ContentDescriptionObject.GUID) is None:
            header.objects.append(ContentDescriptionObject())
        if header.get_child(ExtendedContentDescriptionObject.GUID) is None:
            header.objects.append(ExtendedContentDescriptionObject())
        header_ext = header.get_child(HeaderExtensionObject.GUID)
        if header_ext is None:
            header_ext = HeaderExtensionObject()
            header.objects.append(header_ext)
        if header_ext.get_child(MetadataObject.GUID) is None:
            header_ext.objects.append(MetadataObject())
        if header_ext.get_child(MetadataLibraryObject.GUID) is None:
            header_ext.objects.append(MetadataLibraryObject())

        fileobj = filething.fileobj

        old_size = header.parse_size(fileobj)[0]
        data = header.render_full(self, fileobj, old_size, padding)
        size = len(data)
        resize_bytes(fileobj, old_size, size, 0)
        fileobj.seek(0)
        fileobj.write(data)

save(filething=None, padding=None)

Save tag changes back to the loaded file.

Args:
filething (filething)
padding (:obj:`mutagen.PaddingFunction`)
Raises:
mutagen.MutagenError


def read_submissions_from_directory(dirname, use_gpu):

  result = []
  for sub_dir in os.listdir(dirname):
    submission_path = os.path.join(dirname, sub_dir)
    try:
      if not os.path.isdir(submission_path):
        continue
      if not os.path.exists(os.path.join(submission_path, 'metadata.json')):
        continue
      with open(os.path.join(submission_path, 'metadata.json')) as f:
        metadata = json.load(f)
      if use_gpu and ('container_gpu' in metadata):
        container = metadata['container_gpu']
      else:
        container = metadata['container']
      entry_point = metadata['entry_point']
      submission_type = metadata['type']
      if submission_type == 'attack' or submission_type == 'targeted_attack':
        submission = Attack(submission_path, container, entry_point, use_gpu)
      elif submission_type == 'defense':
        submission = Defense(submission_path, container, entry_point, use_gpu)
      else:
        raise ValueError('Invalid type of submission: %s' % submission_type)
      result.append(submission)
    except (IOError, KeyError, ValueError):
      print('Failed to read submission from directory ', submission_path)
  return result

Scans directory and read all submissions.

Args:
dirname: directory to scan.
use_gpu: whether submissions should use GPU. This argument is
used to pick proper Docker container for each submission and create
instance of Attack or Defense class.

Returns:
List with submissions (subclasses of Submission class).


def from_api_repr(cls, resource, client):

        job_ref_properties = resource.get("jobReference", {"projectId": client.project})
        job_ref = _JobReference._from_api_repr(job_ref_properties)
        job = cls(job_ref, client)

        resource["jobReference"] = job_ref_properties
        job._properties = resource
        return job

Construct an UnknownJob from the JSON representation.

Args:
resource (dict): JSON representation of a job.
client (google.cloud.bigquery.client.Client):
Client connected to BigQuery API.

Returns:
UnknownJob: Job corresponding to the resource.


def set(self, value):
    pywrap_tfe.TFE_MonitoringBoolGaugeCellSet(self._cell, value)

Atomically set the value.

Args:
value: bool value.


def delete_handler(Model, name=None, **kwds):
    from nautilus.database import db

    async def action_handler(service, action_type, payload, props, notify=True, **kwds):
        if (action_type == get_crud_action('delete', (name or Model))):
            try:
                message_props = {}
                if ('correlation_id' in props):
                    message_props['correlation_id'] = props['correlation_id']
                record_id = (payload['id'] if ('id' in payload) else payload['pk'])
                try:
                    model_query = Model.select().where((Model.primary_key() == record_id))
                except KeyError:
                    raise RuntimeError('Could not find appropriate id to remove service record.')
                model_query.get().delete_instance()
                if notify:
                    (await service.event_broker.send(payload='{"status":"ok"}', action_type=change_action_status(action_type, success_status()), **message_props))
            except Exception as err:
                if notify:
                    (await service.event_broker.send(payload=str(err), action_type=change_action_status(action_type, error_status()), **message_props))
                else:
                    raise err
    return action_handler

This factory returns an action handler that deletes a new instance of
the specified model when a delete action is recieved, assuming the
action follows nautilus convetions.

Args:
Model (nautilus.BaseModel): The model to delete when the action
received.

Returns:
function(type, payload): The action handler for this model


def _post(self, url, data, scope):
    self._create_session(scope)
    response = self.session.post(url, data=data)
    return (response.status_code, response.text)

Make a POST request using the session object to a Degreed endpoint.

Args:
url (str): The url to send a POST request to.
data (str): The json encoded payload to POST.
scope (str): Must be one of the scopes Degreed expects:
- `CONTENT_PROVIDER_SCOPE`
- `COMPLETION_PROVIDER_SCOPE`


def delete(self, main_type, sub_type, unique_id, owner=None):

        params = {'owner': owner} if owner else {}
        if not sub_type:
            url = '/v2/{}/{}'.format(main_type, unique_id)
        else:
            url = '/v2/{}/{}/{}'.format(main_type, sub_type, unique_id)
        return self.tcex.session.delete(url, params=params)

Deletes the Indicator/Group/Victim or Security Label
Args:
main_type:
sub_type:
unique_id:
owner:


def set_string(self, option, value):
    if (not isinstance(value, str)):
        raise TypeError(('%s must be a string' % option))
    self.options[option] = value

Set a string option.

Args:
option (str): name of option.
value (str): value of the option.

Raises:
TypeError: Value must be a string.


def group_associations(self, main_type, sub_type, unique_id, owner=None, params=None):

        params = params or {}
        if owner:
            params['owner'] = owner

        if not sub_type:
            url = '/v2/{}/{}/groups'.format(main_type, unique_id)
        else:
            url = '/v2/{}/{}/{}/groups'.format(main_type, sub_type, unique_id)

        for ga in self._iterate(url, params, 'group'):
            yield ga

Args:
owner:
main_type:
sub_type:
unique_id:
params:

Return:


def get_cached_filename(self, filename, extention, settings_list=None):
    cached_name = '_'.join([filename, self.get_hash()])
    return '.'.join([cached_name, extention])

Creates a filename with md5 cache string based on settings list

Args:
filename (str): the filename without extention
extention (str): the file extention without dot. (i.e. 'pkl')
settings_list (dict|list): the settings list as list (optional)
NB! The dictionaries have to be sorted or hash id will change
arbitrarely.


def delete(self, table_name):

        dataset = Dataset(self, table_name)
        deleted = dataset.delete()
        if deleted:
            return deleted

        raise CartoException(.format(table_name))

Delete a table in user's CARTO account.

Args:
table_name (str): Name of table to delete

Returns:
bool: `True` if table is removed


def relu6(x):
    if any_symbolic_tensors((x,)):
        return Relu6().symbolic_call(x)
    return backend.nn.relu6(x)

Rectified linear unit activation function with upper bound of 6.

It is defined as `f(x) = np.clip(x, 0, 6)`.

Args:
x: Input tensor.

Returns:
A tensor with the same shape as `x`.

Example:

>>> x = keras.ops.convert_to_tensor([-3.0, -2.0, 0.1, 0.2, 6.0, 8.0])
>>> keras.ops.relu6(x)
array([0.0, 0.0, 0.1, 0.2, 6.0, 6.0], dtype=float32)


def normalized_start(self):
    namespaces_after_key = list(self.make_datastore_query().Run(limit=1))
    if (not namespaces_after_key):
        return None
    namespace_after_key = (namespaces_after_key[0].name() or '')
    return NamespaceRange(namespace_after_key, self.namespace_end, _app=self.app)

Returns a NamespaceRange with leading non-existant namespaces removed.

Returns:
A copy of this NamespaceRange whose namespace_start is adjusted to exclude
the portion of the range that contains no actual namespaces in the
datastore. None is returned if the NamespaceRange contains no actual
namespaces in the datastore.


def create_binary_descriptor(descriptor):

    func_names = {0: 'copy_latest_a', 1: 'average_a',
                  2: 'copy_all_a', 3: 'sum_a',
                  4: 'copy_count_a', 5: 'trigger_streamer',
                  6: 'call_rpc', 7: 'subtract_afromb'}

    func_codes = {y: x for x, y in func_names.items()}

    node, inputs, processing = parse_node_descriptor(descriptor, DeviceModel())

    func_code = func_codes.get(processing)
    if func_code is None:
        raise ArgumentError("Unknown processing function", function=processing)

    stream_a, trigger_a = inputs[0]
    stream_a = stream_a.encode()

    if len(inputs) == 2:
        stream_b, trigger_b = inputs[1]
        stream_b = stream_b.encode()
    else:
        stream_b, trigger_b = 0xFFFF, None

    if trigger_a is None:
        trigger_a = TrueTrigger()

    if trigger_b is None:
        trigger_b = TrueTrigger()

    ref_a = 0
    if isinstance(trigger_a, InputTrigger):
        ref_a = trigger_a.reference

    ref_b = 0
    if isinstance(trigger_b, InputTrigger):
        ref_b = trigger_b.reference

    trigger_a = _create_binary_trigger(trigger_a)
    trigger_b = _create_binary_trigger(trigger_b)

    combiner = node.trigger_combiner

    bin_desc = struct.pack("<LLHHHBBBB2x", ref_a, ref_b, node.stream.encode(), stream_a, stream_b, func_code, trigger_a, trigger_b, combiner)
    return bin_desc

Convert a string node descriptor into a 20-byte binary descriptor.

This is the inverse operation of parse_binary_descriptor and composing
the two operations is a noop.

Args:
descriptor (str): A string node descriptor

Returns:
bytes: A 20-byte binary node descriptor.


def world_info(world_name, world_config=None, initial_indent="", next_indent="  "):

    if world_config is None:
        for config, _ in _iter_packages():
            for world in config["maps"]:
                if world["name"] == world_name:
                    world_config = world

    if world_config is None:
        raise HolodeckException("Couldn't find world " + world_name)

    second_indent = initial_indent + next_indent
    agent_indent = second_indent + next_indent
    sensor_indent = agent_indent + next_indent

    print(initial_indent, world_config["name"])
    print(second_indent, "Resolution:", world_config["window_width"], "x", world_config["window_height"])
    print(second_indent, "Agents:")
    for agent in world_config["agents"]:
        print(agent_indent, "Name:", agent["agent_name"])
        print(agent_indent, "Type:", agent["agent_type"])
        print(agent_indent, "Sensors:")
        for sensor in agent["sensors"]:
            print(sensor_indent, sensor)

Gets and prints the information of a world.

Args:
world_name (str): the name of the world to retrieve information for
world_config (dict optional): A dictionary containing the world's configuration. Will find the config if None. Defaults to None.
initial_indent (str optional): This indent will apply to each output line. Defaults to "".
next_indent (str optional): This indent will be applied within each nested line. Defaults to "  ".


def clip_gradient(net, clip_value_min, clip_value_max, name=None):
    if (not net.dtype.is_floating):
        raise ValueError('clip_gradient does not support non-float `net` inputs.')
    with tf.name_scope(name, 'clip_gradient', values=[net]):
        dtype = net.dtype.base_dtype
        min_tensor = tf.convert_to_tensor(clip_value_min, dtype=dtype)
        max_tensor = tf.convert_to_tensor(clip_value_max, dtype=dtype)
        clip_gradient_op = _clip_gradient_op(dtype)
        output = clip_gradient_op(net, min_tensor, max_tensor)
        output.set_shape(net.get_shape())
    return output

Clips respective gradients of a given tensor.

Acts as identity for the forward pass, but clips gradient tensor element-wise
by value during the backward pass. Any gradient values less than
`clip_value_min` or greater than `clip_values_max` are set to the respective
limit values.

Args:
net: A `tf.Tensor`.
clip_value_min: A 0-D Tensor or scalar. The minimum value to clip by.
clip_value_max: A 0-D Tensor or scalar. The maximum value to clip by.
name: A name for the operation (optional, default 'clip_gradient').

Returns:
A `tf.Tensor` with the same type as the input tensor.

Raises:
ValueError: If `net` dtype is non-float.


def _get_oauth2_client_id_and_secret(settings_instance):
    secret_json = getattr(settings_instance, 'GOOGLE_OAUTH2_CLIENT_SECRETS_JSON', None)
    if (secret_json is not None):
        return _load_client_secrets(secret_json)
    else:
        client_id = getattr(settings_instance, 'GOOGLE_OAUTH2_CLIENT_ID', None)
        client_secret = getattr(settings_instance, 'GOOGLE_OAUTH2_CLIENT_SECRET', None)
        if ((client_id is not None) and (client_secret is not None)):
            return (client_id, client_secret)
        else:
            raise exceptions.ImproperlyConfigured('Must specify either GOOGLE_OAUTH2_CLIENT_SECRETS_JSON, or both GOOGLE_OAUTH2_CLIENT_ID and GOOGLE_OAUTH2_CLIENT_SECRET in settings.py')

Initializes client id and client secret based on the settings.

Args:
settings_instance: An instance of ``django.conf.settings``.

Returns:
A 2-tuple, the first item is the client id and the second
item is the client secret.