def load_actor_class(self, driver_id, function_descriptor):

        function_id = function_descriptor.function_id

        actor_class = self._loaded_actor_classes.get(function_id, None)
        if actor_class is None:

            if self._worker.load_code_from_local:
                driver_id = ray.DriverID.nil()

                actor_class = self._load_actor_from_local(
                    driver_id, function_descriptor)
            else:

                actor_class = self._load_actor_class_from_gcs(
                    driver_id, function_descriptor)

            self._loaded_actor_classes[function_id] = actor_class

            module_name = function_descriptor.module_name
            actor_class_name = function_descriptor.class_name
            actor_methods = inspect.getmembers(
                actor_class, predicate=is_function_or_method)
            for actor_method_name, actor_method in actor_methods:
                method_descriptor = FunctionDescriptor(
                    module_name, actor_method_name, actor_class_name)
                method_id = method_descriptor.function_id
                executor = self._make_actor_method_executor(
                    actor_method_name,
                    actor_method,
                    actor_imported=True,
                )
                self._function_execution_info[driver_id][method_id] = (
                    FunctionExecutionInfo(
                        function=executor,
                        function_name=actor_method_name,
                        max_calls=0,
                    ))
                self._num_task_executions[driver_id][method_id] = 0
            self._num_task_executions[driver_id][function_id] = 0
        return actor_class

Load the actor class.

Args:
driver_id: Driver ID of the actor.
function_descriptor: Function descriptor of the actor constructor.

Returns:
The actor class.


def _format_field_value(self, field_name) -> str:

        field_name = self._normalize_field_name(field_name)
        field = self._get_model_field(field_name)

        return SQLInsertCompiler.prepare_value(
            self,
            field,

            getattr(self.query.objs[0], field.attname)
        )

Formats a field's value for usage in SQL.

Arguments:
field_name:
The name of the field to format
the value of.

Returns:
The field's value formatted for usage
in SQL.


def to_representation(self, instance):

        updated_program = copy.deepcopy(instance)
        enterprise_customer_catalog = self.context['enterprise_customer_catalog']
        updated_program['enrollment_url'] = enterprise_customer_catalog.get_program_enrollment_url(
            updated_program['uuid']
        )
        for course in updated_program['courses']:
            course['enrollment_url'] = enterprise_customer_catalog.get_course_enrollment_url(course['key'])
            for course_run in course['course_runs']:
                course_run['enrollment_url'] = enterprise_customer_catalog.get_course_run_enrollment_url(
                    course_run['key']
                )
        return updated_program

Return the updated program data dictionary.

Arguments:
instance (dict): The program data.

Returns:
dict: The updated program data.


def bind(self, devices_to_bind):
    if (self.entity_api_key == ''):
        return {'status': 'failure', 'response': 'No API key found in request'}
    url = (self.base_url + 'api/0.1.0/subscribe/bind')
    headers = {'apikey': self.entity_api_key}
    data = {'exchange': 'amq.topic', 'keys': devices_to_bind, 'queue': self.entity_id}
    with self.no_ssl_verification():
        r = requests.post(url, json=data, headers=headers)
    response = dict()
    if ('No API key' in str(r.content.decode('utf-8'))):
        response['status'] = 'failure'
        r = json.loads(r.content.decode('utf-8'))['message']
    elif ('bind queue ok' in str(r.content.decode('utf-8'))):
        response['status'] = 'success'
        r = r.content.decode('utf-8')
    else:
        response['status'] = 'failure'
        r = r.content.decode('utf-8')
    response['response'] = str(r)
    return response

This function allows an entity to list the devices to subscribe for data. This function must be called
at least once, before doing a subscribe. Subscribe function will listen to devices that are bound here.

Args:
devices_to_bind  (list): an array of devices to listen to.
Example bind(["test100","testDemo"])


def add_data(self, data):

        if not self._data:
            self._data = {}
        self._data.update(data)

Add POST data.

Args:
data (dict): key => value dictionary


def tunnel(container, local_port, remote_port=None, gateway_port=None):

    if remote_port is None:
        remote_port = local_port
    if gateway_port is None:
        gateway_port = remote_port

    remote_host = get_ip(container)

    command =  % {
        'key_filename': env.key_filename,
        'local_port': local_port,
        'gateway_port': gateway_port,
        'gateway_user': env.user,
        'gateway_host': env.host,
        'remote_port': remote_port,
        'remote_host': remote_host,
    }

    command = command.replace('\n', '')

    local(command)

Set up an SSH tunnel into the container, using the host as a gateway host.

Args:
* container: Container name or ID
* local_port: Local port
* remote_port=None: Port on the Docker container (defaults to local_port)
* gateway_port=None: Port on the gateway host (defaults to remote_port)


def value(self):
    binary = (UBInt8(self.sub_type).pack() + self.sub_value.pack())
    return BinaryData(binary)

Return sub type and sub value as binary data.

Returns:
:class:`~pyof.foundation.basic_types.BinaryData`:
BinaryData calculated.


def cluster_nodes(self, tol=0.2):

        lattice = self.structure.lattice

        vfcoords = [v.frac_coords for v in self.vnodes]

        dist_matrix = np.array(lattice.get_all_distances(vfcoords, vfcoords))
        dist_matrix = (dist_matrix + dist_matrix.T) / 2
        for i in range(len(dist_matrix)):
            dist_matrix[i, i] = 0
        condensed_m = squareform(dist_matrix)
        z = linkage(condensed_m)
        cn = fcluster(z, tol, criterion="distance")
        merged_vnodes = []
        for n in set(cn):
            poly_indices = set()
            frac_coords = []
            for i, j in enumerate(np.where(cn == n)[0]):
                poly_indices.update(self.vnodes[j].polyhedron_indices)
                if i == 0:
                    frac_coords.append(self.vnodes[j].frac_coords)
                else:
                    fcoords = self.vnodes[j].frac_coords

                    d, image = lattice.get_distance_and_image(frac_coords[0],
                                                              fcoords)
                    frac_coords.append(fcoords + image)
            merged_vnodes.append(
                VoronoiPolyhedron(lattice, np.average(frac_coords, axis=0),
                                  poly_indices, self.coords))
        self.vnodes = merged_vnodes
        logger.debug("%d vertices after combination." % len(self.vnodes))

Cluster nodes that are too close together using a tol.

Args:
tol (float): A distance tolerance. PBC is taken into account.


def _GetFieldPathElementIndex(api_error, field):

  field_path_elements = api_error['fieldPathElements']

  if field_path_elements:
    found_index = [field_path_element['index']
                   for field_path_element in field_path_elements
                   if field_path_element['field'] == field]
    if found_index:
      return found_index

  return None

Retrieve the index of a given field in the api_error's fieldPathElements.

Args:
api_error: a dict containing a partialFailureError returned from the AdWords
API.
field: a str field for which this determines the index in the api_error's
fieldPathElements.

Returns:
An int index of the field path element, or None if the specified field can't
be found in the api_error.


def _GetRecordValue(self, record, value_entry):

    column_type = record.get_column_type(value_entry)
    long_value = None

    if record.is_long_value(value_entry):
      long_value = record.get_value_data_as_long_value(value_entry)

    if record.is_multi_value(value_entry):

      raise ValueError('Multi value support not implemented yet.')

    if column_type == pyesedb.column_types.NULL:
      return None

    if column_type == pyesedb.column_types.BOOLEAN:

      raise ValueError('Boolean value support not implemented yet.')

    if column_type in self.INTEGER_COLUMN_TYPES:
      if long_value:
        raise ValueError('Long integer value not supported.')
      return record.get_value_data_as_integer(value_entry)

    if column_type in self.FLOATING_POINT_COLUMN_TYPES:
      if long_value:
        raise ValueError('Long floating point value not supported.')
      return record.get_value_data_as_floating_point(value_entry)

    if column_type in self.STRING_COLUMN_TYPES:
      if long_value:
        return long_value.get_data_as_string()
      return record.get_value_data_as_string(value_entry)

    if column_type == pyesedb.column_types.GUID:

      raise ValueError('GUID value support not implemented yet.')

    if long_value:
      return long_value.get_data()
    return record.get_value_data(value_entry)

Retrieves a specific value from the record.

Args:
record (pyesedb.record): ESE record.
value_entry (int): value entry.

Returns:
object: value.

Raises:
ValueError: if the value is not supported.


def _emit_op(self, nodestats: step_stats_pb2.NodeExecStats, pid: int, is_gputrace: bool) -> None:
    node_name = nodestats.node_name
    start = nodestats.all_start_micros
    duration = nodestats.all_end_rel_micros
    tid = nodestats.thread_id
    inputs = []
    if is_gputrace:
        node_name, op = self._parse_kernel_label(nodestats.timeline_label, node_name)
    elif node_name == 'RecvTensor':
        op = 'RecvTensor'
    else:
        _, op, inputs = self._parse_op_label(nodestats.timeline_label)
    args = {'name': node_name, 'op': op}
    if build_info.build_info['is_rocm_build']:
        args['kernel'] = nodestats.timeline_label.split('@@')[0]
    for i, iname in enumerate(inputs):
        args['input%d' % i] = iname
    self._chrome_trace.emit_region(start, duration, pid, tid, 'Op', op, args)

Generates a Chrome Trace event to show Op execution.

Args:
nodestats: The 'step_stats_pb2.NodeExecStats' proto recording op
execution.
pid: The pid assigned for the device where this op ran.
is_gputrace: If True then this op came from the GPUTracer.


def coordination_leader(cluster_spec):
    cluster_spec = normalize_cluster_spec(cluster_spec)
    if not cluster_spec.as_dict():
        return ''
    if 'ps' in cluster_spec.jobs:
        return '/job:ps/replica:0/task:0'
    if 'chief' in cluster_spec.jobs:
        return '/job:chief/replica:0/task:0'
    assert 'worker' in cluster_spec.jobs
    return '/job:worker/replica:0/task:0'

Return the task name of the coordination service leader.

Args:
cluster_spec: a dict, `ClusterDef` or `ClusterSpec` object sxpecifying the
cluster configurations.

Returns:
a string indicating the task name of the coordination service leader.


def _init_vocab_from_list(self, vocab_list):

    def token_gen():
      for token in vocab_list:
        if token not in RESERVED_TOKENS:
          yield token

    self._init_vocab(token_gen())

Initialize tokens from a list of tokens.

It is ok if reserved tokens appear in the vocab list. They will be
removed. The set of tokens in vocab_list should be unique.

Args:
vocab_list: A list of tokens.


def switch_to_window(self, window_name):

        data = {
            'name': window_name
        }
        self._execute(Command.SWITCH_TO_WINDOW, data)

Switch to the given window.

Support:
Web(WebView)

Args:
window_name(str): The window to change focus to.

Returns:
WebDriver Object.


def delete_ldap_group_link(self, cn, provider=None, **kwargs):

        path = '/groups/%s/ldap_group_links' % self.get_id()
        if provider is not None:
            path += '/%s' % provider
        path += '/%s' % cn
        self.manager.gitlab.http_delete(path)

Delete an LDAP group link.

Args:
cn (str): CN of the LDAP group
provider (str): LDAP provider for the LDAP group
**kwargs: Extra options to send to the server (e.g. sudo)

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


def detect_unused_return_values(self, f):

        values_returned = []
        nodes_origin = {}
        for n in f.nodes:
            for ir in n.irs:
                if isinstance(ir, HighLevelCall):

                    if ir.lvalue and not isinstance(ir.lvalue, StateVariable):
                        values_returned.append(ir.lvalue)
                        nodes_origin[ir.lvalue] = ir
                for read in ir.read:
                    if read in values_returned:
                        values_returned.remove(read)

        return [nodes_origin[value].node for value in values_returned]

Return the nodes where the return value of a call is unused
Args:
f (Function)
Returns:
list(Node)


def load_parent_implems(self, parent_implems):
    for (trname, attr, implem) in parent_implems.get_custom_implementations():
        self.implementations[trname] = implem.copy()
        self.transitions_at[trname] = attr
        self.custom_implems.add(trname)

Import previously defined implementations.

Args:
parent_implems (ImplementationList): List of implementations defined
in a parent class.


def encode(data, scheme=None, size=None):
    size = (size if size else 'ShapeAuto')
    size_name = '{0}{1}'.format(ENCODING_SIZE_PREFIX, size)
    if (not hasattr(DmtxSymbolSize, size_name)):
        raise PyLibDMTXError('Invalid size [{0}]: should be one of {1}'.format(size, ENCODING_SIZE_NAMES))
    size = getattr(DmtxSymbolSize, size_name)
    scheme = (scheme if scheme else 'Ascii')
    scheme_name = '{0}{1}'.format(ENCODING_SCHEME_PREFIX, scheme.capitalize())
    if (not hasattr(DmtxScheme, scheme_name)):
        raise PyLibDMTXError('Invalid scheme [{0}]: should be one of {1}'.format(scheme, ENCODING_SCHEME_NAMES))
    scheme = getattr(DmtxScheme, scheme_name)
    with _encoder() as encoder:
        dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropScheme, scheme)
        dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropSizeRequest, size)
        if (dmtxEncodeDataMatrix(encoder, len(data), cast(data, c_ubyte_p)) == 0):
            raise PyLibDMTXError('Could not encode data, possibly because the image is not large enough to contain the data')
        (w, h, bpp) = map(partial(dmtxImageGetProp, encoder[0].image), (DmtxProperty.DmtxPropWidth, DmtxProperty.DmtxPropHeight, DmtxProperty.DmtxPropBitsPerPixel))
        size = (((w * h) * bpp)
        pixels = cast(encoder[0].image[0].pxl, ctypes.POINTER((ctypes.c_ubyte * size)))
        return Encoded(width=w, height=h, bpp=bpp, pixels=ctypes.string_at(pixels, size))

Encodes `data` in a DataMatrix image.

For now bpp is the libdmtx default which is 24

Args:
data: bytes instance
scheme: encoding scheme - one of `ENCODING_SCHEME_NAMES`, or `None`.
If `None`, defaults to 'Ascii'.
size: image dimensions - one of `ENCODING_SIZE_NAMES`, or `None`.
If `None`, defaults to 'ShapeAuto'.

Returns:
Encoded: with properties `(width, height, bpp, pixels)`.
You can use that result to build a PIL image:

Image.frombytes('RGB', (width, height), pixels)


def voronoi(points, buffer_percent=100):
    seen = set()
    uniqpoints = [p for p in points if ((str(p[:2]) not in seen) and (not seen.add(str(p[:2]))))]
    classpoints = [_Point(*point[:2]) for point in uniqpoints]
    (xs, ys) = list(zip(*uniqpoints))[:2]
    pointswidth = (max(xs) - min(xs))
    pointsheight = (max(ys) - min(ys))
    (xbuff, ybuff) = (((pointswidth / 100.0) * buffer_percent), ((pointsheight / 100.0) * buffer_percent))
    (midx, midy) = ((sum(xs) / float(len(xs))), (sum(ys) / float(len(ys))))
    bufferbox = [((midx - xbuff), midy), ((midx + xbuff), midy), (midx, (midy + ybuff)), (midx, (midy - ybuff))]
    classpoints.extend([_Point(*corner) for corner in bufferbox])
    (vertices, edges, poly_dict) = tesselator.computeVoronoiDiagram(classpoints)
    polygons = list()
    for (sitepoint, polyedges) in list(poly_dict.items()):
        polyedges = [edge[1:] for edge in polyedges]
        poly = list()
        (firststart, firstend) = polyedges.pop(0)
        poly.append(firstend)
        while polyedges:
            curend = poly[(- 1)]
            for (i, other) in enumerate(polyedges):
                (otherstart, otherend) = other
                if (otherstart == curend):
                    poly.append(otherend)
                    polyedges.pop(i)
                    break
                elif (otherend == curend):
                    poly.append(otherstart)
                    polyedges.pop(i)
                    break
        try:
            sitepoint = uniqpoints[sitepoint]
        except IndexError:
            sitepoint = None
        poly = [vertices[vi] for vi in poly if (vi != (- 1))]
        polygons.append((sitepoint, poly))
    return polygons

Surrounds each point in an input list of xy tuples with a
unique Voronoi polygon.

Arguments:

- **points**: A list of xy or xyz point tuples to triangulate.
- **buffer_percent** (optional): Controls how much bigger than
the original bbox of the input points to set the bbox of fake points,
used to account for lacking values around the edges (default is 100 percent).

Returns:

- Returns a list of 2-tuples, with the first item in each tuple being the
original input point (or None for each corner of the bounding box buffer),
and the second item being the point's corressponding Voronoi polygon.


def repair(self, volume_id_or_uri, timeout=-1):

        data = {
            "type": "ExtraManagedStorageVolumePaths",
            "resourceUri": self._client.build_uri(volume_id_or_uri)
        }
        custom_headers = {'Accept-Language': 'en_US'}
        uri = self.URI + '/repair'
        return self._client.create(data, uri=uri, timeout=timeout, custom_headers=custom_headers)

Removes extra presentations from a specified volume on the storage system.

Args:
volume_id_or_uri:
Can be either the volume id or the volume uri.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation in
OneView, just stops waiting for its completion.

Returns:
dict: Storage volume.


def generate_ast(path):
    if os.path.isfile(path):
        with open(path, 'r') as f:
            try:
                tree = ast.parse(f.read())
                return PytTransformer().visit(tree)
            except SyntaxError:
                global recursive
                if (not recursive):
                    _convert_to_3(path)
                    recursive = True
                    return generate_ast(path)
                else:
                    raise SyntaxError('The ast module can not parse the file and the python 2 to 3 conversion also failed.')
    raise IOError(('Input needs to be a file. Path: ' + path))

Generate an Abstract Syntax Tree using the ast module.

Args:
path(str): The path to the file e.g. example/foo/bar.py


def _should_fetch_reason(self) -> Tuple[(bool, str)]:
    is_redirect = False
    if self._strong_redirects:
        try:
            is_redirect = self._web_client_session.redirect_tracker.is_redirect()
        except AttributeError:
            pass
    return self._fetch_rule.check_subsequent_web_request(self._item_session, is_redirect=is_redirect)

Return info about whether the URL should be fetched.

Returns:
tuple: A two item tuple:

1. bool: If True, the URL should be fetched.
2. str: A short reason string explaining the verdict.


def db_en010(self, value=None):

        if value is not None:
            try:
                value = float(value)
            except ValueError:
                raise ValueError('value {} need to be of type float '
                                 'for field `db_en010`'.format(value))

        self._db_en010 = value

Corresponds to IDD Field `db_en010`
mean coincident dry-bulb temperature to
Enthalpy corresponding to 1.0% annual cumulative frequency of occurrence

Args:
value (float): value for IDD Field `db_en010`
Unit: C
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

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


def iter_processed_text(self, file, encoding=None, base_url=None):

        for text, is_link in self.iter_text(file, encoding):
            if is_link and base_url:
                new_link = urljoin_safe(base_url, text, allow_fragments=False)

                if new_link:
                    yield (new_link, is_link)
                else:
                    yield (new_link, False)
            else:
                yield (text, is_link)

Return the file text and processed absolute links.

Args:
file: A file object containing the document.
encoding (str): The encoding of the document.
base_url (str): The URL at which the document is located.

Returns:
iterator: Each item is a tuple:

1. str: The text
2. bool: Whether the text a link


def _load_plugins(namespace, instantiate=True):
    mgr = ExtensionManager(namespace=namespace, on_load_failure_callback=(lambda _, ep, err: LOGGER.warning('Could not load plugin {}: {}'.format(ep.name, err))))
    if instantiate:
        plugins = dict(((ext.name, (ext.plugin if isinstance(ext.plugin, Plugin) else ext.plugin())) for ext in mgr))
    else:
        plugins = dict(((ext.name, ext.plugin) for ext in mgr))
    return plugins

Loads all the plugins for the given namespace

Args:
namespace(str): Namespace string, as in the setuptools entry_points
instantiate(bool): If true, will instantiate the plugins too

Returns:
dict of str, object: Returns the list of loaded plugins


def master_key_from_seed(seed):
    S = get_bytes(seed)
    I = hmac.new(b'Bitcoin seed', S, hashlib.sha512).digest()
    (Il, Ir) = (I[:32], I[32:])
    parse_Il = int.from_bytes(Il, 'big')
    if ((parse_Il == 0) or (parse_Il >= bitcoin_curve.n)):
        raise ValueError('Bad seed, resulting in invalid key!')
    return HDPrivateKey(key=parse_Il, chain_code=Ir, index=0, depth=0)

Generates a master key from a provided seed.

Args:
seed (bytes or str): a string of bytes or a hex string

Returns:
HDPrivateKey: the master private key.


def _as_document(self, identifier):
    return {'identifier': u('{}').format(identifier['identifier']), 'type': u('{}').format(identifier['type']), 'name': u('{}').format(identifier['name'])}

Converts given identifier to the document indexed by FTS backend.

Args:
identifier (dict): identifier to convert. Dict contains at
least 'identifier', 'type' and 'name' keys.

Returns:
dict with structure matches to BaseIdentifierIndex._schema.


def InitPathInfos(self, client_id, path_infos):
    self.ClearPathHistory(client_id, path_infos)
    self.WritePathInfos(client_id, path_infos)

Initializes a collection of path info records for a client.

Unlike `WritePathInfo`, this method clears stat and hash histories of paths
associated with path info records. This method is intended to be used only
in the data migration scripts.

Args:
client_id: A client identifier for which the paths are to be initialized.
path_infos: A list of `rdf_objects.PathInfo` objects to write.


async def delCronJob(self, iden):
    cron = self.cell.agenda.appts.get(iden)
    if (cron is None):
        raise s_exc.NoSuchIden()
    self._trig_auth_check(cron.useriden)
    (await self.cell.agenda.delete(iden))

Delete a cron job

Args:
iden (bytes):  The iden of the cron job to be deleted


def orient_undirected_graph(self, data, graph):
    self.arguments['{VERBOSE}'] = str(self.verbose).upper()
    self.arguments['{SCORE}'] = self.scores[self.score]
    fe = DataFrame(nx.adj_matrix(graph, weight=None).todense())
    fg = DataFrame((1 - fe.values))
    results = self._run_gies(data, fixedGaps=fg, verbose=self.verbose)
    return nx.relabel_nodes(nx.DiGraph(results), {idx: i for (idx, i) in enumerate(data.columns)})

Run GIES on an undirected graph.

Args:
data (pandas.DataFrame): DataFrame containing the data
graph (networkx.Graph): Skeleton of the graph to orient

Returns:
networkx.DiGraph: Solution given by the GIES algorithm.


def __init__(self, channel):

    self.Ping = channel.unary_unary(
        '/processor.Processor/Ping',
        request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
        response_deserializer=processor__pb2.Status.FromString,
        )
    self.Process = channel.unary_unary(
        '/processor.Processor/Process',
        request_serializer=message__pb2.Message.SerializeToString,
        response_deserializer=message__pb2.Message.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def update_video(video_data):
    try:
        video = _get_video(video_data.get('edx_video_id'))
    except Video.DoesNotExist:
        error_message = u'Video not found when trying to update video with edx_video_id: {0}'.format(video_data.get('edx_video_id'))
        raise ValVideoNotFoundError(error_message)
    serializer = VideoSerializer(video, data=video_data)
    if serializer.is_valid():
        serializer.save()
        return video_data.get('edx_video_id')
    else:
        raise ValCannotUpdateError(serializer.errors)

Called on to update Video objects in the database

update_video is used to update Video objects by the given edx_video_id in the video_data.

Args:
video_data (dict):
{
url: api url to the video
edx_video_id: ID of the video
duration: Length of video in seconds
client_video_id: client ID of video
encoded_video: a list of EncodedVideo dicts
url: url of the video
file_size: size of the video in bytes
profile: ID of the profile
courses: Courses associated with this video
}

Raises:
Raises ValVideoNotFoundError if the video cannot be retrieved.
Raises ValCannotUpdateError if the video cannot be updated.

Returns the successfully updated Video object


def line_on_device(device: 'cirq.google.XmonDevice', length: int, method: LinePlacementStrategy=greedy.GreedySequenceSearchStrategy()) -> GridQubitLineTuple:
    return method.place_line(device, length)

Searches for linear sequence of qubits on device.

Args:
device: Google Xmon device instance.
length: Desired number of qubits making up the line.
method: Line placement method. Defaults to
cirq.greedy.GreedySequenceSearchMethod.

Returns:
Line sequences search results.


def update(self, value: int, force_update: bool=False, comment: Optional[str]=None):
    self.value = value
    if comment is not None:
        self.comment = comment
    if self.last_value is None:
        self.start_time = self.last_time = time.time()
        self.start_value = self.last_value = value
        self.elapsed_time = self.predicted_remaining = None
        self.first_calls = self.warmup
        self.wait_for = 1
        self.update_bar(value)
    elif value <= self.last_value and (not force_update):
        return
    elif force_update or self.first_calls > 0 or value >= min(self.last_value + self.wait_for, self.total):
        if self.first_calls > 0:
            self.first_calls -= 1
        current_time = time.time()
        self.elapsed_time = current_time - self.start_time
        if value > self.start_value:
            self.average_time_per_item = self.elapsed_time / (value - self.start_value)
        else:
            self.average_time_per_item = None
        if value >= self.total:
            value = self.total
            self.predicted_remaining = None
            if not self.leave:
                self.close()
        elif self.average_time_per_item is not None:
            self.predicted_remaining = self.average_time_per_item * (self.total - value)
        self.update_bar(value)
        self.last_value = value
        self.last_time = current_time
        if self.average_time_per_item is None or self.average_time_per_item == 0:
            self.wait_for = 1
        else:
            self.wait_for = max(int(self.update_every / self.average_time_per_item), 1)

The main method to update the progress bar to `value`.

Args:
value (`int`):
The value to use. Must be between 0 and `total`.
force_update (`bool`, *optional*, defaults to `False`):
Whether or not to force and update of the internal state and display (by default, the bar will wait for
`value` to reach the value it predicted corresponds to a time of more than the `update_every` attribute
since the last update to avoid adding boilerplate).
comment (`str`, *optional*):
A comment to add on the left of the progress bar.


def entry_dict_from_list(all_slab_entries):

    entry_dict = {}

    for entry in all_slab_entries:
        hkl = tuple(entry.miller_index)
        if hkl not in entry_dict.keys():
            entry_dict[hkl] = {}
        if entry.clean_entry:
            clean = entry.clean_entry
        else:
            clean = entry
        if clean not in entry_dict[hkl].keys():
            entry_dict[hkl][clean] = []
        if entry.adsorbates:
            entry_dict[hkl][clean].append(entry)

    return entry_dict

Converts a list of SlabEntry to an appropriate dictionary. It is
assumed that if there is no adsorbate, then it is a clean SlabEntry
and that adsorbed SlabEntry has the clean_entry parameter set.

Args:
all_slab_entries (list): List of SlabEntry objects

Returns:
(dict): Dictionary of SlabEntry with the Miller index as the main
key to a dictionary with a clean SlabEntry as the key to a
list of adsorbed SlabEntry.


def calc_timestep_statistic(self, statistic, time):

        ti = np.where(self.times == time)[0][0]
        ma = np.where(self.masks[ti].ravel() == 1)
        if statistic in ['mean', 'max', 'min', 'std', 'ptp']:
            stat_val = getattr(self.timesteps[ti].ravel()[ma], statistic)()
        elif statistic == 'median':
            stat_val = np.median(self.timesteps[ti].ravel()[ma])
        elif 'percentile' in statistic:
            per = int(statistic.split("_")[1])
            stat_val = np.percentile(self.timesteps[ti].ravel()[ma], per)
        elif 'dt' in statistic:
            stat_name = statistic[:-3]
            if ti == 0:
                stat_val = 0
            else:
                stat_val = self.calc_timestep_statistic(stat_name, time) -\
                    self.calc_timestep_statistic(stat_name, time - 1)
        else:
            stat_val = np.nan
        return stat_val

Calculate statistics from the primary attribute of the StObject.

Args:
statistic: statistic being calculated
time: Timestep being investigated

Returns:
Value of the statistic


def remove_trunk_group(self, intf, value):

        string = 'no switchport trunk group {}'.format(value)
        return self.configure_interface(intf, string)

Removes a specified trunk group to the interface

Args:
intf (str): The interface name to remove the trunk group from
value (str): The trunk group value

Returns:
True if the operation as successfully applied otherwise false


def RegisterHasher(cls, hasher_class):

    hasher_name = hasher_class.NAME.lower()
    if hasher_name in cls._hasher_classes:
      raise KeyError((
          'hasher class already set for name: {0:s}.').format(
              hasher_class.NAME))

    cls._hasher_classes[hasher_name] = hasher_class

Registers a hasher class.

The hasher classes are identified based on their lower case name.

Args:
hasher_class (type): class object of the hasher.

Raises:
KeyError: if hasher class is already set for the corresponding name.


def __init__(self, project, throttle_rampup=True, hint_num_workers=_Mutate._DEFAULT_HINT_NUM_WORKERS):
    mutate_fn = DeleteFromDatastore._DatastoreDeleteFn(project)
    super().__init__(mutate_fn, throttle_rampup, hint_num_workers)

Initialize the `DeleteFromDatastore` transform.

Args:
project: (:class:`str`) The ID of the project from which the entities will
be deleted.
throttle_rampup: Whether to enforce a gradual ramp-up.
hint_num_workers: A hint for the expected number of workers, used to
estimate appropriate limits during ramp-up throttling.


def requestedFormat(request, acceptedFormat):
    if ('format' in request.args):
        fieldFormat = request.args.get('format')
        if (fieldFormat not in acceptedFormat):
            raise ValueError(('requested format not supported: ' + fieldFormat))
        return fieldFormat
    else:
        return request.accept_mimetypes.best_match(acceptedFormat)

Return the response format requested by client

Client could specify requested format using:
(options are processed in this order)
- `format` field in http request
- `Accept` header in http request
Example:
chooseFormat(request, ['text/html','application/json'])
Args:
acceptedFormat: list containing all the accepted format
Returns:
string: the user requested mime-type (if supported)
Raises:
ValueError: if user request a mime-type not supported


def create(self, python=None, system_site=False, always_copy=False):
    command = 'virtualenv'
    if python:
        command = '{0} --python={1}'.format(command, python)
    if system_site:
        command = '{0} --system-site-packages'.format(command)
    if always_copy:
        command = '{0} --always-copy'.format(command)
    command = '{0} {1}'.format(command, self.path)
    self._execute(command)

Create a new virtual environment.

Args:
python (str): The name or path of a python interpreter to use while
creating the virtual environment.
system_site (bool): Whether or not use use the system site packages
within the virtual environment. Default is False.
always_copy (bool): Whether or not to force copying instead of
symlinking in the virtual environment. Default is False.


def update_metric_by_name(self, metric_name, metric_type, description=None, custom_properties=None, tags=None, **kwargs):
    data = {'type': metric_type.upper(), 'description': (description or ''), 'customProperties': (custom_properties or {}), 'tags': (tags or [])}
    resp = self._put(self._u(self._METRIC_ENDPOINT_SUFFIX, str(metric_name)), data=data, **kwargs)
    resp.raise_for_status()
    return resp.json()

Create or update a metric object

Args:
metric_name (string): name of metric
type (string): metric type, must be one of 'gauge', 'counter',
'cumulative_counter'
description (optional[string]): a description
custom_properties (optional[dict]): dictionary of custom properties
tags (optional[list of strings]): list of tags associated with
metric


def _print_extension(self, extension: message.Message) -> None:
    if not fhir_types.is_type_or_profile_of_extension(extension):
        raise ValueError(f'Message of type: {extension.DESCRIPTOR.full_name} is not a FHIR Extension.')
    if self.json_format == _FhirJsonFormat.ANALYTIC:
        self.generator.push(f'"{cast(Any, extension).url.value}"')
    else:
        self._print_message(extension)

Pushes the Extension into the JSON text generator.

If the _FhirJsonFormat is set to ANALYTIC, this method only prints the url.

Args:
extension: The Extension to print.


def oauth_required(self, method):

    def check_oauth(request_handler, *args, **kwargs):
        if self._in_error:
            self._display_error_message(request_handler)
            return
        user = users.get_current_user()
        if (not user):
            request_handler.redirect(users.create_login_url(request_handler.request.uri))
            return
        self._create_flow(request_handler)
        self.flow.params['state'] = _build_state_value(request_handler, user)
        self.credentials = self._storage_class(self._credentials_class, None, self._credentials_property_name, user=user).get()
        if (not self.has_credentials()):
            return request_handler.redirect(self.authorize_url())
        try:
            resp = method(request_handler, *args, **kwargs)
        except client.AccessTokenRefreshError:
            return request_handler.redirect(self.authorize_url())
        finally:
            self.credentials = None
        return resp
    return check_oauth

Decorator that starts the OAuth 2.0 dance.

Starts the OAuth dance for the logged in user if they haven't already
granted access for this application.

Args:
method: callable, to be decorated method of a webapp.RequestHandler
instance.


def two_point_effective_mass(cartesian_k_points, eigenvalues):
    assert (cartesian_k_points.shape[0] == 2)
    assert (eigenvalues.size == 2)
    dk = (cartesian_k_points[1] - cartesian_k_points[0])
    mod_dk = np.sqrt(np.dot(dk, dk))
    delta_e = (((eigenvalues[1] - eigenvalues[0]) * ev_to_hartree) * 2.0)
    effective_mass = ((mod_dk * mod_dk) / delta_e)
    return effective_mass

Calculate the effective mass given eigenvalues at two k-points.
Reimplemented from Aron Walsh's original effective mass Fortran code.

Args:
cartesian_k_points (np.array): 2D numpy array containing the k-points in (reciprocal) Cartesian coordinates.
eigenvalues (np.array):        numpy array containing the eigenvalues at each k-point.

Returns:
(float): The effective mass


def is_function_pipelined(self, tf_function, *args):
    attr_name = tpu_embedding_v3._PIPELINE_ATTRIBUTE
    func_graph = tf_function.get_concrete_function(*args).graph
    while_op = None
    for op in func_graph.get_operations():
        if op.name == 'while':
            while_op = op
            break
    self.assertIsNotNone(while_op, 'while op not found')
    body_name = while_op.get_attr('body').name
    while_body_func = None
    try:
        while_body_func = func_graph.get_concrete_function(body_name)
    except AttributeError as exc:
        for func in while_op.graph._functions.values():
            if func.name.decode() == body_name:
                while_body_func = func
                break
        if while_body_func is None:
            raise ValueError('body not found') from exc
    while_body_graph = while_body_func.graph
    attr_value = None
    for op in while_body_graph.get_operations():
        try:
            attr = op.get_attr(attr_name)
            logging.info('Op "%s" has pipelining attr: %s : %s', op.name, attr_name, attr)
            attr_value = attr.decode('utf-8')
            break
        except ValueError:
            pass
    has_pipelining_attr = attr_value in [tpu_embedding_v3._PIPELINE_MODE_FORWARD, tpu_embedding_v3._PIPELINE_MODE_BACKWARD]
    return has_pipelining_attr

Returns whether the tf_function is flagged for embedding pipelining.

Args:
tf_function: a tf.function.
*args: the arguments to the tf_function.

Returns:
Whether the tf_function is (will be) pipelined.

This helper looks for a while loop in the provided function. It then looks
for any op that has the pipelining attribute (e.g.,
XlaSparseDenseMatmulWithCsrInput). The presence of the attribute indicates
that the function is to be pipelined during compilation.

Example usge:

with summary_ops_v2.record_if(False):
is_pipelined = self.is_function_pipelined(tpu_test_fn, tpu_iter)
self.assertTrue(is_pipelined)
with summary_ops_v2.record_if(True):
is_pipelined = self.is_function_pipelined(tpu_test_fn, tpu_iter)
self.assertFalse(is_pipelined)


def _pyval_field_major_to_node_major(keys, values, depth):
    assert keys
    if depth == 0:
        return dict(zip(keys, values))
    nvals = len(values[0])
    assert all((nvals == len(values[i]) for i in range(1, len(values))))
    return [_pyval_field_major_to_node_major(keys, value_slice, depth - 1) for value_slice in zip(*values)]

Regroup each field (k, v) from dict-of-list to list-of-dict.

Given a "field-major" encoding of the StructuredTensor (which maps each key to
a single nested list containing the values for all structs), return a
corresponding "node-major" encoding, consisting of a nested list of dicts.

Args:
keys: The field names (list of string).  Must not be empty.
values: The field values (list of python values).  Must have the same length
as `keys`.
depth: The list depth at which dictionaries should be created.

Returns:
A nested list of dict, with depth `depth`.


def __init__(self, problems, schedule, **kwargs):

    super(MultiProblemV2, self).__init__(**kwargs)
    self.problems = problems
    self.schedule = schedule

Creates a MultiProblem object.

Args:
problems: A list of problem.Problem objects.
schedule: A schedule tuple, see encode_schedule for details.
**kwargs: Keywords for problem.Problem.__init__.


def videos(self, **kwargs):

        path = self._get_series_id_season_number_path('videos')

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

Get the videos that have been added to a TV season (trailers, teasers,
etc...).

Args:
language: (optional) ISO 639 code.

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


def init_cache(self, batch_size, max_length):
    input_ids = jnp.ones((batch_size, max_length))
    attention_mask = jnp.ones_like(input_ids)
    position_ids = jnp.broadcast_to(jnp.arange(jnp.atleast_2d(input_ids).shape[-1]), input_ids.shape)
    init_variables = self.module.init(jax.random.PRNGKey(0), input_ids, attention_mask, position_ids, return_dict=False, init_cache=True)
    return init_variables['cache']

Args:
batch_size (`int`):
batch_size used for fast auto-regressive decoding. Defines the batch size of the initialized cache.
max_length (`int`):
maximum possible length for auto-regressive decoding. Defines the sequence length of the initialized
cache.


def get_if_deleted(self, addresses):
    with self._lock:
        results = []
        for add in addresses:
            results.append(self._get_if_deleted(add))
        return results

Returns a list of addresses that have been deleted, or None if it
hasn't been deleted.

Args:
addresses (list of str): The addresses to check if deleted.

Returns:
(list of str): The addresses, if deleted, or None.


def _pad_image(self, images: 'torch.tensor', size_divisibility: int=32) -> 'torch.tensor':
    height, width = get_image_size(images, channel_dim=ChannelDimension.FIRST)
    pad_height = 0 if height % size_divisibility == 0 else size_divisibility - height % size_divisibility
    pad_width = 0 if width % size_divisibility == 0 else size_divisibility - width % size_divisibility
    if pad_width + pad_height > 0:
        padding = (0, 0, pad_width, pad_height)
        images = F.pad(images, padding)
    return images

Pads an image or batched images constantly so that width and height are divisible by size_divisibility

Args:
image (`torch,tensor`):
Image to pad.
size_divisibility (`int`, *optional*, defaults to 32):
The width and height of the image will be padded to be divisible by this number.


def __init__(self, parent):

        super(ChatFrame, self).__init__(parent, padding=8, text="Chat")

        self.channel = tk.StringVar()
        self.message = tk.StringVar()

        self.channel_frame = ttk.Frame(self)
        self.channel_frame.grid(column=0, row=0, sticky="W E")
        self.channel_label = ttk.Label(self.channel_frame, text="Channel ID:")
        self.channel_label.grid(column=0, row=0, sticky="W E")
        self.channel_box = ttk.Entry(self.channel_frame, textvariable=self.channel)
        self.channel_box.grid(column=0, row=1, sticky="W E")
        self.channel_frame.columnconfigure(0, weight=1)

        self.message_frame = ttk.Frame(self)
        self.message_frame.grid(column=0, row=1, pady=8, sticky="W E")
        self.message_label = ttk.Label(self.message_frame, text="Message:")
        self.message_label.grid(column=0, row=0, sticky="W E")
        self.message_box = ttk.Entry(self.message_frame, textvariable=self.message)
        self.message_box.grid(column=0, row=1, sticky="W E")
        self.message_frame.columnconfigure(0, weight=1)

        self.send_button = ttk.Button(self, command=lambda: self.add_current_message(), text="Send")
        self.send_button.grid(column=0, row=2, sticky="W")

        self.columnconfigure(0, weight=1)

Send messages from the bot

Args:
parent:


def get_process_exit_code(self, task_type, task_id):
    with self._process_lock:
        p = self._processes[task_type, task_id]
    return p.exitcode if p else None

Returns the subprocess exit code given the task type and task id.

Args:
task_type: The task type.
task_id: The task id.

Returns:
The subprocess exit code; `None` if the subprocess has not exited yet.

Raises:
KeyError: If the corresponding subprocess is not found with `task_type`
and `task_id`.


def normalize_tuple(value, n, name):
    if isinstance(value, int):
        return (value,) * n
    else:
        try:
            value_tuple = tuple(value)
        except TypeError:
            raise ValueError(f'Argument `{name}` must be a tuple of {str(n)} integers. Received: {str(value)}')
        if len(value_tuple) != n:
            raise ValueError(f'Argument `{name}` must be a tuple of {str(n)} integers. Received: {str(value)}')
        for single_value in value_tuple:
            try:
                int(single_value)
            except (ValueError, TypeError):
                raise ValueError(f'Argument `{name}` must be a tuple of {str(n)} integers. Received: {str(value)} including element {str(single_value)} of type {str(type(single_value))}')
        return value_tuple

Transforms a single integer or iterable of integers into an integer tuple.

Args:
value: The value to validate and convert. Could an int, or any iterable
of ints.
n: The size of the tuple to be returned.
name: The name of the argument being validated, e.g. "strides" or
"kernel_size". This is only used to format error messages.

Returns:
A tuple of n integers.

Raises:
ValueError: If something else than an int/long or iterable thereof was
passed.


def __init__(self, examples):

    self.config = {}
    self.set_examples(examples)
    self.set_model_type('classification')
    self.set_label_vocab([])

Constructs the WitConfigBuilder object.

Args:
examples: A list of tf.Example or tf.SequenceExample proto objects.
These are the examples that will be displayed in WIT. If not model to
infer these examples with is specified through the methods on this class,
then WIT will display the examples for exploration, but no model inference
will be performed by the tool.


def apply_scissor(self, new_band_gap):

        if self.is_metal():

            max_index = -1000

            for i in range(self.nb_bands):
                below = False
                above = False
                for j in range(len(self.kpoints)):
                    if self.bands[Spin.up][i][j] < self.efermi:
                        below = True
                    if self.bands[Spin.up][i][j] > self.efermi:
                        above = True
                if above and below:
                    if i > max_index:
                        max_index = i

                if self.is_spin_polarized:
                    below = False
                    above = False
                    for j in range(len(self.kpoints)):
                        if self.bands[Spin.down][i][j] < self.efermi:
                            below = True
                        if self.bands[Spin.down][i][j] > self.efermi:
                            above = True
                    if above and below:
                        if i > max_index:
                            max_index = i

            old_dict = self.as_dict()
            shift = new_band_gap
            for spin in old_dict['bands']:
                for k in range(len(old_dict['bands'][spin])):
                    for v in range(len(old_dict['bands'][spin][k])):
                        if k >= max_index:
                            old_dict['bands'][spin][k][v] = \
                                old_dict['bands'][spin][k][v] + shift
        else:

            shift = new_band_gap - self.get_band_gap()['energy']
            old_dict = self.as_dict()
            for spin in old_dict['bands']:
                for k in range(len(old_dict['bands'][spin])):
                    for v in range(len(old_dict['bands'][spin][k])):
                        if old_dict['bands'][spin][k][v] >= \
                                old_dict['cbm']['energy']:
                            old_dict['bands'][spin][k][v] = \
                                old_dict['bands'][spin][k][v] + shift
            old_dict['efermi'] = old_dict['efermi'] + shift

            return LobsterBandStructureSymmLine.from_dict(old_dict)

Apply a scissor operator (shift of the CBM) to fit the given band gap.
If it's a metal. We look for the band crossing the fermi level
and shift this one up. This will not work all the time for metals!

Args:
new_band_gap: the band gap the scissor band structure need to have.

Returns:
a BandStructureSymmLine object with the applied scissor shift


def SetConfiguredUsers(self, users):
    prefix = (self.logger.name + '-')
    with tempfile.NamedTemporaryFile(mode='w', prefix=prefix, delete=True) as updated_users:
        updated_users_file = updated_users.name
        for user in users:
            updated_users.write((user + '\n'))
        updated_users.flush()
        if (not os.path.exists(self.google_users_dir)):
            os.makedirs(self.google_users_dir)
        shutil.copy(updated_users_file, self.google_users_file)
    file_utils.SetPermissions(self.google_users_file, mode=384, uid=0, gid=0)

Set the list of configured Google user accounts.

Args:
users: list, the username strings of the Linux accounts.


def get_model():
    if (not hasattr(g, 'model')):
        g.model = load_model(current_app.config['MODEL_CLS_PATH'], current_app.config['MODEL_CLS_NAME'], current_app.config['MODEL_LOAD_ARGS'])
    return g.model

Get the NN model that's being analyzed from the request context.  Put
the model in the request context if it is not yet there.

Returns:
instance of :class:`.models.model.Model` or derived
class


def price(self, market: pmd.ProcessedMarketData, name: Optional[str]=None):
    name = name or self._name + '_price'
    with tf.name_scope(name):
        discount_curve = get_discount_curve(self._discount_curve_type, market, self._mask)
        discount_factors = discount_curve.discount_factor(self._payment_dates)
        _, cashflows = self.cashflows(market)
        cashflow_pvs = cashflows * discount_factors
        return tf.math.reduce_sum(cashflow_pvs, axis=1)

Returns the present value of the stream on the valuation date.

Args:
market: An instance of `ProcessedMarketData`.
name: Python str. The name to give to the ops created by this function.
Default value: `None` which maps to 'price'.

Returns:
A `Tensor` of shape `batch_shape`  containing the modeled price of each
stream based on the input market data.


def get_servo_torque(self):

        data = []
        data.append(0x09)
        data.append(self.servoid)
        data.append(RAM_READ_REQ)
        data.append(PWM_RAM)
        data.append(BYTE2)
        send_data(data)
        rxdata = []
        try:
            rxdata = SERPORT.read(13)
            if ord(rxdata[10])<=127:
                return ((ord(rxdata[10])&0x03)<<8) | (ord(rxdata[9])&0xFF)
            else:
                return (ord(rxdata[10])-0xFF)*0xFF + (ord(rxdata[9])&0xFF)-0xFF
        except HerkulexError:
            raise HerkulexError("could not communicate with motors")

Gets the current torque of Herkulex

Gives the current load on the servo shaft.
It is actually the PWM value to the motors

Args:
none

Returns:
int: the torque on servo shaft. range from -1023 to 1023

Raises:
SerialException: Error occured while opening serial port


def _handle_client_exception():
    try:
        (yield)
    except _ClientException as exception:
        if (exception.http_status in _ERROR_CODES):
            raise _ERROR_CODES[exception.http_status](exception.http_reason)
        raise

Handle Swift exception and convert to class
IO exceptions

Raises:
OSError subclasses: IO error.


def replace_species(self, species_mapping):
    species_mapping = {get_el_sp(k): v for (k, v) in species_mapping.items()}
    sp_to_replace = set(species_mapping.keys())
    sp_in_structure = set(self.composition.keys())
    if (not sp_in_structure.issuperset(sp_to_replace)):
        warnings.warn(('Some species to be substituted are not present in structure. Pls check your input. Species to be substituted = %s; Species in structure = %s' % (sp_to_replace, sp_in_structure)))
    for site in self._sites:
        if sp_to_replace.intersection(site.species):
            c = Composition()
            for (sp, amt) in site.species.items():
                new_sp = species_mapping.get(sp, sp)
                try:
                    c += (Composition(new_sp) * amt)
                except Exception:
                    c += {new_sp: amt}
            site.species = c

Swap species.

Args:
species_mapping (dict): dict of species to swap. Species can be
elements too. E.g., {Element("Li"): Element("Na")} performs
a Li for Na substitution. The second species can be a
sp_and_occu dict. For example, a site with 0.5 Si that is
passed the mapping {Element('Si): {Element('Ge'):0.75,
Element('C'):0.25} } will have .375 Ge and .125 C.


def _VerifyValues(self, image, ksizes, strides, padding, patches):
    ksizes = [1] + ksizes + [1]
    strides = [1] + strides + [1]
    for dtype in [np.float16, np.float32, np.float64, dtypes.bfloat16.as_numpy_dtype]:
        out_tensor = array_ops.extract_volume_patches(constant_op.constant(image.astype(dtype)), ksizes=ksizes, strides=strides, padding=padding, name='im2col_3d')
        self.assertAllClose(patches.astype(dtype), self.evaluate(out_tensor))

Tests input-output pairs for the ExtractVolumePatches op.

Args:
image: Input tensor with shape:
[batch, in_planes, in_rows, in_cols, depth].
ksizes: Patch size specified as: [ksize_planes, ksize_rows, ksize_cols].
strides: Output strides, specified as:
[stride_planes, stride_rows, stride_cols].
padding: Padding type.
patches: Expected output.

Note:
rates are not supported as of now.


def __init__(self, window_size=zlib.MAX_WBITS):

    super(ZlibDecompressor, self).__init__()
    self._zlib_decompressor = zlib.decompressobj(window_size)

Initializes a decompressor.

Args:
window_size (Optional[int]): base two logarithm of the size of
the compression history buffer (aka window size). When the value
is negative, the standard zlib data header is suppressed.


def load_data(path, verbose=False, raise_errors = False):

        if not os.path.exists(path):
            if raise_errors:
                raise AttributeError('Path given does not exist!')
            else:
                print('Path given does not exist!')
                return

        path = Script.check_filename(path)

        if verbose:
            print('script path', path)

        data = {}

        if 'raw_data' in os.listdir(path):

            if verbose:
                print('raw_data subfolder found')
            data_files = os.listdir(os.path.join(path, 'raw_data' + '/'))
            path = os.path.join(path, 'raw_data' + '/')

        else:
            data_files = glob.glob(os.path.join(path, '*.csv'))

        if verbose:
            print('data_files found', data_files)

        if not data_files:

            if raise_errors:
                raise AttributeError('Could not find data files in {:s}'.format(path))
            else:
                print('Could not find data files in {:s}'.format(path))
                return

        for data_file in data_files:

            data_name = data_file.split('-')[-1][0:-4]

            try:
                imported_data_df = pd.read_csv(os.path.join(path, data_file))

                column_headers = list(imported_data_df.columns.values)
                if sum([int(x.isdigit()) for x in column_headers]) != len(column_headers):
                    data[data_name] = {h: imported_data_df[h].values for h in column_headers}
                else:

                    data[data_name] = np.squeeze(imported_data_df.values)
            except pd.errors.EmptyDataError as err:

                if raise_errors:
                    raise err('data file ' + data_file + ' is empty: did not load!')
                else:
                    print('data file ' + data_file + ' is empty: did not load!')

        return data

loads the data that has been save with Script.save.
Args:
path: path to folder saved by Script.save or raw_data folder within
verbose: if true print additional information
raise_errors: if true raise errors if false just print to std out
Returns:
a dictionary with the data of form
data = {param_1_name: param_1_data, ...}


def received_response(self, value):

        if value == self._defaults['receivedResponse'] and 'receivedResponse' in self._values:
            del self._values['receivedResponse']
        else:
            self._values['receivedResponse'] = value

The received_response property.

Args:
value (string). the property value.


def write_fasta_file_from_dict(indict, outname, outdir=None, outext='.faa', force_rerun=False):

    if not outdir:
        outdir = ''
    outfile = ssbio.utils.outfile_maker(inname='', outname=outname, outdir=outdir, outext=outext)

    if ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
        seqs = []
        for i, s in indict.items():
            seq = ssbio.protein.sequence.utils.cast_to_seq_record(s, id=i)
            seqs.append(seq)
        SeqIO.write(seqs, outfile, "fasta")

    return outfile

Write a FASTA file for a dictionary of IDs and their sequence strings.

Args:
indict: Input dictionary with keys as IDs and values as sequence strings
outname: Name of the output file which will have outext appended to it
outdir: Path to directory to output sequences to
outext: Extension of FASTA file, default ".faa"
force_rerun: If file should be overwritten if it exists

Returns:
str: Path to output FASTA file.


def write_summaries(self, tagged_data, experiment_name, run_name):

    logger.debug('Writing summaries for %s tags', len(tagged_data))

    with self._db:
      self._db.execute('BEGIN TRANSACTION')
      run_id = self._maybe_init_run(experiment_name, run_name)
      tag_to_metadata = {
          tag: tagdata.metadata for tag, tagdata in six.iteritems(tagged_data)
      }
      tag_to_id = self._maybe_init_tags(run_id, tag_to_metadata)
      tensor_values = []
      for tag, tagdata in six.iteritems(tagged_data):
        tag_id = tag_to_id[tag]
        for step, wall_time, tensor_proto in tagdata.values:
          dtype = tensor_proto.dtype
          shape = ','.join(str(d.size) for d in tensor_proto.tensor_shape.dim)

          data = self._make_blob(
              tensor_proto.tensor_content or
              tensor_util.make_ndarray(tensor_proto).tobytes())
          tensor_values.append((tag_id, step, wall_time, dtype, shape, data))
      self._db.executemany(
          ,
          tensor_values)

Transactionally writes the given tagged summary data to the DB.

Args:
tagged_data: map from tag to TagData instances.
experiment_name: name of experiment.
run_name: name of run.


def find_all(container):

    if isinstance(container, dict):
        names = container.keys()
    else:
        names = dir(container)

    built_context = BasicContext()

    for name in names:

        if name.startswith('_'):
            continue

        if isinstance(container, dict):
            obj = container[name]
        else:
            obj = getattr(container, name)

        if isinstance(container, dict) and isinstance(obj, str):
            built_context[name] = obj
        elif hasattr(obj, 'metadata') and isinstance(getattr(obj, 'metadata'), AnnotatedMetadata):
            built_context[name] = obj

    return built_context

Find all annotated function inside of a container.

Annotated functions are identified as those that:
- do not start with a _ character
- are either annotated with metadata
- or strings that point to lazily loaded modules

Args:
container (object): The container to search for annotated functions.

Returns:
dict: A dict with all of the found functions in it.


class MCTCTProcessor(ProcessorMixin):
    feature_extractor_class = 'MCTCTFeatureExtractor'
    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

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

        if self._in_target_context_manager:
            return self.current_processor(*args, **kwargs)
        if 'raw_speech' in kwargs:
            warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.')
            audio = kwargs.pop('raw_speech')
        else:
            audio = kwargs.pop('audio', None)
        sampling_rate = kwargs.pop('sampling_rate', None)
        text = kwargs.pop('text', None)
        if len(args) > 0:
            audio = args[0]
            args = args[1:]
        if audio is None and text is None:
            raise ValueError('You need to specify either an `audio` or `text` input to process.')
        if audio is not None:
            inputs = self.feature_extractor(audio, *args, sampling_rate=sampling_rate, **kwargs)
        if text is not None:
            encodings = self.tokenizer(text, **kwargs)
        if text is None:
            return inputs
        elif audio is None:
            return encodings
        else:
            inputs['labels'] = encodings['input_ids']
            return inputs

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

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

    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 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 MCTCT processor which wraps a MCTCT feature extractor and a MCTCT tokenizer into a single processor.

[`MCTCTProcessor`] offers all the functionalities of [`MCTCTFeatureExtractor`] and [`AutoTokenizer`]. See the
[`~MCTCTProcessor.__call__`] and [`~MCTCTProcessor.decode`] for more information.

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


def run(self, dag):
    for node in dag.op_nodes():
        basic_insts = ['measure', 'reset', 'barrier', 'snapshot']
        if (node.name in basic_insts):
            continue
        if (node.name in self.basis):
            continue
        rule = node.op.definition
        if (not rule):
            raise QiskitError(('Cannot unroll the circuit to the given basis, %s. No rule to expand instruction %s.' % (str(self.basis), node.op.name)))
        decomposition = DAGCircuit()
        decomposition.add_qreg(rule[0][1][0][0])
        for inst in rule:
            decomposition.apply_operation_back(*inst)
        unrolled_dag = self.run(decomposition)
        dag.substitute_node_with_dag(node, unrolled_dag)
    return dag

Expand all op nodes to the given basis.

Args:
dag(DAGCircuit): input dag

Raises:
QiskitError: if unable to unroll given the basis due to undefined
decomposition rules (such as a bad basis) or excessive recursion.

Returns:
DAGCircuit: output unrolled dag


def extract_build_info(exe_path, elf_section=ELF_SECTION):
    build_info = {}
    with mkdtemp() as tempd, pushd(tempd):
        proc = subprocess.Popen([OBJCOPY, DUMP_SECTION, '{secn}={ofile}'.format(secn=elf_section, ofile=BUILDINFO_FILE), exe_path], stderr=subprocess.PIPE)
        proc.wait()
        errno = proc.returncode
        stderr = proc.stderr.read()
        if (errno or len(stderr)):
            LOGGER.warning('objcopy failed with errno %s.', errno)
            if len(stderr):
                LOGGER.warning('objcopy failed with following msg:\n%s', stderr)
            return build_info
        with open(BUILDINFO_FILE) as build_info_f:
            try:
                build_info = json.load(build_info_f, object_hook=byteify)
            except JSONDcdError as jsde:
                LOGGER.warning('benchmark executable build is not valid json:')
                LOGGER.warning(jsde.msg)
                LOGGER.warning('build info section content:')
                LOGGER.warning(jsde.doc)
    return build_info

Extracts the build information from a given executable.

The build information is expected to be in json format, which is parsed
and returned as a dictionary.
If no build information is found an empty dictionary is returned.

This assumes binutils 2.25 to work.

Args:
exe_path (str): The full path to the executable to be examined

Returns:
dict: A dictionary of the extracted information.


def rsqrt(x):
    if any_symbolic_tensors((x,)):
        return Rsqrt().symbolic_call(x)
    x = backend.convert_to_tensor(x)
    return backend.math.rsqrt(x)

Computes reciprocal of square root of x element-wise.

Args:
x: input tensor

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

Example:

>>> x = keras.ops.convert_to_tensor([1.0, 10.0, 100.0])
>>> keras.ops.rsqrt(x)
array([1.0, 0.31622776, 0.1], dtype=float32)


def async_decorator(func):

    @functools.wraps(func)
    def async_wrapper(*args, **kwargs):
        'Wraps up the call to ``func``, so that it is called from a separate\n        thread.\n\n        The callback, if given, will be called with two parameters,\n        ``exception`` and ``result`` as ``callback(exception, result)``.  If\n        the thread ran to completion without error, ``exception`` will be\n        ``None``, otherwise ``exception`` will be the generated exception that\n        stopped the thread.  Result is the result of the exected function.\n\n        Args:\n          callback (function): the callback to ultimately be called\n          args: list of arguments to pass to ``func``\n          kwargs: key-word arguments dictionary to pass to ``func``\n\n        Returns:\n          A thread if the call is asynchronous, otherwise the the return value\n          of the wrapped function.\n\n        Raises:\n          TypeError: if ``callback`` is not callable or is missing\n        '
        if (('callback' not in kwargs) or (not kwargs['callback'])):
            return func(*args, **kwargs)
        callback = kwargs.pop('callback')
        if (not callable(callback)):
            raise TypeError("Expected 'callback' is not callable.")

        def thread_func(*args, **kwargs):
            'Thread function on which the given ``func`` and ``callback``\n            are executed.\n\n            Args:\n              args: list of arguments to pass to ``func``\n              kwargs: key-word arguments dictionary to pass to ``func``\n\n            Returns:\n              Return value of the wrapped function.\n            '
            (exception, res) = (None, None)
            try:
                res = func(*args, **kwargs)
            except Exception as e:
                exception = e
            return callback(exception, res)
        thread = threads.ThreadReturn(target=thread_func, args=args, kwargs=kwargs)
        thread.daemon = True
        thread.start()
        return thread
    return async_wrapper

Asynchronous function decorator.  Interprets the function as being
asynchronous, so returns a function that will handle calling the
Function asynchronously.

Args:
func (function): function to be called asynchronously

Returns:
The wrapped function.

Raises:
AttributeError: if ``func`` is not callable


def get_python_executable(version: tuple[int, ...]) -> list[str] | None:
    if can_compile_bytecode_natively(version):
        return None
    for exe in _get_python_exes(version):
        exe_version = _get_python_exe_version(exe)
        if exe_version == version:
            return exe
    raise PythonNotFoundError()

Get a python executable corresponding to version.

Args:
version: The required python version

Returns:
- None: The current host interpreter can compile `version`
- [path-to-exe, args]: A valid python-`version` interpreter

Raises:
PythonNotFoundError: if no suitable interpreter is found.


def connect():
    upnp = miniupnpc.UPnP()
    upnp.discoverdelay = 200
    providers = upnp.discover()
    if (providers > 1):
        log.debug('multiple upnp providers found', num_providers=providers)
    elif (providers < 1):
        log.error('no upnp providers found')
        return None
    try:
        location = upnp.selectigd()
        log.debug('connected', upnp=upnp)
    except Exception as e:
        log.error('Error when connecting to uPnP provider', exception_info=e)
        return None
    if (not valid_mappable_ipv4(upnp.lanaddr)):
        log.error('could not query your lanaddr', reported=upnp.lanaddr)
        return None
    try:
        if (not valid_mappable_ipv4(upnp.externalipaddress())):
            log.error('could not query your externalipaddress', reported=upnp.externalipaddress())
            return None
        return (upnp, location)
    except Exception:
        log.error('error when connecting with uPnP provider', location=location)
        return None

Try to connect to the router.

Returns:
u (miniupnc.UPnP): the connected upnp-instance
router (string): the connection information


def _split_heads(self, fused_qkv: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
    batch_size, seq_length, three_times_hidden_size = fused_qkv.shape
    fused_qkv = fused_qkv.view(batch_size, seq_length, self.num_heads, 3, self.head_dim)
    return (fused_qkv[..., 0, :], fused_qkv[..., 1, :], fused_qkv[..., 2, :])

Split the last dimension into (num_heads, head_dim) without making any copies, results share same memory
storage as `fused_qkv`

Args:
fused_qkv (`torch.tensor`): [batch_size, seq_length, num_heads * 3 * head_dim]

Returns:
query: [batch_size, seq_length, num_heads, head_dim] key: [batch_size, seq_length, num_heads, head_dim]
value: [batch_size, seq_length, num_heads, head_dim]


def indent(text, n=2, ch=' '):
    padding = (ch * n)
    return '\n'.join(((padding + line) for line in text.split('\n')))

Indent all the lines in a given block of text by a specified amount.

Args:
text (str) :
The text to indent

n (int, optional) :
The amount to indent each line by (default: 2)

ch (char, optional) :
What character to fill the indentation with (default: " ")


def index_in_block(self, channel_index: int) -> int:
    if ((channel_index < 0) or (channel_index >= self.cdim)):
        raise ValueError()
    struct = self.block_structure
    if (len(struct) == 1):
        return (channel_index, 0)
    i = 1
    while ((sum(struct[:i]) <= channel_index) and (i < self.cdim)):
        i += 1
    block_index = (i - 1)
    index_in_block = (channel_index - sum(struct[:block_index]))
    return (index_in_block, block_index)

Return the index a channel has within the subblock it belongs to

I.e., only for reducible circuits, this gives a result different from
the argument itself.

Args:
channel_index (int): The index of the external channel

Raises:
ValueError: for an invalid `channel_index`


def decode_response(data):

    res = CaseInsensitiveDict()
    for dataline in data.decode('utf-8').splitlines()[1:]:
        dataline = dataline.strip()
        if not dataline:
            continue
        line_parts = dataline.split(':', 1)

        if len(line_parts) < 2:
            line_parts = (line_parts[0], '')
        res[line_parts[0].strip()] = line_parts[1].strip()
    return res

Decodes the data from a SSDP response.

Args:
data (bytes): The encoded response.

Returns:
dict of string -> string: Case-insensitive dictionary of header name to
header value pairs extracted from the response.


def leapfrog_step(leapfrog_step_state: LeapFrogStepState,
                  step_size: FloatTensor, target_log_prob_fn: PotentialFn,
                  kinetic_energy_fn: PotentialFn
                 ) -> Tuple[LeapFrogStepState, LeapFrogStepExtras]:

  state = leapfrog_step_state.state
  state_grads = leapfrog_step_state.state_grads
  momentum = leapfrog_step_state.momentum
  step_size = maybe_broadcast_structure(step_size, state)

  state = tf.nest.map_structure(tf.convert_to_tensor, state)
  momentum = tf.nest.map_structure(tf.convert_to_tensor, momentum)
  state = tf.nest.map_structure(tf.convert_to_tensor, state)

  if state_grads is None:
    _, _, state_grads = call_and_grads(target_log_prob_fn, state)
  else:
    state_grads = tf.nest.map_structure(tf.convert_to_tensor, state_grads)

  momentum = tf.nest.map_structure(lambda m, sg, s: m + 0.5 * sg * s, momentum,
                                   state_grads, step_size)

  kinetic_energy, kinetic_energy_extra, momentum_grads = call_and_grads(
      kinetic_energy_fn, momentum)

  state = tf.nest.map_structure(lambda x, mg, s: x + mg * s, state,
                                momentum_grads, step_size)

  target_log_prob, state_extra, state_grads = call_and_grads(
      target_log_prob_fn, state)

  momentum = tf.nest.map_structure(lambda m, sg, s: m + 0.5 * sg * s, momentum,
                                   state_grads, step_size)

  return LeapFrogStepState(state, state_grads, momentum), LeapFrogStepExtras(
      target_log_prob, state_extra, kinetic_energy, kinetic_energy_extra)

Leapfrog `TransitionOperator`.

Args:
leapfrog_step_state: LeapFrogStepState.
step_size: Step size, structure broadcastable to the `target_log_prob_fn`
state.
target_log_prob_fn: Target log prob fn.
kinetic_energy_fn: Kinetic energy fn.

Returns:
leapfrog_step_state: LeapFrogStepState.
leapfrog_step_extras: LeapFrogStepExtras.


def after(self):
    d = Deferred()
    self._after_deferreds.append(d)
    return d.chain

Return a deferred that will fire after the request is finished.

Returns:

Deferred: a new deferred that will fire appropriately


def val_to_mrc(code, val):
    code = str(code)
    if (len(code) < 3):
        code += ((3 - len(code)) * ' ')
    return ('%s   L %s' % (code, val))

Convert one single `val` to MRC.

This function may be used for control fields in MARC records.

Args:,
code (str): Code of the field.
val (str): Value of the field.

Returns:
str: Correctly padded MRC line with field.


def marshal_json(
    obj,
    types=JSON_TYPES,
    fields=None,
):

    return marshal_dict(
        obj,
        types,
        fields=fields,
    )

Recursively marshal a Python object to a JSON-compatible dict
that can be passed to json.{dump,dumps}, a web client,
or a web server, etc...

Args:
obj:    object, It's members can be nested Python
objects which will be converted to dictionaries
types:  tuple-of-types, The JSON primitive types, typically
you would not change this
fields: None-list-of-str, Explicitly marshal only these fields
Returns:
dict


def _render_timestep(self,
            t: int,
            s: Fluents, a: Fluents, f: Fluents,
            r: np.float32) -> None:

        print("============================")
        print("TIME = {}".format(t))
        print("============================")
        fluent_variables = self._compiler.rddl.action_fluent_variables
        self._render_fluent_timestep('action', a, fluent_variables)
        fluent_variables = self._compiler.rddl.interm_fluent_variables
        self._render_fluent_timestep('interms', f, fluent_variables)
        fluent_variables = self._compiler.rddl.state_fluent_variables
        self._render_fluent_timestep('states', s, fluent_variables)
        self._render_reward(r)

Prints fluents and rewards for the given timestep `t`.

Args:
t (int): timestep
s (Sequence[Tuple[str], np.array]: State fluents.
a (Sequence[Tuple[str], np.array]: Action fluents.
f (Sequence[Tuple[str], np.array]: Interm state fluents.
r (np.float32): Reward.


def __init__(self, json_data):

        super(ImmutableData, self).__init__()
        self._json_data = json_dict(json_data)

Init a new ImmutableData object from a dictionary or JSON string.

Args:
json_data(dict, basestring): Input JSON string or dictionary.

Raises:
TypeError: If the input object is not a dictionary or string.


def assign(self, institute, case, user, link):

        LOG.info("Creating event for assigning {0} to {1}"
                    .format(user['name'].encode('utf-8'), case['display_name']))

        self.create_event(
            institute=institute,
            case=case,
            user=user,
            link=link,
            category='case',
            verb='assign',
            subject=case['display_name']
        )
        LOG.info("Updating {0} to be assigned with {1}"
                    .format(case['display_name'], user['name']))

        updated_case = self.case_collection.find_one_and_update(
            {'_id': case['_id']},
            {'$addToSet': {'assignees': user['_id']}},
            return_document=pymongo.ReturnDocument.AFTER
        )
        return updated_case

Assign a user to a case.

This function will create an Event to log that a person has been assigned
to a case. Also the user will be added to case "assignees".

Arguments:
institute (dict): A institute
case (dict): A case
user (dict): A User object
link (str): The url to be used in the event

Returns:
updated_case(dict)


def get_keys_to_action(self):
    keyword_to_key = {'UP': ord('w'), 'DOWN': ord('s'), 'LEFT': ord('a'), 'RIGHT': ord('d'), 'FIRE': ord(' ')}
    keys_to_action = {}
    for (action_id, action_meaning) in enumerate(self.action_meanings):
        keys_tuple = tuple(sorted([key for (keyword, key) in keyword_to_key.items() if (keyword in action_meaning)]))
        assert (keys_tuple not in keys_to_action)
        keys_to_action[keys_tuple] = action_id
    keys_to_action[(ord('r'),)] = self.RETURN_DONE_ACTION
    keys_to_action[(ord('c'),)] = self.TOGGLE_WAIT_ACTION
    keys_to_action[(ord('n'),)] = self.WAIT_MODE_NOOP_ACTION
    return keys_to_action

Get mapping from keyboard keys to actions.

Required by gym.utils.play in environment or top level wrapper.

Returns:
{
Unicode code point for keyboard key: action (formatted for step()),
...
}


def _hash_file(fpath, algorithm='sha256', chunk_size=65535):
    if isinstance(algorithm, str):
        hasher = _resolve_hasher(algorithm)
    else:
        hasher = algorithm
    with open(fpath, 'rb') as fpath_file:
        for chunk in iter(lambda: fpath_file.read(chunk_size), b''):
            hasher.update(chunk)
    return hasher.hexdigest()

Calculates a file sha256 or md5 hash.

Example:

```python
_hash_file('/path/to/file.zip')
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
```

Args:
fpath: path to the file being validated
algorithm: hash algorithm, one of `'auto'`, `'sha256'`, or `'md5'`.
The default `'auto'` detects the hash algorithm in use.
chunk_size: Bytes to read at a time, important for large files.

Returns:
The file hash


def acquire_resources(self, source):

        if source not in self.consulted:
            self.consulted.add(source)
            if isinstance(source, Tag):
                res = source
            else:
                res = source(self.H)
            if res is None:
                res = set()
            elif isinstance(res, (list, tuple)):
                res = set(res)
            elif isinstance(res, Tag):
                res = {res}
            self.resources |= res

Store the resources returned by ``source()``. If ``source`` has
been acquired before, it will not be called a second time.

Args:
source (callable): A function that returns a resource or a
list of resources.

Returns:
None


def register_frame_to_skip(cls, file_name, function_name, line_number=None):
    if (line_number is not None):
        cls._frames_to_skip.add((file_name, function_name, line_number))
    else:
        cls._frames_to_skip.add((file_name, function_name))

Registers a function name to skip when walking the stack.

The ABSLLogger sometimes skips method calls on the stack
to make the log messages meaningful in their appropriate context.
This method registers a function from a particular file as one
which should be skipped.

Args:
file_name: str, the name of the file that contains the function.
function_name: str, the name of the function to skip.
line_number: int, if provided, only the function with this starting line
number will be skipped. Otherwise, all functions with the same name
in the file will be skipped.


def read(self, bands=None, **kwargs):

        arr = self
        if bands is not None:
            arr = self[bands, ...]
        return arr.compute(scheduler=threaded_get)

Reads data from a dask array and returns the computed ndarray matching the given bands

Args:
bands (list): band indices to read from the image. Returns bands in the order specified in the list of bands.

Returns:
ndarray: a numpy array of image data


def get_ISBNs(self):
    invalid_isbns = set(self.get_invalid_ISBNs())
    valid_isbns = [self._clean_isbn(isbn) for isbn in self['020a'] if (self._clean_isbn(isbn) not in invalid_isbns)]
    if valid_isbns:
        return valid_isbns
    return [self._clean_isbn(isbn) for isbn in self['901i']]

Get list of VALID ISBN.

Returns:
list: List with *valid* ISBN strings.


def is_flat(outputs):
    if isinstance(outputs, collections_abc.Sequence):
        for o in outputs:
            if isinstance(o, collections_abc.Sequence) or isinstance(o, collections_abc.Mapping) or hasattr(o.__class__, '__attrs_attrs__'):
                return False
    if isinstance(outputs, collections_abc.Mapping):
        return False
    if hasattr(outputs.__class__, '__attrs_attrs__'):
        return False
    return True

Checks if outputs is a flat structure.

Following structures and values are considered flat:
1) None
2) A single object
3) A list or tuple of Tensors/Operations

The only structures that this function understands are sequences,
dictionaries and types defined using the attrs library.  E.g. this means
that if outputs contains a single user-defined Object, it is considered to
be flat. Errors are raised later on if that Object cannot be converted to a
Tensor.

Args:
outputs: Output from `computation` inside `xla.compile`.

Returns:
A boolean indicates whether outputs is flat.


def cracked(self):
    logging.info('Cracking message: {0}'.format(self.message))
    entropy_values = {}
    attempt_cache = {}
    message = self.message
    for i in range(25):
        self.message = message
        self.offset = (i * (- 1))
        logging.debug('Attempting crack with offset: {0}'.format(self.offset))
        test_cipher = self.cipher()
        logging.debug('Attempting plaintext: {0}'.format(test_cipher))
        entropy_values[i] = self.calculate_entropy(test_cipher)
        attempt_cache[i] = test_cipher
    sorted_by_entropy = sorted(entropy_values, key=entropy_values.get)
    self.offset = (sorted_by_entropy[0] * (- 1))
    cracked_text = attempt_cache[sorted_by_entropy[0]]
    self.message = cracked_text
    logging.debug('Entropy scores: {0}'.format(entropy_values))
    logging.debug('Lowest entropy score: {0}'.format(str(entropy_values[sorted_by_entropy[0]])))
    logging.debug('Most likely offset: {0}'.format(self.offset))
    logging.debug('Most likely message: {0}'.format(cracked_text))
    return cracked_text

Attempts to crack ciphertext using frequency of letters in English.

Returns:
String of most likely message.


def from_task(cls, task):

        target = cls(name=task.get_name(),
                     params=task.get_param_string())

        return target

Create a new target representing a task and its parameters

Args:
task: Task instance to create target for; the task class has to inherit
from :class:`ozelot.tasks.TaskBase`.

Returns:
ozelot.tasks.ORMTarget: a new target instance


def parse_case(config):
    if ('owner' not in config):
        raise ConfigError('A case has to have a owner')
    if ('family' not in config):
        raise ConfigError("A case has to have a 'family'")
    individuals = parse_individuals(config['samples'])
    case_data = {'owner': config['owner'], 'collaborators': [config['owner']], 'case_id': config['family'], 'display_name': config.get('family_name', config['family']), 'genome_build': config.get('human_genome_build'), 'rank_model_version': config.get('rank_model_version'), 'rank_score_threshold': config.get('rank_score_threshold', 0), 'analysis_date': config['analysis_date'], 'individuals': individuals, 'vcf_files': {'vcf_snv': config.get('vcf_snv'), 'vcf_sv': config.get('vcf_sv'), 'vcf_str': config.get('vcf_str'), 'vcf_cancer': config.get('vcf_cancer'), 'vcf_snv_research': config.get('vcf_snv_research'), 'vcf_sv_research': config.get('vcf_sv_research'), 'vcf_cancer_research': config.get('vcf_cancer_research')}, 'default_panels': config.get('default_gene_panels', []), 'gene_panels': config.get('gene_panels', []), 'assignee': config.get('assignee'), 'peddy_ped': config.get('peddy_ped'), 'peddy_sex': config.get('peddy_sex'), 'peddy_check': config.get('peddy_check'), 'delivery_report': config.get('delivery_report'), 'multiqc': config.get('multiqc'), 'track': config.get('track', 'rare')}
    if ('madeline' in config):
        mad_path = Path(config['madeline'])
        if (not mad_path.exists()):
            raise ValueError('madeline path not found: {}'.format(mad_path))
        with mad_path.open('r') as in_handle:
            case_data['madeline_info'] = in_handle.read()
    if (case_data['vcf_files']['vcf_cancer'] or case_data['vcf_files']['vcf_cancer_research']):
        case_data['track'] = 'cancer'
    return case_data

Parse case information from config or PED files.

Args:
config (dict): case config with detailed information

Returns:
dict: parsed case data


def GetApprovalForObject(object_urn, token=None, username=''):
    if (token is None):
        raise access_control.UnauthorizedAccess('No token given, cannot authenticate.')
    if (not username):
        username = token.username
    approvals_root_urn = aff4.ROOT_URN.Add('ACL').Add(object_urn.Path()).Add(username)
    children_urns = list(aff4.FACTORY.ListChildren(approvals_root_urn))
    if (not children_urns):
        raise access_control.UnauthorizedAccess(('No approval found for user %s' % utils.SmartStr(username)), subject=object_urn)
    last_error = None
    approvals = aff4.FACTORY.MultiOpen(children_urns, mode='r', aff4_type=Approval, age=aff4.ALL_TIMES, token=token)
    for approval in approvals:
        try:
            test_token = access_control.ACLToken(username=username, reason=approval.Get(approval.Schema.REASON))
            approval.CheckAccess(test_token)
            return test_token
        except access_control.UnauthorizedAccess as e:
            last_error = e
    if last_error:
        raise access_control.UnauthorizedAccess(last_error, subject=object_urn)
    else:
        raise access_control.UnauthorizedAccess(("Couldn't open any of %d approvals for user %s" % (len(children_urns), utils.SmartStr(username))), subject=object_urn)

Looks for approvals for an object and returns available valid tokens.

Args:
object_urn: Urn of the object we want access to.

token: The token to use to lookup the ACLs.

username: The user to get the approval for, if "" we get it from the
token.

Returns:
A token for access to the object on success, otherwise raises.

Raises:
UnauthorizedAccess: If there are no valid approvals available.


def get_bytes(obj):

    try:
        obj = obj.read(_NUM_SIGNATURE_BYTES)
    except AttributeError:

        pass

    kind = type(obj)

    if kind is bytearray:
        return signature(obj)

    if kind is str:
        return get_signature_bytes(obj)

    if kind is bytes:
        return signature(obj)

    if kind is memoryview:
        return signature(obj).tolist()

    raise TypeError('Unsupported type as file input: %s' % kind)

Infers the input type and reads the first 262 bytes,
returning a sliced bytearray.

Args:
obj: path to readable, file, bytes or bytearray.

Returns:
First 262 bytes of the file content as bytearray type.

Raises:
TypeError: if obj is not a supported type.


def image(title, desc, image_name, group=None, height=None):
    ie = {'Type': 'Image', 'Title': title, 'Description': desc, 'Plot File': image_name}
    if group:
        ie['Group'] = group
    if height:
        ie['Height'] = height
    return ie

Builds an image element.  Image elements are primarily created
and then wrapped into an image gallery element.  This is not required
behavior, however and it's independent usage should be allowed depending
on the behavior required.

The Javascript will search for the `image_name` in the component's
`imgs` directory when rendering.  For example, all verification images
are output to `vv_xxxx-xx-xx/verification/imgs` and then the verification
case's output page will search for `image_name` within that directory.

Args:
title: The title to display
desc: A description of the image or plot
image_name: The filename of the image
group: (optional) Title of lightbox group to join
height: (optional) Height of image thumbnail to draw

Returns:
A dictionary with the metadata specifying that it is to be
rendered as an image element


def _set_optimizer(self, optimizer):
    if isinstance(optimizer, (list, tuple)):
        self.optimizer = [optimizers.get(opt) for opt in optimizer]
    else:
        self.optimizer = optimizers.get(optimizer)
    if isinstance(self._dtype_policy, policy.PolicyV1):
        loss_scale = self._dtype_policy.loss_scale
    elif self._dtype_policy.name == 'mixed_float16':
        loss_scale = 'dynamic'
    else:
        loss_scale = None
    if loss_scale is not None and (not isinstance(self.optimizer, loss_scale_optimizer.LossScaleOptimizer)):
        if isinstance(self.optimizer, list):
            raise ValueError('When a dtype policy with a loss scale is used, you can only pass a single optimizer. Using policy %s and got optimizers: %s' % self._dtype_policy, self.optimizer)
        if not isinstance(self.optimizer, optimizer_v2.OptimizerV2):
            raise ValueError('"optimizer" must be an instance of tf.keras.optimizers.Optimizer when a dype policy with a loss scale  used, but got: %s. Using policy: %s' % (self.optimizer, self._dtype_policy))
        if loss_scale == 'dynamic':
            self.optimizer = loss_scale_optimizer.LossScaleOptimizer(self.optimizer)
        else:
            self.optimizer = loss_scale_optimizer.LossScaleOptimizerV1(self.optimizer, loss_scale)

Sets self.optimizer.

Sets self.optimizer to `optimizer`, potentially wrapping it with a
LossScaleOptimizer.

Args:
optimizer: The optimizer(s) to assign to self.optimizer.


def impute(X, value=None, train=None, dropna=True, inplace=True):

    if value is None:
        Xfit = X[train] if train is not None else X
        value = Xfit.mean()
    else:
        if train is not None:
            raise ValueError("Cannot pass both train and value arguments")

    if dropna:
        null_columns = value.index[value.isnull()]
        if len(null_columns) > 0:
            logging.info('Dropping null columns: \n\t%s' % null_columns)
            if inplace:
                X.drop(null_columns, axis=1, inplace=True)
            else:
                X = X.drop(null_columns, axis=1, inplace=False)

    if inplace:
        X.fillna(value.dropna(), inplace=True)
    else:
        X = X.fillna(value.dropna(), inplace=False)

    return X

Performs mean imputation on a pandas dataframe.
Args:
train: an optional training mask with which to compute the mean
value: instead of computing the mean, use this as the value argument to fillna
dropna: whether to drop all null columns
inplace: whether to perform the imputation inplace
Returns: the imputed DataFrame


def OpenFile(self, filepath):

    archive = False
    if '.zip/' in filepath:
      archive = True
      archive_type = '.zip'
    if '.par/' in filepath:
      archive = True
      archive_type = '.par'
    if archive:
      path, archived_file = filepath.split(archive_type)
      path += archive_type
      zip_file = zipfile.ZipFile(path)
      return zip_file.open(archived_file.strip('/'))
    return open(filepath)

open()-replacement that automatically handles zip files.

This assumes there is at most one .zip in the file path.
Args:
filepath: the path to the file to open.
Returns:
An open file-like object.


def FormatArtifacts(self, artifacts):

    artifact_definitions = [artifact.AsDict() for artifact in artifacts]
    yaml_data = yaml.safe_dump_all(artifact_definitions)
    return yaml_data

Formats artifacts to desired output format.

Args:
artifacts (list[ArtifactDefinition]): artifact definitions.

Returns:
str: formatted string of artifact definition.


def runtime_deps(self):
    install_requires = self.metadata['install_requires']
    if (self.metadata['entry_points'] and ('setuptools' not in install_requires)):
        install_requires.append('setuptools')
    return sorted(self.name_convert_deps_list(deps_from_pyp_format(install_requires, runtime=True)))

Returns list of runtime dependencies of the package specified in
setup.py.

Dependencies are in RPM SPECFILE format - see dependency_to_rpm()
for details, but names are already transformed according to
current distro.

Returns:
list of runtime dependencies of the package


def _flush_range(self, buffer, start, end):
    with self._size_lock:
        if (not self._size_synched):
            self._size_synched = True
            try:
                self._size = self.raw._size
            except (ObjectNotFoundError, UnsupportedOperation):
                self._size = 0
    while (start > self._size):
        sleep(self._FLUSH_WAIT)
    self._raw_flush(buffer, start, end)

Flush a buffer to a range of the file.

Meant to be used asynchronously, used to provides parallel flushing of
file parts when applicable.

Args:
buffer (memoryview): Buffer content.
start (int): Start of buffer position to flush.
end (int): End of buffer position to flush.


def _apply_sparse(self, grad, var):
    raise NotImplementedError()

Add ops to apply sparse gradients to `var`.

The IndexedSlices object passed to `grad` in this function is by default
pre-processed in `_apply_sparse_duplicate_indices` to remove duplicate
indices (see its docstring for details). Optimizers which can tolerate or
have correct special cases for duplicate sparse indices may override
`_apply_sparse_duplicate_indices` instead of this function, avoiding that
overhead.

Args:
grad: `IndexedSlices`, with no repeated indices.
var: A `Variable` object.

Returns:
An `Operation`.


def delete(self, uri):

        try:
            self.connect(uri, method='DELETE')
            return True
        except urllib.error.HTTPError:
            return False

Method deletes a Fedora Object in the repository

Args:
uri(str): URI of Fedora Object


def render(self, mode='human'):

        if mode == 'human':

            if self.viewer is None:
                from ._image_viewer import ImageViewer

                if self.spec is None:

                    caption = self._rom_path.split('/')[-1]
                else:

                    caption = self.spec.id

                self.viewer = ImageViewer(
                    caption=caption,
                    height=SCREEN_HEIGHT,
                    width=SCREEN_WIDTH,
                )

            self.viewer.show(self.screen)
        elif mode == 'rgb_array':
            return self.screen
        else:

            render_modes = [repr(x) for x in self.metadata['render.modes']]
            msg = 'valid render modes are: {}'.format(', '.join(render_modes))
            raise NotImplementedError(msg)

Render the environment.

Args:
mode (str): the mode to render with:
- human: render to the current display
- rgb_array: Return an numpy.ndarray with shape (x, y, 3),
representing RGB values for an x-by-y pixel image

Returns:
a numpy array if mode is 'rgb_array', None otherwise


def _build_mask_ds(mask, mask_offset):
    mask_ds = tf.data.Dataset.from_tensor_slices(mask)
    mask_ds = mask_ds.repeat()
    mask_ds = mask_ds.skip(mask_offset)
    return mask_ds

Build the mask dataset to indicate which element to skip.

Args:
mask: `tf.Tensor`, binary mask to apply to all following elements. This
mask should have a length 100.
mask_offset: `tf.Tensor`, Integer specifying from how much the mask
should be shifted for the first element.

Returns:
mask_ds: `tf.data.Dataset`, a dataset returning False for examples to skip
and True for examples to keep.


def receive_datagram(self, data, address):
    if (not self.app):
        logger.debug('Packet received', address, data)
        return False
    try:
        response = self.app.handle_message(data, address)
    except Exception as err:
        logger.error(((('Error processing message from ' + str(address)) + ':') + str(data)))
        logger.error(traceback.format_exc())
        return False
    if response:
        self.send_datagram(response, address)

Executes when UDP data has been received and sends the packet data
to our app to process the request.

Args:
data (str): The raw serialized packet data received.
address (tuple): The address and port of the origin of the received
packet. E.g. (address, port).

Returns:
None


def find(self, key, dynamic_default_value=None, name=None):
    with tf.name_scope(name or '%s_lookup_table_find' % self._name):
        key = tf.convert_to_tensor(key, dtype=self._key_dtype, name='key')
        if dynamic_default_value is not None:
            dynamic_default_value = tf.convert_to_tensor(dynamic_default_value, dtype=self._value_dtype, name='default_value')
        value = gen_simple_hash_table_op.examples_simple_hash_table_find(self.resource_handle, key, dynamic_default_value if dynamic_default_value is not None else self._default_value)
    return value

Looks up `key` in a table, outputs the corresponding value.

The `default_value` is used if key not present in the table.

Args:
key: Key to look up. Must match the table's key_dtype.
dynamic_default_value: The value to use if the key is missing in the
table. If None (by default), the `table.default_value` will be used.
name: A name for the operation (optional).

Returns:
A tensor containing the value in the same shape as `key` using the
table's value type.

Raises:
TypeError: when `key` do not match the table data types.