def cartesian(self, subsets=None, step_pixels=100, max_distance_pixels=150, *args, **kwargs):
    n = Cartesian.read_cellframe(self, *args, subsets=subsets, step_pixels=step_pixels, max_distance_pixels=max_distance_pixels, prune_neighbors=False, **kwargs)
    if ('measured_regions' in kwargs):
        n.measured_regions = kwargs['measured_regions']
    else:
        n.measured_regions = self.get_measured_regions()
    if ('measured_phenotypes' in kwargs):
        n.measured_phenotypes = kwargs['measured_phenotypes']
    else:
        n.measured_phenotypes = self.phenotypes
    n.microns_per_pixel = self.microns_per_pixel
    return n

Return a class that can be used to create honeycomb plots

Args:
subsets (list): list of SubsetLogic objects
step_pixels (int): distance between hexagons
max_distance_pixels (int): the distance from each point by which to caclulate the quanitty of the phenotype for that area

Returns:
Cartesian: returns a class that holds the layout of the points to plot.


def rank(input, name=None):
    return rank_internal(input, name, optimize=True)

Returns the rank of a tensor.

See also `tf.shape`.

Returns a 0-D `int32` `Tensor` representing the rank of `input`.

For example:

```python
# shape of tensor 't' is [2, 2, 3]
t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]])
tf.rank(t)  # 3
```

**Note**: The rank of a tensor is not the same as the rank of a matrix. The
rank of a tensor is the number of indices required to uniquely select each
element of the tensor. Rank is also known as "order", "degree", or "ndims."

Args:
input: A `Tensor` or `SparseTensor`.
name: A name for the operation (optional).

Returns:
A `Tensor` of type `int32`.

@compatibility(numpy)
Equivalent to np.ndim
@end_compatibility


def get_valid_build_systems(working_dir, package=None):
    from rez.plugin_managers import plugin_manager
    from rez.exceptions import PackageMetadataError
    try:
        package = (package or get_developer_package(working_dir))
    except PackageMetadataError:
        pass
    if package:
        if (getattr(package, 'build_command', None) is not None):
            buildsys_name = 'custom'
        else:
            buildsys_name = getattr(package, 'build_system', None)
        if buildsys_name:
            cls = plugin_manager.get_plugin_class('build_system', buildsys_name)
            return [cls]
    clss = []
    for buildsys_name in get_buildsys_types():
        cls = plugin_manager.get_plugin_class('build_system', buildsys_name)
        if cls.is_valid_root(working_dir, package=package):
            clss.append(cls)
    child_clss = set((x.child_build_system() for x in clss))
    clss = list((set(clss) - child_clss))
    return clss

Returns the build system classes that could build the source in given dir.

Args:
working_dir (str): Dir containing the package definition and potentially
build files.
package (`Package`): Package to be built. This may or may not be needed
to determine the build system. For eg, cmake just has to look for
a CMakeLists.txt file, whereas the 'build_command' package field
must be present for the 'custom' build system type.

Returns:
List of class: Valid build system class types.


def router_id(self, **kwargs):
    router_id = kwargs.pop('router_id')
    rbridge_id = kwargs.pop('rbridge_id', '1')
    callback = kwargs.pop('callback', self._callback)
    rid_args = dict(rbridge_id=rbridge_id, router_id=router_id)
    config = self._rbridge.rbridge_id_ip_rtm_config_router_id(**rid_args)
    return callback(config)

Configures device's Router ID.

Args:
router_id (str): Router ID for the device.
rbridge_id (str): The rbridge ID of the device on which BGP will be
configured in a VCS fabric.
callback (function): A function executed upon completion of the
method.  The only parameter passed to `callback` will be the
``ElementTree`` `config`.

Returns:
Return value of `callback`.

Raises:
KeyError: if `router_id` is not specified.

Examples:
>>> import pynos.device
>>> conn = ('10.24.39.211', '22')
>>> auth = ('admin', 'password')
>>> with pynos.device.Device(conn=conn, auth=auth) as dev:
...     output = dev.system.router_id(router_id='10.24.39.211',
...     rbridge_id='225')
...     dev.system.router_id() # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
KeyError


def process_actions(self, actions):
    notices = {}
    notification_contacts = {}
    for action in actions:
        resource = action['resource']
        action_status = ActionStatus.SUCCEED
        try:
            if (action['action'] == AuditActions.REMOVE):
                action_status = self.process_action(resource, AuditActions.REMOVE)
                if (action_status == ActionStatus.SUCCEED):
                    db.session.delete(action['issue'].issue)
            elif (action['action'] == AuditActions.STOP):
                action_status = self.process_action(resource, AuditActions.STOP)
                if (action_status == ActionStatus.SUCCEED):
                    action['issue'].update({'missing_tags': action['missing_tags'], 'notes': action['notes'], 'last_alert': action['last_alert'], 'state': action['action']})
            elif (action['action'] == AuditActions.FIXED):
                db.session.delete(action['issue'].issue)
            elif (action['action'] == AuditActions.ALERT):
                action['issue'].update({'missing_tags': action['missing_tags'], 'notes': action['notes'], 'last_alert': action['last_alert'], 'state': action['action']})
            db.session.commit()
            if (action_status == ActionStatus.SUCCEED):
                for owner in [dict(t) for t in {tuple(d.items()) for d in (action['owners'] + self.permanent_emails)}]:
                    if (owner['value'] not in notification_contacts):
                        contact = NotificationContact(type=owner['type'], value=owner['value'])
                        notification_contacts[owner['value']] = contact
                        notices[contact] = {'fixed': [], 'not_fixed': []}
                    else:
                        contact = notification_contacts[owner['value']]
                    if (action['action'] == AuditActions.FIXED):
                        notices[contact]['fixed'].append(action)
                    else:
                        notices[contact]['not_fixed'].append(action)
        except Exception as ex:
            self.log.exception('Unexpected error while processing resource {}/{}/{}/{}'.format(action['resource'].account.account_name, action['resource'].id, action['resource'], ex))
    return notices

Process the actions we want to take

Args:
actions (`list`): List of actions we want to take

Returns:
`list` of notifications


def __request_finish(self, queue_item, new_requests, request_failed=False):

        if self.__stopping:
            return

        del self.__threads[queue_item.get_hash()]

        if request_failed:
            new_queue_items = []
            self.queue.move(queue_item, QueueItem.STATUS_ERRORED)
        else:
            self.routing.increase_route_count(queue_item.request)
            new_queue_items = self.__add_scraped_requests_to_queue(queue_item, new_requests)
            self.queue.move(queue_item, QueueItem.STATUS_FINISHED)

        try:
            action = self.__options.callbacks.request_after_finish(self.queue, queue_item, new_queue_items)
        except Exception as e:
            action = None
            print(e)
            print(traceback.format_exc())

        queue_item.decompose()

        if action == CrawlerActions.DO_STOP_CRAWLING:
            self.__should_stop = True

        if action == CrawlerActions.DO_CONTINUE_CRAWLING or action is None:
            self.__should_spawn_new_requests = True

Called when the crawler finished the given queue item.

Args:
queue_item (:class:`nyawc.QueueItem`): The request/response pair that finished.
new_requests list(:class:`nyawc.http.Request`): All the requests that were found during this request.
request_failed (bool): True if the request failed (if needs to be moved to errored).


def __init__(self, env_id):

        self.env_id = env_id
        self.env = gym.make(env_id)

Initialize OpenAI universe environment.

Args:
env_id: string with id/descriptor of the universe environment, e.g. 'HarvestDay-v0'.


def updateParams(self, newvalues):
    for (param, value) in newvalues.items():
        if (param not in self.model.freeparams):
            raise RuntimeError("Can't handle param: {0}".format(param))
    if newvalues:
        self.model.updateParams(newvalues)
        self._updateInternals()
        self._paramsarray = None

Update model parameters and re-compute likelihoods.

This method is the **only** acceptable way to update model
parameters. The likelihood is re-computed as needed
by this method.

Args:
`newvalues` (dict)
A dictionary keyed by param name and with value as new
value to set. Each parameter name must either be a
valid model parameter (in `model.freeparams`).


def _index_filter(index_data, filter_value, filter_operator, field_converter=None):

        filtered_data = []
        if filter_operator == operator.eq:
            if field_converter is not None:
                filter_value = field_converter(filter_value)

            filtered_data = index_data.get(filter_value)

        else:
            for field, data_obj_list in index_data.items():
                if field_converter is not None:
                    field = field_converter(field)

                if filter_operator(field, filter_value):
                    filtered_data.extend(data_obj_list)

        return filtered_data

Post Filter

Args:
index_data (dictionary): The indexed data for the provided field.
field (string): The field to filter on.
filter_value (string | list): The value to match.
filter_operator (string): The operator for comparison.
field_converter (method): A method used to convert the field before comparison.

Returns:
(list): Matching data objects


def unpack_iterator_input(iterator):
    try:
        next_element = iterator.get_next()
    except errors.OutOfRangeError:
        raise RuntimeError('Your dataset iterator ran out of data; Make sure that your dataset can generate required number of samples.')
    if isinstance(next_element, (list, tuple)):
        if len(next_element) not in [2, 3]:
            raise ValueError('Please provide model inputs as a list or tuple of 2 or 3 elements: (input, target) or (input, target, sample_weights) Received %s' % next_element)
        if len(next_element) == 2:
            x, y = next_element
            weights = None
        else:
            x, y, weights = next_element
    else:
        x = next_element
        y = None
        weights = None
    return (x, y, weights)

Convert a dataset iterator to a tuple of tensors `x, y, sample_weights`.

Args:
iterator: Instance of a dataset iterator.

Returns:
Tuple of tensors `x, y, weights`. `y` and `weights` entry may be None.


def delete_subscription(self, subscription_id):
    return self.client._delete((self.url + 'subscriptions/{}'.format(subscription_id)), headers=self.get_headers())

Unsubscribe, delete the relationship of the customer with the plan.

Args:
subscription_id: Identification of the subscription.

Returns:


def conformPadding(cls, chars):

        pad = chars
        if pad and pad[0] not in PAD_MAP:
            pad = cls.getPaddingChars(cls.getPaddingNum(pad))
        return pad

Ensure alternate input padding formats are conformed
to formats defined in PAD_MAP

If chars is already a format defined in PAD_MAP, then
it is returned unmodified.

Example::
'#'    -> '#'
'@@@@' -> '@@@@'
'%04d' -> '#'

Args:
chars (str): input padding chars

Returns:
str: conformed padding chars

Raises:
ValueError: If chars contains invalid padding characters


def ExamineEvent(self, mediator, event):
    event_data_type = getattr(event, 'data_type', '')
    if (event_data_type == 'windows:registry:service'):
        service = WindowsService.FromEvent(event)
        self._service_collection.AddService(service)

Analyzes an event and creates Windows Services as required.

At present, this method only handles events extracted from the Registry.

Args:
mediator (AnalysisMediator): mediates interactions between analysis
plugins and other components, such as storage and dfvfs.
event (EventObject): event to examine.


def parse_psqs(psqs_results_file):
    psqs_results = pd.read_csv(psqs_results_file, sep='\t', header=None)
    psqs_results['pdb_file'] = psqs_results[0].apply((lambda x: str(x).strip('./').strip('.pdb')))
    psqs_results = psqs_results.rename(columns={1: 'psqs_local', 2: 'psqs_burial', 3: 'psqs_contact', 4: 'psqs_total'}).drop(0, axis=1)
    psqs_results['u_pdb'] = psqs_results['pdb_file'].apply((lambda x: (x.upper() if (len(x) == 4) else np.nan)))
    psqs_results['i_entry_name'] = psqs_results['pdb_file'].apply((lambda x: (x.split('_model1')[0] if (len(x) > 4) else np.nan)))
    psqs_results = psqs_results[pd.notnull(psqs_results.psqs_total)]
    return psqs_results

Parse a PSQS result file and returns a Pandas DataFrame of the results

Args:
psqs_results_file: Path to psqs results file

Returns:
Pandas DataFrame: Summary of PSQS results


def _sorted_results(self, results_dicts):
    print('results dicts:', results_dicts)
    sorted_dict = sorted(results_dicts, key=(lambda k: k['start_time']))
    results = []
    for entry in sorted_dict:
        results.append(entry['dt'])
    return results

Sorts dict of results based on log start_time.

Sorts the results and returns an array with only the values but sorted
by oldest value first.value

Args:
results_dicts: List of result dicts

Returns:
List of only the time but sorted oldest first.


def fuse_awq_modules(model, quantization_config):
    if isinstance(quantization_config, dict):
        quantization_config = AwqConfig.from_dict(quantization_config)
    backend = quantization_config.backend
    modules_to_fuse = get_modules_to_fuse(model, quantization_config)
    modules_to_not_convert = getattr(quantization_config, 'modules_to_not_convert', None)
    if backend == AwqBackendPackingMethod.AUTOAWQ:
        from awq.modules.fused.attn import QuantAttentionFused
        from awq.modules.fused.mlp import QuantFusedMLP
        from awq.modules.fused.norm import FasterTransformerRMSNorm
    else:
        raise ValueError('Fusing is only supported for the AutoAWQ backend')
    fused_attention_modules = []
    for name, module in model.named_modules():
        if modules_to_not_convert is not None:
            if any((module_name_to_not_convert in name for module_name_to_not_convert in modules_to_not_convert)):
                continue
        _fuse_awq_layernorm(modules_to_fuse['layernorm'], module, FasterTransformerRMSNorm)
        if quantization_config.version != 'ipex':
            _fuse_awq_mlp(model, name, modules_to_fuse['mlp'], module, QuantFusedMLP)
        else:
            logger.info('The IPEX version AWQ does not support fuse mlp for now.')
        attention_has_been_fused = _fuse_awq_attention_layers(model, module, modules_to_fuse, name, QuantAttentionFused)
        if attention_has_been_fused:
            fused_attention_modules.append(name.split('.')[0])
    if len(fused_attention_modules) > 0:
        for module_name, module in model.named_modules():
            if any((module_name in fused_attention_modules for fused_attention_parent_module in fused_attention_modules)):
                if hasattr(module, 'config') and hasattr(module.config, '_attn_implementation'):
                    module.config._attn_implementation = 'custom'
    return model

Optionally fuse some modules in the model to speedup inference.

Args:
model (`~PreTrainedModel`):
The model to fuse - note this model should have been converted into AWQ format beforehand.
quantization_config (`Union[AwqConfig, dict]`):
The quantization configuration to use.


def dbmin_stddev(self, value=None):

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

        self._dbmin_stddev = value

Corresponds to IDD Field `dbmin_stddev`
Standard deviation of extreme annual minimum dry-bulb temperature

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

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


def world_info(world_name, world_config=None, initial_indent='', next_indent='  '):
    if (world_config is None):
        for (config, _) in _iter_packages():
            for world in config['maps']:
                if (world['name'] == world_name):
                    world_config = world
    if (world_config is None):
        raise HolodeckException(("Couldn't find world " + world_name))
    second_indent = (initial_indent + next_indent)
    agent_indent = (second_indent + next_indent)
    sensor_indent = (agent_indent + next_indent)
    print(initial_indent, world_config['name'])
    print(second_indent, 'Resolution:', world_config['window_width'], 'x', world_config['window_height'])
    print(second_indent, 'Agents:')
    for agent in world_config['agents']:
        print(agent_indent, 'Name:', agent['agent_name'])
        print(agent_indent, 'Type:', agent['agent_type'])
        print(agent_indent, 'Sensors:')
        for sensor in agent['sensors']:
            print(sensor_indent, sensor)

Gets and prints the information of a world.

Args:
world_name (str): the name of the world to retrieve information for
world_config (dict optional): A dictionary containing the world's configuration. Will find the config if None. Defaults to None.
initial_indent (str optional): This indent will apply to each output line. Defaults to "".
next_indent (str optional): This indent will be applied within each nested line. Defaults to "  ".


def get_tests_from_description(name,
                               descriptions,
                               parsed=None):

    tests = []
    if not parsed:
        parsed = []

    description = descriptions.get(name, None)
    if not description:
        raise IpaUtilsException(
            'Test description file with name: %s cannot be located.'
            % name
        )

    if description in parsed:
        return tests

    parsed.append(description)
    test_data = get_yaml_config(description)

    if 'tests' in test_data:
        tests += test_data.get('tests')

    if 'include' in test_data:
        for description_name in test_data.get('include'):
            tests += get_tests_from_description(
                description_name,
                descriptions,
                parsed
            )

    return tests

Recursively collect all tests in test description.

Args:
name (str): Yaml test description file name.
descriptions (dict): Dict of test description name
(key) and absolute file paths
(value).
parsed (list): List of description paths which have
already been parsed to prevent infinte
recursion.
Returns:
A list of expanded test files.


def _path_formatter(self, suffix):
    if (suffix.lower() == 'mirror'):
        path_items = [self.bucket, self.s3path]
    else:
        path_items = [self.bucket, self.s3path, suffix]
    path = '/'.join(path_items)
    s3_format = 's3:
    formatted_path = path.replace('
    full_path = s3_format.format(formatted_path)
    return full_path

Format the s3 path properly.

Args:
suffix (str): suffix to add on to an s3 path

Returns:
str: formatted path


def ParseFileObject(self, parser_mediator, file_object):

    olecf_file = pyolecf.file()
    olecf_file.set_ascii_codepage(parser_mediator.codepage)

    try:
      olecf_file.open_file_object(file_object)
    except IOError as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to open file with error: {0!s}'.format(exception))
      return

    root_item = olecf_file.root_item
    if not root_item:
      return

    item_names = [item.name for item in root_item.sub_items]

    item_names = frozenset(item_names)

    try:
      for plugin in self._plugins:
        if parser_mediator.abort:
          break

        if not plugin.REQUIRED_ITEMS.issubset(item_names):
          continue

        try:
          plugin.UpdateChainAndProcess(parser_mediator, root_item=root_item)

        except Exception as exception:
          parser_mediator.ProduceExtractionWarning((
              'plugin: {0:s} unable to parse OLECF file with error: '
              '{1!s}').format(plugin.NAME, exception))

      if self._default_plugin and not parser_mediator.abort:
        try:
          self._default_plugin.UpdateChainAndProcess(
              parser_mediator, root_item=root_item)

        except Exception as exception:
          parser_mediator.ProduceExtractionWarning((
              'plugin: {0:s} unable to parse OLECF file with error: '
              '{1!s}').format(self._default_plugin.NAME, exception))

    finally:
      olecf_file.close()

Parses an OLE Compound File (OLECF) file-like object.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): file-like object.


def get_structural_variant(self, variant):

        query = {
                'chrom': variant['chrom'],
                'end_chrom': variant['end_chrom'],
                'sv_type': variant['sv_type'],
                '$and': [
                    {'pos_left': {'$lte': variant['pos']}},
                    {'pos_right': {'$gte': variant['pos']}},
                ]
            }

        res = self.db.structural_variant.find(query).sort('pos_left',1)
        match = None
        distance = None
        closest_hit = None

        for hit in res:

            if hit['end_left'] > variant['end']:
                continue
            if hit['end_right'] < variant['end']:
                continue

            distance = (abs(variant['pos'] - (hit['pos_left'] + hit['pos_right'])/2) +
                        abs(variant['end'] - (hit['end_left'] + hit['end_right'])/2))

            if closest_hit is None:
                match = hit
                closest_hit = distance
                continue

            if distance < closest_hit:

                match = hit

                closest_hit = distance

        return match

Check if there are any overlapping sv clusters

Search the sv variants with chrom start end_chrom end and sv_type

Args:
variant (dict): A variant dictionary

Returns:
variant (dict): A variant dictionary


def make_transaction(self):
    if self.pk:
        raise CannotRecreateTransactionOnRecurredCost('The transaction for this recurred cost has already been created. You cannot create it again.')
    amount = self.recurring_cost.get_amount(self.billing_cycle)
    if (not amount):
        return None
    self.transaction = Transaction.objects.create(description='Created by recurring cost', date=self.billing_cycle.date_range.lower)
    splits = self.recurring_cost.splits.all().split(amount)
    self.transaction.legs.add(Leg.objects.create(transaction=self.transaction, amount=Money(amount, self.recurring_cost.currency), account=self.recurring_cost.to_account))
    for (split, split_amount) in splits:
        if split_amount:
            self.transaction.legs.add(Leg.objects.create(transaction=self.transaction, amount=Money((split_amount * (- 1)), self.recurring_cost.currency), account=split.from_account))
    return self.transaction

Create the transaction for this RecurredCost

May only be used to create the RecurredCost's initial transaction.

Returns:
Transaction: The created transaction, also assigned to self.transaction. None if the amount is zero.


def metadata_path(self, m_path):

        if not m_path:
            self.metadata_dir = None
            self.metadata_file = None

        else:
            if not op.exists(m_path):
                raise OSError('{}: file does not exist!'.format(m_path))

            if not op.dirname(m_path):
                self.metadata_dir = '.'
            else:
                self.metadata_dir = op.dirname(m_path)
            self.metadata_file = op.basename(m_path)

            self.update(parse_kegg_gene_metadata(self.metadata_path), overwrite=True)

Provide pointers to the paths of the metadata file

Args:
m_path: Path to metadata file


def parse_GSE(filepath):
    gpls = {}
    gsms = {}
    series_counter = 0
    database = None
    metadata = {}
    gse_name = None
    with utils.smart_open(filepath) as soft:
        groupper = groupby(soft, (lambda x: x.startswith('^')))
        for (is_new_entry, group) in groupper:
            if is_new_entry:
                (entry_type, entry_name) = __parse_entry(next(group))
                logger.debug(('%s: %s' % (entry_type.upper(), entry_name)))
                if (entry_type == 'SERIES'):
                    gse_name = entry_name
                    series_counter += 1
                    if (series_counter > 1):
                        raise Exception('GSE file should contain only one series entry!')
                    (is_data, data_group) = next(groupper)
                    message = 'The key is not False, probably there is an error in the SOFT file'
                    assert (not is_data), message
                    metadata = parse_metadata(data_group)
                elif (entry_type == 'SAMPLE'):
                    (is_data, data_group) = next(groupper)
                    gsms[entry_name] = parse_GSM(data_group, entry_name)
                elif (entry_type == 'PLATFORM'):
                    (is_data, data_group) = next(groupper)
                    gpls[entry_name] = parse_GPL(data_group, entry_name)
                elif (entry_type == 'DATABASE'):
                    (is_data, data_group) = next(groupper)
                    database_metadata = parse_metadata(data_group)
                    database = GEODatabase(name=entry_name, metadata=database_metadata)
                else:
                    logger.error(('Cannot recognize type %s' % entry_type))
    gse = GSE(name=gse_name, metadata=metadata, gpls=gpls, gsms=gsms, database=database)
    return gse

Parse GSE SOFT file.

Args:
filepath (:obj:`str`): Path to GSE SOFT file.

Returns:
:obj:`GEOparse.GSE`: A GSE object.


def _cell_magic(line, query):

    args = magic_arguments.parse_argstring(_cell_magic, line)

    params = []
    if args.params is not None:
        try:
            params = _helpers.to_query_parameters(
                ast.literal_eval("".join(args.params))
            )
        except Exception:
            raise SyntaxError(
                "--params is not a correctly formatted JSON string or a JSON "
                "serializable dictionary"
            )

    project = args.project or context.project
    client = bigquery.Client(project=project, credentials=context.credentials)
    bqstorage_client = _make_bqstorage_client(
        args.use_bqstorage_api or context.use_bqstorage_api, context.credentials
    )
    job_config = bigquery.job.QueryJobConfig()
    job_config.query_parameters = params
    job_config.use_legacy_sql = args.use_legacy_sql
    query_job = _run_query(client, query, job_config)

    if not args.verbose:
        display.clear_output()

    result = query_job.to_dataframe(bqstorage_client=bqstorage_client)
    if args.destination_var:
        IPython.get_ipython().push({args.destination_var: result})
    else:
        return result

Underlying function for bigquery cell magic

Note:
This function contains the underlying logic for the 'bigquery' cell
magic. This function is not meant to be called directly.

Args:
line (str): "%%bigquery" followed by arguments as required
query (str): SQL query to run

Returns:
pandas.DataFrame: the query results.


def overlay(self, dimensions=None, **kwargs):

        if dimensions is None:
            dimensions = self.kdims
        else:
            if not isinstance(dimensions, (list, tuple)):
                dimensions = [dimensions]
            dimensions = [self.get_dimension(d, strict=True)
                          for d in dimensions]
        dims = [d for d in self.kdims if d not in dimensions]
        return self.groupby(dims, group_type=NdOverlay)

Group by supplied dimension(s) and overlay each group

Groups data by supplied dimension(s) overlaying the groups
along the dimension(s).

Args:
dimensions: Dimension(s) of dimensions to group by

Returns:
NdOverlay object(s) with supplied dimensions


def gradients(loss, variables):
    return gradients_module.gradients(loss, variables, colocate_gradients_with_ops=True)

Returns the gradients of `loss` w.r.t. `variables`.

Args:
loss: Scalar tensor to minimize.
variables: List of variables.

Returns:
A gradients tensor.


def has_entities(status):
    try:
        if (sum((len(v) for v in status.entities.values())) > 0):
            return True
    except AttributeError:
        if (sum((len(v) for v in status['entities'].values())) > 0):
            return True
    return False

Returns true if a Status object has entities.

Args:
status: either a tweepy.Status object or a dict returned from Twitter API


def quarter_boundaries(quarter):
    (year, quarter) = quarter.split('Q')
    year = int(year)
    quarter = int(quarter)
    first_month_of_quarter = ((3 * quarter) - 2)
    last_month_of_quarter = (3 * quarter)
    first_day = date(year, first_month_of_quarter, 1)
    last_day = date(year, last_month_of_quarter, monthrange(year, last_month_of_quarter)[1])
    return (first_day, last_day)

Returns first and last day of a quarter

Args:
quarter (str) quarter, in format '2015Q1'

Returns: (tuple) datetime.dates for the first and last days of the quarter


def gen_ref_docs(gen_index=False):
    try:
        from refdoc import generate_docs
    except ImportError as ex:
        msg = 'You need to install sphinx-refdoc if you want to generate code reference docs.'
        print(msg, file=sys.stderr)
        log.err('Exception: {}'.format(ex))
        sys.exit((- 1))
    pretend = context.get('pretend', False)
    docs_dir = conf.get_path('docs.path', 'docs')
    docs_ref_dir = os.path.join(docs_dir, 'ref')
    refdoc_paths = conf.get('docs.reference', [])
    if os.path.exists(docs_ref_dir):
        if (not pretend):
            log.info('Removing existing reference docs')
            shutil.rmtree(docs_ref_dir)
        else:
            log.info('Would remove old reference docs')
    args = {'out_dir': docs_ref_dir, 'verbose': context.get('verbose', 0)}
    if gen_index:
        args['gen_index'] = True
    pkg_paths = [conf.proj_path(p) for p in refdoc_paths]
    if (not pretend):
        log.info('Generating reference documentation')
        generate_docs(pkg_paths, **args)
    else:
        log.info('Would generate reference docs with the following params')
        shell.cprint('<90>{}', util.yaml_dump(args).rstrip())
        shell.cprint('<90>paths:\n<34>{}', util.yaml_dump(pkg_paths).rstrip())

Generate reference documentation for the project.

This will use **sphinx-refdoc** to generate the source .rst files for the
reference documentation.

Args:
gen_index (bool):
Set it to **True** if you want to generate the index file with the
list of top-level packages. This is set to default as in most cases
you only have one package per project so you can link directly to
that package reference (and if index were generated sphinx would
complain about file not included in toctree).


def DeviceReadThread(hid_device):
    hid_device.run_loop_ref = cf.CFRunLoopGetCurrent()
    if (not hid_device.run_loop_ref):
        logger.error('Failed to get current run loop')
        return
    iokit.IOHIDDeviceScheduleWithRunLoop(hid_device.device_handle, hid_device.run_loop_ref, K_CF_RUNLOOP_DEFAULT_MODE)
    run_loop_run_result = K_CF_RUN_LOOP_RUN_TIMED_OUT
    while ((run_loop_run_result == K_CF_RUN_LOOP_RUN_TIMED_OUT) or (run_loop_run_result == K_CF_RUN_LOOP_RUN_HANDLED_SOURCE)):
        run_loop_run_result = cf.CFRunLoopRunInMode(K_CF_RUNLOOP_DEFAULT_MODE, 1000, False)
    if (run_loop_run_result != K_CF_RUN_LOOP_RUN_STOPPED):
        logger.error('Unexpected run loop exit code: %d', run_loop_run_result)
    iokit.IOHIDDeviceUnscheduleFromRunLoop(hid_device.device_handle, hid_device.run_loop_ref, K_CF_RUNLOOP_DEFAULT_MODE)

Binds a device to the thread's run loop, then starts the run loop.

Args:
hid_device: The MacOsHidDevice object

The HID manager requires a run loop to handle Report reads. This thread
function serves that purpose.


def read_video_torchvision(video_path: str, sample_indices_fn: Callable, **kwargs):
    video, _, info = torchvision_io.read_video(video_path, start_pts=0.0, end_pts=None, pts_unit='sec', output_format='THWC')
    video_fps = info['video_fps']
    total_num_frames = video.size(0)
    duration = total_num_frames / video_fps if video_fps else 0
    metadata = VideoMetadata(total_num_frames=int(total_num_frames), fps=float(video_fps), duration=float(duration), video_backend='torchvision')
    indices = sample_indices_fn(metadata=metadata, **kwargs)
    video = video[indices].contiguous().numpy()
    metadata.frames_indices = indices
    return (video, metadata)

Decode the video with torchvision decoder.

Args:
video_path (`str`):
Path to the video file.
sample_indices_fn (`Callable`, *optional*):
A callable function that will return indices at which the video should be sampled. If the video has to be loaded using
by a different sampling technique than provided by `num_frames` or `fps` arguments, one should provide their own `sample_indices_fn`.
If not provided, simple uniform sampling with fps is performed.
Example:
def sample_indices_fn(metadata, **kwargs):
return np.linspace(0, metadata.total_num_frames - 1, num_frames, dtype=int)

Returns:
Tuple[`np.array`, `VideoMetadata`]: A tuple containing:
- Numpy array of frames in RGB (shape: [num_frames, height, width, 3]).
- `VideoMetadata` object.


def view_as(self, cls: Type[PipelineOptionsT]) -> PipelineOptionsT:
    view = cls(self._flags)
    for option_name in view._visible_option_list():
        if option_name not in self._all_options:
            self._all_options[option_name] = getattr(view._visible_options, option_name)
    view._all_options = self._all_options
    return view

Returns a view of current object as provided PipelineOption subclass.

Example Usage::

options = PipelineOptions(['--runner', 'Direct', '--streaming'])
standard_options = options.view_as(StandardOptions)
if standard_options.streaming:
# ... start a streaming job ...

Note that options objects may have multiple views, and modifications
of values in any view-object will apply to current object and other
view-objects.

Args:
cls: PipelineOptions class or any of its subclasses.

Returns:
An instance of cls that is initialized using options contained in current
object.


def find_subclass_in_module(base_class, module):
    subclasses = find_subclasses_in_module([base_class], module)
    if len(subclasses) != 1:
        raise ValueError('Expected 1 subclass of %s per module, found %s.' % (base_class.__name__, [subclass.__name__ for subclass in subclasses]))
    return subclasses[0]

Finds the single subclass of the given base class in the given module.

Args:
base_class: class, the base class to look for a subclass of in the module.
module: module, the module to look for the single subclass in.

Returns:
The single subclass of the given base class.

Raises:
ValueError: If the number of subclasses found was not exactly one.


def _GetArgSpecInfo(fn):
    skip_arg = False
    if inspect.isclass(fn):
        skip_arg = True
    elif inspect.ismethod(fn):
        skip_arg = fn.__self__ is not None
    elif inspect.isbuiltin(fn):
        if not isinstance(fn.__self__, types.ModuleType):
            skip_arg = True
    elif not inspect.isfunction(fn):
        skip_arg = True
    return (fn, skip_arg)

Gives information pertaining to computing the ArgSpec of fn.

Determines if the first arg is supplied automatically when fn is called.
This arg will be supplied automatically if fn is a bound method or a class
with an __init__ method.

Also returns the function who's ArgSpec should be used for determining the
calling parameters for fn. This may be different from fn itself if fn is a
class with an __init__ method.

Args:
fn: The function or class of interest.
Returns:
A tuple with the following two items:
fn: The function to use for determining the arg spec of this function.
skip_arg: Whether the first argument will be supplied automatically, and
hence should be skipped when supplying args from a Fire command.


def _load_callwraps(packname, package):

    global _callwraps
    from acorn.config import settings
    from acorn.logging.descriptors import _obj_getattr
    spack = settings(packname)
    if spack is not None:
        if spack.has_section("callwrap"):
            wrappings = dict(spack.items("callwrap"))
            for fqdn, target in wrappings.items():
                caller = _obj_getattr(package, target)
                _callwraps[fqdn] = caller

Loads the special call wrapping settings for functions in the specified
package. This allows the result of the original method call to be cast as a
different type, or passed to a different constructor before returning from
the wrapped function.

Args:
packname (str): name of the package to get config settings for.
package: actual package object.


def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
    local_buffer = utils.BytearrayStream()
    if self._located_items:
        self._located_items.write(local_buffer, kmip_version=kmip_version)
    if self._unique_identifiers:
        for unique_identifier in self._unique_identifiers:
            unique_identifier.write(local_buffer, kmip_version=kmip_version)
    self.length = local_buffer.length()
    super(LocateResponsePayload, self).write(output_buffer, kmip_version=kmip_version)
    output_buffer.write(local_buffer.buffer)

Write the data encoding the Locate response payload to a buffer.

Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.


def clean(self, force: bool=False):
    assert (not self._closed)
    with (yield from self._host_pools_lock):
        for (key, pool) in tuple(self._host_pools.items()):
            (yield from pool.clean(force=force))
            if ((not self._host_pool_waiters[key]) and pool.empty()):
                del self._host_pools[key]
                del self._host_pool_waiters[key]

Clean all closed connections.

Args:
force: Clean connected and idle connections too.

Coroutine.


def orthologize(self, species_id: str) -> 'BEL':
    if (not self.ast):
        return self
    if (not self.ast.collected_orthologs):
        self = self.collect_orthologs([species_id])
    self.ast.species = set()
    self.ast = bel_utils.orthologize(self.ast, self, species_id)
    return self

Orthologize BEL AST to given species_id

Will return original entity (ns:value) if no ortholog found.

Args:
species_id (str): species id to convert genes/rna/proteins into

Returns:
BEL: returns self


def tersoff_input(self, structure, periodic=False, uc=True, *keywords):

        gin = self.keyword_line(*keywords)
        gin += self.structure_lines(
            structure, cell_flg=periodic, frac_flg=periodic,
            anion_shell_flg=False, cation_shell_flg=False, symm_flg=not uc
        )
        gin += self.tersoff_potential(structure)
        return gin

Gets a GULP input with Tersoff potential for an oxide structure

Args:
structure: pymatgen.core.structure.Structure
periodic (Default=False): Flag denoting whether periodic
boundary conditions are used
library (Default=None): File containing the species and potential.
uc (Default=True): Unit Cell Flag.
keywords: GULP first line keywords.


def get_dm_channel(self, userid):

        dm_open = self.slack_client.api_call('im.open', user=userid)
        return dm_open['channel']['id']

Perform a lookup of users to resolve a userid to a DM channel

Args:
userid (string): Slack userid to lookup.

Returns:
string: DM channel ID of user


def is_mobile(user_agent):
    if user_agent:
        b = reg_b.search(user_agent)
        v = reg_v.search(user_agent[0:4])
        return (b or v)
    return False

Checks if the user browser from the given user agent is mobile.

Args:
user_agent: A given user agent.

Returns: True if the browser from the user agent is mobile.


def date_to_datetime(self, time_input, tz=None):

        dt = None
        try:

            dt = parser.parse(time_input)

            if tz is not None and tz != dt.tzname():
                if dt.tzinfo is None:
                    dt = self._replace_timezone(dt)
                dt = dt.astimezone(timezone(tz))
        except IndexError:
            pass
        except TypeError:
            pass
        except ValueError:
            pass
        return dt

Convert ISO 8601 and other date strings to datetime.datetime type.

Args:
time_input (string): The time input string (see formats above).
tz (string): The time zone for the returned data.

Returns:
(datetime.datetime): Python datetime.datetime object.


def add_api_key(key, value):
    if ((key is None) or (key == '')):
        logger.error('Key cannot be empty')
    if ((value is None) or (value == '')):
        logger.error('Value cannot be empty')
    from .. import datatools
    data = datatools.get_data()
    if ('keys' not in data['discord']):
        data['discord']['keys'] = {}
    is_key_new = False
    if (key not in data['discord']['keys']):
        is_key_new = True
    elif (data['discord']['keys'][key] == value):
        logger.info("API key '{}' already has value '{}'".format(key, value))
        return
    data['discord']['keys'][key] = value
    datatools.write_data(data)
    key_text = ('added' if is_key_new else 'updated')
    logger.info("API key '{}' {} with value '{}'".format(key, key_text, value))

Adds a key to the bot's data

Args:
key: The name of the key to add
value: The value for the key


def dump(collection: BioCCollection, fp, pretty_print: bool = True):

    fp.write(dumps(collection, pretty_print))

Serialize ``collection`` as a BioC formatted stream to ``fp``.

Args:
collection: the BioC collection
fp: a ``.write()``-supporting file-like object
pretty_print: enables formatted XML


def tile_and_concat(image, latent, concat_latent=True):

  if not concat_latent:
    return image
  image_shape = common_layers.shape_list(image)
  latent_shape = common_layers.shape_list(latent)
  height, width = image_shape[1], image_shape[2]
  latent_dims = latent_shape[1]
  height_multiples = height
  pad = height - (height_multiples * latent_dims)
  latent = tf.reshape(latent, (-1, latent_dims, 1, 1))
  latent = tf.tile(latent, (1, height_multiples, width, 1))
  latent = tf.pad(latent, [[0, 0], [pad
  return tf.concat([image, latent], axis=-1)

Tile latent and concatenate to image across depth.

Args:
image: 4-D Tensor, (batch_size X height X width X channels)
latent: 2-D Tensor, (batch_size X latent_dims)
concat_latent: If set to False, the image is returned as is.

Returns:
concat_latent: 4-D Tensor, (batch_size X height X width X channels+1)
latent tiled and concatenated to the image across the channels.


def get_body(name):
    body = Pck()[name]
    body.propagate = (lambda date: get_orbit(name, date))
    return body

Retrieve the Body structure of a JPL .bsp file object

Args:
name (str)
Return:
:py:class:`~beyond.constants.Body`


def __init__(self, string_or_filelike, parser_delegate):

    if hasattr(string_or_filelike, 'readline'):
      line_reader = string_or_filelike.readline
    else:
      if six.PY2:
        string_or_filelike = unicode(string_or_filelike)
      string_io = io.StringIO(string_or_filelike)
      line_reader = string_io.readline

    def _text_line_reader():
      line = line_reader()
      if isinstance(line, bytes):
        line = line.decode('utf8')
      return line

    self._token_generator = tokenize.generate_tokens(_text_line_reader)
    self._filename = getattr(string_or_filelike, 'name', None)
    self._current_token = None
    self._delegate = parser_delegate
    self._advance_one_token()

Construct the parser.

Args:
string_or_filelike: Either the string to parse, or a file-like object
supporting the readline method.
parser_delegate: An instance of the ParserDelegate class, that will be
responsible for constructing appropriate objects for configurable
references and macros.


def _slice_shape(self, start, stop):
    if stop <= start:
        return DynamicRaggedShape._from_inner_shape([])
    elif start == 0:
        if stop <= self.num_row_partitions:
            if stop == 1:
                return DynamicRaggedShape._from_inner_shape([self.row_partitions[0].nrows()])
            new_row_partitions = self.row_partitions[:stop - 1]
            new_inner_shape = [new_row_partitions[-1].nvals()]
            return DynamicRaggedShape(new_row_partitions, new_inner_shape)
        else:
            if self.rank is None:
                new_inner_rank = stop - self.num_row_partitions
                new_inner_shape = self.inner_shape[:new_inner_rank]
                return DynamicRaggedShape(row_partitions=self.row_partitions, inner_shape=new_inner_shape, static_inner_shape=None, validate=False)
            elif self.rank <= stop:
                return self
            new_inner_rank = stop - self.num_row_partitions
            new_inner_shape = self.inner_shape[:new_inner_rank]
            return DynamicRaggedShape(row_partitions=self.row_partitions, inner_shape=new_inner_shape, static_inner_shape=tensor_shape.TensorShape([None] * new_inner_rank), validate=False)
    else:
        if self.rank is None or stop < self.rank:
            partial = self._slice_shape(0, stop)
        else:
            partial = self
        for x in partial.row_partitions:
            if not x.is_uniform():
                raise ValueError('All relevant dimensions must be uniform')
        if partial.rank is None:
            raise NotImplementedError('__getitem__[start:stop] where start > 0 not implemented')
        return DynamicRaggedShape._from_inner_shape(partial._with_num_row_partitions(0).inner_shape[start:])

Returns a shape self[start:stop].

If start == 0, then this truncates dimensions after stop.
If start != 0, then this will return a shape with num_row_partitions == 0.

See __getitem__.

Args:
start: the first dimension. 0 <= start <= rank
stop: the last dimension (exclusive). 0 <= stop <= rank


def scanJoiner(self, xEUI='*', strPSKd='threadjpaketest'):

        print '%s call scanJoiner' % self.port
        if not isinstance(xEUI, str):
            eui64 = self.__convertLongToString(xEUI)

            if len(eui64) < 16:
                eui64 = eui64.zfill(16)
                print eui64
        else:
            eui64 = xEUI

        timeout = 500

        cmd = WPANCTL_CMD + 'commissioner joiner-add %s %s %s' % (eui64, str(timeout), strPSKd)
        print cmd
        if not self.isActiveCommissioner:
            self.startCollapsedCommissioner()
        if self.__sendCommand(cmd)[0] != 'Fail':
            return True
        else:
            return False

scan Joiner

Args:
xEUI: Joiner's EUI-64
strPSKd: Joiner's PSKd for commissioning

Returns:
True: successful to add Joiner's steering data
False: fail to add Joiner's steering data


def _export_files(self, bq: bigquery_tools.BigQueryWrapper, element: 'ReadFromBigQueryRequest', table_reference: TableReference):
    job_labels = self._get_bq_metadata().add_additional_bq_job_labels(self.bigquery_job_labels)
    export_job_name = bigquery_tools.generate_bq_job_name(self._job_name, self._source_uuid, bigquery_tools.BigQueryJobTypes.EXPORT, element.obj_id)
    temp_location = self.options.view_as(GoogleCloudOptions).temp_location
    gcs_location = bigquery_export_destination_uri(self.gcs_location, temp_location, '%s%s' % (self._source_uuid, element.obj_id))
    try:
        if self.use_json_exports:
            job_ref = bq.perform_extract_job([gcs_location], export_job_name, table_reference, bigquery_tools.FileFormat.JSON, project=self._get_project(), job_labels=job_labels, include_header=False)
        else:
            job_ref = bq.perform_extract_job([gcs_location], export_job_name, table_reference, bigquery_tools.FileFormat.AVRO, project=self._get_project(), include_header=False, job_labels=job_labels, use_avro_logical_types=True)
        bq.wait_for_bq_job(job_ref)
    except Exception as exn:
        logging.warning('Error exporting table: %s. Note that external tables cannot be exported: https:
        raise
    metadata_list = FileSystems.match([gcs_location])[0].metadata_list
    if isinstance(table_reference, ValueProvider):
        table_ref = bigquery_tools.parse_table_reference(element.table, project=self._get_project())
    else:
        table_ref = table_reference
    table = bq.get_table(table_ref.projectId, table_ref.datasetId, table_ref.tableId)
    return (table.schema, metadata_list)

Runs a BigQuery export job.

Returns:
bigquery.TableSchema instance, a list of FileMetadata instances


def _make_env(resultdir=None):
    env = {'config': {}, 'resultdir': '', 'config_file': '', 'nodes': {}, 'phase': '', 'user': '', 'cwd': os.getcwd()}
    if resultdir:
        env_path = os.path.join(resultdir, 'env')
        if os.path.isfile(env_path):
            with open(env_path, 'r') as f:
                env.update(yaml.load(f))
                logger.debug('Loaded environment %s', env_path)
        if (('config_file' in env) and (env['config_file'] is not None)):
            if os.path.isfile(env['config_file']):
                with open(env['config_file'], 'r') as f:
                    env['config'].update(yaml.load(f))
                    logger.debug('Reloaded config %s', env['config'])
    return env

Loads the env from `resultdir` if not `None` or makes a new one.

An Enos environment handles all specific variables of an
experiment. This function either generates a new environment or
loads a previous one. If the value of `resultdir` is `None`, then
this function makes a new environment and return it. If the value
is a directory path that contains an Enos environment, then this function
loads and returns it.

In case of a directory path, this function also rereads the
configuration file (the reservation.yaml) and reloads it. This
lets the user update his configuration between each phase.

Args:
resultdir (str): directory path to load the env from.


def strides(self) -> List[int]:
    return _compute_mesh_strides(self.shape())

Returns the strides tensor array for this mesh.

If the mesh shape is `[a, b, c, d]`, then the strides array can be computed
as `[b*c*d, c*d, d, 1]`. This array can be useful in computing local device
offsets given a device ID. Using the same example, the device coordinates of
the mesh can be computed as:

```
[(device_id / (b*c*d)) % a,
(device_id / (c*d))   % b,
(device_id / (d))     % c,
(device_id)           % d]
```

This is the same as `(device_id // mesh.strides) % mesh.shape`.

Returns:
The mesh strides as an integer tensor.


def content(self, request, id):
    gist = self.send(request, id).json()

    def convert(data):
        return base64.b64decode(data).decode('utf-8')
    content = {}
    for (name, data) in gist['files'].items():
        content[name] = convert(data['content'])
    return content

Returns the content of the gist

Arguments:
request: an initial request object
id:      the gist identifier

Returns:
A dict containing the contents of each file in the gist


def _check_triple_quotes(self, quote_record):
    (_, triple, row, col) = quote_record
    if (triple != TRIPLE_QUOTE_OPTS.get(self.config.triple_quote)):
        self._invalid_triple_quote(triple, row, col)

Check if the triple quote from tokenization is valid.

Args:
quote_record: a tuple containing the info about the string
from tokenization, giving the (token, quote, row number, column).


def Get(self, path, follow_symlink=True):
    key = self._Key(path=path, follow_symlink=follow_symlink)
    try:
        return self._cache[key]
    except KeyError:
        value = Stat.FromPath(path, follow_symlink=follow_symlink)
        self._cache[key] = value
        if ((not follow_symlink) and (not value.IsSymlink())):
            self._cache[self._Key(path=path, follow_symlink=True)] = value
        return value

Stats given file or returns a cached result if available.

Args:
path: A path to the file to perform `stat` on.
follow_symlink: True if `stat` of a symlink should be returned instead of
a file that it points to. For non-symlinks this setting has no effect.

Returns:
`Stat` object corresponding to the given path.


def __setitem__(self,key,value):

        self.rdb.hset(self.session_hash,key,value)
        self.rdb.expire(self.session_hash,self.ttl)

Set an existing or new key, value association.

Args:
key (str): The dictionary key.
value (str): The dictionary value


def get_day_end(config):

    day_start_datetime = datetime.datetime.combine(datetime.date.today(), config['day_start'])
    day_end_datetime = day_start_datetime - datetime.timedelta(seconds=1)
    return day_end_datetime.time()

Get the day end time given the day start. This assumes full 24h day.

Args:
config (dict): Configdict. Needed to extract ``day_start``.

Note:
This is merely a convinience funtion so we do not have to deduct this from ``day_start``
by hand all the time.


def push(self, value):
    stream = DataStream.FromEncoded(value.stream)
    if (stream.stream_type == DataStream.OutputType):
        if (len(self.streaming_data) == self.streaming_length):
            raise StorageFullError('Streaming buffer full')
        self.streaming_data.append(value)
    else:
        if (len(self.storage_data) == self.storage_length):
            raise StorageFullError('Storage buffer full')
        self.storage_data.append(value)

Store a new value for the given stream.

Args:
value (IOTileReading): The value to store.  The stream
parameter must have the correct value


def cancel(self, queue):

        try:
            consumer = self._consumers[queue]
            yield consumer.channel.basic_cancel(consumer_tag=consumer.tag)
        except pika.exceptions.AMQPChannelError:

            pass
        except KeyError:
            defer.returnValue(None)

        try:
            yield consumer.channel.close()
        except pika.exceptions.AMQPChannelError:
            pass

        del self._consumers[queue]

Cancel the consumer for a queue.

Args:
queue (str): The name of the queue the consumer is subscribed to.

Returns:
defer.Deferred: A Deferred that fires when the consumer
is canceled, or None if the consumer was already canceled. Wrap
the call in :func:`.defer.maybeDeferred` to always receive a Deferred.


def __tf_tracing_type__(self, context: TracingContext) -> TraceType:

Returns the tracing type of this object.

The tracing type is used to build the signature of a tf.function
when traced, and to match arguments with existing signatures.
When a Function object is called, tf.function looks at the tracing type
of the call arguments. If an existing signature of matching type exists,
it will be used. Otherwise, a new function is traced, and its signature
will use the tracing type of the call arguments.

Args:
context: a context reserved for internal/future usage.

Returns:
The tracing type of this object.


def add_answer(self, vote, rationale):
    self.raw_answers.append({VOTE_KEY: vote, RATIONALE_KEY: rationale})

Add an answer

Args:
vote (int): the option that student voted for
rationale (str): the reason why the student vote for the option


def scale(self, scalar, ignored_variables=None, ignored_interactions=None, ignore_offset=False):
    if (ignored_variables is None):
        ignored_variables = set()
    elif (not isinstance(ignored_variables, abc.Container)):
        ignored_variables = set(ignored_variables)
    if (ignored_interactions is None):
        ignored_interactions = set()
    elif (not isinstance(ignored_interactions, abc.Container)):
        ignored_interactions = set(ignored_interactions)
    linear = self.linear
    for v in linear:
        if (v in ignored_variables):
            continue
        linear[v] *= scalar
    quadratic = self.quadratic
    for (u, v) in quadratic:
        if (((u, v) in ignored_interactions) or ((v, u) in ignored_interactions)):
            continue
        quadratic[(u, v)] *= scalar
    if (not ignore_offset):
        self.offset *= scalar
    try:
        self._counterpart.scale(scalar, ignored_variables=ignored_variables, ignored_interactions=ignored_interactions)
    except AttributeError:
        pass

Multiply by the specified scalar all the biases and offset of a binary quadratic model.

Args:
scalar (number):
Value by which to scale the energy range of the binary quadratic model.

ignored_variables (iterable, optional):
Biases associated with these variables are not scaled.

ignored_interactions (iterable[tuple], optional):
As an iterable of 2-tuples. Biases associated with these interactions are not scaled.

ignore_offset (bool, default=False):
If True, the offset is not scaled.

Examples:

This example creates a binary quadratic model and then scales it to half
the original energy range.

>>> import dimod
...
>>> bqm = dimod.BinaryQuadraticModel({'a': -2.0, 'b': 2.0}, {('a', 'b'): -1.0}, 1.0, dimod.SPIN)
>>> bqm.scale(0.5)
>>> bqm.linear['a']
-1.0
>>> bqm.quadratic[('a', 'b')]
-0.5
>>> bqm.offset
0.5


def _get_variation_id(value, capital=False):

        value = int(value)
        base_power = base_start = base_end = 0
        while value >= base_end:
            base_power += 1
            base_start = base_end
            base_end += pow(26, base_power)
        base_index = value - base_start

        alphas = ['a'] * base_power
        for index in range(base_power - 1, -1, -1):
            alphas[index] = chr(int(97 + (base_index % 26)))
            base_index /= 26

        characters = ''.join(alphas)
        return characters.upper() if capital else characters

Convert an integer value to a character. a-z then double aa-zz etc
Args:
value (int): integer index we're looking up
capital (bool): whether we convert to capitals or not
Returns (str): alphanumeric representation of the index


def _infer(self, request):

    label_vocab = inference_utils.get_label_vocab(
      request.args.get('label_vocab_path'))

    try:
      if request.method != 'GET':
        logger.error('%s requests are forbidden.', request.method)
        return http_util.Respond(request, {'error': 'invalid non-GET request'},
                                    'application/json', code=405)

      (inference_addresses, model_names, model_versions,
          model_signatures) = self._parse_request_arguments(request)

      indices_to_infer = sorted(self.updated_example_indices)
      examples_to_infer = [self.examples[index] for index in indices_to_infer]
      infer_objs = []
      for model_num in xrange(len(inference_addresses)):
        serving_bundle = inference_utils.ServingBundle(
            inference_addresses[model_num],
            model_names[model_num],
            request.args.get('model_type'),
            model_versions[model_num],
            model_signatures[model_num],
            request.args.get('use_predict') == 'true',
            request.args.get('predict_input_tensor'),
            request.args.get('predict_output_tensor'))
        infer_objs.append(inference_utils.run_inference_for_inference_results(
          examples_to_infer, serving_bundle))

      resp = {'indices': indices_to_infer, 'results': infer_objs}
      self.updated_example_indices = set()
      return http_util.Respond(request, {'inferences': json.dumps(resp),
                                         'vocab': json.dumps(label_vocab)},
                               'application/json')
    except common_utils.InvalidUserInputError as e:
      return http_util.Respond(request, {'error': e.message},
                               'application/json', code=400)
    except AbortionError as e:
      return http_util.Respond(request, {'error': e.details},
                               'application/json', code=400)

Returns JSON for the `vz-line-chart`s for a feature.

Args:
request: A request that should contain 'inference_address', 'model_name',
'model_type, 'model_version', 'model_signature' and 'label_vocab_path'.

Returns:
A list of JSON objects, one for each chart.


def remove_species(self, species):
    new_sites = []
    species = [get_el_sp(s) for s in species]
    for site in self._sites:
        new_sp_occu = {sp: amt for (sp, amt) in site.species.items() if (sp not in species)}
        if (len(new_sp_occu) > 0):
            new_sites.append(PeriodicSite(new_sp_occu, site.frac_coords, self._lattice, properties=site.properties))
    self._sites = new_sites

Remove all occurrences of several species from a structure.

Args:
species: Sequence of species to remove, e.g., ["Li", "Na"].


def __init__(self, script_hash=None, key=None):

        self.ScriptHash = script_hash
        self.Key = key

Create an instance.

Args:
script_hash (UInt160):
key (bytes):


def __pad_value(value, pad_len_multiple, pad_char):

    assert pad_len_multiple > 0
    assert len(pad_char) == 1
    padding_length = (pad_len_multiple -
                      (len(value) % pad_len_multiple)) % pad_len_multiple
    return value + pad_char * padding_length

Add padding characters to the value if needed.

Args:
value: The string value to be padded.
pad_len_multiple: Pad the result so its length is a multiple
of pad_len_multiple.
pad_char: The character to use for padding.

Returns:
The string value with padding characters added.


def stop(self, consumer):
    stopped_workflows = []
    for request in [r for r in consumer.controller.state.active_requests]:
        job = AsyncResult(request.id)
        workflow_id = job.result['workflow_id']
        if (workflow_id not in stopped_workflows):
            client = Client(SignalConnection(**consumer.app.user_options['config'].signal, auto_connect=True), request_key=workflow_id)
            client.send(Request(action='stop_workflow'))
            stopped_workflows.append(workflow_id)

This function is called when the worker received a request to terminate.

Upon the termination of the worker, the workflows for all running jobs are
stopped gracefully.

Args:
consumer (Consumer): Reference to the consumer object that handles messages
from the broker.


def get_soundcloud_data(url):
    data = {}
    request = requests.get(url)
    title_tag = request.text.split('<title>')[1].split('</title')[0]
    data['title'] = title_tag.split(' by ')[0].strip()
    data['artist'] = title_tag.split(' by ')[1].split('|')[0].strip()
    return data

Scrapes a SoundCloud page for a track's important information.

Returns:
dict: of audio data


def translate_ostat(ostat):
    ostat_lower = ostat.strip().lower()
    if (ostat_lower == 'monomer'):
        return 1
    elif (ostat_lower == 'homo-dimer'):
        return 2
    elif (ostat_lower == 'homo-trimer'):
        return 3
    elif (ostat_lower == 'homo-tetramer'):
        return 4
    elif (ostat_lower == 'homo-pentamer'):
        return 5
    elif (ostat_lower == 'homo-hexamer'):
        return 6
    elif (ostat_lower == 'homo-heptamer'):
        return 7
    elif (ostat_lower == 'homo-octamer'):
        return 8
    else:
        num = int(ostat_lower.split('-')[1])
        return num

Translate the OSTAT field to an integer.

As of 2018-02-26, works on all E. coli models. Untested on other pre-made organism models.

Args:
ostat (str): Predicted oligomeric state of the PDB file

Returns:
int: Translated string to integer


def find_or_create_all(cls, list_of_kwargs, keys=[]):
    (list_of_kwargs_wo_dupes, markers) = remove_and_mark_duplicate_dicts(list_of_kwargs, keys)
    added_objs = cls.add_all([(cls.first(**subdict(kwargs, keys)) or cls.new(**kwargs)) for kwargs in list_of_kwargs_wo_dupes])
    result_objs = []
    iterator_of_added_objs = iter(added_objs)
    for idx in range(len(list_of_kwargs)):
        if (idx in markers):
            result_objs.append(added_objs[markers[idx]])
        else:
            result_objs.append(next(iterator_of_added_objs))
    return result_objs

Batch method for querying for a list of instances and
creating them if required

Args:
list_of_kwargs(list of dicts): A list of dicts where
each dict denotes the keyword args that you would pass
to the create method separately

keys (list, optional): A list of keys to use for the
initial finding step. Matching is done only on these
attributes.

Examples:

>>> Customer.find_or_create_all([
... {'name': 'Vicky', 'email': 'vicky@x.com', 'age': 34},
... {'name': 'Ron', 'age': 40, 'email': 'ron@x.com',
... 'gender': 'Male'}], keys=['name', 'email'])


def forward(self, hidden_states, output_router_logits):
    forwarded_states, router_tuple = self.mlp(hidden_states)
    forwarded_states += torch.tanh(self.soft_bypass_mlp(hidden_states))
    output = hidden_states + self.norm(forwarded_states)
    if output_router_logits and router_tuple is not None:
        return (output, router_tuple)
    else:
        return output

Args:
hidden_states (`torch.Tensor`) :
[num_groups, tokens_per_group, hidden_dim] inputs to send to experts.
output_router_logits (`bool`) :
output experts router output.
Returns:
torch.Tensor[num_groups, tokens_per_group, hidden_dim]


def _GetFormatErrorLocation(
      self, yaml_definition, last_definition_object):

    name = yaml_definition.get('name', None)
    if name:
      error_location = 'in: {0:s}'.format(name or '<NAMELESS>')
    elif last_definition_object:
      error_location = 'after: {0:s}'.format(last_definition_object.name)
    else:
      error_location = 'at start'

    return error_location

Retrieves a format error location.

Args:
yaml_definition (dict[str, object]): current YAML definition.
last_definition_object (DataTypeDefinition): previous data type
definition.

Returns:
str: format error location.


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

    query_hash = hash(query)

    event_data = TwitterIOSStatusEventData()
    event_data.favorite_count = self._GetRowValue(
        query_hash, row, 'favoriteCount')
    event_data.favorited = self._GetRowValue(query_hash, row, 'favorited')
    event_data.name = self._GetRowValue(query_hash, row, 'name')
    event_data.query = query
    event_data.retweet_count = self._GetRowValue(
        query_hash, row, 'retweetCount')
    event_data.text = self._GetRowValue(query_hash, row, 'text')
    event_data.user_id = self._GetRowValue(query_hash, row, 'user_id')

    timestamp = self._GetRowValue(query_hash, row, 'date')
    if timestamp:

      timestamp = int(timestamp)
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_CREATION)
      parser_mediator.ProduceEventWithEventData(event, event_data)

    timestamp = self._GetRowValue(query_hash, row, 'updatedAt')
    if timestamp:

      timestamp = int(timestamp)
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_UPDATE)
      parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a contact row from the database.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row resulting from query.


def __init__(self, data_type_definition):

    super(StreamMap, self).__init__(data_type_definition)
    self._fold_byte_stream = None
    self._map_byte_stream = None

    if self._element_data_type_definition.IsComposite():
      raise errors.FormatError('Unsupported composite element data type')

Initializes a stream 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 reset(self, name=None):
    if self._reader_ref.dtype == dtypes.resource:
        return gen_io_ops.reader_reset_v2(self._reader_ref, name=name)
    else:
        return gen_io_ops.reader_reset(self._reader_ref, name=name)

Restore a reader to its initial clean state.

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

Returns:
The created Operation.


def ParseOptions(cls, options, configuration_object):

    if not isinstance(configuration_object, tools.CLITool):
      raise errors.BadConfigObject(
          'Configuration object is not an instance of CLITool')

    preferred_year = cls._ParseNumericOption(options, 'preferred_year')

    process_archives = getattr(options, 'process_archives', False)
    process_compressed_streams = getattr(
        options, 'process_compressed_streams', True)

    setattr(configuration_object, '_preferred_year', preferred_year)
    setattr(configuration_object, '_process_archives', process_archives)
    setattr(
        configuration_object, '_process_compressed_streams',
        process_compressed_streams)

Parses and validates options.

Args:
options (argparse.Namespace): parser options.
configuration_object (CLITool): object to be configured by the argument
helper.

Raises:
BadConfigObject: when the configuration object is of the wrong type.


def _create_dom(data):
    if (not isinstance(data, dhtmlparser.HTMLElement)):
        data = dhtmlparser.parseString(utils.handle_encodnig(data))
    dhtmlparser.makeDoubleLinked(data)
    return data

Creates doublelinked DOM from `data`.

Args:
data (str/HTMLElement): Either string or HTML element.

Returns:
obj: HTMLElement containing double linked DOM.


async def _get_async(self, url, session):
    data = None
    async with session.get(url) as resp:
        if (resp.status == 200):
            data = (await resp.json())
    return data

Asynchronous internal method used for GET requests

Args:
url (str): URL to fetch
session (obj): aiohttp client session for async loop

Returns:
data (obj): Individual URL request's response corountine


def saml_metadata(self, client_id):
    return self.get(url='https:

Get SAML2.0 Metadata.

Args:
client_id (str): Client Id of the application to get the SAML metadata for.


def require_params(self, req):

        params = {}

        for name, param in self.params.items():
            if name not in req.params and param.required:

                missing = set(
                    p for p in self.params
                    if self.params[p].required
                ) - set(req.params.keys())

                raise errors.HTTPMissingParam(", ".join(missing))

            elif name in req.params or param.default:

                try:
                    if param.many:

                        values = req.get_param_as_list(

                            name, param.validated_value
                        ) or [
                            param.default and
                            param.validated_value(param.default)
                        ]
                        params[name] = param.container(values)
                    else:

                        params[name] = param.validated_value(
                            req.get_param(name, default=param.default)
                        )

                except ValidationError as err:

                    raise err.as_invalid_param(name)

                except ValueError as err:

                    raise errors.HTTPInvalidParam(str(err), name)

        return params

Require all defined parameters from request query string.

Raises ``falcon.errors.HTTPMissingParam`` exception if any of required
parameters is missing and ``falcon.errors.HTTPInvalidParam`` if any
of parameters could not be understood (wrong format).

Args:
req (falcon.Request): request object


def fit(self, train_x, train_y):

        if self.first_fitted:
            self.incremental_fit(train_x, train_y)
        else:
            self.first_fit(train_x, train_y)

Fit the regressor with more data.
Args:
train_x: A list of NetworkDescriptor.
train_y: A list of metric values.


def log_likelihood(self, y, _const=math.log((2.0 * math.pi)), quiet=False):
    y = self._process_input(y)
    resid = (y - self.mean.get_value(self._t))
    try:
        self._recompute()
    except solver.LinAlgError:
        if quiet:
            return (- np.inf)
        raise
    if (len(y.shape) > 1):
        raise ValueError('dimension mismatch')
    logdet = self.solver.log_determinant()
    if (not np.isfinite(logdet)):
        return (- np.inf)
    loglike = ((- 0.5) * ((self.solver.dot_solve(resid) + logdet) + (len(y) * _const)))
    if (not np.isfinite(loglike)):
        return (- np.inf)
    return loglike

Compute the marginalized likelihood of the GP model

The factorized matrix from the previous call to :func:`GP.compute` is
used so ``compute`` must be called first.

Args:
y (array[n]): The observations at coordinates ``x`` from
:func:`GP.compute`.
quiet (bool): If true, return ``-numpy.inf`` for non-positive
definite matrices instead of throwing an error.

Returns:
float: The marginalized likelihood of the GP model.

Raises:
ValueError: For mismatched dimensions.
solver.LinAlgError: For non-positive definite matrices.


def from_corpus(cls, corpus):

        ds = Corpus()

        tracks = copy.deepcopy(list(corpus.tracks.values()))
        track_mapping = ds.import_tracks(tracks)

        issuers = copy.deepcopy(list(corpus.issuers.values()))
        issuer_mapping = ds.import_issuers(issuers)

        utterances = copy.deepcopy(list(corpus.utterances.values()))
        for utterance in utterances:
            utterance.track = track_mapping[utterance.track.idx]

            if utterance.issuer is not None:
                utterance.issuer = issuer_mapping[utterance.issuer.idx]

        ds.import_utterances(utterances)

        subviews = copy.deepcopy(corpus.subviews)
        for subview_idx, subview in subviews.items():
            ds.import_subview(subview_idx, subview)

        for feat_container_idx, feature_container in corpus.feature_containers.items():
            ds.new_feature_container(feat_container_idx, feature_container.path)

        return ds

Create a new modifiable corpus from any other CorpusView.
This for example can be used to create a independent modifiable corpus from a subview.

Args:
corpus (CorpusView): The corpus to create a copy from.

Returns:
Corpus: A new corpus with the same data as the given one.


def __init__(self, faulty_file, msg):

        self.file = faulty_file
        self.msg = msg
        super().__init__(faulty_file, msg)

Initialization of instances:

Args:
faulty_file (pathlike): path of the file where a parsing problem
was encountered.
msg (str): error message.

Attributes:
file (pathlike): path of the file where a parsing problem was
encountered.
msg (str): error message.


def pi_to_number(self, page=1, item=1):

        if page > 1:
            return ((page - 1) * self.page_items) + item
        else:
            return 0 + item

Convert subpage & subitem to a integer

* if page == 1, then return 0, since the item count is the true # of items
* if page == 2, then return, page-1 * items_per_page, since we are
returning the # of items on a full page.

Args:
* None

Returns:
* Integer - Which represents the number of items up to the page.


def __getitem__(self, column):

        if isinstance(column, (list, tuple)):
            ret = []
            for col in column:
                ret.append(self[col])
            return ret

        try:
            return self._values[self._index[column]]
        except (KeyError, TypeError, ValueError):
            pass

        try:
            return self._values[column]
        except (IndexError, TypeError):
            pass

        raise IndexError('No such column "%s" in row.' % column)

Support for [] notation.

Args:
column: Tuple of column names, or a (str) column name, or positional
column number, 0-indexed.

Returns:
A list or string with column value(s).

Raises:
IndexError: The given column(s) were not found.


def classify_coincident(st_vals, coincident):
    if (not coincident):
        return None
    if ((st_vals[(0, 0)] >= st_vals[(0, 1)]) or (st_vals[(1, 0)] >= st_vals[(1, 1)])):
        return UNUSED_T
    else:
        return CLASSIFICATION_T.COINCIDENT

r"""Determine if coincident parameters are "unused".

.. note::

This is a helper for :func:`surface_intersections`.

In the case that ``coincident`` is :data:`True`, then we'll have two
sets of parameters :math:`(s_1, t_1)` and :math:`(s_2, t_2)`.

If one of :math:`s1 < s2` or :math:`t1 < t2` is not satisfied, the
coincident segments will be moving in opposite directions, hence don't
define an interior of an intersection.

.. warning::

In the "coincident" case, this assumes, but doesn't check, that
``st_vals`` is ``2 x 2``.

Args:
st_vals (numpy.ndarray): ``2 X N`` array of intersection parameters.
coincident (bool): Flag indicating if the intersections are the
endpoints of coincident segments of two curves.

Returns:
Optional[.IntersectionClassification]: The classification of the
intersections.


def _InvokeGitkitApi(self, method, params=None, need_service_account=True):
    body = (simplejson.dumps(params) if params else None)
    req = urllib_request.Request((self.google_api_url + method))
    req.add_header('Content-type', 'application/json')
    if need_service_account:
        if self.credentials:
            access_token = self.credentials.get_access_token().access_token
        elif (self.service_account_email and self.service_account_key):
            access_token = self._GetAccessToken()
        else:
            raise errors.GitkitClientError('Missing service account credentials')
        req.add_header('Authorization', ('Bearer ' + access_token))
    try:
        binary_body = (body.encode('utf-8') if body else None)
        raw_response = urllib_request.urlopen(req, binary_body).read()
    except urllib_request.HTTPError as err:
        if (err.code == 400):
            raw_response = err.read()
        else:
            raise
    return self._CheckGitkitError(raw_response)

Invokes Gitkit API, with optional access token for service account.

Args:
method: string, the api method name.
params: dict of optional parameters for the API.
need_service_account: false if service account is not needed.

Raises:
GitkitClientError: if the request is bad.
GitkitServerError: if Gitkit can not handle the request.

Returns:
API response as dict.


def num_gpus():
    return context().num_gpus()

Get the number of available GPU devices.

Returns:
The number of available GPU devices.


def putenv(key, value):
    key = path2fsn(key)
    value = path2fsn(value)
    if (is_win and PY2):
        try:
            set_windows_env_var(key, value)
        except WindowsError:
            raise ValueError
    else:
        try:
            os.putenv(key, value)
        except OSError:
            raise ValueError

Like `os.putenv` but takes unicode under Windows + Python 2

Args:
key (pathlike): The env var to get
value (pathlike): The value to set
Raises:
ValueError


def _example_from_array_spec(self, prop_spec):
    if isinstance(prop_spec['items'], list):
        return [self.get_example_from_prop_spec(item_prop_spec) for item_prop_spec in prop_spec['items']]
    elif ('type' in prop_spec['items'].keys()):
        if (('format' in prop_spec['items'].keys()) and (prop_spec['items']['format'] == 'date-time')):
            return self._get_example_from_basic_type('datetime')
        else:
            return self._get_example_from_basic_type(prop_spec['items']['type'])
    elif (('$ref' in prop_spec['items'].keys()) or (('schema' in prop_spec) and ('$ref' in prop_spec['schema']['items'].keys()))):
        definition_name = (self.get_definition_name_from_ref(prop_spec['items']['$ref']) or self.get_definition_name_from_ref(prop_spec['schema']['items']['$ref']))
        if self.build_one_definition_example(definition_name):
            example_dict = self.definitions_example[definition_name]
            if (not isinstance(example_dict, dict)):
                return [example_dict]
            if (len(example_dict) == 1):
                try:
                    res = example_dict[example_dict.keys()[0]]
                except TypeError:
                    res = example_dict[list(example_dict)[0]]
                return res
            else:
                return_value = {}
                for (example_name, example_value) in example_dict.items():
                    return_value[example_name] = example_value
                return [return_value]
    elif ('properties' in prop_spec['items']):
        prop_example = {}
        for (prop_name, prop_spec) in prop_spec['items']['properties'].items():
            example = self.get_example_from_prop_spec(prop_spec)
            if (example is not None):
                prop_example[prop_name] = example
        return [prop_example]

Get an example from a property specification of an array.

Args:
prop_spec: property specification you want an example of.

Returns:
An example array.


def apply_transformation(self, structure):

        if structure.is_ordered:
            return structure

        species = [dict(sp) for sp in structure.species_and_occu]

        for sp in species:
            for k, v in sp.items():
                old_occ = sp[k]
                new_occ = float(
                    Fraction(old_occ).limit_denominator(self.max_denominator))
                if self.fix_denominator:
                    new_occ = around(old_occ*self.max_denominator)\
                        / self.max_denominator
                if round(abs(old_occ - new_occ), 6) > self.tol:
                    raise RuntimeError(
                        "Cannot discretize structure within tolerance!")
                sp[k] = new_occ

        return Structure(structure.lattice, species, structure.frac_coords)

Discretizes the site occupancies in the structure.

Args:
structure: disordered Structure to discretize occupancies

Returns:
A new disordered Structure with occupancies discretized


def _make_dense_default(self, key, shape, dtype):
    default_value = self.dense_defaults.get(key)
    if shape.ndims is not None and shape.ndims > 0 and (shape.dims[0].value is None):
        if default_value is None:
            default_value = ops.convert_to_tensor('' if dtype == dtypes.string else 0, dtype=dtype)
        else:
            key_name = 'padding_' + re.sub('[^A-Za-z0-9_.\\-/]', '_', key)
            default_value = ops.convert_to_tensor(default_value, dtype=dtype, name=key_name)
            default_value = array_ops.reshape(default_value, [])
    elif default_value is None:
        default_value = constant_op.constant([], dtype=dtype)
    elif not isinstance(default_value, tensor.Tensor):
        key_name = 'key_' + re.sub('[^A-Za-z0-9_.\\-/]', '_', key)
        default_value = ops.convert_to_tensor(default_value, dtype=dtype, name=key_name)
        default_value = array_ops.reshape(default_value, shape)
    return default_value

Construct the default value tensor for a specified dense feature.

Args:
key: The key string identifying the dense feature.
shape: The dense feature's shape.
dtype: The dense feature's dtype.

Returns:
A Tensor.


def _enrichment_test_preprocessor(test_spec: dict, expected: List[str], env: TestEnvironment):
    if (pipeline := test_spec.get('pipeline', None)):
        for transform in pipeline.get('transforms', []):
            if transform.get('type', '').startswith('Enrichment'):
                transform['type'] = 'TestEnrichment'
    return test_spec

Preprocessor for tests that involve the Enrichment transform.

This preprocessor replaces the actual Enrichment transform with a mock
`TestEnrichment` transform. This allows the test to verify the pipeline's
correctness without requiring external services like BigTable or BigQuery.

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

Returns:
The modified test_spec dictionary with Enrichment transforms replaced.


def structure_path(self, path):
    if (not path):
        self.structure_dir = None
        self.structure_file = None
    else:
        if (not op.exists(path)):
            raise OSError('{}: file does not exist!'.format(path))
        if (not op.dirname(path)):
            self.structure_dir = '.'
        else:
            self.structure_dir = op.dirname(path)
        self.structure_file = op.basename(path)

Provide pointers to the paths of the structure file

Args:
path: Path to structure file


def update(self, *args, **kwargs):
    for next_dict in chain(args, (kwargs,)):
        for (k, v) in next_dict.items():
            self[k] = v

Equivalent to the python dict update method.

Update the dictionary with the key/value pairs from other, overwriting
existing keys.

Args:
other (dict): The source of key value pairs to add to headers
Keyword Args:
All keyword arguments are stored in header directly

Returns:
None


def add_node(self, node_id, name, labels):
    node = self.graph_db.get_or_create_indexed_node('Node', 'node_id', node_id, {'node_id': node_id, 'name': name})
    try:
        node.add_labels(*labels)
    except NotImplementedError:
        pass

Add the node with name and labels.

Args:
node_id: Id for the node.
name: Name for the node.
labels: Label for the node.

Raises:
NotImplementedError: When adding labels is not supported.


def apply_grad_processors(opt, gradprocs):
    assert isinstance(gradprocs, (list, tuple)), gradprocs
    for gp in gradprocs:
        assert isinstance(gp, GradientProcessor), gp

    class _ApplyGradientProcessor(ProxyOptimizer):

        def __init__(self, opt, gradprocs):
            self._gradprocs = gradprocs[:]
            super(_ApplyGradientProcessor, self).__init__(opt)

        def apply_gradients(self, grads_and_vars, global_step=None, name=None):
            g = self._apply(grads_and_vars)
            return self._opt.apply_gradients(g, global_step, name)

        def _apply(self, g):
            for proc in self._gradprocs:
                g = proc.process(g)
            return g
    return _ApplyGradientProcessor(opt, gradprocs)

Wrapper around optimizers to apply gradient processors.

Args:
opt (tf.train.Optimizer):
gradprocs (list[GradientProcessor]): gradient processors to add to the
optimizer.

Returns:
a :class:`tf.train.Optimizer` instance which runs the gradient
processors before updating the variables.


def __init__(self, model: PreTrainedModel):
    super().__init__()
    if model.generation_config is None:
        raise AssertionError('The model must have a generation config to be exported with static caching. Please set `generation_config`.')
    if not model.generation_config.use_cache:
        raise AssertionError('The model must have caching enabled to be exported with static caching. Please set `generation_config.use_cache=True`.')
    if model.generation_config.cache_implementation != 'static':
        raise AssertionError("The model must use a 'static' caching implementation to be exported with static caching. Please set `generation_config.cache_implementation='static'`.")
    self.model = model
    self.static_cache = StaticCache(config=self.model.config, max_batch_size=self.model.generation_config.cache_config.batch_size, max_cache_len=self.model.generation_config.cache_config.max_cache_len, device=self.model.generation_config.cache_config.device, dtype=self.model.dtype)
    for i in range(len(self.static_cache.key_cache)):
        self.register_buffer(f'key_cache_{i}', self.static_cache.key_cache[i], persistent=False)
        self.register_buffer(f'value_cache_{i}', self.static_cache.value_cache[i], persistent=False)

Initializes the wrapper module with the pretrained model.

Args:
model (`PreTrainedModel`): The pretrained model to wrap. The model must have caching
enabled and use a 'static' caching implementation.

Raises:
AssertionError: If the pretrained model does not have caching enabled or if it does
not use a 'static' caching implementation in `model.generation_config`.


def RegisterImplementation(cache_name, map_name, cache):
    global _cache_implementations
    if cache_name not in _cache_implementations:
        logging.info('Registering [%s] cache for [%s].', cache_name, map_name)
        _cache_implementations[cache_name] = {}
    _cache_implementations[cache_name][map_name] = cache

Register a Cache implementation with the CacheFactory.

Child modules are expected to call this method in the file-level scope
so that the CacheFactory is aware of them.

Args:
cache_name: (string) The name of the NSS backend.
map_name: (string) The name of the map handled by this Cache.
cache: A class type that is a subclass of Cache.

Returns: Nothing


def get_selector(self, name):

        try:
            return self.matcher.by_name[name]
        except (AttributeError, KeyError):
            if self.base is not None:
                return self.base.get_selector(name)
            else:
                raise KeyError("No selector found for style '{}'".format(name))

Find a selector mapped to a style in this or a base style sheet.

Args:
name (str): a style name

Returns:
:class:`.Selector`: the selector mapped to the style `name`

Raises:
KeyError: if the style `name` was not found in this or a base
style sheet


def op(name, data, bucket_count=None, display_name=None, description=None, collections=None):
    import tensorflow.compat.v1 as tf
    if (display_name is None):
        display_name = name
    summary_metadata = metadata.create_summary_metadata(display_name=display_name, description=description)
    with tf.name_scope(name):
        tensor = _buckets(data, bucket_count=bucket_count)
        return tf.summary.tensor_summary(name='histogram_summary', tensor=tensor, collections=collections, summary_metadata=summary_metadata)

Create a legacy histogram summary op.

Arguments:
name: A unique name for the generated summary node.
data: A `Tensor` of any shape. Must be castable to `float64`.
bucket_count: Optional positive `int`. The output will have this
many buckets, except in two edge cases. If there is no data, then
there are no buckets. If there is data but all points have the
same value, then there is one bucket whose left and right
endpoints are the same.
display_name: Optional name for this summary in TensorBoard, as a
constant `str`. Defaults to `name`.
description: Optional long-form description for this summary, as a
constant `str`. Markdown is supported. Defaults to empty.
collections: Optional list of graph collections keys. The new
summary op is added to these collections. Defaults to
`[Graph Keys.SUMMARIES]`.

Returns:
A TensorFlow summary op.


def setDocuments(self, documenting_pid, documented_pid):

        self._check_initialized()
        documenting_id = self.getObjectByPid(documenting_pid)
        documented_id = self.getObjectByPid(documented_pid)
        self.add((documenting_id, CITO.documents, documented_id))

Add a CiTO, the Citation Typing Ontology, triple asserting that
``documenting_pid`` documents ``documented_pid``.

Adds assertion: ``documenting_pid cito:documents documented_pid``

Args:
documenting_pid: str
PID of a Science Object that documents ``documented_pid``.

documented_pid: str
PID of a Science Object that is documented by ``documenting_pid``.


def print_stack_info(self):

        try:
            rest_api_id = None
            deployment_found = False

            response = self._cf_client.describe_stack_resources(
                StackName=self._stack_name
            )

            print('\nThe following resources were created:')
            rows = []
            for resource in response['StackResources']:
                if resource['ResourceType'] == 'AWS::ApiGateway::RestApi':
                    rest_api_id = resource['PhysicalResourceId']
                elif resource['ResourceType'] == 'AWS::ApiGateway::Deployment':
                    deployment_found = True

                row = []
                row.append(resource['ResourceType'])
                row.append(resource['LogicalResourceId'])
                row.append(resource['PhysicalResourceId'])
                rows.append(row)

            print(tabulate(rows, headers=['Resource Type', 'Logical ID', 'Physical ID']))

            if rest_api_id and deployment_found:
                url = 'https:
                    rest_api_id,
                    self._region,
                    '<stage>'
                )
                print('\nThe deployed service can be found at this URL:')
                print('\t{}\n'.format(url))

            return response
        except Exception as wtf:
            print(wtf)
            return None

List resources from the given stack

Args:
None

Returns:
A dictionary filled resources or None if things went sideways


def WriteOutput(self, output_file, feed_merger,
                  old_feed_path, new_feed_path, merged_feed_path):

    if merged_feed_path is None:
      html_merged_feed_path = ''
    else:
      html_merged_feed_path = '
Merged feed created: %s
' % (
          merged_feed_path)

    html_header =  % locals()

    html_stats = self._GenerateStatsTable(feed_merger)
    html_summary = self._GenerateSummary()
    html_notices = self._GenerateNotices()
    html_errors = self._GenerateSection(transitfeed.TYPE_ERROR)
    html_warnings = self._GenerateSection(transitfeed.TYPE_WARNING)

    html_footer =  % (transitfeed.__version__,
              time.strftime('%B %d, %Y at %I:%M %p %Z'))

    output_file.write(transitfeed.EncodeUnicode(html_header))
    output_file.write(transitfeed.EncodeUnicode(html_stats))
    output_file.write(transitfeed.EncodeUnicode(html_summary))
    output_file.write(transitfeed.EncodeUnicode(html_notices))
    output_file.write(transitfeed.EncodeUnicode(html_errors))
    output_file.write(transitfeed.EncodeUnicode(html_warnings))
    output_file.write(transitfeed.EncodeUnicode(html_footer))

Write the HTML output to a file.

Args:
output_file: The file object that the HTML output will be written to.
feed_merger: The FeedMerger instance.
old_feed_path: The path to the old feed file as a string.
new_feed_path: The path to the new feed file as a string
merged_feed_path: The path to the merged feed file as a string. This
may be None if no merged feed was written.


def conv1d(x, kernel, strides=1, padding='valid', data_format=None, dilation_rate=1):
    if data_format is None:
        data_format = image_data_format()
    if data_format not in {'channels_first', 'channels_last'}:
        raise ValueError('Unknown data_format: ' + str(data_format))
    kernel_shape = kernel.shape.as_list()
    if padding == 'causal':
        left_pad = dilation_rate * (kernel_shape[0] - 1)
        x = temporal_padding(x, (left_pad, 0))
        padding = 'valid'
    padding = _preprocess_padding(padding)
    x, tf_data_format = _preprocess_conv1d_input(x, data_format)
    x = nn.convolution(input=x, filter=kernel, dilation_rate=dilation_rate, strides=strides, padding=padding, data_format=tf_data_format)
    if data_format == 'channels_first' and tf_data_format == 'NWC':
        x = array_ops.transpose(x, (0, 2, 1))
    return x

1D convolution.

Args:
x: Tensor or variable.
kernel: kernel tensor.
strides: stride integer.
padding: string, `"same"`, `"causal"` or `"valid"`.
data_format: string, one of "channels_last", "channels_first".
dilation_rate: integer dilate rate.

Returns:
A tensor, result of 1D convolution.

Raises:
ValueError: if `data_format` is neither `channels_last` or
`channels_first`.


def _section_from_possible_title(possible_title):
    for section in SECTION_TITLES:
        if _matches_section(possible_title, section):
            return section
    return None

Returns a section matched by the possible title, or None if none match.

Args:
possible_title: A string that may be the title of a new section.
Returns:
A Section type if one matches, or None if no section type matches.


def randint(self, low: int, high: int) -> int:

        return int(lib.TCOD_random_get_i(self.random_c, low, high))

Return a random integer within the linear range: low <= n <= high.

Args:
low (int): The lower bound of the random range.
high (int): The upper bound of the random range.

Returns:
int: A random integer.


def get_google_drive_folder_location():
    gdrive_db_path = 'Library/Application Support/Google/Drive/sync_config.db'
    yosemite_gdrive_db_path = 'Library/Application Support/Google/Drive/user_default/sync_config.db'
    yosemite_gdrive_db = os.path.join(os.environ['HOME'], yosemite_gdrive_db_path)
    if os.path.isfile(yosemite_gdrive_db):
        gdrive_db_path = yosemite_gdrive_db
    googledrive_home = None
    gdrive_db = os.path.join(os.environ['HOME'], gdrive_db_path)
    if os.path.isfile(gdrive_db):
        con = sqlite3.connect(gdrive_db)
        if con:
            cur = con.cursor()
            query = "SELECT data_value FROM data WHERE entry_key = 'local_sync_root_path';"
            cur.execute(query)
            data = cur.fetchone()
            googledrive_home = str(data[0])
            con.close()
    if (not googledrive_home):
        error('Unable to find your Google Drive install =(')
    return googledrive_home

Try to locate the Google Drive folder.

Returns:
(str) Full path to the current Google Drive folder


def set_cellpy_datadir(self, directory=None):

        if directory is None:
            self.logger.info("no directory name given")
            return
        if not os.path.isdir(directory):
            self.logger.info("directory does not exist")
            return
        self.cellpy_datadir = directory

Set the directory containing .hdf5-files.

Used for setting directory for looking for hdf5-files.
A valid directory name is required.

Args:
directory (str): path to hdf5-directory

Example:
>>> d = CellpyData()
>>> directory = "MyData/HDF5"
>>> d.set_raw_datadir(directory)


def DeregisterPlugin(cls, plugin_class):
    name = getattr(plugin_class, 'ARTIFACT_DEFINITION_NAME', plugin_class.__name__)
    name = name.lower()
    if (name not in cls._plugins):
        raise KeyError('Artifact plugin class not set for name: {0:s}.'.format(name))
    del cls._plugins[name]
    if (name in cls._file_system_plugins):
        del cls._file_system_plugins[name]
    if (name in cls._knowledge_base_plugins):
        del cls._knowledge_base_plugins[name]
    if (name in cls._windows_registry_plugins):
        del cls._windows_registry_plugins[name]

Deregisters an preprocess plugin class.

Args:
plugin_class (type): preprocess plugin class.

Raises:
KeyError: if plugin class is not set for the corresponding name.
TypeError: if the source type of the plugin class is not supported.