def _process_exception(e, body, tb):
    msg = (e.message if hasattr(e, 'message') else str(e))
    exception_type = str(e.__class__)
    exception_name = str(e.__class__.__name__)
    properties = pika.BasicProperties(content_type='application/text', delivery_mode=2, headers={'exception': msg, 'exception_type': exception_type, 'exception_name': exception_name, 'traceback': tb, 'UUID': str(uuid.uuid4())})
    send_message('harvester', body, properties=properties)

Process informations about exception and send them thru AMQP.

Args:
e (obj): Exception instance.
body (str): Text which will be sent over AMQP.
tb (obj): Traceback object with informations, which will be put to the
headers.


def _fulfillment_to_details(fulfillment):

    if fulfillment.type_name == 'ed25519-sha-256':
        return {
            'type': 'ed25519-sha-256',
            'public_key': base58.b58encode(fulfillment.public_key).decode(),
        }

    if fulfillment.type_name == 'threshold-sha-256':
        subconditions = [
            _fulfillment_to_details(cond['body'])
            for cond in fulfillment.subconditions
        ]
        return {
            'type': 'threshold-sha-256',
            'threshold': fulfillment.threshold,
            'subconditions': subconditions,
        }

    raise UnsupportedTypeError(fulfillment.type_name)

Encode a fulfillment as a details dictionary

Args:
fulfillment: Crypto-conditions Fulfillment object


def random_masking(inputs: torch.Tensor, mask_ratio: float, unmasked_channel_indices: Optional[list]=None, channel_consistent_masking: bool=False, mask_value: int=0):
    if mask_ratio < 0 or mask_ratio >= 1:
        raise ValueError(f'Mask ratio {mask_ratio} has to be between 0 and 1.')
    batch_size, num_channels, sequence_length, num_features = inputs.shape
    device = inputs.device
    len_keep = int(sequence_length * (1 - mask_ratio))
    if channel_consistent_masking:
        noise = torch.rand(batch_size, 1, sequence_length, device=device)
        noise = noise.repeat(1, num_channels, 1)
    else:
        noise = torch.rand(batch_size, num_channels, sequence_length, device=device)
    mask = torch.ones(batch_size, num_channels, sequence_length, device=device)
    mask[:, :, :len_keep] = 0
    ids_shuffle = torch.argsort(noise, dim=-1)
    ids_restore = torch.argsort(ids_shuffle, dim=-1)
    mask = torch.gather(mask, dim=-1, index=ids_restore)
    mask = mask.unsqueeze(-1).repeat(1, 1, 1, num_features)
    if unmasked_channel_indices is not None:
        mask[:, unmasked_channel_indices, :, :] = 0
    inputs_mask = inputs.masked_fill(mask.bool(), mask_value)
    return (inputs_mask, mask[..., 0])

random_masking: Mask the input considering the control variables.

Args:
inputs (`torch.Tensor` of shape `(batch_size, num_channels, sequence_length, num_features)`):
The input tensor to mask.
mask_ratio (`float`):
Masking ratio applied to mask the input data during random pretraining. It is the number between 0 and 1.
unmasked_channel_indices (list, *optional*):
Indices of channels that will not be masked.
channel_consistent_masking (bool, *optional*, defaults to `False`):
When true, masking will be same across all channels of a timeseries. Otherwise, masking positions will vary
across channels.
mask_value (int, *optional*, defaults to 0):
Define the value of masked patches for pretraining.

Returns:
`tuple(torch.Tensor)`: inputs_mask, masked input, same shape as input Tensor and mask tensor of shape [bs x c x
n]


def assertAllDifferent(self, tensors):
    values = [array_ops.reshape(t, shape=[-1]) for t in tensors]
    values = array_ops.concat(values, axis=0)
    values = self.evaluate(values)
    values = values.tolist()
    self.assertAllEqual(len(values), len(set(values)))

Checks that there are no duplicate elements anywhere among the tensors.

Args:
tensors: a list of tensors. They can have different shapes.


def _matplotlib_circuit_drawer(circuit, scale=0.7, filename=None, style=None, plot_barriers=True, reverse_bits=False, justify=None):
    (qregs, cregs, ops) = utils._get_layered_instructions(circuit, reverse_bits=reverse_bits, justify=justify)
    qcd = _matplotlib.MatplotlibDrawer(qregs, cregs, ops, scale=scale, style=style, plot_barriers=plot_barriers, reverse_bits=reverse_bits)
    return qcd.draw(filename)

Draw a quantum circuit based on matplotlib.
If `%matplotlib inline` is invoked in a Jupyter notebook, it visualizes a circuit inline.
We recommend `%config InlineBackend.figure_format = 'svg'` for the inline visualization.

Args:
circuit (QuantumCircuit): a quantum circuit
scale (float): scaling factor
filename (str): file path to save image to
style (dict or str): dictionary of style or file name of style file
reverse_bits (bool): When set to True reverse the bit order inside
registers for the output visualization.
plot_barriers (bool): Enable/disable drawing barriers in the output
circuit. Defaults to True.
justify (str) : `left`, `right` or `none`. Defaults to `left`. Says how
the circuit should be justified.

Returns:
matplotlib.figure: a matplotlib figure object for the circuit diagram


def create(self,params=None, headers=None):

        path = '/creditor_bank_accounts'

        if params is not None:
            params = {self._envelope_key(): params}

        try:
          response = self._perform_request('POST', path, params, headers,
                                            retry_failures=True)
        except errors.IdempotentCreationConflictError as err:
          return self.get(identity=err.conflicting_resource_id,
                          params=params,
                          headers=headers)
        return self._resource_for(response)

Create a creditor bank account.

Creates a new creditor bank account object.

Args:
params (dict, optional): Request body.

Returns:
ListResponse of CreditorBankAccount instances


def __init__(self, imports=None, events=None, todos=None, creator=None):

        self._timezones = {}
        self.events = set()
        self.todos = set()
        self._unused = Container(name='VCALENDAR')
        self.scale = None
        self.method = None

        self.timeline = Timeline(self)

        if imports is not None:
            if isinstance(imports, string_types):
                container = string_to_container(imports)
            elif isinstance(imports, collections.Iterable):
                container = lines_to_container(imports)
            else:
                raise TypeError("Expecting a sequence or a string")

            if len(container) != 1:
                raise NotImplementedError(
                    'Multiple calendars in one file are not supported')

            self._populate(container[0])
        else:
            if events is not None:
                self.events.update(set(events))
            if todos is not None:
                self.todos.update(set(todos))
            self._creator = creator

Instantiates a new Calendar.

Args:
imports (string or list of lines/strings): data to be imported into the Calendar(),
events (set of Event): :class:`ics.event.Event`s to be added to the calendar
todos (set of Todo): :class:`ics.event.Todo`s to be added to the calendar
creator (string): uid of the creator program.

If `imports` is specified, every other argument will be ignored.


def clean(struct: Union[dict, list]) -> Union[dict, list]:
    if isinstance(struct, dict):
        for key, value in struct.items():
            if isinstance(value, str) and DATETIME_RE.match(value):
                struct[key] = struct[key].replace('.000Z', 'Z')
            else:
                Discovery_To_BigQuery.clean(value)
    elif isinstance(struct, list):
        for index, value in enumerate(struct):
            if isinstance(value, str) and DATETIME_RE.match(value):
                struct[index] = struct[index].replace('.000Z', 'Z')
            else:
                Discovery_To_BigQuery.clean(value)
    return struct

Helper to recursively clean up dates for BigQuery.

Usually applied to the data iterator being written to the BigQuery table.
Right now only cleans the date by stripping the '.000Z'

Args:
struct: The object or row being cleaned up.

Returns:
The object or row with the offending data cleaned up.

Raises:
HttpError: If the wrong API values are specified.


def list_patches(self):
    if (not self.__squid):
        return []
    if (self.__patch_list is None):
        try:
            pat_all_handle = win32api.RegOpenKeyEx(getattr(win32con, self.__reg_hive), self.__reg_patches_path, 0, (win32con.KEY_READ | self.__reg_32bit_access))
        except pywintypes.error as exc:
            if (exc.winerror == winerror.ERROR_FILE_NOT_FOUND):
                log.warning('Not Found %s\\%s 32bit %s', self.__reg_hive, self.__reg_patches_path, self.__reg_32bit)
                return []
            raise
        (pc_sub_key_cnt, _, _) = win32api.RegQueryInfoKey(pat_all_handle)
        if (not pc_sub_key_cnt):
            return []
        (squid_patch_all, _, _, _) = zip(*win32api.RegEnumKeyEx(pat_all_handle))
        ret = []
        for patch_squid in squid_patch_all:
            try:
                patch_squid_handle = win32api.RegOpenKeyEx(pat_all_handle, patch_squid, 0, (win32con.KEY_READ | self.__reg_32bit_access))
                (patch_display_name, patch_display_name_type) = self.__reg_query_value(patch_squid_handle, 'DisplayName')
                (patch_state, patch_state_type) = self.__reg_query_value(patch_squid_handle, 'State')
                if ((patch_state_type != win32con.REG_DWORD) or (not isinstance(patch_state_type, six.integer_types)) or (patch_state != 1) or (patch_display_name_type != win32con.REG_SZ)):
                    continue
                win32api.RegCloseKey(patch_squid_handle)
                ret.append(patch_display_name)
            except pywintypes.error as exc:
                if (exc.winerror == winerror.ERROR_FILE_NOT_FOUND):
                    log.debug('skipped patch, not found %s', patch_squid)
                    continue
                raise
    return ret

For installers which follow the Microsoft Installer standard, returns
a list of patches applied.

Returns:
value (list): Long name of the patch.


def get_collection(self, lang=None, task=None):

    if lang: id = "{}{}".format(Downloader.LANG_PREFIX, lang)
    elif task: id = "{}{}".format(Downloader.TASK_PREFIX, task)
    else: raise ValueError("You should pass either the task or the lang")
    try:
      return self.info(id)
    except ValueError as e:
      if lang: raise LanguageNotSupported("Language {} is not supported".format(id))
      if task: raise TaskNotSupported("Task {} is not supported".format(id))

Return the collection that represents a specific language or task.

Args:
lang (string): Language code.
task (string): Task name.


def curie_search(self, curie: str) -> dict:
    ilx_row = self.curie2row.get(curie)
    if (not ilx_row):
        return None
    else:
        return ilx_row

Returns the row in InterLex associated with the curie

Note:
Pressumed to not have duplicate curies in InterLex
Args:
curie: The "prefix:fragment_id" of the existing_id pertaining to the ontology
Returns:
None or dict


def put_task(self, func, args, response):
    self._rpc_queue.put_nowait((func, args, response))

Place a task onto the RPC queue.

This temporary functionality will go away but it lets you run a
task synchronously with RPC dispatch by placing it onto the
RCP queue.

Args:
func (callable): The function to execute
args (iterable): The function arguments
response (GenericResponse): The response object to signal the
result on.


class ConvNextV2Stage(nn.Module):

    def __init__(self, config, in_channels, out_channels, kernel_size=2, stride=2, depth=2, drop_path_rates=None):
        super().__init__()
        if in_channels != out_channels or stride > 1:
            self.downsampling_layer = nn.Sequential(ConvNextV2LayerNorm(in_channels, eps=1e-06, data_format='channels_first'), nn.Conv2d(in_channels, out_channels, kernel_size=kernel_size, stride=stride))
        else:
            self.downsampling_layer = nn.Identity()
        drop_path_rates = drop_path_rates or [0.0] * depth
        self.layers = nn.Sequential(*[ConvNextV2Layer(config, dim=out_channels, drop_path=drop_path_rates[j]) for j in range(depth)])

    def forward(self, hidden_states: torch.FloatTensor) -> torch.Tensor:
        hidden_states = self.downsampling_layer(hidden_states)
        hidden_states = self.layers(hidden_states)
        return hidden_states

ConvNeXTV2 stage, consisting of an optional downsampling layer + multiple residual blocks.

Args:
config ([`ConvNextV2Config`]): Model configuration class.
in_channels (`int`): Number of input channels.
out_channels (`int`): Number of output channels.
depth (`int`): Number of residual blocks.
drop_path_rates(`List[float]`): Stochastic depth rates for each layer.


def get_counter(self, counter_name, default=0):
    self.__update_state()
    return self._state.counters_map.get(counter_name, default)

Get the value of the named counter from this job.

When a job is running, counter values won't be very accurate.

Args:
counter_name: name of the counter in string.
default: default value if the counter doesn't exist.

Returns:
Value in int of the named counter.


def download_cutout(self, reading, focus=None, needs_apcor=False):
    logger.debug('Doing download_cutout with inputs: reading:{} focus:{} needs_apcor:{}'.format(reading, focus, needs_apcor))
    assert isinstance(reading, SourceReading)
    min_radius = config.read('CUTOUTS.SINGLETS.RADIUS')
    if (not isinstance(min_radius, Quantity)):
        min_radius = (min_radius * units.arcsec)
    radius = ((max(reading.uncertainty_ellipse.a, reading.uncertainty_ellipse.b) * 2.5) + min_radius)
    logger.debug('got radius for cutout: {}'.format(radius))
    image_uri = reading.get_image_uri()
    logger.debug('Getting cutout at {} for {}'.format(reading.reference_sky_coord, image_uri))
    hdulist = storage._cutout_expnum(reading.obs, reading.reference_sky_coord, radius)
    logger.debug('Getting the aperture correction.')
    source = SourceCutout(reading, hdulist, radius=radius)
    try:
        apcor = source.apcor
        zmag = source.zmag
        source.reading.get_observation_header()
    except Exception as ex:
        if needs_apcor:
            import sys, traceback
            sys.stderr.write('Failed to retrieve apcor but apcor required.  Raising error, see logs for more details')
            sys.stderr.write(traceback.print_exc())
        pass
    logger.debug('Sending back the source reading.')
    return source

Downloads a cutout of the FITS image for a given source reading.

Args:
reading: ossos.astrom.SourceReading
The reading which will be the focus of the downloaded image.
focus: tuple(int, int)
The x, y coordinates that should be the focus of the downloaded
image.  These coordinates should be in terms of the
source_reading parameter's coordinate system.
Default value is None, in which case the source reading's x, y
position is used as the focus.
needs_apcor: bool
If True, the apcor file with data needed for photometry
calculations is downloaded in addition to the image.
Defaults to False.

Returns:
cutout: ossos.downloads.data.SourceCutout


def apply_enhancement(data, func, exclude=None, separate=False, pass_dask=False):
    attrs = data.attrs
    bands = data.coords['bands'].values
    if (exclude is None):
        exclude = (['A'] if ('A' in bands) else [])
    if separate:
        data_arrs = []
        for (idx, band_name) in enumerate(bands):
            band_data = data.sel(bands=[band_name])
            if (band_name in exclude):
                data_arrs.append(band_data)
                continue
            if pass_dask:
                dims = band_data.dims
                coords = band_data.coords
                d_arr = func(band_data.data, index=idx)
                band_data = xr.DataArray(d_arr, dims=dims, coords=coords)
            else:
                band_data = func(band_data, index=idx)
            data_arrs.append(band_data)
            attrs.update(band_data.attrs)
        data.data = xr.concat(data_arrs, dim='bands').data
        data.attrs = attrs
        return data
    else:
        band_data = data.sel(bands=[b for b in bands if (b not in exclude)])
        if pass_dask:
            dims = band_data.dims
            coords = band_data.coords
            d_arr = func(band_data.data)
            band_data = xr.DataArray(d_arr, dims=dims, coords=coords)
        else:
            band_data = func(band_data)
        attrs.update(band_data.attrs)
        new_data = xr.concat([band_data, data.sel(bands=exclude)], dim='bands')
        data.data = new_data.sel(bands=bands).data
        data.attrs = attrs
    return data

Apply `func` to the provided data.

Args:
data (xarray.DataArray): Data to be modified inplace.
func (callable): Function to be applied to an xarray
exclude (iterable): Bands in the 'bands' dimension to not include
in the calculations.
separate (bool): Apply `func` one band at a time. Default is False.
pass_dask (bool): Pass the underlying dask array instead of the
xarray.DataArray.


def f0(E, fermi, T):

    return 1. / (1. + np.exp((E - fermi) / (_cd("Boltzmann constant in eV/K") * T)))

Returns the equilibrium fermi-dirac.
Args:
E (float): energy in eV
fermi (float): the fermi level in eV
T (float): the temperature in kelvin


def get_hash(file_path, checksum='sha1'):
    sha = getattr(hashlib, checksum)()
    with open(file_path) as file_descriptor:
        while True:
            chunk = file_descriptor.read(65536)
            if (not chunk):
                break
            sha.update(chunk)
    return sha.hexdigest()

Generate a hash for the given file

Args:
file_path (str): Path to the file to generate the hash for
checksum (str): hash to apply, one of the supported by hashlib, for
example sha1 or sha512

Returns:
str: hash for that file


def get_additional_charge_by_description(self, description):

        params = {
            "description": description
        }
        return self.client._get(self.url + 'recurringBillItems/', params=params, headers=self.get_headers())

Query extra charges of shop’s invoices that meet the stipulated filters.

Args:
description: Description entered in the extra charge.

Returns:


def forward_cfg_node(self, new_name, condition=None):
    new_node = self.ctx.connect_new_cfg_node(self.node, new_name, condition)
    return self.change_cfg_node(new_node)

Create a new CFG Node connected to the current cfg node.

Args:
new_name: A name for the new node.
condition: A cfg.Binding representing the condition that needs to be true
for this node to be reached.

Returns:
A new state which is the same as this state except for the node, which is
the new one.


async def send(self, msg: Message):

        if not msg.sender:
            msg.sender = str(self.agent.jid)
            logger.debug(f"Adding agent's jid as sender to message: {msg}")
        await self.agent.container.send(msg, self)
        msg.sent = True
        self.agent.traces.append(msg, category=str(self))

Sends a message.

Args:
msg (spade.message.Message): the message to be sent.


def summarize(self, document, Abstractor, similarity_filter=None):
    if (isinstance(document, str) is False):
        raise TypeError('The type of document must be str.')
    if (isinstance(Abstractor, AbstractableDoc) is False):
        raise TypeError('The type of Abstractor must be AbstractableDoc.')
    if ((isinstance(similarity_filter, SimilarityFilter) is False) and (similarity_filter is not None)):
        raise TypeError('The type of similarity_filter must be SimilarityFilter.')
    normalized_sentences = self.listup_sentence(document)
    if (similarity_filter is not None):
        normalized_sentences = similarity_filter.similar_filter_r(normalized_sentences)
    self.tokenize(document)
    words = self.token
    fdist = nltk.FreqDist(words)
    top_n_words = [w[0] for w in fdist.items()][:self.target_n]
    scored_list = self.__closely_associated_score(normalized_sentences, top_n_words)
    filtered_list = Abstractor.filter(scored_list)
    result_list = [normalized_sentences[idx] for (idx, score) in filtered_list]
    result_dict = {'summarize_result': result_list, 'scoring_data': filtered_list}
    return result_dict

Execute summarization.

Args:
document:           The target document.
Abstractor:         The object of AbstractableDoc.
similarity_filter   The object of SimilarityFilter.

Returns:
dict data.
- "summarize_result": The list of summarized sentences.,
- "scoring_data":     The list of scores.


def airing_today(self, **kwargs):

        path = self._get_path('airing_today')

        response = self._GET(path, kwargs)
        self._set_attrs_to_values(response)
        return response

Get the list of TV shows that air today. Without a specified timezone,
this query defaults to EST (Eastern Time UTC-05:00).

Args:
page: (optional) Minimum 1, maximum 1000.
language: (optional) ISO 639 code.
timezone: (optional) Valid value from the list of timezones.

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


def __init__(self, scores=None, classes=None):
    if scores is not None and (not (isinstance(scores, tensor.Tensor) and scores.dtype.is_floating)):
        raise ValueError('Classification scores must be a float32 Tensor; got {}'.format(scores))
    if classes is not None and (not (isinstance(classes, tensor.Tensor) and dtypes.as_dtype(classes.dtype) == dtypes.string)):
        raise ValueError('Classification classes must be a string Tensor; got {}'.format(classes))
    if scores is None and classes is None:
        raise ValueError('Cannot create a ClassificationOutput with empty arguments. At least one of `scores` and `classes` must be defined.')
    self._scores = scores
    self._classes = classes

Constructor for `ClassificationOutput`.

Args:
scores: A float `Tensor` giving scores (sometimes but not always
interpretable as probabilities) for each class.  May be `None`, but
only if `classes` is set.  Interpretation varies-- see class doc.
classes: A string `Tensor` giving predicted class labels.  May be `None`,
but only if `scores` is set.  Interpretation varies-- see class doc.

Raises:
ValueError: if neither classes nor scores is set, or one of them is not a
`Tensor` with the correct dtype.


def l2_distance(t1, t2, epsilon=1e-12, name=None):
    with tf.name_scope(name, 'l2_distance', [t1, t2]) as scope:
        t1 = tf.convert_to_tensor(t1, name='t1')
        t2 = tf.convert_to_tensor(t2, name='t2')
        return tf.sqrt(tf.maximum(l2_distance_sq(t1, t2, scope), epsilon))

l2 distance between t1 and t2 and caps the gradient of the Square Root.

Args:
t1: A tensor.
t2: A tensor that is the same size as t1.
epsilon: A lower bound for distance, useful to avoid sqrt of very small
values that can blow up gradients.
name: Optional name for this op.
Returns:
The l2 distance between t1 and t2.


def plot_vec(axis, step, var):
    (xmesh, ymesh, vec1, vec2) = get_meshes_vec(step, var)
    dipz = (step.geom.nztot
    if conf.field.shift:
        vec1 = np.roll(vec1, conf.field.shift, axis=0)
        vec2 = np.roll(vec2, conf.field.shift, axis=0)
    if (step.geom.spherical or (conf.plot.ratio is None)):
        dipx = dipz
    else:
        dipx = (step.geom.nytot if step.geom.twod_yz else step.geom.nxtot)
        dipx = (int(((dipx
    axis.quiver(xmesh[(::dipx, ::dipz)], ymesh[(::dipx, ::dipz)], vec1[(::dipx, ::dipz)], vec2[(::dipx, ::dipz)], linewidths=1)

Plot vector field.

Args:
axis (:class:`matplotlib.axes.Axes`): the axis handler of an
existing matplotlib figure where the vector field should
be plotted.
step (:class:`~stagpy.stagyydata._Step`): a step of a StagyyData
instance.
var (str): the vector field name.


def subCell2DFnArray(arr, fn, shape, dtype=None, **kwargs):

    sh = list(arr.shape)
    sh[:2] = shape
    out = np.empty(sh, dtype=dtype)
    for i, j, c in subCell2DGenerator(arr, shape, **kwargs):
        out[i, j] = fn(c)
    return out

Return array where every cell is the output of a given cell function

Args:
fn (function): ...to be executed on all sub-arrays

Returns:
array: value of every cell equals result of fn(sub-array)

Example:
mx = subCell2DFnArray(myArray, np.max, (10,6) )
- -> here mx is a 2d array containing all cell maxima


def create_from_json(cls, json_data):
    msa = Msa()
    msa.msa = json_data['msa_info']['msa']
    msa.meta = (json_data['meta'] if ('meta' in json_data) else None)
    msa.component_results = _create_component_results(json_data, 'msa_info')
    return msa

Deserialize msa json data into a Msa object

Args:
json_data (dict): The json data for this msa

Returns:
Msa object


def UpdateTaskAsProcessingByIdentifier(self, task_identifier):
    with self._lock:
        task_processing = self._tasks_processing.get(task_identifier, None)
        if task_processing:
            task_processing.UpdateProcessingTime()
            self._UpdateLatestProcessingTime(task_processing)
            return
        task_queued = self._tasks_queued.get(task_identifier, None)
        if task_queued:
            logger.debug('Task {0:s} was queued, now processing.'.format(task_identifier))
            self._tasks_processing[task_identifier] = task_queued
            del self._tasks_queued[task_identifier]
            task_queued.UpdateProcessingTime()
            self._UpdateLatestProcessingTime(task_queued)
            return
        task_abandoned = self._tasks_abandoned.get(task_identifier, None)
        if task_abandoned:
            del self._tasks_abandoned[task_identifier]
            self._tasks_processing[task_identifier] = task_abandoned
            logger.debug('Task {0:s} was abandoned, but now processing.'.format(task_identifier))
            task_abandoned.UpdateProcessingTime()
            self._UpdateLatestProcessingTime(task_abandoned)
            return
        if (task_identifier in self._tasks_pending_merge):
            return
    raise KeyError('Status of task {0:s} is unknown.'.format(task_identifier))

Updates the task manager to reflect the task is processing.

Args:
task_identifier (str): unique identifier of the task.

Raises:
KeyError: if the task is not known to the task manager.


def get_tag(self, key, *, case_sensitive=True):

        key = key if case_sensitive else key.lower()
        for tag in self.resource.tags:
            if not case_sensitive:
                if tag.key.lower() == key:
                    return tag
            elif key == tag.key:
                return tag

        return None

Return a tag by key, if found

Args:
key (str): Name/key of the tag to locate
case_sensitive (bool): Should tag keys be treated case-sensitive (default: true)

Returns:
`Tag`,`None`


def __schema_descriptor(self, services):

    methods_desc = {}

    for service in services:
      protorpc_methods = service.all_remote_methods()
      for protorpc_method_name in protorpc_methods.iterkeys():
        rosy_method = '%s.%s' % (service.__name__, protorpc_method_name)
        method_id = self.__id_from_name[rosy_method]

        request_response = {}

        request_schema_id = self.__request_schema.get(method_id)
        if request_schema_id:
          request_response['request'] = {
              '$ref': request_schema_id
              }

        response_schema_id = self.__response_schema.get(method_id)
        if response_schema_id:
          request_response['response'] = {
              '$ref': response_schema_id
              }

        methods_desc[rosy_method] = request_response

    descriptor = {
        'methods': methods_desc,
        'schemas': self.__parser.schemas(),
        }

    return descriptor

Descriptor for the all the JSON Schema used.

Args:
services: List of protorpc.remote.Service instances implementing an
api/version.

Returns:
Dictionary containing all the JSON Schema used in the service.


def __init__(self, optimizer, clipping_value, scope='clipped-step', summary_labels=()):

        assert isinstance(clipping_value, float) and clipping_value > 0.0
        self.clipping_value = clipping_value

        super(ClippedStep, self).__init__(optimizer=optimizer, scope=scope, summary_labels=summary_labels)

Creates a new multi-step meta optimizer instance.

Args:
optimizer: The optimizer which is modified by this meta optimizer.
clipping_value: Clip deltas at this value.


def _apply_combiner_to_embeddings(self, embeddings: tensor.Tensor, weight: tensor.Tensor, combiner: Optional[Text]=None) -> tensor.Tensor:
    if combiner is None:
        combiner = 'mean'
    if combiner == 'sum':
        embeddings = math_ops.reduce_sum(embeddings, axis=-2)
    elif combiner == 'mean':
        embeddings = math_ops.reduce_sum(embeddings, axis=-2)
        weight_sum = math_ops.reduce_sum(weight, axis=-2)
        embeddings = math_ops.div_no_nan(embeddings, weight_sum)
    elif combiner == 'sqrtn':
        embeddings = math_ops.reduce_sum(embeddings, axis=-2)
        weight_squared = math_ops.pow(weight, 2)
        weight_sum = math_ops.reduce_sum(weight_squared, axis=-2)
        weight_sum_sqrt = math_ops.sqrt(weight_sum)
        embeddings = math_ops.div_no_nan(embeddings, weight_sum_sqrt)
    else:
        raise ValueError(f"combiner must be one of 'mean', 'sqrtn' or 'sum', got {combiner}")
    return embeddings

Apply the combiner to the embedding look up result on second to last axis.

Args:
embeddings: A Tensor of the embedding lookup result.
weight: A Tensor of weight which has the same shape of the embeddings.
combiner: One of "mean", "sum", "sqrtn". Defaults to "mean".

Raises:
ValueError: If the combiner is not one of 'mean', 'sqrtn' or 'sum'.
Returns:
A Tensor.


def _chain_part_processors(part_processors: Sequence[PartProcessorWithMatchFn], task_name: str) -> PartProcessorFn:

    async def processor(part: ProcessorPart) -> AsyncIterable[ProcessorPart]:
        output_queue = asyncio.Queue()
        processors = []
        match_fns = []
        for p in part_processors:
            processors.append(_CaptureReservedSubstreams(output_queue, p))
            match_fns.append(p.match)
        chained_processor = map_processor.chain_part_functions(processors, match_fns)
        content = chained_processor(part)
        create_task(_enqueue_content(content, output_queue), name=task_name)
        while (part := (await output_queue.get())) is not None:
            yield part
            output_queue.task_done()
    return processor

Combine **part processors** in sequence.

Adds debug and status streams to the output.

NOTE: Substreams debug and status are yielded immediately instead of passing
them to the next processor.

Args:
part_processors: sequence of part processors to chain.
task_name: Name that will be assigned to the asyncio task running the
processor.

Returns:
Part processor that is a chain of the provided Sequence of part
processors.


def dump(self):
    import tempfile
    with tempfile.NamedTemporaryFile(delete=False, mode='w') as fobj:
        json.dump(self.info, fobj)
        return fobj.name

Save analytics report to a temporary file.

Returns:
str: path to the temporary file that contains the analytics report.


def get_path_for_url(url, folder=None, filename=None, overwrite=False):
    if (not filename):
        urlpath = urlsplit(url).path
        filename = basename(urlpath)
    (filename, extension) = splitext(filename)
    if (not folder):
        folder = get_temp_dir()
    path = join(folder, ('%s%s' % (filename, extension)))
    if overwrite:
        try:
            remove(path)
        except OSError:
            pass
    else:
        count = 0
        while exists(path):
            count += 1
            path = join(folder, ('%s%d%s' % (filename, count, extension)))
    return path

Get filename from url and join to provided folder or temporary folder if no folder supplied, ensuring uniqueness

Args:
url (str): URL to download
folder (Optional[str]): Folder to download it to. Defaults to None (temporary folder).
filename (Optional[str]): Filename to use for downloaded file. Defaults to None (derive from the url).
overwrite (bool): Whether to overwrite existing file. Defaults to False.

Returns:
str: Path of downloaded file


def equals(self, rhs):

    try:
      return isinstance(rhs, self._class_name)
    except TypeError:

      return type(rhs) == type(self._class_name)

Check to see if the RHS is an instance of class_name.

Args:
# rhs: the right hand side of the test
rhs: object

Returns:
bool


def size(self, path):
    return self._gcsIO().size(path)

Get size of path on the FileSystem.

Args:
path: string path in question.

Returns: int size of path according to the FileSystem.

Raises:
``BeamIOError``: if path doesn't exist.


def convert_unsqueeze(params, w_name, scope_name, inputs, layers, weights, names):

    print('Converting unsqueeze ...')

    if names == 'short':
        tf_name = 'UNSQ' + random_string(4)
    elif names == 'keep':
        tf_name = w_name
    else:
        tf_name = w_name + str(random.random())

    def target_layer(x):
        import keras
        return keras.backend.expand_dims(x)

    lambda_layer = keras.layers.Lambda(target_layer, name=tf_name + 'E')
    layers[scope_name] = lambda_layer(layers[inputs[0]])

Convert unsqueeze operation.

Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers


def finalize_options(self):
    self.cwd = os.path.abspath(os.path.dirname(__file__))
    self.build_dirs = [os.path.join(self.cwd, 'build'), os.path.join(self.cwd, 'htmlcov'), os.path.join(self.cwd, 'dist'), os.path.join(self.cwd, 'pylink_square.egg-info')]
    self.build_artifacts = ['.pyc', '.o', '.elf', '.bin']

Populate the attributes.

Args:
self (CleanCommand): the ``CleanCommand`` instance

Returns:
``None``


def check_diffs(hunks: Iterable[diff_parser.Hunk], *, prohibited_regex: str, suppression_regex: str | None=None) -> list[RegexLocation]:
    prohibited_regex = re.compile(prohibited_regex)
    if suppression_regex is not None:
        suppression_regex = re.compile(suppression_regex)

    def should_not_suppress(line) -> bool:
        if suppression_regex:
            return not suppression_regex.search(line)
        return True
    regex_locations = []
    for hunk in hunks:
        for line_no, line in hunk.added_lines():
            if should_not_suppress(line):
                regex_locations.extend([RegexLocation(hunk.file, line_no, line, regex_match.group()) for regex_match in prohibited_regex.finditer(line)])
    return regex_locations

Checks FileDiffs for prohibited regexes.

Arguments:
hunks: A sequence of Hunk objects representing the hunks of the diff.
prohibited_regex: The regex that isn't allowed in the diff.
suppression_regex: A regex used as an escape hatch to allow the prohibited
regex in the diff. If this is found on the same line as prohibited_regex,
there is no error.

Returns:
A list of RegexLocations where the prohibited_regex is found.


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

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

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

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


def all_gather(data):

    world_size = get_world_size()
    if world_size == 1:
        return [data]

    buffer = pickle.dumps(data)
    storage = torch.ByteStorage.from_buffer(buffer)
    tensor = torch.ByteTensor(storage).to("cuda")

    local_size = torch.IntTensor([tensor.numel()]).to("cuda")
    size_list = [torch.IntTensor([0]).to("cuda") for _ in range(world_size)]
    dist.all_gather(size_list, local_size)
    size_list = [int(size.item()) for size in size_list]
    max_size = max(size_list)

    tensor_list = []
    for _ in size_list:
        tensor_list.append(torch.ByteTensor(size=(max_size,)).to("cuda"))
    if local_size != max_size:
        padding = torch.ByteTensor(size=(max_size - local_size,)).to("cuda")
        tensor = torch.cat((tensor, padding), dim=0)
    dist.all_gather(tensor_list, tensor)

    data_list = []
    for size, tensor in zip(size_list, tensor_list):
        buffer = tensor.cpu().numpy().tobytes()[:size]
        data_list.append(pickle.loads(buffer))

    return data_list

Run all_gather on arbitrary picklable data (not necessarily tensors)
Args:
data: any picklable object
Returns:
list[data]: list of data gathered from each rank


def clean_tag(name):
    if name is not None:
        new_name = _INVALID_TAG_CHARACTERS.sub('_', name)
        new_name = new_name.lstrip('/')
        if new_name != name:
            tf_logging.info('Summary name %s is illegal; using %s instead.' % (name, new_name))
            name = new_name
    return name

Cleans a tag. Removes illegal characters for instance.

Args:
name: The original tag name to be processed.

Returns:
The cleaned tag name.


def downsample_bottleneck(x, output_channels, dim='2d', stride=1, scope='h'):

  conv = CONFIG[dim]['conv']
  with tf.variable_scope(scope):
    x = conv(x, output_channels, 1, strides=stride, padding='SAME',
             activation=None)
    return x

Downsamples 'x' by `stride` using a 1x1 convolution filter.

Args:
x: input tensor of size [N, H, W, C]
output_channels: Desired number of output channels.
dim: '2d' if 2-dimensional, '3d' if 3-dimensional.
stride: What stride to use. Usually 1 or 2.
scope: Optional variable scope.

Returns:
A downsampled tensor of size [N, H/2, W/2, output_channels] if stride
is 2, else returns a tensor of size [N, H, W, output_channels] if
stride is 1.


def get_axfr_records(self, server, domains):
    zones = []
    for zoneName in domains:
        try:
            zone = {'zone_id': get_resource_id('axfrz', zoneName), 'name': zoneName, 'source': 'AXFR', 'comment': None, 'tags': {}, 'records': []}
            z = dns_zone.from_xfr(query.xfr(server, zoneName))
            rdata_fields = ('name', 'ttl', 'rdata')
            for rr in [dict(zip(rdata_fields, x)) for x in z.iterate_rdatas()]:
                record_name = rr['name'].derelativize(z.origin).to_text()
                zone['records'].append({'id': get_resource_id('axfrr', record_name, ['{}={}'.format(k, str(v)) for (k, v) in rr.items()]), 'zone_id': zone['zone_id'], 'name': record_name, 'value': sorted([rr['rdata'].to_text()]), 'type': type_to_text(rr['rdata'].rdtype)})
            if (len(zone['records']) > 0):
                zones.append(zone)
        except Exception as ex:
            self.log.exception('Failed fetching DNS zone information for {}: {}'.format(zoneName, ex))
            raise
    return zones

Return a `list` of `dict`s containing the zones and their records, obtained from the DNS server

Returns:
:obj:`list` of `dict`


def set_lacp_timeout(self, name, value=None):

        commands = ['interface %s' % name]
        string = 'port-channel lacp fallback timeout'
        commands.append(self.command_builder(string, value=value))
        return self.configure(commands)

Configures the Port-Channel LACP fallback timeout
The fallback timeout configures the period an interface in
fallback mode remains in LACP mode without receiving a PDU.

Args:
name(str): The Port-Channel interface name

value(int): port-channel lacp fallback timeout in seconds

Returns:
True if the operation succeeds otherwise False is returned


def download_and_extract(path, url, input_filename, target_filename):

  logging.info('Downloading and extracting data to: %s' % path)

  input_file = find_file(path, input_filename)
  target_file = find_file(path, target_filename)
  if input_file and target_file:
    logging.info("Already downloaded and extracted %s." % url)
    return input_file, target_file

  compressed_file = download_from_url(path, url)

  logging.info("Extracting %s." % compressed_file)
  with tarfile.open(compressed_file, "r:gz") as corpus_tar:
    corpus_tar.extractall(path)

  input_file = find_file(path, input_filename)
  target_file = find_file(path, target_filename)

  if input_file and target_file:
    return input_file, target_file

  raise OSError("Download/extraction failed for url %s to path %s" %
                (url, path))

Extract files from downloaded compressed archive file.

Args:
path: string directory where the files will be downloaded
url: url containing the compressed input and target files
input_filename: name of file containing data in source language
target_filename: name of file containing data in target language

Returns:
Full paths to extracted input and target files.

Raises:
OSError: if the the download/extraction fails.


def Recv(self):
    size = struct.unpack(_STRUCT_FMT, self._ReadN(_STRUCT_LEN))[0]
    if (size > MAX_SIZE):
        raise ProtocolError(('Expected size to be at most %d, got %d' % (MAX_SIZE, size)))
    with self._read_lock:
        buf = self._ReadN(size)
        self._ReadMagic()
    res = common_pb2.Message()
    res.ParseFromString(buf)
    return (res, len(buf))

Accept a message from Fleetspeak.

Returns:
A tuple (common_pb2.Message, size of the message in bytes).
Raises:
ProtocolError: If we receive unexpected data from Fleetspeak.


def as_decimal(self) -> decimal.Decimal:
    if len(self._messages) != 1:
        raise ValueError('FHIRPath did not evaluate to a single decimal.')
    return decimal.Decimal(proto_utils.get_value_at_field(self._messages[0], 'value'))

Returns the result as a decimal.

Raises:
ValueError if the `EvaluationResult` is not a single decimal.


def get_max_instability(self, min_voltage=None, max_voltage=None):

        data = []
        for pair in self._select_in_voltage_range(min_voltage, max_voltage):
            if pair.decomp_e_charge is not None:
                data.append(pair.decomp_e_charge)
            if pair.decomp_e_discharge is not None:
                data.append(pair.decomp_e_discharge)
        return max(data) if len(data) > 0 else None

The maximum instability along a path for a specific voltage range.

Args:
min_voltage: The minimum allowable voltage.
max_voltage: The maximum allowable voltage.

Returns:
Maximum decomposition energy of all compounds along the insertion
path (a subset of the path can be chosen by the optional arguments)


def get_signature_request_list(self, page=1, ux_version=None):
    request = self._get_request()
    parameters = {'page': page}
    if (ux_version is not None):
        parameters['ux_version'] = ux_version
    return request.get(self.SIGNATURE_REQUEST_LIST_URL, parameters=parameters)

Get a list of SignatureRequest that you can access

This includes SignatureRequests you have sent as well as received, but
not ones that you have been CCed on.

Args:

page (int, optional):   Which page number of the SignatureRequest list to return. Defaults to 1.

ux_version (int):       UX version, either 1 (default) or 2.

Returns:
A ResourceList object


def split_result_of_axis_func_pandas(axis, num_splits, result, length_list=None):
    if (num_splits == 1):
        return result
    if (length_list is not None):
        length_list.insert(0, 0)
        sums = np.cumsum(length_list)
        if (axis == 0):
            return [result.iloc[sums[i]:sums[(i + 1)]] for i in range((len(sums) - 1))]
        else:
            return [result.iloc[(:, sums[i]:sums[(i + 1)])] for i in range((len(sums) - 1))]
    chunksize = compute_chunksize(result, num_splits, axis=axis)
    if (axis == 0):
        return [result.iloc[(chunksize * i):(chunksize * (i + 1))] for i in range(num_splits)]
    else:
        return [result.iloc[(:, (chunksize * i):(chunksize * (i + 1)))] for i in range(num_splits)]

Split the Pandas result evenly based on the provided number of splits.

Args:
axis: The axis to split across.
num_splits: The number of even splits to create.
result: The result of the computation. This should be a Pandas
DataFrame.
length_list: The list of lengths to split this DataFrame into. This is used to
return the DataFrame to its original partitioning schema.

Returns:
A list of Pandas DataFrames.


def GetPlatformRestrictions(campaign_feed):

  platform_restrictions = None

  if campaign_feed['matchingFunction']['operator'] == 'AND':
    for argument in campaign_feed['matchingFunction']['lhsOperand']:

      if argument['value']['operator'] == 'EQUALS':
        request_context_operand = argument['value']['lhsOperand'][0]

        if (request_context_operand and
            request_context_operand == 'DEVICE_PLATFORM'):

          platform_restrictions = argument['value']['rhsOperand'][0].upper()

  return platform_restrictions

Get the Platform Restrictions for a given Campaign Feed.

Args:
campaign_feed: the Campaign Feed we are retrieving Platform Restrictons for.

Returns:
The Platform Restrictions for the given feed.


def save_model_secs(self):
    return self._save_model_secs

Return the delay between checkpoints.

Returns:
A timestamp.


def transform(self, X):
    for (i, col) in enumerate(X.columns):
        X_col = self._transform_col(X[col], i)
        if (X_col is not None):
            if (i == 0):
                X_new = X_col
            else:
                X_new = sparse.hstack((X_new, X_col))
        logger.debug('{} --> {} features'.format(col, self.label_encoder.label_maxes[i]))
    return X_new

Encode categorical columns into sparse matrix with one-hot-encoding.

Args:
X (pandas.DataFrame): categorical columns to encode

Returns:
X_new (scipy.sparse.coo_matrix): sparse matrix encoding categorical
variables into dummy variables


def _percent_match(result, out, yP=None, *argl):
    if (len(argl) > 1):
        if (yP is None):
            Xt = argl[1]
            key = id(Xt)
            if (key in _splits):
                yP = _splits[key][3]
        if (yP is not None):
            import math
            out['%'] = round((1.0 - (sum(abs((yP - result))) / float(len(result)))), 3)

Returns the percent match for the specified prediction call; requires
that the data was split before using an analyzed method.

Args:
out (dict): output dictionary to save the result to.


def __init__(self, num_input_pipelines=1, input_pipeline_id=0, num_replicas_in_sync=1):
    self._num_input_pipelines = num_input_pipelines
    self._input_pipeline_id = input_pipeline_id
    self._num_replicas_in_sync = num_replicas_in_sync

Initializes an InputContext object.

Args:
num_input_pipelines: the number of input pipelines in a cluster.
input_pipeline_id: the current input pipeline id, should be an int in
[0,`num_input_pipelines`).
num_replicas_in_sync: the number of replicas that are in sync.


def create_centerlines(src, dst, density=0.5):
    try:
        DST_DRIVER = get_ogr_driver(filepath=dst)
    except ValueError:
        raise
    with fiona.Env():
        with fiona.open(src, mode='r') as source:
            SCHEMA = source.schema.copy()
            SCHEMA.update({'geometry': 'MultiLineString'})
            with fiona.open(dst, mode='w', driver=DST_DRIVER.GetName(), schema=SCHEMA, crs=source.crs, encoding=source.encoding) as destination:
                for record in source:
                    geom = record.get('geometry')
                    input_geom = shape(geom)
                    if (not is_valid_geometry(geometry=input_geom)):
                        continue
                    attributes = record.get('properties')
                    try:
                        centerline_obj = Centerline(input_geom=input_geom, interpolation_dist=density, **attributes)
                    except RuntimeError as err:
                        logging.warning('ignoring record that could not be processed: %s', err)
                        continue
                    centerline_dict = {'geometry': mapping(centerline_obj), 'properties': {k: v for (k, v) in centerline_obj.__dict__.items() if (k in attributes.keys())}}
                    destination.write(centerline_dict)
    return None

Create centerlines and save the to an ESRI Shapefile.

Reads polygons from the `src` ESRI Shapefile, creates Centerline
objects with the specified `density` parameter and writes them to
the `dst` ESRI Shapefile.

Only Polygon features are converted to centerlines. Features of
different types are skipped.

Args:
src (str): source ESRI Shapefile
dst (str): destination ESRI Shapefile
density (:obj:`float`, optional): the Centerline's density.
Defaults to 0.5 (meters)

Returns:
None


def ReadFromPath(filepath):

  with io.open(filepath, mode="r", encoding="utf-8") as filedesc:
    return ReadFromFile(filedesc)

Reads a Python object stored in a specified YAML file.

Args:
filepath: A filepath to the YAML file.

Returns:
A Python data structure corresponding to the YAML in the given file.


def __init__(self, session, run_with_hooks_fn):
    self._session = session
    self._run_with_hooks_fn = run_with_hooks_fn

Initializes the `step_context` argument for a `step_fn` invocation.

Args:
session: An instance of `tf.compat.v1.Session`.
run_with_hooks_fn: A function for running fetches and hooks.


def _update_trial_queue(self, blocking=False, timeout=600):

        trials = self._search_alg.next_trials()
        if blocking and not trials:
            start = time.time()

            while (not trials and not self.is_finished()
                   and time.time() - start < timeout):
                logger.info("Blocking for next trial...")
                trials = self._search_alg.next_trials()
                time.sleep(1)

        for trial in trials:
            self.add_trial(trial)

Adds next trials to queue if possible.

Note that the timeout is currently unexposed to the user.

Args:
blocking (bool): Blocks until either a trial is available
or is_finished (timeout or search algorithm finishes).
timeout (int): Seconds before blocking times out.


def constant(duration: int, amp: complex, name: str=None) -> SamplePulse:
    return _sampled_constant_pulse(duration, amp, name=name)

Generates constant-sampled `SamplePulse`.

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

Args:
duration: Duration of pulse. Must be greater than zero.
amp: Complex pulse amplitude.
name: Name of pulse.


def aligned_8k_grouped():
    hparams = aligned_grouped()
    hparams.batch_size = 8192
    hparams.num_groups = 16
    hparams.multiplicative_overhead = 1.1
    return hparams

version for languagemodel_wiki_scramble8k50.

languagemodel_wiki_scramble1k50, 1gpu, 7k steps: log(ppl)_eval = 2.92
3.3 steps/sec on P100
8gpu (8x batch), 7k steps: log(ppl)_eval = 2.15

Returns:
a hparams object


Called at the beginning of evaluation or validation.

Subclasses should override for any actions to run.

Args:
logs: Dict. Currently no data is passed to this argument for this method
but that may change in the future.


def _InferAndVerify(self, src, pythonpath, module_name, report_errors, analyze_annotated, imports_map=None, quick=False, **kwargs):
    self.ConfigureOptions(module_name=module_name, quick=quick, use_pickled_files=True, analyze_annotated=analyze_annotated, **self._GetPythonpathArgs(pythonpath, imports_map))
    if test_utils.ErrorMatcher(src).expected:
        self.fail('Cannot assert errors with Infer(); use InferWithErrors()')
    ret = self.analyze_lib.infer_types(src, options=self.options, loader=self.loader, **kwargs)
    errorlog = ret.context.errorlog
    unit = ret.ast
    assert unit is not None
    unit.Visit(visitors.VerifyVisitor())
    if report_errors and errorlog:
        errorlog.print_to_stderr()
        self.fail(f'Inferencer found {len(errorlog)} errors:\n{errorlog}')
    return (unit, ret.ast_deps)

Infer types for the source code treating it as a module.

Used by Infer().

Args:
src: The source code of a module. Treat it as "__main__".
pythonpath: --pythonpath as list/tuple of string
module_name: Name of the module we're analyzing. E.g. "foo.bar.mymodule".
report_errors: Whether to fail if the type inferencer reports any errors
in the program.
analyze_annotated: Whether to analyze functions with return annotations.
imports_map: --imports_info data
quick: Try to run faster, by avoiding costly computations.
**kwargs: Keyword parameters to pass through to the type inferencer.

Raises:
AssertionError: If report_errors is True and we found errors.
Returns:
A pytd.TypeDeclUnit


class Wav2Vec2Processor(ProcessorMixin):
    feature_extractor_class = 'Wav2Vec2FeatureExtractor'
    tokenizer_class = 'AutoTokenizer'

    def __init__(self, feature_extractor, tokenizer):
        super().__init__(feature_extractor, tokenizer)
        self.current_processor = self.feature_extractor
        self._in_target_context_manager = False

    @classmethod
    def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
        try:
            return super().from_pretrained(pretrained_model_name_or_path, **kwargs)
        except (OSError, ValueError):
            warnings.warn(f"Loading a tokenizer inside {cls.__name__} from a config that does not include a `tokenizer_class` attribute is deprecated and will be removed in v5. Please add `'tokenizer_class': 'Wav2Vec2CTCTokenizer'` attribute to either your `config.json` or `tokenizer_config.json` file to suppress this warning: ", FutureWarning)
            feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(pretrained_model_name_or_path, **kwargs)
            tokenizer = Wav2Vec2CTCTokenizer.from_pretrained(pretrained_model_name_or_path, **kwargs)
            return cls(feature_extractor=feature_extractor, tokenizer=tokenizer)

    def __call__(self, audio: AudioInput=None, text: Optional[Union[str, List[str], TextInput, PreTokenizedInput]]=None, images=None, videos=None, **kwargs: Unpack[Wav2Vec2ProcessorKwargs]):

        if 'raw_speech' in kwargs:
            warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.')
            audio = kwargs.pop('raw_speech')
        if audio is None and text is None:
            raise ValueError('You need to specify either an `audio` or `text` input to process.')
        output_kwargs = self._merge_kwargs(Wav2Vec2ProcessorKwargs, tokenizer_init_kwargs=self.tokenizer.init_kwargs, **kwargs)
        if self._in_target_context_manager:
            return self.current_processor(audio, **output_kwargs['audio_kwargs'], **output_kwargs['text_kwargs'], **output_kwargs['common_kwargs'])
        if audio is not None:
            inputs = self.feature_extractor(audio, **output_kwargs['audio_kwargs'])
        if text is not None:
            encodings = self.tokenizer(text, **output_kwargs['text_kwargs'])
        if text is None:
            return inputs
        elif audio is None:
            return encodings
        else:
            inputs['labels'] = encodings['input_ids']
            return inputs

    def pad(self, *args, **kwargs):

        if self._in_target_context_manager:
            return self.current_processor.pad(*args, **kwargs)
        input_features = kwargs.pop('input_features', None)
        labels = kwargs.pop('labels', None)
        if len(args) > 0:
            input_features = args[0]
            args = args[1:]
        if input_features is not None:
            input_features = self.feature_extractor.pad(input_features, *args, **kwargs)
        if labels is not None:
            labels = self.tokenizer.pad(labels, **kwargs)
        if labels is None:
            return input_features
        elif input_features is None:
            return labels
        else:
            input_features['labels'] = labels['input_ids']
            return input_features

    def batch_decode(self, *args, **kwargs):

        return self.tokenizer.batch_decode(*args, **kwargs)

    def decode(self, *args, **kwargs):

        return self.tokenizer.decode(*args, **kwargs)

    @contextmanager
    def as_target_processor(self):

        warnings.warn('`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your labels by using the argument `text` of the regular `__call__` method (either in the same call as your audio inputs, or in a separate call.')
        self._in_target_context_manager = True
        self.current_processor = self.tokenizer
        yield
        self.current_processor = self.feature_extractor
        self._in_target_context_manager = False

Constructs a Wav2Vec2 processor which wraps a Wav2Vec2 feature extractor and a Wav2Vec2 CTC tokenizer into a single
processor.

[`Wav2Vec2Processor`] offers all the functionalities of [`Wav2Vec2FeatureExtractor`] and [`PreTrainedTokenizer`].
See the docstring of [`~Wav2Vec2Processor.__call__`] and [`~Wav2Vec2Processor.decode`] for more information.

Args:
feature_extractor (`Wav2Vec2FeatureExtractor`):
An instance of [`Wav2Vec2FeatureExtractor`]. The feature extractor is a required input.
tokenizer ([`PreTrainedTokenizer`]):
An instance of [`PreTrainedTokenizer`]. The tokenizer is a required input.


def double_sha256(ba):

    d1 = hashlib.sha256(ba)
    d2 = hashlib.sha256()
    d1.hexdigest()
    d2.update(d1.digest())
    return d2.hexdigest()

Perform two SHA256 operations on the input.

Args:
ba (bytes): data to hash.

Returns:
str: hash as a double digit hex string.


def __security_definitions_descriptor(self, issuers):

    if not issuers:
      result = {
          _DEFAULT_SECURITY_DEFINITION: {
              'authorizationUrl': '',
              'flow': 'implicit',
              'type': 'oauth2',
              'x-google-issuer': 'https:
              'x-google-jwks_uri': 'https:
          }
      }
      return result

    result = {}

    for issuer_key, issuer_value in issuers.items():
      result[issuer_key] = {
          'authorizationUrl': '',
          'flow': 'implicit',
          'type': 'oauth2',
          'x-google-issuer': issuer_value.issuer,
      }

      if issuer_value.jwks_uri:
        result[issuer_key]['x-google-jwks_uri'] = issuer_value.jwks_uri

    return result

Create a descriptor for the security definitions.

Args:
issuers: dict, mapping issuer names to Issuer tuples

Returns:
The dict representing the security definitions descriptor.


def sort_all_auto_mappings(overwrite: bool=False):
    fnames = [os.path.join(PATH_TO_AUTO_MODULE, f) for f in os.listdir(PATH_TO_AUTO_MODULE) if f.endswith('.py')]
    diffs = [sort_auto_mapping(fname, overwrite=overwrite) for fname in fnames]
    if not overwrite and any(diffs):
        failures = [f for f, d in zip(fnames, diffs) if d]
        raise ValueError(f'The following files have auto mappings that need sorting: {', '.join(failures)}. Run `make style` to fix this.')

Sort all auto mappings in the library.

Args:
overwrite (`bool`, *optional*, defaults to `False`): Whether or not to fix and overwrite the file.


class PatchTSMixerForPredictionOutput(ModelOutput):
    loss: Optional[torch.FloatTensor] = None
    prediction_outputs: Optional[torch.FloatTensor] = None
    last_hidden_state: Optional[torch.FloatTensor] = None
    hidden_states: Optional[Tuple[torch.FloatTensor]] = None
    loc: Optional[torch.FloatTensor] = None
    scale: Optional[torch.FloatTensor] = None

Output type of [`PatchTSMixerForPredictionOutput`].

Args:
prediction_outputs (`torch.FloatTensor` of shape `(batch_size, prediction_length, num_input_channels)`):
Prediction output from the forecast head.
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_input_channels, num_patches, d_model)`):
Backbone embeddings before passing through the head.
hidden_states (`tuple(torch.FloatTensor)`, *optional*):
Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
loss (*optional*, returned when `y` is provided, `torch.FloatTensor` of shape `()`):
Total loss.
loc (`torch.FloatTensor`, *optional* of shape `(batch_size, 1, num_input_channels)`):
Input mean
scale (`torch.FloatTensor`, *optional* of shape `(batch_size, 1, num_input_channels)`):
Input std dev


def truncate_table_rows(self, table_content: Dict, question: str, answer: Optional[Union[str, List[str]]]=None, max_length=None):
    delete_ratio, remain_token_len = self.estimate_delete_ratio(table_content, question, max_length)
    self.delete_unrelated_rows(table_content, question, answer, delete_ratio)
    maximum_keep_rows = 0
    for ind, row_example in enumerate(table_content['rows']):
        value_string = self.table_linearize.process_row(row_example, ind + 1)
        value_token_len = len(self.tokenize(value_string))
        if value_token_len > remain_token_len:
            break
        remain_token_len -= value_token_len
        maximum_keep_rows += 1
    del table_content['rows'][maximum_keep_rows:]

Args:
table_content:
{"header": xxx, "rows": xxx, "id" (Optionally): xxx}

question:
natural language sentence

answer:
if for training, is the supervision; otherwise will be empty


def GenerateLabels(self, hash_information):

    if not hash_information:
      return ['viper_not_present']

    projects = []
    tags = []
    for project, entries in iter(hash_information.items()):
      if not entries:
        continue

      projects.append(project)

      for entry in entries:
        if entry['tags']:
          tags.extend(entry['tags'])

    if not projects:
      return ['viper_not_present']
    strings = ['viper_present']

    for project_name in projects:
      label = events.EventTag.CopyTextToLabel(
          project_name, prefix='viper_project_')
      strings.append(label)

    for tag_name in tags:
      label = events.EventTag.CopyTextToLabel(tag_name, prefix='viper_tag_')
      strings.append(label)

    return strings

Generates a list of strings that will be used in the event tag.

Args:
hash_information (dict[str, object]): JSON decoded contents of the result
of a Viper lookup, as produced by the ViperAnalyzer.

Returns:
list[str]: list of labels to apply to events.


def load_model(itos_filename, classifier_filename, num_classes):

    itos = pickle.load(Path(itos_filename).open('rb'))

    stoi = collections.defaultdict(lambda:0, {str(v):int(k) for k,v in enumerate(itos)})

    bptt,em_sz,nh,nl = 70,400,1150,3
    dps = np.array([0.4,0.5,0.05,0.3,0.4])*0.5
    vs = len(itos)

    model = get_rnn_classifer(bptt, 20*70, num_classes, vs, emb_sz=em_sz, n_hid=nh, n_layers=nl, pad_token=1,
            layers=[em_sz*3, 50, num_classes], drops=[dps[4], 0.1],
            dropouti=dps[0], wdrop=dps[1], dropoute=dps[2], dropouth=dps[3])

    model.load_state_dict(torch.load(classifier_filename, map_location=lambda storage, loc: storage))

    model.reset()
    model.eval()

    return stoi, model

Load the classifier and int to string mapping

Args:
itos_filename (str): The filename of the int to string mapping file (usually called itos.pkl)
classifier_filename (str): The filename of the trained classifier

Returns:
string to int mapping, trained classifer model


def mark_as_done(self, **kwargs):

        path = '%s/%s/mark_as_done' % (self.manager.path, self.id)
        server_data = self.manager.gitlab.http_post(path, **kwargs)
        self._update_attrs(server_data)

Mark the todo as done.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabTodoError: If the server failed to perform the request


def HandleGetDataMessageReceived(self, payload):

        inventory = IOHelper.AsSerializableWithType(payload, 'neo.Network.Payloads.InvPayload.InvPayload')
        if not inventory:
            return

        for hash in inventory.Hashes:
            hash = hash.encode('utf-8')

            item = None

            if hash in self.leader.RelayCache.keys():
                item = self.leader.RelayCache[hash]

            if inventory.Type == InventoryType.TXInt:
                if not item:
                    item, index = BC.Default().GetTransaction(hash)
                if not item:
                    item = self.leader.GetTransaction(hash)
                if item:
                    message = Message(command='tx', payload=item, print_payload=False)
                    self.SendSerializedMessage(message)

            elif inventory.Type == InventoryType.BlockInt:
                if not item:
                    item = BC.Default().GetBlock(hash)
                if item:
                    message = Message(command='block', payload=item, print_payload=False)
                    self.SendSerializedMessage(message)

            elif inventory.Type == InventoryType.ConsensusInt:
                if item:
                    self.SendSerializedMessage(Message(command='consensus', payload=item, print_payload=False))

Process a InvPayload payload.

Args:
payload (neo.Network.Inventory):


def line_plot(df, xypairs, mode, layout={}, config=_BASE_CONFIG):
    if df.empty:
        return {'x': [], 'y': [], 'mode': mode}
    _data = []
    for (x, y) in xypairs:
        if ((x in df.columns) and (y in df.columns)):
            _data.append({'x': df[x].values.tolist(), 'y': df[y].values.tolist(), 'mode': mode})
    return {'data': _data, 'layout': layout, 'config': config}

basic line plot

dataframe to json for a line plot

Args:
df (pandas.DataFrame): input dataframe
xypairs (list): list of tuples containing column names
mode (str): plotly.js mode (e.g. lines)
layout (dict): layout parameters
config (dict): config parameters


def raise_on_errors(errors, level=logging.CRITICAL):

    if errors:
        log.log(level, "\n".join(errors))
        raise CoTError("\n".join(errors))

Raise a CoTError if errors.

Helper function because I had this code block everywhere.

Args:
errors (list): the error errors
level (int, optional): the log level to use.  Defaults to logging.CRITICAL

Raises:
CoTError: if errors is non-empty


def __init__(self, selenium, handles):

        self.selenium = selenium
        self.handles = handles

Create new_browser_window_is_opened object.

Args:
selenium:
(:py:class:`~selenium.webdriver.remote.webdriver.WebDriver`):
Firefox WebDriver object.
handles: (:obj:`list` of str): List of current Firefox window
handles.


def Getvar(self, var, info_cb=DEFAULT_MESSAGE_CALLBACK):

        return self._SimpleCommand(b'getvar', arg=var, info_cb=info_cb)

Returns the given variable's definition.

Args:
var: A variable the bootloader tracks. Use 'all' to get them all.
info_cb: See Download. Usually no messages.

Returns:
Value of var according to the current bootloader.


def getprop(self, prop_name):
    return self.shell(['getprop', prop_name], timeout=DEFAULT_GETPROP_TIMEOUT_SEC).decode('utf-8').strip()

Get a property of the device.

This is a convenience wrapper for "adb shell getprop xxx".

Args:
prop_name: A string that is the name of the property to get.

Returns:
A string that is the value of the property, or None if the property
doesn't exist.


def get_penalty_model(specification):
    for factory in iter_factories():
        try:
            pm = factory(specification)
        except ImpossiblePenaltyModel as e:
            raise e
        except FactoryException:
            continue
        for cache in iter_caches():
            cache(pm)
        return pm
    return None

Retrieve a PenaltyModel from one of the available factories.

Args:
specification (:class:`.Specification`): The specification
for the desired PenaltyModel.

Returns:
:class:`.PenaltyModel`/None: A PenaltyModel as returned by
the highest priority factory, or None if no factory could
produce it.

Raises:
:exc:`ImpossiblePenaltyModel`: If the specification
describes a penalty model that cannot be built by any
factory.


def subset(self, logic, update=False):
    pnames = self.phenotypes
    snames = self.scored_names
    data = self.copy()
    values = []
    phenotypes = logic.phenotypes
    if (len(phenotypes) == 0):
        phenotypes = pnames
    removing = (set(self.phenotypes) - set(phenotypes))
    for k in phenotypes:
        if (k not in pnames):
            raise ValueError('phenotype must exist in defined')
        temp = data.loc[data['phenotype_calls'].apply((lambda x: (x[k] == 1)))].copy()
        if ((len(removing) > 0) and (temp.shape[0] > 0)):
            temp['phenotype_calls'] = temp.apply((lambda x: dict([(k, v) for (k, v) in x['phenotype_calls'].items() if (k not in removing)])), 1)
        values.append(temp)
    data = pd.concat(values)
    for (k, v) in logic.scored_calls.items():
        if (k not in snames):
            raise ValueError('Scored name must exist in defined')
        myfilter = (0 if (v == '-') else 1)
        data = data.loc[data['scored_calls'].apply((lambda x: (x[k] == myfilter)))]
    data.microns_per_pixel = self.microns_per_pixel
    if update:
        data['phenotype_calls'] = data['phenotype_calls'].apply((lambda x: {logic.label: 1}))
    data.fill_phenotype_label(inplace=True)
    data.db = self.db
    return data

subset create a specific phenotype based on a logic,
logic is a 'SubsetLogic' class,
take union of all the phenotypes listed.  If none are listed use all phenotypes.
take the intersection of all the scored calls.

Args:
logic (SubsetLogic): A subsetlogic object to slice on
update (bool): (default False) change the name of the phenotype according to the label in the subset logic

Returns:
CellDataFrame: The CellDataFrame modified.


def compile_state_action_constraints(self, state: Sequence[tf.Tensor], action: Sequence[tf.Tensor]) -> List[TensorFluent]:
    scope = self.transition_scope(state, action)
    constraints = []
    with self.graph.as_default():
        with tf.name_scope('state_action_constraints'):
            for p in self.rddl.domain.constraints:
                fluent = self._compile_expression(p, scope)
                constraints.append(fluent)
            return constraints

Compiles the state-action constraints given current `state` and `action` fluents.

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

Returns:
A list of :obj:`rddl2tf.fluent.TensorFluent`.


def _test_connection(url):

        import redis
        try:
            with _disconnecting(redis.StrictRedis.from_url(url)) as conn:
                conn.ping()
        except redis.connection.ConnectionError as e:
            raise ValidationError(e)

Attempt to connect to redis

Args:
url: string in the form "redis://[:password@]host[:port][/db-number][?option=value]"


def set_estimator_and_feature_spec(self, estimator, feature_spec):
    self.delete('custom_predict_fn')
    self.store('estimator_and_spec', {'estimator': estimator, 'feature_spec': feature_spec})
    self.set_inference_address('estimator')
    if (not self.has_model_name()):
        self.set_model_name('1')
    return self

Sets the model for inference as a TF Estimator.

Instead of using TF Serving to host a model for WIT to query, WIT can
directly use a TF Estimator object as the model to query. In order to
accomplish this, a feature_spec must also be provided to parse the
example protos for input into the estimator.

Args:
estimator: The TF Estimator which will be used for model inference.
feature_spec: The feature_spec object which will be used for example
parsing.

Returns:
self, in order to enabled method chaining.


def console_set_default_foreground(
    con: tcod.console.Console, col: Tuple[int, int, int]
) -> None:

    lib.TCOD_console_set_default_foreground(_console(con), col)

Change the default foreground color for a console.

Args:
con (Console): Any Console instance.
col (Union[Tuple[int, int, int], Sequence[int]]):
An (r, g, b) sequence or Color instance.

.. deprecated:: 8.5
Use :any:`Console.default_fg` instead.


def add_meta_graph(self, meta_graph_def, global_step=None):
    if not isinstance(meta_graph_def, meta_graph_pb2.MetaGraphDef):
        raise TypeError('meta_graph_def must be type MetaGraphDef, saw type: %s' % type(meta_graph_def))
    meta_graph_bytes = meta_graph_def.SerializeToString()
    event = event_pb2.Event(meta_graph_def=meta_graph_bytes)
    self._add_event(event, global_step)

Adds a `MetaGraphDef` to the event file.

The `MetaGraphDef` allows running the given graph via
`saver.import_meta_graph()`.

Args:
meta_graph_def: A `MetaGraphDef` object, often as returned by
`saver.export_meta_graph()`.
global_step: Number. Optional global step counter to record with the
graph.

Raises:
TypeError: If both `meta_graph_def` is not an instance of `MetaGraphDef`.


def find_parents(root, path, names):

    if not root:
        return []

    if not os.path.commonprefix((root, path)):
        log.warning("Path %s not in %s", path, root)
        return []

    dirs = [root] + os.path.relpath(os.path.dirname(path), root).split(os.path.sep)

    while dirs:
        search_dir = os.path.join(*dirs)
        existing = list(filter(os.path.exists, [os.path.join(search_dir, n) for n in names]))
        if existing:
            return existing
        dirs.pop()

    return []

Find files matching the given names relative to the given path.

Args:
path (str): The file path to start searching up from.
names (List[str]): The file/directory names to look for.
root (str): The directory at which to stop recursing upwards.

Note:
The path MUST be within the root.


def _headers(self, name, is_file=False):

        value = self._files[name] if is_file else self._data[name]
        _boundary = self.boundary.encode("utf-8") if isinstance(self.boundary, unicode) else urllib.quote_plus(self.boundary)

        headers = ["--%s" % _boundary]

        if is_file:
            disposition = 'form-data; name="%s"; filename="%s"' % (name, os.path.basename(value))
        else:
            disposition = 'form-data; name="%s"' % name

        headers.append("Content-Disposition: %s" % disposition)

        if is_file:
            file_type = self._file_type(name)
        else:
            file_type = "text/plain; charset=utf-8"

        headers.append("Content-Type: %s" % file_type)

        if is_file:
            headers.append("Content-Length: %i" % self._file_size(name))
        else:
            headers.append("Content-Length: %i" % len(value))

        headers.append("")
        headers.append("")

        return "\r\n".join(headers)

Returns the header of the encoding of this parameter.

Args:
name (str): Field name

Kwargs:
is_file (bool): If true, this is a file field

Returns:
array. Headers


def __setitem__(self, key, value):

        message = "{0} (of type {1}) is not in {2}".format(str(value), type(value), str(self.valid_values[key]))
        assert self.is_valid(value, self.valid_values[key]), message

        if isinstance(value, dict) and len(self)>0 and len(self) == len(self.valid_values):
            for k, v in value.items():
                    self[key].update({k:v})
        else:
            super(Parameter, self).__setitem__(key, value)

overwrites the standard dictionary and checks if value is valid
Args:
key: dictionary key
value: dictionary value


def scatter_drag(x_points: 'Array', y_points: 'Array', *, fig=None, show_eqn=True, options={}):
    params = {'marks': [{'x': x_points, 'y': y_points, 'enable_move': True}, {'colors': [GOLDENROD]}]}
    fig = (options.get('_fig', False) or _create_fig(options=options))
    [scat, lin] = _create_marks(fig=fig, marks=[bq.Scatter, bq.Lines], options=options, params=params)
    _add_marks(fig, [scat, lin])
    equation = widgets.Label()

    def update_line(change=None):
        x_sc = scat.scales['x']
        lin.x = [(x_sc.min if (x_sc.min is not None) else np.min(scat.x)), (x_sc.max if (x_sc.max is not None) else np.max(scat.x))]
        poly = np.polyfit(scat.x, scat.y, deg=1)
        lin.y = np.polyval(poly, lin.x)
        if show_eqn:
            equation.value = 'y = {:.2f}x + {:.2f}'.format(poly[0], poly[1])
    update_line()
    scat.observe(update_line, names=['x', 'y'])
    return widgets.VBox([equation, fig])

Generates an interactive scatter plot with the best fit line plotted over
the points. The points can be dragged by the user and the line will
automatically update.

Args:
x_points (Array Number): x-values of points to plot

y_points (Array Number): y-values of points to plot

Kwargs:
show_eqn (bool): If True (default), displays the best fit line's
equation above the scatterplot.

{options}

Returns:
VBox with two children: the equation widget and the figure.

>>> xs = np.arange(10)
>>> ys = np.arange(10) + np.random.rand(10)
>>> scatter_drag(xs, ys)
VBox(...)


def alleles_to_retrieve(df):

    contig_blastn_records = defaultdict(list)
    markers = df.marker.unique()
    for m in markers:
        dfsub = df[df.marker == m]
        for i, r in dfsub.iterrows():
            if r.coverage < 1.0:
                contig_blastn_records[r.stitle].append(r)
            break
    return contig_blastn_records

Alleles to retrieve from genome fasta

Get a dict of the genome fasta contig title to a list of blastn results of the allele sequences that must be
retrieved from the genome contig.

Args:
df (pandas.DataFrame): blastn results dataframe

Returns:
{str:[pandas.Series]}: dict of contig title (header name) to list of top blastn result records for each marker
for which the allele sequence must be retrieved from the original sequence.


def AddrStrToScriptHash(address):

        data = b58decode(address)
        if len(data) != 25:
            raise ValueError('Not correct Address, wrong length.')
        if data[0] != settings.ADDRESS_VERSION:
            raise ValueError('Not correct Coin Version')

        checksum = Crypto.Default().Hash256(data[:21])[:4]
        if checksum != data[21:]:
            raise Exception('Address format error')
        return UInt160(data=data[1:21])

Convert a public address to a script hash.

Args:
address (str): base 58 check encoded public address.

Raises:
ValueError: if the address length of address version is incorrect.
Exception: if the address checksum fails.

Returns:
UInt160:


def _load_features_from_images(self, images, names=None):

        if names is not None and len(names) != len(images):
            raise Exception(
                "Lists of feature names and images must be of same length!")
        self.feature_names = names if names is not None else images
        self.feature_images = imageutils.load_imgs(images, self.masker)

Load feature image data from image files.

Args:
images: A list of image filenames.
names: An optional list of strings to use as the feature names. Must
be in the same order as the images.


def load_new_checkpoint_when_available(self, sess, current_checkpoint, sleep_seconds=10):
    while True:
        next_checkpoint = self.load_from_checkpoint(sess)
        if ((not next_checkpoint) or (next_checkpoint == current_checkpoint)):
            print(('Model not yet available, sleeping for %d seconds: path %s; found: %s' % (sleep_seconds, os.path.dirname(self._save_path), current_checkpoint)))
            sys.stdout.flush()
            time.sleep(sleep_seconds)
        else:
            return next_checkpoint

Waits for a new checkpoint to be available and then loads it.

Args:
sess: The current session.
current_checkpoint: The current checkpoint or None to just load the next
one.
sleep_seconds: How long to sleep between checks.

Returns:
The next checkpoint to use.


def str2dict_keys(str_in):

    tmp_dict = str2dict(str_in)
    if tmp_dict is None:
        return None
    return sorted([k for k in tmp_dict])

Extracts the keys from a string that represents a dict and returns them
sorted by key.

Args:
str_in (string) that contains python dict
Returns:
(list) with keys or None if no valid dict was found
Raises:
-


def monolayer_vs_BE(self, plot_eads=False):

        plt = pretty_plot(width=8, height=7)
        for hkl in self.all_slab_entries.keys():
            ml_be_dict = {}
            for clean_entry in self.all_slab_entries[hkl].keys():
                if self.all_slab_entries[hkl][clean_entry]:
                    for ads_entry in self.all_slab_entries[hkl][clean_entry]:
                        if ads_entry.get_monolayer not in ml_be_dict.keys():
                            ml_be_dict[ads_entry.get_monolayer] = 1000
                        be = ads_entry.gibbs_binding_energy(eads=plot_eads)
                        if be < ml_be_dict[ads_entry.get_monolayer]:
                            ml_be_dict[ads_entry.get_monolayer] = be

            vals = sorted(ml_be_dict.items())
            monolayers, BEs = zip(*vals)
            plt.plot(monolayers, BEs, '-o',
                     c=self.color_dict[clean_entry], label=hkl)

        adsorbates = tuple(ads_entry.ads_entries_dict.keys())
        plt.xlabel(" %s" * len(adsorbates) % adsorbates + " Coverage (ML)")
        plt.ylabel("Adsorption Energy (eV)") if plot_eads \
            else plt.ylabel("Binding Energy (eV)")
        plt.legend()
        plt.tight_layout()

        return plt

Plots the binding energy energy as a function of monolayers (ML), i.e.
the fractional area adsorbate density for all facets. For each
facet at a specific monlayer, only plot the lowest binding energy.

Args:
plot_eads (bool): Option to plot the adsorption energy (binding
energy multiplied by number of adsorbates) instead.

Returns:
(Plot): Plot of binding energy vs monolayer for all facets.


def save(multiplex_op, path):
    example_cond, example_a, example_b = _get_example_tensors()

    class UseMultiplex(tf.Module):

        @tf.function(input_signature=[tf.TensorSpec.from_tensor(example_cond), tf.TensorSpec.from_tensor(example_a), tf.TensorSpec.from_tensor(example_b)])
        def use_multiplex(self, cond, a, b):
            return multiplex_op(cond, a, b)
    model = UseMultiplex()
    tf.saved_model.save(model, path, signatures=model.use_multiplex.get_concrete_function(tf.TensorSpec.from_tensor(example_cond), tf.TensorSpec.from_tensor(example_a), tf.TensorSpec.from_tensor(example_b)))

Save a model that contains the given `multiplex_op`.

Args:
multiplex_op: A multiplex Custom Op, e.g. multiplex_4_op.multiplex. This is
parameterized so it can also be used to create an "old" model with an
older version of the op, e.g. multiplex_2_op.multiplex.
path: Directory to save model to.


def RowWith(self, column, value):
    for row in self._table[1:]:
        if (row[column] == value):
            return row
    return None

Retrieves the first non header row with the column of the given value.

Args:
column: str, the name of the column to check.
value: str, The value of the column to check.

Returns:
A Row() of the first row found, None otherwise.

Raises:
IndexError: The specified column does not exist.


def __init__(self, name=None, schema='DNS'):

    super(HostnameArtifact, self).__init__()
    self.name = name
    self.schema = schema

Initializes a hostname artifact.

Args:
name (Optional[str]): name of the host according to the naming schema.
schema (Optional[str]): naming schema.


def plot(self, num_pts, color=None, alpha=None, ax=None):
    if (self._dimension != 2):
        raise NotImplementedError('2D is the only supported dimension', 'Current dimension', self._dimension)
    s_vals = np.linspace(0.0, 1.0, num_pts)
    points = self.evaluate_multi(s_vals)
    if (ax is None):
        ax = _plot_helpers.new_axis()
    ax.plot(points[(0, :)], points[(1, :)], color=color, alpha=alpha)
    return ax

Plot the current curve.

Args:
num_pts (int): Number of points to plot.
color (Optional[Tuple[float, float, float]]): Color as RGB profile.
alpha (Optional[float]): The alpha channel for the color.
ax (Optional[matplotlib.artist.Artist]): matplotlib axis object
to add plot to.

Returns:
matplotlib.artist.Artist: The axis containing the plot. This
may be a newly created axis.

Raises:
NotImplementedError: If the curve's dimension is not ``2``.


def validate_request(request):
    if getattr(settings, 'BASICAUTH_DISABLE', False):
        return True
    if ('HTTP_AUTHORIZATION' not in request.META):
        return False
    authorization_header = request.META['HTTP_AUTHORIZATION']
    ret = extract_basicauth(authorization_header)
    if (not ret):
        return False
    (username, password) = ret
    raw_pass = settings.BASICAUTH_USERS.get(username)
    if (raw_pass is None):
        return False
    if (not constant_time_compare(raw_pass, password)):
        return False
    request.META['REMOTE_USER'] = username
    return True

Check an incoming request.

Returns:
- True if authentication passed
- Adding request['REMOTE_USER'] as authenticated username.


def share(self, name, item):
    try:
        if isinstance(item, s_telepath.Aware):
            item.onTeleShare(self, name)
        self.shared[name] = item
    except Exception:
        logger.exception(f'onTeleShare() error for: {name}')

Share an object via the telepath protocol.

Args:
name (str): Name of the shared object
item (object): The object to share over telepath.


def _format_download_uri(etextno, mirror=None, prefer_ascii=False):
    mirror = (mirror or _GUTENBERG_MIRROR)
    if (not _does_mirror_exist(mirror)):
        raise UnknownDownloadUriException('Could not reach Gutenberg mirror "{:s}". Try setting a different mirror (https:
    ascii_first = ('.txt', '-0.txt', '-8.txt')
    utf8_first = ('-0.txt', '-8.txt', '.txt')
    extensions = (ascii_first if prefer_ascii else utf8_first)
    for extension in extensions:
        uri = _format_download_uri_for_extension(etextno, extension, mirror)
        if _does_uri_exist(uri):
            return uri
    raise UnknownDownloadUriException('Failed to find a textual download candidate for {} on {}. Either the book does not exist or it is only available in non-textual formats.'.format(etextno, mirror))

Returns the download location on the Project Gutenberg servers for a
given text.

Use prefer_ascii to control whether you want to fetch plaintext us-ascii
file first (default old behavior) or if you prefer UTF-8 then 8-bits then
plaintext.

Raises:
UnknownDownloadUri: If no download location can be found for the text.


def enhance_pubmed_annotations(pubmed: Mapping[(str, Any)]) -> Mapping[(str, Any)]:
    text = (pubmed['title'] + pubmed['abstract'])
    annotations = {}
    for nsarg in pubmed['annotations']:
        url = f"{config['bel_api']['servers']['api_url']}/terms/{url_path_param_quoting(nsarg)}"
        log.info(f'URL: {url}')
        r = get_url(url)
        log.info(f'Result: {r}')
        new_nsarg = ''
        if (r and (r.status_code == 200)):
            term = r.json()
            new_nsarg = bel_utils.convert_nsarg(term['id'], decanonicalize=True)
            pubmed['annotations'][nsarg]['name'] = term['name']
            pubmed['annotations'][nsarg]['label'] = term['label']
            pubmed['annotations'][nsarg]['entity_types'] = list(set((pubmed['annotations'][nsarg]['entity_types'] + term.get('entity_types', []))))
            pubmed['annotations'][nsarg]['annotation_types'] = list(set((pubmed['annotations'][nsarg]['annotation_types'] + term.get('annotation_types', []))))
        if (new_nsarg != nsarg):
            annotations[new_nsarg] = copy.deepcopy(pubmed['annotations'][nsarg])
        else:
            annotations[nsarg] = copy.deepcopy(pubmed['annotations'][nsarg])
    for nsarg in annotations:
        for (idx, span) in enumerate(annotations[nsarg]['spans']):
            string = text[(span['begin'] - 1):(span['end'] - 1)]
            annotations[nsarg]['spans'][idx]['text'] = string
    pubmed['annotations'] = copy.deepcopy(annotations)
    return pubmed

Enhance pubmed namespace IDs

Add additional entity and annotation types to annotations
Use preferred id for namespaces as needed
Add strings from Title, Abstract matching Pubtator BioConcept spans

NOTE - basically duplicated code with bel_api:api.services.pubmed

Args:
pubmed

Returns:
pubmed object


def op_nodes(self, op=None):
    nodes = []
    for node in self._multi_graph.nodes():
        if (node.type == 'op'):
            if ((op is None) or isinstance(node.op, op)):
                nodes.append(node)
    return nodes

Get the list of "op" nodes in the dag.

Args:
op (Type): Instruction subclass op nodes to return. if op=None, return
all op nodes.
Returns:
list[DAGNode]: the list of node ids containing the given op.


def parseInt(self, words):

        words = words.replace(" and ", " ").lower()

        words = re.sub(r'(\b)a(\b)', '\g<1>one\g<2>', words)

        def textToNumber(s):

            a = re.split(r"[\s-]+", s)
            n = 0
            g = 0
            for w in a:
                x = NumberService.__small__.get(w, None)
                if x is not None:
                    g += x
                elif w == "hundred":
                    g *= 100
                else:
                    x = NumberService.__magnitude__.get(w, None)
                    if x is not None:
                        n += g * x
                        g = 0
                    else:
                        raise NumberService.NumberException(
                            "Unknown number: " + w)
            return n + g

        return textToNumber(words)

Parses words to the integer they describe.

Args:
words (str): Description of the integer.

Returns:
An integer representation of the words.


def md2tvd(self, kind='linear'):
    if (self.position is None):
        return (lambda x: x)
    return interp1d(self.md, self.tvd, kind=kind, assume_sorted=True, fill_value='extrapolate', bounds_error=False)

Provides an transformation and interpolation function that converts
MD to TVD.

Args:
kind (str): The kind of interpolation to do, e.g. 'linear',
'cubic', 'nearest'.

Returns:
function.


def validate_email(self, email):

        user, domain = email.rsplit("@", 1)

        return "@".join([user, domain.lower()])

Validate the provided email address.

Args:
email:
The email address to validate.

Returns:
The provided email address, transformed to match the RFC
spec. Namely, the domain portion of the email must be
lowercase.


def _validate_user_inputs(self, attributes=None, event_tags=None):

    if attributes and not validator.are_attributes_valid(attributes):
      self.logger.error('Provided attributes are in an invalid format.')
      self.error_handler.handle_error(exceptions.InvalidAttributeException(enums.Errors.INVALID_ATTRIBUTE_FORMAT))
      return False

    if event_tags and not validator.are_event_tags_valid(event_tags):
      self.logger.error('Provided event tags are in an invalid format.')
      self.error_handler.handle_error(exceptions.InvalidEventTagException(enums.Errors.INVALID_EVENT_TAG_FORMAT))
      return False

    return True

Helper method to validate user inputs.

Args:
attributes: Dict representing user attributes.
event_tags: Dict representing metadata associated with an event.

Returns:
Boolean True if inputs are valid. False otherwise.


def materialize(self, node=None, bounds=None, callback=None, out_format='TILE_STREAM', **kwargs):

        kwargs.update({
          "node": node,
          "bounds": bounds,
          "callback": callback,
          "out_format": out_format
        })
        return self.rda._materialize(**kwargs)

Materializes images into gbdx user buckets in s3.
Note: This method is only available to RDA based image classes.

Args:
node (str): the node in the graph to materialize
bounds (list): optional bbox for cropping what gets materialized in s3
out_format (str): VECTOR_TILE, VECTOR, TIF, TILE_STREAM
callback (str): a callback url like an `sns://`
Returns:
job_id (str): the job_id of the materialization


def plot_kdes(self, mnemonic, alias=None, uwi_regex=None, return_fig=False):

        wells = self.find_wells_with_curve(mnemonic, alias=alias)
        fig, axs = plt.subplots(len(self), 1, figsize=(10, 1.5*len(self)))

        curves = [w.get_curve(mnemonic, alias=alias) for w in wells]
        all_data = np.hstack(curves)
        all_data = all_data[~np.isnan(all_data)]

        amax = np.percentile(all_data, 99)
        amin = np.percentile(all_data,  1)

        for i, w in enumerate(self):
            c = w.get_curve(mnemonic, alias=alias)

            if uwi_regex is not None:
                label = re.sub(uwi_regex, r'\1', w.uwi)
            else:
                label = w.uwi

            if c is not None:
                axs[i] = c.plot_kde(ax=axs[i], amax=amax, amin=amin, label=label+'-'+str(c.mnemonic))
            else:
                continue

        if return_fig:
            return fig
        else:
            return

Plot KDEs for all curves with the given name.

Args:
menmonic (str): the name of the curve to look for.
alias (dict): a welly alias dictionary.
uwi_regex (str): a regex pattern. Only this part of the UWI will be displayed
on the plot of KDEs.
return_fig (bool): whether to return the matplotlib figure object.

Returns:
None or figure.


def get_current_transport_info(self):
    response = self.avTransport.GetTransportInfo([('InstanceID', 0)])
    playstate = {'current_transport_status': '', 'current_transport_state': '', 'current_transport_speed': ''}
    playstate['current_transport_state'] = response['CurrentTransportState']
    playstate['current_transport_status'] = response['CurrentTransportStatus']
    playstate['current_transport_speed'] = response['CurrentSpeed']
    return playstate

Get the current playback state.

Returns:
dict: The following information about the
speaker's playing state:

*   current_transport_state (``PLAYING``, ``TRANSITIONING``,
``PAUSED_PLAYBACK``, ``STOPPED``)
*   current_transport_status (OK, ?)
*   current_speed(1, ?)

This allows us to know if speaker is playing or not. Don't know other
states of CurrentTransportStatus and CurrentSpeed.


def _write_json_blob(encoded_value, pipeline_id=None):

  default_bucket = app_identity.get_default_gcs_bucket_name()
  if default_bucket is None:
    raise Exception(
      "No default cloud storage bucket has been set for this application. "
      "This app was likely created before v1.9.0, please see: "
      "https:

  path_components = ['/', default_bucket, "appengine_pipeline"]
  if pipeline_id:
    path_components.append(pipeline_id)
  path_components.append(uuid.uuid4().hex)

  file_name = posixpath.join(*path_components)
  with cloudstorage.open(file_name, 'w', content_type='application/json') as f:
    for start_index in xrange(0, len(encoded_value), _MAX_JSON_SIZE):
      end_index = start_index + _MAX_JSON_SIZE
      f.write(encoded_value[start_index:end_index])

  key_str = blobstore.create_gs_key("/gs" + file_name)
  logging.debug("Created blob for filename = %s gs_key = %s", file_name, key_str)
  return blobstore.BlobKey(key_str)

Writes a JSON encoded value to a Cloud Storage File.

This function will store the blob in a GCS file in the default bucket under
the appengine_pipeline directory. Optionally using another directory level
specified by pipeline_id
Args:
encoded_value: The encoded JSON string.
pipeline_id: A pipeline id to segment files in Cloud Storage, if none,
the file will be created under appengine_pipeline

Returns:
The blobstore.BlobKey for the file that was created.


def parse(self, line):

        tree = list(self.parser.raw_parse(line))[0]
        tree = tree[0]
        return tree

Returns tree objects from a sentence

Args:
line: Sentence to be parsed into a tree

Returns:
Tree object representing parsed sentence
None if parse fails


def control_dependency_on_returns(return_value):

    def control_dependency_handle(t):
        if isinstance(t, tensor_array_ops.TensorArray):
            return t.flow
        return t
    if return_value is None:
        return contextlib.contextmanager(lambda: (yield))()
    if not isinstance(return_value, (list, tuple)):
        return_value = (return_value,)
    return_value = tuple((control_dependency_handle(t) for t in return_value))
    return ops.control_dependencies(return_value)

Create a TF control dependency on the return values of a function.

If the function had no return value, a no-op context is returned.

Args:
return_value: The return value to set as control dependency.

Returns:
A context manager.


def pdf(self, resource_id):
    self.resource_id(str(resource_id))
    self._request_uri = '{}/pdf'.format(self._request_uri)

Update the request URI to get the pdf for this resource.

Args:
resource_id (integer): The group id.


def unbatch(self, spec):

    def unbatch_field(f):
        if isinstance(f, type_spec.BatchableTypeSpec):
            return f.__batch_encoder__.unbatch(f)
        elif isinstance(f, tensor_shape.TensorShape):
            return f[1:]
        else:
            return f
    fields = tuple(spec.__dict__.items())
    unbatched_fields = nest.map_structure(unbatch_field, fields)
    return _create_object_from_type_and_dict(type(spec), unbatched_fields)

Returns the TypeSpec for a single unbatched element in `spec`.

The default definition returns a `TypeSpec` that is equal to `spec`, except
that the outermost axis is removed from every nested `TypeSpec`, and
`TensorShape` field.  Subclasses may override this default definition, when
necessary.

Args:
spec: The `TypeSpec` for a batch of values.

Returns:
A `TypeSpec` for an individual value.


def compile(self, prog, features=Features.ALL):

        return LPProg(Parser(Tokenizer(prog, features), features).program(), features)

Currently this compiler simply returns an interpreter instead of compiling
TODO: Write this compiler to increase LPProg run speed and to prevent exceeding maximum recursion depth

Args:
prog (str): A string containing the program.
features (FeatureSet): The set of features to enable during compilation.

Returns:
LPProg