def find_exception_by_code(code):

    errorName = None
    for error in WebDriverError:
        if error.value.code == code:
            errorName = error
            break
    return errorName

Find name of exception by WebDriver defined error code.

Args:
code(str): Error code defined in protocol.

Returns:
The error name defined in protocol.


def get_property_dict(entity_proto):

  return dict((p.key, p.value) for p in entity_proto.property)

Convert datastore.Entity to a dict of property name -> datastore.Value.

Args:
entity_proto: datastore.Entity proto message.

Usage:
>>> get_property_dict(entity_proto)
{'foo': {string_value='a'}, 'bar': {integer_value=2}}

Returns:
dict of entity properties.


def merge_annotations(code, annotations, param_annotations):
    if param_annotations:
        visitor = FunctionDefVisitor(param_annotations)
        pyc.visit(code, visitor)
    visitor = CollectAnnotationTargetsVisitor()
    code = pyc.visit(code, visitor)
    for line, op in visitor.store_ops.items():
        if line in annotations:
            annot = annotations[line]
            if annot.name in (None, op.argval):
                op.annotation = annot.annotation
    for start, (end, op) in sorted(visitor.make_function_ops.items(), reverse=True):
        for i in range(start, end):
            if i in annotations:
                op.annotation = (annotations[i].annotation, i)
                break
    return code

Merges type comments into their associated opcodes.

Modifies code in place.

Args:
code: An OrderedCode object.
annotations: A map of lines to annotations.
param_annotations: A list of _ParamAnnotations from the director

Returns:
The code with annotations added to the relevant opcodes.


def convert(model_path: str, out_file: str):

    print('Converting', model_path, 'to', out_file, '...')

    import tensorflow as tf
    from precise.model import load_precise_model
    from keras import backend as K

    out_dir, filename = split(out_file)
    out_dir = out_dir or '.'
    os.makedirs(out_dir, exist_ok=True)

    K.set_learning_phase(0)
    model = load_precise_model(model_path)

    out_name = 'net_output'
    tf.identity(model.output, name=out_name)
    print('Output node name:', out_name)
    print('Output folder:', out_dir)

    sess = K.get_session()

    tf.train.write_graph(sess.graph.as_graph_def(), out_dir, filename + 'txt', as_text=True)
    print('Saved readable graph to:', filename + 'txt')

    from tensorflow.python.framework import graph_util
    from tensorflow.python.framework import graph_io

    cgraph = graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), [out_name])
    graph_io.write_graph(cgraph, out_dir, filename, as_text=False)

    if isfile(model_path + '.params'):
        copyfile(model_path + '.params', out_file + '.params')

    print('Saved graph to:', filename)

    del sess

Converts an HD5F file from Keras to a .pb for use with TensorFlow

Args:
model_path: location of Keras model
out_file: location to write protobuf


def blit_2x(self, console: tcod.console.Console, dest_x: int, dest_y: int, img_x: int=0, img_y: int=0, img_width: int=(- 1), img_height: int=(- 1)) -> None:
    lib.TCOD_image_blit_2x(self.image_c, _console(console), dest_x, dest_y, img_x, img_y, img_width, img_height)

Blit onto a Console with double resolution.

Args:
console (Console): Blit destination Console.
dest_x (int): Console tile X position starting from the left at 0.
dest_y (int): Console tile Y position starting from the top at 0.
img_x (int): Left corner pixel of the Image to blit
img_y (int): Top corner pixel of the Image to blit
img_width (int): Width of the Image to blit.
Use -1 for the full Image width.
img_height (int): Height of the Image to blit.
Use -1 for the full Image height.


def create_log(log_file, uid):

    if not os.path.exists(log_file):
        dir_name = os.path.dirname(log_file)
        if not os.path.exists(dir_name):
            os.makedirs(dir_name, 0755)
            os.chown(dir_name, uid, -1)

        with open(log_file, "w") as f:
            f.write("")

    os.chown(log_file, uid, -1)
    os.chmod(log_file, 0640)

Create log file and set necessary permissions.

Args:
log_file (str): Path to the log file.
uid (int): User ID - will be used for chown.


def update(self, data):

        updated = False
        if 'missing_tags' in data:
            updated |= self.set_property('missing_tags', data['missing_tags'])

        if 'notes' in data:
            updated |= self.set_property('notes', data['notes'])

        if 'state' in data:
            updated |= self.set_property('state', data['state'])

        if 'last_alert' in data:
            updated |= self.set_property('last_alert', data['last_alert'])

        if updated:
            now = datetime.now()
            self.set_property('last_change', now)

        return updated

Updates the object information based on live data, if there were any changes made. Any changes will be
automatically applied to the object, but will not be automatically persisted. You must manually call
`db.session.add(instance)` on the object.

Args:
data (:obj:): AWS API Resource object fetched from AWS API

Returns:
`bool`


def get_lattice_type(number):
    f = (lambda i, j: (i <= number <= j))
    cs = {'triclinic': (1, 2), 'monoclinic': (3, 15), 'orthorhombic': (16, 74), 'tetragonal': (75, 142), 'trigonal': (143, 167), 'hexagonal': (168, 194), 'cubic': (195, 230)}
    crystal_system = None
    for (k, v) in cs.items():
        if f(*v):
            crystal_system = k
            break
    if (number in [146, 148, 155, 160, 161, 166, 167]):
        return 'rhombohedral'
    elif (crystal_system == 'trigonal'):
        return 'hexagonal'
    else:
        return crystal_system

Return the lattice crystal system.

Hexagonal cells are differentiated into rhombohedral and hexagonal
lattices.

Args:
number (int): The international space group number.

Returns:
str: The lattice crystal system.


def update_z(self, z, indices=None):
    z = _make_np_bool(z)
    if (indices is None):
        if (len(self._z) != len(z)):
            raise QiskitError('During updating whole z, you can not change the number of qubits.')
        self._z = z
    else:
        if ((not isinstance(indices, list)) and (not isinstance(indices, np.ndarray))):
            indices = [indices]
        for (p, idx) in enumerate(indices):
            self._z[idx] = z[p]
    return self

Update partial or entire z.

Args:
z (numpy.ndarray or list): to-be-updated z
indices (numpy.ndarray or list or optional): to-be-updated qubit indices

Returns:
Pauli: self

Raises:
QiskitError: when updating whole z, the number of qubits must be the same.


def run_iperf_client(self, server_host, extra_args=''):
    out = self.adb.shell(('iperf3 -c %s %s' % (server_host, extra_args)))
    clean_out = new_str(out, 'utf-8').strip().split('\n')
    if ('error' in clean_out[0].lower()):
        return (False, clean_out)
    return (True, clean_out)

Start iperf client on the device.

Return status as true if iperf client start successfully.
And data flow information as results.

Args:
server_host: Address of the iperf server.
extra_args: A string representing extra arguments for iperf client,
e.g. '-i 1 -t 30'.

Returns:
status: true if iperf client start successfully.
results: results have data flow information


def downloadMARCXML(doc_id, library, base='nkc'):
    downer = Downloader()
    data = downer.download((ALEPH_URL + Template(DOC_URL_TEMPLATE).substitute(DOC_ID=doc_id, LIBRARY=library)))
    dom = dhtmlparser.parseString(data)
    error = dom.find('login')
    if error:
        error_msg = error[0].find('error')
        if error_msg:
            raise LibraryNotFoundException((((((("Can't download document doc_id: '" + str(doc_id)) + "' ") + "(probably bad library: '") + library) + "')!\nMessage: ") + '\n'.join(map((lambda x: x.getContent()), error_msg))))
    error = dom.find('ill-get-doc')
    if error:
        error_msg = error[0].find('error')
        if error_msg:
            raise DocumentNotFoundException('\n'.join(map((lambda x: x.getContent()), error_msg)))
    return data

Download MARC XML document with given `doc_id` from given `library`.

Args:
doc_id (DocumentID): You will get this from :func:`getDocumentIDs`.
library (str): "``NKC01``" in our case, but don't worry,
:func:`getDocumentIDs` adds library specification into
:class:`DocumentID` named tuple.

Returns:
str: MARC XML unicode string.

Raises:
LibraryNotFoundException
DocumentNotFoundException


def _load_from_file(path):
    config = []
    try:
        with open(path, 'r') as config_file:
            config = yaml.load(config_file)['normalizations']
    except EnvironmentError as e:
        raise ConfigError((('Problem while loading file: %s' % e.args[1]) if (len(e.args) > 1) else e))
    except (TypeError, KeyError) as e:
        raise ConfigError(('Config file has an unexpected structure: %s' % e))
    except yaml.YAMLError:
        raise ConfigError('Invalid YAML file syntax')
    return config

Load a config file from the given path.

Load all normalizations from the config file received as
argument. It expects to find a YAML file with a list of
normalizations and arguments under the key 'normalizations'.

Args:
path: Path to YAML file.


def _ReadRecordHeader(self, file_object, record_header_offset):

    data_type_map = self._GetDataTypeMap('keychain_record_header')

    record_header, _ = self._ReadStructureFromFileObject(
        file_object, record_header_offset, data_type_map)

    return record_header

Reads the record header.

Args:
file_object (file): file-like object.
record_header_offset (int): offset of the record header relative to
the start of the file.

Returns:
keychain_record_header: record header.

Raises:
ParseError: if the record header cannot be read.


def restore(self, request):

        self._connection.connection.rpush(self._request_key, pickle.dumps(request))

Push the request back onto the queue.

Args:
request (Request): Reference to a request object that should be pushed back
onto the request queue.


def add_context(self, name, context, prefix_char=None):

        if name in self.contexts:
            raise SuiteError("Context already in suite: %r" % name)
        if not context.success:
            raise SuiteError("Context is not resolved: %r" % name)

        self.contexts[name] = dict(name=name,
                                   context=context.copy(),
                                   tool_aliases={},
                                   hidden_tools=set(),
                                   priority=self._next_priority,
                                   prefix_char=prefix_char)
        self._flush_tools()

Add a context to the suite.

Args:
name (str): Name to store the context under.
context (ResolvedContext): Context to add.


def get(self, column, default_value=None):

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

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

Get an item from the Row by column name.

Args:
column: Tuple of column names, or a (str) column name, or positional
column number, 0-indexed.
default_value: The value to use if the key is not found.

Returns:
A list or string with column value(s) or default_value if not found.


def from_esri_code(code):
    code = str(code)
    proj4 = utils.crscode_to_string('esri', code, 'proj4')
    crs = from_proj4(proj4)
    return crs

Load crs object from esri code, via spatialreference.org.
Parses based on the proj4 representation.

Arguments:

- *code*: The ESRI code as an integer.

Returns:

- A CS instance of the indicated type.


def is_comparable_type(var, type_):
    other_types = COMPARABLE_TYPES.get(type_, type_)
    return isinstance(var, other_types)

Check to see if `var` is an instance of known compatible types for `type_`

Args:
var (?):
type_ (?):

Returns:
bool:

CommandLine:
python -m utool.util_type is_comparable_type --show

Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_type import *  # NOQA
>>> import utool as ut
>>> flags = []
>>> flags += [is_comparable_type(0, float)]
>>> flags += [is_comparable_type(0, np.float32)]
>>> flags += [is_comparable_type(0, np.int32)]
>>> flags += [is_comparable_type(0, int)]
>>> flags += [is_comparable_type(0.0, int)]
>>> result = ut.repr2(flags)
>>> print(result)
[True, True, True, True, False]


def draw_vr_anaglyph(cube_fbo, vr_scene, active_scene, eye_poses=(.035, -.035)):

    color_masks = [(True, False, False, True), (False, True, True, True)]
    cam = vr_scene.camera
    orig_cam_position = cam.position.xyz

    for color_mask, eye_pos in zip(color_masks, eye_poses):
        gl.glColorMask(*color_mask)
        cam.position.xyz = cam.model_matrix.dot([eye_pos, 0., 0., 1.])[:3]
        cam.uniforms['playerPos'] = cam.position.xyz
        with cube_fbo as fbo:
            vr_scene.draw360_to_texture(fbo.texture)
        cam.position.xyz = orig_cam_position
        active_scene.draw()

Experimental anaglyph drawing function for VR system with red/blue glasses, used in Sirota lab.
Draws a virtual scene in red and blue, from subject's (heda trackers) perspective in active scene.

Note: assumes shader uses playerPos like ratcave's default shader

Args:
cube_fbo: texture frameBuffer object.
vr_scene: virtual scene object
active_scene: active scene object
eye_poses: the eye positions

Returns:


def _CreateCampaignGroup(client):

  campaign_group_service = client.GetService('CampaignGroupService',
                                             version='v201809')

  operations = [{
      'operator': 'ADD',

      'operand': {
          'name': 'Mars campaign group
      }
  }]

  campaign_group = campaign_group_service.mutate(operations)['value'][0]
  campaign_group_id = campaign_group['id']

  print 'Campaign group with ID "%d" and name "%s" was created.' % (
      campaign_group_id, campaign_group['name'])

  return campaign_group_id

Create a campaign group.

Args:
client: an AdWordsClient instance.

Returns:
The integer ID of the created campaign group.


def run_validate_program_main(self, program_main):

        program_language = self.profile.get('install_json').get('programLanguage', 'python').lower()
        if program_language == 'python' and not os.path.isfile('{}.py'.format(program_main)):
            print(
                '{}{}Could not find program main file ({}).'.format(
                    c.Style.BRIGHT, c.Fore.RED, program_main
                )
            )
            sys.exit(1)

Validate the program main file exists.

Args:
program_main (str): The executable name.


def _decode_crop_and_flip(image_buffer, num_channels):

  min_object_covered=0.1
  aspect_ratio_range=[0.75, 1.33]
  area_range=[0.05, 1.0]
  max_attempts=100

  mlperf_log.resnet_print(key=mlperf_log.INPUT_DISTORTED_CROP_MIN_OBJ_COV,
                          value=min_object_covered)
  mlperf_log.resnet_print(key=mlperf_log.INPUT_DISTORTED_CROP_RATIO_RANGE,
                          value=aspect_ratio_range)
  mlperf_log.resnet_print(key=mlperf_log.INPUT_DISTORTED_CROP_AREA_RANGE,
                          value=area_range)
  mlperf_log.resnet_print(key=mlperf_log.INPUT_DISTORTED_CROP_MAX_ATTEMPTS,
                          value=max_attempts)
  mlperf_log.resnet_print(key=mlperf_log.INPUT_CROP_USES_BBOXES, value=False)

  bbox = tf.constant([0.0, 0.0, 1.0, 1.0],
                     dtype=tf.float32, shape=[1, 1, 4])
  sample_distorted_bounding_box = tf.image.sample_distorted_bounding_box(
      tf.image.extract_jpeg_shape(image_buffer),
      bounding_boxes=bbox,
      min_object_covered=min_object_covered,
      aspect_ratio_range=aspect_ratio_range,
      area_range=area_range,
      max_attempts=max_attempts,
      use_image_if_no_bounding_boxes=True)
  bbox_begin, bbox_size, _ = sample_distorted_bounding_box

  offset_y, offset_x, _ = tf.unstack(bbox_begin)
  target_height, target_width, _ = tf.unstack(bbox_size)
  crop_window = tf.stack([offset_y, offset_x, target_height, target_width])

  cropped = tf.image.decode_and_crop_jpeg(
      image_buffer, crop_window, channels=num_channels)

  mlperf_log.resnet_print(key=mlperf_log.INPUT_RANDOM_FLIP)
  cropped = tf.image.random_flip_left_right(cropped)
  return cropped

Crops the given image to a random part of the image, and randomly flips.

We use the fused decode_and_crop op, which performs better than the two ops
used separately in series, but note that this requires that the image be
passed in as an un-decoded string Tensor.

Args:
image_buffer: scalar string Tensor representing the raw JPEG image buffer.
num_channels: Integer depth of the image buffer for decoding.

Returns:
3-D tensor with cropped image.


def get_dict_definition(self, dict, get_list=False):

        list_def_candidate = []
        for definition_name in self.specification['definitions'].keys():
            if self.validate_definition(definition_name, dict):
                if not get_list:
                    return definition_name
                list_def_candidate.append(definition_name)
        if get_list:
            return list_def_candidate
        return None

Get the definition name of the given dict.

Args:
dict: dict to test.
get_list: if set to true, return a list of definition that match the body.
if False, only return the first.

Returns:
The definition name or None if the dict does not match any definition.
If get_list is True, return a list of definition_name.


def form_to_params(fn=None, return_json=True):

    def forms_to_params_decorator(fn):

        @handle_type_error
        @wraps(fn)
        def forms_to_params_wrapper(*args, **kwargs):
            kwargs.update(dict(request.forms))
            if (not return_json):
                return fn(*args, **kwargs)
            return encode_json_body(fn(*args, **kwargs))
        return forms_to_params_wrapper
    if fn:
        return forms_to_params_decorator(fn)
    return forms_to_params_decorator

Convert bottle forms request to parameters for the wrapped function.

Args:
return_json (bool, default True): Should the decorator automatically
convert returned value to JSON?


def in_place_subclassed_model_state_restoration(model):
    assert not model._is_graph_network
    if hasattr(model, '_original_attributes_cache') and model._original_attributes_cache is not None:
        setattr_tracking = model._setattr_tracking
        model._setattr_tracking = False
        model._self_tracked_trackables = []
        for name, value in model._original_attributes_cache.items():
            setattr(model, name, value)
            if isinstance(value, Layer):
                model._self_tracked_trackables.append(value)
        model._original_attributes_cache = None
        model._setattr_tracking = setattr_tracking
    else:
        _reset_build_compile_trackers(model)

Restores the original state of a model after it was "reset".

This undoes this action of `_in_place_subclassed_model_reset`, which is called
in `clone_and_build_model` if `in_place_reset` is set to True.

Args:
model: Instance of a Keras model created via subclassing, on which
`_in_place_subclassed_model_reset` was previously called.


def get_vm(access_token, subscription_id, resource_group, vm_name):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/virtualMachines/', vm_name,
                        '?api-version=', COMP_API])
    return do_get(endpoint, access_token)

Get virtual machine details.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vm_name (str): Name of the virtual machine.

Returns:
HTTP response. JSON body of VM properties.


def export_with_dynamic_cache(model: PreTrainedModel, example_input_ids: Optional[torch.Tensor]=None, example_attention_mask: Optional[torch.Tensor]=None):
    if not is_torch_greater_or_equal_than_2_3:
        raise ImportError('torch >= 2.3 is required.')
    ALL_MASK_ATTENTION_FUNCTIONS.register('sdpa_without_vmap', sdpa_mask_without_vmap)
    ALL_ATTENTION_FUNCTIONS.register('sdpa_without_vmap', ALL_ATTENTION_FUNCTIONS['sdpa'])
    model.config._attn_implementation = 'sdpa_without_vmap'
    with torch.no_grad():
        exported_program = torch.export.export(model, (), {'input_ids': example_input_ids, 'attention_mask': example_attention_mask, 'past_key_values': DynamicCache(), 'use_cache': True}, strict=False)
        return exported_program

Export a model with DynamicCache using `torch.export`, ensuring the exported model is compatible with `ExecuTorch`.

Args:
model (`PreTrainedModel`): The pretrained model to be exported.
example_input_ids (`Optional[torch.Tensor]`): Example input token id used by `torch.export`.
example_attention_mask (`Optional[torch.Tensor]`): Example attention mask used by `torch.export`.

Returns:
Exported program (`torch.export.ExportedProgram`): The exported program generated via `torch.export`.


def list_children(self, obj, save_type=base.SaveType.CHECKPOINT, **kwargs):
    children = []
    for name, ref in super(ObjectGraphView, self).children(obj, save_type, **kwargs).items():
        children.append(base.TrackableReference(name, ref))
    if obj is self.root and self._attached_dependencies:
        children.extend(self._attached_dependencies)
    return children

Returns list of all child trackables attached to obj.

Args:
obj: A `Trackable` object.
save_type: A string, can be 'savedmodel' or 'checkpoint'.
**kwargs: kwargs to use when retrieving the object's children.

Returns:
List of all children attached to the object.


def _ParseLogFileOptions(self, options):
    self._log_file = self.ParseStringOption(options, 'log_file')
    if (not self._log_file):
        local_date_time = datetime.datetime.now()
        self._log_file = '{0:s}-{1:04d}{2:02d}{3:02d}T{4:02d}{5:02d}{6:02d}.log.gz'.format(self.NAME, local_date_time.year, local_date_time.month, local_date_time.day, local_date_time.hour, local_date_time.minute, local_date_time.second)

Parses the log file options.

Args:
options (argparse.Namespace): command line arguments.


def insert_or_update(table, columns, values):
    rows = len(values)
    cells = len(columns) * len(values)
    return _Mutator(mutation=Mutation(insert_or_update=batch._make_write_pb(table, columns, values)), operation=WriteMutation._OPERATION_INSERT_OR_UPDATE, rows=rows, cells=cells, kwargs={'table': table, 'columns': columns, 'values': values})

Insert/update one or more table rows.
Args:
table: Name of the table to be modified.
columns: Name of the table columns to be modified.
values: Values to be modified.


def binary_op(self, op, other, **kwargs):
    func = getattr(pandas.DataFrame, op)
    return self._inter_df_op_handler(func, other, **kwargs)

Perform an operation between two objects.

Note: The list of operations is as follows:
- add
- eq
- floordiv
- ge
- gt
- le
- lt
- mod
- mul
- ne
- pow
- rfloordiv
- rmod
- rpow
- rsub
- rtruediv
- sub
- truediv
- __and__
- __or__
- __xor__
Args:
op: The operation. See list of operations above
other: The object to operate against.

Returns:
A new QueryCompiler object.


def _check_element_shape(self, shape):
    if not shape.is_compatible_with(self.element_shape):
        raise ValueError('Inconsistent shapes: saw %s but expected %s ' % (shape, self.element_shape))
    if self._infer_shape:
        self._element_shape[0] = self.element_shape.merge_with(shape)

Changes the element shape of the array given a shape to merge with.

Args:
shape: A `TensorShape` object to merge with.

Raises:
ValueError: if the provided shape is incompatible with the current
element shape of the `TensorArray`.


def resize_images(x, height_factor, width_factor, data_format, interpolation='nearest'):
    if data_format == 'channels_first':
        rows, cols = (2, 3)
    elif data_format == 'channels_last':
        rows, cols = (1, 2)
    else:
        raise ValueError('Invalid `data_format` argument: %s' % (data_format,))
    new_shape = x.shape[rows:cols + 1]
    if new_shape.is_fully_defined():
        new_shape = constant_op.constant(new_shape.as_list(), dtype='int32')
    else:
        new_shape = array_ops.shape_v2(x)[rows:cols + 1]
    new_shape *= constant_op.constant(np.array([height_factor, width_factor], dtype='int32'))
    if data_format == 'channels_first':
        x = permute_dimensions(x, [0, 2, 3, 1])
    if interpolation == 'nearest':
        x = image_ops.resize_images_v2(x, new_shape, method=image_ops.ResizeMethod.NEAREST_NEIGHBOR)
    elif interpolation == 'bilinear':
        x = image_ops.resize_images_v2(x, new_shape, method=image_ops.ResizeMethod.BILINEAR)
    else:
        raise ValueError('interpolation should be one of "nearest" or "bilinear".')
    if data_format == 'channels_first':
        x = permute_dimensions(x, [0, 3, 1, 2])
    return x

Resizes the images contained in a 4D tensor.

Args:
x: Tensor or variable to resize.
height_factor: Positive integer.
width_factor: Positive integer.
data_format: One of `"channels_first"`, `"channels_last"`.
interpolation: A string, one of `nearest` or `bilinear`.

Returns:
A tensor.

Raises:
ValueError: in case of incorrect value for
`data_format` or `interpolation`.


def symbol(name: str=None, symbol_type: Type[Symbol]=Symbol) -> 'SymbolWildcard':
    if (isinstance(name, type) and issubclass(name, Symbol) and (symbol_type is Symbol)):
        return SymbolWildcard(name)
    return SymbolWildcard(symbol_type, variable_name=name)

Create a `SymbolWildcard` that matches a single `Symbol` argument.

Args:
name:
Optional variable name for the wildcard.
symbol_type:
An optional subclass of `Symbol` to further limit which kind of symbols are
matched by the wildcard.

Returns:
A `SymbolWildcard` that matches the *symbol_type*.


def get_group_id(self, uuid=None):
    group_data = self.get_group(uuid)
    try:
        return group_data['response']['docs'][0]['id']
    except (KeyError, IndexError):
        failure_message = 'Error in get_group response data - got {0}'.format(group_data)
        log.exception(failure_message)
        raise PyLmodUnexpectedData(failure_message)

Get group id based on uuid.

Args:
uuid (str): optional uuid. defaults to self.cuuid

Raises:
PyLmodUnexpectedData: No group data was returned.
requests.RequestException: Exception connection error

Returns:
int: numeric group id


def replaceFA(self, faDataType: int, xml: str):
    self.client.replaceFA(faDataType, xml)

Replaces Financial Advisor's settings.

Args:
faDataType: See :meth:`.requestFA`.
xml: The XML-formatted configuration string.


def download(self, temp_ver, store_metadata=True):

        dest = self._prefixed(temp_ver.name)
        temp_dest = '%s.tmp' % dest

        with utils.LockFile(dest + '.lock'):

            if os.path.exists(dest):
                return

            temp_ver.download(temp_dest)
            if store_metadata:
                with open('%s.metadata' % dest, 'w') as f:
                    utils.json_dump(temp_ver.get_metadata(), f)

            sha1 = utils.get_hash(temp_dest)
            if temp_ver.get_hash() != sha1:
                raise RuntimeError(
                    'Image %s does not match the expected hash %s' % (
                        temp_ver.name,
                        sha1,
                    )
                )

            with open('%s.hash' % dest, 'w') as f:
                f.write(sha1)

            with log_utils.LogTask('Convert image', logger=LOGGER):
                result = utils.run_command(
                    [
                        'qemu-img',
                        'convert',
                        '-O',
                        'raw',
                        temp_dest,
                        dest,
                    ],
                )

                os.unlink(temp_dest)
                if result:
                    raise RuntimeError(result.err)

Retrieve the given template version

Args:
temp_ver (TemplateVersion): template version to retrieve
store_metadata (bool): If set to ``False``, will not refresh the
local metadata with the retrieved one

Returns:
None


def describe_message(message_definition):
    message_descriptor = MessageDescriptor()
    message_descriptor.name = message_definition.definition_name().split('.')[(- 1)]
    fields = sorted(message_definition.all_fields(), key=(lambda v: v.number))
    if fields:
        message_descriptor.fields = [describe_field(field) for field in fields]
    try:
        nested_messages = message_definition.__messages__
    except AttributeError:
        pass
    else:
        message_descriptors = []
        for name in nested_messages:
            value = getattr(message_definition, name)
            message_descriptors.append(describe_message(value))
        message_descriptor.message_types = message_descriptors
    try:
        nested_enums = message_definition.__enums__
    except AttributeError:
        pass
    else:
        enum_descriptors = []
        for name in nested_enums:
            value = getattr(message_definition, name)
            enum_descriptors.append(describe_enum(value))
        message_descriptor.enum_types = enum_descriptors
    return message_descriptor

Build descriptor for Message class.

Args:
message_definition: Message class to provide descriptor for.

Returns:
Initialized MessageDescriptor instance describing the Message class.


def prune_graph(graph_str, package_name):

    g = read_dot(graph_str)
    nodes = set()

    for node, attrs in g.node_attr.iteritems():
        attr = [x for x in attrs if x[0] == "label"]
        if attr:
            label = attr[0][1]
            try:
                req_str = _request_from_label(label)
                request = PackageRequest(req_str)
            except PackageRequestError:
                continue

            if request.name == package_name:
                nodes.add(node)

    if not nodes:
        raise ValueError("The package %r does not appear in the graph."
                         % package_name)

    g_rev = g.reverse()
    accessible_nodes = set()
    access = accessibility(g_rev)
    for node in nodes:
        nodes_ = access.get(node, [])
        accessible_nodes |= set(nodes_)

    inaccessible_nodes = set(g.nodes()) - accessible_nodes
    for node in inaccessible_nodes:
        g.del_node(node)

    return write_dot(g)

Prune a package graph so it only contains nodes accessible from the
given package.

Args:
graph_str (str): Dot-language graph string.
package_name (str): Name of package of interest.

Returns:
Pruned graph, as a string.


def __init__(self, resolver_context, file_object=None):

    if file_object:
      raise ValueError('File object value set.')

    super(EWFFile, self).__init__(resolver_context)
    self._file_objects = []

Initializes a file-like object.

Args:
resolver_context (Context): resolver context.
file_object (Optional[FileIO]): file-like object.

Raises:
ValueError: when file_object is set.


def add_answer_for_student(student_item, vote, rationale):

    answers = get_answers_for_student(student_item)
    answers.add_answer(vote, rationale)

    sub_api.create_submission(student_item, {
        ANSWER_LIST_KEY: answers.get_answers_as_list()
    })

Add an answer for a student to the backend

Args:
student_item (dict): The location of the problem this submission is
associated with, as defined by a course, student, and item.
vote (int): the option that student voted for
rationale (str): the reason why the student vote for the option


def parse(self, sentence: str) -> typing.List[str]:
    if sentence == '':
        return []
    chunks = [sentence[0]]
    base_score = -sum((sum(g.values()) for g in self.model.values())) * 0.5
    for i in range(1, len(sentence)):
        score = base_score
        if i > 2:
            score += self.model.get('UW1', {}).get(sentence[i - 3], 0)
        if i > 1:
            score += self.model.get('UW2', {}).get(sentence[i - 2], 0)
        score += self.model.get('UW3', {}).get(sentence[i - 1], 0)
        score += self.model.get('UW4', {}).get(sentence[i], 0)
        if i + 1 < len(sentence):
            score += self.model.get('UW5', {}).get(sentence[i + 1], 0)
        if i + 2 < len(sentence):
            score += self.model.get('UW6', {}).get(sentence[i + 2], 0)
        if i > 1:
            score += self.model.get('BW1', {}).get(sentence[i - 2:i], 0)
        score += self.model.get('BW2', {}).get(sentence[i - 1:i + 1], 0)
        if i + 1 < len(sentence):
            score += self.model.get('BW3', {}).get(sentence[i:i + 2], 0)
        if i > 2:
            score += self.model.get('TW1', {}).get(sentence[i - 3:i], 0)
        if i > 1:
            score += self.model.get('TW2', {}).get(sentence[i - 2:i + 1], 0)
        if i + 1 < len(sentence):
            score += self.model.get('TW3', {}).get(sentence[i - 1:i + 2], 0)
        if i + 2 < len(sentence):
            score += self.model.get('TW4', {}).get(sentence[i:i + 3], 0)
        if score > 0:
            chunks.append(sentence[i])
        else:
            chunks[-1] += sentence[i]
    return chunks

Parses the input sentence and returns a list of semantic chunks.

Args:
sentence (str): An input sentence.

Returns:
A list of semantic chunks (List[str]).


def ValidateDependencies(rdf_artifact):
    for dependency in GetArtifactDependencies(rdf_artifact):
        try:
            dependency_obj = REGISTRY.GetArtifact(dependency)
        except rdf_artifacts.ArtifactNotRegisteredError as e:
            raise rdf_artifacts.ArtifactDependencyError(rdf_artifact, 'missing dependency', cause=e)
        message = dependency_obj.error_message
        if message:
            raise rdf_artifacts.ArtifactDependencyError(rdf_artifact, 'dependency error', cause=message)

Validates artifact dependencies.

This method checks whether all dependencies of the artifact are present
and contain no errors.

This method can be called only after all other artifacts have been loaded.

Args:
rdf_artifact: RDF object artifact.

Raises:
ArtifactDependencyError: If a dependency is missing or contains errors.


def plot_val_with_title(self, idxs, y):

        if len(idxs) > 0:
            imgs = np.stack([self.ds[x][0] for x in idxs])
            title_probs = [self.probs[x,y] for x in idxs]

            return plots(self.ds.denorm(imgs), rows=1, titles=title_probs)

        else:
            return False;

Displays the images and their probabilities of belonging to a certain class

Arguments:
idxs (numpy.ndarray): indexes of the image samples from the dataset
y (int): the selected class

Returns:
Plots the images in n rows [rows = n]


def _cast_to_frameset(cls, other):

        if isinstance(other, FrameSet):
            return other
        try:
            return FrameSet(other)
        except Exception:
            return NotImplemented

Private method to simplify comparison operations.

Args:
other (:class:`FrameSet` or set or frozenset or or iterable): item to be compared

Returns:
:class:`FrameSet`

Raises:
:class:`NotImplemented`: if a comparison is impossible


def tracer_diffusion_coefficient( self ):

        if self.has_run:
            return self.atoms.sum_dr_squared() / ( 6.0 * float( self.number_of_atoms ) * self.lattice.time )
        else:
            return None

Tracer diffusion coefficient, D*.

Args:
None

Returns:
(Float): The tracer diffusion coefficient, D*.


def import_family(self, rfa_file):
    self._add_entry(templates.IMPORT_FAMILY.format(family_file=rfa_file))

Append a import family entry to the journal.

This instructs Revit to import a family into the opened model.

Args:
rfa_file (str): full path of the family file


def from_sub_models_config(cls, text_encoder_config: PretrainedConfig, audio_encoder_config: PretrainedConfig, decoder_config: MusicgenDecoderConfig, **kwargs):
    return cls(text_encoder=text_encoder_config.to_dict(), audio_encoder=audio_encoder_config.to_dict(), decoder=decoder_config.to_dict(), **kwargs)

Instantiate a [`MusicgenConfig`] (or a derived class) from text encoder, audio encoder and decoder
configurations.

Returns:
[`MusicgenConfig`]: An instance of a configuration object


def find_link(self, target_node):
    try:
        return next((l for l in self.link_list if (l.target == target_node)))
    except StopIteration:
        return None

Find the link that points to ``target_node`` if it exists.

If no link in ``self`` points to ``target_node``, return None

Args:
target_node (Node): The node to look for in ``self.link_list``

Returns:
Link: An existing link pointing to ``target_node`` if found

None: If no such link exists

Example:
>>> node_1 = Node('One')
>>> node_2 = Node('Two')
>>> node_1.add_link(node_2, 1)
>>> link_1 = node_1.link_list[0]
>>> found_link = node_1.find_link(node_2)
>>> found_link == link_1
True


def valid_vlan_id(vlan_id, extended=True):
    minimum_vlan_id = 1
    maximum_vlan_id = 4095
    if extended:
        maximum_vlan_id = 8191
    return (minimum_vlan_id <= int(vlan_id) <= maximum_vlan_id)

Validates a VLAN ID.

Args:
vlan_id (integer): VLAN ID to validate.  If passed as ``str``, it will
be cast to ``int``.
extended (bool): If the VLAN ID range should be considered extended
for Virtual Fabrics.

Returns:
bool: ``True`` if it is a valid VLAN ID.  ``False`` if not.

Raises:
None

Examples:
>>> import pynos.utilities
>>> vlan = '565'
>>> pynos.utilities.valid_vlan_id(vlan)
True
>>> extended = False
>>> vlan = '6789'
>>> pynos.utilities.valid_vlan_id(vlan, extended=extended)
False
>>> pynos.utilities.valid_vlan_id(vlan)
True


def memory_write32(self, addr, data, zone=None):

        return self.memory_write(addr, data, zone, 32)

Writes words to memory of a target system.

Args:
self (JLink): the ``JLink`` instance
addr (int): start address to write to
data (list): list of words to write
zone (str): optional memory zone to access

Returns:
Number of words written to target.

Raises:
JLinkException: on memory access error.


def get_raw_data(self, url, *args, **kwargs):

        res = self._conn.get(url, headers=self._prepare_headers(**kwargs))
        if res.status_code == 200:
            return res.content
        else:
            return None

Gets data from url as bytes

Returns content under the provided url as bytes
ie. for binary data

Args:
**url**: address of the wanted data

.. versionadded:: 0.3.2
**additional_headers**: (optional) Additional headers
to be used with request

Returns:
bytes


def __new__(cls: Type[_T], *args: PathLike) -> _T:
    if cls == Path:
        if not args:
            return register.make_path('.')
        root, *parts = args
        return register.make_path(root).joinpath(*parts)
    else:
        return super().__new__(cls, *args)

Create a new path.

```python
path = abcpath.Path()
```

We use __new__ instead of __init__ to allow subclassing, even though the
usage of __init__ is possible from python>=3.12.

Args:
*args: Paths to create

Returns:
path: The registered path


def count_tornadoes(input_data):
    return input_data | 'months with tornadoes' >> beam.FlatMap(lambda row: [(int(row['month']), 1)] if row['tornado'] else []) | 'monthly count' >> beam.CombinePerKey(sum) | 'format' >> beam.Map(lambda k_v: {'month': k_v[0], 'tornado_count': k_v[1]})

Workflow computing the number of tornadoes for each month that had one.

Args:
input_data: a PCollection of dictionaries representing table rows. Each
dictionary will have a 'month' and a 'tornado' key as described in the
module comment.

Returns:
A PCollection of dictionaries containing 'month' and 'tornado_count' keys.
Months without tornadoes are skipped.


def _get_new_group_key(self, devices):
    new_key = self._group_key
    self._group_key += 1
    self._instance_key_table[new_key] = {}
    for device in devices:
        self._instance_key_table[new_key][device] = INSTANCE_KEY_START_NUMBER
    return new_key

Returns a new group key.

The caller should store and reuse the same group key for the same set of
devices. Calling this method always returns a new group key.

This method is not thread-safe.

Args:
devices: a list of canonical device strings in a collective group.

Returns:
a new group key.


def reset_internal_states(self, record=None):
    self._record = None
    self._count = 0
    self._record = record

Resets the internal state of the recorder.

Args:
record: records.TestResultRecord, the test record for a test.


def error(msg):
    return debugger_cli_common.rich_text_lines_from_rich_line_list([RL('ERROR: ' + msg, COLOR_RED)])

Generate a RichTextLines output for error.

Args:
msg: (str) The error message.

Returns:
(debugger_cli_common.RichTextLines) A representation of the error message
for screen output.


def start_time_distance(item_a, item_b, max_value):

    start_time_diff = np.abs(item_a.times[0] - item_b.times[0])
    return np.minimum(start_time_diff, max_value) / float(max_value)

Absolute difference between the starting times of each item.

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

Returns:
Distance value between 0 and 1.


def generate_tests(self, test_logic, name_func, arg_sets, uid_func=None):
    self._assert_function_names_in_stack([STAGE_NAME_PRE_RUN])
    root_msg = 'During test generation of "%s":' % test_logic.__name__
    for args in arg_sets:
        test_name = name_func(*args)
        if test_name in self.get_existing_test_names():
            raise Error('%s Test name "%s" already exists, cannot be duplicated!' % (root_msg, test_name))
        test_func = functools.partial(test_logic, *args)
        for attr_name in (ATTR_MAX_RETRY_CNT, ATTR_MAX_CONSEC_ERROR, ATTR_REPEAT_CNT):
            attr = getattr(test_logic, attr_name, None)
            if attr is not None:
                setattr(test_func, attr_name, attr)
        if uid_func is not None:
            uid = uid_func(*args)
            if uid is None:
                logging.warning('%s UID for arg set %s is None.', root_msg, args)
            else:
                setattr(test_func, 'uid', uid)
        self._generated_test_table[test_name] = test_func

Generates tests in the test class.

This function has to be called inside a test class's `self.pre_run`.

Generated tests are not written down as methods, but as a list of
parameter sets. This way we reduce code repetition and improve test
scalability.

Users can provide an optional function to specify the UID of each test.
Not all generated tests are required to have UID.

Args:
test_logic: function, the common logic shared by all the generated
tests.
name_func: function, generate a test name according to a set of
test arguments. This function should take the same arguments as
the test logic function.
arg_sets: a list of tuples, each tuple is a set of arguments to be
passed to the test logic function and name function.
uid_func: function, an optional function that takes the same
arguments as the test logic function and returns a string that
is the corresponding UID.


def logsumexp(x, axis=None, keepdims=False):
    if any_symbolic_tensors((x,)):
        return Logsumexp(axis, keepdims).symbolic_call(x)
    return backend.math.logsumexp(x, axis=axis, keepdims=keepdims)

Computes the logarithm of sum of exponentials of elements in a tensor.

Args:
x: Input tensor.
axis: An integer or a tuple of integers specifying the axis/axes
along which to compute the sum. If `None`, the sum is computed
over all elements. Defaults to `None`.
keepdims: A boolean indicating whether to keep the dimensions of
the input tensor when computing the sum. Defaults to `False`.

Returns:
A tensor containing the logarithm of the sum of exponentials of
elements in `x`.

Example:

>>> x = keras.ops.convert_to_tensor([1., 2., 3.])
>>> logsumexp(x)
3.407606


def add_query(self, query, join_with=AND):

        if not isinstance(query, DomainCondition):
            query = DomainCondition.from_tuple(query)
        if len(self.query):
            self.query.append(join_with)
        self.query.append(query)

Join a new query to existing queries on the stack.

Args:
query (tuple or list or DomainCondition): The condition for the
query. If a ``DomainCondition`` object is not provided, the
input should conform to the interface defined in
:func:`~.domain.DomainCondition.from_tuple`.
join_with (str): The join string to apply, if other queries are
already on the stack.


def get_inventory(self, keys=None):
    inventory = defaultdict(list)
    keys = (keys or ['vm-type', 'groups', 'vm-provider'])
    vms = self.prefix.get_vms().values()
    for vm in vms:
        entry = self._generate_entry(vm)
        vm_spec = vm.spec
        for key in keys:
            value = self.get_key(key, vm_spec)
            if (value is None):
                continue
            if isinstance(value, list):
                for sub_value in value:
                    inventory['{}={}'.format(key, sub_value)].append(entry)
            else:
                inventory['{}={}'.format(key, value)].append(entry)
        for group in vm_spec.get('groups', []):
            inventory[group].append(entry)
    return inventory

Create an Ansible inventory based on python dicts and lists.
The returned value is a dict in which every key represents a group
and every value is a list of entries for that group.

Args:
keys (list of str): Path to the keys that will be used to
create groups.

Returns:
dict: dict based Ansible inventory


def download_url(url, root, filename=None, md5=None):

    from six.moves import urllib

    root = os.path.expanduser(root)
    if not filename:
        filename = os.path.basename(url)
    fpath = os.path.join(root, filename)

    makedir_exist_ok(root)

    if os.path.isfile(fpath) and check_integrity(fpath, md5):
        print('Using downloaded and verified file: ' + fpath)
    else:
        try:
            print('Downloading ' + url + ' to ' + fpath)
            urllib.request.urlretrieve(
                url, fpath,
                reporthook=gen_bar_updater()
            )
        except OSError:
            if url[:5] == 'https':
                url = url.replace('https:', 'http:')
                print('Failed download. Trying https -> http instead.'
                      ' Downloading ' + url + ' to ' + fpath)
                urllib.request.urlretrieve(
                    url, fpath,
                    reporthook=gen_bar_updater()
                )

Download a file from a url and place it in root.

Args:
url (str): URL to download file from
root (str): Directory to place downloaded file in
filename (str, optional): Name to save the file under. If None, use the basename of the URL
md5 (str, optional): MD5 checksum of the download. If None, do not check


def ParseFileObject(self, parser_mediator, file_object):
    if (not self._encoding):
        self._encoding = parser_mediator.codepage
    try:
        if (not self._HasExpectedLineLength(file_object)):
            display_name = parser_mediator.GetDisplayName()
            raise errors.UnableToParseFile('[{0:s}] Unable to parse DSV file: {1:s} with error: unexpected line length.'.format(self.NAME, display_name))
    except UnicodeDecodeError as exception:
        display_name = parser_mediator.GetDisplayName()
        raise errors.UnableToParseFile('[{0:s}] Unable to parse DSV file: {1:s} with error: {2!s}.'.format(self.NAME, display_name, exception))
    try:
        line_reader = self._CreateLineReader(file_object)
        reader = self._CreateDictReader(line_reader)
        row_offset = line_reader.tell()
        row = next(reader)
    except (StopIteration, csv.Error, UnicodeDecodeError) as exception:
        display_name = parser_mediator.GetDisplayName()
        raise errors.UnableToParseFile('[{0:s}] Unable to parse DSV file: {1:s} with error: {2!s}.'.format(self.NAME, display_name, exception))
    number_of_columns = len(self.COLUMNS)
    number_of_records = len(row)
    if (number_of_records != number_of_columns):
        display_name = parser_mediator.GetDisplayName()
        raise errors.UnableToParseFile('[{0:s}] Unable to parse DSV file: {1:s}. Wrong number of records (expected: {2:d}, got: {3:d})'.format(self.NAME, display_name, number_of_columns, number_of_records))
    for (key, value) in row.items():
        if (self._MAGIC_TEST_STRING in (key, value)):
            display_name = parser_mediator.GetDisplayName()
            raise errors.UnableToParseFile('[{0:s}] Unable to parse DSV file: {1:s}. Signature mismatch.'.format(self.NAME, display_name))
    row = self._ConvertRowToUnicode(parser_mediator, row)
    if (not self.VerifyRow(parser_mediator, row)):
        display_name = parser_mediator.GetDisplayName()
        raise errors.UnableToParseFile('[{0:s}] Unable to parse DSV file: {1:s}. Verification failed.'.format(self.NAME, display_name))
    self.ParseRow(parser_mediator, row_offset, row)
    row_offset = line_reader.tell()
    for row in reader:
        if parser_mediator.abort:
            break
        row = self._ConvertRowToUnicode(parser_mediator, row)
        self.ParseRow(parser_mediator, row_offset, row)
        row_offset = line_reader.tell()

Parses a DSV text file-like object.

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

Raises:
UnableToParseFile: when the file cannot be parsed.


def test_pass(self, e=None):
    self._test_end(TestResultEnums.TEST_RESULT_PASS, e)

To mark the test as passed in this record.

Args:
e: An instance of mobly.signals.TestPass.


def angle(self, deg=False):

        if self.dtype.str[1] != 'c':
            warnings.warn('angle() is intended for complex-valued timeseries',
                          RuntimeWarning, 1)
        return Timeseries(np.angle(self, deg=deg), self.tspan, self.labels)

Return the angle of the complex argument.

Args:
deg (bool, optional):
Return angle in degrees if True, radians if False (default).

Returns:
angle (Timeseries):
The counterclockwise angle from the positive real axis on
the complex plane, with dtype as numpy.float64.


def is_valid(self, value):
    try:
        if validation_on():
            self.validate(value, False)
    except ValueError:
        return False
    else:
        return True

Whether the value passes validation

Args:
value (obj) : the value to validate against this property type

Returns:
True if valid, False otherwise


def _html_checker(job_var, interval, status, header, _interval_set=False):
    job_status = job_var.status()
    job_status_name = job_status.name
    job_status_msg = job_status.value
    status.value = (header % job_status_msg)
    while (job_status_name not in ['DONE', 'CANCELLED']):
        time.sleep(interval)
        job_status = job_var.status()
        job_status_name = job_status.name
        job_status_msg = job_status.value
        if (job_status_name == 'ERROR'):
            break
        else:
            if (job_status_name == 'QUEUED'):
                job_status_msg += (' (%s)' % job_var.queue_position())
                if (not _interval_set):
                    interval = max(job_var.queue_position(), 2)
            elif (not _interval_set):
                interval = 2
            status.value = (header % job_status_msg)
    status.value = (header % job_status_msg)

Internal function that updates the status
of a HTML job monitor.

Args:
job_var (BaseJob): The job to keep track of.
interval (int): The status check interval
status (widget): HTML ipywidget for output ot screen
header (str): String representing HTML code for status.
_interval_set (bool): Was interval set by user?


def __init__(self, property_type=TableFeaturePropType.OFPTFPT_NEXT_TABLES,
                 next_table_ids=None):

        super().__init__(property_type)
        self.next_table_ids = (ListOfInstruction() if next_table_ids is None
                               else next_table_ids)
        self.update_length()

Create a NextTablesProperty with the optional parameters below.

Args:
type(|TableFeaturePropType_v0x04|):
Property Type value of this instance.
next_table_ids (|ListOfInstruction_v0x04|):
List of InstructionGotoTable instances.


def lyap_e_len(**kwargs):
    m = ((kwargs['emb_dim'] - 1)
    min_len = kwargs['emb_dim']
    min_len += m
    min_len += (kwargs['min_tsep'] * 2)
    min_len += kwargs['min_nb']
    return min_len

Helper function that calculates the minimum number of data points required
to use lyap_e.

Note that none of the required parameters may be set to None.

Kwargs:
kwargs(dict):
arguments used for lyap_e (required: emb_dim, matrix_dim, min_nb
and min_tsep)

Returns:
minimum number of data points required to call lyap_e with the given
parameters


def _subtoken_to_tokens(self, subtokens):
    concatenated = ''.join(subtokens)
    split = concatenated.split('_')
    return [_unescape_token((t + '_')) for t in split if t]

Converts a list of subtoken to a list of tokens.

Args:
subtokens: a list of integers in the range [0, vocab_size)

Returns:
a list of strings.


def get_heroku_connect_models():
    from django.apps import apps
    apps.check_models_ready()
    from heroku_connect.db.models import HerokuConnectModel
    return (model for models in apps.all_models.values() for model in models.values() if (issubclass(model, HerokuConnectModel) and (not model._meta.managed)))

Return all registered Heroku Connect Models.

Returns:
(Iterator):
All registered models that are subclasses of `.HerokuConnectModel`.
Abstract models are excluded, since they are not registered.


def hamming_distance(str1, str2):

    if len(str1) != len(str2):
        raise VisualizationError('Strings not same length.')
    return sum(s1 != s2 for s1, s2 in zip(str1, str2))

Calculate the Hamming distance between two bit strings

Args:
str1 (str): First string.
str2 (str): Second string.
Returns:
int: Distance between strings.
Raises:
VisualizationError: Strings not same length


def __init__(self, num_classes: int, matcher: OneFormerHungarianMatcher, weight_dict: Dict[str, float], eos_coef: float, num_points: int, oversample_ratio: float, importance_sample_ratio: float, contrastive_temperature: Optional[float]=None):
    requires_backends(self, ['scipy'])
    super().__init__()
    self.num_classes = num_classes
    self.matcher = matcher
    self.weight_dict = weight_dict
    self.eos_coef = eos_coef
    empty_weight = torch.ones(self.num_classes + 1)
    empty_weight[-1] = self.eos_coef
    self.register_buffer('empty_weight', empty_weight)
    self.num_points = num_points
    self.oversample_ratio = oversample_ratio
    self.importance_sample_ratio = importance_sample_ratio
    self.contrastive_temperature = contrastive_temperature
    if self.contrastive_temperature is not None:
        self.logit_scale = nn.Parameter(torch.tensor(np.log(1 / contrastive_temperature)))

This class computes the losses using the class predictions, mask predictions and the contrastive queries.

Oneformer calculates the classification CE loss on the class predictions. Mask predictions are used for
calculating the binary CE loss and dice loss. The contrastive queries are used for calculating the contrastive
loss.

Args:
num_labels (`int`):
The number of classes.
matcher (`OneFormerHungarianMatcher`):
A torch module that computes the assignments between the predictions and labels.
weight_dict (`Dict[str, float]`):
A dictionary of weights to be applied to the different losses.
eos_coef (`float`):
Weight to apply to the null class.
num_points (`int`):
Number of points to be sampled for dice and mask loss calculations.
oversample_ratio (`float`):
Required for pointwise loss calculation.
importance_sample_ratio (`float`):
Required for pointwise loss calculation.
contrastive_temperature (`float`):
Temperature for scaling the contrastive logits.


def list_and_add(a, b):

    if not isinstance(b, list):
        b = [b]
    if not isinstance(a, list):
        a = [a]
    return a + b

Concatenate anything into a list.

Args:
a: the first thing
b: the second thing

Returns:
list. All the things in a list.


def ParseNumericOption(self, options, name, base=10, default_value=None):

    numeric_value = getattr(options, name, None)
    if not numeric_value:
      return default_value

    try:
      return int(numeric_value, base)

    except (TypeError, ValueError):
      name = name.replace('_', ' ')
      raise errors.BadConfigOption(
          'Unsupported numeric value {0:s}: {1!s}.'.format(
              name, numeric_value))

Parses a numeric option.

If the option is not set the default value is returned.

Args:
options (argparse.Namespace): command line arguments.
name (str): name of the numeric option.
base (Optional[int]): base of the numeric value.
default_value (Optional[object]): default value.

Returns:
int: numeric value.

Raises:
BadConfigOption: if the options are invalid.


def swap(self, old_chunks, new_chunk):

    indexes = [self.index(chunk) for chunk in old_chunks]
    del self[indexes[0]:indexes[-1] + 1]
    self.insert(indexes[0], new_chunk)

Swaps old consecutive chunks with new chunk.

Args:
old_chunks (:obj:`budou.chunk.ChunkList`): List of consecutive Chunks to
be removed.
new_chunk (:obj:`budou.chunk.Chunk`): A Chunk to be inserted.


def __init__(self, model_name: str, *, max_seq_length: Optional[int]=None, **kwargs):
    if not SentenceTransformer:
        raise ImportError('sentence-transformers is required to use HuggingfaceTextEmbeddings.Please install it with using `pip install sentence-transformers`.')
    super().__init__(type_adapter=create_rag_adapter(), **kwargs)
    self.model_name = model_name
    self.max_seq_length = max_seq_length
    self.model_class = SentenceTransformer

Utilizes huggingface SentenceTransformer embeddings for RAG pipeline.

Args:
model_name: Name of the sentence-transformers model to use
max_seq_length: Maximum sequence length for the model
**kwargs: Additional arguments passed to
:class:`~apache_beam.ml.transforms.base.EmbeddingsManager`
constructor including ModelHandler arguments


def days_since_last_snowfall(self, value=99):
    if (value is not None):
        try:
            value = int(value)
        except ValueError:
            raise ValueError('value {} need to be of type int for field `days_since_last_snowfall`'.format(value))
    self._days_since_last_snowfall = value

Corresponds to IDD Field `days_since_last_snowfall`

Args:
value (int): value for IDD Field `days_since_last_snowfall`
Missing value: 99
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

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


def retry(func):

    def retried_func(*args, **kwargs):
        max_tries = 3
        tries = 0
        while True:
            try:
                resp = func(*args, **kwargs)

            except requests.exceptions.ConnectionError as exc:
                exc.msg = "Connection error for session; exiting"
                raise exc

            except requests.exceptions.HTTPError as exc:
                exc.msg = "HTTP error for session; exiting"
                raise exc

            if resp.status_code != 200 and tries < max_tries:
                logger.warning("retrying request; current status code: {}"
                               .format(resp.status_code))
                tries += 1

                time.sleep(tries ** 2)
                continue

            break

        if resp.status_code != 200:
            error_message = resp.json()["error"]["message"]
            logger.error("HTTP Error code: {}: {}".format(resp.status_code, error_message))
            logger.error("Rule payload: {}".format(kwargs["rule_payload"]))
            raise requests.exceptions.HTTPError

        return resp

    return retried_func

Decorator to handle API retries and exceptions. Defaults to three retries.

Args:
func (function): function for decoration

Returns:
decorated function


def read_log(self, logfile):
    logfile.seek(0)
    (field_names, _) = self._parse_bro_header(logfile)
    while 1:
        _line = next(logfile).strip()
        if (not _line.startswith('
            (yield self._cast_dict(dict(zip(field_names, _line.split(self.delimiter)))))
        else:
            time.sleep(0.1)
            break

The read_log method returns a memory efficient generator for rows in a Bro log.

Usage:
rows = my_bro_reader.read_log(logfile)
for row in rows:
do something with row

Args:
logfile: The Bro Log file.


def tf_baseline_loss(self, states, internals, reward, update, reference=None):
    if (self.baseline_mode == 'states'):
        loss = self.baseline.loss(states=states, internals=internals, reward=reward, update=update, reference=reference)
    elif (self.baseline_mode == 'network'):
        loss = self.baseline.loss(states=self.network.apply(x=states, internals=internals, update=update), internals=internals, reward=reward, update=update, reference=reference)
    regularization_loss = self.baseline.regularization_loss()
    if (regularization_loss is not None):
        loss += regularization_loss
    return loss

Creates the TensorFlow operations for calculating the baseline loss of a batch.

Args:
states: Dict of state tensors.
internals: List of prior internal state tensors.
reward: Reward tensor.
update: Boolean tensor indicating whether this call happens during an update.
reference: Optional reference tensor(s), in case of a comparative loss.

Returns:
Loss tensor.


def get_nic(access_token, subscription_id, resource_group, nic_name):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Network/networkInterfaces/', nic_name,
                        '?api-version=', NETWORK_API])
    return do_get(endpoint, access_token)

Get details about a network interface.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
nic_name (str): Name of the NIC.

Returns:
HTTP response. NIC JSON body.


def ListChildren(self, urn, limit=None, age=NEWEST_TIME):

    _, children_urns = list(
        self.MultiListChildren([urn], limit=limit, age=age))[0]
    return children_urns

Lists bunch of directories efficiently.

Args:
urn: Urn to list children.
limit: Max number of children to list.
age: The age of the items to retrieve. Should be one of ALL_TIMES,
NEWEST_TIME or a range.

Returns:
RDFURNs instances of each child.


def kms_key_arn(kms_client, alias):

  try:
    response = kms_client.describe_key(KeyId=alias)
    key_arn = response["KeyMetadata"]["Arn"]
  except ClientError as error:
    raise RuntimeError("Failed to obtain key arn for alias {}, error: {}".format(alias, error.response["Error"]["Message"]))

  return key_arn

Obtain the full key arn based on the key alias provided
Args:
kms_client (boto3 kms client object): Instantiated kms client object. Usually created through create_aws_clients.
alias (string): alias of key, example alias/proto0-evs-drm.

Returns:
string of the full key arn


def find_duplicates_in_array(array):

    duplicates = []
    non_duplicates = []

    if len(array) != len(set(array)):
        for item in array:
            if item not in non_duplicates:
                non_duplicates.append(item)
            elif item in non_duplicates and item not in duplicates:
                duplicates.append(item)

    return duplicates

Runs through the array and returns the elements that contain
more than one duplicate

Args:
array: The array to check for duplicates.

Returns:
Array of the elements that are duplicates. Returns empty list if
there are no duplicates.


def _parse_meta_info(self, line):
    if self.mslevel:
        self.meta_info['ms_level'] = self.mslevel
    if self.polarity:
        self.meta_info['polarity'] = self.polarity
    for (k, regexes) in six.iteritems(self.meta_regex):
        for reg in regexes:
            m = re.search(reg, line, re.IGNORECASE)
            if m:
                self.meta_info[k] = m.group(1).strip()

Parse and extract all meta data by looping through the dictionary of meta_info regexs

updates self.meta_info

Args:
line (str): line of the msp file


def add_values_to_bundle_safe(connection, bundle, values):
    for value in values:
        try:
            connection.addValueToBundle(bundle, value)
        except YouTrackException as e:
            if (e.response.status == 409):
                print(('Value with name [ %s ] already exists in bundle [ %s ]' % (utf8encode(value.name), utf8encode(bundle.name))))
            else:
                raise e

Adds values to specified bundle. Checks, whether each value already contains in bundle. If yes, it is not added.

Args:
connection: An opened Connection instance.
bundle: Bundle instance to add values in.
values: Values, that should be added in bundle.

Raises:
YouTrackException: if something is wrong with queries.


def check(self, dsm, independence_factor=5, **kwargs):

        least_common_mechanism = False
        message = ''

        data = dsm.data
        categories = dsm.categories
        dsm_size = dsm.size[0]

        if not categories:
            categories = ['appmodule'] * dsm_size

        dependent_module_number = []

        for j in range(0, dsm_size):
            dependent_module_number.append(0)
            for i in range(0, dsm_size):
                if (categories[i] != 'framework' and
                        categories[j] != 'framework' and
                        data[i][j] > 0):
                    dependent_module_number[j] += 1

        for index, item in enumerate(dsm.categories):
            if item == 'broker' or item == 'applib':
                dependent_module_number[index] = 0
        if max(dependent_module_number) <= dsm_size / independence_factor:
            least_common_mechanism = True
        else:
            maximum = max(dependent_module_number)
            message = (
                'Dependencies to %s (%s) > matrix size (%s) / '
                'independence factor (%s) = %s' % (
                    dsm.entities[dependent_module_number.index(maximum)],
                    maximum, dsm_size, independence_factor,
                    dsm_size / independence_factor))

        return least_common_mechanism, message

Check least common mechanism.

Args:
dsm (:class:`DesignStructureMatrix`): the DSM to check.
independence_factor (int): if the maximum dependencies for one
module is inferior or equal to the DSM size divided by the
independence factor, then this criterion is verified.

Returns:
bool: True if least common mechanism, else False


def __init__(self, channel):

        self.CreateCompany = channel.unary_unary(
            "/google.cloud.talent.v4beta1.CompanyService/CreateCompany",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__service__pb2.CreateCompanyRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__pb2.Company.FromString,
        )
        self.GetCompany = channel.unary_unary(
            "/google.cloud.talent.v4beta1.CompanyService/GetCompany",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__service__pb2.GetCompanyRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__pb2.Company.FromString,
        )
        self.UpdateCompany = channel.unary_unary(
            "/google.cloud.talent.v4beta1.CompanyService/UpdateCompany",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__service__pb2.UpdateCompanyRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__pb2.Company.FromString,
        )
        self.DeleteCompany = channel.unary_unary(
            "/google.cloud.talent.v4beta1.CompanyService/DeleteCompany",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__service__pb2.DeleteCompanyRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
        self.ListCompanies = channel.unary_unary(
            "/google.cloud.talent.v4beta1.CompanyService/ListCompanies",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__service__pb2.ListCompaniesRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__service__pb2.ListCompaniesResponse.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def set_configuration_from_input_tensors(self, input_tensors):
    if len(input_tensors) != self.number_of_tuple_elements:
        raise ValueError(f'input_tensors is {str(input_tensors)}, but should be a list of {self.number_of_tuple_elements} Tensors')
    self.set_tuple_shapes([t.shape for t in input_tensors])
    self.set_tuple_types([t.dtype for t in input_tensors])

Sets the shapes and types of the queue tuple elements.

input_tensors is a list of Tensors whose types and shapes are used
to set the queue configuration.

Args:
input_tensors: list of Tensors of the same types and shapes as
the desired queue Tuple.

Raises:
ValueError: if input_tensors is not a list of length
self.number_of_tuple_elements


def _get_create_query(partition, tablename, include=None):

        TYPE_MAP = {
            'int': 'INTEGER',
            'float': 'REAL',
            six.binary_type.__name__: 'TEXT',
            six.text_type.__name__: 'TEXT',
            'date': 'DATE',
            'datetime': 'TIMESTAMP WITHOUT TIME ZONE'
        }
        columns_types = []
        if not include:
            include = []
        for column in sorted(partition.datafile.reader.columns, key=lambda x: x['pos']):
            if include and column['name'] not in include:
                continue
            sqlite_type = TYPE_MAP.get(column['type'])
            if not sqlite_type:
                raise Exception('Do not know how to convert {} to sql column.'.format(column['type']))
            columns_types.append('    "{}" {}'.format(column['name'], sqlite_type))
        columns_types_str = ',\n'.join(columns_types)
        query = 'CREATE TABLE IF NOT EXISTS {}(\n{})'.format(tablename, columns_types_str)
        return query

Creates and returns `CREATE TABLE ...` sql statement for given mprows.

Args:
partition (orm.Partition):
tablename (str): name of the table in the return create query.
include (list of str, optional): list of columns to include to query.

Returns:
str: create table query.


def site_coordination_numbers( self ):

        coordination_numbers = {}
        for l in self.site_labels:
            coordination_numbers[ l ] = set( [ len( site.neighbours ) for site in self.sites if site.label is l ] )
        return coordination_numbers

Returns a dictionary of the coordination numbers for each site label. e.g.::

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

Args:
none

Returns:
coordination_numbers (Dict(Str:Set(Int))): dictionary of coordination
numbers for each site label.


def make_subdivision_matrices(degree):
    left = np.zeros(((degree + 1), (degree + 1)), order='F')
    right = np.zeros(((degree + 1), (degree + 1)), order='F')
    left[(0, 0)] = 1.0
    right[((- 1), (- 1))] = 1.0
    for col in six.moves.xrange(1, (degree + 1)):
        half_prev = (0.5 * left[(:col, (col - 1))])
        left[(:col, col)] = half_prev
        left[(1:(col + 1), col)] += half_prev
        complement = (degree - col)
        right[((- (col + 1)):, complement)] = left[(:(col + 1), col)]
    return (left, right)

Make the matrix used to subdivide a curve.

.. note::

This is a helper for :func:`_subdivide_nodes`. It does not have a
Fortran speedup because it is **only** used by a function which has
a Fortran speedup.

Args:
degree (int): The degree of the curve.

Returns:
Tuple[numpy.ndarray, numpy.ndarray]: The matrices used to convert
the nodes into left and right nodes, respectively.


def register_rml_def(self, location_type, location, filename=None, **kwargs):
    if (location_type == 'directory'):
        self.register_directory(location, **kwargs)
    elif (location_type == 'filepath'):
        if (not os.path.exists(location)):
            raise OSError('File not found', location)
        if os.path.isfile(location):
            self.register_rml(location)
        elif filename:
            new_loc = os.path.join(location, filename)
            if (not os.path.exists(new_loc)):
                raise OSError('File not found', new_loc)
            elif os.path.isfile(new_loc):
                self.register_rml(new_loc)
        else:
            raise OSError('File not found', location)
    elif location_type.startswith('package'):
        pkg_path = importlib.util.find_spec(location).submodule_search_locations[0]
        if location_type.endswith('_all'):
            self.register_directory(pkg_path, **kwargs)
        elif location_type.endswith('_file'):
            filepath = os.path.join(pkg_path, filename)
            self.register_rml(filepath, **kwargs)
        else:
            raise NotImplementedError

Registers the rml file locations for easy access

Args:
-----
location_type: ['package_all',
'package_file',
'directory',
'filepath']
location: The correlated location string based on the location_type
filename: Optional, associated with 'package_file' location_type

kwargs:
-------
include_subfolders: Boolean


def BuildTypeDescriptor(self, value_cls):
    result = ApiRDFValueDescriptor(name=value_cls.__name__, parents=[klass.__name__ for klass in value_cls.__mro__], doc=(value_cls.__doc__ or ''), kind='PRIMITIVE')
    result.default = self.BuildDefaultValue(value_cls)
    return result

Renders metadata of a given value class.

Args:
value_cls: Metadata of this class will be rendered. This class has to be
(or to be a subclass of) a self.value_class (i.e. a class that this
renderer is capable of rendering).

Returns:
Dictionary with class metadata.


def get_container_service(access_token, subscription_id, resource_group, service_name):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourcegroups/', resource_group, '/providers/Microsoft.ContainerService/ContainerServices/', service_name, '?api-version=', ACS_API])
    return do_get(endpoint, access_token)

Get details about an Azure Container Server

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
service_name (str): Name of container service.

Returns:
HTTP response. JSON model.


def _resource_capture_helper(self, tensor):
    assert tensor.dtype == dtypes.resource
    forward_graph_input_names = [t.name for t in self._forward_graph.inputs]
    forward_graph_name_to_opdef = {op.name: op.node_def for op in self._forward_graph.get_operations()}
    index = util.resource_input_index(tensor.name, forward_graph_input_names, forward_graph_name_to_opdef, self._forward_graph._functions)
    input_placeholder = self._forward_graph.inputs[index]
    tensor_in_outer_graph = self._forward_graph._while.inputs[index]
    assert input_placeholder.dtype == dtypes.resource
    assert tensor_in_outer_graph.dtype == dtypes.resource
    if index != util.resource_input_index(self._forward_graph.outputs[index].name, forward_graph_input_names, forward_graph_name_to_opdef, self._forward_graph._functions):
        raise AssertionError(f'Resource tensors must be loop invariants {tensor_in_outer_graph}')
    self._indirect_captures[ops.tensor_id(tensor)] = self.capture(tensor_in_outer_graph)
    return self._indirect_captures[ops.tensor_id(tensor)]

Returns the captured resource tensor.

Resource-type tensors are not accumulated. If a resource tensor exists in
the loop body it must either be a loop input or an output of a nested While
op inside the loop body which had captured the external resource.

Args:
tensor: the external resource Tensor to be captured.

Returns:
Tensor in this graph.


def cancelOrder(self, order: Order) -> Trade:

        self.client.cancelOrder(order.orderId)
        now = datetime.datetime.now(datetime.timezone.utc)
        key = self.wrapper.orderKey(
            order.clientId, order.orderId, order.permId)
        trade = self.wrapper.trades.get(key)
        if trade:
            if not trade.isDone():
                status = trade.orderStatus.status
                if (status == OrderStatus.PendingSubmit and not order.transmit
                        or status == OrderStatus.Inactive):
                    newStatus = OrderStatus.Cancelled
                else:
                    newStatus = OrderStatus.PendingCancel
                logEntry = TradeLogEntry(now, newStatus, '')
                trade.log.append(logEntry)
                trade.orderStatus.status = newStatus
                self._logger.info(f'cancelOrder: {trade}')
                trade.cancelEvent.emit(trade)
                trade.statusEvent.emit(trade)
                self.cancelOrderEvent.emit(trade)
                self.orderStatusEvent.emit(trade)
                if newStatus == OrderStatus.Cancelled:
                    trade.cancelledEvent.emit(trade)
        else:
            self._logger.error(f'cancelOrder: Unknown orderId {order.orderId}')
        return trade

Cancel the order and return the Trade it belongs to.

Args:
order: The order to be canceled.


def document(self, document_id=None):
    if (document_id is None):
        document_id = _auto_id()
    child_path = (self._path + (document_id,))
    return self._client.document(*child_path)

Create a sub-document underneath the current collection.

Args:
document_id (Optional[str]): The document identifier
within the current collection. If not provided, will default
to a random 20 character string composed of digits,
uppercase and lowercase and letters.

Returns:
~.firestore_v1beta1.document.DocumentReference: The child
document.


def get_ytvideos(query, ilogger):
    queue = []
    search_result = ytdiscoveryapi.search().list(q=query, part='id,snippet', maxResults=1, type='video,playlist').execute()
    if (not search_result['items']):
        return []
    title = search_result['items'][0]['snippet']['title']
    ilogger.info('Queueing {}'.format(title))
    if (search_result['items'][0]['id']['kind'] == 'youtube
        videoid = search_result['items'][0]['id']['videoId']
        queue.append(['https:
    elif (search_result['items'][0]['id']['kind'] == 'youtube
        queue = get_queue_from_playlist(search_result['items'][0]['id']['playlistId'])
    return queue

Gets either a list of videos from a playlist or a single video, using the
first result of a YouTube search

Args:
query (str): The YouTube search query
ilogger (logging.logger): The logger to log API calls to

Returns:
queue (list): The items obtained from the YouTube search


def from_deformation(cls, deformation):
    dfm = Deformation(deformation)
    return cls((0.5 * (np.dot(dfm.trans, dfm) - np.eye(3))))

Factory method that returns a Strain object from a deformation
gradient

Args:
deformation (3x3 array-like):


def fit(self, X, y):

        self._word_vocab.add_documents(X)
        self._label_vocab.add_documents(y)
        if self._use_char:
            for doc in X:
                self._char_vocab.add_documents(doc)

        self._word_vocab.build()
        self._char_vocab.build()
        self._label_vocab.build()

        return self

Learn vocabulary from training set.

Args:
X : iterable. An iterable which yields either str, unicode or file objects.

Returns:
self : IndexTransformer.


def to_obj(self, ns_info=None):
    if ns_info:
        ns_info.collect(self)
    if (not hasattr(self, '_binding_class')):
        return None
    entity_obj = self._binding_class()
    for (field, val) in six.iteritems(self._fields):
        if (isinstance(val, EntityList) and (len(val) == 0)):
            val = None
        elif field.multiple:
            if val:
                val = [_objectify(field, x, ns_info) for x in val]
            else:
                val = []
        else:
            val = _objectify(field, val, ns_info)
        setattr(entity_obj, field.name, val)
    self._finalize_obj(entity_obj)
    return entity_obj

Convert to a GenerateDS binding object.

Subclasses can override this function.

Returns:
An instance of this Entity's ``_binding_class`` with properties
set from this Entity.


def __use_cache__(self, cache):

        try:
            cache_mod = os.path.getmtime(self.cache_filepath)
        except FileNotFoundError:
            return False
        last_file_mod = sorted( \
                self.conn.mgr.loaded_times.values())[-1].timestamp()
        if last_file_mod > cache_mod:
            return False
        curr_load = set(self.conn.mgr.loaded)

        try:
            with open(self.loaded_filepath, "r") as fo:
                loaded_files = set(json.loads(fo.read()))
            if curr_load != loaded_files:
                return False
        except FileNotFoundError:
            return False

        return cache

checks for changes in the vocabulary and mod times of the files
to see if the cache should be used.

Args:
cache: the kwarg passed in to use the cache during __init__

Returns:
Bool: True = use the cache files
False = requery the triplestore


def _example_from_definition(self, prop_spec):
    definition_name = self.get_definition_name_from_ref(prop_spec['$ref'])
    if self.build_one_definition_example(definition_name):
        example_dict = self.definitions_example[definition_name]
        if (not isinstance(example_dict, dict)):
            return example_dict
        example = dict(((example_name, example_value) for (example_name, example_value) in example_dict.items()))
        return example

Get an example from a property specification linked to a definition.

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

Returns:
An example.


def _make_cluster_def(self):
    self._cluster_def = cluster_pb2.ClusterDef()
    for job_name, tasks in sorted(self._cluster_spec.items()):
        try:
            job_name = compat.as_bytes(job_name)
        except TypeError:
            raise TypeError('Job name %r must be bytes or unicode' % job_name)
        job_def = self._cluster_def.job.add()
        job_def.name = job_name
        for i, task_address in sorted(tasks.items()):
            try:
                task_address = compat.as_bytes(task_address)
            except TypeError:
                raise TypeError('Task address %r must be bytes or unicode' % task_address)
            job_def.tasks[i] = task_address

Creates a `tf.train.ClusterDef` based on the given `cluster_spec`.

Raises:
TypeError: If `cluster_spec` is not a dictionary mapping strings to lists
of strings.


def from_json_file(cls, json_file: Union[str, os.PathLike]):
    with open(json_file, encoding='utf-8') as reader:
        text = reader.read()
    image_processor_dict = json.loads(text)
    return cls(**image_processor_dict)

Instantiates a image processor of type [`~image_processing_utils.ImageProcessingMixin`] from the path to a JSON
file of parameters.

Args:
json_file (`str` or `os.PathLike`):
Path to the JSON file containing the parameters.

Returns:
A image processor of type [`~image_processing_utils.ImageProcessingMixin`]: The image_processor object
instantiated from that JSON file.


def _get_addresses(tx):

        from_address = set([vin['address'] for vin in tx['vins']])
        if len(from_address) != 1:
            raise InvalidTransactionError("Transaction should have inputs " \
                                          "from only one address {}".format(from_address))

        vouts = sorted(tx['vouts'], key=lambda d: d['n'])[:-1]
        piece_address = vouts[0]['address']
        to_address = vouts[-1]['address']
        from_address = from_address.pop()

        return from_address, to_address, piece_address

Checks for the from, to, and piece address of a SPOOL transaction.

Args:
tx (dict): Transaction payload, as returned by
:meth:`transactions.Transactions.get()`.

.. note:: Formats as returned by JSON-RPC API
``decoderawtransaction`` have yet to be supported.

Returns:
Tuple([str]): Sender, receiver, and piece addresses.


def _cleanup_workflow(config, task_id, args, **kwargs):
    from lightflow.models import Workflow
    if isinstance(args[0], Workflow):
        if (config.celery['result_expires'] == 0):
            AsyncResult(task_id).forget()

Cleanup the results of a workflow when it finished.

Connects to the postrun signal of Celery. If the signal was sent by a workflow,
remove the result from the result backend.

Args:
task_id (str): The id of the task.
args (tuple): The arguments the task was started with.
**kwargs: Keyword arguments from the hook.


def placeholder_symbol_table(name, version, max_id):
    if (version <= 0):
        raise ValueError(('Version must be grater than or equal to 1: %s' % version))
    if (max_id < 0):
        raise ValueError(('Max ID must be zero or positive: %s' % max_id))
    return SymbolTable(table_type=SHARED_TABLE_TYPE, symbols=repeat(None, max_id), name=name, version=version, is_substitute=True)

Constructs a shared symbol table that consists symbols that all have no known text.

This is generally used for cases where a shared symbol table is not available by the
application.

Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol table.
max_id (int): The maximum ID allocated by this symbol table, must be ``>= 0``

Returns:
SymbolTable: The synthesized table.


def edgelist_to_adjacency(edgelist):
    adjacency = dict()
    for (u, v) in edgelist:
        if (u in adjacency):
            adjacency[u].add(v)
        else:
            adjacency[u] = {v}
        if (v in adjacency):
            adjacency[v].add(u)
        else:
            adjacency[v] = {u}
    return adjacency

Converts an iterator of edges to an adjacency dict.

Args:
edgelist (iterable):
An iterator over 2-tuples where each 2-tuple is an edge.

Returns:
dict: The adjacency dict. A dict of the form {v: Nv, ...} where v is a node in a graph and
Nv is the neighbors of v as an set.


def __init__(self, service):

        if not isinstance(service, sm_messages.Service):
            raise ValueError(u'service should be an instance of Service')
        if not service.name:
            raise ValueError(u'Bad service: the name is missing')

        self._service = service
        self._extracted_methods = {}

        self._auth_infos = self._extract_auth_config()
        self._quota_infos = self._extract_quota_config()

        self._templates_method_infos = collections.defaultdict(list)
        self._extract_methods()

Constructor.

Args:
service (:class:`endpoints_management.gen.servicemanagement_v1_messages.Service`):
a service instance


def inference(cluster_info, feed_timeout=600, qname='input'):

    def _inference(iter):
        mgr = _get_manager(cluster_info, util.get_ip_address(), util.read_executor_id())
        try:
            queue_in = mgr.get_queue(qname)
            equeue = mgr.get_queue('error')
        except (AttributeError, KeyError):
            msg = "Queue '{}' not found on this node, check for exceptions on other nodes.".format(qname)
            raise Exception(msg)
        logging.info('Feeding partition {0} into {1} queue {2}'.format(iter, qname, queue_in))
        count = 0
        for item in iter:
            count += 1
            queue_in.put(item, block=True)
        queue_in.put(marker.EndPartition())
        if (count == 0):
            return []
        joinThr = Thread(target=queue_in.join)
        joinThr.start()
        timeout = feed_timeout
        while joinThr.isAlive():
            if (not equeue.empty()):
                e_str = equeue.get()
                equeue.task_done()
                raise Exception(('exception in worker:\n' + e_str))
            time.sleep(1)
            timeout -= 1
            if (timeout <= 0):
                raise Exception('Timeout while feeding partition')
        logging.info('Processed {0} items in partition'.format(count))
        results = []
        queue_out = mgr.get_queue('output')
        while (count > 0):
            result = queue_out.get(block=True)
            results.append(result)
            count -= 1
            queue_out.task_done()
        logging.info('Finished processing partition')
        return results
    return _inference

Feeds Spark partitions into the shared multiprocessing.Queue and returns inference results.

Args:
:cluster_info: node reservation information for the cluster (e.g. host, executor_id, pid, ports, etc)
:feed_timeout: number of seconds after which data feeding times out (600 sec default)
:qname: *INTERNAL_USE*

Returns:
A dataRDD.mapPartitions() function


def load_exons(adapter, exon_lines, build='37', ensembl_genes=None):

    ensembl_genes = ensembl_genes or adapter.ensembl_genes(build)
    hgnc_id_transcripts = adapter.id_transcripts_by_gene(build=build)

    if isinstance(exon_lines, DataFrame):
        exons = parse_ensembl_exon_request(exon_lines)
        nr_exons = exon_lines.shape[0]
    else:
        exons = parse_ensembl_exons(exon_lines)
        nr_exons = 1000000

    start_insertion = datetime.now()
    loaded_exons = 0
    LOG.info("Loading exons...")
    with progressbar(exons, label="Loading exons", length=nr_exons) as bar:
        for exon in bar:
            ensg_id = exon['gene']
            enst_id = exon['transcript']
            gene_obj = ensembl_genes.get(ensg_id)

            if not gene_obj:
                continue

            hgnc_id = gene_obj['hgnc_id']

            if not enst_id in hgnc_id_transcripts[hgnc_id]:
                continue

            exon['hgnc_id'] = hgnc_id

            exon_obj = build_exon(exon, build)
            adapter.load_exon(exon_obj)
            loaded_exons += 1

    LOG.info('Number of exons in build {0}: {1}'.format(build, nr_exons))
    LOG.info('Number loaded: {0}'.format(loaded_exons))
    LOG.info('Time to load exons: {0}'.format(datetime.now() - start_insertion))

Load all the exons

Transcript information is from ensembl.
Check that the transcript that the exon belongs to exists in the database

Args:
adapter(MongoAdapter)
exon_lines(iterable): iterable with ensembl exon lines
build(str)
ensembl_transcripts(dict): Existing ensembl transcripts


def parse_args(args):

    parser = argparse.ArgumentParser(
        description="Imports GramVaani data for Deep Speech"
    )
    parser.add_argument(
        "--version",
        action="version",
        version="GramVaaniImporter {ver}".format(ver=__version__),
    )
    parser.add_argument(
        "-v",
        "--verbose",
        action="store_const",
        required=False,
        help="set loglevel to INFO",
        dest="loglevel",
        const=logging.INFO,
    )
    parser.add_argument(
        "-vv",
        "--very-verbose",
        action="store_const",
        required=False,
        help="set loglevel to DEBUG",
        dest="loglevel",
        const=logging.DEBUG,
    )
    parser.add_argument(
        "-c",
        "--csv_filename",
        required=True,
        help="Path to the GramVaani csv",
        dest="csv_filename",
    )
    parser.add_argument(
        "-t",
        "--target_dir",
        required=True,
        help="Directory in which to save the importer GramVaani data",
        dest="target_dir",
    )
    return parser.parse_args(args)

Parse command line parameters
Args:
args ([str]): Command line parameters as list of strings
Returns:
:obj:`argparse.Namespace`: command line parameters namespace


def _sync_to_uri(self, uri):

        cmd_cp = 'aws s3 cp {} {} --recursive --profile {}'.format(self.s3_version_uri, uri, self.env)

        cmd_sync = 'aws s3 sync {} {} --delete --exact-timestamps --profile {}'.format(
            self.s3_version_uri, uri, self.env)

        cp_result = subprocess.run(cmd_cp, check=True, shell=True, stdout=subprocess.PIPE)
        LOG.debug("Copy to %s before sync output: %s", uri, cp_result.stdout)
        LOG.info("Copied version %s to %s", self.version, uri)

        sync_result = subprocess.run(cmd_sync, check=True, shell=True, stdout=subprocess.PIPE)
        LOG.debug("Sync to %s command output: %s", uri, sync_result.stdout)
        LOG.info("Synced version %s to %s", self.version, uri)

Copy and sync versioned directory to uri in S3.

Args:
uri (str): S3 URI to sync version to.


def add_timeout_arg(a_func, timeout, **kwargs):

    def inner(*args):

        updated_args = args + (timeout,)
        return a_func(*updated_args, **kwargs)

    return inner

Updates a_func so that it gets called with the timeout as its final arg.

This converts a callable, a_func, into another callable with an additional
positional arg.

Args:
a_func (callable): a callable to be updated
timeout (int): to be added to the original callable as it final positional
arg.
kwargs: Addtional arguments passed through to the callable.

Returns:
callable: the original callable updated to the timeout arg


def __init__(self, object_type: str, subscriber: str,
                 callback_handler: Callable = None):

        self._queue = DB.pub_sub()
        if callback_handler is None:
            self._queue.subscribe(object_type)
        else:
            self._queue.subscribe(**{object_type: callback_handler})
        self._pub_key = _keys.published(object_type, subscriber)
        self._data_key = _keys.data(object_type, subscriber)
        self._processed_key = _keys.processed_events(object_type, subscriber)
        self._object_type = object_type
        self._subscriber = subscriber

Initialise the event queue.

Subscribes to Redis pub/sub events of the given object type.

Args:
object_type (str): Object type
subscriber (str): Subscriber name


def __init__(self, env, directory, collect_freq=1, flush_freq=100):

        super().__init__(env)

        self.directory = directory

        self.states = []
        self.action_infos = []

        self.collect_freq = collect_freq

        self.flush_freq = flush_freq

        if not os.path.exists(directory):
            print("DataCollectionWrapper: making new directory at {}".format(directory))
            os.makedirs(directory)

        self.ep_directory = None

        self.has_interaction = False

Initializes the data collection wrapper.

Args:
env: The environment to monitor.
directory: Where to store collected data.
collect_freq: How often to save simulation state, in terms of environment steps.
flush_freq: How frequently to dump data to disk, in terms of environment steps.


def objects_copy(self, source_bucket, source_key, target_bucket, target_key):

    url = Api._ENDPOINT + (Api._OBJECT_COPY_PATH % (source_bucket, Api._escape_key(source_key),
                                                    target_bucket, Api._escape_key(target_key)))
    return datalab.utils.Http.request(url, method='POST', credentials=self._credentials)

Updates the metadata associated with an object.

Args:
source_bucket: the name of the bucket containing the source object.
source_key: the key of the source object being copied.
target_bucket: the name of the bucket that will contain the copied object.
target_key: the key of the copied object.
Returns:
A parsed object information dictionary.
Raises:
Exception if there is an error performing the operation.


def RemoveObject(self, identifier):

    if identifier not in self._values:
      raise KeyError('Missing cached object for identifier: {0:s}'.format(
          identifier))

    del self._values[identifier]

Removes a cached object based on the identifier.

This method ignores the cache value reference count.

Args:
identifier (str): VFS object identifier.

Raises:
KeyError: if the VFS object is not found in the cache.


def SetActiveBreakpoints(self, breakpoints_data):

    with self._lock:
      ids = set([x['id'] for x in breakpoints_data])

      for breakpoint_id in six.viewkeys(self._active) - ids:
        self._active.pop(breakpoint_id).Clear()

      self._active.update([
          (x['id'],
           python_breakpoint.PythonBreakpoint(
               x,
               self._hub_client,
               self,
               self.data_visibility_policy))
          for x in breakpoints_data
          if x['id'] in ids - six.viewkeys(self._active) - self._completed])

      self._completed &= ids

      if self._active:
        self._next_expiration = datetime.min
      else:
        self._next_expiration = datetime.max

Adds new breakpoints and removes missing ones.

Args:
breakpoints_data: updated list of active breakpoints.


def update_remote_archive(self, save_uri, timeout=(- 1)):
    return self._client.update_with_zero_body(uri=save_uri, timeout=timeout)

Saves a backup of the appliance to a previously-configured remote location.

Args:
save_uri (dict): The URI for saving the backup to a previously configured location.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView, just stop waiting for its completion.

Returns:
dict: Backup details.


def to_hg_scheme_url(cls, url):

        regexes = cls._get_url_scheme_regexes()
        for scheme_key, pattern, regex in regexes:
            match = regex.match(url)
            if match is not None:
                groups = match.groups()
                if len(groups) == 2:
                    return u''.join(
                        scheme_key,
                        ':
                        pattern.replace('{1}', groups[0]),
                        groups[1])
                elif len(groups) == 1:
                    return u''.join(
                        scheme_key,
                        ':
                        pattern,
                        groups[0])

Convert a URL to local mercurial URL schemes

Args:
url (str): URL to map to local mercurial URL schemes

example::

# schemes.gh = git://github.com/
>> remote_url = git://github.com/westurner/dotfiles'
>> to_hg_scheme_url(remote_url)
<< gh://westurner/dotfiles