def infer_types(src, options, loader, init_maximum_depth=INIT_MAXIMUM_DEPTH, maximum_depth=None):
    ctx = context.Context(options, loader, src=src)
    loc, defs = ctx.vm.run_program(src, options.input, init_maximum_depth)
    log.info('===Done running definitions and module-level code===')
    snapshotter = metrics.get_metric('memory', metrics.Snapshot)
    snapshotter.take_snapshot('analyze:infer_types:tracer')
    if maximum_depth is None:
        if not options.quick:
            maximum_depth = MAXIMUM_DEPTH
        elif options.analyze_annotated:
            maximum_depth = QUICK_CHECK_MAXIMUM_DEPTH
        else:
            maximum_depth = QUICK_INFER_MAXIMUM_DEPTH
    ctx.exitpoint = ctx.vm.analyze(loc, defs, maximum_depth)
    snapshotter.take_snapshot('analyze:infer_types:post')
    ast = ctx.vm.compute_types(defs)
    ast = ctx.loader.resolve_ast(ast)
    if ctx.vm.has_unknown_wildcard_imports or any((a in defs for a in abstract_utils.DYNAMIC_ATTRIBUTE_MARKERS)):
        if '__getattr__' not in ast:
            ast = pytd_utils.Concat(ast, ctx.loader.get_default_ast())
    if options.protocols:
        protocols_pytd = ctx.loader.import_name('protocols')
    else:
        protocols_pytd = None
    deps_pytd = ctx.loader.concat_all()
    ast = ast.Visit(visitors.CreateTypeParametersForSignatures())
    if options.protocols:
        log.info('=========== PyTD to solve =============\n%s', pytd_utils.Print(ast))
        ast = convert_structural.convert_pytd(ast, deps_pytd, protocols_pytd)
    else:
        log.info('Solving is turned off. Discarding call traces.')
        ast = ast.Visit(visitors.RemoveUnknownClasses())
        ast = convert_structural.extract_local(ast)
    _maybe_output_debug(options, ctx.program)
    return Analysis(ctx, ast, deps_pytd)

Given Python source return its types.

Args:
src: A string containing Python source code.
options: config.Options object
loader: A load_pytd.Loader instance to load PYI information.
init_maximum_depth: Depth of analysis during module loading.
maximum_depth: Depth of the analysis. Default: unlimited.

Returns:
A tuple of (ast: TypeDeclUnit, builtins: TypeDeclUnit)
Raises:
AssertionError: In case of a bad parameter combination.


def reload_class_methods(self, class_, verbose=True):
    if verbose:
        print(('[util_class] Reloading self=%r as class_=%r' % (self, class_)))
    self.__class__ = class_
    for key in dir(class_):
        func = getattr(class_, key)
        if isinstance(func, types.MethodType):
            inject_func_as_method(self, func, class_=class_, allow_override=True, verbose=verbose)

rebinds all class methods

Args:
self (object): class instance to reload
class_ (type): type to reload as

Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_class import *  # NOQA
>>> self = '?'
>>> class_ = '?'
>>> result = reload_class_methods(self, class_)
>>> print(result)


def AddAdGroup(self, client_customer_id, campaign_id, name, status):

    self.client.SetClientCustomerId(client_customer_id)

    ad_group_service = self.client.GetService('AdGroupService')
    operations = [{
        'operator': 'ADD',
        'operand': {
            'campaignId': campaign_id,
            'name': name,
            'status': status
        }
    }]
    ad_group_service.mutate(operations)

Create a new ad group.

Args:
client_customer_id: str Client Customer Id used to create the AdGroup.
campaign_id: str Id of the campaign to use.
name: str Name to assign to the AdGroup.
status: str Status to assign to the AdGroup when it is created.


def mean_minimum_centroid_distance(item_a, item_b, max_value):

    centroids_a = np.array([item_a.center_of_mass(t) for t in item_a.times])
    centroids_b = np.array([item_b.center_of_mass(t) for t in item_b.times])
    distance_matrix = (centroids_a[:, 0:1] - centroids_b.T[0:1]) ** 2 + (centroids_a[:, 1:] - centroids_b.T[1:]) ** 2
    mean_min_distances = np.sqrt(distance_matrix.min(axis=0).mean() + distance_matrix.min(axis=1).mean())
    return np.minimum(mean_min_distances, max_value) / float(max_value)

RMS difference in the minimum distances from the centroids of one track to the centroids of another track

Args:
item_a: STObject from the first set in TrackMatcher
item_b: STObject from the second set in TrackMatcher
max_value: Maximum distance value used as scaling value and upper constraint.

Returns:
Distance value between 0 and 1.


def build_action(name=None, image_uri=None, commands=None, entrypoint=None, environment=None, pid_namespace=None, flags=None, port_mappings=None, mounts=None, labels=None):
    return {'name': name, 'imageUri': image_uri, 'commands': commands, 'entrypoint': entrypoint, 'environment': environment, 'pidNamespace': pid_namespace, 'flags': flags, 'portMappings': port_mappings, 'mounts': mounts, 'labels': labels}

Build an Action object for a Pipeline request.

Args:
name (str): An optional name for the container.
image_uri (str): The URI to pull the container image from.
commands (List[str]): commands and arguments to run inside the container.
entrypoint (str): overrides the ENTRYPOINT specified in the container.
environment (dict[str,str]): The environment to pass into the container.
pid_namespace (str): The PID namespace to run the action inside.
flags (str): Flags that control the execution of this action.
port_mappings (dict[int, int]): A map of container to host port mappings for
this container.
mounts (List): A list of mounts to make available to the action.
labels (dict[str]): Labels to associate with the action.

Returns:
An object representing an Action resource.


def create(path, mime_type='application/octet-stream', compression_type=CompressionTypes.AUTO):
    filesystem = FileSystems.get_filesystem(path)
    return filesystem.create(path, mime_type, compression_type)

Returns a write channel for the given file path.

Args:
path: string path of the file object to be written to the system
mime_type: MIME type to specify the type of content in the file object
compression_type: Type of compression to be used for this object. See
``CompressionTypes`` for possible values.

Returns: file handle with a ``close`` function for the user to use.


def get_capture_file(self):
    raise NotImplementedError('Base class should not be called directly!')

The sniffer places a capture in the logger directory. This function
enables the caller to obtain the path of that capture.

Returns:
The full path of the current or last capture.


def config_stdio(self, log_configurations: Optional[List[LogConfiguration]]=None, default_level=logging.INFO) -> None:
    if (not log_configurations):
        for logger in self.loggers.values():
            self._restrict_output(logger, default_level)
    else:
        for (component, level) in log_configurations:
            try:
                logger = self.loggers[(self.root + component)]
            except KeyError:
                raise ValueError('Failed to configure component. Invalid name: {}'.format(component))
            self._restrict_output(logger, level)

Configure the stdio `StreamHandler` levels on the specified loggers.
If no log configurations are specified then the `default_level` will be applied to all handlers.

Args:
log_configurations: a list of (component name, log level) tuples
default_level: logging level to apply when no log_configurations are specified


def closing(input_rasterfilename, times):

        input_raster = RasterUtilClass.read_raster(input_rasterfilename)
        closing_raster = input_raster
        for i in range(times):
            closing_raster = RasterUtilClass.raster_dilation(closing_raster)
        for i in range(times):
            closing_raster = RasterUtilClass.raster_erosion(closing_raster)
        return closing_raster

Do closing.

Closing: Dilate firstly, then Erode.

Args:
input_rasterfilename: input original raster image filename.
times: Erode and Dilate times.

Returns:
closing_raster: raster image after close.


def get_backup(self, id_or_uri):

        uri = self.BACKUPS_PATH + '/' + extract_id_from_uri(id_or_uri)
        return self._client.get(id_or_uri=uri)

Get the details for the backup from an Artifact Bundle.

Args:
id_or_uri: ID or URI of the Artifact Bundle.

Returns:
Dict: Backup for an Artifacts Bundle.


def get_paths(self, id_or_uri, path_id_or_uri=''):

        if path_id_or_uri:
            uri = self._client.build_uri(path_id_or_uri)
            if "/paths" not in uri:
                uri = self._client.build_uri(
                    id_or_uri) + "/paths" + "/" + path_id_or_uri

        else:
            uri = self._client.build_uri(id_or_uri) + "/paths"

        return self._client.get(uri)

Gets all paths or a specific attachment path for the specified volume attachment.

Args:
id_or_uri: Can be either the volume attachment id or the volume attachment uri.
path_id_or_uri: Can be either the path id or the path uri.

Returns:
dict: Paths.


def setup(self, keywords=None):

    self._keywords = keywords
    self._output_path = tempfile.mkdtemp()

Sets up the _keywords attribute.

Args:
keywords: pipe separated list of keyword to search


def easeInOutQuad(n):
    _checkRange(n)
    if (n < 0.5):
        return (2 * (n ** 2))
    else:
        n = ((n * 2) - 1)
        return ((- 0.5) * ((n * (n - 2)) - 1))

A quadratic tween function that accelerates, reaches the midpoint, and then decelerates.

Args:
n (float): The time progress, starting at 0.0 and ending at 1.0.

Returns:
(float) The line progress, starting at 0.0 and ending at 1.0. Suitable for passing to getPointOnLine().


def operator_shards(self, qubits: List[cirq.GridQubit]):
    raise NotImplementedError()

Parameter independent Pauli Z strings to measure.

Args:
qubits: List of cirq.GridQubits. objects to measure.

Returns:
List of PauliSum objects whose expectation values are fed to
`operator_expectation` to compute average energy.


def from_json(json_str, allow_pickle=False):
    if six.PY3:
        if isinstance(json_str, bytes):
            json_str = json_str.decode('utf-8')
    UtoolJSONEncoder = make_utool_json_encoder(allow_pickle)
    object_hook = UtoolJSONEncoder._json_object_hook
    val = json.loads(json_str, object_hook=object_hook)
    return val

Decodes a JSON object specified in the utool convention

Args:
json_str (str):
allow_pickle (bool): (default = False)

Returns:
object: val

CommandLine:
python -m utool.util_cache from_json --show

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_cache import *  # NOQA
>>> import utool as ut
>>> json_str = 'just a normal string'
>>> json_str = '["just a normal string"]'
>>> allow_pickle = False
>>> val = from_json(json_str, allow_pickle)
>>> result = ('val = %s' % (ut.repr2(val),))
>>> print(result)


def _ParseSubKey(
      self, parser_mediator, registry_key, parent_path_segments,
      codepage='cp1252'):

    try:
      mrulistex = self._ParseMRUListExValue(registry_key)
    except (ValueError, errors.ParseError) as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to parse MRUListEx value with error: {0!s}'.format(exception))
      return

    if not mrulistex:
      return

    entry_numbers = {}
    values_dict = {}
    value_strings = {}

    found_terminator = False
    for index, entry_number in enumerate(mrulistex):

      if entry_number == -1:
        continue

      if found_terminator:
        parser_mediator.ProduceExtractionWarning((
            'found additional MRUListEx entries after terminator in key: '
            '{0:s}.').format(registry_key.path))

        found_terminator = False

      path_segment = self._ParseMRUListExEntryValue(
          parser_mediator, registry_key, index, entry_number, values_dict,
          value_strings, parent_path_segments, codepage=codepage)

      entry_numbers[entry_number] = path_segment

    event_data = windows_events.WindowsRegistryEventData()
    event_data.key_path = registry_key.path
    event_data.offset = registry_key.offset
    event_data.regvalue = values_dict
    event_data.source_append = self._SOURCE_APPEND
    event_data.urls = self.URLS

    event = time_events.DateTimeValuesEvent(
        registry_key.last_written_time, definitions.TIME_DESCRIPTION_WRITTEN)
    parser_mediator.ProduceEventWithEventData(event, event_data)

    for entry_number, path_segment in iter(entry_numbers.items()):
      sub_key_name = '{0:d}'.format(entry_number)
      sub_key = registry_key.GetSubkeyByName(sub_key_name)
      if not sub_key:
        parser_mediator.ProduceExtractionWarning(
            'Missing BagMRU sub key: {0:d} in key: {1:s}.'.format(
                entry_number, registry_key.path))
        continue

      parent_path_segments.append(path_segment)
      self._ParseSubKey(
          parser_mediator, sub_key, parent_path_segments, codepage=codepage)
      parent_path_segments.pop()

Extract event objects from a MRUListEx Registry key.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
parent_path_segments (list[str]): parent shell item path segments.
codepage (Optional[str]): extended ASCII string codepage.


def top(self, container, ps_args=None):

        u = self._url("/containers/{0}/top", container)
        params = {}
        if ps_args is not None:
            params['ps_args'] = ps_args
        return self._result(self._get(u, params=params), True)

Display the running processes of a container.

Args:
container (str): The container to inspect
ps_args (str): An optional arguments passed to ps (e.g. ``aux``)

Returns:
(str): The output of the top

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def is_first(self, value):

        if value == self._defaults['ai.session.isFirst'] and 'ai.session.isFirst' in self._values:
            del self._values['ai.session.isFirst']
        else:
            self._values['ai.session.isFirst'] = value

The is_first property.

Args:
value (string). the property value.


def generic_visit(self, node):

        if (isinstance(node, ast.stmt) and
                not isinstance(node, ast.FunctionDef)):

            new_node = self.wrap_with_try(node)

            if isinstance(node, self.ast_try_except):
                self.try_except_handler(node)
                return new_node

            super(ErrorsCatchTransformer, self).generic_visit(node)

            return new_node

        return super(ErrorsCatchTransformer, self).generic_visit(node)

Surround node statement with a try/except block to catch errors.

This method is called for every node of the parsed code, and only
changes statement lines.

Args:
node (ast.AST): node statement to surround.


def write_raw_pb(tensor, step=None, name=None):
    with ops.name_scope(name, 'write_raw_pb') as scope:
        if _summary_state.writer is None:
            return constant_op.constant(False)
        if step is None:
            step = get_step()
            if step is None:
                raise ValueError('No step set. Please specify one either through the `step` argument or through tf.summary.experimental.set_step()')

        def record():

            with ops.device('cpu:0'):
                raw_summary_op = gen_summary_ops.write_raw_proto_summary(_summary_state.writer._resource, step, array_ops.identity(tensor), name=scope)
                with ops.control_dependencies([raw_summary_op]):
                    return constant_op.constant(True)
        with ops.device('cpu:0'):
            op = smart_cond.smart_cond(should_record_summaries(), record, _nothing, name='summary_cond')
            if not context.executing_eagerly():
                ops.add_to_collection(ops.GraphKeys._SUMMARY_COLLECTION, op)
            return op

Writes a summary using raw `tf.compat.v1.Summary` protocol buffers.

Experimental: this exists to support the usage of V1-style manual summary
writing (via the construction of a `tf.compat.v1.Summary` protocol buffer)
with the V2 summary writing API.

Args:
tensor: the string Tensor holding one or more serialized `Summary` protobufs
step: Explicit `int64`-castable monotonic step value for this summary. If
omitted, this defaults to `tf.summary.experimental.get_step()`, which must
not be None.
name: Optional string name for this op.

Returns:
True on success, or false if no summary was written because no default
summary writer was available.

Raises:
ValueError: if a default writer exists, but no step was provided and
`tf.summary.experimental.get_step()` is None.


def call(self, input_ids=None, position_ids=None, token_type_ids=None, inputs_embeds=None, past_key_values_length=0, training=False):
    assert not (input_ids is None and inputs_embeds is None)
    if input_ids is not None:
        check_embeddings_within_bounds(input_ids, self.config.vocab_size)
        inputs_embeds = tf.gather(params=self.weight, indices=input_ids)
    input_shape = shape_list(inputs_embeds)[:-1]
    if token_type_ids is None:
        token_type_ids = tf.fill(dims=input_shape, value=0)
    if position_ids is None:
        if input_ids is not None:
            position_ids = self.create_position_ids_from_input_ids(input_ids=input_ids, past_key_values_length=past_key_values_length)
        else:
            position_ids = tf.expand_dims(tf.range(start=self.padding_idx + 1, limit=input_shape[-1] + self.padding_idx + 1), axis=0)
    position_embeds = tf.gather(params=self.position_embeddings, indices=position_ids)
    token_type_embeds = tf.gather(params=self.token_type_embeddings, indices=token_type_ids)
    final_embeddings = inputs_embeds + position_embeds + token_type_embeds
    final_embeddings = self.LayerNorm(inputs=final_embeddings)
    final_embeddings = self.dropout(inputs=final_embeddings, training=training)
    return final_embeddings

Applies embedding based on inputs tensor.

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


def check(cls, status):

        assert cls.trigger is not None, 'Invalid ErrorTrap, trigger not set'
        assert cls.error is not None, 'Invalid ErrorTrap, error not set'

        if status == cls.trigger:

            raise cls.error()

Checks if a status enum matches the trigger originally set, and
if so, raises the appropriate error.

Args:
status (int, enum): A protobuf enum response status to check.

Raises:
AssertionError: If trigger or error were not set.
_ApiError: If the statuses don't match. Do not catch. Will be
caught automatically and sent back to the client.


def generate_pb_config(pb_id: str,
                       pb_config: dict = None,
                       workflow_config: dict = None) -> dict:

    if workflow_config is None:
        workflow_config = dict()
    if pb_config is None:
        pb_config = dict()
    pb_type = pb_config.get('type', choice(PB_TYPES))
    workflow_id = workflow_config.get('id')
    if workflow_id is None:
        if pb_type == 'offline':
            workflow_id = choice(OFFLINE_WORKFLOWS)
        else:
            workflow_id = choice(REALTIME_WORKFLOWS)
    workflow_version = workflow_config.get('version', generate_version())
    workflow_parameters = workflow_config.get('parameters', dict())
    pb_data = dict(
        id=pb_id,
        version=__pb_version__,
        type=pb_type,
        priority=pb_config.get('priority', randint(0, 10)),
        dependencies=pb_config.get('dependencies', []),
        resources_required=pb_config.get('resources_required', []),
        workflow=dict(
            id=workflow_id,
            version=workflow_version,
            parameters=workflow_parameters
        )
    )
    return pb_data

Generate a PB configuration dictionary.

Args:
pb_id (str): Processing Block Id
pb_config (dict, optional) PB configuration.
workflow_config (dict, optional): Workflow configuration

Returns:
dict, PB configuration dictionary.


def pull(self, arm_id, success, failure):
    self.__beta_dist_dict[arm_id].observe(success, failure)

Pull arms.

Args:
arm_id:     Arms master id.
success:    The number of success.
failure:    The number of failure.


def get_cod_ids(self, formula):

        sql = 'select file from data where formula="- %s -"' % \
            Composition(formula).hill_formula
        text = self.query(sql).split("\n")
        cod_ids = []
        for l in text:
            m = re.search(r"(\d+)", l)
            if m:
                cod_ids.append(int(m.group(1)))
        return cod_ids

Queries the COD for all cod ids associated with a formula. Requires
mysql executable to be in the path.

Args:
formula (str): Formula.

Returns:
List of cod ids.


def create_user(self, claims):
    username_claim = settings.USERNAME_CLAIM
    usermodel = get_user_model()
    (user, created) = usermodel.objects.get_or_create(**{usermodel.USERNAME_FIELD: claims[username_claim]})
    if (created or (not user.password)):
        user.set_unusable_password()
        logger.debug("User '{}' has been created.".format(claims[username_claim]))
    return user

Create the user if it doesn't exist yet

Args:
claims (dict): claims from the access token

Returns:
django.contrib.auth.models.User: A Django user


def observe_reward_value(self, state_arr, action_arr):

        if self.__check_goal_flag(action_arr) is True:
            return 1.0
        else:
            self.__move_enemy(action_arr)

            x, y = np.where(action_arr[-1] == 1)
            x, y = x[0], y[0]

            e_dist_sum = 0.0
            for e in range(self.__enemy_num):
                e_dist = np.sqrt(
                    ((x - self.__enemy_pos_list[e][0]) ** 2) + ((y - self.__enemy_pos_list[e][1]) ** 2)
                )
                e_dist_sum += e_dist

            e_dist_penalty = e_dist_sum / self.__enemy_num
            goal_x, goal_y = self.__goal_pos

            if x == goal_x and y == goal_y:
                distance = 0.0
            else:
                distance = np.sqrt(((x - goal_x) ** 2) + (y - goal_y) ** 2)

            if (x, y) in self.__route_long_memory_list:
                repeating_penalty = self.__repeating_penalty
            else:
                repeating_penalty = 0.0

            return 1.0 - distance - repeating_penalty + e_dist_penalty

Compute the reward value.

Args:
state_arr:              `np.ndarray` of state.
action_arr:             `np.ndarray` of action.

Returns:
Reward value.


def DeleteOldFeedItems(client, feed_item_ids, feed):

  if not feed_item_ids:
    return

  feed_item_service = client.GetService('FeedItemService', 'v201809')

  operations = [{
      'operator': 'REMOVE',
      'operand': {
          'feedId': feed['id'],
          'feedItemId': feed_item_id
      }
  } for feed_item_id in feed_item_ids]

  feed_item_service.mutate(operations)

Deletes the old feed items for which extension settings have been created.

Args:
client: an AdWordsClient instance.
feed_item_ids: a list of Feed Item Ids.
feed: the Feed containing the given Feed Item Ids.


def get_visible_devices(device_type=None):
    return context.context().get_visible_devices(device_type)

Get the list of visible physical devices.

Returns the list of `PhysicalDevice`s currently marked as visible to the
runtime. A visible device will have at least one `LogicalDevice` associated
with it once the runtime is initialized.

The following example verifies all visible GPUs have been disabled:

>>> physical_devices = tf.config.list_physical_devices('GPU')
>>> try:
...   # Disable all GPUS
...   tf.config.set_visible_devices([], 'GPU')
...   visible_devices = tf.config.get_visible_devices()
...   for device in visible_devices:
...     assert device.device_type != 'GPU'
... except:
...   # Invalid device or cannot modify virtual devices once initialized.
...   pass

Args:
device_type: (optional string) Only include devices matching this device
type. For example "CPU" or "GPU".

Returns:
List of visible `PhysicalDevice`s


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

Return text in dot.case style.

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

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


def importFile(self, path, mode, outp=None):

        if not os.path.isfile(path):
            raise s_exc.NoSuchFile('File does not exist')

        fname = os.path.split(path)[1]
        parts = fname.rsplit('.', 1)
        ext = parts[1] if len(parts) is 2 else None

        if not ext or ext not in ('crt', 'key', 'p12'):
            mesg = 'importFile only supports .crt, .key, .p12 extensions'
            raise s_exc.BadFileExt(mesg=mesg, ext=ext)

        newpath = s_common.genpath(self.certdir, mode, fname)
        if os.path.isfile(newpath):
            raise s_exc.FileExists('File already exists')

        shutil.copy(path, newpath)
        if outp is not None:
            outp.printf('copied %s to %s' % (path, newpath))

Imports certs and keys into the Synapse cert directory

Args:
path (str): The path of the file to be imported.
mode (str): The certdir subdirectory to import the file into.

Examples:
Import CA certifciate 'mycoolca.crt' to the 'cas' directory.

certdir.importFile('mycoolca.crt', 'cas')

Notes:
importFile does not perform any validation on the files it imports.

Returns:
None


def refresh(self):
    res = gpsoauth.perform_oauth(self._email, self._master_token, self._android_id, service=self._scopes, app='com.google.android.keep', client_sig='38918a453d07199354f8b19af05ec6562ced5788')
    if ('Auth' not in res):
        if ('Token' not in res):
            raise exception.LoginException(res.get('Error'))
    self._auth_token = res['Auth']
    return self._auth_token

Refresh the OAuth token.

Returns:
string: The auth token.

Raises:
LoginException: If there was a problem refreshing the OAuth token.


def post_info(self, name, message):

        self.post_command(OPERATIONS.CMD_POST_MESSAGE,
                          _create_message(name, states.INFO_LEVEL, message))

Asynchronously post a user facing info message about a service.

Args:
name (string): The name of the service
message (string): The user facing info message that will be stored
for the service and can be queried later.


def __init__(self, host='localhost', port=12223):

        channel = grpc.insecure_channel('{}:{}'.format(host, port))
        self._stub = clearly_pb2_grpc.ClearlyServerStub(channel)

Constructs a client instance.

Args:
host (str): the hostname of the server
port (int): the port of the server


def prepare_read(data, method='readlines', mode='r'):

    if hasattr(data, 'readlines'):
        data = getattr(data, method)()
    elif isinstance(data, list):
        if method == 'read':
            return ''.join(data)
    elif isinstance(data, basestring):
        data = getattr(open(data, mode), method)()
    else:
        raise TypeError('Unable to handle data of type %r' % type(data))
    return data

Prepare various input types for parsing.

Args:
data (iter): Data to read
method (str): Method to process data with
mode (str): Custom mode to process with, if data is a file

Returns:
list: List suitable for parsing

Raises:
TypeError: Invalid value for data


def ip_address(address):

    try:
        return IPv4Address(address)
    except (AddressValueError, NetmaskValueError):
        pass

    try:
        return IPv6Address(address)
    except (AddressValueError, NetmaskValueError):
        pass

    if isinstance(address, bytes):
        raise AddressValueError(
            '%r does not appear to be an IPv4 or IPv6 address. '
            'Did you pass in a bytes (str in Python 2) instead of'
            ' a unicode object?' % address)

    raise ValueError('%r does not appear to be an IPv4 or IPv6 address' %
                     address)

Take an IP string/int and return an object of the correct type.

Args:
address: A string or integer, the IP address.  Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.

Returns:
An IPv4Address or IPv6Address object.

Raises:
ValueError: if the *address* passed isn't either a v4 or a v6
address


def _load_file_from_gcs(gcs_file_path, credentials=None):

  gcs_service = _get_storage_service(credentials)

  bucket_name, object_name = gcs_file_path[len('gs:
  request = gcs_service.objects().get_media(
      bucket=bucket_name, object=object_name)

  file_handle = io.BytesIO()
  downloader = MediaIoBaseDownload(file_handle, request, chunksize=1024 * 1024)
  done = False
  while not done:
    _, done = _downloader_next_chunk(downloader)
  filevalue = file_handle.getvalue()
  if not isinstance(filevalue, six.string_types):
    filevalue = filevalue.decode()
  return six.StringIO(filevalue)

Load context from a text file in gcs.

Args:
gcs_file_path: The target file path; should have the 'gs://' prefix.
credentials: Optional credential to be used to load the file from gcs.

Returns:
The content of the text file as a string.


def __init__(self, data_type_definition):

    super(PaddingMap, self).__init__(data_type_definition)
    self.byte_size = None

Initializes a padding data type map.

Args:
data_type_definition (DataTypeDefinition): data type definition.

Raises:
FormatError: if the data type map cannot be determined from the data
type definition.


def check_symmetry(A):

    A = asanyarray(A)
    if A.ndim != 2:
        raise ValueError("Checks symmetry only for bi-dimensional arrays.")

    if A.shape[0] != A.shape[1]:
        return False

    return abs(A - A.T).max() < sqrt(finfo(float).eps)

Check if ``A`` is a symmetric matrix.

Args:
A (array_like): Matrix.

Returns:
bool: ``True`` if ``A`` is symmetric; ``False`` otherwise.


def plot_spectrum_min_max(self, t=0, f_start=None, f_stop=None, logged=False, if_id=0, c=None, **kwargs):

        ax = plt.gca()

        plot_f, plot_data = self.grab_data(f_start, f_stop, if_id)

        if self.header[b'foff'] < 0:
            plot_data = plot_data[..., ::-1]
            plot_f = plot_f[::-1]

        fig_max = plot_data[0].max()
        fig_min = plot_data[0].min()

        print("averaging along time axis...")

        if len(plot_data.shape) > 1:
            plot_max = plot_data.max(axis=0)
            plot_min = plot_data.min(axis=0)
            plot_data = plot_data.mean(axis=0)
        else:
            plot_max = plot_data.max()
            plot_min = plot_data.min()
            plot_data = plot_data.mean()

        dec_fac_x = 1
        MAX_PLT_POINTS = 8*64
        if plot_data.shape[0] > MAX_PLT_POINTS:
            dec_fac_x = int(plot_data.shape[0] / MAX_PLT_POINTS)

        plot_data = rebin(plot_data, dec_fac_x, 1)
        plot_min = rebin(plot_min, dec_fac_x, 1)
        plot_max = rebin(plot_max, dec_fac_x, 1)
        plot_f    = rebin(plot_f, dec_fac_x, 1)

        if logged:
            plt.plot(plot_f, db(plot_data), "
            plt.plot(plot_f, db(plot_max),  "
            plt.plot(plot_f, db(plot_min),  '
            plt.ylabel("Power [dB]")
        else:
            plt.plot(plot_f, plot_data,  "
            plt.plot(plot_f, plot_max,   "
            plt.plot(plot_f, plot_min,   '
            plt.ylabel("Power [counts]")
        plt.xlabel("Frequency [MHz]")
        plt.legend()

        try:
            plt.title(self.header[b'source_name'])
        except KeyError:
            plt.title(self.filename)

        plt.xlim(plot_f[0], plot_f[-1])
        if logged:
            plt.ylim(db(fig_min),db(fig_max))

Plot frequency spectrum of a given file

Args:
logged (bool): Plot in linear (False) or dB units (True)
if_id (int): IF identification (if multiple IF signals in file)
c: color for line
kwargs: keyword args to be passed to matplotlib plot()


def create_model_package_from_algorithm(self, name, description, algorithm_arn, model_data):
    request = {'ModelPackageName': name, 'ModelPackageDescription': description, 'SourceAlgorithmSpecification': {'SourceAlgorithms': [{'AlgorithmName': algorithm_arn, 'ModelDataUrl': model_data}]}}
    try:
        LOGGER.info('Creating model package with name: {}'.format(name))
        self.sagemaker_client.create_model_package(**request)
    except ClientError as e:
        error_code = e.response['Error']['Code']
        message = e.response['Error']['Message']
        if ((error_code == 'ValidationException') and ('ModelPackage already exists' in message)):
            LOGGER.warning('Using already existing model package: {}'.format(name))
        else:
            raise

Create a SageMaker Model Package from the results of training with an Algorithm Package

Args:
name (str): ModelPackage name
description (str): Model Package description
algorithm_arn (str): arn or name of the algorithm used for training.
model_data (str): s3 URI to the model artifacts produced by training


def install(self, connection, partition, table_name=None, index_columns=None, materialize=False,
                logger=None):

        raise NotImplementedError

Installs partition's mpr to the database to allow to execute sql queries over mpr.

Args:
connection:
partition (orm.Partition):
materialize (boolean): if True, create generic table. If False create MED over mpr.

Returns:
str: name of the created table.


def from_string(string):
    lines = string.split('\n')
    toks = lines[0].split()
    lengths = [float(i) for i in toks]
    toks = lines[1].split()
    angles = [float(i) for i in toks[0:3]]
    latt = Lattice.from_lengths_and_angles(lengths, angles)
    sp = []
    coords = []
    for l in lines[4:]:
        m = re.match('\\d+\\s+(\\w+)\\s+([0-9\\-\\.]+)\\s+([0-9\\-\\.]+)\\s+([0-9\\-\\.]+)', l.strip())
        if m:
            sp.append(m.group(1))
            coords.append([float(m.group(i)) for i in range(2, 5)])
    return Cssr(Structure(latt, sp, coords))

Reads a string representation to a Cssr object.

Args:
string (str): A string representation of a CSSR.

Returns:
Cssr object.


def __init__(self, memory_estimator, scheduler_alg="LIST"):

    self._estimator = memory_estimator
    self._scheduler_alg = scheduler_alg
    self._layout_validator = self._estimator.get_layout_validator()
    self._graph = self._estimator.get_graph_interface()
    self._memory_contents = None

    self._model = cp_model.CpModel()

    self._preprocess_input()
    self._initialize_variables()
    self._add_constraints()
    self._build_objective_function()

Uses a auto_mtf.memory_estimator to set up the integer program.

Args:
memory_estimator: a memory_estimator.MemoryEstimator.
scheduler_alg: an optional string, see scheduler.MinimizePeakMemory.


def get_computed_entry(self, inc_structure=True, parameters=None, data=None):
    param_names = {'is_hubbard', 'hubbards', 'potcar_symbols', 'potcar_spec', 'run_type'}
    if parameters:
        param_names.update(parameters)
    params = {p: getattr(self, p) for p in param_names}
    data = ({p: getattr(self, p) for p in data} if (data is not None) else {})
    if inc_structure:
        return ComputedStructureEntry(self.final_structure, self.final_energy, parameters=params, data=data)
    else:
        return ComputedEntry(self.final_structure.composition, self.final_energy, parameters=params, data=data)

Returns a ComputedStructureEntry from the vasprun.

Args:
inc_structure (bool): Set to True if you want
ComputedStructureEntries to be returned instead of
ComputedEntries.
parameters (list): Input parameters to include. It has to be one of
the properties supported by the Vasprun object. If
parameters is None, a default set of parameters that are
necessary for typical post-processing will be set.
data (list): Output data to include. Has to be one of the properties
supported by the Vasprun object.

Returns:
ComputedStructureEntry/ComputedEntry


def __init__(self, workdays=None, holidays=None):

        if workdays is None:
            self.workdays = [MO, TU, WE, TH, FR]
        else:
            self.workdays = sorted(list(set(workdays)))

        if holidays is None:
            holidays = []

        weekdaymap = []
        for wkday in range(0, 7):
            wmap = {}
            wmap['dayofweek'] = wkday
            if wkday in self.workdays:
                wmap['isworkday'] = True
                i = self.workdays.index(wkday)

                if i == len(self.workdays) - 1:
                    wmap['nextworkday'] = self.workdays[0]
                    wmap['offsetnext'] = wmap['nextworkday'] + 7 - wkday
                else:
                    wmap['nextworkday'] = self.workdays[i+1]
                    wmap['offsetnext'] = wmap['nextworkday'] - wkday

                if i == 0:
                    wmap['prevworkday'] = self.workdays[-1]
                    wmap['offsetprev'] = wmap['prevworkday'] - wkday - 7
                else:
                    wmap['prevworkday'] = self.workdays[i-1]
                    wmap['offsetprev'] = wmap['prevworkday'] - wkday
            else:
                wmap['isworkday'] = False

                after = [x for x in range(wkday+1, 7) if x in self.workdays]
                if after:
                    wmap['nextworkday'] = after[0]
                    wmap['offsetnext'] = wmap['nextworkday'] - wkday
                else:
                    wmap['nextworkday'] = self.workdays[0]
                    wmap['offsetnext'] = wmap['nextworkday'] + 7 - wkday

                before = [x for x in range(0, wkday) if x in self.workdays]
                if before:
                    wmap['prevworkday'] = before[-1]
                    wmap['offsetprev'] = wmap['prevworkday'] - wkday
                else:
                    wmap['prevworkday'] = self.workdays[-1]
                    wmap['offsetprev'] = wmap['prevworkday'] - wkday - 7
            weekdaymap.append(DayOfWeek(**wmap))
        self.weekdaymap = weekdaymap

        holidays = set([parsefun(hol) for hol in holidays])
        self.holidays = sorted(
            [hol for hol in holidays if weekdaymap[hol.weekday()].isworkday])

Initialize object and creates the week day map.

Args:
workdays: List or tuple of week days considered 'work days'.
Anything not in this list is considered a rest day.
Defaults to [MO, TU, WE, TH, FR].
holidays: List or tuple of holidays (or strings).
Default is [].


def find_import(self, module_name: str) -> tuple[str, bool] | None:
    module_name_split = module_name.split('.')
    for searchdir in self.options.pythonpath:
        path = path_utils.join(searchdir, *module_name_split)
        init_path = path_utils.join(path, '__init__')
        full_path = self.get_pyi_path(init_path)
        if full_path is not None:
            log.debug('Found module %r with path %r', module_name, init_path)
            return (full_path, True)
        elif self.options.imports_map is None and path_utils.isdir(path):
            log.debug('Created empty module %r with path %r', module_name, init_path)
            full_path = path_utils.join(path, '__init__.pyi')
            return (full_path, False)
        else:
            full_path = self.get_pyi_path(path)
            if full_path is not None:
                log.debug('Found module %r in path %r', module_name, path)
                return (full_path, True)
    return None

Search through pythonpath for a module.

Loops over self.options.pythonpath, taking care of the semantics for
__init__.pyi, and pretending there's an empty __init__.pyi if the path
(derived from module_name) is a directory.

Args:
module_name: module name

Returns:
- (path, file_exists) if we find a path (file_exists will be false if we
have found a directory where we need to create an __init__.pyi)
- None if we cannot find a full path


def get(self, txn_id):

        if txn_id not in self._receipt_db:
            raise KeyError('Unknown transaction id {}'.format(txn_id))

        txn_receipt_bytes = self._receipt_db[txn_id]
        txn_receipt = TransactionReceipt()
        txn_receipt.ParseFromString(txn_receipt_bytes)
        return txn_receipt

Returns the TransactionReceipt

Args:
txn_id (str): the id of the transaction for which the receipt
should be retrieved.

Returns:
TransactionReceipt: The receipt for the given transaction id.

Raises:
KeyError: if the transaction id is unknown.


def _separate_words(string):

    words = []
    separator = ""

    i = 1

    s = 0

    p = string[0:1]

    was_upper = False
    if string.isupper():
        string = string.lower()
        was_upper = True

    while i <= len(string):
        c = string[i:i + 1]

        split = False
        if i < len(string):

            if UPPER.match(c):
                split = True

            elif NOTSEP.match(c) and SEP.match(p):
                split = True

            elif SEP.match(c) and NOTSEP.match(p):
                split = True
        else:

            split = True

        if split:
            if NOTSEP.match(p):
                words.append(string[s:i])
            else:

                if not separator:
                    separator = string[s:s + 1]

                words.append(None)

            s = i

        i += 1
        p = c

    return words, separator, was_upper

Segment string on separator into list of words.

Arguments:
string -- the string we want to process

Returns:
words -- list of words the string got minced to
separator -- the separator char intersecting words
was_upper -- whether string happened to be upper-case


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

        response = self.verifyAccountResponse(subject, vendorSpecific)
        return self._read_boolean_response(response)

See Also: verifyAccountResponse()

Args:
subject:
vendorSpecific:

Returns:


def _create_single_feature_method(feature):
    fx_name = feature.name.lower()
    if ('detection' in fx_name):
        fx_doc = 'Perform {0}.'.format(fx_name.replace('_', ' '))
    else:
        fx_doc = 'Return {desc} information.'.format(desc=fx_name.replace('_', ' '))
    fx_doc += '\n\n    Args:\n        image (:class:`~.{module}.types.Image`): The image to analyze.\n        max_results (int):\n            Number of results to return, does not apply for\n            TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.\n        retry (int): Number of retries to do before giving up.\n        timeout (int): Number of seconds before timing out.\n        kwargs (dict): Additional properties to be set on the\n            :class:`~.{module}.types.AnnotateImageRequest`.\n\n    Returns:\n        :class:`~.{module}.types.AnnotateImageResponse`: The API response.\n    '
    feature_value = {'type': feature}

    def inner(self, image, max_results=None, retry=None, timeout=None, **kwargs):
        'Return a single feature annotation for the given image.\n\n        Intended for use with functools.partial, to create the particular\n        single-feature methods.\n        '
        copied_features = feature_value.copy()
        if (max_results is not None):
            copied_features['max_results'] = max_results
        request = dict(image=image, features=[copied_features], **kwargs)
        response = self.annotate_image(request, retry=retry, timeout=timeout)
        return response
    inner.__name__ = fx_name
    inner.__doc__ = fx_doc
    return inner

Return a function that will detect a single feature.

Args:
feature (enum): A specific feature defined as a member of
:class:`~enums.Feature.Type`.

Returns:
function: A helper function to detect just that feature.


def get_hgnc_id(gene_info, adapter):

    hgnc_id = gene_info.get('hgnc_id')
    hgnc_symbol = gene_info.get('hgnc_symbol')

    true_id = None

    if hgnc_id:
        true_id = int(hgnc_id)
    else:
        gene_result = adapter.hgnc_genes(hgnc_symbol)
        if gene_result.count() == 0:
            raise Exception("No gene could be found for {}".format(hgnc_symbol))
        for gene in gene_result:
            if hgnc_symbol.upper() == gene.hgnc_symbol.upper():
                true_id = gene.hgnc_id
        if not gene_info['hgnc_id']:
            true_id = gene.hgnc_id

    return true_id

Get the hgnc id for a gene

The proprity order will be
1. if there is a hgnc id this one will be choosen
2. if the hgnc symbol matches a genes proper hgnc symbol
3. if the symbol ony matches aliases on several genes one will be
choosen at random

Args:
gene_info(dict)
adapter

Returns:
true_id(int)


def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
    super(LongInteger, self).write(ostream, kmip_version=kmip_version)
    ostream.write(pack('!q', self.value))

Write the encoding of the LongInteger to the output stream.

Args:
ostream (stream): A buffer to contain the encoded bytes of a
LongInteger. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.


def create_epub(self, output_directory, epub_name=None):

        def createTOCs_and_ContentOPF():
            for epub_file, name in ((self.toc_html, 'toc.html'), (self.toc_ncx, 'toc.ncx'), (self.opf, 'content.opf'),):
                epub_file.add_chapters(self.chapters)
                epub_file.write(os.path.join(self.OEBPS_DIR, name))

        def create_zip_archive(epub_name):
            try:
                assert isinstance(epub_name, basestring) or epub_name is None
            except AssertionError:
                raise TypeError('epub_name must be string or None')
            if epub_name is None:
                epub_name = self.title
            epub_name = ''.join([c for c in epub_name if c.isalpha() or c.isdigit() or c == ' ']).rstrip()
            epub_name_with_path = os.path.join(output_directory, epub_name)
            try:
                os.remove(os.path.join(epub_name_with_path, '.zip'))
            except OSError:
                pass
            shutil.make_archive(epub_name_with_path, 'zip', self.EPUB_DIR)
            return epub_name_with_path + '.zip'

        def turn_zip_into_epub(zip_archive):
            epub_full_name = zip_archive.strip('.zip') + '.epub'
            try:
                os.remove(epub_full_name)
            except OSError:
                pass
            os.rename(zip_archive, epub_full_name)
            return epub_full_name
        createTOCs_and_ContentOPF()
        epub_path = turn_zip_into_epub(create_zip_archive(epub_name))
        return epub_path

Create an epub file from this object.

Args:
output_directory (str): Directory to output the epub file to
epub_name (Option[str]): The file name of your epub. This should not contain
.epub at the end. If this argument is not provided, defaults to the title of the epub.


def print_resolve_diff(self, other, heading=None):

        d = self.get_resolve_diff(other)
        if not d:
            return

        rows = []
        if heading is True and self.load_path and other.load_path:
            a = os.path.basename(self.load_path)
            b = os.path.basename(other.load_path)
            heading = (a, b)
        if isinstance(heading, tuple):
            rows.append(list(heading) + [""])
            rows.append(('-' * len(heading[0]), '-' * len(heading[1]), ""))

        newer_packages = d.get("newer_packages", {})
        older_packages = d.get("older_packages", {})
        added_packages = d.get("added_packages", set())
        removed_packages = d.get("removed_packages", set())

        if newer_packages:
            for name, pkgs in newer_packages.iteritems():
                this_pkg = pkgs[0]
                other_pkg = pkgs[-1]
                diff_str = "(+%d versions)" % (len(pkgs) - 1)
                rows.append((this_pkg.qualified_name,
                            other_pkg.qualified_name,
                            diff_str))

        if older_packages:
            for name, pkgs in older_packages.iteritems():
                this_pkg = pkgs[0]
                other_pkg = pkgs[-1]
                diff_str = "(-%d versions)" % (len(pkgs) - 1)
                rows.append((this_pkg.qualified_name,
                            other_pkg.qualified_name,
                            diff_str))

        if added_packages:
            for pkg in sorted(added_packages, key=lambda x: x.name):
                rows.append(("-", pkg.qualified_name, ""))

        if removed_packages:
            for pkg in sorted(removed_packages, key=lambda x: x.name):
                rows.append((pkg.qualified_name, "-", ""))

        print '\n'.join(columnise(rows))

Print the difference between the resolve of two contexts.

Args:
other (`ResolvedContext`): Context to compare to.
heading: One of:
- None: Do not display a heading;
- True: Display the filename of each context as a heading, if
both contexts have a filepath;
- 2-tuple: Use the given two strings as headings - the first is
the heading for `self`, the second for `other`.


def create_query(self, fields=None):
    if (fields is None):
        return Query(self.fields)
    non_contained_fields = (set(fields) - set(self.fields))
    if non_contained_fields:
        raise BaseLunrException('Fields {} are not part of the index', non_contained_fields)
    return Query(fields)

Convenience method to create a Query with the Index's fields.

Args:
fields (iterable, optional): The fields to include in the Query,
defaults to the Index's `all_fields`.

Returns:
Query: With the specified fields or all the fields in the Index.


def _list_records_internal(self, rtype=None, name=None, content=None, identifier=None):
    name = (self._full_name(name) if (name is not None) else name)
    if (self._records is None):
        records = []
        rows = self._get_dns_entry_trs()
        for (index, row) in enumerate(rows):
            self._log('DNS list entry', row)
            try:
                rec = {}
                if row.has_attr('ondblclick'):
                    rec['id'] = int(row['ondblclick'].split('id=')[1].split("'")[0])
                else:
                    rec['id'] = (- index)
                columns = row.find_all('td')
                rec['name'] = (columns[0].string or '').strip()
                rec['type'] = (columns[1].contents[1] or '').strip()
                rec['content'] = (columns[2].string or '').strip()
                rec['priority'] = (columns[3].string or '').strip()
                rec['ttl'] = (columns[4].string or '').strip()
                if rec['priority']:
                    rec['priority'] = int(rec['priority'])
                if rec['ttl']:
                    rec['ttl'] = int(rec['ttl'])
            except Exception as error:
                errmsg = 'Cannot parse DNS entry ({}).'.format(error)
                LOGGER.warning(errmsg)
                raise AssertionError(errmsg)
            records.append(rec)
        self._records = records
    records = self._filter_records(self._records, rtype, name, content, identifier)
    LOGGER.debug('Final records (%d): %s', len(records), records)
    return records

Filter and list DNS entries of domain zone on Easyname.
Easyname shows each entry in a HTML table row and each attribute on a
table column.

Args:
[rtype] (str): Filter by DNS rtype (e.g. A, TXT, MX, etc)
[name] (str): Filter by the name of the DNS entry, e.g the domain for
which a MX entry shall be valid.
[content] (str): Filter by the content of the DNS entry, e.g. the
mail server hostname for a MX entry.
[identifier] (str): Filter by the easyname id of the DNS entry.

Returns:
list: A list of DNS entries. A DNS entry is an object with DNS
attribute names as keys (e.g. name, content, priority, etc)
and additionally an id.

Raises:
AssertionError: When a request returns unexpected or unknown data.


def ApprovalRevokeRaw(aff4_path, token):
    try:
        urn = rdf_client.ClientURN(aff4_path)
    except type_info.TypeValueError:
        urn = rdfvalue.RDFURN(aff4_path)
    approval_urn = aff4.ROOT_URN.Add('ACL').Add(urn.Path()).Add(token.username).Add(utils.EncodeReasonString(token.reason))
    super_token = access_control.ACLToken(username='raw-approval-superuser')
    super_token.supervisor = True
    approval_request = aff4.FACTORY.Open(approval_urn, mode='rw', token=super_token)
    approval_request.DeleteAttribute(approval_request.Schema.APPROVER)
    approval_request.Close()

Revokes an approval for a given token.

This method requires raw datastore access to manipulate approvals directly.

Args:
aff4_path: The aff4_path or client id the approval should be created for.
token: The token that should be revoked.


def multiprocess_mapping(func, iterable):
    if (os.name == 'nt'):
        return list(map(func, iterable))
    try:
        p = multiprocessing.Pool()
        return_data = list(p.imap(func, iterable))
        p.close()
        p.join()
        return return_data
    except OSError:
        return list(map(func, iterable))

Multiprocess mapping the given function on the given iterable.

This only works in Linux and Mac systems since Windows has no forking capability. On Windows we fall back on
single processing. Also, if we reach memory limits we fall back on single cpu processing.

Args:
func (func): the function to apply
iterable (iterable): the iterable with the elements we want to apply the function on


def run(image, name=None, command=None, environment=None, ports=None, volumes=None):
    if (ports and (not name)):
        abort('The ports flag currently only works if you specify a container name')
    if ports:
        ports = [parse_port_spec(p) for p in ports.split(',')]
    else:
        ports = None
    if environment:
        environment = dict([x.split('=') for x in environment.split(',')])
    else:
        environment = None
    if volumes:
        volumes = dict([x.split(':') for x in volumes.split(',')])
    else:
        volumes = None
    run_container(image=image, name=name, command=command, ports=ports, environment=environment, volumes=volumes)

Run a docker container.

Args:
* image: Docker image to run, e.g. orchardup/redis, quay.io/hello/world
* name=None: Container name
* command=None: Command to execute
* environment: Comma separated environment variables in the format NAME=VALUE
* ports=None: Comma separated port specs in the format CONTAINER_PORT[:EXPOSED_PORT][/PROTOCOL]
* volumes=None: Comma separated volumes in the format HOST_DIR:CONTAINER_DIR

Examples:
* fab docker.run:orchardup/redis,name=redis,ports=6379
* fab docker.run:quay.io/hello/world,name=hello,ports="80:8080,1000/udp",volumes="/docker/hello/log:/var/log"
* fab docker.run:andreasjansson/redis,environment="MAX_MEMORY=4G,FOO=bar",ports=6379


def symbolic_trace(model: 'PreTrainedModel', input_names: Optional[list[str]]=None, disable_check: bool=False, tracer_cls: type[HFTracer]=HFTracer) -> GraphModule:
    if input_names is None:
        input_names = model.dummy_inputs.keys()
    input_names = list(input_names)
    concrete_args = get_concrete_args(model, input_names)
    if not disable_check:
        check_if_model_is_supported(model)
    if 'past_key_values' in input_names and (not getattr(model.config, 'use_cache', False)):
        logger.warning('`past_key_values` were specified as input names, but model.config.use_cache = False, this might lead to unexpected behavior.')
    if 'past_key_values' not in input_names and getattr(model.config, 'use_cache', False):
        logger.warning('`past_key_values` were not specified as input names, but model.config.use_cache = True. Setting model.config.use_cache = False.')
        model.config.use_cache = False
    tracer = tracer_cls()
    traced_graph = tracer.trace(model, concrete_args=concrete_args)
    traced = torch.fx.GraphModule(model, traced_graph)
    traced.config = model.config
    traced.class_for_deserialization = model.__class__
    traced.device = model.device
    return traced

Performs symbolic tracing on the model.

Args:
model ([`PretrainedModel`]):
The model to trace.
input_names (`List[str]`, *optional*):
The names of the inputs of the traced model. If unset, model.dummy_inputs.keys() are used instead.
disable_check (`bool`, *optional*, defaults to `False`):
If `True`, no check is done before trying to trace the model, this is mostly usesul for debugging purposes.
tracer_cls (`Type[HFTracer]`, *optional*, defaults to `HFTracer`):
The tracer class to use for instantiating the tracer. If unset, `HFTracer` is used instead.

Returns:
`torch.fx.GraphModule`: A GraphModule constructed by recording operations seen while tracing the model.

Example:

```python
from transformers.utils.fx import symbolic_trace

traced_model = symbolic_trace(model, input_names=["input_ids", "attention_mask", "token_type_ids"])
```


def expand_dims(x, axis):
    if any_symbolic_tensors((x,)):
        return ExpandDims(axis=axis).symbolic_call(x)
    return backend.numpy.expand_dims(x, axis)

Expand the shape of a tensor.

Insert a new axis at the `axis` position in the expanded tensor shape.

Args:
x: Input tensor.
axis: Position in the expanded axes where the new axis
(or axes) is placed.

Returns:
Output tensor with the number of dimensions increased.


def IsInitializerList(clean_lines, linenum):
    for i in xrange(linenum, 1, (- 1)):
        line = clean_lines.elided[i]
        if (i == linenum):
            remove_function_body = Match('^(.*)\\{\\s*$', line)
            if remove_function_body:
                line = remove_function_body.group(1)
        if Search('\\s:\\s*\\w+[({]', line):
            return True
        if Search('\\}\\s*,\\s*$', line):
            return True
        if Search('[{};]\\s*$', line):
            return False
    return False

Check if current line is inside constructor initializer list.

Args:
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
Returns:
True if current line appears to be inside constructor initializer
list, False otherwise.


def change_to_count_endpoint(endpoint):

    tokens = filter(lambda x: x != '', re.split("[/:]", endpoint))
    filt_tokens = list(filter(lambda x: x != "https", tokens))
    last = filt_tokens[-1].split('.')[0]
    filt_tokens[-1] = last
    if last == 'counts':
        return endpoint
    else:
        return "https:

Utility function to change a normal endpoint to a ``count`` api
endpoint. Returns the same endpoint if it's already a valid count endpoint.
Args:
endpoint (str): your api endpoint

Returns:
str: the modified endpoint for a count endpoint.


def stats(self, **kwargs):
    return self.client.api.stats(self.id, **kwargs)

Stream statistics for this container. Similar to the
``docker stats`` command.

Args:
decode (bool): If set to true, stream will be decoded into dicts
on the fly. Only applicable if ``stream`` is True.
False by default.
stream (bool): If set to false, only the current stats will be
returned instead of a stream. True by default.

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def deserialize_dtype(d):

    if isinstance(d['descr'], six.string_types):
        return np.dtype(d['descr'])
    descr = []
    for col in d['descr']:
        col_descr = []
        for c in col:
            if isinstance(c, six.string_types):
                col_descr.append(str(c))
            elif type(c) is list:
                col_descr.append(tuple(c))
            else:
                col_descr.append(c)
        descr.append(tuple(col_descr))
    return np.dtype(descr)

Deserializes a JSONified :obj:`numpy.dtype`.

Args:
d (:obj:`dict`): A dictionary representation of a :obj:`dtype` object.

Returns:
A :obj:`dtype` object.


def Add(self, category, label, age):

    now = rdfvalue.RDFDatetime.Now()
    category = utils.SmartUnicode(category)

    for active_time in self.active_days:
      self.categories[active_time].setdefault(label, {})
      if (now - age).seconds < active_time * 24 * 60 * 60:
        self.categories[active_time][label][
            category] = self.categories[active_time][label].get(category, 0) + 1

Adds another instance of this category into the active_days counter.

We automatically count the event towards all relevant active_days. For
example, if the category "Windows" was seen 8 days ago it will be counted
towards the 30 day active, 14 day active but not against the 7 and 1 day
actives.

Args:
category: The category name to account this instance against.
label: Client label to which this should be applied.
age: When this instance occurred.


def center_crop(self, image: np.ndarray, crop_size: Dict[str, int], size: Optional[int]=None, data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None, **kwargs) -> np.ndarray:
    size = self.size if size is None else size
    size = get_size_dict(size)
    crop_size = get_size_dict(crop_size, param_name='crop_size')
    height, width = get_image_size(image, channel_dim=input_data_format)
    min_dim = min(height, width)
    cropped_height = size['height'] / crop_size['height'] * min_dim
    cropped_width = size['width'] / crop_size['width'] * min_dim
    return center_crop(image, size=(cropped_height, cropped_width), data_format=data_format, input_data_format=input_data_format, **kwargs)

Center crop an image to `(size["height"] / crop_size["height"] * min_dim, size["width"] / crop_size["width"] *
min_dim)`. Where `min_dim = min(size["height"], size["width"])`.

If the input size is smaller than `crop_size` along any edge, the image will be padded with zeros and then
center cropped.

Args:
image (`np.ndarray`):
Image to center crop.
crop_size (`Dict[str, int]`):
Desired output size after applying the center crop.
size (`Dict[str, int]`, *optional*):
Size of the image after resizing. If not provided, the self.size attribute will be used.
data_format (`str` or `ChannelDimension`, *optional*):
The channel dimension format of the image. If not provided, it will be the same as the input image.
input_data_format (`str` or `ChannelDimension`, *optional*):
The channel dimension format of the input image. If not provided, it will be inferred.


def initAttrs(cls):

        def __init__(self, skype=None, raw=None, *args, **kwargs):
            super(cls, self).__init__(skype, raw)

            for i in range(len(args)):
                kwargs[cls.attrs[i]] = args[i]

            unknown = set(kwargs) - set(cls.attrs)
            if unknown:
                unknownDesc = "an unexpected keyword argument" if len(unknown) == 1 else "unexpected keyword arguments"
                unknownList = ", ".join("'{0}'".format(k) for k in sorted(unknown))
                raise TypeError("__init__() got {0} {1}".format(unknownDesc, unknownList))

            for k in cls.attrs:
                setattr(self, k, kwargs.get(k, cls.defaults.get(k)))

        setattr(cls, "__init__", __init__)
        return cls

Class decorator: automatically generate an ``__init__`` method that expects args from cls.attrs and stores them.

Args:
cls (class): class to decorate

Returns:
class: same, but modified, class


def _get_raw_data_feature_spec_per_column(self, typ: type, col_name: str) -> tf.io.VarLenFeature:
    typ = native_type_compatibility.convert_builtin_to_typing(typ)
    primitive_containers_type = (list, collections.abc.Sequence)
    is_primitive_container = typing.get_origin(typ) in primitive_containers_type
    if is_primitive_container:
        dtype = typing.get_args(typ)[0]
        if len(typing.get_args(typ)) > 1 or typing.get_origin(dtype) == Union:
            raise RuntimeError(f'Union type is not supported for column: {col_name}. Please pass a PCollection with valid schema for column {col_name} by passing a single type in container. For example, list[int].')
    elif issubclass(typ, np.generic) or typ in _default_type_to_tensor_type_map:
        dtype = typ
    else:
        raise TypeError(f'Unable to identify type: {typ} specified on column: {col_name}. Please provide a valid type from the following: {_default_type_to_tensor_type_map.keys()}')
    return tf.io.VarLenFeature(_default_type_to_tensor_type_map[dtype])

Return a FeatureSpec object to be used with
tft_beam.AnalyzeAndTransformDataset
Args:
typ: A type of the column.
col_name: A name of the column.
Returns:
A FeatureSpec object.


def boundary(self):
    return (int(self.WESTERNMOST_LONGITUDE), int(self.EASTERNMOST_LONGITUDE), int(self.MINIMUM_LATITUDE), int(self.MAXIMUM_LATITUDE))

Get the image boundary

Returns:
A tupple composed by the westernmost_longitude,
the westernmost_longitude, the minimum_latitude and
the maximum_latitude.


def _assertOpOutputMatchesExpected(self, params, solution, high_level=True, rtol=0.001, atol=1e-05):
    input = params['input']
    diagonal = params['diagonal']
    with self.session() as session:
        for dtype in self.numeric_types - {np.int8, np.uint8}:
            expected = solution.astype(dtype)
            with self.test_scope():
                params['input'] = array_ops.placeholder(dtype, input.shape, name='input')
                params['diagonal'] = array_ops.placeholder(dtype, diagonal.shape, name='diagonal')
                if high_level:
                    output = array_ops.matrix_set_diag(**params)
                else:
                    output = gen_array_ops.matrix_set_diag(**params)
            result = session.run(output, {params['input']: input.astype(dtype), params['diagonal']: diagonal.astype(dtype)})
            self.assertEqual(output.dtype, expected.dtype)
            self.assertAllCloseAccordingToType(expected, result, rtol=rtol, atol=atol, bfloat16_rtol=0.03)

Verifies that matrix_set_diag produces `solution` when fed `params`.

Args:
params: dictionary containing input parameters to matrix_set_diag.
solution: numpy array representing the expected output of matrix_set_diag.
high_level: call high_level matrix_set_diag
rtol: relative tolerance for equality test.
atol: absolute tolerance for equality test.


def _RemoveIllegalXMLCharacters(self, xml_string):

    if not isinstance(xml_string, py2to3.STRING_TYPES):
      return xml_string

    return self._ILLEGAL_XML_RE.sub('\ufffd', xml_string)

Removes illegal characters for XML.

If the input is not a string it will be returned unchanged.

Args:
xml_string (str): XML with possible illegal characters.

Returns:
str: XML where all illegal characters have been removed.


def cafferesnet101(num_classes=1000, pretrained='imagenet'):

    model = ResNet(Bottleneck, [3, 4, 23, 3], num_classes=num_classes)
    if pretrained is not None:
        settings = pretrained_settings['cafferesnet101'][pretrained]
        assert num_classes == settings['num_classes'], \
            "num_classes should be {}, but is {}".format(settings['num_classes'], num_classes)
        model.load_state_dict(model_zoo.load_url(settings['url']))
        model.input_space = settings['input_space']
        model.input_size = settings['input_size']
        model.input_range = settings['input_range']
        model.mean = settings['mean']
        model.std = settings['std']
    return model

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


def _insert_vars(self, path: str, data: dict) -> str:
    data = data.copy()
    while True:
        match = re.search(self.VAR_REPLACE_REGEX, path)
        if (not match):
            return path
        replace_from = match.group(0)
        replace_with = str(data.get(match.group(1)))
        path = path.replace(replace_from, replace_with)

Inserts variables into the ESI URL path.

Args:
path: raw ESI URL path
data: data to insert into the URL

Returns:
path with variables filled


def has_no_narrow_start(neuron, frac=0.9):
    bad_ids = [(neurite.root_node.id, [neurite.root_node.points[1]]) for neurite in neuron.neurites if (neurite.root_node.points[1][COLS.R] < (frac * neurite.root_node.points[2][COLS.R]))]
    return CheckResult((len(bad_ids) == 0), bad_ids)

Check if neurites have a narrow start

Arguments:
neuron(Neuron): The neuron object to test
frac(float): Ratio that the second point must be smaller than the first

Returns:
CheckResult with a list of all first segments of neurites with a narrow start


def crcMeterRead(self, raw_read, def_buf):
    try:
        if (len(raw_read) == 0):
            ekm_log((('(' + self.m_context) + ') Empty return read.'))
            return False
        sent_crc = self.calc_crc16(raw_read[1:(- 2)])
        logstr = ((('(' + self.m_context) + ')CRC sent = ') + str(def_buf['crc16'][MeterData.StringValue]))
        logstr += (' CRC calc = ' + sent_crc)
        ekm_log(logstr)
        if (int(def_buf['crc16'][MeterData.StringValue], 16) == int(sent_crc, 16)):
            return True
    except struct.error:
        ekm_log(str(sys.exc_info()))
        for frame in traceback.extract_tb(sys.exc_info()[2]):
            (fname, lineno, fn, text) = frame
            ekm_log(('Error in %s on line %d' % (fname, lineno)))
        return False
    except TypeError:
        ekm_log(str(sys.exc_info()))
        for frame in traceback.extract_tb(sys.exc_info()[2]):
            (fname, lineno, fn, text) = frame
            ekm_log(('Error in %s on line %d' % (fname, lineno)))
        return False
    except ValueError:
        ekm_log(str(sys.exc_info()))
        for frame in traceback.extract_tb(sys.exc_info()[2]):
            (fname, lineno, fn, text) = frame
            ekm_log(('Error in %s on line %d' % (fname, lineno)))
        return False
    return False

Internal read CRC wrapper.

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

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


def start_router(router_class, router_name):

    handle = router_class.remote(router_name)
    ray.experimental.register_actor(router_name, handle)
    handle.start.remote()
    return handle

Wrapper for starting a router and register it.

Args:
router_class: The router class to instantiate.
router_name: The name to give to the router.

Returns:
A handle to newly started router actor.


def load_object(obj) -> object:

    if isinstance(obj, str):
        if ':' in obj:
            module_name, obj_name = obj.split(':')
            if not module_name:
                module_name = '.'
        else:
            module_name = obj
        obj = importlib.import_module(module_name)
        if obj_name:
            attrs = obj_name.split('.')
            for attr in attrs:
                obj = getattr(obj, attr)
    return obj

Load an object.

Args:
obj (str|object): Load the indicated object if this is a string;
otherwise, return the object as is.

To load a module, pass a dotted path like 'package.module';
to load an an object from a module pass a path like
'package.module:name'.

Returns:
object


def GetAllPluginInformation(cls, show_all=True):
    results = []
    for plugin_class in iter(cls._plugin_classes.values()):
        plugin_object = plugin_class()
        if ((not show_all) and (not plugin_class.ENABLE_IN_EXTRACTION)):
            continue
        (doc_string, _, _) = plugin_class.__doc__.partition('\n')
        type_string = cls._PLUGIN_TYPE_STRINGS.get(plugin_object.plugin_type)
        information_tuple = (plugin_object.plugin_name, doc_string, type_string)
        results.append(information_tuple)
    return sorted(results)

Retrieves a list of the registered analysis plugins.

Args:
show_all (Optional[bool]): True if all analysis plugin names should
be listed.

Returns:
list[tuple[str, str, str]]: the name, docstring and type string of each
analysis plugin in alphabetical order.


def __init__(self, indices, values, dense_shape):
    with ops.name_scope(None, 'SparseTensor', [indices, values, dense_shape]):
        indices = ops.convert_to_tensor(indices, name='indices', dtype=dtypes.int64)
        values = ops.convert_to_tensor(values, name='values')
        dense_shape = ops.convert_to_tensor(dense_shape, name='dense_shape', dtype=dtypes.int64)
        dense_shape_default = tensor_util.constant_value_as_shape(dense_shape)
    self._indices = indices
    self._values = values
    self._dense_shape = dense_shape
    self._dense_shape_default = dense_shape_default
    indices_shape = indices.shape.with_rank(2)
    values_shape = values.shape.with_rank(1)
    dense_shape_shape = dense_shape.shape.with_rank(1)
    indices_shape.dims[0].assert_is_compatible_with(values_shape.dims[0])
    indices_shape.dims[1].assert_is_compatible_with(dense_shape_shape.dims[0])

Creates a `SparseTensor`.

Args:
indices: A 2-D int64 tensor of shape `[N, ndims]`.
values: A 1-D tensor of any type and shape `[N]`.
dense_shape: A 1-D int64 tensor of shape `[ndims]`.

Raises:
ValueError: When building an eager SparseTensor if `dense_shape` is
unknown or contains unknown elements (None or -1).


def _ParseLogline(self, parser_mediator, structure):
    (month, day_of_month, year, hours, minutes, seconds, milliseconds) = structure.date_time
    time_elements_tuple = (year, month, day_of_month, hours, minutes, seconds, milliseconds)
    try:
        date_time = dfdatetime_time_elements.TimeElementsInMilliseconds(time_elements_tuple=time_elements_tuple)
    except ValueError:
        parser_mediator.ProduceExtractionWarning('invalid date time value: {0!s}'.format(structure.date_time))
        return
    event_data = SkyDriveOldLogEventData()
    event_data.log_level = structure.log_level
    event_data.offset = self.offset
    event_data.source_code = structure.source_code
    event_data.text = structure.text
    event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_ADDED)
    parser_mediator.ProduceEventWithEventData(event, event_data)
    self._last_date_time = date_time
    self._last_event_data = event_data

Parse a logline and store appropriate attributes.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
structure (pyparsing.ParseResults): structure of tokens derived from
a line of a text file.


def render(self, value: Any, *, name: Optional[str]=None, root_path: Optional[utils.KeyPath]=None, **kwargs) -> Content:

Renders the input value.

Args:
value: The value to render.
name: (Optional) The referred name of the value from its container.
root_path: (Optional) The path of `value` under its object tree.
**kwargs: Additional keyword arguments passed from `pg.view` or wrapper
functions (e.g. `pg.to_html`).

Returns:
The rendered content.


def _full_axis_reduce(self, axis, func, alternate_index=None):
    result = self.data.map_across_full_axis(axis, func)
    if (axis == 0):
        columns = (alternate_index if (alternate_index is not None) else self.columns)
        return self.__constructor__(result, index=['__reduced__'], columns=columns)
    else:
        index = (alternate_index if (alternate_index is not None) else self.index)
        return self.__constructor__(result, index=index, columns=['__reduced__'])

Applies map that reduce Manager to series but require knowledge of full axis.

Args:
func: Function to reduce the Manager by. This function takes in a Manager.
axis: axis to apply the function to.
alternate_index: If the resulting series should have an index
different from the current query_compiler's index or columns.

Return:
Pandas series containing the reduced data.


def add_link(self, name: str, url: str) -> None:

Adds a related link to current trial.

Added links can be retrieved from the `Trial.related_links` property via
`pg.poll_result`.

Args:
name: Name for the related link.
url: URL for this link.


def __init__(self, name, aliases=None, description=None, urls=None):

    super(FixedSizeDataTypeDefinition, self).__init__(
        name, aliases=aliases, description=description, urls=urls)
    self.size = definitions.SIZE_NATIVE
    self.units = 'bytes'

Initializes a fixed-size data type definition.

Args:
name (str): name.
aliases (Optional[list[str]]): aliases.
description (Optional[str]): description.
urls (Optional[list[str]]): URLs.


def predict_dataset(self, df):

        if len(list(df.columns)) == 2:
            df.columns = ["A", "B"]
        if self.model is None:
            raise AssertionError("Model has not been trained before predictions")
        df2 = DataFrame()

        for idx, row in df.iterrows():
            df2 = df2.append(row, ignore_index=True)
            df2 = df2.append({'A': row["B"], 'B': row["A"]}, ignore_index=True)
        return predict.predict(deepcopy(df2), deepcopy(self.model))[::2]

Runs Jarfo independently on all pairs.

Args:
x (pandas.DataFrame): a CEPC format Dataframe.
kwargs (dict): additional arguments for the algorithms

Returns:
pandas.DataFrame: a Dataframe with the predictions.


def assignHolidayDate(self, holiday, month, day):
    holiday += 1
    if ((month > 12) or (month < 0) or (day > 31) or (day < 0) or (holiday < 1) or (holiday > Extents.Holidays)):
        ekm_log(((((('Out of bounds: month ' + str(month)) + ' day ') + str(day)) + ' holiday ') + str(holiday)))
        return False
    day_str = (('Holiday_' + str(holiday)) + '_Day')
    mon_str = (('Holiday_' + str(holiday)) + '_Month')
    if (day_str not in self.m_holiday_date_params):
        ekm_log(('Incorrect index: ' + day_str))
        return False
    if (mon_str not in self.m_holiday_date_params):
        ekm_log(('Incorrect index: ' + mon_str))
        return False
    self.m_holiday_date_params[day_str] = day
    self.m_holiday_date_params[mon_str] = month
    return True

Set a singe holiday day and month in object buffer.

There is no class style enum for holidays.

Args:
holiday (int): 0-19 or range(Extents.Holidays).
month (int): Month 1-12.
day (int): Day 1-31

Returns:
bool: True on completion.


def _send_offset_requests(self, timestamps):
    timestamps_by_node = collections.defaultdict(dict)
    for (partition, timestamp) in six.iteritems(timestamps):
        node_id = self._client.cluster.leader_for_partition(partition)
        if (node_id is None):
            self._client.add_topic(partition.topic)
            log.debug('Partition %s is unknown for fetching offset, wait for metadata refresh', partition)
            return Future().failure(Errors.StaleMetadata(partition))
        elif (node_id == (- 1)):
            log.debug('Leader for partition %s unavailable for fetching offset, wait for metadata refresh', partition)
            return Future().failure(Errors.LeaderNotAvailableError(partition))
        else:
            timestamps_by_node[node_id][partition] = timestamp
    list_offsets_future = Future()
    responses = []
    node_count = len(timestamps_by_node)

    def on_success(value):
        responses.append(value)
        if (len(responses) == node_count):
            offsets = {}
            for r in responses:
                offsets.update(r)
            list_offsets_future.success(offsets)

    def on_fail(err):
        if (not list_offsets_future.is_done):
            list_offsets_future.failure(err)
    for (node_id, timestamps) in six.iteritems(timestamps_by_node):
        _f = self._send_offset_request(node_id, timestamps)
        _f.add_callback(on_success)
        _f.add_errback(on_fail)
    return list_offsets_future

Fetch offsets for each partition in timestamps dict. This may send
request to multiple nodes, based on who is Leader for partition.

Arguments:
timestamps (dict): {TopicPartition: int} mapping of fetching
timestamps.

Returns:
Future: resolves to a mapping of retrieved offsets


def interm_range_type(self) -> Sequence[str]:
    fluents = self.domain.intermediate_fluents
    ordering = self.domain.interm_fluent_ordering
    return self._fluent_range_type(fluents, ordering)

The range type of each intermediate fluent in canonical order.

Returns:
Sequence[str]: A tuple of range types representing
the range of each fluent.


def make_fixture(model_class, **kwargs):
    all_fields = get_fields(model_class)
    fields_for_random_generation = map((lambda x: getattr(model_class, x)), all_fields)
    overrides = {}
    for (kwarg, value) in kwargs.items():
        if (kwarg in all_fields):
            kwarg_field = getattr(model_class, kwarg)
            fields_for_random_generation.remove(kwarg_field)
            overrides.update({kwarg_field: value})
    random_values = get_random_values(fields_for_random_generation)
    values = dict(overrides, **random_values)
    assert (len(all_fields) == len(values)), 'Mismatch in values, {} != {}'.format(len(all_fields), len(values))
    data = {k.name: v for (k, v) in values.items()}
    return model_class(**data)

Take the model_klass and generate a fixure for it

Args:
model_class (MongoEngine Document): model for which a fixture
is needed
kwargs (dict): any overrides instead of random values

Returns:
dict for now, other fixture types are not implemented yet


def _create_simulator_trial_result(self, params: study.ParamResolver, measurements: Dict[(str, np.ndarray)], final_simulator_state: Any) -> 'SimulationTrialResult':
    return SimulationTrialResult(params=params, measurements=measurements, final_simulator_state=final_simulator_state)

This method can be overridden to creation of a trial result.

Args:
params: The ParamResolver for this trial.
measurements: The measurement results for this trial.
final_simulator_state: The final state of the simulator for the
StepResult.

Returns:
The SimulationTrialResult.


def parse_data_types_and_routes_from_doc_ref(
    api,
    doc,
    namespace_context,
    ignore_missing_entries=False
):

    assert doc is not None
    data_types = set()
    routes = defaultdict(set)

    for match in doc_ref_re.finditer(doc):
        try:
            tag = match.group('tag')
            val = match.group('val')
            supplied_namespace = api.namespaces[namespace_context]
            if tag == 'field':
                if '.' in val:
                    type_name, __ = val.split('.', 1)
                    doc_type = supplied_namespace.data_type_by_name[type_name]
                    data_types.add(doc_type)
                else:
                    pass
            elif tag == 'route':
                if '.' in val:
                    namespace_name, val = val.split('.', 1)
                    namespace = api.namespaces[namespace_name]
                else:
                    namespace = supplied_namespace

                try:
                    route_name, version = parse_route_name_and_version(val)
                except ValueError as ex:
                    raise KeyError(str(ex))

                route = namespace.routes_by_name[route_name].at_version[version]
                routes[namespace.name].add(route)
            elif tag == 'type':
                if '.' in val:
                    namespace_name, val = val.split('.', 1)
                    doc_type = api.namespaces[namespace_name].data_type_by_name[val]
                    data_types.add(doc_type)
                else:
                    doc_type = supplied_namespace.data_type_by_name[val]
                    data_types.add(doc_type)
        except KeyError:
            if not ignore_missing_entries:
                raise
    return data_types, routes

Given a documentation string, parse it and return all references to other
data types and routes.

Args:
- api: The API containing this doc ref.
- doc: The documentation string to parse.
- namespace_context: The namespace name relative to this documentation.
- ignore_missing_entries: If set, this will skip references to nonexistent data types instead
of raising an exception.

Returns:
- a tuple of referenced data types and routes


def _process_allow_headers(self, req, resp, requested_headers):
    if (not requested_headers):
        return True
    elif self._cors_config['allow_all_headers']:
        self._set_allowed_headers(resp, requested_headers)
        return True
    approved_headers = []
    for header in requested_headers:
        if (header.lower() in self._cors_config['allow_headers_list']):
            approved_headers.append(header)
        elif self._cors_config.get('allow_headers_regex'):
            if self._cors_config['allow_headers_regex'].match(header):
                approved_headers.append(header)
    if (len(approved_headers) == len(requested_headers)):
        self._set_allowed_headers(resp, approved_headers)
        return True
    return False

Adds the Access-Control-Allow-Headers header to the response,
using the cors settings to determine which headers are allowed.

Returns:
True if all the headers the client requested are allowed.
False if some or none of the headers the client requested are allowed.


def ParseInput(self, a_file):
    input_lines = a_file.read().splitlines()
    self.ParseLines(input_lines)

Consumes input extracting definitions.

Args:
a_file: The file like stream to parse.

Raises:
PDDMError if there are any issues.


def format_statevector(vec, decimals=None):

    num_basis = len(vec)
    vec_complex = np.zeros(num_basis, dtype=complex)
    for i in range(num_basis):
        vec_complex[i] = vec[i][0] + 1j * vec[i][1]
    if decimals:
        vec_complex = np.around(vec_complex, decimals=decimals)
    return vec_complex

Format statevector coming from the backend to present to the Qiskit user.

Args:
vec (list): a list of [re, im] complex numbers.
decimals (int): the number of decimals in the statevector.
If None, no rounding is done.

Returns:
list[complex]: a list of python complex numbers.


def update_detector(self, detector_id, detector):

        resp = self._put(self._u(self._DETECTOR_ENDPOINT_SUFFIX, detector_id),
                         data=detector)
        resp.raise_for_status()
        return resp.json()

Update an existing detector.

Args:
detector_id (string): the ID of the detector.
detector (object): the detector model object. Will be serialized as
JSON.
Returns:
dictionary of the response (updated detector model).


def create_binary_array(self, key, value):

        data = None
        if key is not None and value is not None:
            value_encoded = []
            for v in value:
                try:

                    value_encoded.append(base64.b64encode(bytes(v)).decode('utf-8'))
                except TypeError:

                    value_encoded.append(base64.b64encode(bytes(v, 'utf-8')).decode('utf-8'))
            data = self.db.create(key.strip(), json.dumps(value_encoded))
        else:
            self.tcex.log.warning(u'The key or value field was None.')
        return data

Create method of CRUD operation for binary array data.

Args:
key (string): The variable to write to the DB.
value (any): The data to write to the DB.

Returns:
(string): Result of DB write.


def consumer_partitions_for_topic(consumer, topic):

    topic_partitions = []
    partitions = consumer.partitions_for_topic(topic)
    if partitions is not None:
        for partition in partitions:
            topic_partitions.append(TopicPartition(topic, partition))
    else:
        logging.error(
            "No partitions found for topic {}. Maybe it doesn't exist?".format(topic),
        )
    return topic_partitions

Returns a list of all TopicPartitions for a given topic.

Arguments:
consumer: an initialized KafkaConsumer
topic: a topic name to fetch TopicPartitions for

:returns:
list(TopicPartition): A list of TopicPartitions that belong to the given topic


def PmfProbLess(pmf1, pmf2):

    total = 0.0
    for v1, p1 in pmf1.Items():
        for v2, p2 in pmf2.Items():
            if v1 < v2:
                total += p1 * p2
    return total

Probability that a value from pmf1 is less than a value from pmf2.

Args:
pmf1: Pmf object
pmf2: Pmf object

Returns:
float probability


def download(url, file=None):

    import urllib.request
    import shutil
    if isinstance(file, str):
        file = open(file, 'wb')
    try:
        with urllib.request.urlopen(url) as response:
            if file:
                shutil.copyfileobj(response, file)
            else:
                return response.read()
    finally:
        if file:
            file.close()

Pass file as a filename, open file object, or None to return the request bytes

Args:
url (str): URL of file to download
file (Union[str, io, None]): One of the following:
- Filename of output file
- File opened in binary write mode
- None: Return raw bytes instead

Returns:
Union[bytes, None]: Bytes of file if file is None


def get_image_embeddings(self, pixel_values, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None):
    vision_output = self.vision_encoder(pixel_values, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict)
    image_embeddings = vision_output[0]
    return image_embeddings

Returns the image embeddings by passing the pixel values through the vision encoder.

Args:
pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):
Input pixel values
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers.
output_hidden_states (`bool`, *optional*):
Whether or not to return the hidden states of all layers.
return_dict (`bool`, *optional*):
Whether or not to return a [`~utils.TFModelOutput`] instead of a plain tuple.


def _get_stringlist_from_commastring(self, field):
    strings = self.data.get(field)
    if strings:
        return strings.split(',')
    else:
        return list()

Return list of strings from comma separated list

Args:
field (str): Field containing comma separated list

Returns:
List[str]: List of strings


def iterator_product(variables: VarType, parent: str = None) -> Iterable[VarMatrix]:

    logger.debug("Yielding from product iterator")
    if isinstance(variables, list):
        raise ValueError(
            f"Product only takes mappings of values, got {variables} of type {type(variables)}"
        )

    yield list(variable_matrix(variables, parent, "product"))

Apply the product operator to a set of variables.

This uses the python itertools.product iterator to combine multiple variables
such that all possible combinations are generated. This is the default iterator
however this is a method of manually specifying the option.

Args:
variables: The variables object
parent: Unused


def reverse_taskname(name: str) -> str:

  components = name.split('.')
  assert len(components) <= 3
  return '.'.join(components[::-1])

Reverses components in the name of task. Reversed convention is used for filenames since
it groups log/scratch files of related tasks together

0.somejob.somerun -> somerun.somejob.0
0.somejob -> somejob.0
somename -> somename

Args:
name: name of task


def delete_by_hash(self, file_hash):

        full_path = self.file_path_from_hash(file_hash)

        return self.delete_by_path(full_path)

Remove file/archive by it's `file_hash`.

Args:
file_hash (str): Hash, which is used to find the file in storage.

Raises:
IOError: If the file for given `file_hash` was not found in \
storage.


def _transform_local_field_to_expression(expression, node, context):

    column_name = expression.field_name
    column = sql_context_helpers.get_column(column_name, node, context)
    return column

Transform a LocalField compiler expression into its SQLAlchemy expression representation.

Args:
expression: expression, LocalField compiler expression.
node: SqlNode, the SqlNode the expression applies to.
context: CompilationContext, global compilation state and metadata.

Returns:
Expression, SQLAlchemy expression.


def __is_bound_method(method):
    if (not (hasattr(method, '__func__') and hasattr(method, '__self__'))):
        return False
    return (six.get_method_self(method) is not None)

Return ``True`` if the `method` is a bound method (attached to an class
instance.

Args:
method: A method or function type object.


def find_eq_stress(strains, stresses, tol=1e-10):

    stress_array = np.array(stresses)
    strain_array = np.array(strains)
    eq_stress = stress_array[np.all(abs(strain_array)<tol, axis=(1,2))]

    if eq_stress.size != 0:
        all_same = (abs(eq_stress - eq_stress[0]) < 1e-8).all()
        if len(eq_stress) > 1 and not all_same:
            raise ValueError("Multiple stresses found for equilibrium strain"
                             " state, please specify equilibrium stress or  "
                             " remove extraneous stresses.")
        eq_stress = eq_stress[0]
    else:
        warnings.warn("No eq state found, returning zero voigt stress")
        eq_stress = Stress(np.zeros((3, 3)))
    return eq_stress

Finds stress corresponding to zero strain state in stress-strain list

Args:
strains (Nx3x3 array-like): array corresponding to strains
stresses (Nx3x3 array-like): array corresponding to stresses
tol (float): tolerance to find zero strain state


def timestr2time(time_str):
    if any(((c not in '0123456789:') for c in time_str)):
        raise ValueError('Illegal character in time string')
    if (time_str.count(':') == 2):
        (h, m, s) = time_str.split(':')
    elif (time_str.count(':') == 1):
        (h, m) = time_str.split(':')
        s = '00'
    elif (len(time_str) == 6):
        h = time_str[:2]
        m = time_str[2:4]
        s = time_str[4:]
    else:
        raise ValueError('Time format not recognised. {}'.format(VALID_TIME_FORMATS_TEXT))
    if ((len(m) == 2) and (len(s) == 2)):
        mins = int(m)
        sec = int(s)
    else:
        raise ValueError('m and s must be 2 digits')
    try:
        return datetime.time(int(h), mins, sec)
    except ValueError:
        raise ValueError('Invalid time {}. {}'.format(time_str, VALID_TIME_FORMATS_TEXT))

Turns a string into a datetime.time object. This will only work if the
format can be "guessed", so the string must have one of the formats from
VALID_TIME_FORMATS_TEXT.

Args:
time_str (str) a string that represents a date
Returns:
datetime.time object
Raises:
ValueError if the input string does not have a valid format.


def can_user_access_build(param_name):

    build_id = (
        request.args.get(param_name, type=int) or
        request.form.get(param_name, type=int) or
        request.json[param_name])
    if not build_id:
        logging.debug('Build ID in param_name=%r was missing', param_name)
        abort(400)

    ops = operations.UserOps(current_user.get_id())
    build, user_is_owner = ops.owns_build(build_id)
    if not build:
        logging.debug('Could not find build_id=%r', build_id)
        abort(404)

    if current_user.is_authenticated() and not user_is_owner:

        ops.evict()
        claim_invitations(current_user)
        build, user_is_owner = ops.owns_build(build_id)

    if not user_is_owner:
        if current_user.is_authenticated() and current_user.superuser:
            pass
        elif request.method != 'GET':
            logging.debug('No way to log in user via modifying request')
            abort(403)
        elif build.public:
            pass
        elif current_user.is_authenticated():
            logging.debug('User does not have access to this build')
            abort(flask.Response('You cannot access this build', 403))
        else:
            logging.debug('Redirecting user to login to get build access')
            abort(login.unauthorized())
    elif not login_fresh():
        logging.debug('User login is old; forcing refresh')
        abort(login.needs_refresh())

    return build

Determines if the current user can access the build ID in the request.

Args:
param_name: Parameter name to use for getting the build ID from the
request. Will fetch from GET or POST requests.

Returns:
The build the user has access to.


def FileEntryExistsByPathSpec(self, path_spec):

    location = getattr(path_spec, 'location', None)

    if (location is None or
        not location.startswith(self.LOCATION_ROOT)):
      return False

    if len(location) == 1:
      return True

    try:
      self._zip_file.getinfo(location[1:])
      return True
    except KeyError:
      pass

    for name in iter(self._zip_file.namelist()):

      if name.startswith(location[1:]):
        return True

    return False

Determines if a file entry for a path specification exists.

Args:
path_spec (PathSpec): path specification of the file entry.

Returns:
bool: True if the file entry exists.


def get_devices(ads, **kwargs):

    def _get_device_filter(ad):
        for (k, v) in kwargs.items():
            if (not hasattr(ad, k)):
                return False
            elif (getattr(ad, k) != v):
                return False
        return True
    filtered = filter_devices(ads, _get_device_filter)
    if (not filtered):
        raise Error(('Could not find a target device that matches condition: %s.' % kwargs))
    else:
        return filtered

Finds a list of AndroidDevice instance from a list that has specific
attributes of certain values.

Example:
get_devices(android_devices, label='foo', phone_number='1234567890')
get_devices(android_devices, model='angler')

Args:
ads: A list of AndroidDevice instances.
kwargs: keyword arguments used to filter AndroidDevice instances.

Returns:
A list of target AndroidDevice instances.

Raises:
Error: No devices are matched.


def scale(self, replicas):
    if ('Global' in self.attrs['Spec']['Mode'].keys()):
        raise InvalidArgument('Cannot scale a global container')
    service_mode = ServiceMode('replicated', replicas)
    return self.client.api.update_service(self.id, self.version, mode=service_mode, fetch_current_spec=True)

Scale service container.

Args:
replicas (int): The number of containers that should be running.

Returns:
bool: ``True`` if successful.


def delete(self, url, callback, json=None):
    return self.adapter.delete(url, callback, json=json)

Delete a URL.

Args:

url(string): URL for the request

callback(func): The response callback function

Keyword Args:

json(dict): JSON body for the request

Returns:

The result of the callback handling the resopnse from the
executed request


def __init__(self,config_file):

		self.game = DoomGame()

		self.game.load_config(config_file)
		self.game.init()

		self.state_shape = self.featurize(self.game.get_state()).shape
		self.num_actions = len(self.game.get_available_buttons())

Initialize ViZDoom environment.

Args:
config_file: .cfg file path, which defines how a world works and look like (maps)


def is_sample_set(self, md5):

        try:
            self.get_sample_set(md5)
            return True
        except WorkBench.DataNotFound:
            return False

Does the md5 represent a sample_set?
Args:
md5: the md5 of the sample_set
Returns:
True/False


def input_mask(self):
    inputs = self.input
    if isinstance(inputs, list):
        return [getattr(x, '_keras_mask', None) for x in inputs]
    else:
        return getattr(inputs, '_keras_mask', None)

Retrieves the input mask tensor(s) of a layer.

Only applicable if the layer has exactly one inbound node,
i.e. if it is connected to one incoming layer.

Returns:
Input mask tensor (potentially None) or list of input
mask tensors.

Raises:
AttributeError: if the layer is connected to
more than one incoming layers.