def _ConvertToTimestamp(self, date, time):
    if (len(date) != 8):
        raise ValueError('Unsupported length of date string: {0!s}'.format(repr(date)))
    if ((len(time) < 3) or (len(time) > 4)):
        raise ValueError('Unsupported length of time string: {0!s}'.format(repr(time)))
    try:
        year = int(date[:4], 10)
        month = int(date[4:6], 10)
        day = int(date[6:8], 10)
    except (TypeError, ValueError):
        raise ValueError('Unable to parse date string: {0!s}'.format(repr(date)))
    try:
        hour = int(time[:(- 2)], 10)
        minutes = int(time[(- 2):], 10)
    except (TypeError, ValueError):
        raise ValueError('Unable to parse time string: {0!s}'.format(repr(date)))
    time_elements_tuple = (year, month, day, hour, minutes, 0)
    date_time = dfdatetime_time_elements.TimeElements(time_elements_tuple=time_elements_tuple)
    date_time.is_local_time = True
    date_time._precision = dfdatetime_definitions.PRECISION_1_MINUTE
    return date_time

Converts date and time strings into a timestamp.

Recent versions of Office Scan write a log field with a Unix timestamp.
Older versions may not write this field; their logs only provide a date and
a time expressed in the local time zone. This functions handles the latter
case.

Args:
date (str): date as an 8-character string in the YYYYMMDD format.
time (str): time as a 3 or 4-character string in the [H]HMM format or a
6-character string in the HHMMSS format.

Returns:
dfdatetime_time_elements.TimestampElements: the parsed timestamp.

Raises:
ValueError: if the date and time values cannot be parsed.


def from_yang(self, text: str) -> ScalarValue:

        res = self.parse_value(text)
        if res is None:
            raise InvalidArgument(text)
        return res

Parse value specified in a YANG module.

Args:
text: String representation of the value.

Raises:
InvalidArgument: If the receiver type cannot parse the text.


def set_name(self, vid, name=None, default=False, disable=False):
    cmds = self.command_builder('name', value=name, default=default, disable=disable)
    return self.configure_vlan(vid, cmds)

Configures the VLAN name

EosVersion:
4.13.7M

Args:
vid (str): The VLAN ID to Configures
name (str): The value to configure the vlan name
default (bool): Defaults the VLAN ID name
disable (bool): Negates the VLAN ID name

Returns:
True if the operation was successful otherwise False


def join(self, delimiter=' ', overlap_threshold=0.1):
    sorted_by_start = sorted(self.labels)
    concat_values = []
    last_label_end = None
    for label in sorted_by_start:
        if ((last_label_end is None) or (((last_label_end - label.start) < overlap_threshold) and (last_label_end > 0))):
            concat_values.append(label.value)
            last_label_end = label.end
        else:
            raise ValueError('Labels overlap, not able to define the correct order')
    return delimiter.join(concat_values)

Return a string with all labels concatenated together.
The order of the labels is defined by the start of the label.
If the overlapping between two labels is greater than ``overlap_threshold``,
an Exception is thrown.

Args:
delimiter (str): A string to join two consecutive labels.
overlap_threshold (float): Maximum overlap between two consecutive labels.

Returns:
str: A string with all labels concatenated together.

Example:
>>> ll = LabelList(idx='some', labels=[
>>>     Label('a', start=0, end=4),
>>>     Label('b', start=3.95, end=6.0),
>>>     Label('c', start=7.0, end=10.2),
>>>     Label('d', start=10.3, end=14.0)
>>> ])
>>> ll.join(' - ')
'a - b - c - d'


def get_tick(self, index):
    name = self.tick_name(index)
    if (name is None):
        return [pack_error(ControllerSubsystem.SENSOR_GRAPH, Error.INVALID_ARRAY_KEY), 0]
    return [Error.NO_ERROR, self.ticks[name]]

Get a tick's interval.

Args:
index (int): The index of the tick that you want to fetch.

Returns:
int, int: Error code and The tick's interval in seconds.

A value of 0 means that the tick is disabled.


def _Enum(docstring, *names):

  enums = dict(zip(names, range(len(names))))
  reverse = dict((value, key) for key, value in enums.iteritems())
  enums['reverse_mapping'] = reverse
  enums['__doc__'] = docstring
  return type('Enum', (object,), enums)

Utility to generate enum classes used by annotations.

Args:
docstring: Docstring for the generated enum class.
*names: Enum names.

Returns:
A class that contains enum names as attributes.


def adjust_saturation(img, saturation_factor):
    if (not _is_pil_image(img)):
        raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
    enhancer = ImageEnhance.Color(img)
    img = enhancer.enhance(saturation_factor)
    return img

Adjust color saturation of an image.

Args:
img (PIL Image): PIL Image to be adjusted.
saturation_factor (float):  How much to adjust the saturation. 0 will
give a black and white image, 1 will give the original image while
2 will enhance the saturation by a factor of 2.

Returns:
PIL Image: Saturation adjusted image.


def parse_config(file_path):

    if not os.path.isfile(file_path):
        return {}
    parser = ConfigParser()
    parser.read(file_path)

    for s in parser._sections:
        for v in six.iterkeys(parser._sections[s]):
            parser._sections[s][v] = parser._sections[s][v].split("
    return parser._sections

Convert the CISM configuration file to a python dictionary

Args:
file_path: absolute path to the configuration file

Returns:
A dictionary representation of the given file


def managed(name, table, data, record=None):

    ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
    if record is None:
        record = name
    current_data = {
        column: __salt__['openvswitch.db_get'](table, record, column)
        for column in data
    }

    comment_changes = 'Columns have been updated.'
    comment_no_changes = 'All columns are already up to date.'
    comment_error = 'Error while updating column {0}: {1}'

    if __opts__['test']:
        for column in data:
            if data[column] != current_data[column]:
                ret['changes'][column] = {'old': current_data[column],
                                          'new': data[column]}
        if ret['changes']:
            ret['result'] = None
            ret['comment'] = comment_changes
        else:
            ret['result'] = True
            ret['comment'] = comment_no_changes
        return ret

    for column in data:
        if data[column] != current_data[column]:
            result = __salt__['openvswitch.db_set'](table, record, column,
                                                    data[column])
            if result is not None:
                ret['comment'] = comment_error.format(column, result)
                ret['result'] = False
                return ret
            ret['changes'][column] = {'old': current_data[column],
                                      'new': data[column]}
    ret['result'] = True
    ret['comment'] = comment_no_changes
    return ret

Ensures that the specified columns of the named record have the specified
values.

Args:
name: The name of the record.
table: The name of the table to which the record belongs.
data: Dictionary containing a mapping from column names to the desired
values. Columns that exist, but are not specified in this
dictionary are not touched.
record: The name of the record (optional). Replaces name if specified.


def device(self, idx):

        class GpuDevice(Structure):
            pass

        c_nvmlDevice_t = POINTER(GpuDevice)

        c_index = c_uint(idx)
        device = c_nvmlDevice_t()
        _check_return(_NVML.get_function(
            "nvmlDeviceGetHandleByIndex_v2")(c_index, byref(device)))
        return NvidiaDevice(device)

Get a specific GPU device

Args:
idx: index of device

Returns:
NvidiaDevice: single GPU device


def get_backdoor(self, name, version=''):

        params = {}
        params['or'] = 1
        params['c-name'] = name
        params['c-aliases__in'] = name
        r = requests.get('{0}/backdoors/'.format(self.url),
                         params=params,
                         verify=self.verify,
                         proxies=self.proxies)
        if r.status_code == 200:
            result_data = json.loads(r.text)
            if 'meta' not in result_data:
                return None
            if 'total_count' not in result_data['meta']:
                return None
            if result_data['meta']['total_count'] <= 0:
                return None
            if 'objects' not in result_data:
                return None
            for backdoor in result_data['objects']:
                if 'version' in backdoor:
                    if backdoor['version'] == version:
                        return backdoor
        else:
            log.error('Non-200 status code: {}'.format(r.status_code))
        return None

Searches for the backdoor based on name and version.

Args:
name: The name of the backdoor. This can be an alias.
version: The version.
Returns:
Returns a JSON object contain one or more backdoor results or
None if not found.


def _RecAnnotate(tree, annotate_name, annotate_value):
    for child in tree.children:
        _RecAnnotate(child, annotate_name, annotate_value)
    if isinstance(tree, pytree.Leaf):
        cur_annotate = pytree_utils.GetNodeAnnotation(tree, annotate_name, default=0)
        if cur_annotate < annotate_value:
            pytree_utils.SetNodeAnnotation(tree, annotate_name, annotate_value)

Recursively set the given annotation on all leafs of the subtree.

Takes care to only increase the penalty. If the node already has a higher
or equal penalty associated with it, this is a no-op.

Args:
tree: subtree to annotate
annotate_name: name of the annotation to set
annotate_value: value of the annotation to set


def __init__(self, fn, buffer_size=_DEFAULT_BUFFER_SIZE):
    if not callable(fn):
        raise TypeError('Expected a callable object instead of: %r' % fn)
    super().__init__()
    self._fn = fn
    self._buffer_size = buffer_size

Initializes a CallableFn object wrapping a callable.

Args:
fn: A callable object that reduces elements of an iterable to a single
value (like the builtins sum and max). This callable must be capable of
receiving the kind of values it generates as output in its input, and
for best results, its operation must be commutative and associative.

Raises:
TypeError: if fn parameter is not a callable type.


def debug_string(self, indent: int=0) -> str:
    self_repr = f'{'| ' * indent}{self.__class__.__name__}<{repr(self)}>'
    if self._children:
        child_repr = '\n'.join((child.debug_string(indent=indent + 1) for child in self._children))
        self_repr = f'{self_repr}\n{child_repr}'
    return self_repr

Returns a debug string for the tree rooted at this node.

Args:
indent: The level of indentation to begin printing the tree.

Returns:
A string representing this node and its descendant nodes.


def logical_not(x):
    if any_symbolic_tensors((x,)):
        return LogicalNot().symbolic_call(x)
    return backend.numpy.logical_not(x)

Computes the element-wise NOT of the given input tensor.

Zeros are treated as `False` and non-zeros are treated as `True`.

Args:
x: Input tensor.

Returns:
Output tensor, element-wise logical NOT of the input.


def build_graph(device, input_shape, perm, datatype, num_iters):
    with ops.device('/%s:0' % device):
        total_size = np.prod(input_shape)
        inp = np.arange(1, total_size + 1, dtype=datatype).reshape(input_shape)
        t = constant_op.constant(inp, shape=input_shape)
        outputs = []
        transpose_op = array_ops.transpose(t, perm)
        outputs.append(transpose_op)
        for _ in range(1, num_iters):
            with ops.control_dependencies([transpose_op]):
                transpose_op = array_ops.transpose(t, perm)
                outputs.append(transpose_op)
        return control_flow_ops.group(*outputs)

builds a graph containing a sequence of conv2d operations.

Args:
device: String, the device to run on.
input_shape: Shape of the input tensor.
perm: A list of ints with the same length as input tensor's dimension.
datatype: numpy data type of the input tensor.
num_iters: number of iterations to run transpose.

Returns:
An array of tensors to run()


def _compile_ast_node_to_ir(schema, current_schema_type, ast, location, context):
    basic_blocks = []
    local_unique_directives = get_unique_directives(ast)
    fields = _get_fields(ast)
    (vertex_fields, property_fields) = fields
    fragment = _get_inline_fragment(ast)
    filter_operations = get_local_filter_directives(ast, current_schema_type, vertex_fields)
    fragment_exists = (fragment is not None)
    fields_exist = (vertex_fields or property_fields)
    if (fragment_exists and fields_exist):
        raise GraphQLCompilationError(u'Cannot compile GraphQL that has inline fragment and selected fields in the same selection. Please move the selected fields inside the inline fragment.')
    if (location.field is not None):
        if fragment_exists:
            raise AssertionError(u'Found inline fragment at a property field: {} {}'.format(location, fragment))
        if (len(property_fields) > 0):
            raise AssertionError(u'Found property fields on a property field: {} {}'.format(location, property_fields))
    for filter_operation_info in filter_operations:
        filter_block = process_filter_directive(filter_operation_info, location, context)
        if (isinstance(location, FoldScopeLocation) and (location.field == COUNT_META_FIELD_NAME)):
            set_fold_innermost_scope(context)
            expected_field = expressions.LocalField(COUNT_META_FIELD_NAME)
            replacement_field = expressions.FoldedContextField(location, GraphQLInt)
            visitor_fn = expressions.make_replacement_visitor(expected_field, replacement_field)
            filter_block = filter_block.visit_and_update_expressions(visitor_fn)
            visitor_fn = expressions.make_type_replacement_visitor(expressions.ContextField, (lambda context_field: expressions.GlobalContextField(context_field.location, context_field.field_type)))
            filter_block = filter_block.visit_and_update_expressions(visitor_fn)
            set_fold_count_filter(context)
            context['global_filters'].append(filter_block)
        else:
            basic_blocks.append(filter_block)
    if (location.field is not None):
        _compile_property_ast(schema, current_schema_type, ast, location, context, local_unique_directives)
    elif fragment_exists:
        basic_blocks.extend(_compile_fragment_ast(schema, current_schema_type, fragment, location, context))
    else:
        basic_blocks.extend(_compile_vertex_ast(schema, current_schema_type, ast, location, context, local_unique_directives, fields))
    return basic_blocks

Compile the given GraphQL AST node into a list of basic blocks.

Args:
schema: GraphQL schema object, obtained from the graphql library
current_schema_type: GraphQLType, the schema type at the current location
ast: the current GraphQL AST node, obtained from the graphql library
location: Location object representing the current location in the query
context: dict, various per-compilation data (e.g. declared tags, whether the current block
is optional, etc.). May be mutated in-place in this function!

Returns:
list of basic blocks corresponding to this GraphQL AST node


def clean_dataset_tags(self):
    (tags_dict, wildcard_tags) = Tags.tagscleanupdicts()

    def delete_tag(tag):
        logger.info(('%s - Deleting tag %s!' % (self.data['name'], tag)))
        return (self.remove_tag(tag), False)

    def update_tag(tag, final_tags, wording, remove_existing=True):
        text = ('%s - %s: %s -> ' % (self.data['name'], wording, tag))
        if (not final_tags):
            logger.error(('%snothing!' % text))
            return (False, True)
        tags_lower_five = final_tags[:5].lower()
        if ((tags_lower_five == 'merge') or (tags_lower_five == 'split') or ((';' not in final_tags) and (len(final_tags) > 50))):
            logger.error(('%s%s - Invalid final tag!' % (text, final_tags)))
            return (False, True)
        if remove_existing:
            self.remove_tag(tag)
        tags = ', '.join(self.get_tags())
        if self.add_tags(final_tags.split(';')):
            logger.info(('%s%s! Dataset tags: %s' % (text, final_tags, tags)))
        else:
            logger.warning(('%s%s - At least one of the tags already exists! Dataset tags: %s' % (text, final_tags, tags)))
        return (True, False)

    def do_action(tag, tags_dict_key):
        whattodo = tags_dict[tags_dict_key]
        action = whattodo[u'action']
        final_tags = whattodo[u'final tags (semicolon separated)']
        if (action == u'Delete'):
            (changed, error) = delete_tag(tag)
        elif (action == u'Merge'):
            (changed, error) = update_tag(tag, final_tags, 'Merging')
        elif (action == u'Fix spelling'):
            (changed, error) = update_tag(tag, final_tags, 'Fixing spelling')
        elif (action == u'Non English'):
            (changed, error) = update_tag(tag, final_tags, 'Anglicising', remove_existing=False)
        else:
            changed = False
            error = False
        return (changed, error)

    def process_tag(tag):
        changed = False
        error = False
        if (tag in tags_dict.keys()):
            (changed, error) = do_action(tag, tag)
        else:
            for wildcard_tag in wildcard_tags:
                if fnmatch.fnmatch(tag, wildcard_tag):
                    (changed, error) = do_action(tag, wildcard_tag)
                    break
        return (changed, error)
    anychange = False
    anyerror = False
    for tag in self.get_tags():
        (changed, error) = process_tag(tag)
        if changed:
            anychange = True
        if error:
            anyerror = True
    return (anychange, anyerror)

Clean dataset tags according to tags cleanup spreadsheet and return if any changes occurred

Returns:
Tuple[bool, bool]: Returns (True if tags changed or False if not, True if error or False if not)


def get_videos_for_ids(
        edx_video_ids,
        sort_field=None,
        sort_dir=SortDirection.asc
):

    videos, __ = _get_videos_for_filter(
        {"edx_video_id__in":edx_video_ids},
        sort_field,
        sort_dir,
    )
    return videos

Returns an iterator of videos that match the given list of ids.

Args:
edx_video_ids (list)
sort_field (VideoSortField)
sort_dir (SortDirection)

Returns:
A generator expression that contains the videos found, sorted by the
given field and direction, with ties broken by edx_video_id to ensure a
total order


def __leastsq_fit(tomo_data, weights=None, trace=None, beta=None):
    if (trace is None):
        trace = 1.0
    data = tomo_data['data']
    keys = data[0]['circuit'].keys()
    counts = []
    shots = []
    ops = []
    for dat in data:
        for key in keys:
            counts.append(dat['counts'][key])
            shots.append(dat['shots'])
            projectors = dat['circuit'][key]
            op = __projector(projectors['meas'], tomo_data['meas_basis'])
            if ('prep' in projectors):
                op_prep = __projector(projectors['prep'], tomo_data['prep_basis'])
                op = np.kron(op_prep.conj(), op)
            ops.append(op)
    counts = np.array(counts)
    shots = np.array(shots)
    freqs = (counts / shots)
    if (weights is None):
        if (beta is None):
            beta = 0.50922
        K = len(keys)
        freqs_hedged = ((counts + beta) / (shots + (K * beta)))
        weights = np.sqrt((shots / (freqs_hedged * (1 - freqs_hedged))))
    return __tomo_linear_inv(freqs, ops, weights, trace=trace)

Reconstruct a state from unconstrained least-squares fitting.

Args:
tomo_data (list[dict]): state or process tomography data.
weights (list or array or None): weights to use for least squares
fitting. The default is standard deviation from a binomial
distribution.
trace (float or None): trace of returned operator. The default is 1.
beta (float or None): hedge parameter (>=0) for computing frequencies
from zero-count data. The default value is 0.50922.

Returns:
numpy.array: A numpy array of the reconstructed operator.


def site_specific_coordination_numbers(self):
    specific_coordination_numbers = {}
    for site in self.sites:
        specific_coordination_numbers[site.label] = site.site_specific_neighbours()
    return specific_coordination_numbers

Returns a dictionary of coordination numbers for each site type.

Args:
None

Returns:
(Dict(Str:List(Int))) : Dictionary of coordination numbers for each site type, e.g.::

{ 'A' : [ 2, 4 ], 'B' : [ 2 ] }


def get_settable_properties(cls):
    results = []
    for attr, value in vars(cls).items():
        if isinstance(value, property) and value.fset is not None:
            results.append(attr)
    return results

Gets the settable properties of a class.

Only returns the explicitly defined properties with setters.

Args:
cls: A class in Python.


def get_job(self, job_resource_name: str) -> Dict:

        return self.service.projects().programs().jobs().get(
            name=job_resource_name).execute()

Returns metadata about a previously created job.

See get_job_result if you want the results of the job and not just
metadata about the job.

Params:
job_resource_name: A string of the form
`projects/project_id/programs/program_id/jobs/job_id`.

Returns:
A dictionary containing the metadata.


def _get_formatted_date(dataset_date, date_format=None):

        if dataset_date:
            if date_format:
                return dataset_date.strftime(date_format)
            else:
                return dataset_date.date().isoformat()
        else:
            return None

Get supplied dataset date as string in specified format.
If no format is supplied, an ISO 8601 string is returned.

Args:
dataset_date (Optional[datetime.datetime]): dataset date in datetime.datetime format
date_format (Optional[str]): Date format. None is taken to be ISO 8601. Defaults to None.

Returns:
Optional[str]: Dataset date string or None if no date is set


def _GetValueAsObject(self, property_value):

    if property_value.type == pyolecf.value_types.BOOLEAN:
      return property_value.data_as_boolean

    if property_value.type in self._INTEGER_TYPES:
      return property_value.data_as_integer

    if property_value.type in self._STRING_TYPES:
      return property_value.data_as_string

    try:
      data = property_value.data
    except IOError:
      data = None

    return data

Retrieves the property value as a Python object.

Args:
property_value (pyolecf.property_value): OLECF property value.

Returns:
object: property value as a Python object.


def all(self, customer_id, data={}, **kwargs):
    url = '{}/{}/tokens'.format(self.base_url, customer_id)
    return self.get_url(url, data, **kwargs)

Get all tokens for given customer Id

Args:
customer_id : Customer Id for which tokens have to be fetched

Returns:
Token dicts for given cutomer Id


def _StartProfiling(self, configuration):

    if not configuration:
      return

    if configuration.HaveProfileMemoryGuppy():
      self._guppy_memory_profiler = profilers.GuppyMemoryProfiler(
          self._name, configuration)
      self._guppy_memory_profiler.Start()

    if configuration.HaveProfileMemory():
      self._memory_profiler = profilers.MemoryProfiler(
          self._name, configuration)
      self._memory_profiler.Start()

    if configuration.HaveProfileProcessing():
      identifier = '{0:s}-processing'.format(self._name)
      self._processing_profiler = profilers.ProcessingProfiler(
          identifier, configuration)
      self._processing_profiler.Start()

    if configuration.HaveProfileSerializers():
      identifier = '{0:s}-serializers'.format(self._name)
      self._serializers_profiler = profilers.SerializersProfiler(
          identifier, configuration)
      self._serializers_profiler.Start()

    if configuration.HaveProfileStorage():
      self._storage_profiler = profilers.StorageProfiler(
          self._name, configuration)
      self._storage_profiler.Start()

    if configuration.HaveProfileTaskQueue():
      self._task_queue_profiler = profilers.TaskQueueProfiler(
          self._name, configuration)
      self._task_queue_profiler.Start()

Starts profiling.

Args:
configuration (ProfilingConfiguration): profiling configuration.


def generate_name(self, name_format=DEFAULT_FILE_NAME_FORMAT):

        if len(self.segments) > 0:
            return self.segments[0].points[0].time.strftime(name_format) + ".gpx"
        else:
            return "EmptyTrack"

Generates a name for the track

The name is generated based on the date of the first point of the
track, or in case it doesn't exist, "EmptyTrack"

Args:
name_format (str, optional): Name formar to give to the track, based on
its start time. Defaults to DEFAULT_FILE_NAME_FORMAT
Returns:
str


def create_walker(self, selector, skip_all=True):
    if selector.buffered:
        walker = BufferedStreamWalker(selector, self._engine, skip_all=skip_all)
        self._queue_walkers.append(walker)
        return walker
    if (selector.match_type == DataStream.CounterType):
        walker = CounterStreamWalker(selector)
    else:
        walker = VirtualStreamWalker(selector)
    self._virtual_walkers.append(walker)
    return walker

Create a stream walker based on the given selector.

This function returns a StreamWalker subclass that will
remain up to date and allow iterating over and popping readings
from the stream(s) specified by the selector.

When the stream walker is done, it should be passed to
destroy_walker so that it is removed from internal lists that
are used to always keep it in sync.

Args:
selector (DataStreamSelector): The selector describing the
streams that we want to iterate over.
skip_all (bool): Whether to start at the beginning of the data
or to skip everything and start at the end.  Defaults
to skipping everything.  This parameter only has any
effect on buffered stream selectors.

Returns:
StreamWalker: A properly updating stream walker with the given selector.


def span_to_answer(self, text: str, start: int, end: int) -> Dict[str, Union[str, int]]:
    words = []
    token_idx = char_start_idx = char_end_idx = chars_idx = 0
    for i, word in enumerate(text.split(' ')):
        token = self.tokenizer.tokenize(word)
        if start <= token_idx <= end:
            if token_idx == start:
                char_start_idx = chars_idx
            if token_idx == end:
                char_end_idx = chars_idx + len(word)
            words += [word]
        if token_idx > end:
            break
        token_idx += len(token)
        chars_idx += len(word) + 1
    return {'answer': ' '.join(words), 'start': max(0, char_start_idx), 'end': min(len(text), char_end_idx)}

When decoding from token probabilities, this method maps token indexes to actual word in the initial context.

Args:
text (`str`): The actual context to extract the answer from.
start (`int`): The answer starting token index.
end (`int`): The answer end token index.

Returns:
Dictionary like `{'answer': str, 'start': int, 'end': int}`


def _ComputeUniquifier(self, debuggee):
    uniquifier = hashlib.sha1()
    if (('minorversion' not in debuggee.get('labels', [])) and ('sourceContexts' not in debuggee)):
        uniquifier_computer.ComputeApplicationUniquifier(uniquifier)
    return uniquifier.hexdigest()

Computes debuggee uniquifier.

The debuggee uniquifier has to be identical on all instances. Therefore the
uniquifier should not include any random numbers and should only be based
on inputs that are guaranteed to be the same on all instances.

Args:
debuggee: complete debuggee message without the uniquifier

Returns:
Hex string of SHA1 hash of project information, debuggee labels and
debuglet version.


def CreateDynamicDisplayAdSettings(client, opener):
    media_service = client.GetService('MediaService', 'v201809')
    logo = {'xsi_type': 'Image', 'mediaId': _CreateImage(media_service, opener, 'https:
    dynamic_settings = {'landscapeLogoImage': logo, 'pricePrefix': 'as low as', 'promoText': 'Free shipping!'}
    return dynamic_settings

Creates dynamic display ad settings.

Args:
client: an AdWordsClient instance.
opener: an OpenerDirector instance.

Returns:
A dict containing the dynamic display ad settings.


def update_config_pwd(msg, cfg):
    msg_type = msg.__class__.__name__.lower()
    key_fmt = ((msg.profile + '_') + msg_type)
    if isinstance(msg._auth, (MutableSequence, tuple)):
        cfg.pwd[key_fmt] = ' :: '.join(msg._auth)
    else:
        cfg.pwd[key_fmt] = msg._auth

Updates the profile's auth entry with values set by the user.
This will overwrite existing values.

Args:
:msg: (Message class) an instance of a message class.
:cfg: (jsonconfig.Config) config instance.


def wrap_inference_results(inference_result_proto):

  inference_proto = inference_pb2.InferenceResult()
  if isinstance(inference_result_proto,
                classification_pb2.ClassificationResponse):
    inference_proto.classification_result.CopyFrom(
        inference_result_proto.result)
  elif isinstance(inference_result_proto, regression_pb2.RegressionResponse):
    inference_proto.regression_result.CopyFrom(inference_result_proto.result)
  return inference_proto

Returns packaged inference results from the provided proto.

Args:
inference_result_proto: The classification or regression response proto.

Returns:
An InferenceResult proto with the result from the response.


def _analemma_position(self, hour):
    low = self.calculate_sun(12, 21, hour).is_during_day
    high = self.calculate_sun(6, 21, hour).is_during_day
    if (low and high):
        return 1
    elif (low or high):
        return 0
    else:
        return (- 1)

Check what the analemma position is for an hour.

This is useful for calculating hours of analemma curves.

Returns:
-1 if always night,
0 if both day and night,
1 if always day.


def collect_hunt_results(self, hunt):

    if not os.path.isdir(self.output_path):
      os.makedirs(self.output_path)

    output_file_path = os.path.join(
        self.output_path, '.'.join((self.hunt_id, 'zip')))

    if os.path.exists(output_file_path):
      print('{0:s} already exists: Skipping'.format(output_file_path))
      return None

    self._check_approval_wrapper(
        hunt, self._get_and_write_archive, hunt, output_file_path)

    results = self._extract_hunt_results(output_file_path)
    print('Wrote results of {0:s} to {1:s}'.format(
        hunt.hunt_id, output_file_path))
    return results

Download current set of files in results.

Args:
hunt: The GRR hunt object to download files from.

Returns:
list: tuples containing:
str: human-readable description of the source of the collection. For
example, the name of the source host.
str: path to the collected data.
Raises:
ValueError: if approval is needed and approvers were not specified.


def hugepage_support(user, group='hugetlb', nr_hugepages=256,
                     max_map_count=65536, mnt_point='/run/hugepages/kvm',
                     pagesize='2MB', mount=True, set_shmmax=False):

    group_info = add_group(group)
    gid = group_info.gr_gid
    add_user_to_group(user, group)
    if max_map_count < 2 * nr_hugepages:
        max_map_count = 2 * nr_hugepages
    sysctl_settings = {
        'vm.nr_hugepages': nr_hugepages,
        'vm.max_map_count': max_map_count,
        'vm.hugetlb_shm_group': gid,
    }
    if set_shmmax:
        shmmax_current = int(check_output(['sysctl', '-n', 'kernel.shmmax']))
        shmmax_minsize = bytes_from_string(pagesize) * nr_hugepages
        if shmmax_minsize > shmmax_current:
            sysctl_settings['kernel.shmmax'] = shmmax_minsize
    sysctl.create(yaml.dump(sysctl_settings), '/etc/sysctl.d/10-hugepage.conf')
    mkdir(mnt_point, owner='root', group='root', perms=0o755, force=False)
    lfstab = fstab.Fstab()
    fstab_entry = lfstab.get_entry_by_attr('mountpoint', mnt_point)
    if fstab_entry:
        lfstab.remove_entry(fstab_entry)
    entry = lfstab.Entry('nodev', mnt_point, 'hugetlbfs',
                         'mode=1770,gid={},pagesize={}'.format(gid, pagesize), 0, 0)
    lfstab.add_entry(entry)
    if mount:
        fstab_mount(mnt_point)

Enable hugepages on system.

Args:
user (str)  -- Username to allow access to hugepages to
group (str) -- Group name to own hugepages
nr_hugepages (int) -- Number of pages to reserve
max_map_count (int) -- Number of Virtual Memory Areas a process can own
mnt_point (str) -- Directory to mount hugepages on
pagesize (str) -- Size of hugepages
mount (bool) -- Whether to Mount hugepages


def get_HDX_code_from_location_partial(location, locations=None, configuration=None):

        hdx_code = Locations.get_HDX_code_from_location(location, locations, configuration)

        if hdx_code is not None:
            return hdx_code, True

        if locations is None:
            locations = Locations.validlocations(configuration)
        locationupper = location.upper()
        for locdict in locations:
            locationname = locdict['title'].upper()
            if locationupper in locationname or locationname in locationupper:
                return locdict['name'].upper(), False

        return None, False

Get HDX code for location

Args:
location (str): Location for which to get HDX code
locations (Optional[List[Dict]]): Valid locations list. Defaults to list downloaded from HDX.
configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration.

Returns:
Tuple[Optional[str], bool]: HDX code and if the match is exact or (None, False) for no match


def validate(self, message):
    if hasattr(message, '__json__'):
        message = message.__json__()
        if isinstance(message['body'], six.text_type):
            message['body'] = json.loads(message['body'])
        elif isinstance(message['body'], six.binary_type):
            warnings.warn('Message body is not unicode', DeprecationWarning)
            message['body'] = json.loads(message['body'].decode('utf-8'))
    if ('topic' not in message['body']):
        message['body'] = {'topic': message.get('topic'), 'msg': message['body']}
    if (not self.validate_signatures):
        return
    if (not (message['topic'] == message['body']['topic'])):
        raise RuntimeWarning('Topic envelope mismatch.')
    if (not fedmsg.crypto.validate(message['body'], **self.hub.config)):
        raise RuntimeWarning('Failed to authn message.')

Validate the message before the consumer processes it.

This needs to raise an exception, caught by moksha.

Args:
message (dict): The message as a dictionary. This must, at a minimum,
contain the 'topic' key with a unicode string value and 'body' key
with a dictionary value. However, the message might also be an object
with a ``__json__`` method that returns a dict with a 'body' key that
can be a unicode string that is JSON-encoded.

Raises:
RuntimeWarning: If the message is not valid.
UnicodeDecodeError: If the message body is not unicode or UTF-8 and also
happens to contain invalid UTF-8 binary.


def AddWarning(self, warning):

    self._RaiseIfNotWritable()

    self._AddAttributeContainer(
        self._CONTAINER_TYPE_EXTRACTION_WARNING, warning)

Adds an warning.

Args:
warning (ExtractionWarning): warning.

Raises:
IOError: when the storage file is closed or read-only.
OSError: when the storage file is closed or read-only.


def windows(self):
    from foxpuppet.windows import BrowserWindow
    return [BrowserWindow(self.selenium, handle) for handle in self.selenium.window_handles]

Return a list of all open windows.

Returns:
list: List of FoxPuppet BrowserWindow objects.


def objects_delete(self, bucket, key):

    url = Api._ENDPOINT + (Api._OBJECT_PATH % (bucket, Api._escape_key(key)))
    datalab.utils.Http.request(url, method='DELETE', credentials=self._credentials,
                               raw_response=True)

Deletes the specified object.

Args:
bucket: the name of the bucket.
key: the key of the object within the bucket.
Raises:
Exception if there is an error performing the operation.


def notify(self, notices):

        tmpl_html = get_template('required_tags_notice.html')
        tmpl_text = get_template('required_tags_notice.txt')
        for recipient, data in list(notices.items()):
            body_html = tmpl_html.render(data=data)
            body_text = tmpl_text.render(data=data)

            send_notification(
                subsystem=self.ns,
                recipients=[recipient],
                subject=self.email_subject,
                body_html=body_html,
                body_text=body_text
            )

Send notifications to the recipients provided

Args:
notices (:obj:`dict` of `str`: `list`): A dictionary mapping notification messages to the recipient.

Returns:
`None`


def _PromptUserForEncryptedVolumeCredential(self, scan_context, locked_scan_node, output_writer):
    credentials = credentials_manager.CredentialsManager.GetCredentials(locked_scan_node.path_spec)
    if (locked_scan_node.type_indicator == definitions.TYPE_INDICATOR_APFS_CONTAINER):
        line = 'Found an APFS encrypted volume.'
    elif (locked_scan_node.type_indicator == definitions.TYPE_INDICATOR_BDE):
        line = 'Found a BitLocker encrypted volume.'
    elif (locked_scan_node.type_indicator == definitions.TYPE_INDICATOR_FVDE):
        line = 'Found a CoreStorage (FVDE) encrypted volume.'
    else:
        line = 'Found an encrypted volume.'
    output_writer.WriteLine(line)
    credentials_list = list(credentials.CREDENTIALS)
    credentials_list.append('skip')
    output_writer.WriteLine('Supported credentials:')
    output_writer.WriteLine('')
    for (index, name) in enumerate(credentials_list):
        output_writer.WriteLine('  {0:d}. {1:s}'.format((index + 1), name))
    output_writer.WriteLine('')
    result = False
    while (not result):
        output_writer.WriteString('Select a credential to unlock the volume: ')
        input_line = sys.stdin.readline()
        input_line = input_line.strip()
        if (input_line in credentials_list):
            credential_identifier = input_line
        else:
            try:
                credential_identifier = int(input_line, 10)
                credential_identifier = credentials_list[(credential_identifier - 1)]
            except (IndexError, ValueError):
                output_writer.WriteLine('Unsupported credential: {0:s}'.format(input_line))
                continue
        if (credential_identifier == 'skip'):
            break
        getpass_string = 'Enter credential data: '
        if (sys.platform.startswith('win') and (sys.version_info[0] < 3)):
            getpass_string = self._EncodeString(getpass_string)
        credential_data = getpass.getpass(getpass_string)
        output_writer.WriteLine('')
        result = self._source_scanner.Unlock(scan_context, locked_scan_node.path_spec, credential_identifier, credential_data)
        if (not result):
            output_writer.WriteLine('Unable to unlock volume.')
            output_writer.WriteLine('')

Prompts the user to provide a credential for an encrypted volume.

Args:
scan_context (SourceScannerContext): the source scanner context.
locked_scan_node (SourceScanNode): the locked scan node.
output_writer (StdoutWriter): the output writer.


def write_bottom_half(f, row_metadata_df, data_df, data_null, data_float_format, metadata_null):

    size_of_left_bottom_half_df = (row_metadata_df.shape[0],
                              1 + row_metadata_df.shape[1])
    left_bottom_half_df = pd.DataFrame(np.full(size_of_left_bottom_half_df, metadata_null, dtype=object))

    bottom_half_df = pd.concat([left_bottom_half_df, data_df.reset_index(drop=True)], axis=1)
    bottom_half_df.columns = range(bottom_half_df.shape[1])

    bottom_half_df.iloc[:, 0] = row_metadata_df.index.values

    row_metadata_col_indices = range(1, 1 + row_metadata_df.shape[1])
    bottom_half_df.iloc[:, row_metadata_col_indices] = (
        row_metadata_df.astype(str).replace("nan", value=metadata_null).values)

    bottom_half_df.to_csv(f, header=False, index=False, sep="\t",
                          na_rep=data_null,
                          float_format=data_float_format)

Write the bottom half of the gct file: row metadata and data.

Args:
f (file handle): handle for output file
row_metadata_df (pandas df)
data_df (pandas df)
data_null (string): how to represent missing values in the data
metadata_null (string): how to represent missing values in the metadata
data_float_format (string): how many decimal points to keep in representing data

Returns:
None


def read_value(self):
    return array_ops.identity(self._variable, name='read')

Returns the value of this variable, read in the current context.

Can be different from value() if it's on another device, with control
dependencies, etc.

Returns:
A `Tensor` containing the value of the variable.


def getHostCaPath(self, name):
    cert = self.getHostCert(name)
    if (cert is None):
        return None
    return self._getCaPath(cert)

Gets the path to the CA certificate that issued a given host keypair.

Args:
name (str): The name of the host keypair.

Examples:
Get the path to the CA cert which issue the cert for "myhost":

mypath = cdir.getHostCaPath('myhost')

Returns:
str: The path if exists.


def decode(message, pblite, ignore_first_item=False):
    if (not isinstance(pblite, list)):
        logger.warning('Ignoring invalid message: expected list, got %r', type(pblite))
        return
    if ignore_first_item:
        pblite = pblite[1:]
    if (pblite and isinstance(pblite[(- 1)], dict)):
        extra_fields = {int(field_number): value for (field_number, value) in pblite[(- 1)].items()}
        pblite = pblite[:(- 1)]
    else:
        extra_fields = {}
    fields_values = itertools.chain(enumerate(pblite, start=1), extra_fields.items())
    for (field_number, value) in fields_values:
        if (value is None):
            continue
        try:
            field = message.DESCRIPTOR.fields_by_number[field_number]
        except KeyError:
            if (value not in [[], '', 0]):
                logger.debug('Message %r contains unknown field %s with value %r', message.__class__.__name__, field_number, value)
            continue
        if (field.label == FieldDescriptor.LABEL_REPEATED):
            _decode_repeated_field(message, field, value)
        else:
            _decode_field(message, field, value)

Decode pblite to Protocol Buffer message.

This method is permissive of decoding errors and will log them as warnings
and continue decoding where possible.

The first element of the outer pblite list must often be ignored using the
ignore_first_item parameter because it contains an abbreviation of the name
of the protobuf message (eg.  cscmrp for ClientSendChatMessageResponseP)
that's not part of the protobuf.

Args:
message: protocol buffer message instance to decode into.
pblite: list representing a pblite-serialized message.
ignore_first_item: If True, ignore the item at index 0 in the pblite
list, making the item at index 1 correspond to field 1 in the
message.


def errorhandler_callback(cls, exc):
    if exc.flash_message:
        flash(exc.flash_message, exc.flash_level)
    if (exc.redirect is not MISSING):
        return redirect(url_for(exc.redirect, **exc.redirect_args))
    error_result = exc.error_page()
    if (error_result is not None):
        return (error_result, (exc.status_code or 500))

This function should be called in the global error handlers. This
will allow for consolidating of cleanup tasks if the exception
bubbles all the way to the top of the stack.

For example, this method will automatically rollback the database
session if the exception bubbles to the top.

This is the method that :meth:`register_errorhandler` adds as an
errorhandler. See the documentation there for more info.

Args:
exc (FleakerBaseException):
The exception that was thrown that we are to handle.


def format_snippet(sensor_graph):

    output = []

    output.append("disable")
    output.append("clear")
    output.append("reset")

    for node in sensor_graph.dump_nodes():
        output.append('add_node "{}"'.format(node))

    for streamer in sensor_graph.streamers:
        line = "add_streamer '{}' '{}' {} {} {}".format(streamer.selector, streamer.dest, streamer.automatic, streamer.format, streamer.report_type)

        if streamer.with_other is not None:
            line += ' --withother {}'.format(streamer.with_other)

        output.append(line)

    for stream, value in sorted(sensor_graph.constant_database.items(), key=lambda x: x[0].encode()):
        output.append("set_constant '{}' {}".format(stream, value))

    output.append("persist")

    output.append("back")

    app_tag = sensor_graph.metadata_database.get('app_tag')
    app_version = sensor_graph.metadata_database.get('app_version')

    if app_tag is not None:
        if app_version is None:
            app_version = "0.0"

        output.append("test_interface")
        output.append("set_version app %d --version '%s'" % (app_tag, app_version))
        output.append("back")

    output.append("config_database")
    output.append("clear_variables")

    for slot, conf_vars in sensor_graph.config_database.items():
        for conf_var, conf_def in conf_vars.items():
            conf_type, conf_val = conf_def

            if conf_type == 'binary':
                conf_val = 'hex:' + hexlify(conf_val)
            elif isinstance(conf_val, str):
                conf_val = '"%s"' % conf_val

            output.append("set_variable '{}' {} {} {}".format(slot, conf_var, conf_type, conf_val))

    output.append("back")
    output.append("reset")

    return "\n".join(output) + '\n'

Format this sensor graph as iotile command snippets.

This includes commands to reset and clear previously stored
sensor graphs.

Args:
sensor_graph (SensorGraph): the sensor graph that we want to format


def run_metadata_graphs(name, data, step=None):
    summary_metadata = summary_pb2.SummaryMetadata()
    summary_metadata.plugin_data.plugin_name = 'graph_run_metadata_graph'
    summary_metadata.plugin_data.content = b'1'
    data = config_pb2.RunMetadata(function_graphs=data.function_graphs, partition_graphs=data.partition_graphs)
    with summary_scope(name, 'graph_run_metadata_graph_summary', [data, step]) as (tag, _):
        with ops.device('cpu:0'):
            tensor = constant_op.constant(data.SerializeToString(), dtype=dtypes.string)
        return write(tag=tag, tensor=tensor, step=step, metadata=summary_metadata)

Writes graphs from a RunMetadata summary.

Args:
name: A name for this summary. The summary tag used for TensorBoard will be
this name prefixed by any active name scopes.
data: A RunMetadata proto to write.
step: Explicit `int64`-castable monotonic step value for this summary. If
omitted, this defaults to `tf.summary.experimental.get_step()`, which must
not be None.

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

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


def to(self, device: Optional[torch.device], dtype: Optional[torch.dtype]) -> Rotation:
    if self._rot_mats is not None:
        return Rotation(rot_mats=self._rot_mats.to(device=device, dtype=dtype), quats=None)
    elif self._quats is not None:
        return Rotation(rot_mats=None, quats=self._quats.to(device=device, dtype=dtype), normalize_quats=False)
    else:
        raise ValueError('Both rotations are None')

Analogous to the to() method of torch Tensors

Args:
device:
A torch device
dtype:
A torch dtype
Returns:
A copy of the Rotation using the new device and dtype


def create_band_mask_from_inputs(from_blocked_mask, to_blocked_mask):
    exp_blocked_to_pad = torch.cat([to_blocked_mask[:, 1:-3], to_blocked_mask[:, 2:-2], to_blocked_mask[:, 3:-1]], dim=2)
    band_mask = torch.einsum('blq,blk->blqk', from_blocked_mask[:, 2:-2], exp_blocked_to_pad)
    band_mask.unsqueeze_(1)
    return band_mask

Create 3D attention mask from a 2D tensor mask.

Args:
from_blocked_mask: 2D Tensor of shape [batch_size,
from_seq_length//from_block_size, from_block_size].
to_blocked_mask: int32 Tensor of shape [batch_size,
to_seq_length//to_block_size, to_block_size].

Returns:
float Tensor of shape [batch_size, 1, from_seq_length//from_block_size-4, from_block_size,
3*to_block_size].


def build_from_config(self, config):
    if config:
        if 'input_shape' in config:
            self.build(config['input_shape'])
        elif 'shapes_dict' in config:
            self.build(**config['shapes_dict'])

Builds the layer's states with the supplied config dict.

By default, this method calls the `build(config["input_shape"])` method,
which creates weights based on the layer's input shape in the supplied
config. If your config contains other information needed to load the
layer's state, you should override this method.

Args:
config: Dict containing the input shape associated with this layer.


def __init__(self, length=None, experimenter=None):

        super().__init__(action_type=ActionType.OFPAT_EXPERIMENTER)
        self.length = length
        self.experimenter = experimenter

Create ActionExperimenterHeader with the optional parameters below.

Args:
experimenter (int): The experimenter field is the Experimenter ID,
which takes the same form as in struct ofp_experimenter.


def _get_new_alive_state(self, new_seq, new_log_probs, new_cache):
    new_finished_flags = tf.equal(new_seq[(:, :, (- 1))], self.eos_id)
    new_log_probs += (tf.to_float(new_finished_flags) * (- INF))
    (top_alive_seq, top_alive_log_probs, top_alive_cache) = _gather_topk_beams([new_seq, new_log_probs, new_cache], new_log_probs, self.batch_size, self.beam_size)
    return {_StateKeys.ALIVE_SEQ: top_alive_seq, _StateKeys.ALIVE_LOG_PROBS: top_alive_log_probs, _StateKeys.ALIVE_CACHE: top_alive_cache}

Gather the top k sequences that are still alive.

Args:
new_seq: New sequences generated by growing the current alive sequences
int32 tensor with shape [batch_size, 2 * beam_size, cur_index + 1]
new_log_probs: Log probabilities of new sequences
float32 tensor with shape [batch_size, beam_size]
new_cache: Dict of cached values for each sequence.

Returns:
Dictionary with alive keys from _StateKeys:
{Top beam_size sequences that are still alive (don't end with eos_id)
Log probabilities of top alive sequences
Dict cache storing decoder states for top alive sequences}


def _process_for_docstring(self, node, node_type):
    if (node.doc is not None):
        if (node_type == 'module'):
            if (not node.body):
                for key in list(self._tokenized_triple_quotes.keys()):
                    quote_record = self._tokenized_triple_quotes.get(key)
                    if quote_record:
                        self._check_docstring_quotes(quote_record)
                        del self._tokenized_triple_quotes[key]
            else:
                for i in range(0, node.body[0].lineno):
                    quote_record = self._tokenized_triple_quotes.get(i)
                    if quote_record:
                        self._check_docstring_quotes(quote_record)
                        del self._tokenized_triple_quotes[i]
                        break
        elif (not node.body):
            lineno = self._find_docstring_line_for_no_body(node.fromlineno)
            quote_record = self._tokenized_triple_quotes.get(lineno)
            if quote_record:
                self._check_docstring_quotes(quote_record)
                del self._tokenized_triple_quotes[lineno]
        else:
            doc_row = self._find_docstring_line(node.fromlineno, node.tolineno)
            quote_record = self._tokenized_triple_quotes.get(doc_row)
            if quote_record:
                self._check_docstring_quotes(quote_record)
                del self._tokenized_triple_quotes[doc_row]

Check for docstring quote consistency.

Args:
node: the AST node being visited.
node_type: the type of node being operated on.


def run_exit_code(self, returncode):

        exit_status = False
        self.log.info('[run] Exit Code {}'.format(returncode))

        self.reports.increment_total()
        valid_exit_codes = self.profile.get('exit_codes', [0])
        self.reports.exit_code(returncode)

        if returncode in valid_exit_codes:
            exit_status = True
            self.reports.profile_execution(True)
            print('App Exit Code: {}{}{}'.format(c.Style.BRIGHT, c.Fore.GREEN, returncode))
        else:
            print(
                'App Exit Code: {}{}{}{} (Valid Exit Codes: {})'.format(
                    c.Style.BRIGHT,
                    c.Fore.RED,
                    returncode,
                    c.Fore.RESET,
                    self.profile.get('exit_codes', [0]),
                )
            )

            self.reports.profile_execution(False)
            self.exit_code = 1
            if self.args.halt_on_fail:
                raise RuntimeError('App exited with invalid exit code {}'.format(returncode))
        return exit_status

Handle the exit code for the current run.

Args:
returncode (int): The return exit code.

Raises:
RuntimeError: Raise on invalid exit code if halt_on_fail is True.

Returns:
bool: True if exit code is a valid exit code, else False.


def _add_property(self, name, default_value):

        name = str(name)
        self._properties[name] = default_value

Add a device property with a given default value.

Args:
name (str): The name of the property to add
default_value (int, bool): The value of the property


def non_transactional(func, args, kwds, allow_existing=True):
    from . import tasklets
    ctx = tasklets.get_context()
    if (not ctx.in_transaction()):
        return func(*args, **kwds)
    if (not allow_existing):
        raise datastore_errors.BadRequestError(('%s cannot be called within a transaction.' % func.__name__))
    save_ctx = ctx
    while ctx.in_transaction():
        ctx = ctx._parent_context
        if (ctx is None):
            raise datastore_errors.BadRequestError('Context without non-transactional ancestor')
    save_ds_conn = datastore._GetConnection()
    try:
        if hasattr(save_ctx, '_old_ds_conn'):
            datastore._SetConnection(save_ctx._old_ds_conn)
        tasklets.set_context(ctx)
        return func(*args, **kwds)
    finally:
        tasklets.set_context(save_ctx)
        datastore._SetConnection(save_ds_conn)

A decorator that ensures a function is run outside a transaction.

If there is an existing transaction (and allow_existing=True), the
existing transaction is paused while the function is executed.

Args:
allow_existing: If false, throw an exception if called from within
a transaction.  If true, temporarily re-establish the
previous non-transactional context.  Defaults to True.

This supports two forms, similar to transactional().

Returns:
A wrapper for the decorated function that ensures it runs outside a
transaction.


def __chunk(segment, abbr=False):
    names = ('north', 'east', 'south', 'west', 'north')
    if (not abbr):
        sjoin = '-'
    else:
        names = [s[0].upper() for s in names]
        sjoin = ''
    if ((segment % 2) == 0):
        return (names[segment].capitalize(), sjoin.join((names[segment].capitalize(), names[segment], names[(segment + 1)])), sjoin.join((names[segment].capitalize(), names[(segment + 1)])), sjoin.join((names[(segment + 1)].capitalize(), names[segment], names[(segment + 1)])))
    else:
        return (names[segment].capitalize(), sjoin.join((names[segment].capitalize(), names[(segment + 1)], names[segment])), sjoin.join((names[(segment + 1)].capitalize(), names[segment])), sjoin.join((names[(segment + 1)].capitalize(), names[(segment + 1)], names[segment])))

Generate a ``tuple`` of compass direction names.

Args:
segment (list): Compass segment to generate names for
abbr (bool): Names should use single letter abbreviations

Returns:
bool: Direction names for compass segment


def fts_intersection(self, segs):

        fts_vecs = [self.fts(s) for s in self.filter_segs(segs)]
        return reduce(lambda a, b: a & b, fts_vecs)

Return the features shared by `segs`

Args:
segs (list): list of Unicode IPA segments

Returns:
set: set of (value, feature) tuples shared by the valid segments in
`segs`


def get_imported_namespaces(self, must_have_imported_data_type=False, consider_annotations=False, consider_annotation_types=False):
    imported_namespaces = []
    for (imported_namespace, reason) in self._imported_namespaces.items():
        if (must_have_imported_data_type and (not reason.data_type)):
            continue
        if ((not consider_annotations) and (not (reason.data_type or reason.alias or reason.annotation_type))):
            continue
        if ((not consider_annotation_types) and (not (reason.data_type or reason.alias or reason.annotation))):
            continue
        imported_namespaces.append(imported_namespace)
    imported_namespaces.sort(key=(lambda n: n.name))
    return imported_namespaces

Returns a list of Namespace objects. A namespace is a member of this
list if it is imported by the current namespace and a data type is
referenced from it. Namespaces are in ASCII order by name.

Args:
must_have_imported_data_type (bool): If true, result does not
include namespaces that were not imported for data types.
consider_annotations (bool): If false, result does not include
namespaces that were only imported for annotations
consider_annotation_types (bool): If false, result does not
include namespaces that were only imported for annotation types.

Returns:
List[Namespace]: A list of imported namespaces.


Linear depolarizarion ratio (LDR) for the current setup.

Args:
scatterer: a Scatterer instance.
h_pol: If True (default), return LDR_h.
If False, return LDR_v.

Returns:
The LDR.


def __batch_update(self, train_events, test_events, n_epoch):
    for epoch in range(n_epoch):
        if (n_epoch != 1):
            np.random.shuffle(train_events)
        for e in train_events:
            self.rec.update(e, batch_train=True)
        MPR = self.__batch_evaluate(test_events)
        if self.debug:
            logger.debug(('epoch %2d: MPR = %f' % ((epoch + 1), MPR)))

Batch update called by the fitting method.

Args:
train_events (list of Event): Positive training events.
test_events (list of Event): Test events.
n_epoch (int): Number of epochs for the batch training.


def update_exif_for_rotated_image(exif):

    orientation_value = exif.get('0th', ).get(
        piexif.ImageIFD.Orientation, exif.get('1st', ).get(
            piexif.ImageIFD.Orientation, None))

    if orientation_value is not None:

        exif['0th'][piexif.ImageIFD.Orientation] = 1
        if exif.get('1st', {}).get(piexif.ImageIFD.Orientation) is not None:
            exif['1st'][piexif.ImageIFD.Orientation] = 1

        if orientation_value > 4:
            for exif_tag in ['0th', '1st']:
                if exif.get(exif_tag) is not None:
                    x, y = (exif.get(exif_tag).get(piexif.ImageIFD.ImageWidth),
                            exif.get(exif_tag).get(piexif.ImageIFD.ImageLength))
                    if x is not None and y is not None:
                        exif[exif_tag][piexif.ImageIFD.ImageWidth] = y
                        exif[exif_tag][piexif.ImageIFD.ImageLength] = x

                    x, y = (exif.get(exif_tag).get(piexif.ImageIFD.XResolution),
                            exif.get(exif_tag).get(piexif.ImageIFD.YResolution))
                    if x is not None and y is not None:
                        exif[exif_tag][piexif.ImageIFD.XResolution] = y
                        exif[exif_tag][piexif.ImageIFD.YResolution] = x

                    x, y = (exif.get(exif_tag).get(piexif.ImageIFD.TileWidth),
                            exif.get(exif_tag).get(piexif.ImageIFD.TileLength))
                    if x is not None and y is not None:
                        exif[exif_tag][piexif.ImageIFD.TileWidth] = y
                        exif[exif_tag][piexif.ImageIFD.TileLength] = x
            if exif.get('Exif') is not None:
                x, y = (exif.get('Exif').get(piexif.ExifIFD.PixelXDimension),
                        exif.get('Exif').get(piexif.ExifIFD.PixelYDimension))
                if x is not None and y is not None:
                    exif['Exif'][piexif.ExifIFD.PixelXDimension] = y
                    exif['Exif'][piexif.ExifIFD.PixelYDimension] = x
        if exif.get('thumbnail') is not None:
            try:
                thumbnail = pil_open(io.BytesIO(exif.get('thumbnail')))
                thumbnail = autorotate(thumbnail, orientation=orientation_value)
                with io.BytesIO() as bio:
                    thumbnail.save(bio, format='jpeg')
                    bio.seek(0)
                    exif['thumbnail'] = bio.read()
            except Exception as e:
                warnings.warn("deprecated", DeprecationWarning)

    return exif

Modifies the Exif tag if rotation has been performed.

0th, 1st
--------
ImageWidth = 256
ImageLength = 257
XResolution = 282
YResolution = 283
TileWidth = 322
TileLength = 323

Exif
----
PixelXDimension = 40962
PixelYDimension = 40963

Args:
exif (dict): The parsed Exif tag

Returns:
The modified Exif dict.


class Siglip2Encoder(nn.Module):

    def __init__(self, config: Siglip2Config):
        super().__init__()
        self.config = config
        self.layers = nn.ModuleList([Siglip2EncoderLayer(config) for _ in range(config.num_hidden_layers)])
        self.gradient_checkpointing = False

    @can_return_tuple
    def forward(self, inputs_embeds, attention_mask: Optional[torch.Tensor]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None) -> BaseModelOutput:

        output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
        output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
        encoder_states = () if output_hidden_states else None
        all_attentions = () if output_attentions else None
        hidden_states = inputs_embeds
        for encoder_layer in self.layers:
            if output_hidden_states:
                encoder_states = encoder_states + (hidden_states,)
            layer_outputs = encoder_layer(hidden_states, attention_mask, output_attentions=output_attentions)
            hidden_states = layer_outputs[0]
            if output_attentions:
                all_attentions = all_attentions + (layer_outputs[1],)
        if output_hidden_states:
            encoder_states = encoder_states + (hidden_states,)
        return BaseModelOutput(last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions)

Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
[`Siglip2EncoderLayer`].

Args:
config: Siglip2Config


def swd_sync(self, pad=False):

        if pad:
            self._dll.JLINK_SWD_SyncBytes()
        else:
            self._dll.JLINK_SWD_SyncBits()
        return None

Causes a flush to write all data remaining in output buffers to SWD
device.

Args:
self (JLink): the ``JLink`` instance
pad (bool): ``True`` if should pad the data to full byte size

Returns:
``None``


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 execute(desktop_file, files=None, return_cmd=False, background=False):

	desktop_file_exec = parse(desktop_file)['Exec']

	for i in desktop_file_exec.split():
		if i.startswith('%'):
			desktop_file_exec = desktop_file_exec.replace(i, '')

	desktop_file_exec = desktop_file_exec.replace(r'%F', '')
	desktop_file_exec = desktop_file_exec.replace(r'%f', '')

	if files:
		for i in files:
			desktop_file_exec += ' ' + i

	if parse(desktop_file)['Terminal']:

		desktop_file_exec = eval(
				('__import__("libdesktop").applications.terminal(exec_="%s",'
				 ' keep_open_after_cmd_exec=True, return_cmd=True)') %
			desktop_file_exec)

	if return_cmd:
		return desktop_file_exec

	desktop_file_proc = sp.Popen([desktop_file_exec], shell=True)

	if not background:
		desktop_file_proc.wait()

Execute a .desktop file.
Executes a given .desktop file path properly.
Args:
desktop_file (str) : The path to the .desktop file.
files		(list): Any files to be launched by the .desktop. Defaults to empty list.
return_cmd   (bool): Return the command (as ``str``) instead of executing. Defaults to ``False``.
background   (bool): Run command in background. Defaults to ``False``.
Returns:
str: Only if ``return_cmd``. Returns command instead of running it. Else returns nothing.


def __init__(self, n_output_node, input_shape):

        super(MlpGenerator, self).__init__(n_output_node, input_shape)
        if len(self.input_shape) > 1:
            raise ValueError("The input dimension is too high.")

Initialize the instance.
Args:
n_output_node: An integer. Number of output nodes in the network.
input_shape: A tuple. Input shape of the network. If it is 1D, ensure the value is appended by a comma
in the tuple.


def get_error_intro(tf_error):
    if hasattr(tf_error, 'op') and hasattr(tf_error.op, 'name'):
        op_name = tf_error.op.name
    else:
        op_name = None
    intro_lines = ['--------------------------------------', RL('!!! An error occurred during the run !!!', 'blink'), '']
    out = debugger_cli_common.rich_text_lines_from_rich_line_list(intro_lines)
    if op_name is not None:
        out.extend(debugger_cli_common.RichTextLines(['You may use the following commands to debug:']))
        out.extend(_recommend_command('ni -a -d -t %s' % op_name, 'Inspect information about the failing op.', create_link=True))
        out.extend(_recommend_command('li -r %s' % op_name, 'List inputs to the failing op, recursively.', create_link=True))
        out.extend(_recommend_command('lt', 'List all tensors dumped during the failing run() call.', create_link=True))
    else:
        out.extend(debugger_cli_common.RichTextLines(['WARNING: Cannot determine the name of the op that caused the error.']))
    more_lines = ['', 'Op name:    %s' % op_name, 'Error type: ' + str(type(tf_error)), '', 'Details:', str(tf_error), '', '--------------------------------------', '']
    out.extend(debugger_cli_common.RichTextLines(more_lines))
    return out

Generate formatted intro for TensorFlow run-time error.

Args:
tf_error: (errors.OpError) TensorFlow run-time error object.

Returns:
(RichTextLines) Formatted intro message about the run-time OpError, with
sample commands for debugging.


def im_open(self, *, user: str, **kwargs) -> SlackResponse:

        kwargs.update({"user": user})
        return self.api_call("im.open", json=kwargs)

Opens a direct message channel.

Args:
user (str): The user id to open a DM with. e.g. 'W1234567890'


def __rtruediv__(self, other):
    raise TypeError("unsupported operand type(s) for /: '{}' and 'Dimension', please use

Use `__floordiv__` via `x // y` instead.

This function exists only to have a better error message. Instead of:
`TypeError: unsupported operand type(s) for /: 'int' and 'Dimension'`,
this function will explicitly call for usage of `//` instead.

Args:
other: Another `Dimension`.

Raises:
TypeError.


def user_has_access(self, user):

        if ROLE_ADMIN in user.roles:
            return True

        if self.enabled:
            if not self.required_roles:
                return True

            for role in self.required_roles:
                if role in user.roles:
                    return True

        return False

Check if a user has access to view information for the account

Args:
user (:obj:`User`): User object to check

Returns:
True if user has access to the account, else false


def get_unique_tags(field_to_obs):

  return {field: sorted(set([x.get('tag', '') for x in observations]))
          for field, observations in field_to_obs.items()
          if field in TAG_FIELDS}

Returns a dictionary of tags that a user could query over.

Args:
field_to_obs: Dict that maps string field to `Observation` list.

Returns:
A dict that maps keys in `TAG_FIELDS` to a list of string tags present in
the event files. If the dict does not have any observations of the type,
maps to an empty list so that we can render this to console.


def validate_bindings(bindings):
    if (not isinstance(bindings, (list, tuple))):
        raise exceptions.ConfigurationException('bindings must be a list or tuple of dictionaries, but was a {}'.format(type(bindings)))
    for binding in bindings:
        missing_keys = []
        for key in ('queue', 'exchange', 'routing_keys'):
            if (key not in binding):
                missing_keys.append(key)
        if missing_keys:
            raise exceptions.ConfigurationException('a binding is missing the following keys from its settings value: {}'.format(missing_keys))
        if (not isinstance(binding['routing_keys'], (list, tuple))):
            raise exceptions.ConfigurationException('routing_keys must be a list or tuple, but was a {}'.format(type(binding['routing_keys'])))

Validate the bindings configuration.

Raises:
exceptions.ConfigurationException: If the configuration provided is of an
invalid format.


def load_data_and_labels(filename, encoding='utf-8'):
    (sents, labels) = ([], [])
    (words, tags) = ([], [])
    with open(filename, encoding=encoding) as f:
        for line in f:
            line = line.rstrip()
            if line:
                (word, tag) = line.split('\t')
                words.append(word)
                tags.append(tag)
            else:
                sents.append(words)
                labels.append(tags)
                (words, tags) = ([], [])
    return (sents, labels)

Loads data and label from a file.

Args:
filename (str): path to the file.
encoding (str): file encoding format.

The file format is tab-separated values.
A blank line is required at the end of a sentence.

For example:
```
EU	B-ORG
rejects	O
German	B-MISC
call	O
to	O
boycott	O
British	B-MISC
lamb	O
.	O

Peter	B-PER
Blackburn	I-PER
...
```

Returns:
tuple(numpy array, numpy array): data and labels.

Example:
>>> filename = 'conll2003/en/ner/train.txt'
>>> data, labels = load_data_and_labels(filename)


def __init__(self, encoding, buffer_size=2048):

    super(EncodedTextReader, self).__init__()
    self._buffer = ''
    self._buffer_size = buffer_size
    self._current_offset = 0
    self._encoding = encoding
    self.lines = ''

Initializes the encoded text reader object.

Args:
encoding (str): encoding.
buffer_size (Optional[int]): buffer size.


def beta_to_uni(text, strict=False):

    param_key = (strict,)
    try:
       t = _BETA_CONVERSION_TRIES[param_key]
    except KeyError:
        t = _create_conversion_trie(*param_key)
        _BETA_CONVERSION_TRIES[param_key] = t

    transform = []
    idx = 0
    possible_word_boundary = False

    while idx < len(text):
        if possible_word_boundary and _penultimate_sigma_word_final(transform):
            transform[-2] = _FINAL_LC_SIGMA

        step = t.longest_prefix(text[idx:idx + _MAX_BETA_TOKEN_LEN])

        if step:
            possible_word_boundary = text[idx] in _BETA_PUNCTUATION

            key, value = step
            transform.append(value)
            idx += len(key)
        else:
            possible_word_boundary = True

            transform.append(text[idx])
            idx += 1

    if possible_word_boundary and _penultimate_sigma_word_final(transform):
        transform[-2] = _FINAL_LC_SIGMA
    elif len(transform) > 0 and transform[-1] == _MEDIAL_LC_SIGMA:
        transform[-1] = _FINAL_LC_SIGMA

    converted = ''.join(transform)
    return converted

Converts the given text from betacode to unicode.

Args:
text: The beta code text to convert. All of this text must be betacode.
strict: Flag to allow for flexible diacritic order on input.

Returns:
The converted text.


def read_user_data(self, user_data_path):

        raw_user_data = read_value_from_path(user_data_path)

        variables = self.get_variables()

        return parse_user_data(variables, raw_user_data, self.name)

Reads and parses a user_data file.

Args:
user_data_path (str):
path to the userdata file

Returns:
str: the parsed user data file


def update_user_groups(self, user, claims):

        if settings.GROUPS_CLAIM is not None:

            django_groups = [group.name for group in user.groups.all()]

            if settings.GROUPS_CLAIM in claims:
                claim_groups = claims[settings.GROUPS_CLAIM]
                if not isinstance(claim_groups, list):
                    claim_groups = [claim_groups, ]
            else:
                logger.debug(
                    "The configured groups claim '{}' was not found in the access token".format(settings.GROUPS_CLAIM))
                claim_groups = []

            groups_to_remove = set(django_groups) - set(claim_groups)
            groups_to_add = set(claim_groups) - set(django_groups)

            for group_name in groups_to_remove:
                group = Group.objects.get(name=group_name)
                user.groups.remove(group)
                logger.debug("User removed from group '{}'".format(group_name))

            for group_name in groups_to_add:
                try:
                    if settings.MIRROR_GROUPS:
                        group, _ = Group.objects.get_or_create(name=group_name)
                        logger.debug("Created group '{}'".format(group_name))
                    else:
                        group = Group.objects.get(name=group_name)
                    user.groups.add(group)
                    logger.debug("User added to group '{}'".format(group_name))
                except ObjectDoesNotExist:

                    pass

Updates user group memberships based on the GROUPS_CLAIM setting.

Args:
user (django.contrib.auth.models.User): User model instance
claims (dict): Claims from the access token


def from_dict(cls, d):
    for cat in ['HEADER', 'VERS']:
        if (cat not in d):
            d[cat] = None
    alat = (d['ALAT'] * bohr_to_angstrom)
    plat = (d['PLAT'] * alat)
    species = []
    positions = []
    for site in d['SITE']:
        species.append(re.split('[0-9*]', site['ATOM'])[0])
        positions.append((site['POS'] * alat))
    if (('CLASS' in d) and ('SPCGRP' in d) and (len(d['SITE']) == len(d['CLASS']))):
        try:
            structure = Structure.from_spacegroup(d['SPCGRP'], plat, species, positions, coords_are_cartesian=True)
        except ValueError:
            structure = Structure(plat, species, positions, coords_are_cartesian=True, to_unit_cell=True)
    else:
        structure = Structure(plat, species, positions, coords_are_cartesian=True, to_unit_cell=True)
    return cls(structure, header=d['HEADER'], version=d['VERS'])

Creates a CTRL file object from a dictionary. The dictionary
must contain the items "ALAT", PLAT" and "SITE".

Valid dictionary items are:
ALAT: the a-lattice parameter
PLAT: (3x3) array for the lattice vectors
SITE: list of dictionaries: {'ATOM': class label,
'POS': (3x1) array of fractional
coordinates}
CLASS (optional): list of unique atom labels as str
SPCGRP (optional): space group symbol (str) or number (int)
HEADER (optional): HEADER text as a str
VERS (optional): LMTO version as a str

Args:
d: The CTRL file as a dictionary.

Returns:
An LMTOCtrl object.


def execute_before(self, sensor_graph, scope_stack):

        parent = scope_stack[-1]
        new_scope = TriggerScope(sensor_graph, scope_stack, parent.clock(self.interval, basis=self.basis))
        scope_stack.append(new_scope)

Execute statement before children are executed.

Args:
sensor_graph (SensorGraph): The sensor graph that we are building or
modifying
scope_stack (list(Scope)): A stack of nested scopes that may influence
how this statement allocates clocks or other stream resources.


def tagged(pode, tag):
    if tag.startswith('
        tag = tag[1:]
    return (pode[1]['tags'].get(tag) is not None)

Check if a packed node has a given tag.

Args:
pode (tuple): A packed node.
tag (str): The tag to check.

Examples:
Check if a node is tagged with "woot" and dostuff if it is.

if s_node.tagged(node,'woot'):
dostuff()

Notes:
If the tag starts with `#`, this is removed prior to checking.

Returns:
bool: True if the tag is present. False otherwise.


def raise_not_enough_arguments(self, string):
    requested = errors.number((self.counter + 1))
    number = len(self.positional)
    verb = ('was' if (number == 1) else 'were')
    what = "Requested {} formatting argument for '{}' but only {} {} supplied!"
    what = what.format(requested, string, number, verb)
    raise errors.ArgumentError(what)

Raises an errors.ArgumentError if not enough arguments were supplied.

Takes care of formatting for detailed error messages.

Arguments:
string (str): The string of the phrase for which there weren't enough
arguments.

Raises:
errors.ArgumentError with a detailed error message.


def determine_encoding(path, default=None):

    byte_order_marks = (
        ('utf-8-sig', (codecs.BOM_UTF8, )),
        ('utf-16', (codecs.BOM_UTF16_LE, codecs.BOM_UTF16_BE)),
        ('utf-32', (codecs.BOM_UTF32_LE, codecs.BOM_UTF32_BE)),
    )

    try:
        with open(path, 'rb') as infile:
            raw = infile.read(4)
    except IOError:
        return default

    for encoding, boms in byte_order_marks:
        if any(raw.startswith(bom) for bom in boms):
            return encoding

    return default

Determines the encoding of a file based on byte order marks.

Arguments:
path (str): The path to the file.
default (str, optional): The encoding to return if the byte-order-mark
lookup does not return an answer.

Returns:
str: The encoding of the file.


def certificate_rabbitmq(self):
    if (not self.__certificate_rabbitmq):
        self.__certificate_rabbitmq = CertificateRabbitMQ(self.__connection)
    return self.__certificate_rabbitmq

Gets the Certificate RabbitMQ API client.

Returns:
CertificateRabbitMQ:


def generate_lars_path(weighted_data, weighted_labels):

        x_vector = weighted_data
        alphas, _, coefs = lars_path(x_vector,
                                     weighted_labels,
                                     method='lasso',
                                     verbose=False)
        return alphas, coefs

Generates the lars path for weighted data.

Args:
weighted_data: data that has been weighted by kernel
weighted_label: labels, weighted by kernel

Returns:
(alphas, coefs), both are arrays corresponding to the
regularization parameter and coefficients, respectively


def register_items(self, items):

        for item in items:
            item.set_parent(self)
        self.items.extend(items)

Bulk ``register_item``.

Args:
items (iterable[Tree]):
Sequence of nodes to be registered as children.


def numpy(self) -> npt.ArrayLike:
    maybe_arr = self._numpy()
    return maybe_arr.copy() if isinstance(maybe_arr, np.ndarray) else maybe_arr

Copy of the contents of this Tensor into a NumPy array or scalar.

Unlike NumPy arrays, Tensors are immutable, so this method has to copy
the contents to ensure safety. Use `memoryview` to get a readonly
view of the contents without doing a copy:

>>> t = tf.constant([42])
>>> np.asarray(memoryview(t))
array([42], dtype=int32)

Note that `memoryview` is only zero-copy for Tensors on CPU. If a Tensor
is on GPU, it will have to be transferred to CPU first in order for
`memoryview` to work.

Returns:
A NumPy array of the same shape and dtype or a NumPy scalar, if this
Tensor has rank 0.

Raises:
ValueError: If the dtype of this Tensor does not have a compatible
NumPy dtype.


def __init__(self, text: str, name: YangIdentifier = None, rev: str = None):

        super().__init__(text)
        self.name = name
        self.rev = rev

Initialize the parser instance.

Args:
name: Expected module name.
rev: Expected revision date.


def show_events(self, status=None, nids=None):

        nrows, ncols = get_terminal_size()

        for task in self.iflat_tasks(status=status, nids=nids):
            report = task.get_event_report()
            if report:
                print(make_banner(str(task), width=ncols, mark="="))
                print(report)

Print the Abinit events (ERRORS, WARNIING, COMMENTS) to stdout

Args:
status: if not None, only the tasks with this status are select
nids: optional list of node identifiers used to filter the tasks.


def __init__(self, channel):

        self.ListMonitoredResourceDescriptors = channel.unary_unary(
            "/google.monitoring.v3.MetricService/ListMonitoredResourceDescriptors",
            request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.ListMonitoredResourceDescriptorsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.ListMonitoredResourceDescriptorsResponse.FromString,
        )
        self.GetMonitoredResourceDescriptor = channel.unary_unary(
            "/google.monitoring.v3.MetricService/GetMonitoredResourceDescriptor",
            request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.GetMonitoredResourceDescriptorRequest.SerializeToString,
            response_deserializer=google_dot_api_dot_monitored__resource__pb2.MonitoredResourceDescriptor.FromString,
        )
        self.ListMetricDescriptors = channel.unary_unary(
            "/google.monitoring.v3.MetricService/ListMetricDescriptors",
            request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.ListMetricDescriptorsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.ListMetricDescriptorsResponse.FromString,
        )
        self.GetMetricDescriptor = channel.unary_unary(
            "/google.monitoring.v3.MetricService/GetMetricDescriptor",
            request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.GetMetricDescriptorRequest.SerializeToString,
            response_deserializer=google_dot_api_dot_metric__pb2.MetricDescriptor.FromString,
        )
        self.CreateMetricDescriptor = channel.unary_unary(
            "/google.monitoring.v3.MetricService/CreateMetricDescriptor",
            request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.CreateMetricDescriptorRequest.SerializeToString,
            response_deserializer=google_dot_api_dot_metric__pb2.MetricDescriptor.FromString,
        )
        self.DeleteMetricDescriptor = channel.unary_unary(
            "/google.monitoring.v3.MetricService/DeleteMetricDescriptor",
            request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.DeleteMetricDescriptorRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
        self.ListTimeSeries = channel.unary_unary(
            "/google.monitoring.v3.MetricService/ListTimeSeries",
            request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.ListTimeSeriesRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.ListTimeSeriesResponse.FromString,
        )
        self.CreateTimeSeries = channel.unary_unary(
            "/google.monitoring.v3.MetricService/CreateTimeSeries",
            request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_metric__service__pb2.CreateTimeSeriesRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def _request_reports(self, domains):

        params = [{'url': domain} for domain in domains]
        responses = self._requests.multi_get(
            self.BASE_URL, query_params=params, to_json=False)
        return responses

Sends multiples requests for the resources to a particular endpoint.

Args:
resource_param_name: a string name of the resource parameter.
resources: list of of the resources.
endpoint_name: AlexaRankingApi endpoint URL suffix.
Returns:
A list of the responses.


def traverse_nodes(self, node_set, depth=0):

        tab = "  "
        result = list()
        for n in node_set:
            repr = (
                n
                if self.nodes[n]["type"] == "variable"
                else f"{n}{inspect.signature(self.nodes[n]['lambda_fn'])}"
            )

            result.append(f"{tab * depth}{repr}")
            result.extend(
                self.traverse_nodes(self.successors(n), depth=depth + 1)
            )
        return result

BFS traversal of nodes that returns name traversal as large string.

Args:
node_set: Set of input nodes to begin traversal.
depth: Current traversal depth for child node viewing.

Returns:
type: String containing tabbed traversal view.


def _kl_pareto_pareto(a, b, name=None):

  with tf.name_scope(name or "kl_pareto_pareto"):

    final_batch_shape = distribution_util.get_broadcast_shape(
        a.concentration, b.concentration, a.scale, b.scale)
    common_type = dtype_util.common_dtype(
        [a.concentration, b.concentration, a.scale, b.scale], tf.float32)
    return tf.where(
        a.scale >= b.scale,
        b.concentration * (tf.math.log(a.scale) - tf.math.log(b.scale)) +
        tf.math.log(a.concentration) - tf.math.log(b.concentration) +
        b.concentration / a.concentration - 1.0,
        tf.broadcast_to(tf.cast(np.inf, common_type), final_batch_shape))

Calculate the batched KL divergence KL(a || b) with a and b Pareto.

Args:
a: instance of a Pareto distribution object.
b: instance of a Pareto distribution object.
name: (optional) Name to use for created operations.
default is "kl_pareto_pareto".

Returns:
Batchwise KL(a || b)


def get_forced_variation(self, experiment_key, user_id):

    if not self.is_valid:
      self.logger.error(enums.Errors.INVALID_DATAFILE.format('get_forced_variation'))
      return None

    if not validator.is_non_empty_string(experiment_key):
      self.logger.error(enums.Errors.INVALID_INPUT_ERROR.format('experiment_key'))
      return None

    if not isinstance(user_id, string_types):
      self.logger.error(enums.Errors.INVALID_INPUT_ERROR.format('user_id'))
      return None

    forced_variation = self.config.get_forced_variation(experiment_key, user_id)
    return forced_variation.key if forced_variation else None

Gets the forced variation for a given user and experiment.

Args:
experiment_key: A string key identifying the experiment.
user_id: The user ID.

Returns:
The forced variation key. None if no forced variation key.


def calculate_sun_from_date_time(self, datetime, is_solar_time=False):

        if datetime.year != 2016 and self.is_leap_year:
            datetime = DateTime(datetime.month, datetime.day, datetime.hour,
                                datetime.minute, True)

        sol_dec, eq_of_time = self._calculate_solar_geometry(datetime)

        hour = datetime.float_hour

        is_daylight_saving = self.is_daylight_saving_hour(datetime.hoy)

        hour = hour + 1 if self.is_daylight_saving_hour(datetime.hoy) else hour

        sol_time = self._calculate_solar_time(hour, eq_of_time, is_solar_time) * 60

        if sol_time / 4 < 0:
            hour_angle = sol_time / 4 + 180
        else:
            hour_angle = sol_time / 4 - 180

        zenith = math.degrees(math.acos
                              (math.sin(self._latitude) *
                               math.sin(math.radians(sol_dec)) +
                               math.cos(self._latitude) *
                               math.cos(math.radians(sol_dec)) *
                               math.cos(math.radians(hour_angle))))

        altitude = 90 - zenith

        if altitude > 85:
            atmos_refraction = 0
        else:
            if altitude > 5:
                atmos_refraction = 58.1 / math.tan(math.radians(altitude))

                - 0.07 / (math.tan(math.radians(altitude)))**3
                + 0.000086 / (math.tan(math.radians(altitude)))**5
            else:
                if altitude > -0.575:
                    atmos_refraction = 1735

                    + altitude * (-518.2 + altitude *
                                  (103.4 + altitude *
                                   (-12.79 + altitude * 0.711)))
                else:

                    atmos_refraction = -20.772 / math.tan(
                        math.radians(altitude))

        atmos_refraction /= 3600

        altitude += atmos_refraction

        if hour_angle > 0:
            azimuth = (math.degrees(
                math.acos(
                    (
                        (math.sin(self._latitude) *
                         math.cos(math.radians(zenith))) -
                        math.sin(math.radians(sol_dec))) /
                    (math.cos(self._latitude) *
                     math.sin(math.radians(zenith)))
                )
            ) + 180) % 360
        else:
            azimuth = (540 - math.degrees(math.acos((
                (math.sin(self._latitude) *
                 math.cos(math.radians(zenith))) -
                math.sin(math.radians(sol_dec))) /
                (math.cos(self._latitude) *
                 math.sin(math.radians(zenith))))
            )) % 360

        altitude = math.radians(altitude)
        azimuth = math.radians(azimuth)

        return Sun(datetime, altitude, azimuth, is_solar_time, is_daylight_saving,
                   self.north_angle)

Get Sun for an hour of the year.

This code is originally written by Trygve Wastvedt \
(Trygve.Wastvedt@gmail.com)
based on (NOAA) and modified by Chris Mackey and Mostapha Roudsari

Args:
datetime: Ladybug datetime
is_solar_time: A boolean to indicate if the input hour is solar time.
(Default: False)

Returns:
A sun object for this particular time


def from_cif_string(cif_string, transformations=None, primitive=True, occupancy_tolerance=1.0):
    parser = CifParser.from_string(cif_string, occupancy_tolerance)
    raw_string = re.sub("'", '"', cif_string)
    cif_dict = parser.as_dict()
    cif_keys = list(cif_dict.keys())
    s = parser.get_structures(primitive)[0]
    partial_cif = cif_dict[cif_keys[0]]
    if ('_database_code_ICSD' in partial_cif):
        source = (partial_cif['_database_code_ICSD'] + '-ICSD')
    else:
        source = 'uploaded cif'
    source_info = {'source': source, 'datetime': str(datetime.datetime.now()), 'original_file': raw_string, 'cif_data': cif_dict[cif_keys[0]]}
    return TransformedStructure(s, transformations, history=[source_info])

Generates TransformedStructure from a cif string.

Args:
cif_string (str): Input cif string. Should contain only one
structure. For cifs containing multiple structures, please use
CifTransmuter.
transformations ([Transformations]): Sequence of transformations
to be applied to the input structure.
primitive (bool): Option to set if the primitive cell should be
extracted. Defaults to True. However, there are certain
instances where you might want to use a non-primitive cell,
e.g., if you are trying to generate all possible orderings of
partial removals or order a disordered structure.
occupancy_tolerance (float): If total occupancy of a site is
between 1 and occupancy_tolerance, the occupancies will be
scaled down to 1.

Returns:
TransformedStructure


def get_numeric_feature_names(example):
    numeric_features = ('float_list', 'int64_list')
    features = get_example_features(example)
    return sorted([feature_name for feature_name in features if (features[feature_name].WhichOneof('kind') in numeric_features)])

Returns a list of feature names for float and int64 type features.

Args:
example: An example.

Returns:
A list of strings of the names of numeric features.


def init(self, force_deploy=False):

        machines = self.provider_conf.machines
        networks = self.provider_conf.networks
        _networks = []
        for network in networks:
            ipnet = IPNetwork(network.cidr)
            _networks.append({
                "netpool": list(ipnet)[10:-10],
                "cidr": network.cidr,
                "roles": network.roles,
                "gateway": ipnet.ip
            })

        vagrant_machines = []
        vagrant_roles = {}
        j = 0
        for machine in machines:
            for _ in range(machine.number):
                vagrant_machine = {
                    "name": "enos-%s" % j,
                    "cpu": machine.flavour_desc["core"],
                    "mem": machine.flavour_desc["mem"],
                    "ips": [n["netpool"].pop() for n in _networks],
                }
                vagrant_machines.append(vagrant_machine)

                for role in machine.roles:
                    vagrant_roles.setdefault(role, []).append(vagrant_machine)
                j = j + 1

        logger.debug(vagrant_roles)

        loader = FileSystemLoader(searchpath=TEMPLATE_DIR)
        env = Environment(loader=loader, autoescape=True)
        template = env.get_template('Vagrantfile.j2')
        vagrantfile = template.render(machines=vagrant_machines,
                                      provider_conf=self.provider_conf)
        vagrantfile_path = os.path.join(os.getcwd(), "Vagrantfile")
        with open(vagrantfile_path, 'w') as f:
            f.write(vagrantfile)

        v_env = dict(os.environ)
        v_env['VAGRANT_DEFAULT_PROVIDER'] = self.provider_conf.backend

        v = vagrant.Vagrant(root=os.getcwd(),
                            quiet_stdout=False,
                            quiet_stderr=False,
                            env=v_env)
        if force_deploy:
            v.destroy()
        v.up()
        v.provision()
        roles = {}
        for role, machines in vagrant_roles.items():
            for machine in machines:
                keyfile = v.keyfile(vm_name=machine['name'])
                port = v.port(vm_name=machine['name'])
                address = v.hostname(vm_name=machine['name'])
                roles.setdefault(role, []).append(
                    Host(address,
                         alias=machine['name'],
                         user=self.provider_conf.user,
                         port=port,
                         keyfile=keyfile))

        networks = [{
            'cidr': str(n["cidr"]),
            'start': str(n["netpool"][0]),
            'end': str(n["netpool"][-1]),
            'dns': '8.8.8.8',
            'gateway': str(n["gateway"]),
            'roles': n["roles"]
            } for n in _networks]
        logger.debug(roles)
        logger.debug(networks)

        return (roles, networks)

Reserve and deploys the vagrant boxes.

Args:
force_deploy (bool): True iff new machines should be started


def initialize_logger():
    logger = logging.getLogger('steppy')
    logger.setLevel(logging.INFO)
    message_format = logging.Formatter(fmt='%(asctime)s %(name)s >>> %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
    console_handler = logging.StreamHandler(sys.stdout)
    console_handler.setLevel(logging.INFO)
    console_handler.setFormatter(fmt=message_format)
    logger.addHandler(console_handler)
    return logger

Initialize steppy logger.

This logger is used throughout the steppy library to report computation progress.

Example:

Simple use of steppy logger:

.. code-block:: python

initialize_logger()
logger = get_logger()
logger.info('My message inside pipeline')

result looks like this:

.. code::

2018-06-02 12:33:48 steppy >>> My message inside pipeline

Returns:
logging.Logger: logger object formatted in the steppy style


def interpolate(self, x: types.RealTensor, y: types.RealTensor, name: str=None):
    name = name or self._name + '_interpolate'
    with tf.name_scope(name):
        x = tf.convert_to_tensor(x, dtype=self._dtype, name='x')
        y = tf.convert_to_tensor(y, dtype=self._dtype, name='y')
        y = tf.expand_dims(y, axis=-2)
        xy = cubic.interpolate(y, self._spline_yz, name='interpolation_in_y_direction')
        xy_rank = xy.shape.rank
        perm = [xy_rank - 1] + list(range(xy_rank - 1))
        yx = tf.transpose(xy, perm=perm)
        perm_original = list(range(1, xy_rank)) + [0]
        x = tf.expand_dims(tf.transpose(x, [xy_rank - 2] + list(range(xy_rank - 2))), axis=-1)
        z_values = linear.interpolate(x, self._xdata, yx)
        return tf.squeeze(tf.transpose(z_values, perm=perm_original), axis=-2)

Performs 2-D interpolation on a specified set of points.

Args:
x: Real-valued `Tensor` of shape `batch_shape + [num_points]`.
Defines the x-coordinates at which the interpolation should be
performed. Note that `batch_shape` should be the same as in the
underlying data.
y: A `Tensor` of the same shape and `dtype` as `x`.
Defines the y-coordinates at which the interpolation should be
performed.
name: Python `str` name prefixed to ops created by this function.
Default value: `None` which is mapped to the default name
`interpolate`.

Returns:
A `Tensor` of the same shape and `dtype` as `x`. Represents the
interpolated values of the function on for the coordinates
`(x, y)`.


def delete(self, filename):

        if is_package(filename):
            self.connection["jss"].Package(filename).delete()
        else:
            self.connection["jss"].Script(filename).delete()

Delete a package or script from the distribution server.

This method simply finds the Package or Script object from the
database with the API GET call and then deletes it. This will
remove the file from the database blob.

For setups which have file share distribution points, you will
need to delete the files on the shares also.

Args:
filename: Filename (no path) to delete.