def dag_to_circuit(dag):

    qregs = collections.OrderedDict()
    for qreg in dag.qregs.values():
        qreg_tmp = QuantumRegister(qreg.size, name=qreg.name)
        qregs[qreg.name] = qreg_tmp
    cregs = collections.OrderedDict()
    for creg in dag.cregs.values():
        creg_tmp = ClassicalRegister(creg.size, name=creg.name)
        cregs[creg.name] = creg_tmp

    name = dag.name or None
    circuit = QuantumCircuit(*qregs.values(), *cregs.values(), name=name)

    for node in dag.topological_op_nodes():
        qubits = []
        for qubit in node.qargs:
            qubits.append(qregs[qubit[0].name][qubit[1]])

        clbits = []
        for clbit in node.cargs:
            clbits.append(cregs[clbit[0].name][clbit[1]])

        if node.condition is None:
            control = None
        else:
            control = (node.condition[0], node.condition[1])

        inst = node.op.copy()
        inst.control = control
        circuit.append(inst, qubits, clbits)
    return circuit

Build a ``QuantumCircuit`` object from a ``DAGCircuit``.

Args:
dag (DAGCircuit): the input dag.

Return:
QuantumCircuit: the circuit representing the input dag.


def call(self, input_ids: Optional[tf.Tensor]=None, position_ids: Optional[tf.Tensor]=None, token_type_ids: Optional[tf.Tensor]=None, inputs_embeds: Optional[tf.Tensor]=None, training: bool=False) -> tf.Tensor:
    assert not (input_ids is None and inputs_embeds is None)
    if input_ids is not None:
        input_shape = shape_list(input_ids)
    else:
        input_shape = shape_list(inputs_embeds)[:-1]
    seq_length = input_shape[1]
    if token_type_ids is None:
        token_type_ids = tf.fill(dims=input_shape + [self.number_of_token_type_embeddings], value=0)
    if position_ids is None:
        position_ids = tf.expand_dims(tf.range(start=0, limit=seq_length), axis=0)
        position_ids = tf.broadcast_to(position_ids, shape=input_shape)
        if self.reset_position_index_per_cell:
            col_index = IndexMap(token_type_ids[:, :, 1], self.config.type_vocab_sizes[1], batch_dims=1)
            row_index = IndexMap(token_type_ids[:, :, 2], self.config.type_vocab_sizes[2], batch_dims=1)
            full_index = ProductIndexMap(col_index, row_index)
            first_position_per_segment = reduce_min(position_ids, full_index)[0]
            first_position = gather(first_position_per_segment, full_index)
            position = tf.expand_dims(tf.range(start=0, limit=seq_length), axis=0)
            position_ids = tf.math.minimum(self.max_position_embeddings - 1, position - first_position)
    if input_ids is not None:
        check_embeddings_within_bounds(input_ids, self.config.vocab_size)
        inputs_embeds = tf.gather(params=self.weight, indices=input_ids)
    position_embeddings = tf.gather(self.position_embeddings, indices=position_ids)
    final_embeddings = inputs_embeds + position_embeddings
    for i in range(self.number_of_token_type_embeddings):
        name = f'token_type_embeddings_{i}'
        final_embeddings += tf.gather(params=getattr(self, name), indices=token_type_ids[:, :, i])
    final_embeddings = self.LayerNorm(inputs=final_embeddings)
    final_embeddings = self.dropout(inputs=final_embeddings, training=training)
    return final_embeddings

Applies embedding based on inputs tensor.

Returns:
final_embeddings (`tf.Tensor`): output embedding tensor.


def get_countries(is_legacy_xml=False):

    countries = {}

    if sys.platform == 'win32' and getattr(sys, 'frozen', False):

        data_dir = path.dirname(sys.executable)

    else:

        data_dir = path.dirname(__file__)

    if is_legacy_xml:

        log.debug('Opening country code legacy XML: {0}'.format(
                str(data_dir) + '/data/iso_3166-1_list_en.xml'))

        f = io.open(str(data_dir) + '/data/iso_3166-1_list_en.xml', 'r',
                    encoding='ISO-8859-1')

        data = f.read()

        if not data:

            return {}

        dom = parseString(data)

        entries = dom.getElementsByTagName('ISO_3166-1_Entry')

        for entry in entries:

            code = entry.getElementsByTagName(
                'ISO_3166-1_Alpha-2_Code_element')[0].firstChild.data
            name = entry.getElementsByTagName(
                'ISO_3166-1_Country_name')[0].firstChild.data

            countries[code] = name.title()

    else:

        log.debug('Opening country code CSV: {0}'.format(
                str(data_dir) + '/data/iso_3166-1_list_en.xml'))

        f = io.open(str(data_dir) + '/data/iso_3166-1.csv', 'r',
                    encoding='utf-8')

        csv_reader = csv.reader(f, delimiter=',', quotechar='"')

        for row in csv_reader:

            code = row[0]
            name = row[1]

            countries[code] = name

    return countries

The function to generate a dictionary containing ISO_3166-1 country codes
to names.

Args:
is_legacy_xml (:obj:`bool`): Whether to use the older country code
list (iso_3166-1_list_en.xml).

Returns:
dict: A mapping of country codes as the keys to the country names as
the values.


def get_variant_by_name(self, name):

        try:
            geno = self.df.loc[:, name].values
            info = self.map_info.loc[name, :]

        except KeyError:

            logging.variant_name_not_found(name)
            return []

        else:
            return [Genotypes(
                Variant(info.name, info.chrom, info.pos, [info.a1, info.a2]),
                geno,
                reference=info.a2,
                coded=info.a1,
                multiallelic=False,
            )]

Get the genotypes for a given variant (by name).

Args:
name (str): The name of the variant to retrieve the genotypes.

Returns:
list: A list of Genotypes. This is a list in order to keep the same
behaviour as the other functions.


def write_seq_as_temp_fasta(seq):
    sr = ssbio.protein.sequence.utils.cast_to_seq_record(seq, id='tempfasta')
    return write_fasta_file(seq_records=sr, outname='temp', outdir=tempfile.gettempdir(), force_rerun=True)

Write a sequence as a temporary FASTA file

Args:
seq (str, Seq, SeqRecord): Sequence string, Biopython Seq or SeqRecord object

Returns:
str: Path to temporary FASTA file (located in system temporary files directory)


def get_parts_of_url_path(url):

    parsed = urlparse(url)
    path = unquote(parsed.path).lstrip('/')
    parts = path.split('/')
    return parts

Given a url, take out the path part and split it by '/'.

Args:
url (str): the url slice

returns
list: parts after the domain name of the URL


def as_dataframe(self, pattern='*', max_rows=None):
    data = []
    for (i, group) in enumerate(self.list(pattern)):
        if ((max_rows is not None) and (i >= max_rows)):
            break
        parent = self._group_dict.get(group.parent_id)
        parent_display_name = ('' if (parent is None) else parent.display_name)
        data.append([group.id, group.display_name, group.parent_id, parent_display_name, group.is_cluster, group.filter])
    return pandas.DataFrame(data, columns=self._DISPLAY_HEADERS)

Creates a pandas dataframe from the groups that match the filters.

Args:
pattern: An optional pattern to further filter the groups. This can
include Unix shell-style wildcards. E.g. ``"Production *"``,
``"*-backend"``.
max_rows: The maximum number of groups to return. If None, return all.

Returns:
A pandas dataframe containing matching groups.


def create_releasenotes(project_dir=os.curdir, bugtracker_url=''):

    pkg_info_file = os.path.join(project_dir, 'PKG-INFO')
    if os.path.exists(pkg_info_file):
        return

    with open('RELEASE_NOTES', 'wb') as releasenotes_fd:
        releasenotes_fd.write(
            get_releasenotes(
                project_dir=project_dir,
                bugtracker_url=bugtracker_url,
            ).encode('utf-8') + b'\n'
        )

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

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

Returns:
None

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


def post_create_app(cls, app, **settings):
    register_errorhandler = settings.pop('register_errorhandler', True)
    if register_errorhandler:
        AppException.register_errorhandler(app)
    return app

Register the errorhandler for the AppException to the passed in
App.

Args:
app (fleaker.base.BaseApplication): A Flask application that
extends the Fleaker Base Application, such that the hooks are
implemented.

Kwargs:
register_errorhandler (bool): A boolean indicating if we want to
automatically register an errorhandler for the
:class:`AppException` exception class after we create this App.
Pass ``False`` to prevent registration. Default is ``True``.

Returns:
fleaker.base.BaseApplication: Returns the app it was given.


def _AggregatedGrads(grads, op, gradient_uid, loop_state, aggregation_method=None):
    if aggregation_method is None:
        aggregation_method = AggregationMethod.DEFAULT
    valid_aggregation_methods = [AggregationMethod.ADD_N, AggregationMethod.EXPERIMENTAL_TREE, AggregationMethod.EXPERIMENTAL_ACCUMULATE_N]
    if aggregation_method not in valid_aggregation_methods:
        raise ValueError(f'Invalid `aggregation_method` specified {aggregation_method}. Accepted values are {valid_aggregation_methods}.')
    out_grads = _GetGrads(grads, op)
    for i, out_grad in enumerate(out_grads):
        if loop_state:
            if isinstance(out_grad, (tensor_lib.Tensor, indexed_slices.IndexedSlices)):
                assert control_flow_util.IsLoopSwitch(op)
                continue
        if isinstance(out_grad, collections_abc.Sequence) and (not all((isinstance(g, (tensor_lib.Tensor, indexed_slices.IndexedSlices)) for g in out_grad if g is not None))):
            raise TypeError(f'Invalid gradient {out_grad} [index = {i}]. Gradients have to be either all Tensors or all IndexedSlices')
        if out_grad:
            if len(out_grad) < 2:
                used = 'nop'
                out_grads[i] = out_grad[0]
            elif all((isinstance(g, tensor_lib.Tensor) for g in out_grad if g is not None)):
                tensor_shape = _AccumulatorShape(out_grad)
                if aggregation_method in [AggregationMethod.EXPERIMENTAL_TREE, AggregationMethod.EXPERIMENTAL_ACCUMULATE_N]:
                    used = 'tree'
                    with ops.name_scope(op.name + '_gradient_sum'):
                        running_sum = out_grad[0]
                        for grad in out_grad[1:]:
                            running_sum = math_ops.add_n([running_sum, grad])
                        out_grads[i] = running_sum
                else:
                    used = 'add_n'
                    out_grads[i] = _MultiDeviceAddN(out_grad, gradient_uid)
                logging.vlog(2, '  _AggregatedGrads %d x %s using %s', len(out_grad), tensor_shape, used)
            else:
                out_grads[i] = backprop_util.AggregateIndexedSlicesGradients(out_grad)
        else:
            out_grads[i] = None
    return out_grads

Get the aggregated gradients for op.

Args:
grads: The map of memoized gradients.
op: The op to get gradients for.
gradient_uid: A unique identifier within the graph indicating
which invocation of gradients is being executed. Used to cluster
ops for compilation.
loop_state: An object for maintaining the state of the while loops in the
graph. It is of type ControlFlowState. None if the graph
contains no while loops.
aggregation_method: Specifies the method used to combine gradient terms.
Accepted values are constants defined in the class `AggregationMethod`.

Returns:
A list of gradients, one per each output of `op`. If the gradients
for a particular output is a list, this function aggregates it
before returning.

Raises:
TypeError: if the incoming grads are not Tensors or IndexedSlices.
ValueError: if the arguments are invalid.


def url(self, endpoint=''):

        if not endpoint.startswith('/'):
            endpoint = "/" + endpoint
        return self.protocol + ":

Get the base URL of the Remote.

Arguments:
None
Returns:
`str` base URL


def _sort_course_modes(self, modes):

        def slug_weight(mode):

            sorting_slugs = COURSE_MODE_SORT_ORDER
            sorting_slugs_size = len(sorting_slugs)
            if mode['slug'] in sorting_slugs:
                return sorting_slugs_size - sorting_slugs.index(mode['slug'])
            return 0

        return sorted(modes, key=slug_weight, reverse=True)

Sort the course mode dictionaries by slug according to the COURSE_MODE_SORT_ORDER constant.

Arguments:
modes (list): A list of course mode dictionaries.
Returns:
list: A list with the course modes dictionaries sorted by slug.


def sg_reuse(tensor, **opt):
    opt = tf.sg_opt(opt)
    assert hasattr(tensor, '_sugar'), 'cannot reuse this node.'
    assert (opt.input is not None), 'input is mandatory.'
    (nodes, prev) = ([tensor], tensor._sugar.prev)
    while (prev is not None):
        nodes = ([prev] + nodes)
        prev = (prev._sugar.prev if hasattr(prev, '_sugar') else None)
    out = opt.input
    for node in nodes[1:]:
        if node._sugar.is_layer:
            fn = tf.sg_layer_func(node._sugar.func)
            if node._sugar.arg.scope_name:
                with tf.variable_scope(node._sugar.arg.scope_name):
                    out = fn(out, **(node._sugar.arg + tf.sg_opt(name=node._sugar.name, reuse=True)))
            else:
                out = fn(out, **(node._sugar.arg + tf.sg_opt(name=node._sugar.name, reuse=True)))
        else:
            out = node._sugar.func(out, node._sugar.arg)
    return out

r""" Reconstruct computational graph of `tensor` so all the parameters
can be reused and replace its input tensor with `opt.input`.

Args:
tensor: A `Tensor` (automatically given by chaining).
**opt:
input: A `Tensor` that will replace the original input tensor.

Returns:
Reconstructed tensor nodes.


def _GetExpectedFractionalMaxPoolResult(self, input_tensor, row_seq, col_seq, overlapping):
    input_shape = input_tensor.shape
    output_shape = (input_shape[0], len(row_seq) - 1, len(col_seq) - 1, input_shape[3])
    output_tensor = np.zeros(shape=output_shape, dtype=input_tensor.dtype)
    for batch in range(input_shape[0]):
        for channel in range(input_shape[3]):
            two_dim_slice = input_tensor[batch, :, :, channel]
            tmp = self._MaxPoolAlongRows(two_dim_slice, row_seq, overlapping)
            output_tensor[batch, :, :, channel] = self._MaxPoolAlongCols(tmp, col_seq, overlapping)
    return output_tensor

Get expected fractional max pool result.

row_seq and col_seq together defines the fractional pooling region.

Args:
input_tensor: Original input tensor, assuming it is a 4-D tensor, with
dimension as [batch, height/row, width/column, channels/depth].
row_seq: Cumulative pooling sequence along row.
col_seq: Cumulative pooling sequence along column.
overlapping: Use overlapping when doing pooling.

Returns:
A 4-D tensor that is the result of max pooling on input_tensor based on
pooling region defined by row_seq and col_seq, conditioned on whether or
not overlapping is used.


def authenticate(self):

        basic_auth = request.authorization
        is_valid = False
        user = None
        if basic_auth:
            is_valid, user = self.check_basic_auth(
                basic_auth.username, basic_auth.password
            )
        else:
            token = request.headers.get('Authorization', None)
            param_token = request.args.get('access_token')
            if token or param_token:
                if token:

                    token = token[6:]
                else:

                    token = param_token
                log.debug('Received token: %s', token)

                is_valid, user = self.check_token_auth(token)
        return (is_valid, user)

Authenticate user by any means and return either true or false.

Args:

Returns:
tuple (is_valid, username): True is valid user, False if not


def __init__(self, name: str, object_id: int, timestamp: int, pid: int, allocator: str, num_bytes: int) -> None:
    self._name = name
    self._pid = pid
    self._object_id = object_id
    self._create_time = timestamp
    self._allocator = allocator
    self._num_bytes = num_bytes
    self._ref_times = []
    self._unref_times = []

Creates an object to track tensor references.

This class is not thread safe and is intended only for internal use by
the 'Timeline' class in this file.

Args:
name:  The name of the Tensor as a string.
object_id:  Chrome Trace object identifier assigned for this Tensor.
timestamp:  The creation timestamp of this event as a long integer.
pid:  Process identifier of the associated device, as an integer.
allocator:  Name of the allocator used to create the Tensor.
num_bytes:  Number of bytes allocated (long integer).

Returns:
A 'TensorTracker' object.


def get_broadcast_shape(*tensors):

  s_shape = tensors[0].shape
  for t in tensors[1:]:
    s_shape = tf.broadcast_static_shape(s_shape, t.shape)
  if tensorshape_util.is_fully_defined(s_shape):
    return tensorshape_util.as_list(s_shape)

  d_shape = tf.shape(input=tensors[0])
  for t in tensors[1:]:
    d_shape = tf.broadcast_dynamic_shape(d_shape, tf.shape(input=t))
  return d_shape

Get broadcast shape as a Python list of integers (preferred) or `Tensor`.

Args:
*tensors:  One or more `Tensor` objects (already converted!).

Returns:
broadcast shape:  Python list (if shapes determined statically), otherwise
an `int32` `Tensor`.


def get_timestamp(self, cycle=None, dataset_number=None,
                      in_minutes=False, full=True):

        dataset_number = self._validate_dataset_number(dataset_number)
        if dataset_number is None:
            self._report_empty_dataset()
            return
        cycle_index_header = self.headers_normal.cycle_index_txt
        timestamp_header = self.headers_normal.test_time_txt

        v = pd.Series()
        test = self.datasets[dataset_number].dfdata
        if cycle:
            c = test[(test[cycle_index_header] == cycle)]
            if not self.is_empty(c):
                v = c[timestamp_header]

        else:
            if not full:
                self.logger.debug("getting timestapm for all cycles")
                v = []
                no_cycles = np.amax(test[cycle_index_header])
                for j in range(1, no_cycles + 1):
                    txt = "Cycle  %i:  " % j
                    self.logger.debug(txt)
                    c = test[(test[cycle_index_header] == j)]
                    v.append(c[timestamp_header])
            else:
                self.logger.debug("returning full timestamp col")
                v = test[timestamp_header]
                if in_minutes and v is not None:
                    v /= 60.0
        if in_minutes and v is not None:
            v /= 60.0
        return v

Returns timestamps (in sec or minutes (if in_minutes==True)).

Args:
cycle: cycle number (all if None)
dataset_number: first dataset if None
in_minutes: return values in minutes instead of seconds if True
full: valid only for cycle=None (i.e. all cycles), returns the full
pandas.Series if True, else a list of pandas.Series

Returns:
pandas.Series (or list of pandas.Series if cycle=None og full=False)


def __init__(self, **kwargs):

        try:
            arguments = Adapter(CollectorStage.schema_complete().validate(kwargs))
            self.stage = arguments.stage
            self.status = arguments.status
            self.events = arguments.events
        except SchemaError as exception:
            Logger.get_logger(__name__).error(exception)
            raise RuntimeError(str(exception))

Initializing and validating fields.

Args:
kwargs (dict): application command line options.

Raises:
RuntimeError: when validation of parameters has failed.


def dotcase(text, acronyms=None):

    words, _case, _sep = case_parse.parse_case(text, acronyms)
    return '.'.join([w.lower() for w in words])

Return text in dot.case style.

Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect

>>> dotcase("hello world")
'hello.world'
>>> dotcase("helloHTMLWorld", True, ["HTML"])
'hello.html.world'


def get_aws_session(account):

    from cloud_inquisitor.config import dbconfig
    from cloud_inquisitor.plugins.types.accounts import AWSAccount

    if not isinstance(account, AWSAccount):
        raise InquisitorError('Non AWSAccount passed to get_aws_session, got {}'.format(account.__class__.__name__))

    session = get_local_aws_session()
    if session.get_credentials().method in ['iam-role', 'env', 'explicit']:
        sts = session.client('sts')
    else:

        temp_sts = session.client('sts')

        audit_sts_role = temp_sts.assume_role(
            RoleArn=app_config.aws_api.instance_role_arn,
            RoleSessionName='inquisitor'
        )
        sts = boto3.session.Session(
            audit_sts_role['Credentials']['AccessKeyId'],
            audit_sts_role['Credentials']['SecretAccessKey'],
            audit_sts_role['Credentials']['SessionToken']
        ).client('sts')

    role = sts.assume_role(
        RoleArn='arn:aws:iam::{}:role/{}'.format(
            account.account_number,
            dbconfig.get('role_name', default='cinq_role')
        ),
        RoleSessionName='inquisitor'
    )

    sess = boto3.session.Session(
        role['Credentials']['AccessKeyId'],
        role['Credentials']['SecretAccessKey'],
        role['Credentials']['SessionToken']
    )

    return sess

Function to return a boto3 Session based on the account passed in the first argument.

Args:
account (:obj:`Account`): Account to create the session object for

Returns:
:obj:`boto3:boto3.session.Session`


def resnet50(pretrained=False, **kwargs):

    model = ResNet(Bottleneck, [3, 4, 6, 3], **kwargs)
    if pretrained:
        model.load_state_dict(model_zoo.load_url(model_urls['resnet50']))
    return model

Constructs a ResNet-50 model.

Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet


def reverse_transform(self, column):

        self.check_data_type()

        return pd.DataFrame({self.col_name: np.log(column[self.col_name])})

Applies the natural logarithm function to turn positive values into real ranged values.

Args:
column (pandas.DataFrame): Data to transform.

Returns:
pd.DataFrame


def _get_table_names(statement):
    parts = statement.to_unicode().split()
    tables = set()
    for (i, token) in enumerate(parts):
        if ((token.lower() == 'from') or token.lower().endswith('join')):
            tables.add(parts[(i + 1)].rstrip(';'))
    return list(tables)

Returns table names found in the query.

NOTE. This routine would use the sqlparse parse tree, but vnames don't parse very well.

Args:
statement (sqlparse.sql.Statement): parsed by sqlparse sql statement.

Returns:
list of str


def setup_model(x, y, model_type='random_forest', seed=None, **kwargs):
    assert ((len(x) > 1) and (len(y) > 1)), 'Not enough data objects to train on (minimum is at least two, you have (x: {0}) and (y: {1}))'.format(len(x), len(y))
    sets = namedtuple('Datasets', ['train', 'test'])
    (x_train, x_test, y_train, y_test) = train_test_split(x, y, random_state=seed, shuffle=False)
    x = sets(x_train, x_test)
    y = sets(y_train, y_test)
    if ((model_type == 'random_forest') or (model_type == 'rf')):
        model = rf.RandomForest(x, y, random_state=seed, **kwargs)
    elif ((model_type == 'deep_neural_network') or (model_type == 'dnn')):
        model = dnn.DeepNeuralNetwork(x, y, **kwargs)
    else:
        raise ValueError('Invalid model type kwarg')
    return model

Initializes a machine learning model

Args:
x: Pandas DataFrame, X axis of features
y: Pandas Series, Y axis of targets
model_type: Machine Learning model to use
Valid values: 'random_forest'
seed: Random state to use when splitting sets and creating the model
**kwargs: Scikit Learn's RandomForestClassifier kwargs

Returns:
Trained model instance of model_type


def emit(self, value):

    if not self._tstate.output_writer:
      logging.error("emit is called, but no output writer is set.")
      return
    self._tstate.output_writer.write(value)

Emits a value to output writer.

Args:
value: a value of type expected by the output writer.


def _set_read_only_resource_inputs_attr(op, branch_graphs):
    read_only_indices = set(range(len(op.inputs) - 1))
    for branch_graph in branch_graphs:
        assert len(branch_graph.inputs) == len(op.inputs) - 1, 'should never happen'
        if not read_only_indices:
            break
        branch_read_only_indices = acd.get_read_only_resource_input_indices_graph(branch_graph)
        read_only_indices = read_only_indices.intersection(branch_read_only_indices)
    read_only_indices = [i + 1 for i in read_only_indices]
    ops.set_int_list_attr(op, acd.READ_ONLY_RESOURCE_INPUTS_ATTR, sorted(read_only_indices))

Sets the list of resource inputs which are read-only.

This is used by AutomaticControlDependencies.

Args:
op: If or Case Operation.
branch_graphs: List of branch FuncGraphs.


def get_javascript_error(self, return_type='string'):
    if BROME_CONFIG['proxy_driver']['intercept_javascript_error']:
        js_errors = self._driver.execute_script('return window.jsErrors; window.jsErrors = [];')
        if (not js_errors):
            js_errors = []
        if (return_type == 'list'):
            if len(js_errors):
                return js_errors
            else:
                return []
        elif len(js_errors):
            return os.linesep.join(js_errors)
        else:
            return self.no_javascript_error_string
    elif (return_type == 'list'):
        return []
    else:
        return self.no_javascript_error_string

Return the gathered javascript error

Args:
return_type: 'string' | 'list'; default: 'string'


def inflate_nd_checker(identifier, definition):
    if isinstance(definition, bool):
        return Checker(name=identifier, passes=definition)
    elif isinstance(definition, dict):
        return Checker(definition.pop('name', identifier), **definition)
    else:
        raise ValueError(('%s type is not supported for no-data checkers, use bool or dict' % type(definition)))

Inflate a no-data checker from a basic definition.

Args:
identifier (str): the no-data checker identifier / name.
definition (bool/dict): a boolean acting as "passes" or a full
dict definition with "passes" and "allow_failure".

Returns:
Checker: a checker instance.

Raises:
ValueError: when the definition type is not bool or dict.


def get_all_threads(self, expand=False):
    if (not expand):
        return self._request_threads(self._url.catalog())
    thread_ids = self.get_all_thread_ids()
    threads = [self.get_thread(id, raise_404=False) for id in thread_ids]
    return filter(None, threads)

Return every thread on this board.

If not expanded, result is same as get_threads run across all board pages,
with last 3-5 replies included.

Uses the catalog when not expanding, and uses the flat thread ID listing
at /{board}/threads.json when expanding for more efficient resource usage.

If expanded, all data of all threads is returned with no omitted posts.

Args:
expand (bool): Whether to download every single post of every thread.
If enabled, this option can be very slow and bandwidth-intensive.

Returns:
list of :mod:`basc_py4chan.Thread`: List of Thread objects representing every thread on this board.


def init(self, force_deploy=False, client=None):

        _force_deploy = self.provider_conf.force_deploy
        self.provider_conf.force_deploy = _force_deploy or force_deploy
        self._provider_conf = self.provider_conf.to_dict()
        r = api.Resources(self._provider_conf, client=client)
        r.launch()
        roles = r.get_roles()
        networks = r.get_networks()

        return (_to_enos_roles(roles),
                _to_enos_networks(networks))

Reserve and deploys the nodes according to the resources section

In comparison to the vagrant provider, networks must be characterized
as in the networks key.

Args:
force_deploy (bool): True iff the environment must be redeployed
Raises:
MissingNetworkError: If one network is missing in comparison to
what is claimed.
NotEnoughNodesError: If the `min` constraints can't be met.


def identity(self):
    return self._implementation.identity()

Returns a TensorArray with the same content and properties.

Returns:
A new TensorArray object with flow that ensures the control dependencies
from the contexts will become control dependencies for writes, reads, etc.
Use this object for all subsequent operations.


def __init__(self, name, description, *labels):
    super(IntGauge, self).__init__('IntGauge', _int_gauge_methods, len(labels), name, description, *labels)

Creates a new IntGauge.

Args:
name: name of the new metric.
description: description of the new metric.
*labels: The label list of the new metric.


def _ExtractRequestSummaryFields(document):
    headers = document.childAtPath('Header/RequestHeader')
    body = document.childAtPath('Body')
    summary_fields = {'methodName': body.getChildren()[0].name}
    client_customer_id = headers.getChild('clientCustomerId')
    if (client_customer_id is not None):
        summary_fields['clientCustomerId'] = client_customer_id.text
    network_code = headers.getChild('networkCode')
    if (network_code is not None):
        summary_fields['networkCode'] = network_code.text
    return summary_fields

Extract logging fields from the request's suds.sax.element.Element.

Args:
document: A suds.sax.element.Element instance containing the API request.

Returns:
A dict mapping logging field names to their corresponding value.


def remove_node(self, node):
    if (node not in self.node_list):
        return
    self.node_list.remove(node)
    for n in self.node_list:
        n.link_list = [link for link in n.link_list if (link.target != node)]

Remove a node from ``self.node_list`` and links pointing to it.

If ``node`` is not in the graph, do nothing.

Args:
node (Node): The node to be removed

Returns: None

Example:
>>> from blur.markov.node import Node
>>> node_1 = Node('One')
>>> graph = Graph([node_1])
>>> graph.remove_node(node_1)
>>> len(graph.node_list)
0


def _prefix_from_prefix_int(self, prefixlen):
    if (not isinstance(prefixlen, (int, long))):
        raise NetmaskValueError(('%r is not an integer' % prefixlen))
    prefixlen = int(prefixlen)
    if (not (0 <= prefixlen <= self._max_prefixlen)):
        raise NetmaskValueError(('%d is not a valid prefix length' % prefixlen))
    return prefixlen

Validate and return a prefix length integer.

Args:
prefixlen: An integer containing the prefix length.

Returns:
The input, possibly converted from long to int.

Raises:
NetmaskValueError: If the input is not an integer, or out of range.


def matches(self, other, **kwargs):

        from pymatgen.analysis.structure_matcher import StructureMatcher
        m = StructureMatcher(**kwargs)
        return m.fit(Structure.from_sites(self), Structure.from_sites(other))

Check whether this structure is similar to another structure.
Basically a convenience method to call structure matching fitting.

Args:
other (IStructure/Structure): Another structure.
**kwargs: Same **kwargs as in
:class:`pymatgen.analysis.structure_matcher.StructureMatcher`.

Returns:
(bool) True is the structures are similar under some affine
transformation.


def are_equal_elements(a_el, b_el):

    if a_el.tagName != b_el.tagName:
        return False
    if sorted(a_el.attributes.items()) != sorted(b_el.attributes.items()):
        return False
    if len(a_el.childNodes) != len(b_el.childNodes):
        return False
    for a_child_el, b_child_el in zip(a_el.childNodes, b_el.childNodes):
        if a_child_el.nodeType != b_child_el.nodeType:
            return False
        if (
            a_child_el.nodeType == a_child_el.TEXT_NODE
            and a_child_el.data != b_child_el.data
        ):
            return False
        if a_child_el.nodeType == a_child_el.ELEMENT_NODE and not are_equal_elements(
            a_child_el, b_child_el
        ):
            return False
    return True

Normalize and compare ElementTrees for equality.

Args:
a_el: ElementTree
b_el: ElementTree
ElementTrees to compare for equality.

Returns:
bool: ``True`` if the ElementTrees are semantically equivalent.


def build_constraint(cls, fhir_path_expression: str, key: str='key-1', severity: codes_pb2.ConstraintSeverityCode.Value=codes_pb2.ConstraintSeverityCode.ERROR) -> datatypes_pb2.ElementDefinition.Constraint:
    return datatypes_pb2.ElementDefinition.Constraint(key=datatypes_pb2.Id(value=key), expression=datatypes_pb2.String(value=fhir_path_expression), severity=datatypes_pb2.ElementDefinition.Constraint.SeverityCode(value=severity))

Returns an `ElementDefinition.Constraint` for a FHIRPath expression.

Args:
fhir_path_expression: The raw FHIRPath expression.
key: The FHIRPath constraint unique identifier. Defaults to 'key-1'.
severity: The constraint severity.  Defaults to ERROR.

Returns:
An instance of `ElementDefinition.Constraint` capturing the raw underlying
`fhir_path_expression`.


def _do_pass(self, pass_, dag, options):
    if (not options['ignore_requires']):
        for required_pass in pass_.requires:
            dag = self._do_pass(required_pass, dag, options)
    if (pass_ not in self.valid_passes):
        if pass_.is_transformation_pass:
            pass_.property_set = self.fenced_property_set
            new_dag = pass_.run(dag)
            if (not isinstance(new_dag, DAGCircuit)):
                raise TranspilerError(('Transformation passes should return a transformed dag.The pass %s is returning a %s' % (type(pass_).__name__, type(new_dag))))
            dag = new_dag
        elif pass_.is_analysis_pass:
            pass_.property_set = self.property_set
            pass_.run(FencedDAGCircuit(dag))
        else:
            raise TranspilerError('I dont know how to handle this type of pass')
        self._update_valid_passes(pass_, options['ignore_preserves'])
    return dag

Do a pass and its "requires".

Args:
pass_ (BasePass): Pass to do.
dag (DAGCircuit): The dag on which the pass is ran.
options (dict): PassManager options.
Returns:
DAGCircuit: The transformed dag in case of a transformation pass.
The same input dag in case of an analysis pass.
Raises:
TranspilerError: If the pass is not a proper pass instance.


def _query(self, key_pos: int, src: Any, use_inferred: bool) -> Any:
    if key_pos == len(self._keys):
        return src
    key = self.keys[key_pos]
    if hasattr(src, 'sym_hasattr'):
        if src.sym_hasattr(key):
            if use_inferred:
                v = src.sym_inferred(key)
            else:
                v = src.sym_getattr(key)
            return self._query(key_pos + 1, v, use_inferred)
    elif hasattr(src, '__getitem__'):
        if isinstance(key, int):
            if not hasattr(src, '__len__'):
                raise KeyError(f"Cannot query index ({key}) on object ({src!r}): '__len__' does not exist.")
            if key < len(src):
                return self._query(key_pos + 1, src[key], use_inferred)
        else:
            if not hasattr(src, '__contains__'):
                raise KeyError(f"Cannot query key ({key!r}) on object ({src!r}): '__contains__' does not exist.")
            if key in src:
                return self._query(key_pos + 1, src[key], use_inferred)
    else:
        raise KeyError(f"Cannot query sub-key {key!r} of object ({src!r}): '__getitem__' does not exist. (path={KeyPath(self.keys[:key_pos])})")
    raise KeyError(f'Path {KeyPath(self._keys[:key_pos + 1])!r} does not exist: key {key!r} is absent from innermost value {src!r}.')

Query the value of current path up to key_pos from an object.

Args:
key_pos: Start position in self._keys.
src: Source value to query.
use_inferred: If True, infer `pg.Inferential` values. Otherwise returns
their symbolic form. Applicable only for symbolic values.

Returns:
Value from src if path exists.

Raises:
KeyError: Path doesn't exist in src.


def start(self, request: Request) -> Response:

        if self._session_state != SessionState.ready:
            raise RuntimeError('Session already started')

        assert not self._request
        self._request = request
        _logger.debug(__('Client fetch request {0}.', request))

        connection = yield from self._acquire_request_connection(request)
        full_url = connection.proxied and not connection.tunneled

        self._stream = stream = self._stream_factory(connection)

        yield from self._stream.reconnect()

        request.address = connection.address

        self.event_dispatcher.notify(self.Event.begin_request, request)
        write_callback = functools.partial(self.event_dispatcher.notify, self.Event.request_data)
        stream.data_event_dispatcher.add_write_listener(write_callback)

        yield from stream.write_request(request, full_url=full_url)

        if request.body:
            assert 'Content-Length' in request.fields
            length = int(request.fields['Content-Length'])
            yield from stream.write_body(request.body, length=length)

        stream.data_event_dispatcher.remove_write_listener(write_callback)
        self.event_dispatcher.notify(self.Event.end_request, request)

        read_callback = functools.partial(self.event_dispatcher.notify, self.Event.response_data)
        stream.data_event_dispatcher.add_read_listener(read_callback)

        self._response = response = yield from stream.read_response()
        response.request = request

        self.event_dispatcher.notify(self.Event.begin_response, response)

        self._session_state = SessionState.request_sent

        return response

Begin a HTTP request

Args:
request: Request information.

Returns:
A response populated with the HTTP headers.

Once the headers are received, call :meth:`download`.

Coroutine.


def true_events(network, previous_state, current_state, next_state, indices=None, major_complex=None):
    if major_complex:
        nodes = major_complex.subsystem.node_indices
    elif indices:
        nodes = indices
    else:
        major_complex = compute.major_complex(network, current_state)
        nodes = major_complex.subsystem.node_indices
    return events(network, previous_state, current_state, next_state, nodes)

Return all mechanisms that have true causes and true effects within the
complex.

Args:
network (Network): The network to analyze.
previous_state (tuple[int]): The state of the network at ``t - 1``.
current_state (tuple[int]): The state of the network at ``t``.
next_state (tuple[int]): The state of the network at ``t + 1``.

Keyword Args:
indices (tuple[int]): The indices of the major complex.
major_complex (AcSystemIrreducibilityAnalysis): The major complex. If
``major_complex`` is given then ``indices`` is ignored.

Returns:
tuple[Event]: List of true events in the major complex.


def Search(self, artifact, os_name=None, cpe=None, label=None):
    hit = (lambda x: ((x[0] == x[1]) or (not x[0])))
    seq = [(artifact, self.artifact), (os_name, self.os_name), (cpe, self.cpe), (label, self.label)]
    return all(map(hit, seq))

Whether the condition contains the specified values.

Args:
artifact: A string identifier for the artifact.
os_name: An OS string.
cpe: A CPE string.
label: A label string.

Returns:
True if the values match the non-empty query attributes.
Empty query attributes are ignored in the comparison.


def __init__(self, parent, isolated=True, function_name=None):
    self.parent = parent
    self.isolated = isolated
    self.function_name = function_name
    self.isolated_names = set()
    self.read = set()
    self.modified = set()
    self.deleted = set()
    self.bound = set()
    self.globals = set()
    self.nonlocals = set()
    self.annotations = set()
    self.params = weakref.WeakValueDictionary()
    self.is_final = False

Create a new scope.

Args:
parent: A Scope or None.
isolated: Whether the scope is isolated, that is, whether variables
modified in this scope should be considered modified in the parent
scope.
function_name: Name of the function owning this scope.


def _is_tensor(x):
    return isinstance(x, (tensor_lib.Tensor, variables.Variable))

Returns `True` if `x` is a symbolic tensor-like object.

Args:
x: A python object to check.

Returns:
`True` if `x` is a `tf.Tensor` or `tf.Variable`, otherwise `False`.


def post_process_semantic_segmentation(self, outputs, target_sizes: Optional[List[Tuple[int, int]]]=None) -> 'torch.Tensor':
    class_queries_logits = outputs.class_queries_logits
    masks_queries_logits = outputs.masks_queries_logits
    masks_classes = class_queries_logits.softmax(dim=-1)[..., :-1]
    masks_probs = masks_queries_logits.sigmoid()
    segmentation = torch.einsum('bqc, bqhw -> bchw', masks_classes, masks_probs)
    batch_size = class_queries_logits.shape[0]
    if target_sizes is not None:
        if batch_size != len(target_sizes):
            raise ValueError('Make sure that you pass in as many target sizes as the batch dimension of the logits')
        semantic_segmentation = []
        for idx in range(batch_size):
            resized_logits = torch.nn.functional.interpolate(segmentation[idx].unsqueeze(dim=0), size=target_sizes[idx], mode='bilinear', align_corners=False)
            semantic_map = resized_logits[0].argmax(dim=0)
            semantic_segmentation.append(semantic_map)
    else:
        semantic_segmentation = segmentation.argmax(dim=1)
        semantic_segmentation = [semantic_segmentation[i] for i in range(semantic_segmentation.shape[0])]
    return semantic_segmentation

Converts the output of [`MaskFormerForInstanceSegmentation`] into semantic segmentation maps. Only supports
PyTorch.

Args:
outputs ([`MaskFormerForInstanceSegmentation`]):
Raw outputs of the model.
target_sizes (`List[Tuple[int, int]]`, *optional*):
List of length (batch_size), where each list item (`Tuple[int, int]]`) corresponds to the requested
final size (height, width) of each prediction. If left to None, predictions will not be resized.
Returns:
`List[torch.Tensor]`:
A list of length `batch_size`, where each item is a semantic segmentation map of shape (height, width)
corresponding to the target_sizes entry (if `target_sizes` is specified). Each entry of each
`torch.Tensor` correspond to a semantic class id.


def dew_point_temperature(self, value=99.9):

        if value is not None:
            try:
                value = float(value)
            except ValueError:
                raise ValueError(
                    'value {} need to be of type float '
                    'for field `dew_point_temperature`'.format(value))
            if value <= -70.0:
                raise ValueError('value need to be greater -70.0 '
                                 'for field `dew_point_temperature`')
            if value >= 70.0:
                raise ValueError('value need to be smaller 70.0 '
                                 'for field `dew_point_temperature`')

        self._dew_point_temperature = value

Corresponds to IDD Field `dew_point_temperature`

Args:
value (float): value for IDD Field `dew_point_temperature`
Unit: C
value > -70.0
value < 70.0
Missing value: 99.9
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

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


async def enqueue(self, query, queue_index=None, stop_current=False, shuffle=False):
    if ((query is None) or (query == '')):
        return
    self.statuslog.info('Parsing {}'.format(query))
    self.logger.debug('Enqueueing from query')
    indexnum = None
    if (queue_index is not None):
        try:
            indexnum = (int(queue_index) - 1)
        except TypeError:
            self.statuslog.error('Play index argument must be a number')
            return
        except ValueError:
            self.statuslog.error('Play index argument must be a number')
            return
    if (not self.vready):
        self.parse_query(query, indexnum, stop_current, shuffle)
    else:
        parse_thread = threading.Thread(target=self.parse_query, args=[query, indexnum, stop_current, shuffle])
        parse_thread.start()

Queues songs based on either a YouTube search or a link

Args:
query (str): Either a search term or a link
queue_index (str): The queue index to enqueue at (None for end)
stop_current (bool): Whether to stop the current song after the songs are queued
shuffle (bool): Whether to shuffle the added songs


def get_clusters_interfaces(clusters, extra_cond=(lambda nic: True)):
    interfaces = {}
    for cluster in clusters:
        nics = get_cluster_interfaces(cluster, extra_cond=extra_cond)
        interfaces.setdefault(cluster, nics)
    return interfaces

Returns for each cluster the available cluster interfaces

Args:
clusters (str): list of the clusters
extra_cond (lambda): extra predicate to filter network card retrieved
from the API. E.g lambda nic: not nic['mounted'] will retrieve all the
usable network cards that are not mounted by default.

Returns:
dict of cluster with their associated nic names

Examples:
.. code-block:: python

# pseudo code
actual = get_clusters_interfaces(["paravance"])
expected = {"paravance": ["eth0", "eth1"]}
assertDictEquals(expected, actual)


def visualize_instance_html(self, exp, label, div_name, exp_object_name,
                                text=True, opacity=True):

        if not text:
            return u''
        text = (self.indexed_string.raw_string()
                .encode('utf-8', 'xmlcharrefreplace').decode('utf-8'))
        text = re.sub(r'[<>&]', '|', text)
        exp = [(self.indexed_string.word(x[0]),
                self.indexed_string.string_position(x[0]),
                x[1]) for x in exp]
        all_occurrences = list(itertools.chain.from_iterable(
            [itertools.product([x[0]], x[1], [x[2]]) for x in exp]))
        all_occurrences = [(x[0], int(x[1]), x[2]) for x in all_occurrences]
        ret =  % (exp_object_name, json.dumps(all_occurrences), label,
                   json.dumps(text), div_name, json.dumps(opacity))
        return ret

Adds text with highlighted words to visualization.

Args:
exp: list of tuples [(id, weight), (id,weight)]
label: label id (integer)
div_name: name of div object to be used for rendering(in js)
exp_object_name: name of js explanation object
text: if False, return empty
opacity: if True, fade colors according to weight


def remove_indirect_links(g, alg='aracne', **kwargs):
    alg = {'aracne': aracne, 'nd': network_deconvolution, 'clr': clr}[alg]
    mat = np.array(nx.adjacency_matrix(g).todense())
    return nx.relabel_nodes(nx.DiGraph(alg(mat, **kwargs)), {idx: i for (idx, i) in enumerate(list(g.nodes()))})

Apply deconvolution to a networkx graph.

Args:
g (networkx.Graph): Graph to apply deconvolution to
alg (str): Algorithm to use ('aracne', 'clr', 'nd')
kwargs (dict): extra options for algorithms

Returns:
networkx.Graph: graph with undirected links removed.


def pack_image_features(self, image_features, image_sizes, vision_feature_select_strategy, image_newline=None):
    new_image_features = []
    feature_lens = []
    for image_idx, image_feature in enumerate(image_features):
        if image_feature.shape[0] > 1:
            base_image_feature = image_feature[0]
            image_feature = image_feature[1:]
            height = width = self.config.vision_config.image_size
            num_patch_height, num_patch_width = get_anyres_image_grid_shape(image_sizes[image_idx], self.config.image_grid_pinpoints, self.config.vision_config.image_size)
            if np.prod(image_feature.shape) % (num_patch_height * num_patch_width * height * width) != 0 and vision_feature_select_strategy == 'default':
                logger.warning_once('Image feature shape does not line up with the provided patch size. You may be using the `default` vision_feature_select_strategy with a visual encoder that does not have CLS.')
            image_feature = image_feature.view(num_patch_height, num_patch_width, height, width, -1)
            image_feature = image_feature.permute(4, 0, 2, 1, 3).contiguous()
            image_feature = image_feature.flatten(1, 2).flatten(2, 3)
            image_feature = unpad_image(image_feature, image_sizes[image_idx])
            if image_newline is not None:
                image_feature = torch.cat((image_feature, image_newline[:, None, None].expand(*image_feature.shape[:-1], 1).to(image_feature.device, image_feature.dtype)), dim=-1)
            image_feature = image_feature.flatten(1, 2).transpose(0, 1)
            image_feature = torch.cat((base_image_feature, image_feature), dim=0)
        else:
            image_feature = image_feature[0]
            if image_newline is not None:
                image_feature = torch.cat((image_feature, image_newline[None].to(image_feature)), dim=0)
        new_image_features.append(image_feature)
        feature_lens.append(image_feature.size(0))
    feature_lens = torch.tensor(feature_lens, dtype=torch.long, device=image_features[0].device)
    return (new_image_features, feature_lens)

Reshape, unpad and then pack each image_feature into a single image_features tensor containing all visual vectors.

Args:
image_features (`List[torch.Tensor]` of length num_images, each of shape `(num_patches, image_length, embed_dim)`)
List of image feature tensor, each contains all the visual feature of all patches.
image_sizes (`torch.Tensor` of shape `(num_images, 2)`)
Actual image size of each images (H, W).
vision_feature_select_strategy (`str`)
The feature selection strategy used to select the vision feature from the vision backbone.
image_newline (`torch.Tensor` of shape `(embed_dim)`)
New line embedding vector.
Returns:
image_features (`torch.Tensor` of shape `(all_feat_len, embed_dim)`)
feature_lens (`List[int]`)
token length of each image in image_features


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

Updates a `BuildTrigger` by its project ID and trigger ID. This API is experimental.

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


def get_image_and_mask(self, label, positive_only=True, hide_rest=False, num_features=5, min_weight=0.0):
    if (label not in self.local_exp):
        raise KeyError('Label not in explanation')
    segments = self.segments
    image = self.image
    exp = self.local_exp[label]
    mask = np.zeros(segments.shape, segments.dtype)
    if hide_rest:
        temp = np.zeros(self.image.shape)
    else:
        temp = self.image.copy()
    if positive_only:
        fs = [x[0] for x in exp if ((x[1] > 0) and (x[1] > min_weight))][:num_features]
        for f in fs:
            temp[(segments == f)] = image[(segments == f)].copy()
            mask[(segments == f)] = 1
        return (temp, mask)
    else:
        for (f, w) in exp[:num_features]:
            if (np.abs(w) < min_weight):
                continue
            c = (0 if (w < 0) else 1)
            mask[(segments == f)] = (1 if (w < 0) else 2)
            temp[(segments == f)] = image[(segments == f)].copy()
            temp[((segments == f), c)] = np.max(image)
            for cp in [0, 1, 2]:
                if (c == cp):
                    continue
        return (temp, mask)

Init function.

Args:
label: label to explain
positive_only: if True, only take superpixels that contribute to
the prediction of the label. Otherwise, use the top
num_features superpixels, which can be positive or negative
towards the label
hide_rest: if True, make the non-explanation part of the return
image gray
num_features: number of superpixels to include in explanation
min_weight: TODO

Returns:
(image, mask), where image is a 3d numpy array and mask is a 2d
numpy array that can be used with
skimage.segmentation.mark_boundaries


def get_special_tokens_mask(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None, already_has_special_tokens: bool=False) -> List[int]:
    if already_has_special_tokens:
        return super().get_special_tokens_mask(token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True)
    if token_ids_1 is not None:
        return [0] * len(token_ids_0) + [1] + [0] * len(token_ids_1) + [1]
    return [0] * len(token_ids_0) + [1]

Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer `prepare_for_model` method.

Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.
already_has_special_tokens (`bool`, *optional*, defaults to `False`):
Whether or not the token list is already formatted with special tokens for the model.

Returns:
`List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.


def sample_observed_state(self, s: pd.Series) -> Dict:

        return {
            n[0]: {
                i.name: np.random.normal(s[n[0]] * i.mean, i.stdev)
                for i in n[1]["indicators"].values()
            }
            for n in self.nodes(data=True)
        }

Sample observed state vector. This is the implementation of the
emission function.

Args:
s: Latent state vector.

Returns:
Observed state vector.


def get_mailcap_entry(self, url):

        for parser in mime_parsers.parsers:
            if parser.pattern.match(url):

                try:
                    modified_url, content_type = parser.get_mimetype(url)
                except Exception as e:

                    _logger.warning('parser %s raised an exception', parser)
                    _logger.exception(e)
                    raise exceptions.MailcapEntryNotFound()
                if not content_type:
                    _logger.info('Content type could not be determined')
                    raise exceptions.MailcapEntryNotFound()
                elif content_type == 'text/html':
                    _logger.info('Content type text/html, deferring to browser')
                    raise exceptions.MailcapEntryNotFound()

                command, entry = mailcap.findmatch(
                    self._mailcap_dict, content_type, filename=modified_url)
                if not entry:
                    _logger.info('Could not find a valid mailcap entry')
                    raise exceptions.MailcapEntryNotFound()

                return command, entry

        raise exceptions.MailcapEntryNotFound()

Search through the mime handlers list and attempt to find the
appropriate command to open the provided url with.

Will raise a MailcapEntryNotFound exception if no valid command exists.

Params:
url (text): URL that will be checked

Returns:
command (text): The string of the command that should be executed
in a subprocess to open the resource.
entry (dict): The full mailcap entry for the corresponding command


def export(self, name=None):
    with ops.name_scope(name, '%s_Export' % self.name, [self.resource_handle]):
        exported_keys, exported_values = gen_lookup_ops.lookup_table_export_v2(self.resource_handle, self._key_dtype, self._value_dtype)
    exported_values.set_shape(exported_keys.get_shape().concatenate(self._value_shape))
    return (exported_keys, exported_values)

Returns tensors of all keys and values in the table.

Args:
name: A name for the operation (optional).

Returns:
A pair of tensors with the first tensor containing all keys and the
second tensors containing all values in the table.


def Logger(name, debug=False, facility=None):

  logger = logging.getLogger(name)
  logger.handlers = []
  logger.addHandler(logging.NullHandler())
  logger.propagate = False
  logger.setLevel(logging.DEBUG)
  formatter = logging.Formatter(name + ': %(levelname)s %(message)s')

  if debug:

    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.DEBUG)
    console_handler.setFormatter(formatter)
    logger.addHandler(console_handler)

  if facility:

    syslog_handler = logging.handlers.SysLogHandler(
        address=constants.SYSLOG_SOCKET, facility=facility)
    syslog_handler.setLevel(logging.INFO)
    syslog_handler.setFormatter(formatter)
    logger.addHandler(syslog_handler)

  return logger

Get a logging object with handlers for sending logs to SysLog.

Args:
name: string, the name of the logger which will be added to log entries.
debug: bool, True if debug output should write to the console.
facility: int, an encoding of the SysLog handler's facility and priority.

Returns:
logging object, an object for logging entries.


def strip_hidden(key_tuples, visibilities):

    result = []
    for key_tuple in key_tuples:
        if len(key_tuple) != len(visibilities):
            raise ValueError(
                "length of key tuple {} is not equal to length of visibilities {}".format(
                    key_tuple, visibilities
                )
            )
        filtered_tuple = tuple(item for item, visible in zip(key_tuple, visibilities) if visible)
        result.append(filtered_tuple)
    return result

Filter each tuple according to visibility.

Args:
key_tuples: A sequence of tuples of equal length (i.e. rectangular)
visibilities: A sequence of booleans equal in length to the tuples contained in key_tuples.

Returns:
A sequence equal in length to key_tuples where the items are tuples with a length corresponding
to the number of items in visibility which are True.


def find_paths_referenced(self) -> Collection[str]:
    _, paths = self._find_paths_referenced()
    return set(paths)

Finds paths for any elements referenced in this expression.

For example, given the expression 'a.b.where(c > d.e).f' returns paths
{'a', 'a.b', 'a.b.c', 'a.b.d', 'a.b.d.e', 'a.b.f'}

Returns:
A collections of paths referenced in the expression.


def debug_watch_keys(self, node_name, device_name=None):
    try:
        device_name = self._infer_device_name(device_name, node_name)
    except ValueError:
        return []
    if node_name not in self._debug_watches[device_name]:
        return []
    watch_keys = []
    for watched_slot in self._debug_watches[device_name][node_name]:
        debug_ops = self._debug_watches[device_name][node_name][watched_slot]
        for debug_op in debug_ops:
            watch_keys.append(_get_tensor_watch_key(node_name, watched_slot, debug_op))
    return watch_keys

Get all tensor watch keys of given node according to partition graphs.

Args:
node_name: (`str`) name of the node.
device_name: (`str`) name of the device. If there is only one device or if
node_name exists on only one device, this argument is optional.

Returns:
(`list` of `str`) all debug tensor watch keys. Returns an empty list if
the node name does not correspond to any debug watch keys.

Raises:
`LookupError`: If debug watch information has not been loaded from
partition graphs yet.


def _log_score(score):

    logger.info(
        "Score of ({}/{}) set for submission {}"
        .format(score.points_earned, score.points_possible, score.submission.uuid)
    )

Log the creation of a score.

Args:
score (Score): The score model.

Returns:
None


def instantiate(self, substitutions):

        param_dict = self.substitute_params(substitutions)
        pkg, ident = self.name.rsplit(".", 1)
        pkg = "malcolm.modules.%s" % pkg
        try:
            ob = importlib.import_module(pkg)
        except ImportError as e:
            raise_with_traceback(
                ImportError("\n%s:%d:\n%s" % (
                    self.filename, self.lineno, e)))
        try:
            ob = getattr(ob, ident)
        except AttributeError:
            raise_with_traceback(
                ImportError("\n%s:%d:\nPackage %r has no ident %r" % (
                    self.filename, self.lineno, pkg, ident)))
        try:
            model = MethodModel.from_callable(ob, returns=False)
            args = model.validate(param_dict)
            ret = ob(**args)
        except Exception as e:
            sourcefile = inspect.getsourcefile(ob)
            lineno = inspect.getsourcelines(ob)[1]
            raise_with_traceback(
                YamlError("\n%s:%d:\n%s:%d:\n%s" % (
                    self.filename, self.lineno, sourcefile, lineno, e)))
        else:
            return ret

Keep recursing down from base using dotted name, then call it with
self.params and args

Args:
substitutions (dict): Substitutions to make to self.param_dict

Returns:
The found object called with (*args, map_from_d)

E.g. if ob is malcolm.parts, and name is "ca.CADoublePart", then the
object will be malcolm.parts.ca.CADoublePart


def nonzero_monies(self):
    return [copy.copy(m) for m in self._money_obs if (m.amount != 0)]

Get a list of the underlying ``Money`` instances that are not zero

Returns:
([Money]): A list of zero or more money instances. Currencies will be unique.


def has_chosen(state, correct, msgs):

    if not issubclass(type(correct), int):
        raise InstructorError(
            "Inside `has_chosen()`, the argument `correct` should be an integer."
        )

    student_process = state.student_process
    if not isDefinedInProcess(MC_VAR_NAME, student_process):
        raise InstructorError("Option not available in the student process")
    else:
        selected_option = getOptionFromProcess(student_process, MC_VAR_NAME)
        if not issubclass(type(selected_option), int):
            raise InstructorError("selected_option should be an integer")

        if selected_option < 1 or correct < 1:
            raise InstructorError(
                "selected_option and correct should be greater than zero"
            )

        if selected_option > len(msgs) or correct > len(msgs):
            raise InstructorError("there are not enough feedback messages defined")

        feedback_msg = msgs[selected_option - 1]

        state.reporter.success_msg = msgs[correct - 1]

        state.do_test(EqualTest(selected_option, correct, feedback_msg))

Test multiple choice exercise.

Test for a MultipleChoiceExercise. The correct answer (as an integer) and feedback messages
are passed to this function.

Args:
correct (int): the index of the correct answer (should be an instruction). Starts at 1.
msgs (list(str)): a list containing all feedback messages belonging to each choice of the
student. The list should have the same length as the number of options.


def _initialize_splittable_and_unsplittable_dims(self, default_splittability, exception_dims_iterable=None):
    default_dims = set()
    exception_dims = set()
    if exception_dims_iterable:
        exception_dims.update(exception_dims_iterable)
    for t in itertools.chain(self.inputs, self.outputs):
        for dim_name in t.shape.dimension_names:
            if (dim_name not in exception_dims):
                default_dims.add(dim_name)
    if (default_splittability == 'splittable'):
        return (frozenset(default_dims), frozenset(exception_dims))
    elif (default_splittability == 'unsplittable'):
        return (frozenset(exception_dims), frozenset(default_dims))
    else:
        raise ValueError('default_splittability should be either "splittable" or "unsplittable" but was {}'.format(default_splittability))

Initializer for splittable_dims and unsplittable_dims.

Helper method to categorize all dimensions in the input/output tensors as
either splittable or unsplittable.

Args:
default_splittability: a string which is either "splittable" or
"unsplittable".
exception_dims_iterable: an optional iterable of names of dimensions
which are exceptions to the default splittability.

Returns:
splittable_dims and unsplittable_dims, two frozensets of names of
dimensions (strings)

Raises:
ValueError: default_splittability is not one of "splittable" or
"unsplittable".


def _source_file_paths_outside_tensorflow_py_library(code_defs, id_to_string):
    file_ids = set()
    for code_def in code_defs:
        for trace in code_def.traces:
            file_ids.add(trace.file_id)
    non_tf_files = (id_to_string[file_id] for file_id in file_ids)
    non_tf_files = (f for f in non_tf_files if not source_utils.guess_is_tensorflow_py_library(f) and gfile.Exists(f))
    return non_tf_files

Extract source file paths outside TensorFlow Python library.

Args:
code_defs: An iterable of `CodeDef` protos, i.e., an iterable of stack
traces.
id_to_string: A proto map from integer ids to strings.

Returns:
An iterable of source file paths outside the TensorFlow Python library.


def ParseAccountInformation(
      self, parser_mediator, query, row, **unused_kwargs):

    query_hash = hash(query)

    display_name = self._GetRowValue(query_hash, row, 'given_displayname')
    fullname = self._GetRowValue(query_hash, row, 'fullname')

    username = '{0!s} <{1!s}>'.format(fullname, display_name)

    event_data = SkypeAccountEventData()
    event_data.country = self._GetRowValue(query_hash, row, 'country')
    event_data.display_name = display_name
    event_data.email = self._GetRowValue(query_hash, row, 'emails')
    event_data.offset = self._GetRowValue(query_hash, row, 'id')
    event_data.query = query
    event_data.username = username

    timestamp = self._GetRowValue(query_hash, row, 'profile_timestamp')
    if timestamp:
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(date_time, 'Profile Changed')
      parser_mediator.ProduceEventWithEventData(event, event_data)

    timestamp = self._GetRowValue(query_hash, row, 'authreq_timestamp')
    if timestamp:
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(
          date_time, 'Authenticate Request')
      parser_mediator.ProduceEventWithEventData(event, event_data)

    timestamp = self._GetRowValue(query_hash, row, 'lastonline_timestamp')
    if timestamp:
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(date_time, 'Last Online')
      parser_mediator.ProduceEventWithEventData(event, event_data)

    timestamp = self._GetRowValue(query_hash, row, 'mood_timestamp')
    if timestamp:
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(date_time, 'Mood Event')
      parser_mediator.ProduceEventWithEventData(event, event_data)

    timestamp = self._GetRowValue(query_hash, row, 'sent_authrequest_time')
    if timestamp:
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(date_time, 'Auth Request Sent')
      parser_mediator.ProduceEventWithEventData(event, event_data)

    timestamp = self._GetRowValue(query_hash, row, 'lastused_timestamp')
    if timestamp:
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(date_time, 'Last Used')
      parser_mediator.ProduceEventWithEventData(event, event_data)

Parses account information.

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 with account information.


def __delitem__(self, keyword):

        status = False
        if keyword:
            if not self.case_sensitive:
                keyword = keyword.lower()
            current_dict = self.keyword_trie_dict
            character_trie_list = []
            for letter in keyword:
                if letter in current_dict:
                    character_trie_list.append((letter, current_dict))
                    current_dict = current_dict[letter]
                else:

                    current_dict = None
                    break

            if current_dict and self._keyword in current_dict:

                character_trie_list.append((self._keyword, current_dict))
                character_trie_list.reverse()

                for key_to_remove, dict_pointer in character_trie_list:
                    if len(dict_pointer.keys()) == 1:
                        dict_pointer.pop(key_to_remove)
                    else:

                        dict_pointer.pop(key_to_remove)
                        break

                status = True
                self._terms_in_trie -= 1
        return status

To remove keyword from the dictionary
pass the keyword and the clean name it maps to.

Args:
keyword : string
keyword that you want to remove if it's present

Examples:
>>> keyword_processor.add_keyword('Big Apple')
>>> del keyword_processor['Big Apple']


class Poisson(reduction_metrics.MeanMetricWrapper):

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

    def get_config(self):
        return {'name': self.name, 'dtype': self.dtype}

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

Formula:

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

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

Examples:

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

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

Usage with `compile()` API:

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


def imshow(img, win_name='', wait_time=0):
    cv2.imshow(win_name, imread(img))
    cv2.waitKey(wait_time)

Show an image.

Args:
img (str or ndarray): The image to be displayed.
win_name (str): The window name.
wait_time (int): Value of waitKey param.


class CLIPEncoder(nn.Module):

    def __init__(self, config: CLIPConfig):
        super().__init__()
        self.config = config
        self.layers = nn.ModuleList([CLIPEncoderLayer(config) for _ in range(config.num_hidden_layers)])
        self.gradient_checkpointing = False

    @can_return_tuple
    def forward(self, inputs_embeds, attention_mask: Optional[torch.Tensor]=None, causal_attention_mask: Optional[torch.Tensor]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None) -> BaseModelOutput:

        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
        encoder_states = () if output_hidden_states else None
        all_attentions = () if output_attentions else None
        hidden_states = inputs_embeds
        for idx, encoder_layer in enumerate(self.layers):
            if output_hidden_states:
                encoder_states = encoder_states + (hidden_states,)
            if self.gradient_checkpointing and self.training:
                layer_outputs = self._gradient_checkpointing_func(encoder_layer.__call__, hidden_states, attention_mask, causal_attention_mask, output_attentions)
            else:
                layer_outputs = encoder_layer(hidden_states, attention_mask, causal_attention_mask, output_attentions=output_attentions)
            hidden_states = layer_outputs[0]
            if output_attentions:
                all_attentions = all_attentions + (layer_outputs[1],)
        if output_hidden_states:
            encoder_states = encoder_states + (hidden_states,)
        return BaseModelOutput(last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions)

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

Args:
config: CLIPConfig


def _load_config(self, client_secrets_file, client_id, client_secret):
    if (client_id and client_secret):
        (self.client_id, self.client_secret) = (client_id, client_secret)
        return
    if client_secrets_file:
        self._load_client_secrets(client_secrets_file)
        return
    if ('GOOGLE_OAUTH2_CLIENT_SECRETS_FILE' in self.app.config):
        self._load_client_secrets(self.app.config['GOOGLE_OAUTH2_CLIENT_SECRETS_FILE'])
        return
    try:
        (self.client_id, self.client_secret) = (self.app.config['GOOGLE_OAUTH2_CLIENT_ID'], self.app.config['GOOGLE_OAUTH2_CLIENT_SECRET'])
    except KeyError:
        raise ValueError('OAuth2 configuration could not be found. Either specify the client_secrets_file or client_id and client_secret or set the app configuration variables GOOGLE_OAUTH2_CLIENT_SECRETS_FILE or GOOGLE_OAUTH2_CLIENT_ID and GOOGLE_OAUTH2_CLIENT_SECRET.')

Loads oauth2 configuration in order of priority.

Priority:
1. Config passed to the constructor or init_app.
2. Config passed via the GOOGLE_OAUTH2_CLIENT_SECRETS_FILE app
config.
3. Config passed via the GOOGLE_OAUTH2_CLIENT_ID and
GOOGLE_OAUTH2_CLIENT_SECRET app config.

Raises:
ValueError if no config could be found.


def ClaimNotificationsForCollection(cls, token=None, start_time=None, lease_time=200, collection=None):

    class CollectionFilter(object):

        def __init__(self, collection):
            self.collection = collection

        def FilterRecord(self, notification):
            if (self.collection is None):
                self.collection = notification.result_collection_urn
            return (self.collection != notification.result_collection_urn)
    f = CollectionFilter(collection)
    results = []
    with aff4.FACTORY.OpenWithLock(RESULT_NOTIFICATION_QUEUE, aff4_type=HuntResultQueue, lease_time=300, blocking=True, blocking_sleep_interval=15, blocking_lock_timeout=600, token=token) as queue:
        for record in queue.ClaimRecords(record_filter=f.FilterRecord, start_time=start_time, timeout=lease_time, limit=100000):
            results.append(record)
    return (f.collection, results)

Return unclaimed hunt result notifications for collection.

Args:
token: The security token to perform database operations with.
start_time: If set, an RDFDateTime indicating at what point to start
claiming notifications. Only notifications with a timestamp after this
point will be claimed.
lease_time: How long to claim the notifications for.
collection: The urn of the collection to find notifications for. If unset,
the earliest (unclaimed) notification will determine the collection.

Returns:
A pair (collection, results) where collection is the collection
that notifications were retrieved for and results is a list of
Record objects which identify GrrMessage within the result
collection.


def create_win_salt_restart_task():
    cmd = 'cmd'
    args = '/c ping -n 3 127.0.0.1 && net stop salt-minion && net start salt-minion'
    return __salt__['task.create_task'](name='restart-salt-minion', user_name='System', force=True, action_type='Execute', cmd=cmd, arguments=args, trigger_type='Once', start_date='1975-01-01', start_time='01:00')

Create a task in Windows task scheduler to enable restarting the salt-minion

Returns:
bool: ``True`` if successful, otherwise ``False``

CLI Example:

.. code-block:: bash

salt '*' service.create_win_salt_restart_task()


def init(dvc_dir):
    config_file = os.path.join(dvc_dir, Config.CONFIG)
    open(config_file, 'w+').close()
    return Config(dvc_dir)

Initializes dvc config.

Args:
dvc_dir (str): path to .dvc directory.

Returns:
dvc.config.Config: config object.


def build_nccl_all_reduce(input_tensors, red_op, un_op=None):
    if red_op == math_ops.add:
        output_tensors = nccl_ops.all_sum(input_tensors)
    else:
        raise ValueError('red_op not supported by NCCL all-reduce: ', red_op)
    if un_op:
        un_op_wrapped = []
        for t in output_tensors:
            with ops.colocate_with(t):
                un_op_wrapped.append(un_op(t))
        output_tensors = un_op_wrapped
    return output_tensors

Build a subgraph that does one full all-reduce, using NCCL.

Args:
input_tensors: list of `tf.Tensor` of same-shape and type values to
be reduced.
red_op: binary elementwise reduction operator. Must be one of
{tf.add}
un_op: optional unary elementwise Op to apply to fully-reduce values.

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

Raises:
ValueError: red_op not supported.


class PatchTSMixerGatedAttention(nn.Module):

    def __init__(self, in_size: int, out_size: int):
        super().__init__()
        self.attn_layer = nn.Linear(in_size, out_size)
        self.attn_softmax = nn.Softmax(dim=-1)

    def forward(self, inputs):
        attn_weight = self.attn_softmax(self.attn_layer(inputs))
        inputs = inputs * attn_weight
        return inputs

Module that applies gated attention to input data.

Args:
in_size (`int`): The input size.
out_size (`int`): The output size.


def validate_format(self, **kwargs):

        args = dict(
            dict_type=self._dict,
            allow_no_value=self._allow_no_value,
            inline_comment_prefixes=self._inline_comment_prefixes,
            strict=self._strict,
            empty_lines_in_values=self._empty_lines_in_values
        )
        args.update(kwargs)
        parser = ConfigParser(**args)
        updated_cfg = str(self)
        parser.read_string(updated_cfg)

Call ConfigParser to validate config

Args:
kwargs: are passed to :class:`configparser.ConfigParser`


def get_project_details(self, project_id):
    if (not is_valid_uuid(project_id)):
        raise StorageArgumentException('Invalid UUID for project_id: {0}'.format(project_id))
    return self._authenticated_request.to_endpoint('project/{}/'.format(project_id)).return_body().get()

Get information on a given project

Args:
project_id (str): The UUID of the requested project.

Returns:
A dictionary describing the project::

{
u'collab_id': 2271,
u'created_by': u'303447',
u'created_on': u'2017-03-10T12:50:06.077891Z',
u'description': u'',
u'entity_type': u'project',
u'modified_by': u'303447',
u'modified_on': u'2017-03-10T12:50:06.077946Z',
u'name': u'2271',
u'uuid': u'3abd8742-d069-44cf-a66b-2370df74a682'
}

Raises:
StorageForbiddenException: Server response code 403
StorageNotFoundException: Server response code 404
StorageException: other 400-600 error codes


def _resource_apply_dense(self, grad, handle):
    raise NotImplementedError()

Add ops to apply dense gradients to the variable `handle`.

Args:
grad: a `Tensor` representing the gradient.
handle: a `Tensor` of dtype `resource` which points to the variable
to be updated.

Returns:
An `Operation` which updates the value of the variable.


def add_output(self, output):

        if not isinstance(output, Output):
            raise TypeError('`output` must be an Output instance or None')
        self.outputs.append(output)

Adds an output to a Transaction's list of outputs.

Args:
output (:class:`~bigchaindb.common.transaction.
Output`): An Output to be added to the
Transaction.


def is_bit_mask(enumeration, potential_mask):
    if (not isinstance(potential_mask, six.integer_types)):
        return False
    mask_enumerations = (CryptographicUsageMask, ProtectionStorageMask, StorageStatusMask)
    if (enumeration not in mask_enumerations):
        return False
    mask = 0
    for value in [e.value for e in enumeration]:
        if ((value & potential_mask) == value):
            mask |= value
    if (mask != potential_mask):
        return False
    return True

A utility function that checks if the provided value is a composite bit
mask of enumeration values in the specified enumeration class.

Args:
enumeration (class): One of the mask enumeration classes found in this
file. These include:
* Cryptographic Usage Mask
* Protection Storage Mask
* Storage Status Mask
potential_mask (int): A potential bit mask composed of enumeration
values belonging to the enumeration class.

Returns:
True: if the potential mask is a valid bit mask of the mask enumeration
False: otherwise


def filter(self, field_name, operand, value):
    if (operand not in self._FILTER_OPERANDS):
        raise ValueError('Operand must be one of {}'.format(', '.join(self._FILTER_OPERANDS)))
    record_stub = record_factory(self._app)
    field = record_stub.get_field(field_name)
    self._raw['filters'].append({'fieldId': field.id, 'filterType': operand, 'value': field.get_report(value)})

Adds a filter to report

Notes:
All filters are currently AND'ed together

Args:
field_name (str): Target field name to filter on
operand (str): Operand used in comparison. See `swimlane.core.search` for options
value: Target value used in comparision


def CreateDataTypeMap(self, definition_name):
    data_type_definition = self._definitions_registry.GetDefinitionByName(definition_name)
    if (not data_type_definition):
        return None
    return DataTypeMapFactory.CreateDataTypeMapByType(data_type_definition)

Creates a specific data type map by name.

Args:
definition_name (str): name of the data type definition.

Returns:
DataTypeMap: data type map or None if the date type definition
is not available.


def lex_index(n, k, lst):

    if len(lst) != k:
        raise VisualizationError("list should have length k")
    comb = list(map(lambda x: n - 1 - x, lst))
    dualm = sum([n_choose_k(comb[k - 1 - i], i + 1) for i in range(k)])
    return int(dualm)

Return  the lex index of a combination..

Args:
n (int): the total number of options .
k (int): The number of elements.
lst (list): list

Returns:
int: returns int index for lex order

Raises:
VisualizationError: if length of list is not equal to k


def get_site_orbital_dos(self, site, orbital):

        return Dos(self.efermi, self.energies, self.pdos[site][orbital])

Get the Dos for a particular orbital of a particular site.

Args:
site: Site in Structure associated with CompleteDos.
orbital: Orbital in the site.

Returns:
Dos containing densities for orbital of site.


def _init_profile_batch(self, profile_batch):
    profile_batch_error_message = 'profile_batch must be a non-negative integer or 2-tuple of positive integers. A pair of positive integers signifies a range of batches to profile. Found: {}'.format(profile_batch)
    if isinstance(profile_batch, str):
        profile_batch = str(profile_batch).split(',')
        profile_batch = nest.map_structure(int, profile_batch)
    if isinstance(profile_batch, int):
        self._start_batch = profile_batch
        self._stop_batch = profile_batch
    elif isinstance(profile_batch, (tuple, list)) and len(profile_batch) == 2:
        self._start_batch, self._stop_batch = profile_batch
    else:
        raise ValueError(profile_batch_error_message)
    if self._start_batch < 0 or self._stop_batch < self._start_batch:
        raise ValueError(profile_batch_error_message)
    self._profiler_started = False
    if self._start_batch > 0:
        self._start_profiler(logdir='')
        self._stop_profiler(save=False)
    self._is_tracing = False
    self._should_trace = not (self._start_batch == 0 and self._stop_batch == 0)

Validate profile_batch value and set the range of batches to profile.
Sets values of _start_batch and _stop_batch attributes,
specifying the start and stop batch to profile.
Setting `profile_batch=0` disables profiling.

Args:
profile_batch: The range of batches to profile. Should be a non-negative
integer or a comma separated string of pair of positive integers. A pair
of positive integers signify a range of batches to profile.

Raises:
ValueError: If profile_batch is not an integer or a comma separated pair
of positive integers.


def get_creator_by_name(name):

    return {'docker(container)': Container.creator,
            'shell': Bash.creator, 'docker(image)': Image.creator,
            'python': Script.creator, 'packer': Packer.creator,
            'ansible(simple)': Ansible.creator}[name]

Get creator function by name.

Args:
name (str): name of the creator function.

Returns:
function: creater function.


def email_address(self, address, owner=None, **kwargs):

        return EmailAddress(self.tcex, address, owner=owner, **kwargs)

Create the Email Address TI object.

Args:
owner:
address:
**kwargs:

Return:


Converts CamelCase to snake_case.

Args:
name (string): The name to convert from CamelCase to snake_case.

Returns:
string: Converted string.


def __edit_distance_alt(self, words):
    words = [x.lower() for x in words]
    return [e2 for e1 in words for e2 in self.edit_distance_1(e1)]

Compute all strings that are 1 edits away from all the words using
only the letters in the corpus

Args:
words (list): The words for which to calculate the edit distance
Returns:
set: The set of strings that are edit distance two from the \
provided words


def get_audio_features(self, input_features: torch.FloatTensor, feature_attention_mask: Optional[torch.LongTensor]=None, audio_feature_lengths: Optional[torch.LongTensor]=None):
    if feature_attention_mask is not None:
        audio_feature_lengths = torch.sum(feature_attention_mask, dim=1)
        input_features = input_features.permute(0, 2, 1)[feature_attention_mask.bool()].permute(1, 0)
    else:
        audio_feature_lengths = None
    audio_feat_lengths, audio_output_lengths = self.audio_tower._get_feat_extract_output_lengths(audio_feature_lengths if audio_feature_lengths is not None else feature_attention_mask.sum(-1))
    feature_lens = audio_feature_lengths if audio_feature_lengths is not None else feature_attention_mask.sum(-1)
    audio_outputs = self.audio_tower(input_features, feature_lens=feature_lens, aftercnn_lens=audio_feat_lengths)
    audio_features = audio_outputs.last_hidden_state
    if audio_features.shape[0] != sum(audio_output_lengths.tolist()):
        raise ValueError('length of audio_features should match audio_output_lengths')
    return audio_features

Encodes audios into continuous embeddings that can be forwarded to the language model.

Args:
input_features (`torch.FloatTensor`):
The tensors corresponding to the input audios.
feature_attention_mask (`torch.LongTensor`, *optional*):
Mask to avoid performing attention on padding feature indices. Mask values selected in `[0, 1]`:
audio_feature_lengths (`torch.LongTensor` of shape `(num_audios)`, *optional*):
The length of feature shape of each audio in LLM.


def ReadTimestamp(filename):
    if not os.path.exists(filename):
        return None
    try:
        timestamp_file = open(filename, 'r')
        timestamp_string = timestamp_file.read().strip()
    except IOError as e:
        logging.warning('error opening timestamp file: %s', e)
        timestamp_string = None
    else:
        timestamp_file.close()
    logging.debug('read timestamp %s from file %r', timestamp_string, filename)
    if timestamp_string is not None:
        try:
            timestamp = time.strptime(timestamp_string + ' UTC', '%Y-%m-%dT%H:%M:%SZ %Z')
        except ValueError as e:
            logging.error('cannot parse timestamp file %r: %s', filename, e)
            timestamp = None
    else:
        timestamp = None
    logging.debug('Timestamp is: %r', timestamp)
    now = time.gmtime()
    logging.debug('      Now is: %r', now)
    if timestamp > now:
        logging.warning('timestamp %r (%r) from %r is in the future, now is %r', timestamp_string, time.mktime(timestamp), filename, time.mktime(now))
        if time.mktime(timestamp) - time.mktime(now) >= 60 * 60:
            logging.info('Resetting timestamp to now.')
            timestamp = now
    return timestamp

Return a timestamp from a file.

The timestamp file format is a single line, containing a string in the
ISO-8601 format YYYY-MM-DDThh:mm:ssZ (i.e. UTC time).  We do not support
all ISO-8601 formats for reasons of convenience in the code.

Timestamps internal to nss_cache deliberately do not carry milliseconds.

Args:
filename:  A String naming the file to read from.

Returns:
A time.struct_time, or None if the timestamp file doesn't
exist or has errors.


def get_contact(self, response=None, nir=None, handle=None, retry_count=3, dt_format=None):
    if (response or (nir == 'krnic')):
        contact_response = response
    else:
        contact_response = self._net.get_http_raw(url=str(NIR_WHOIS[nir]['url']).format(handle), retry_count=retry_count, headers=NIR_WHOIS[nir]['request_headers'], request_type=NIR_WHOIS[nir]['request_type'])
    return self.parse_fields(response=contact_response, fields_dict=NIR_WHOIS[nir]['contact_fields'], dt_format=dt_format, hourdelta=int(NIR_WHOIS[nir]['dt_hourdelta']), is_contact=True)

The function for retrieving and parsing NIR whois data based on
NIR_WHOIS contact_fields.

Args:
response (:obj:`str`): Optional response object, this bypasses the
lookup.
nir (:obj:`str`): The NIR to query ('jpnic' or 'krnic'). Required
if response is None.
handle (:obj:`str`): For NIRs that have separate contact queries
(JPNIC), this is the contact handle to use in the query.
Defaults to None.
retry_count (:obj:`int`): The number of times to retry in case
socket errors, timeouts, connection resets, etc. are
encountered. Defaults to 3.
dt_format (:obj:`str`): The format of datetime fields if known.
Defaults to None.

Returns:
dict: Mapping of the fields provided in contact_fields, to their
parsed results.


def rmdir(path, dir_fd=None):
    system = get_instance(path)
    system.remove(system.ensure_dir_path(path))

Remove a directory.

Equivalent to "os.rmdir".

Args:
path (path-like object): Path or URL.
dir_fd: directory descriptors;
see the os.rmdir() description for how it is interpreted.
Not supported on cloud storage objects.


def set_viewbox(self, x, y, w, h):
    self.attributes['viewBox'] = ('%s %s %s %s' % (x, y, w, h))
    self.attributes['preserveAspectRatio'] = 'none'

Sets the origin and size of the viewbox, describing a virtual view area.

Args:
x (int): x coordinate of the viewbox origin
y (int): y coordinate of the viewbox origin
w (int): width of the viewbox
h (int): height of the viewbox


def to_grid_locator(latitude, longitude, precision='square'):
    if (precision not in ('square', 'subsquare', 'extsquare')):
        raise ValueError(('Unsupported precision value %r' % precision))
    if (not ((- 90) <= latitude <= 90)):
        raise ValueError(('Invalid latitude value %r' % latitude))
    if (not ((- 180) <= longitude <= 180)):
        raise ValueError(('Invalid longitude value %r' % longitude))
    latitude += 90.0
    longitude += 180.0
    locator = []
    field = int((longitude / LONGITUDE_FIELD))
    locator.append(chr((field + 65)))
    longitude -= (field * LONGITUDE_FIELD)
    field = int((latitude / LATITUDE_FIELD))
    locator.append(chr((field + 65)))
    latitude -= (field * LATITUDE_FIELD)
    square = int((longitude / LONGITUDE_SQUARE))
    locator.append(str(square))
    longitude -= (square * LONGITUDE_SQUARE)
    square = int((latitude / LATITUDE_SQUARE))
    locator.append(str(square))
    latitude -= (square * LATITUDE_SQUARE)
    if (precision in ('subsquare', 'extsquare')):
        subsquare = int((longitude / LONGITUDE_SUBSQUARE))
        locator.append(chr((subsquare + 97)))
        longitude -= (subsquare * LONGITUDE_SUBSQUARE)
        subsquare = int((latitude / LATITUDE_SUBSQUARE))
        locator.append(chr((subsquare + 97)))
        latitude -= (subsquare * LATITUDE_SUBSQUARE)
    if (precision == 'extsquare'):
        extsquare = int((longitude / LONGITUDE_EXTSQUARE))
        locator.append(str(extsquare))
        extsquare = int((latitude / LATITUDE_EXTSQUARE))
        locator.append(str(extsquare))
    return ''.join(locator)

Calculate Maidenhead locator from latitude and longitude.

Args:
latitude (float): Position's latitude
longitude (float): Position's longitude
precision (str): Precision with which generate locator string

Returns:
str: Maidenhead locator for latitude and longitude

Raise:
ValueError: Invalid precision identifier
ValueError: Invalid latitude or longitude value


def update_user_attributes(self, user, claims):

        required_fields = [field.name for field in user._meta.fields if field.blank is False]

        for field, claim in settings.CLAIM_MAPPING.items():
            if hasattr(user, field):
                if claim in claims:
                    setattr(user, field, claims[claim])
                    logger.debug("Attribute '{}' for user '{}' was set to '{}'.".format(field, user, claims[claim]))
                else:
                    if field in required_fields:
                        msg = "Claim not found in access token: '{}'. Check ADFS claims mapping."
                        raise ImproperlyConfigured(msg.format(claim))
                    else:
                        msg = "Claim '{}' for user field '{}' was not found in the access token for user '{}'. " \
                              "Field is not required and will be left empty".format(claim, field, user)
                        logger.warning(msg)
            else:
                msg = "User model has no field named '{}'. Check ADFS claims mapping."
                raise ImproperlyConfigured(msg.format(field))

Updates user attributes based on the CLAIM_MAPPING setting.

Args:
user (django.contrib.auth.models.User): User model instance
claims (dict): claims from the access token


def is_extension_type(tensor):
    return isinstance(tensor, composite_tensor.CompositeTensor)

Returns whether a tensor is of an ExtensionType.

github.com/tensorflow/community/pull/269
Currently it works by checking if `tensor` is a `CompositeTensor` instance,
but this will be changed to use an appropriate extensiontype protocol
check once ExtensionType is made public.

Args:
tensor: An object to test

Returns:
True if the tensor is an extension type object, false if not.


def iaf_hparams(hidden_size=512, filter_size=4096):

  hparams = common_hparams.basic_params1()

  hparams.hidden_size = hidden_size
  hparams.add_hparam("attention_key_channels", None)
  hparams.add_hparam("attention_value_channels", None)
  hparams.add_hparam("num_heads", 4)
  hparams.add_hparam("attention_dropout", 0.1)
  hparams.add_hparam("shared_rel", False)
  hparams.add_hparam("block_width", 1)
  hparams.add_hparam("block_length", 1)
  hparams.add_hparam("q_filter_width", 1)
  hparams.add_hparam("kv_filter_width", 1)

  hparams.layer_preprocess_sequence = "n"
  hparams.layer_prepostprocess_dropout = 0.1
  hparams.norm_type = "layer"
  hparams.norm_epsilon = 1e-06
  hparams.layer_prepostprocess_dropout_broadcast_dims = ""
  hparams.layer_postprocess_sequence = "da"

  hparams.add_hparam("filter_size", filter_size)
  hparams.add_hparam("ffn_layer", "conv_hidden_relu")
  hparams.add_hparam("relu_dropout", 0.1)
  return hparams

Create hyperpameters for inverse autoregressive flows.

Args:
hidden_size: Width of attention layers and neural network output layer.
filter_size: Hidden layer width for neural network.

Returns:
hparams: Hyperpameters with basic presets for inverse autoregressive flows.


def setup_logging(verbosity, formats=None):

    if formats is None:
        formats = {}

    log_level = logging.INFO

    log_format = formats.get("info", INFO_FORMAT)

    if sys.stdout.isatty():
        log_format = formats.get("color", COLOR_FORMAT)

    if verbosity > 0:
        log_level = logging.DEBUG
        log_format = formats.get("debug", DEBUG_FORMAT)

    if verbosity < 2:
        logging.getLogger("botocore").setLevel(logging.CRITICAL)

    hdlr = logging.StreamHandler()
    hdlr.setFormatter(ColorFormatter(log_format, ISO_8601))
    logging.root.addHandler(hdlr)
    logging.root.setLevel(log_level)

Configure a proper logger based on verbosity and optional log formats.

Args:
verbosity (int): 0, 1, 2
formats (dict): Optional, looks for `info`, `color`, and `debug` keys
which may override the associated default log formats.


def metadata_extractor(self):
    if (not hasattr(self, '_local_file')):
        raise AttributeError('local_file attribute must be set before calling metadata_extractor')
    if (not hasattr(self, '_metadata_extractor')):
        if self.local_file.endswith('.whl'):
            logger.info('Getting metadata from wheel using WheelMetadataExtractor.')
            extractor_cls = metadata_extractors.WheelMetadataExtractor
        else:
            logger.info('Getting metadata from setup.py using SetupPyMetadataExtractor.')
            extractor_cls = metadata_extractors.SetupPyMetadataExtractor
        base_python_version = (self.base_python_version or self.template_base_py_ver)
        self._metadata_extractor = extractor_cls(self.local_file, self.name, self.name_convertor, self.version, self.rpm_name, self.venv, base_python_version)
    return self._metadata_extractor

Returns an instance of proper MetadataExtractor subclass.
Always returns the same instance.

Returns:
The proper MetadataExtractor subclass according to local file
suffix.


def cmd2(command, shell=False, detatch=False, verbose=False, verbout=None):
    import shlex
    if isinstance(command, (list, tuple)):
        raise ValueError('command tuple not supported yet')
    args = shlex.split(command, posix=(not WIN32))
    if (verbose is True):
        verbose = 2
    if (verbout is None):
        verbout = (verbose >= 1)
    if (verbose >= 2):
        print('+=== START CMD2 ===')
        print('Command:')
        print(command)
        if verbout:
            print('----')
            print('Stdout:')
    proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell, universal_newlines=True)
    if detatch:
        info = {'proc': proc}
    else:
        write_fn = sys.stdout.write
        flush_fn = sys.stdout.flush
        logged_out = []
        for line in _run_process(proc):
            line_ = (line if six.PY2 else line)
            if (len(line_) > 0):
                if verbout:
                    write_fn(line_)
                    flush_fn()
                logged_out.append(line)
        try:
            from utool import util_str
            out = ''.join(logged_out)
        except UnicodeDecodeError:
            from utool import util_str
            logged_out = util_str.ensure_unicode_strlist(logged_out)
            out = ''.join(logged_out)
        (out_, err) = proc.communicate()
        ret = proc.wait()
        info = {'out': out, 'err': err, 'ret': ret}
    if (verbose >= 2):
        print('L___ END CMD2 ___')
    return info

Trying to clean up cmd

Args:
command (str): string command
shell (bool): if True, process is run in shell
detatch (bool): if True, process is run in background
verbose (int): verbosity mode
verbout (bool): if True, `command` writes to stdout in realtime.
defaults to True iff verbose > 0

Returns:
dict: info - information about command status