def remove_backup(name):

    if name not in list_backups():
        log.debug('Backup already removed: %s', name)
        return True

    ps_cmd = ['Remove-WebConfigurationBackup',
              '-Name', "'{0}'".format(name)]

    cmd_ret = _srvmgr(ps_cmd)

    if cmd_ret['retcode'] != 0:
        msg = 'Unable to remove web configuration: {0}\nError: {1}' \
              ''.format(name, cmd_ret['stderr'])
        raise CommandExecutionError(msg)

    return name not in list_backups()

Remove an IIS Configuration backup from the System.

.. versionadded:: 2017.7.0

Args:
name (str): The name of the backup to remove

Returns:
bool: True if successful, otherwise False

CLI Example:

.. code-block:: bash

salt '*' win_iis.remove_backup backup_20170209


def delete(self, branch, commit_message, **kwargs):

        file_path = self.get_id().replace('/', '%2F')
        self.manager.delete(file_path, branch, commit_message, **kwargs)

Delete the file from the server.

Args:
branch (str): Branch from which the file will be removed
commit_message (str): Commit message for the deletion
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabDeleteError: If the server cannot perform the request


def FromLdapToTimestamp(self, ldap_ts_string):
    if isinstance(ldap_ts_string, bytes):
        ldap_ts_string = ldap_ts_string.decode('utf-8')
    try:
        if self.conf.get('ad'):
            t = time.strptime(ldap_ts_string, '%Y%m%d%H%M%S.0Z')
        else:
            t = time.strptime(ldap_ts_string, '%Y%m%d%H%M%SZ')
    except ValueError:
        m = re.match('([0-9]*)(\\.[0-9]*)?(Z)', ldap_ts_string)
        if m:
            ldap_ts_string = m.group(1) + m.group(3)
        if self.conf.get('ad'):
            t = time.strptime(ldap_ts_string, '%Y%m%d%H%M%S.0Z')
        else:
            t = time.strptime(ldap_ts_string, '%Y%m%d%H%M%SZ')
    return int(calendar.timegm(t))

Transforms a LDAP timestamp into the nss_cache internal timestamp.

Args:
ldap_ts_string: An LDAP timestamp string in the format %Y%m%d%H%M%SZ

Returns:
number of seconds since epoch.


def AddToBalance(self, assetId, fixed8_val):
    found = False
    for (key, balance) in self.Balances.items():
        if (key == assetId):
            self.Balances[assetId] = (self.Balances[assetId] + fixed8_val)
            found = True
    if (not found):
        self.Balances[assetId] = fixed8_val

Add amount to the specified balance.

Args:
assetId (UInt256):
fixed8_val (Fixed8): amount to add.


def _validate_isvalid_composition(self, isvalid_composition, field, value):
    sum_amount = 0.0
    if (value['kind'] in ['mass fraction', 'mole fraction']):
        low_lim = 0.0
        up_lim = 1.0
        total_amount = 1.0
    elif (value['kind'] in ['mole percent']):
        low_lim = 0.0
        up_lim = 100.0
        total_amount = 100.0
    else:
        self._error(field, 'composition kind must be "mole percent", "mass fraction", or "mole fraction"')
        return False
    for sp in value['species']:
        amount = sp['amount'][0]
        sum_amount += amount
        if (amount < low_lim):
            self._error(field, (((('Species ' + sp['species-name']) + ' ') + value['kind']) + ' must be greater than {:.1f}'.format(low_lim)))
        elif (amount > up_lim):
            self._error(field, (((('Species ' + sp['species-name']) + ' ') + value['kind']) + ' must be less than {:.1f}'.format(up_lim)))
    if (not np.isclose(total_amount, sum_amount)):
        self._error(field, ((('Species ' + value['kind']) + 's do not sum to {:.1f}: '.format(total_amount)) + '{:f}'.format(sum_amount)))

Checks for valid specification of composition.

Args:
isvalid_composition (bool): flag from schema indicating
composition to be checked.
field (str): 'composition'
value (dict): dictionary of composition

The rule's arguments are validated against this schema:
{'isvalid_composition': {'type': 'bool'}, 'field': {'type': 'str'},
'value': {'type': 'dict'}}


def keras_serializable(cls):
    initializer = cls.__init__
    config_class = getattr(cls, 'config_class', None)
    if config_class is None:
        raise AttributeError('Must set `config_class` to use @keras_serializable')

    @functools.wraps(initializer)
    def wrapped_init(self, *args, **kwargs):
        config = args[0] if args and isinstance(args[0], PretrainedConfig) else kwargs.pop('config', None)
        if isinstance(config, dict):
            config = config_class.from_dict(config)
            initializer(self, config, *args, **kwargs)
        elif isinstance(config, PretrainedConfig):
            if len(args) > 0:
                initializer(self, *args, **kwargs)
            else:
                initializer(self, config, *args, **kwargs)
        else:
            raise ValueError('Must pass either `config` (PretrainedConfig) or `config` (dict)')
        self._config = config
        self._kwargs = kwargs
    cls.__init__ = wrapped_init
    if not hasattr(cls, 'get_config'):
        raise TypeError('Only use @keras_serializable on keras.layers.Layer subclasses')
    if hasattr(cls.get_config, '_is_default'):

        def get_config(self):
            cfg = super(cls, self).get_config()
            cfg['config'] = self._config.to_dict()
            cfg.update(self._kwargs)
            return cfg
        cls.get_config = get_config
    cls._keras_serializable = True
    if hasattr(keras.utils, 'register_keras_serializable'):
        cls = keras.utils.register_keras_serializable()(cls)
    return cls

Decorate a Keras Layer class to support Keras serialization.

This is done by:

1. Adding a `transformers_config` dict to the Keras config dictionary in `get_config` (called by Keras at
serialization time.
2. Wrapping `__init__` to accept that `transformers_config` dict (passed by Keras at deserialization time) and
convert it to a config object for the actual layer initializer.
3. Registering the class as a custom object in Keras (if the Tensorflow version supports this), so that it does not
need to be supplied in `custom_objects` in the call to `keras.models.load_model`.

Args:
cls (a `keras.layers.Layers subclass`):
Typically a `TF.MainLayer` class in this project, in general must accept a `config` argument to its
initializer.

Returns:
The same class object, with modifications for Keras deserialization.


def outputZip(self, figtype='png'):
    from zipfile import ZipFile
    with ZipFile((self.outfile + '.zip'), 'w') as zipcontainer:
        zipcontainer.writestr('summary.txt', '
        c = count(1)
        for section in self.sections:
            section.sectionOutZip(zipcontainer, 's{}_{}/'.format(next(c), section.title.replace(' ', '_')), figtype=figtype)

Outputs the report in a zip container.
Figs and tabs as pngs and excells.

Args:
figtype (str): Figure type of images in the zip folder.


def exp(array, ty):
    weld_obj = WeldObject(encoder_, decoder_)
    array_var = weld_obj.update(array)
    if isinstance(array, WeldObject):
        array_var = array.obj_id
        weld_obj.dependencies[array_var] = array
    weld_template = '\n       map(\n         %(array)s,\n         |ele: %(ty)s| exp(ele)\n       )\n    '
    weld_obj.weld_code = (weld_template % {'array': array_var, 'ty': ty})
    return weld_obj

Computes the per-element exponenet of the passed-in array.

Args:
array (WeldObject / Numpy.ndarray): Input array
ty (WeldType): Type of each element in the input array

Returns:
A WeldObject representing this computation


def describe(self, model_name):

    model_yaml = yaml.safe_dump(self.get_model_details(model_name), default_flow_style=False)
    print(model_yaml)

Print information of a specified model.

Args:
model_name: the name of the model to print details on.


def getSubjectInfo(self, subject, vendorSpecific=None):

        response = self.getSubjectInfoResponse(subject, vendorSpecific)
        return self._read_dataone_type_response(response, 'SubjectInfo')

See Also: getSubjectInfoResponse()

Args:
subject:
vendorSpecific:

Returns:


def get_available_references(self, datas):
    names = []
    for (k, v) in datas.items():
        if k.startswith(RULE_REFERENCE):
            names.append(k[(len(RULE_REFERENCE) + 1):])
    return names

Get available manifest reference names.

Every rules starting with prefix from ``nomenclature.RULE_REFERENCE``
are available references.

Only name validation is performed on these references.

Arguments:
datas (dict): Data where to search for reference declarations.

Returns:
list: List of every available reference names. This is the real
name unprefixed.


def crcMeterRead(self, raw_read, def_buf):

        try:
            if len(raw_read) == 0:
                ekm_log("(" + self.m_context + ") Empty return read.")
                return False
            sent_crc = self.calc_crc16(raw_read[1:-2])
            logstr = "(" + self.m_context + ")CRC sent = " + str(def_buf["crc16"][MeterData.StringValue])
            logstr += " CRC calc = " + sent_crc
            ekm_log(logstr)
            if int(def_buf["crc16"][MeterData.StringValue], 16) == int(sent_crc, 16):
                return True

        except struct.error:
            ekm_log(str(sys.exc_info()))
            for frame in traceback.extract_tb(sys.exc_info()[2]):
                fname, lineno, fn, text = frame
                ekm_log("Error in %s on line %d" % (fname, lineno))
            return False

        except TypeError:
            ekm_log(str(sys.exc_info()))
            for frame in traceback.extract_tb(sys.exc_info()[2]):
                fname, lineno, fn, text = frame
                ekm_log("Error in %s on line %d" % (fname, lineno))
            return False

        except ValueError:
            ekm_log(str(sys.exc_info()))
            for frame in traceback.extract_tb(sys.exc_info()[2]):
                fname, lineno, fn, text = frame
                ekm_log("Error in %s on line %d" % (fname, lineno))
            return False

        return False

Internal read CRC wrapper.

Args:
raw_read (str): Bytes with implicit string cast from serial read
def_buf (SerialBlock): Populated read buffer.

Returns:
bool:  True if passed CRC equals calculated CRC.


def __init__(self, input_size: int, num_experts: int, top_k: int):
    super().__init__()
    self.num_experts = num_experts
    self.input_size = input_size
    self.top_k = top_k
    self.layer = nn.Linear(input_size, num_experts, bias=False)

Initialize the top-k gating mechanism.
Args:
input_size (`int`):
Size of the input.
num_experts (`int`):
Number of experts.
top_k (`int`):
Number of top experts to select.


def _parse_symbol(self, sym):

        special = {"Hw": "H", "Ow": "O", "Wat": "O",
                   "wat": "O", "OH": "", "OH2": "", "NO3": "N"}

        parsed_sym = None

        m_sp = re.match("|".join(special.keys()), sym)
        if m_sp:
            parsed_sym = special[m_sp.group()]
        elif Element.is_valid_symbol(sym[:2].title()):
            parsed_sym = sym[:2].title()
        elif Element.is_valid_symbol(sym[0].upper()):
            parsed_sym = sym[0].upper()
        else:
            m = re.match(r"w?[A-Z][a-z]*", sym)
            if m:
                parsed_sym = m.group()

        if parsed_sym is not None and (m_sp or not re.match(r"{}\d*".format(parsed_sym), sym)):
            msg = "{} parsed as {}".format(sym, parsed_sym)
            warnings.warn(msg)
            self.errors.append(msg)

        return parsed_sym

Parse a string with a symbol to extract a string representing an element.

Args:
sym (str): A symbol to be parsed.

Returns:
A string with the parsed symbol. None if no parsing was possible.


def _collect_layer_statistics(self) -> Dict[str, Dict[str, float]]:
    layer_statistics = collections.defaultdict(lambda: collections.defaultdict(list))
    initialize = True
    for tensor_data in self._data_gen():
        self._set_input_tensors(self._quant_interpreter, tensor_data, initialize)
        initialize = False
        self._quant_interpreter.invoke()
        for tensor_detail in self._get_numeric_verify_tensor_details():
            tensor_name = tensor_detail['name']
            diffs = self._quant_interpreter.get_tensor(tensor_detail['index'])
            for metric_name, metric_fn in self._layer_debug_metrics.items():
                layer_statistics[tensor_name][metric_name].append(metric_fn(diffs))
        if self._debug_options.layer_direct_compare_metrics is not None:
            for tensor_detail in self._get_numeric_verify_tensor_details():
                tensor_name = tensor_detail['name']
                op_idx = self._defining_op[tensor_detail['index']]
                op_detail = self._quant_interpreter._get_op_details(op_idx)
                q_idx, f_idx = op_detail['inputs']
                quant_input_detail = self._quant_interpreter._get_tensor_details(q_idx, subgraph_index=0)
                for metric_name, metric_fn in self._debug_options.layer_direct_compare_metrics.items():
                    layer_statistics[tensor_name][metric_name].append(metric_fn(self._quant_interpreter.get_tensor(f_idx), self._quant_interpreter.get_tensor(q_idx), quant_input_detail['quantization_parameters']['scales'][0], quant_input_detail['quantization_parameters']['zero_points'][0]))
    for metrics in layer_statistics.values():
        for metric_name in metrics:
            metrics[metric_name] = np.nanmean(metrics[metric_name])
    return layer_statistics

Collects layer statistics by applying layer debug metrics.

For all data from the given RepresentativeDataset, collect statistics per
example by getting the NumericVerify op results in _quant_interpreter
and calculating layer debug metrics on the results.

Returns:
aggregated per-layer statistics of NumericVerify results.
{layer_name: {metric_name: metric}}


def register_actor(name, actor_handle):

    if not isinstance(name, str):
        raise TypeError("The name argument must be a string.")
    if not isinstance(actor_handle, ray.actor.ActorHandle):
        raise TypeError("The actor_handle argument must be an ActorHandle "
                        "object.")
    actor_name = _calculate_key(name)
    pickled_state = pickle.dumps(actor_handle)

    already_exists = _internal_kv_put(actor_name, pickled_state)
    if already_exists:

        actor_handle._ray_new_actor_handles.pop()
        raise ValueError(
            "Error: the actor with name={} already exists".format(name))

Register a named actor under a string key.

Args:
name: The name of the named actor.
actor_handle: The actor object to be associated with this name


def parent(self):
    if (len(self._path) == 1):
        return None
    else:
        parent_path = self._path[:(- 1)]
    return self._client.document(*parent_path)

Document that owns the current collection.

Returns:
Optional[~.firestore_v1beta1.document.DocumentReference]: The
parent document, if the current collection is not a
top-level collection.


def view(molecule, viewer=settings['defaults']['viewer'], use_curr_dir=False):
    try:
        molecule.view(viewer=viewer, use_curr_dir=use_curr_dir)
    except AttributeError:
        if pd.api.types.is_list_like(molecule):
            cartesian_list = molecule
        else:
            raise ValueError('Argument is neither list nor Cartesian.')
        if use_curr_dir:
            TEMP_DIR = os.path.curdir
        else:
            TEMP_DIR = tempfile.gettempdir()

        def give_filename(i):
            filename = (('ChemCoord_list_' + str(i)) + '.molden')
            return os.path.join(TEMP_DIR, filename)
        i = 1
        while os.path.exists(give_filename(i)):
            i = (i + 1)
        to_molden(cartesian_list, buf=give_filename(i))

        def open_file(i):
            'Open file and close after being finished.'
            try:
                subprocess.check_call([viewer, give_filename(i)])
            except (subprocess.CalledProcessError, FileNotFoundError):
                raise
            finally:
                if use_curr_dir:
                    pass
                else:
                    os.remove(give_filename(i))
        Thread(target=open_file, args=(i,)).start()

View your molecule or list of molecules.

.. note:: This function writes a temporary file and opens it with
an external viewer.
If you modify your molecule afterwards you have to recall view
in order to see the changes.

Args:
molecule: Can be a cartesian, or a list of cartesians.
viewer (str): The external viewer to use. The default is
specified in settings.viewer
use_curr_dir (bool): If True, the temporary file is written to
the current diretory. Otherwise it gets written to the
OS dependendent temporary directory.

Returns:
None:


def visit(self, visitor):
    visited = set()
    self._root_transform().visit(visitor, self, visited)

Visits depth-first every node of a pipeline's DAG.

Runner-internal implementation detail; no backwards-compatibility guarantees

Args:
visitor (~apache_beam.pipeline.PipelineVisitor):
:class:`~apache_beam.pipeline.PipelineVisitor` object whose callbacks
will be called for each node visited. See
:class:`~apache_beam.pipeline.PipelineVisitor` comments.

Raises:
TypeError: if node is specified and is not a
:class:`~apache_beam.pvalue.PValue`.
~apache_beam.error.PipelineError: if node is specified and does not
belong to this pipeline instance.


def _iceberg_io_read_test_preprocessor(test_spec: dict, expected: List[str], env: TestEnvironment):
    if (pipeline := test_spec.get('pipeline', None)):
        for transform in pipeline.get('transforms', []):
            if transform.get('type', '') == 'ReadFromIceberg':
                config = transform['config']
                db_name, table_name, field_value_dynamic_destinations = config['table'].split('.')
                transform['type'] = 'Create'
                transform['config'] = {k: v for k, v in config.items() if k.startswith('__')}
                transform['config']['elements'] = INPUT_TABLES[str(db_name), str(table_name), str(field_value_dynamic_destinations)]
    return test_spec

Preprocessor for tests that involve reading from Iceberg.

This preprocessor replaces any ReadFromIceberg transform with a Create
transform that reads from a predefined in-memory dictionary. This allows
the test to verify the pipeline's correctness without relying on Iceberg
tables stored externally.

Args:
test_spec: The dictionary representation of the YAML pipeline specification.
expected: A list of strings representing the expected output of the
pipeline.
env: The TestEnvironment object providing utilities for creating temporary
files.

Returns:
The modified test_spec dictionary with ReadFromIceberg transforms replaced.


def get_path(url):

        if url not in URLHelper.__cache:
            URLHelper.__cache[url] = urlparse(url)

        return URLHelper.__cache[url].path

Get the path (e.g /page/23) of the given URL.

Args:
url (str): The URL to get the path from.

Returns:
str: The path


def update(self, friendly_name=None, description=None, expiry=None, schema=None):

    self._load_info()
    if friendly_name is not None:
      self._info['friendlyName'] = friendly_name
    if description is not None:
      self._info['description'] = description
    if expiry is not None:
      if isinstance(expiry, datetime.datetime):
        expiry = calendar.timegm(expiry.utctimetuple()) * 1000
      self._info['expirationTime'] = expiry
    if schema is not None:
      if isinstance(schema, _schema.Schema):
        schema = schema._bq_schema
      self._info['schema'] = {'fields': schema}
    try:
      self._api.table_update(self._name_parts, self._info)
    except datalab.utils.RequestException:

      self._info = None
    except Exception as e:
      raise e

Selectively updates Table information.

Any parameters that are omitted or None are not updated.

Args:
friendly_name: if not None, the new friendly name.
description: if not None, the new description.
expiry: if not None, the new expiry time, either as a DateTime or milliseconds since epoch.
schema: if not None, the new schema: either a list of dictionaries or a Schema.


def execute_no_wait(self, cmd, walltime=2, envs={}):

        stdin, stdout, stderr = self.ssh_client.exec_command(
            self.prepend_envs(cmd, envs), bufsize=-1, timeout=walltime
        )
        return None, stdout, stderr

Execute asynchronousely without waiting for exitcode

Args:
- cmd (string): Commandline string to be executed on the remote side
- walltime (int): timeout to exec_command

KWargs:
- envs (dict): A dictionary of env variables

Returns:
- None, stdout (readable stream), stderr (readable stream)

Raises:
- ChannelExecFailed (reason)


def trace_tensor(tensor, tracepoint_name=None):
    if tracepoint_name is None:
        tracepoint_name = tensor.name
    tensor.graph.get_collection(_TENSOR_TRACER_COLLECTION)
    tensor.graph.add_to_collection(_TENSOR_TRACER_COLLECTION, (tensor, tracepoint_name))
    return tensor

Programmatic interface to trace a tensor with Tensor Tracer.

Tensor Tracer, by default, traces all tensors in the execution. This function
can be used to limit traced tensors. If this function is called for a subset
of the tensors, only those will be traced.

For example, Tensor Traacer will only trace c below.
c = tf.MatMul(a, b)
tensor_tracer.trace_tensor(c)
d = tf.add(c, 1)
Args:
tensor: the tensor object for which the tracing is requested.
tracepoint_name: an optional tensor tracepoint name string. A tracepoint
name is an Tensor Tracer internal name for the tensor. It is useful when
comparing equivalent traces from different models that have different
tensor namings. Equivalent tensors (with different names) can be mapped
to each other by assigning a common tracepoint_name.

Returns:
The provided tensor.


def wrap_text(text, width=80):

    text = re.sub(r"\s+", " ", text).strip()
    wrapper = TextWrapper(
        width=width, break_long_words=False, replace_whitespace=True
    )
    return wrapper.fill(text)

Wrap text lines to maximum *width* characters.

Wrapped text is aligned against the left text border.

Args:
text (str): Text to wrap.
width (int): Maximum number of characters per line.

Returns:
str: Wrapped text.


def insert_at_frontier(self,
                           operations: ops.OP_TREE,
                           start: int,
                           frontier: Dict[ops.Qid, int] = None
                           ) -> Dict[ops.Qid, int]:

        if frontier is None:
            frontier = defaultdict(lambda: 0)
        operations = tuple(ops.flatten_op_tree(operations))
        if not operations:
            return frontier
        qubits = set(q for op in operations for q in op.qubits)
        if any(frontier[q] > start for q in qubits):
            raise ValueError('The frontier for qubits on which the operations'
                             'to insert act cannot be after start.')

        next_moments = self.next_moments_operating_on(qubits, start)

        insertion_indices, _ = self._pick_inserted_ops_moment_indices(
            operations, start, frontier)

        self._push_frontier(frontier, next_moments)

        self._insert_operations(operations, insertion_indices)

        return frontier

Inserts operations inline at frontier.

Args:
operations: the operations to insert
start: the moment at which to start inserting the operations
frontier: frontier[q] is the earliest moment in which an operation
acting on qubit q can be placed.


def datetimeobj_d_b_Y_H_M_S(value):

    d, b, Y, t, Z = value.split()
    H, M, S = t.split(":")
    return datetime.datetime(
        int(Y), _months[b.lower()], int(d), int(H), int(M), int(S), tzinfo=TZ_GMT
    )

Convert timestamp string to a datetime object.

Timestamps strings like '18 Jun 2013 12:00:00 GMT' are able to be converted
by this function.

Args:
value: A timestamp string in the format '%d %b %Y %H:%M:%S GMT'.

Returns:
A datetime object.

Raises:
ValueError: If timestamp is invalid.
KeyError: If the abbrieviated month is invalid.

Note: The timezone is ignored it is simply assumed to be UTC/GMT.


def HandleClockSync(self, response):
    self.logger.info('Clock drift token has changed: %s.', response)
    self.distro_utils.HandleClockSync(self.logger)

Called when clock drift token changes.

Args:
response: string, the metadata response with the new drift token value.


def download_models(self, uniprot_acc, outdir='', force_rerun=False):

        downloaded = []
        subset = self.get_models(uniprot_acc)

        for entry in subset:
            ident = '{}_{}_{}_{}'.format(uniprot_acc, entry['template'], entry['from'], entry['to'])
            outfile = op.join(outdir, ident + '.pdb')

            if ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
                response = requests.get(entry['url'])

                if response.status_code == 404:
                    log.error('{}: 404 returned, no model available.'.format(ident))

                else:
                    with open(outfile, 'w') as f:
                        f.write(response.text)

                    log.debug('{}: downloaded homology model'.format(ident))
                    downloaded.append(outfile)
            else:
                downloaded.append(outfile)

        return downloaded

Download all models available for a UniProt accession number.

Args:
uniprot_acc (str): UniProt ACC/ID
outdir (str): Path to output directory, uses working directory if not set
force_rerun (bool): Force a redownload the models if they already exist

Returns:
list: Paths to the downloaded models


def save_state(self, out_path):

        state = self.dump_state()

        state = _clean_intenum(state)

        with open(out_path, "w") as outfile:
            json.dump(state, outfile, indent=4)

Save the current state of this emulated object to a file.

Args:
out_path (str): The path to save the dumped state of this emulated
object.


def unsubscribe(self, future):

        assert future not in self._pending_unsubscribes, \
            "%r has already been unsubscribed from" % \
            self._pending_unsubscribes[future]
        subscribe = self._requests[future]
        self._pending_unsubscribes[future] = subscribe

        self._subscriptions.pop(subscribe.id)
        request = Unsubscribe(subscribe.id)
        request.set_callback(self._q.put)
        try:
            controller = self.get_controller(subscribe.path[0])
        except ValueError:

            pass
        else:
            self.handle_request(controller, request)

Terminates the subscription given by a future

Args:
future (Future): The future of the original subscription


def sample(self, fields=None, count=5, sampling=None, use_cache=True, dialect=None, billing_tier=None):
    from . import _query
    sql = self._repr_sql_()
    return _query.Query.sampling_query(sql, context=self._context, count=count, fields=fields, sampling=sampling).results(use_cache=use_cache, dialect=dialect, billing_tier=billing_tier)

Retrieves a sampling of data from the table.

Args:
fields: an optional list of field names to retrieve.
count: an optional count of rows to retrieve which is used if a specific
sampling is not specified.
sampling: an optional sampling strategy to apply to the table.
use_cache: whether to use cached results or not.
dialect : {'legacy', 'standard'}, default 'legacy'
'legacy' : Use BigQuery's legacy SQL dialect.
'standard' : Use BigQuery's standard SQL (beta), which is
compliant with the SQL 2011 standard.
billing_tier: Limits the billing tier for this job. Queries that have resource
usage beyond this tier will fail (without incurring a charge). If unspecified, this
will be set to your project default. This can also be used to override your
project-wide default billing tier on a per-query basis.
Returns:
A QueryResultsTable object containing the resulting data.
Raises:
Exception if the sample query could not be executed or query response was malformed.


def project_hidden(x, projection_tensors, hidden_size, num_blocks):
    (batch_size, latent_dim, _) = common_layers.shape_list(x)
    x = tf.reshape(x, shape=[1, (- 1), hidden_size])
    x_tiled = tf.reshape(tf.tile(x, multiples=[num_blocks, 1, 1]), shape=[num_blocks, (- 1), hidden_size])
    x_projected = tf.matmul(x_tiled, projection_tensors)
    x_projected = tf.transpose(x_projected, perm=[1, 0, 2])
    x_4d = tf.reshape(x_projected, [batch_size, latent_dim, num_blocks, (- 1)])
    return x_4d

Project encoder hidden state under num_blocks using projection tensors.

Args:
x: Encoder hidden state of shape [batch_size, latent_dim,  hidden_size].
projection_tensors: Projection tensors used to project the hidden state.
hidden_size: Dimension of the latent space.
num_blocks: Number of blocks in DVQ.

Returns:
x_projected: Projected states of shape [batch_size, latent_dim, num_blocks,
hidden_size / num_blocks].


async def wait(self, timeout=None):

        await asyncio.wait_for(self._future, timeout)

        if self._exception is not None:
            self._raise_exception()

        return self._result

Wait for this operation to finish.

You can specify an optional timeout that defaults to no timeout if
None is passed.  The result of the operation is returned from this
method. If the operation raised an exception, it is reraised from this
method.

Args:
timeout (float): The maximum number of seconds to wait before timing
out.


def remove(self):
    removes = 0
    for (path, info) in self._make_iter(search='depth'):
        if info.is_dir:
            self.fs.removetree(path)
        else:
            self.fs.remove(path)
        removes += 1
    return removes

Removed all matched paths.

Returns:
int: Number of file and directories removed.

Example:
>>> import fs
>>> fs.open_fs('~/projects/my_project').glob('**/*.pyc').remove()
29


def _CreateMethod(self, method_name):

    soap_service_method = self.zeep_client.service[method_name]

    def MakeSoapRequest(*args):
      AddToUtilityRegistry('zeep')
      soap_headers = self._GetZeepFormattedSOAPHeaders()
      packed_args = self._PackArguments(method_name, args)
      try:
        return soap_service_method(
            *packed_args, _soapheaders=soap_headers)['body']['rval']
      except zeep.exceptions.Fault as e:
        error_list = ()
        if e.detail is not None:
          underlying_exception = e.detail.find(
              '{%s}ApiExceptionFault' % self._GetBindingNamespace())
          fault_type = self.zeep_client.get_element(
              '{%s}ApiExceptionFault' % self._GetBindingNamespace())
          fault = fault_type.parse(
              underlying_exception, self.zeep_client.wsdl.types)
          error_list = fault.errors or error_list
        raise googleads.errors.GoogleAdsServerFault(
            e.detail, errors=error_list, message=e.message)
    return MakeSoapRequest

Create a method wrapping an invocation to the SOAP service.

Args:
method_name: A string identifying the name of the SOAP method to call.

Returns:
A callable that can be used to make the desired SOAP request.


def get_grouping_from_attentions(attentions: Tuple[tf.Tensor], hw_shape: Tuple[int]) -> tf.Tensor:
    attn_maps = []
    prev_attn_masks = None
    for attn_masks in attentions:
        attn_masks = tf.transpose(attn_masks, perm=(0, 2, 1))
        if prev_attn_masks is None:
            prev_attn_masks = attn_masks
        else:
            prev_attn_masks = tf.matmul(prev_attn_masks, attn_masks)
        cur_attn_map = resize_attention_map(tf.transpose(prev_attn_masks, perm=(0, 2, 1)), *hw_shape)
        attn_maps.append(cur_attn_map)
    final_grouping = attn_maps[-1]
    return tf.stop_gradient(final_grouping)

Args:
attentions (`tuple(tf.Tensor)`: tuple of attention maps returned by `TFGroupViTVisionTransformer`
hw_shape (`tuple(int)`): height and width of the output attention map
Returns:
`tf.Tensor`: the attention map of shape [batch_size, groups, height, width]


def retry(transport: 'UDPTransport', messagedata: bytes, message_id: UDPMessageID, recipient: Address, stop_event: Event, timeout_backoff: Iterable[int]) -> bool:
    async_result = transport.maybe_sendraw_with_result(recipient, messagedata, message_id)
    event_quit = event_first_of(async_result, stop_event)
    for timeout in timeout_backoff:
        if (event_quit.wait(timeout=timeout) is True):
            break
        log.debug('retrying message', node=pex(transport.raiden.address), recipient=pex(recipient), msgid=message_id)
        transport.maybe_sendraw_with_result(recipient, messagedata, message_id)
    return async_result.ready()

Send messagedata until it's acknowledged.

Exit when:

- The message is delivered.
- Event_stop is set.
- The iterator timeout_backoff runs out.

Returns:
bool: True if the message was acknowledged, False otherwise.


def register_defs(self, def_list, **kwargs):

        for item in def_list:
            if isinstance(item, tuple):
                self.register_rml_def(*item, **kwargs)
            elif isinstance(item, dict):
                cp_kwargs = kwargs.copy()
                item.update(kwargs)
                self.register_rml_def(**item)

Registers a list of Rml defintions objects

Args:
-----
def_list: list of objects defining the rml definitons


def _parse_expiry(response_data):

    expires_in = response_data.get('expires_in', None)

    if expires_in is not None:
        return _helpers.utcnow() + datetime.timedelta(
            seconds=expires_in)
    else:
        return None

Parses the expiry field from a response into a datetime.

Args:
response_data (Mapping): The JSON-parsed response data.

Returns:
Optional[datetime]: The expiration or ``None`` if no expiration was
specified.


def get_all_for_resource(identifier, configuration=None):
    resourceview = ResourceView(configuration=configuration)
    (success, result) = resourceview._read_from_hdx('resource view', identifier, 'id', ResourceView.actions()['list'])
    resourceviews = list()
    if success:
        for resourceviewdict in result:
            resourceview = ResourceView(resourceviewdict, configuration=configuration)
            resourceviews.append(resourceview)
    return resourceviews

Read all resource views for a resource given by identifier from HDX and returns list of ResourceView objects

Args:
identifier (str): Identifier of resource
configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration.

Returns:
List[ResourceView]: List of ResourceView objects


def get_pipe_series_output(commands: Sequence[str], stdinput: BinaryIO=None) -> bytes:
    processes = []
    for i in range(len(commands)):
        if (i == 0):
            processes.append(subprocess.Popen(shlex.split(commands[i]), stdin=subprocess.PIPE, stdout=subprocess.PIPE))
        else:
            processes.append(subprocess.Popen(shlex.split(commands[i]), stdin=processes[(i - 1)].stdout, stdout=subprocess.PIPE))
    return processes[(len(processes) - 1)].communicate(stdinput)[0]

Get the output from a piped series of commands.

Args:
commands: sequence of command strings
stdinput: optional ``stdin`` data to feed into the start of the pipe

Returns:
``stdout`` from the end of the pipe


def copyfile(src, dst, follow_symlinks=True):
    (src, src_is_storage) = format_and_is_storage(src)
    (dst, dst_is_storage) = format_and_is_storage(dst)
    if ((not src_is_storage) and (not dst_is_storage)):
        return shutil_copyfile(src, dst, follow_symlinks=follow_symlinks)
    with handle_os_exceptions():
        try:
            if ((not hasattr(dst, 'read')) and (not isdir(dirname(dst)))):
                raise IOError(("No such file or directory: '%s'" % dst))
        except ObjectPermissionError:
            pass
        _copy(src, dst, src_is_storage, dst_is_storage)

Copies a source file to a destination file.

Equivalent to "shutil.copyfile".

Source and destination can also be binary opened file-like objects.

Args:
src (path-like object or file-like object): Source file.
dst (path-like object or file-like object): Destination file.
follow_symlinks (bool): Follow symlinks.
Not supported on cloud storage objects.

Raises:
IOError: Destination directory not found.


async def __anit__(self, core, node):

        await s_base.Base.__anit__(self)

        self.core = core

        self.node = node
        self.iden = node.name()

        self.borked = None

        self.info = await node.dict()
        self.info.setdefault('owner', 'root')
        self.info.setdefault('layers', ())

        self.layers = []

        for iden in self.info.get('layers'):

            layr = core.layers.get(iden)

            if layr is None:
                self.borked = iden
                logger.warning('view %r has missing layer %r' % (self.iden, iden))
                continue

            if not self.layers and layr.readonly:
                self.borked = iden
                raise s_exc.ReadOnlyLayer(mesg=f'First layer {iden} must not be read-only')

            self.layers.append(layr)

Async init the view.

Args:
core (Cortex):  The cortex that owns the view.
node (HiveNode): The hive node containing the view info.


def add_callback(self, name, func):

        if name not in self.callbacks:
            raise ValueError("Unknown callback name: %s" % name)

        self.callbacks[name].add(func)

Add a callback when Device events happen

Args:
name (str): currently support 'on_scan' and 'on_disconnect'
func (callable): the function that should be called


def lsdirs(root=".", **kwargs):

    paths = ls(root=root, **kwargs)
    if isfile(root):
        return []
    return [_path for _path in paths if isdir(path(root, _path))]

Return only subdirectories from a directory listing.

Arguments:

root (str): Path to directory. Can be relative or absolute.
**kwargs: Any additional arguments to be passed to ls().

Returns:

list of str: A list of directory paths.

Raises:

OSError: If root directory does not exist.


def CredibleInterval(pmf, percentage=90):
    cdf = pmf.MakeCdf()
    prob = ((1 - (percentage / 100.0)) / 2)
    interval = (cdf.Value(prob), cdf.Value((1 - prob)))
    return interval

Computes a credible interval for a given distribution.

If percentage=90, computes the 90% CI.

Args:
pmf: Pmf object representing a posterior distribution
percentage: float between 0 and 100

Returns:
sequence of two floats, low and high


def __call__(self, shape, dtype=None):
    dtype = standardize_dtype(dtype)
    frame_length, input_channels, fft_length = shape
    win = None
    scaling = 1
    if self.window is not None:
        win = self.window
        if isinstance(win, str):
            win = scipy.signal.get_window(win, frame_length, self.periodic)
        win = ops.convert_to_tensor(win, dtype=dtype)
        if len(win.shape) != 1 or win.shape[-1] != frame_length:
            raise ValueError(f'The shape of `window` must be equal to [frame_length].Received: window shape={win.shape}')
        win = ops.reshape(win, [frame_length, 1, 1])
        if self.scaling == 'density':
            scaling = ops.sqrt(ops.sum(ops.square(win)))
        elif self.scaling == 'spectrum':
            scaling = ops.sum(ops.abs(win))
    _fft_length = (fft_length - 1) * 2
    freq = ops.reshape(ops.arange(fft_length, dtype=dtype), (1, 1, fft_length)) / _fft_length
    time = ops.reshape(ops.arange(frame_length, dtype=dtype), (frame_length, 1, 1))
    args = -2 * time * freq * ops.arccos(ops.cast(-1, dtype))
    if self.side == 'real':
        kernel = ops.cast(ops.cos(args), dtype)
    else:
        kernel = ops.cast(ops.sin(args), dtype)
    if win is not None:
        kernel = kernel * win / scaling
    return kernel

Returns a tensor object initialized as specified by the initializer.

The shape is assumed to be `(T, 1, F // 2 + 1)`, where `T` is the size
of the given window, and `F` is the number of frequency bands. Only half
the frequency bands are used, which is a common practice in STFT,
because the second half are the conjugates of the first half in
a reversed order.

Args:
shape: Shape of the tensor.
dtype: Optional dtype of the tensor. Only numeric or boolean dtypes
are supported. If not specified, `keras.backend.floatx()`
is used, which default to `float32` unless you configured it
otherwise (via `keras.backend.set_floatx(float_dtype)`).


def _CheckStatusAnalysisProcess(self, pid):
    self._RaiseIfNotRegistered(pid)
    if (pid in self._completed_analysis_processes):
        status_indicator = definitions.STATUS_INDICATOR_COMPLETED
        process_status = {'processing_status': status_indicator}
        used_memory = 0
    else:
        process = self._processes_per_pid[pid]
        process_status = self._QueryProcessStatus(process)
        if (process_status is None):
            process_is_alive = False
        else:
            process_is_alive = True
        process_information = self._process_information_per_pid[pid]
        used_memory = (process_information.GetUsedMemory() or 0)
        if (self._worker_memory_limit and (used_memory > self._worker_memory_limit)):
            logger.warning('Process: {0:s} (PID: {1:d}) killed because it exceeded the memory limit: {2:d}.'.format(process.name, pid, self._worker_memory_limit))
            self._KillProcess(pid)
        if isinstance(process_status, dict):
            self._rpc_errors_per_pid[pid] = 0
            status_indicator = process_status.get('processing_status', None)
            if (status_indicator == definitions.STATUS_INDICATOR_COMPLETED):
                self._completed_analysis_processes.add(pid)
        else:
            rpc_errors = (self._rpc_errors_per_pid.get(pid, 0) + 1)
            self._rpc_errors_per_pid[pid] = rpc_errors
            if (rpc_errors > self._MAXIMUM_RPC_ERRORS):
                process_is_alive = False
            if process_is_alive:
                rpc_port = process.rpc_port.value
                logger.warning('Unable to retrieve process: {0:s} (PID: {1:d}) status via RPC socket: http:
                processing_status_string = 'RPC error'
                status_indicator = definitions.STATUS_INDICATOR_RUNNING
            else:
                processing_status_string = 'killed'
                status_indicator = definitions.STATUS_INDICATOR_KILLED
            process_status = {'processing_status': processing_status_string}
    self._UpdateProcessingStatus(pid, process_status, used_memory)
    if (status_indicator in definitions.ERROR_STATUS_INDICATORS):
        logger.error('Process {0:s} (PID: {1:d}) is not functioning correctly. Status code: {2!s}.'.format(process.name, pid, status_indicator))
        self._TerminateProcessByPid(pid)

Checks the status of an analysis process.

Args:
pid (int): process ID (PID) of a registered analysis process.

Raises:
KeyError: if the process is not registered with the engine.


def __init__(
      self, data_stream=None, inode=None, location=None, parent=None, **kwargs):

    if (inode is None and not location) or not parent:
      raise ValueError('Missing inode and location, or parent value.')

    super(TSKPathSpec, self).__init__(parent=parent, **kwargs)
    self.data_stream = data_stream
    self.inode = inode
    self.location = location

Initializes a path specification.

Note that the TSK path specification must have a parent.

Args:
data_stream (Optional[str]): data stream name, where None indicates
the default data stream.
inode (Optional[int]): inode.
location (Optional[str]): location.
parent (Optional[PathSpec]): parent path specification.

Raises:
ValueError: when inode and location, or parent are not set.


def recordbatch(self, auth, resource, entries, defer=False):

        return self._call('recordbatch', auth, [resource, entries], defer)

Records a list of historical entries to the resource specified.

Calls a function that bulids a request that writes a list of historical entries to the
specified resource.

Args:
auth: Takes the device cik
resource: Takes the dataport alias or rid.
entries: A list of entries to write to the resource.


def observations_np(self, boundary=20):

    list_observations_np_ts = [t.observations_np for t in self.trajectories]

    OBS = list_observations_np_ts[0].shape[1:]

    num_time_steps = [t.num_time_steps for t in self.trajectories]
    t_max = max(num_time_steps)

    boundary = int(boundary)
    bucket_length = boundary * int(np.ceil(float(t_max) / boundary))

    def padding_config(obs):

      num_to_pad = bucket_length + 1 - obs.shape[0]
      return [(0, num_to_pad)] + [(0, 0)] * len(OBS)

    return np.stack([
        np.pad(obs, padding_config(obs), "constant")
        for obs in list_observations_np_ts]), num_time_steps

Pads the observations in all the trajectories and returns them.

Args:
boundary: integer, Observations will be padded to (n * boundary) + 1 where
n is an integer.

Returns:
a tuple(padded_observations, time_steps), with shapes:
padded_observations: (self.batch_size, n * boundary + 1) + OBS
time_steps: integer list of length = self.batch_size


def __init__(self, criterion, description=None, font_attr=DEFAULT_TENSOR_ELEMENT_HIGHLIGHT_FONT_ATTR):
    self.criterion = criterion
    self.description = description
    self.font_attr = font_attr

Constructor of HighlightOptions.

Args:
criterion: (callable) A callable of the following signature:
def to_highlight(X):
# Args:
#   X: The tensor to highlight elements in.
#
# Returns:
#   (boolean ndarray) A boolean ndarray of the same shape as X
#   indicating which elements are to be highlighted (iff True).
This callable will be used as the argument of np.argwhere() to
determine which elements of the tensor are to be highlighted.
description: (str) Description of the highlight criterion embodied by
criterion.
font_attr: (str) Font attribute to be applied to the
highlighted elements.


def __intervals_from_tops(self, tops, values, basis, components, field=None, ignore_nan=True):
    length = float(basis.size)
    (start, stop) = (basis[0], basis[(- 1)])
    tops = [(start + ((p / (length - 1)) * (stop - start))) for p in tops]
    bases = (tops[1:] + [stop])
    list_of_Intervals = []
    for (i, t) in enumerate(tops):
        (v, c, d) = (values[i], [], {})
        if (ignore_nan and np.isnan(v)):
            continue
        if (field is not None):
            d = {field: v}
        if (components is not None):
            try:
                c = [deepcopy(components[int(v)])]
            except IndexError:
                c = []
            if (c and (c[0] is None)):
                c = []
        interval = Interval(t, bases[i], data=d, components=c)
        list_of_Intervals.append(interval)
    return list_of_Intervals

Private method. Take a sequence of tops in an arbitrary dimension,
and provide a list of intervals from which a striplog can be made.

This is only intended to be used by ``from_image()``.

Args:
tops (iterable). A list of floats.
values (iterable). A list of values to look up.
basis (iterable). A list of components.
components (iterable). A list of Components.

Returns:
List. A list of Intervals.


def cw_ssim_value(self, target, width=30):

        if not isinstance(target, SSIMImage):
            target = SSIMImage(target, size=self.img.size)

        widths = np.arange(1, width+1)

        sig1 = np.asarray(self.img.img_gray.getdata())
        sig2 = np.asarray(target.img_gray.getdata())

        cwtmatr1 = signal.cwt(sig1, signal.ricker, widths)
        cwtmatr2 = signal.cwt(sig2, signal.ricker, widths)

        c1c2 = np.multiply(abs(cwtmatr1), abs(cwtmatr2))
        c1_2 = np.square(abs(cwtmatr1))
        c2_2 = np.square(abs(cwtmatr2))
        num_ssim_1 = 2 * np.sum(c1c2, axis=0) + self.k
        den_ssim_1 = np.sum(c1_2, axis=0) + np.sum(c2_2, axis=0) + self.k

        c1c2_conj = np.multiply(cwtmatr1, np.conjugate(cwtmatr2))
        num_ssim_2 = 2 * np.abs(np.sum(c1c2_conj, axis=0)) + self.k
        den_ssim_2 = 2 * np.sum(np.abs(c1c2_conj), axis=0) + self.k

        ssim_map = (num_ssim_1 / den_ssim_1) * (num_ssim_2 / den_ssim_2)

        index = np.average(ssim_map)
        return index

Compute the complex wavelet SSIM (CW-SSIM) value from the reference
image to the target image.

Args:
target (str or PIL.Image): Input image to compare the reference image
to. This may be a PIL Image object or, to save time, an SSIMImage
object (e.g. the img member of another SSIM object).
width: width for the wavelet convolution (default: 30)

Returns:
Computed CW-SSIM float value.


def __init__(self, station_code, DST=False):

        filename = env.WEATHER_DATA_PATH + '/' + _basename(station_code)
        self.csvfile = None
        try:
            self.csvfile = open(filename)
        except IOError:
            logger.info("File not found")
            download_extract(_eere_url(station_code))
            self.csvfile = open(filename)
        logging.debug('opened %s', self.csvfile.name)
        fieldnames = ["Year", "Month", "Day", "Hour", "Minute", "DS",
                      "Dry-bulb (C)", "Dewpoint (C)", "Relative Humidity",
                      "Pressure (Pa)", "ETR (W/m^2)", "ETRN (W/m^2)",
                      "HIR (W/m^2)", "GHI (W/m^2)", "DNI (W/m^2)",
                      "DHI (W/m^2)", "GHIL (lux)", "DNIL (lux)", "DFIL (lux)",
                      "Zlum (Cd/m2)", "Wdir (degrees)", "Wspd (m/s)",
                      "Ts cover", "O sky cover", "CeilHgt (m)",
                      "Present Weather", "Pw codes", "Pwat (cm)",
                      "AOD (unitless)", "Snow Depth (cm)",
                      "Days since snowfall"]
        station_meta = self.csvfile.readline().split(',')
        self.station_name = station_meta[1]
        self.CC = station_meta[3]
        self.station_fmt = station_meta[4]
        self.station_code = station_meta[5]
        self.lat = station_meta[6]
        self.lon = station_meta[7]
        self.TZ = float(station_meta[8])
        self.ELEV = station_meta[9]
        self.DST = DST

        if self.DST:
            geocoder = geocoders.GoogleV3()
            self.local_tz = pytz.timezone(geocoder.timezone((self.lat,
                                                             self.lon)).zone)
        dummy = ""
        for _ in range(7):
            dummy += self.csvfile.readline()
        self.epw_data = csv.DictReader(self.csvfile, fieldnames=fieldnames)

Data for a weather station.

Args:
station_code (str): Station code of weather station
DST (bool): Weather timestands in daylight savings. Default False


def _to_enos_networks(networks):

    nets = []
    for roles, network in networks:
        nets.append(network.to_enos(roles))
    logger.debug(nets)
    return nets

Transform the networks returned by deploy5k.

Args:
networks (dict): networks returned by
:py:func:`enoslib.infra.provider.Provider.init`


def get_escalatee(self, main_type, sub_type, unique_id, escalatee_id, params=None):

        params = params or {}

        return self.escalatee(main_type, sub_type, unique_id, escalatee_id, params=params)

Args:
main_type:
sub_type:
unique_id:
escalatee_id:
params:

Return:


def merge_caches_on_tpu(self, local_tpu_cache_tensor):
    x = array_ops.broadcast_to(local_tpu_cache_tensor, shape=[self._tt_config.num_replicas] + local_tpu_cache_tensor.shape.as_list())
    if tensor_tracer_flags.TT_SINGLE_CORE_SUMMARIES.value:
        return x
    return tpu_ops.all_to_all(x, concat_dimension=0, split_dimension=0, split_count=self._tt_config.num_replicas, group_assignment=[list(range(self._tt_config.num_replicas))])

Merges the given caches on tpu.

Args:
local_tpu_cache_tensor: A local tensor that needs to be merged
by concanting data from other tpu cores.
Returns:
A merged tf.Tensor.


class GaussianDropout(layers.Layer):

    def __init__(self, rate, seed=None, **kwargs):
        super().__init__(**kwargs)
        if not 0 <= rate <= 1:
            raise ValueError(f'Invalid value received for argument `rate`. Expected a float value between 0 and 1. Received: rate={rate}')
        self.rate = rate
        self.seed = seed
        if rate > 0:
            self.seed_generator = backend.random.SeedGenerator(seed)
        self.supports_masking = True
        self._build_at_init()

    def call(self, inputs, training=False):
        if training and self.rate > 0:
            stddev = math.sqrt(self.rate / (1.0 - self.rate))
            return inputs * backend.random.normal(shape=ops.shape(inputs), mean=1.0, stddev=stddev, dtype=self.compute_dtype, seed=self.seed_generator)
        return inputs

    def compute_output_shape(self, input_shape):
        return input_shape

    def get_config(self):
        base_config = super().get_config()
        config = {'rate': self.rate, 'seed': self.seed}
        return {**base_config, **config}

Apply multiplicative 1-centered Gaussian noise.

As it is a regularization layer, it is only active at training time.

Args:
rate: Float, drop probability (as with `Dropout`).
The multiplicative noise will have
standard deviation `sqrt(rate / (1 - rate))`.
seed: Integer, optional random seed to enable deterministic behavior.

Call arguments:
inputs: Input tensor (of any rank).
training: Python boolean indicating whether the layer should behave in
training mode (adding dropout) or in inference mode (doing nothing).


def _DownloadUrl(self, url, dest_dir):
    dest_file = tempfile.NamedTemporaryFile(dir=dest_dir, delete=False)
    dest_file.close()
    dest = dest_file.name
    self.logger.info('Downloading url from %s to %s.', url, dest)
    try:
        urlretrieve.urlretrieve(url, dest)
        return dest
    except (httpclient.HTTPException, socket.error, urlerror.URLError) as e:
        self.logger.warning('Could not download %s. %s.', url, str(e))
    except Exception as e:
        self.logger.warning('Exception downloading %s. %s.', url, str(e))
    return None

Download a script from a given URL.

Args:
url: string, the URL to download.
dest_dir: string, the path to a directory for storing metadata scripts.

Returns:
string, the path to the file storing the metadata script.


def get_metrics_namespace(self) -> str:
    return 'BeamML_HuggingFacePipelineModelHandler'

Returns:
A namespace for metrics collected by the RunInference transform.


def apply_operation_back(self, op, qargs=None, cargs=None, condition=None):
    qargs = (qargs or [])
    cargs = (cargs or [])
    all_cbits = self._bits_in_condition(condition)
    all_cbits.extend(cargs)
    self._check_condition(op.name, condition)
    self._check_bits(qargs, self.output_map)
    self._check_bits(all_cbits, self.output_map)
    self._add_op_node(op, qargs, cargs, condition)
    al = [qargs, all_cbits]
    for q in itertools.chain(*al):
        ie = list(self._multi_graph.predecessors(self.output_map[q]))
        if (len(ie) != 1):
            raise DAGCircuitError('output node has multiple in-edges')
        self._multi_graph.add_edge(ie[0], self._id_to_node[self._max_node_id], name=('%s[%s]' % (q[0].name, q[1])), wire=q)
        self._multi_graph.remove_edge(ie[0], self.output_map[q])
        self._multi_graph.add_edge(self._id_to_node[self._max_node_id], self.output_map[q], name=('%s[%s]' % (q[0].name, q[1])), wire=q)
    return self._id_to_node[self._max_node_id]

Apply an operation to the output of the circuit.

Args:
op (Instruction): the operation associated with the DAG node
qargs (list[tuple]): qubits that op will be applied to
cargs (list[tuple]): cbits that op will be applied to
condition (tuple or None): optional condition (ClassicalRegister, int)

Returns:
DAGNode: the current max node

Raises:
DAGCircuitError: if a leaf node is connected to multiple outputs


def markers(self, values):

        if not isinstance(values, list):
            raise TypeError("Markers must be a list of objects")

        self.options["markers"] = values

Set the markers.

Args:
values (list): list of marker objects.

Raises:
ValueError: Markers must be a list of objects.


def read_profile(name):

    config = configparser.ConfigParser()
    config.read(CONFIG_FILE)
    profile = config[name]
    repo = profile["repo"]
    token = profile["token"]
    return {"repo": repo, "token": token}

Get a named profile from the CONFIG_FILE.

Args:

name
The name of the profile to load.

Returns:
A dictionary with the profile's ``repo`` and ``token`` values.


def _init_net_specs(conf):
    for (net_name, net_spec) in conf.get('nets', {}).items():
        net_spec['name'] = net_name
        net_spec['mapping'] = {}
        net_spec.setdefault('type', 'nat')
    return conf

Given a configuration specification, initializes all the net
definitions in it so they can be used comfortably

Args:
conf (dict): Configuration specification

Returns:
dict: the adapted new conf


def open(self, filepath):

        with io.open(filepath, 'r', encoding='utf-8') as fp:
            content = fp.read()
        return content

Open settings backend to return its content

Args:
filepath (str): Settings object, depends from backend

Returns:
string: File content.


def generate_code(max_length, max_nest, ops):
    stack = []

    def fetch_one():
        if stack:
            return stack.pop()
        else:
            value = random.randint((10 ** (max_length - 1)), ((10 ** max_length) - 1))
            code = str(value)
            return (value, code)

    def fetch(num_operands):
        (values, codes) = zip(*[fetch_one() for _ in six.moves.range(num_operands)])
        return (values, codes)
    for _ in six.moves.range(max_nest):
        op = random.choice(ops)
        (values, codes) = fetch(op.num_operands)
        new_value = op.eval(values)
        new_code = op.get_code(codes)
        stack.append((new_value, (('(' + new_code) + ')')))
    (final_value, final_code) = stack.pop()
    final_code = final_code[1:(- 1)]
    final_code.strip('()')
    if (not op.is_memory):
        final_value = (int(final_value) % (10 ** (max_length + 1)))
    return (str(final_value), final_code)

Generates code samples.

Args:
max_length: int.  max literal length.
max_nest: int. max nesting level.
ops: CodeOp. set of allowable operations.

Returns:
1. (str) output value.
2. (str) Code operation.


def events(self, institute, case=None, variant_id=None, level=None, comments=False, panel=None):
    query = {}
    if variant_id:
        if comments:
            LOG.debug('Fetching all comments for institute {0} case {1} variant {2}'.format(institute['_id'], case['_id'], variant_id))
            query = {'$or': [{'category': 'variant', 'variant_id': variant_id, 'verb': 'comment', 'level': 'global'}, {'category': 'variant', 'variant_id': variant_id, 'institute': institute['_id'], 'case': case['_id'], 'verb': 'comment', 'level': 'specific'}]}
        else:
            query['institute'] = institute['_id']
            query['category'] = 'variant'
            query['variant_id'] = variant_id
            query['case'] = case['_id']
    else:
        query['institute'] = institute['_id']
        if panel:
            query['panel'] = panel
        else:
            query['category'] = 'case'
            if case:
                query['case'] = case['_id']
            if comments:
                query['verb'] = 'comment'
    return self.event_collection.find(query).sort('created_at', pymongo.DESCENDING)

Fetch events from the database.

Args:
institute (dict): A institute
case (dict): A case
variant_id (str, optional): global variant id
level (str, optional): restrict comments to 'specific' or 'global'
comments (bool, optional): restrict events to include only comments
panel (str): A panel name

Returns:
pymongo.Cursor: Query result


def _assert_validators(self, validators):
    for validator in sorted(validators, key=(lambda validator: validator.insertion_index)):
        try:
            validator.verify(self)
        except _exceptions.ValidationError as e:
            message = validator.print_flags_with_values(self)
            raise _exceptions.IllegalFlagValueError(('%s: %s' % (message, str(e))))

Asserts if all validators in the list are satisfied.

It asserts validators in the order they were created.

Args:
validators: Iterable(validators.Validator), validators to be
verified.
Raises:
AttributeError: Raised if validators work with a non-existing flag.
IllegalFlagValueError: Raised if validation fails for at least one
validator.


def _freeze_keras_model(self):
    input_signature = None
    if not isinstance(self._keras_model.call, _def_function.Function):
        input_signature = _model_input_signature(self._keras_model, keep_original_batch_size=True)
    func = _trace_model_call(self._keras_model, input_signature)
    concrete_func = func.get_concrete_function()
    self._funcs = [concrete_func]
    frozen_func, graph_def = _convert_to_constants.convert_variables_to_constants_v2_as_graph(self._funcs[0], lower_control_flow=False)
    input_tensors = [tensor for tensor in frozen_func.inputs if tensor.dtype != _dtypes.resource]
    output_tensors = frozen_func.outputs
    return (graph_def, input_tensors, output_tensors, frozen_func)

Freeze Keras model to frozen graph.

Returns:
graph_def: The frozen GraphDef.
input_tensors: List of input tensors.
output_tensors: List of output tensors.
frozen_func: The frozen ConcreteFunction.


def _testSimpleHelper(self, dtype, test_cases):
    current_test_case = []
    dataset = dataset_ops.Dataset.from_generator(lambda: current_test_case, dtype).unique()
    for test_case, expected in test_cases:
        current_test_case = test_case
        self.assertDatasetProduces(dataset, [compat.as_bytes(element) if dtype == dtypes.string else element for element in expected])

Test the `unique()` transformation on a list of test cases.

Args:
dtype: The `dtype` of the elements in each test case.
test_cases: A list of pairs of lists. The first component is the test
input that will be passed to the transformation; the second component is
the expected sequence of outputs from the transformation.


def tv(self, **kwargs):
    path = self._get_path('tv')
    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response

Search for TV shows by title.

Args:
query: CGI escpaed string.
page: (optional) Minimum value of 1. Expected value is an integer.
language: (optional) ISO 639-1 code.
first_air_date_year: (optional) Filter the results to only match
shows that have a air date with with value.
search_type: (optional) By default, the search type is 'phrase'.
This is almost guaranteed the option you will want.
It's a great all purpose search type and by far the
most tuned for every day querying. For those wanting
more of an "autocomplete" type search, set this
option to 'ngram'.

Returns:
A dict respresentation of the JSON returned from the API.


def remove_accent_marks(text, excluded=None):

        if excluded is None:
            excluded = set()

        return unicodedata.normalize(
            'NFKC', ''.join(
                c for c in unicodedata.normalize(
                    'NFKD', text) if unicodedata.category(c) != 'Mn' or c in excluded))

Remove accent marks from input text.

This function removes accent marks in the text, but leaves
unicode characters defined in the 'excluded' parameter.

Args:
text: The text to be processed.
excluded: Set of unicode characters to exclude.

Returns:
The text without accent marks.


def _get_extras(self):
    extra_parts = ['']
    for value in self._unknown_keys.values():
        extra_parts.append(value)
    extra_parts.append(self._known_keys[_InstrumentationKnownStatusKeys.STREAM])
    extra_parts.append(self._known_keys[_InstrumentationKnownResultKeys.SHORTMSG])
    extra_parts.append(self._known_keys[_InstrumentationKnownResultKeys.LONGMSG])
    extra_parts.append(self._known_keys[_InstrumentationKnownStatusKeys.ERROR])
    if self._known_keys[_InstrumentationKnownStatusKeys.STACK] not in self._known_keys[_InstrumentationKnownStatusKeys.STREAM]:
        extra_parts.append(self._known_keys[_InstrumentationKnownStatusKeys.STACK])
    return '\n'.join(filter(None, extra_parts))

Gets the output for the extras section of the TestResultRecord.

Returns:
A string to set for a TestResultRecord's extras.


def resolve_lookups(variable, context, provider):
    resolved_lookups = {}
    for lookup in variable.lookups:
        try:
            handler = LOOKUP_HANDLERS[lookup.type]
        except KeyError:
            raise UnknownLookupType(lookup)
        try:
            resolved_lookups[lookup] = handler(value=lookup.input, context=context, provider=provider)
        except Exception as e:
            raise FailedVariableLookup(variable.name, lookup, e)
    return resolved_lookups

Resolve a set of lookups.

Args:
variable (:class:`stacker.variables.Variable`): The variable resolving
it's lookups.
context (:class:`stacker.context.Context`): stacker context
provider (:class:`stacker.provider.base.BaseProvider`): subclass of the
base provider

Returns:
dict: dict of Lookup -> resolved value


def sequence_beam_search(symbols_to_logits_fn, initial_ids, initial_cache, vocab_size, beam_size, alpha, max_decode_length, eos_id):
    batch_size = tf.shape(initial_ids)[0]
    sbs = SequenceBeamSearch(symbols_to_logits_fn, vocab_size, batch_size, beam_size, alpha, max_decode_length, eos_id)
    return sbs.search(initial_ids, initial_cache)

Search for sequence of subtoken ids with the largest probability.

Args:
symbols_to_logits_fn: A function that takes in ids, index, and cache as
arguments. The passed in arguments will have shape:
ids -> [batch_size * beam_size, index]
index -> [] (scalar)
cache -> nested dictionary of tensors [batch_size * beam_size, ...]
The function must return logits and new cache.
logits -> [batch * beam_size, vocab_size]
new cache -> same shape/structure as inputted cache
initial_ids: Starting ids for each batch item.
int32 tensor with shape [batch_size]
initial_cache: dict containing starting decoder variables information
vocab_size: int size of tokens
beam_size: int number of beams
alpha: float defining the strength of length normalization
max_decode_length: maximum length to decoded sequence
eos_id: int id of eos token, used to determine when a sequence has finished

Returns:
Top decoded sequences [batch_size, beam_size, max_decode_length]
sequence scores [batch_size, beam_size]


def send(self, cumulative_counters=None, gauges=None, counters=None):
    if ((not gauges) and (not cumulative_counters) and (not counters)):
        return
    data = {'cumulative_counter': cumulative_counters, 'gauge': gauges, 'counter': counters}
    _logger.debug('Sending datapoints to SignalFx: %s', data)
    for (metric_type, datapoints) in data.items():
        if (not datapoints):
            continue
        if (not isinstance(datapoints, list)):
            raise TypeError('Datapoints not of type list %s', datapoints)
        for datapoint in datapoints:
            self._add_extra_dimensions(datapoint)
            self._add_to_queue(metric_type, datapoint)
    self._start_thread()

Send the given metrics to SignalFx.

Args:
cumulative_counters (list): a list of dictionaries representing the
cumulative counters to report.
gauges (list): a list of dictionaries representing the gauges to
report.
counters (list): a list of dictionaries representing the counters
to report.


def short(self, url):

        url = self.clean_url(url)
        shorten_url = f'{self.api_url}v1/shorten'
        payload = {
            'domain': getattr(self, 'domain', 'adf.ly'),
            'advert_type': getattr(self, 'type', 'int'),
            'group_id': getattr(self, 'group_id', None),
            'key': self.api_key,
            'user_id': self.user_id,
            'url': url,
        }
        response = self._post(shorten_url, data=payload)
        if not response.ok:
            raise BadAPIResponseException(response.content)

        try:
            data = response.json()
        except json.decoder.JSONDecodeError:
            raise BadAPIResponseException('API response could not be decoded')

        if data.get('errors'):
            errors = ','.join(i['msg'] for i in data['errors'])
            raise ShorteningErrorException(errors)

        if not data.get('data'):
            raise BadAPIResponseException(response.content)

        return data['data'][0]['short_url']

Short implementation for Adf.ly
Args:
url: the URL you want to shorten

Returns:
A string containing the shortened URL

Raises:
BadAPIResponseException: If the data is malformed or we got a bad
status code on API response
ShorteningErrorException: If the API Returns an error as response


def attention_lm_moe_prepare_decoder(targets, hparams):

  targets_pad_mask = common_attention.embedding_to_padding(targets)
  with tf.name_scope("pad_remover"):

    pad_remover = expert_utils.PadRemover(targets_pad_mask)

  if hparams.prepend_mode == "prepend_inputs_full_attention":
    decoder_self_attention_bias = (
        common_attention.attention_bias_prepend_inputs_full_attention(
            targets_pad_mask))
  else:
    decoder_self_attention_bias = (
        common_attention.attention_bias_lower_triangle(tf.shape(targets)[1]))
  decoder_input = common_layers.shift_right_3d(targets)
  if hparams.pos == "timing":
    decoder_input = common_attention.add_timing_signal_1d(decoder_input)
  return (decoder_input, decoder_self_attention_bias, pad_remover)

Prepare one shard of the model for the decoder.

Args:
targets: a Tensor.
hparams: run hyperparameters

Returns:
decoder_input: a Tensor, bottom of decoder stack
decoder_self_attention_bias: a Tensor, containing large negative values
to implement masked attention and possibly biases for diagonal alignments
pad_remover (expert_utils.PadRemover): an util object to remove padding


def add_error(self, error, critical=False):
    self.errors.append((error, critical))

Adds an error to the state.

Args:
error: The text that will be added to the error list.
critical: If set to True and the error is checked with check_errors, will
dfTimewolf will abort.


def ascii_tree(self, no_types: bool=False, val_count: bool=False) -> str:
    return self.schema._ascii_tree('', no_types, val_count)

Generate ASCII art representation of the schema tree.

Args:
no_types: Suppress output of data type info.
val_count: Show accumulated validation counts.

Returns:
String with the ASCII tree.


def _ConvertToTimestamp(self, date, time, timezone):
    if ((not date) and (not time)):
        raise errors.TimestampError('Unable to extract timestamp from McAfee AV logline.')
    try:
        time_string = '{0:s} {1:s}'.format(date, time)
    except UnicodeDecodeError:
        raise errors.TimestampError('Unable to form a timestamp string.')
    return timelib.Timestamp.FromTimeString(time_string, timezone=timezone)

Converts date and time values into a timestamp.

The date and time are made up of two strings, the date and the time,
separated by a tab. The time is in local time. The month and day can
be either 1 or 2 characters long, e.g.: 7/30/2013\\t10:22:48 AM

Args:
date (str): date.
time (str): time.
timezone (pytz.timezone): timezone of the date and time.

Returns:
int: a timestamp integer containing the number of micro seconds since
January 1, 1970, 00:00:00 UTC.

Raises:
TimestampError: if the timestamp is badly formed or unable to transfer
the supplied date and time into a timestamp.


def compute_ngrams(word_list, S=3, T=3):

    _ngrams = []
    if isinstance(word_list, str):
        word_list = [word_list]
    for word in word_list:
        for n in range(S, T+1):
            _ngrams += zip(*(word[i:] for i in range(n)))
    return [''.join(_ngram) for _ngram in _ngrams]

Compute NGrams in the word_list from [S-T)
Args:
word_list (list): A list of words to compute ngram set from
S (int): The smallest NGram (default=3)
T (int): The biggest NGram (default=3)


def get_enterprise_user_id(self, obj):

        enterprise_learner = EnterpriseCustomerUser.objects.filter(user_id=obj.id).first()

        return enterprise_learner and enterprise_learner.id

Get enterprise user id from user object.

Arguments:
obj (User): Django User object

Returns:
(int): Primary Key identifier for enterprise user object.


def euler_angles_1q(unitary_matrix):

    if unitary_matrix.shape != (2, 2):
        raise QiskitError("euler_angles_1q: expected 2x2 matrix")
    phase = la.det(unitary_matrix)**(-1.0/2.0)
    U = phase * unitary_matrix

    if abs(U[0, 0]) > _CUTOFF_PRECISION:
        theta = 2 * math.acos(abs(U[0, 0]))
    else:
        theta = 2 * math.asin(abs(U[1, 0]))

    phase11 = 0.0
    phase10 = 0.0
    if abs(math.cos(theta/2.0)) > _CUTOFF_PRECISION:
        phase11 = U[1, 1] / math.cos(theta/2.0)
    if abs(math.sin(theta/2.0)) > _CUTOFF_PRECISION:
        phase10 = U[1, 0] / math.sin(theta/2.0)
    phiplambda = 2 * math.atan2(np.imag(phase11), np.real(phase11))
    phimlambda = 2 * math.atan2(np.imag(phase10), np.real(phase10))
    phi = 0.0
    if abs(U[0, 0]) > _CUTOFF_PRECISION and abs(U[1, 0]) > _CUTOFF_PRECISION:
        phi = (phiplambda + phimlambda) / 2.0
        lamb = (phiplambda - phimlambda) / 2.0
    else:
        if abs(U[0, 0]) < _CUTOFF_PRECISION:
            lamb = -phimlambda
        else:
            lamb = phiplambda

    Rzphi = np.array([[np.exp(-1j*phi/2.0), 0],
                      [0, np.exp(1j*phi/2.0)]], dtype=complex)
    Rytheta = np.array([[np.cos(theta/2.0), -np.sin(theta/2.0)],
                        [np.sin(theta/2.0), np.cos(theta/2.0)]], dtype=complex)
    Rzlambda = np.array([[np.exp(-1j*lamb/2.0), 0],
                         [0, np.exp(1j*lamb/2.0)]], dtype=complex)
    V = np.dot(Rzphi, np.dot(Rytheta, Rzlambda))
    if la.norm(V - U) > _CUTOFF_PRECISION:
        raise QiskitError("euler_angles_1q: incorrect result")
    return theta, phi, lamb

Compute Euler angles for a single-qubit gate.

Find angles (theta, phi, lambda) such that
unitary_matrix = phase * Rz(phi) * Ry(theta) * Rz(lambda)

Args:
unitary_matrix (ndarray): 2x2 unitary matrix

Returns:
tuple: (theta, phi, lambda) Euler angles of SU(2)

Raises:
QiskitError: if unitary_matrix not 2x2, or failure


def collective_manager_ids_from_op(op):
    if op.type == 'CollectiveReduce':
        try:
            return [op.get_attr('_collective_manager_id')]
        except ValueError:
            pass
    elif op.type == 'StatefulPartitionedCall':
        try:
            return op.get_attr(utils.COLLECTIVE_MANAGER_IDS)
        except ValueError:
            pass
    return []

Returns CollectiveManager ID from the op if one exists, else None.

CollectiveManager adds collective and no_op operations tagged with an ID,
unique to the manager object. This function extracts that ID, or None, if the
node was not generated by a CollectiveManager.

Args:
op: `Operation` to get the collective manager ID from.

Returns:
List of CollectiveManager IDs used by the op.


def start(authkey, queues, mode='local'):

  global mgr, qdict, kdict
  qdict.clear()
  kdict.clear()
  for q in queues:
    qdict[q] = JoinableQueue()

  TFManager.register('get_queue', callable=lambda qname: _get_queue(qname))
  TFManager.register('get', callable=lambda key: _get(key))
  TFManager.register('set', callable=lambda key, value: _set(key, value))
  if mode == 'remote':
    mgr = TFManager(address=('', 0), authkey=authkey)
  else:
    mgr = TFManager(authkey=authkey)
  mgr.start()
  return mgr

Create a new multiprocess.Manager (or return existing one).

Args:
:authkey: string authorization key
:queues: *INTERNAL_USE*
:mode: 'local' indicates that the manager will only be accessible from the same host, otherwise remotely accessible.

Returns:
A TFManager instance, which is also cached in local memory of the Python worker process.


def _constant_to_value(self, pyval, subst, get_node):
    if isinstance(pyval, str):
        return self.build_concrete_value(pyval, str)
    elif isinstance(pyval, bytes):
        return self.build_concrete_value(pyval, bytes)
    elif isinstance(pyval, bool):
        return self.true if pyval else self.false
    elif isinstance(pyval, int) and -1 <= pyval <= _MAX_IMPORT_DEPTH:
        return self.build_concrete_value(pyval, int)
    elif pyval.__class__ in self.primitive_classes:
        return self.primitive_instances[pyval.__class__]
    elif pyval.__class__ is frozenset:
        return self._frozenset_literal_to_value(pyval)
    elif isinstance(pyval, (pycnite.types.CodeTypeBase, blocks.OrderedCode)):
        return abstract.ConcreteValue(pyval, self.primitive_classes[types.CodeType], self.ctx)
    elif pyval is super:
        return special_builtins.Super.make(self.ctx)
    elif pyval is object:
        return special_builtins.Object.make(self.ctx)
    elif pyval.__class__ is type:
        try:
            return self.lookup_value(*self._type_to_name(pyval), subst)
        except (KeyError, AttributeError):
            log.debug('Failed to find pytd', exc_info=True)
            raise
    elif isinstance(pyval, abstract_utils.AsInstance):
        cls = pyval.cls
        if isinstance(cls, pytd.LateType):
            actual = self._load_late_type(cls)
            if not isinstance(actual, pytd.ClassType):
                return self.unsolvable
            cls = actual.cls
        if isinstance(cls, pytd.ClassType):
            cls = cls.cls
        if isinstance(cls, pytd.GenericType) and cls.name == 'typing.ClassVar':
            param, = cls.parameters
            return self.constant_to_value(abstract_utils.AsInstance(param), subst)
        elif isinstance(cls, pytd.GenericType) or (isinstance(cls, pytd.Class) and cls.template):
            if isinstance(cls, pytd.Class):
                params = tuple((t.type_param.upper_value for t in cls.template))
                cls = pytd.GenericType(base_type=pytd.ClassType(cls.name, cls), parameters=params)
            return self._pytd_generic_type_to_instance_value(cls, subst, get_node)
        elif isinstance(cls, pytd.Class):
            return self._pytd_class_to_instance_value(cls, subst)
        elif isinstance(cls, pytd.Literal):
            return self._get_literal_value(cls.value, subst)
        else:
            return self.constant_to_value(cls, subst)
    elif isinstance(pyval, pytd.Node):
        return self._pytd_constant_to_value(pyval, subst, get_node)
    elif pyval.__class__ is tuple:
        return self._tuple_literal_to_value(pyval)
    else:
        raise NotImplementedError(f"Can't convert constant {type(pyval)} {pyval!r}")

Create a BaseValue that represents a python constant.

This supports both constant from code constant pools and PyTD constants such
as classes. This also supports builtin python objects such as int and float.

Args:
pyval: The python or PyTD value to convert.
subst: The current type parameters.
get_node: A getter function for the current node.

Returns:
A Value that represents the constant, or None if we couldn't convert.
Raises:
NotImplementedError: If we don't know how to convert a value.
TypeParameterError: If we can't find a substitution for a type parameter.


def _get_cached_response_from_django_cache(key):

        if TieredCache._should_force_django_cache_miss():
            return CachedResponse(is_found=False, key=key, value=None)

        cached_value = django_cache.get(key, _CACHE_MISS)
        is_found = cached_value is not _CACHE_MISS
        return CachedResponse(is_found, key, cached_value)

Retrieves a CachedResponse for the given key from the django cache.

If the request was set to force cache misses, then this will always
return a cache miss response.

Args:
key (string)

Returns:
A CachedResponse with is_found status and value.


def equivalent_to(std_function):

    def decorate(cos_function):
        'Decorator argument handler'

        @wraps(cos_function)
        def decorated(path, *args, **kwargs):
            'Decorated function'
            path = fsdecode(path).replace('\\', '/')
            if is_storage(path):
                with handle_os_exceptions():
                    return cos_function(path, *args, **kwargs)
            return std_function(path, *args, **kwargs)
        return decorated
    return decorate

Decorates a cloud object compatible function
to provides fall back to standard function if
used on local files.

Args:
std_function (function): standard function to
used with local files.

Returns:
function: new function


def StartsWithIgnoreCase(self, value):

    self._awql = self._CreateSingleValueCondition(value,
                                                  'STARTS_WITH_IGNORE_CASE')
    return self._query_builder

Sets the type of the WHERE clause as "starts with ignore case".

Args:
value: The value to be used in the WHERE condition.

Returns:
The query builder that this WHERE builder links to.


def get_geometry(self):
    return (self.thet0, self.thet, self.phi0, self.phi, self.alpha, self.beta)

A convenience function to get the geometry variables.

Returns:
A tuple containing (thet0, thet, phi0, phi, alpha, beta).
See the Scatterer class documentation for a description of these
angles.


def predict_proba(self, L):

        self._set_constants(L)

        L_aug = self._get_augmented_label_matrix(L)
        mu = np.clip(self.mu.detach().clone().numpy(), 0.01, 0.99)

        if len(self.deps) > 0:
            jtm = np.zeros(L_aug.shape[1])

            for i in self.c_tree.nodes():
                node = self.c_tree.node[i]
                jtm[node["start_index"] : node["end_index"]] = 1

            for i, j in self.c_tree.edges():
                edge = self.c_tree[i][j]
                jtm[edge["start_index"] : edge["end_index"]] = 1
        else:
            jtm = np.ones(L_aug.shape[1])

        X = np.exp(L_aug @ np.diag(jtm) @ np.log(mu) + np.log(self.p))
        Z = np.tile(X.sum(axis=1).reshape(-1, 1), self.k)
        return X / Z

Returns the [n,k] matrix of label probabilities P(Y | \lambda)

Args:
L: An [n,m] scipy.sparse label matrix with values in {0,1,...,k}


def get_points_and_weights(w_func=(lambda x: np.ones(x.shape)), left=(- 1.0), right=1.0, num_points=5, n=4096):
    dx = ((float(right) - left) / n)
    z = np.hstack(np.linspace((left + (0.5 * dx)), (right - (0.5 * dx)), n))
    w = (dx * w_func(z))
    (a, b) = discrete_gautschi(z, w, num_points)
    alpha = a
    beta = np.sqrt(b)
    J = np.diag(alpha)
    J += np.diag(beta, k=(- 1))
    J += np.diag(beta, k=1)
    (points, v) = np.linalg.eigh(J)
    ind = points.argsort()
    points = points[ind]
    weights = ((v[(0, :)] ** 2) * w.sum())
    weights = weights[ind]
    return (points, weights)

Quadratude points and weights for a weighting function.

Points and weights for approximating the integral
I = \int_left^right f(x) w(x) dx
given the weighting function w(x) using the approximation
I ~ w_i f(x_i)

Args:
w_func: The weighting function w(x). Must be a function that takes
one argument and is valid over the open interval (left, right).
left: The left boundary of the interval
right: The left boundary of the interval
num_points: number of integration points to return
n: the number of points to evaluate w_func at.

Returns:
A tuple (points, weights) where points is a sorted array of the
points x_i and weights gives the corresponding weights w_i.


def _matches_version(actual_version, required_version):
    if actual_version is None:
        return False
    actual_version = actual_version.strip()
    required_version = required_version.strip()
    return actual_version.startswith(required_version)

Checks whether some version meets the requirements.

All elements of the required_version need to be present in the
actual_version.

required_version  actual_version  result
-----------------------------------------
1                 1.1             True
1.2               1               False
1.2               1.3             False
1               True

Args:
required_version: The version specified by the user.
actual_version: The version detected from the CUDA installation.
Returns: Whether the actual version matches the required one.


def normalize(self, mode='max', value=1):
    if (mode.lower() == 'sum'):
        factor = np.sum(self.y, axis=0)
    elif (mode.lower() == 'max'):
        factor = np.max(self.y, axis=0)
    else:
        raise ValueError(('Unsupported normalization mode %s!' % mode))
    self.y /= (factor / value)

Normalize the spectrum with respect to the sum of intensity

Args:
mode (str): Normalization mode. Supported modes are "max" (set the
max y value to value, e.g., in XRD patterns), "sum" (set the
sum of y to a value, i.e., like a probability density).
value (float): Value to normalize to. Defaults to 1.


def __init__(self, identifier=None):

    super(SessionCompletion, self).__init__()
    self.aborted = False
    self.analysis_reports_counter = None
    self.event_labels_counter = None
    self.identifier = identifier
    self.parsers_counter = None
    self.timestamp = None

Initializes a session completion attribute container.

Args:
identifier (Optional[str]): unique identifier of the session.
The identifier should match that of the corresponding
session start information.


def spawn(self, function, *args, **kwargs):
    assert (self.state != STOPPED), "Can't spawn when process stopped"
    spawned = Spawned(function, args, kwargs)
    self._spawned.append(spawned)
    self._spawn_count += 1
    if (self._spawn_count > SPAWN_CLEAR_COUNT):
        self._clear_spawn_list()
    return spawned

Runs the function in a worker thread, returning a Result object

Args:
function: Function to run
args: Positional arguments to run the function with
kwargs: Keyword arguments to run the function with

Returns:
Spawned: Something you can call wait(timeout) on to see when it's
finished executing


def from_prev_calc(cls, prev_calc_dir, copy_wavecar=True, mode='DIAG', nbands_factor=5, ncores=16, **kwargs):
    (vasprun, outcar) = get_vasprun_outcar(prev_calc_dir)
    prev_incar = vasprun.incar
    structure = vasprun.final_structure
    nbands = int(vasprun.parameters['NBANDS'])
    if (mode.upper() == 'DIAG'):
        nbands = int((np.ceil(((nbands * nbands_factor) / ncores)) * ncores))
    files_to_transfer = {}
    if copy_wavecar:
        for fname in ('WAVECAR', 'WAVEDER', 'WFULL'):
            w = sorted(glob.glob(str((Path(prev_calc_dir) / (fname + '*')))))
            if w:
                if (fname == 'WFULL'):
                    for f in w:
                        fname = Path(f).name
                        fname = fname.split('.')[0]
                        files_to_transfer[fname] = f
                else:
                    files_to_transfer[fname] = str(w[(- 1)])
    return cls(structure=structure, prev_incar=prev_incar, nbands=nbands, mode=mode, files_to_transfer=files_to_transfer, **kwargs)

Generate a set of Vasp input files for GW or BSE calculations from a
directory of previous Exact Diag Vasp run.

Args:
prev_calc_dir (str): The directory contains the outputs(
vasprun.xml of previous vasp run.
copy_wavecar: Whether to copy the old WAVECAR, WAVEDER and
associated files. Defaults to True.
mode (str): Supported modes are "STATIC", "DIAG" (default), "GW",
and "BSE".
nbands_factor (int): Multiplicative factor for NBANDS. Only applies
if mode=="DIAG". Need to be tested for convergence.
ncores (int): numbers of cores you do calculations. VASP will alter
NBANDS if it was not dividable by ncores. Only applies
if mode=="DIAG".
\\*\\*kwargs: All kwargs supported by MVLGWSet,
other than structure, prev_incar and mode, which
are determined from the prev_calc_dir.


def lease(self, items):
    self._manager.leaser.add(items)
    self._manager.maybe_pause_consumer()

Add the given messages to lease management.

Args:
items(Sequence[LeaseRequest]): The items to lease.


def create_unique_autosave_filename(self, filename, autosave_dir):

        basename = osp.basename(filename)
        autosave_filename = osp.join(autosave_dir, basename)
        if autosave_filename in self.name_mapping.values():
            counter = 0
            root, ext = osp.splitext(basename)
            while autosave_filename in self.name_mapping.values():
                counter += 1
                autosave_basename = '{}-{}{}'.format(root, counter, ext)
                autosave_filename = osp.join(autosave_dir, autosave_basename)
        return autosave_filename

Create unique autosave file name for specified file name.

Args:
filename (str): original file name
autosave_dir (str): directory in which autosave files are stored


def select_action(self, state_key, next_action_list):

        if self.q_df is None or self.q_df.shape[0] == 0:
            return random.choice(next_action_list)

        next_action_b_df = self.__calculate_boltzmann_factor(state_key, next_action_list)

        if next_action_b_df.shape[0] == 1:
            return next_action_b_df["action_key"].values[0]

        prob = np.random.random()
        next_action_b_df = next_action_b_df.sort_values(by=["boltzmann_factor"])

        i = 0
        while prob > next_action_b_df.iloc[i, :]["boltzmann_factor"] + next_action_b_df.iloc[i + 1, :]["boltzmann_factor"]:
            i += 1
            if i + 1 >= next_action_b_df.shape[0]:
                break

        max_b_action_key = next_action_b_df.iloc[i, :]["action_key"]
        return max_b_action_key

Select action by Q(state, action).

Concreat method for boltzmann distribution.

Args:
state_key:              The key of state.
next_action_list:       The possible action in `self.t+1`.
If the length of this list is 0, all action should be possible.

Returns:
The key of action.


def DoesNotContain(self, value):

    self._awql = self._CreateSingleValueCondition(value, 'DOES_NOT_CONTAIN')
    return self._query_builder

Sets the type of the WHERE clause as "does not contain".

Args:
value: The value to be used in the WHERE condition.

Returns:
The query builder that this WHERE builder links to.


def date_to_integer(date):
    if (pd and isinstance(date, pd.Timestamp)):
        try:
            date = date.to_datetime64()
        except:
            date = date.to_datetime()
    if isinstance(date, np.datetime64):
        return date.astype('datetime64[ms]').astype(float)
    elif isinstance(date, cftime_types):
        return cftime_to_timestamp(date, 'ms')
    if hasattr(date, 'timetuple'):
        dt_int = (calendar.timegm(date.timetuple()) * 1000)
    else:
        raise ValueError('Datetime type not recognized')
    return dt_int

Converts support date types to milliseconds since epoch

Attempts highest precision conversion of different datetime
formats to milliseconds since the epoch (1970-01-01 00:00:00).
If datetime is a cftime with a non-standard calendar the
caveats described in hv.core.util.cftime_to_timestamp apply.

Args:
date: Date- or datetime-like object

Returns:
Milliseconds since 1970-01-01 00:00:00


def poisson_source(rate, iterable, target):
    if (rate <= 0.0):
        raise ValueError('poisson_source rate {} is not positive'.format(rate))
    it = iter(iterable)
    for item in it:
        duration = random.expovariate(rate)
        sleep(duration)
        try:
            target.send(item)
        except StopIteration:
            return prepend(item, it)
    return empty_iter()

Send events at random times with uniform probability.

Args:
rate: The average number of events to send per second.
iterable: A series of items which will be sent to the target one by one.
target: The target coroutine or sink.

Returns:
An iterator over any remaining items.


async def _handle_conversation_delta(self, conversation):
    conv_id = conversation.conversation_id.id
    conv = self._conv_dict.get(conv_id, None)
    if (conv is None):
        (await self._get_or_fetch_conversation(conv_id))
    else:
        conv.update_conversation(conversation)

Receive Conversation delta and create or update the conversation.

Args:
conversation: hangouts_pb2.Conversation instance

Raises:
NetworkError: A request to fetch the complete conversation failed.


def open_street_map_geoloc_link(data):

    if isinstance(data, str):
        lat_lon = ip_geoloc(data)
        if lat_lon is None:
            return ''
        lat, lon = lat_lon
    else:
        lat, lon = data
    return 'https:
           '?query=%s%%2C%s

Get a link to open street map pointing on this IP's geolocation.

Args:
data (str/tuple): IP address or (latitude, longitude).

Returns:
str: a link to open street map pointing on this IP's geolocation.


def extract_list_from_list_of_dict(list_of_dict, key):

    result = list()
    for dictionary in list_of_dict:
        result.append(dictionary[key])
    return result

Extract a list by looking up key in each member of a list of dictionaries

Args:
list_of_dict (List[DictUpperBound]): List of dictionaries
key (Any): Key to find in each dictionary

Returns:
List: List containing values returned from each dictionary


def DeleteRecords(cls, ids, token):

    with data_store.DB.GetMutationPool() as mutation_pool:
      mutation_pool.QueueDeleteRecords(ids)

Delete records identified by ids.

Args:
ids: A list of ids provided by ClaimRecords.
token: The database access token to delete with.

Raises:
LockError: If the queue is not locked.


def days(start, end=None):

    return iterate.between(start, datetime.timedelta(days=1), end)

Iterate over the days between the given datetime_tzs.

Args:
start: datetime_tz to start from.
end: (Optional) Date to end at, if not given the iterator will never
terminate.

Returns:
An iterator which generates datetime_tz objects a day apart.


def parse_genetic_models(models_info, case_id):

    genetic_models = []
    if models_info:
        for family_info in models_info.split(','):
            splitted_info = family_info.split(':')
            if splitted_info[0] == case_id:
                genetic_models = splitted_info[1].split('|')

    return genetic_models

Parse the genetic models entry of a vcf

Args:
models_info(str): The raw vcf information
case_id(str)

Returns:
genetic_models(list)


def unwrap(data_type):
    unwrapped_nullable = False
    unwrapped_alias = False
    while (is_alias(data_type) or is_nullable_type(data_type)):
        if is_nullable_type(data_type):
            unwrapped_nullable = True
        if is_alias(data_type):
            unwrapped_alias = True
        data_type = data_type.data_type
    return (data_type, unwrapped_nullable, unwrapped_alias)

Convenience method to unwrap all Aliases and Nullables from around a
DataType. This checks for nullable wrapping aliases, as well as aliases
wrapping nullables.

Args:
data_type (DataType): The target to unwrap.

Return:
Tuple[DataType, bool, bool]: The underlying data type; a bool that is
set if a nullable was present; a bool that is set if an alias was
present.


def line(self, x0, y0, x1, y1, char):
    if (x0 > x1):
        (x1, x0) = (x0, x1)
        (y1, y0) = (y0, y1)
    dx = (x1 - x0)
    dy = (y1 - y0)
    if ((dx == 0) and (dy == 0)):
        self.point(x0, y0, char)
    elif (abs(dx) >= abs(dy)):
        for x in range(x0, (x1 + 1)):
            if (dx == 0):
                y = y0
            else:
                y = (y0 + int(round((((x - x0) * dy) / float(dx)))))
            self.point(x, y, char)
    elif (y0 < y1):
        for y in range(y0, (y1 + 1)):
            if (dy == 0):
                x = x0
            else:
                x = (x0 + int(round((((y - y0) * dx) / float(dy)))))
            self.point(x, y, char)
    else:
        for y in range(y1, (y0 + 1)):
            if (dy == 0):
                x = x0
            else:
                x = (x1 + int(round((((y - y1) * dx) / float(dy)))))
            self.point(x, y, char)

Create a line on ASCII canvas.

Args:
x0 (int): x coordinate where the line should start.
y0 (int): y coordinate where the line should start.
x1 (int): x coordinate where the line should end.
y1 (int): y coordinate where the line should end.
char (str): character to draw the line with.


def is_empty(self):
    return self._empty

Deteremines whether or not anything has been parsed with this
instrumentation block.

Returns:
A boolean indicating whether or not the this instrumentation block
has parsed and contains any output.


def FromEvent(cls, service_event):
    (_, _, name) = service_event.key_path.rpartition(WindowsService._REGISTRY_KEY_PATH_SEPARATOR)
    service_type = service_event.regvalue.get('Type', '')
    image_path = service_event.regvalue.get('ImagePath', '')
    start_type = service_event.regvalue.get('Start', '')
    service_dll = service_event.regvalue.get('ServiceDll', '')
    object_name = service_event.regvalue.get('ObjectName', '')
    if service_event.pathspec:
        source = (service_event.pathspec.location, service_event.key_path)
    else:
        source = ('Unknown', 'Unknown')
    return cls(name=name, service_type=service_type, image_path=image_path, start_type=start_type, object_name=object_name, source=source, service_dll=service_dll)

Creates a service object from an event.

Args:
service_event (EventObject): event to create a new service object from.

Returns:
WindowsService: service.


def ptb_producer(raw_data, batch_size, num_steps, name=None):
    with tf.name_scope(name, 'PTBProducer', [raw_data, batch_size, num_steps]):
        raw_data = tf.convert_to_tensor(raw_data, name='raw_data', dtype=tf.int32)
        data_len = tf.size(raw_data)
        batch_len = (data_len
        data = tf.reshape(raw_data[0:(batch_size * batch_len)], [batch_size, batch_len])
        epoch_size = ((batch_len - 1)
        assertion = tf.assert_positive(epoch_size, message='epoch_size == 0, decrease batch_size or num_steps')
        with tf.control_dependencies([assertion]):
            epoch_size = tf.identity(epoch_size, name='epoch_size')
        i = tf.train.range_input_producer(epoch_size, shuffle=False).dequeue()
        x = tf.strided_slice(data, [0, (i * num_steps)], [batch_size, ((i + 1) * num_steps)])
        x.set_shape([batch_size, num_steps])
        y = tf.strided_slice(data, [0, ((i * num_steps) + 1)], [batch_size, (((i + 1) * num_steps) + 1)])
        y.set_shape([batch_size, num_steps])
        return (x, y)

Iterate on the raw PTB data.

This chunks up raw_data into batches of examples and returns Tensors that
are drawn from these batches.

Args:
raw_data: one of the raw data outputs from ptb_raw_data.
batch_size: int, the batch size.
num_steps: int, the number of unrolls.
name: the name of this operation (optional).

Returns:
A pair of Tensors, each shaped [batch_size, num_steps]. The second element
of the tuple is the same data time-shifted to the right by one.

Raises:
tf.errors.InvalidArgumentError: if batch_size or num_steps are too high.


def preconnect(self, size=-1):

        if size == -1 and self.max_size == -1:
            raise ClientError("size=-1 not allowed with pool max_size=-1")
        limit = min(size, self.max_size) if size != -1 else self.max_size
        clients = yield [self.get_connected_client() for _ in range(0, limit)]
        for client in clients:
            self.release_client(client)

(pre)Connects some or all redis clients inside the pool.

Args:
size (int): number of redis clients to build and to connect
(-1 means all clients if pool max_size > -1)

Raises:
ClientError: when size == -1 and pool max_size == -1