def _check_callback(callback):

    if inspect.isclass(callback):
        callback_object = callback()
        if not callable(callback_object):
            raise ValueError(
                "Callback must be a class that implements __call__ or a function."
            )
    elif callable(callback):
        callback_object = callback
    else:
        raise ValueError(
            "Callback must be a class that implements __call__ or a function."
        )

    return callback_object

Turns a callback that is potentially a class into a callable object.

Args:
callback (object): An object that might be a class, method, or function.
if the object is a class, this creates an instance of it.

Raises:
ValueError: If an instance can't be created or it isn't a callable object.
TypeError: If the class requires arguments to be instantiated.

Returns:
callable: A callable object suitable for use as the consumer callback.


def main(self, ignored_argv=('',)):
    self._install_signal_handler(signal.SIGTERM, 'SIGTERM')
    if self.flags.inspect:
        logger.info('Not bringing up TensorBoard, but inspecting event files.')
        event_file = os.path.expanduser(self.flags.event_file)
        efi.inspect(self.flags.logdir, event_file, self.flags.tag)
        return 0
    if self.flags.version_tb:
        print(version.VERSION)
        return 0
    try:
        server = self._make_server()
        sys.stderr.write(('TensorBoard %s at %s (Press CTRL+C to quit)\n' % (version.VERSION, server.get_url())))
        sys.stderr.flush()
        self._register_info(server)
        server.serve_forever()
        return 0
    except TensorBoardServerException as e:
        logger.error(e.msg)
        sys.stderr.write(('ERROR: %s\n' % e.msg))
        sys.stderr.flush()
        return (- 1)

Blocking main function for TensorBoard.

This method is called by `tensorboard.main.run_main`, which is the
standard entrypoint for the tensorboard command line program. The
configure() method must be called first.

Args:
ignored_argv: Do not pass. Required for Abseil compatibility.

Returns:
Process exit code, i.e. 0 if successful or non-zero on failure. In
practice, an exception will most likely be raised instead of
returning non-zero.

:rtype: int


def _check_remote_command(self, destination, timeout_ms, success_msgs=None):
    timeout = timeouts.PolledTimeout.from_millis(timeout_ms)
    stream = self._adb_connection.open_stream(destination, timeout)
    if (not stream):
        raise usb_exceptions.AdbStreamUnavailableError('Service %s not supported', destination)
    try:
        message = stream.read(timeout_ms=timeout)
        if any([(m in message) for m in success_msgs]):
            return
    except usb_exceptions.CommonUsbError:
        if destination.startswith('reboot:'):
            return
        raise
    raise usb_exceptions.AdbRemoteError('Device message: %s', message)

Open a stream to destination, check for remote errors.

Used for reboot, remount, and root services.  If this method returns, the
command was successful, otherwise an appropriate error will have been
raised.

Args:
destination: Stream destination to open.
timeout_ms: Timeout in milliseconds for the operation.
success_msgs: If provided, a list of messages that, if returned from the
device, indicate success, so don't treat them as errors.

Raises:
AdbRemoteError: If the remote command fails, will contain any message we
got back from the device.
AdbStreamUnavailableError: The service requested isn't supported.


def add_newlines(f, output, char):

    line_count = get_line_count(f)
    f = open(f, 'r+')
    output = open(output, 'r+')
    for line in range(line_count):
        string = f.readline()
        string = re.sub(char, char + '\n', string)
        output.write(string)

Adds line breaks after every occurance of a given character in a file.

Args:
f: string, path to input file.

output: string, path to output file.

Returns:
None.


def decode_conjure_bean_type(cls, obj, conjure_type):

        deserialized = {}
        for (python_arg_name, field_definition) \
                in conjure_type._fields().items():
            field_identifier = field_definition.identifier

            if field_identifier not in obj or obj[field_identifier] is None:
                cls.check_null_field(
                    obj, deserialized, python_arg_name, field_definition)
            else:
                value = obj[field_identifier]
                field_type = field_definition.field_type
                deserialized[python_arg_name] = \
                    cls.do_decode(value, field_type)
        return conjure_type(**deserialized)

Decodes json into a conjure bean type (a plain bean, not enum
or union).

Args:
obj: the json object to decode
conjure_type: a class object which is the bean type
we're decoding into
Returns:
A instance of a bean of type conjure_type.


def _extract_from(raw_json, pandas_options=None):
    data_frames = []
    if (pandas_options is None):
        pandas_options = {}
    columns = pandas_options.pop('columns', None)
    (columns, header_line_number) = _convert_pandas_csv_options(pandas_options, columns)
    for table in raw_json:
        list_data = [[(np.nan if (not e['text']) else e['text']) for e in row] for row in table['data']]
        _columns = columns
        if (isinstance(header_line_number, int) and (not columns)):
            _columns = list_data.pop(header_line_number)
            _columns = [('' if (e is np.nan) else e) for e in _columns]
        data_frames.append(pd.DataFrame(data=list_data, columns=_columns, **pandas_options))
    return data_frames

Extract tables from json.

Args:
raw_json (list):
Decoded list from tabula-java JSON.
pandas_options (dict optional):
pandas options for `pd.DataFrame()`


def create_atomic_observe_operations(self, states, actions, internals, terminal, reward, index):
    num_episodes = tf.count_nonzero(input_tensor=terminal, dtype=util.tf_dtype('int'))
    increment_episode = tf.assign_add(ref=self.episode, value=tf.to_int64(x=num_episodes))
    increment_global_episode = tf.assign_add(ref=self.global_episode, value=tf.to_int64(x=num_episodes))
    with tf.control_dependencies(control_inputs=(increment_episode, increment_global_episode)):
        states = util.map_tensors(fn=tf.stop_gradient, tensors=states)
        internals = util.map_tensors(fn=tf.stop_gradient, tensors=internals)
        actions = util.map_tensors(fn=tf.stop_gradient, tensors=actions)
        terminal = tf.stop_gradient(input=terminal)
        reward = tf.stop_gradient(input=reward)
        observation = self.fn_observe_timestep(states=states, internals=internals, actions=actions, terminal=terminal, reward=reward)
    with tf.control_dependencies(control_inputs=(observation,)):
        self.unbuffered_episode_output = (self.global_episode + 0)

Returns the tf op to fetch when unbuffered observations are passed in.

Args:
states (any): One state (usually a value tuple) or dict of states if multiple states are expected.
actions (any): One action (usually a value tuple) or dict of states if multiple actions are expected.
internals (any): Internal list.
terminal (bool): boolean indicating if the episode terminated after the observation.
reward (float): scalar reward that resulted from executing the action.

Returns: Tf op to fetch when `observe()` is called.


def set_of_vars(arg_plot):

    return set(var for var in arg_plot.split(',') if var in phyvars.PLATES)

Build set of needed variables.

Args:
arg_plot (str): string with variable names separated with ``,``.
Returns:
set of str: set of variables.


def set_value_at_field(msg: message.Message, field: Union[descriptor.FieldDescriptor, str], value: Any):
    if isinstance(field, str):
        field = _field_descriptor_for_name(msg, field)
    if field_is_repeated(field):
        if field_is_primitive(field):
            getattr(msg, field.name)[:] = value
        else:
            del getattr(msg, field.name)[:]
            getattr(msg, field.name).extend(value)
    elif field_is_primitive(field):
        setattr(msg, field.name, value)
    else:
        getattr(msg, field.name).CopyFrom(value)

Sets value at the field.

Args:
msg: The message whose field to mutate.
field: The FieldDescriptor or name of the field to mutate.
value: The value to set.


def __generate_object_term__(self, datatype, value):

        if datatype == NS_MGR.xsd.anyURI.rdflib:
            term = rdflib.URIRef(value)
        elif datatype:
            term = rdflib.Literal(value, datatype=datatype)
        else:
            term = rdflib.Literal(value)
        return term

Internal method takes a datatype (can be None) and returns
the RDF Object Term

Args:

-----
datatype: None, or rdflib.URIRef
value: Varys depending on ingester


def ResolveFlats(
  dem,
  in_place = False
):

  if type(dem) is not rdarray:
    raise Exception("A richdem.rdarray or numpy.ndarray is required!")

  if not in_place:
    dem = dem.copy()

  _AddAnalysis(dem, "ResolveFlats(dem, in_place={in_place})".format(in_place=in_place))

  demw = dem.wrap()

  _richdem.rdResolveFlatsEpsilon(demw)

  dem.copyFromWrapped(demw)

  if not in_place:
    return dem

Attempts to resolve flats by imposing a local gradient

Args:
dem          (rdarray):   An elevation model
in_place (bool):   If True, the DEM is modified in place and there is
no return; otherwise, a new, altered DEM is returned.

Returns:
DEM modified such that all flats drain.


def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
    original_shape = hidden_states.shape
    hidden_states = hidden_states.view(-1, hidden_states.size(-1))
    logits = self.router(hidden_states)
    top_logits, top_indices = torch.topk(logits, k=self.config.moe_topk, dim=1)
    scores = nn.functional.softmax(top_logits, dim=-1)
    original_dtype = top_indices.dtype
    tokens_per_expert = torch.histc(top_indices.flatten().to(torch.float32), bins=self.config.moe_num_experts, min=0, max=self.config.moe_num_experts - 1).to(original_dtype)
    indices = top_indices
    flatten_indices = indices.view(-1)
    sorted_indices = torch.argsort(flatten_indices)
    permuted_tokens = hidden_states.index_select(0, sorted_indices
    expert_output = self.experts(permuted_tokens, tokens_per_expert)
    unpermuted_tokens = torch.zeros((scores.shape[0] * self.config.moe_topk, expert_output.size(1)), dtype=expert_output.dtype, device=expert_output.device)
    unpermuted_tokens.index_copy_(0, sorted_indices, expert_output)
    unpermuted_tokens = unpermuted_tokens.view(-1, self.config.moe_topk, expert_output.size(1))
    output = (unpermuted_tokens * scores.unsqueeze(-1)).sum(dim=1).view(original_shape)
    shared_expert_output = self.shared_experts(hidden_states.view(original_shape))
    return output + shared_expert_output

Forward pass of the MoE Layer.

Args:
hidden_states (`torch.Tensor`):
Input tensor of shape (batch_size, sequence_length, hidden_size).

Returns:
torch.Tensor: Output tensor after passing through the MoE layer.

Process:
1. Route tokens to experts using the router.
2. Permute tokens based on routing decisions.
3. Process tokens through experts.
4. Unpermute and combine expert outputs.
5. Add shared expert output to the final result.


def getHostCaPath(self, name):

        cert = self.getHostCert(name)
        if cert is None:
            return None

        return self._getCaPath(cert)

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

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

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

mypath = cdir.getHostCaPath('myhost')

Returns:
str: The path if exists.


def _convert_update_row(row):

    after_values = row['after_values']
    before_values = row['before_values']
    values = after_values
    return {
        'values': values,
        'updated_values': _get_updated_values(before_values, after_values)
    }

Convert a row for update event

Args:
row (dict): event row data


def blit(self, dest: tcod.console.Console, fill_fore: bool=True, fill_back: bool=True) -> None:
    if (not dest):
        dest = tcod.console.Console._from_cdata(ffi.NULL)
    if ((dest.width != self.width) or (dest.height != self.height)):
        raise ValueError('ConsoleBuffer.blit: Destination console has an incorrect size.')
    if fill_back:
        bg = dest.bg.ravel()
        bg[0::3] = self.back_r
        bg[1::3] = self.back_g
        bg[2::3] = self.back_b
    if fill_fore:
        fg = dest.fg.ravel()
        fg[0::3] = self.fore_r
        fg[1::3] = self.fore_g
        fg[2::3] = self.fore_b
        dest.ch.ravel()[:] = self.char

Use libtcod's "fill" functions to write the buffer to a console.

Args:
dest (Console): Console object to modify.
fill_fore (bool):
If True, fill the foreground color and characters.
fill_back (bool):
If True, fill the background color.


def write(self, destination, filename, template_name, **kwargs):
    template = self.env.get_template(template_name)
    content = template.render(kwargs)
    super(TemplateFileWriter, self).write(destination=destination, filename=filename, content=content)

Write a file according to the template name

Args:
destination (string): the destination location
filename (string): the filename that will be written
template_name (string): the name of the template
kwargs (dict): all attribute that will be passed to the template


def load_videos(template, video_length, frame_shape):
    filenames = tf.gfile.Glob(template)
    if (not filenames):
        raise ValueError('no files found.')
    filenames = sorted(filenames)
    dataset_len = len(filenames)
    filenames = tf.constant(filenames)
    dataset = tf.data.Dataset.from_tensor_slices(filenames)
    dataset = dataset.apply(tf.data.experimental.map_and_batch((lambda filename: load_image_map_function(filename, frame_shape)), video_length, drop_remainder=True))
    return (dataset, dataset_len)

Loads videos from files.

Args:
template: template string for listing the image files.
video_length: length of the video.
frame_shape: shape of each frame.

Returns:
dataset: the tf dataset frame by frame.
dataset_len: number of the items which is the number of image files.

Raises:
ValueError: if no files found.


def distances(self, word, words):
    point = self[word]
    vectors = np.asarray([self[w] for w in words])
    diff = (vectors - point)
    distances = np.linalg.norm(diff, axis=1)
    return distances

Calculate eucledean pairwise distances between `word` and `words`.

Args:
word (string): single word.
words (list): list of strings.

Returns:
numpy array of the distances.

Note:
L2 metric is used to calculate distances.


def create_from_json(cls, json_data):

        msa = Msa()
        msa.msa = json_data["msa_info"]["msa"]
        msa.meta = json_data["meta"] if "meta" in json_data else None

        msa.component_results = _create_component_results(json_data, "msa_info")

        return msa

Deserialize msa json data into a Msa object

Args:
json_data (dict): The json data for this msa

Returns:
Msa object


def login(self, client_id, access_token, connection, scope='openid'):
    return self.post('https:

Login using a social provider's access token

Given the social provider's access_token and the connection specified,
it will do the authentication on the provider and return a dict with
the access_token and id_token. Currently, this endpoint only works for
Facebook, Google, Twitter and Weibo.

Args:
client_id (str): application's client id.

access_token (str): social provider's access_token.

connection (str): connection type (e.g: 'facebook')

Returns:
A dict with 'access_token' and 'id_token' keys.


def delete_recursively_v2(path):
    _pywrap_file_io.DeleteRecursively(compat.path_to_bytes(path))

Deletes everything under path recursively.

Args:
path: string, a path

Raises:
errors.OpError: If the operation fails.


def ConvertMessage(self, value, message):

    message_descriptor = message.DESCRIPTOR
    full_name = message_descriptor.full_name
    if _IsWrapperMessage(message_descriptor):
      self._ConvertWrapperMessage(value, message)
    elif full_name in _WKTJSONMETHODS:
      methodcaller(_WKTJSONMETHODS[full_name][1], value, message)(self)
    else:
      self._ConvertFieldValuePair(value, message)

Convert a JSON object into a message.

Args:
value: A JSON object.
message: A WKT or regular protocol message to record the data.

Raises:
ParseError: In case of convert problems.


def write_input(self, output_dir='.', make_dir_if_not_present=True):
    if (make_dir_if_not_present and (not os.path.exists(output_dir))):
        os.makedirs(output_dir)
    feff = self.all_input()
    feff_input = '\n\n'.join((str(feff[k]) for k in ['HEADER', 'PARAMETERS', 'POTENTIALS', 'ATOMS'] if (k in feff)))
    for (k, v) in feff.items():
        with open(os.path.join(output_dir, k), 'w') as f:
            f.write(str(v))
    with open(os.path.join(output_dir, 'feff.inp'), 'w') as f:
        f.write(feff_input)
    if ('ATOMS' not in feff):
        self.atoms.struct.to(fmt='cif', filename=os.path.join(output_dir, feff['PARAMETERS']['CIF']))

Writes a set of FEFF input to a directory.

Args:
output_dir: Directory to output the FEFF input files
make_dir_if_not_present: Set to True if you want the directory (
and the whole path) to be created if it is not present.


def _parse_format_pages_isbn(html_chunk):
    ppi = get_first_content(html_chunk.find('div', {'class': 'price-overflow'}))
    if (not ppi):
        return (None, None, None)
    ppi = filter((lambda x: x.strip()), ppi.split('<br />'))[0]
    isbn = dhtmlparser.parseString(ppi)
    isbn = isbn.find('b')
    isbn = (isbn[0].getContent() if isbn else None)
    pages = None
    book_format = None
    details = ppi.split('|')
    if (len(details) >= 2):
        book_format = details[0].strip()
        pages = details[1].strip()
    return (book_format, pages, isbn)

Parse format, number of pages and ISBN.

Args:
html_chunk (obj): HTMLElement containing slice of the page with details.

Returns:
tuple: (format, pages, isbn), all as string.


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

Applies embedding based on inputs tensor.

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


def get_elements_between_bands(self, band_i, band_j):

        if band_i < 1 or band_i > self.nb_bands or band_j < 1 or band_j > self.nb_bands:
            raise ValueError("Band index out of bounds")

        return self.data[:, band_i - 1, band_j - 1, :]

Method returning a numpy array with elements

[cdum_x_real, cdum_x_imag, cdum_y_real, cdum_y_imag, cdum_z_real, cdum_z_imag]

between bands band_i and band_j (vasp 1-based indexing) for all kpoints.

Args:
band_i (Integer): Index of band i
band_j (Integer): Index of band j

Returns:
a numpy list of elements for each kpoint


def is_prefix(cls, path):

        lagofile = paths.Paths(path).prefix_lagofile()
        return os.path.isfile(lagofile)

Check if a path is a valid prefix

Args:
path(str): path to be checked

Returns:
bool: True if the given path is a prefix


def _ConvertValueBinaryDataToFloatingPointValue(self, value):
    if (not value):
        return None
    value_length = len(value)
    if (value_length not in (4, 8)):
        raise errors.ParseError('Unsupported value data size: {0:d}'.format(value_length))
    if (value_length == 4):
        floating_point_map = self._GetDataTypeMap('float32le')
    elif (value_length == 8):
        floating_point_map = self._GetDataTypeMap('float64le')
    try:
        return self._ReadStructureFromByteStream(value, 0, floating_point_map)
    except (ValueError, errors.ParseError) as exception:
        raise errors.ParseError('Unable to parse floating-point value with error: {0!s}'.format(exception))

Converts a binary data value into a floating-point value.

Args:
value (bytes): binary data value containing an ASCII string or None.

Returns:
float: floating-point representation of binary data value or None if
value is not set.

Raises:
ParseError: if the floating-point value data size is not supported or
if the value cannot be parsed.


def call(self, hidden_states: tf.Tensor, attention_mask: np.ndarray | tf.Tensor | None=None, encoder_hidden_states: np.ndarray | tf.Tensor | None=None, encoder_attention_mask: np.ndarray | tf.Tensor | None=None, layer_head_mask: tf.Tensor | None=None, cross_attn_layer_head_mask: tf.Tensor | None=None, past_key_value: Optional[Tuple[Tuple[Union[np.ndarray, tf.Tensor]]]]=None, training: Optional[bool]=False) -> Tuple[tf.Tensor, tf.Tensor, Tuple[Tuple[tf.Tensor]]]:
    residual = hidden_states
    self_attn_past_key_value = past_key_value[:2] if past_key_value is not None else None
    hidden_states, self_attn_weights, present_key_value = self.self_attn(hidden_states=hidden_states, past_key_value=self_attn_past_key_value, attention_mask=attention_mask, layer_head_mask=layer_head_mask)
    hidden_states = self.dropout(hidden_states, training=training)
    hidden_states = residual + hidden_states
    hidden_states = self.self_attn_layer_norm(hidden_states)
    cross_attn_present_key_value = None
    cross_attn_weights = None
    if encoder_hidden_states is not None:
        residual = hidden_states
        cross_attn_past_key_value = past_key_value[-2:] if past_key_value is not None else None
        hidden_states, cross_attn_weights, cross_attn_present_key_value = self.encoder_attn(hidden_states=hidden_states, key_value_states=encoder_hidden_states, attention_mask=encoder_attention_mask, layer_head_mask=cross_attn_layer_head_mask, past_key_value=cross_attn_past_key_value)
        hidden_states = self.dropout(hidden_states, training=training)
        hidden_states = residual + hidden_states
        hidden_states = self.encoder_attn_layer_norm(hidden_states)
        present_key_value = present_key_value + cross_attn_present_key_value
    residual = hidden_states
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = self.activation_dropout(hidden_states, training=training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = self.dropout(hidden_states, training=training)
    hidden_states = residual + hidden_states
    hidden_states = self.final_layer_norm(hidden_states)
    return (hidden_states, self_attn_weights, cross_attn_weights, present_key_value)

Args:
hidden_states (`tf.Tensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`tf.Tensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
encoder_hidden_states (`tf.Tensor`):
cross attention input to the layer of shape `(batch, seq_len, embed_dim)`
encoder_attention_mask (`tf.Tensor`): encoder attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
layer_head_mask (`tf.Tensor`): mask for attention heads in a given layer of size
`(decoder_attention_heads,)`
cross_attn_layer_head_mask (`tf.Tensor`): mask for heads of the cross-attention module.
`(decoder_attention_heads,)`
past_key_value (`Tuple(tf.Tensor)`): cached past key and value projection states


def UpdateMaps(self, conf, incremental, force_write=False, force_lock=False):
    if not self._Lock(path=conf.lockfile, force=force_lock):
        self.log.error('Failed to acquire lock, aborting!')
        return self.ERR_LOCK
    retval = 0
    for map_name in conf.maps:
        if map_name not in conf.options:
            self.log.error('No such map name defined in config: %s', map_name)
            return 1
        if incremental:
            self.log.info('Updating and verifying %s cache.', map_name)
        else:
            self.log.info('Rebuilding and verifying %s cache.', map_name)
        cache_options = conf.options[map_name].cache
        source_options = conf.options[map_name].source
        old_cwd = os.getcwd()
        tempdir = tempfile.mkdtemp(dir=cache_options['dir'], prefix='nsscache-%s-' % map_name)
        if not os.path.isabs(cache_options['dir']):
            cache_options['dir'] = os.path.abspath(cache_options['dir'])
        if not os.path.isabs(conf.timestamp_dir):
            conf.timestamp_dir = os.path.abspath(conf.timestamp_dir)
        if not os.path.isabs(tempdir):
            tempdir = os.path.abspath(tempdir)
        os.chdir(tempdir)
        try:
            try:
                source = source_factory.Create(source_options)
                updater = self._Updater(map_name, source, cache_options, conf)
                if incremental:
                    self.log.info('Updating and verifying %s cache.', map_name)
                else:
                    self.log.info('Rebuilding and verifying %s cache.', map_name)
                retval = updater.UpdateFromSource(source, incremental=incremental, force_write=force_write)
            except error.PermissionDenied:
                self.log.error('Permission denied: could not update map %r.  Aborting', map_name)
                retval += 1
            except (error.EmptyMap, error.InvalidMap) as e:
                self.log.error(e)
                retval += 1
            except error.InvalidMerge as e:
                self.log.warning('Could not merge map %r: %s.  Skipping.', map_name, e)
        finally:
            os.chdir(old_cwd)
            shutil.rmtree(tempdir)
    return retval

Update each configured map.

For each configured map, create a source and cache object and
update the cache from the source.

Args:
conf: configuration object
incremental: flag indicating incremental update should occur
force_write: optional flag indicating safety checks should be ignored
force_lock: optional flag indicating we override existing locks

Returns:
integer, zero indicating success, non-zero failure


def impersonate(self, user, enterprise):
    if ((not user) or (not enterprise)):
        raise ValueError('You must set a user name and an enterprise name to begin impersonification')
    self._is_impersonating = True
    self._impersonation = ('%s@%s' % (user, enterprise))

Impersonate a user in a enterprise

Args:
user: the name of the user to impersonate
enterprise: the name of the enterprise where to use impersonation


def _iterate(self, url, params, api_entity):

        params['resultLimit'] = self.result_limit
        should_iterate = True
        result_start = 0
        while should_iterate:

            params['resultStart'] = result_start
            r = self.tcex.session.get(url, params=params)
            if not self.success(r):
                err = r.text or r.reason
                self.tcex.handle_error(950, [r.status_code, err, r.url])

            data = r.json().get('data').get(api_entity)

            if len(data) < self.result_limit:
                should_iterate = False
            result_start += self.result_limit

            for result in data:
                yield result


def inference(self, state_arr, limit=1000):

        agent_x, agent_y = np.where(state_arr[0] == 1)
        agent_x, agent_y = agent_x[0], agent_y[0]
        result_list = [(agent_x, agent_y, 0.0)]
        self.t = 1
        while self.t <= limit:
            next_action_arr = self.extract_possible_actions(state_arr)
            next_q_arr = self.function_approximator.inference_q(next_action_arr)
            action_arr, q = self.select_action(next_action_arr, next_q_arr)

            agent_x, agent_y = np.where(action_arr[0] == 1)
            agent_x, agent_y = agent_x[0], agent_y[0]
            result_list.append((agent_x, agent_y, q[0]))

            state_arr = self.update_state(state_arr, action_arr)

            self.t += 1

            end_flag = self.check_the_end_flag(state_arr)
            if end_flag is True:
                break

        return result_list

Infernce.

Args:
state_arr:    `np.ndarray` of state.
limit:        The number of inferencing.

Returns:
`list of `np.ndarray` of an optimal route.


def ToScriptHash(data, unhex=True):

        if len(data) > 1 and unhex:
            data = binascii.unhexlify(data)
        return UInt160(data=binascii.unhexlify(bytes(Crypto.Hash160(data), encoding='utf-8')))

Get a script hash of the data.

Args:
data (bytes): data to hash.
unhex (bool): (Default) True. Set to unhexlify the stream. Use when the bytes are not raw bytes; i.e. b'aabb'

Returns:
UInt160: script hash.


def _make_tags_vector(self, tags, bucket_length=None) -> np.ndarray:

        bucket_length = bucket_length or len(tags)
        answer = np.zeros(shape=(bucket_length,), dtype=np.int32)
        for i, tag in enumerate(tags):
            answer[i] = self.tags.tok2idx(tag)
        return answer

Transforms a sentence of tags to Numpy array, which will be the network target.

Args:
tags: input sentence of tags
bucket_length: the width of the bucket

Returns:
A 2d array, answer[i][j] contains the index of j-th tag in i-th input sentence.


def IsHFS(self):
    tsk_fs_type = self.GetFsType()
    return (tsk_fs_type in [pytsk3.TSK_FS_TYPE_HFS, pytsk3.TSK_FS_TYPE_HFS_DETECT])

Determines if the file system is HFS, HFS+ or HFSX.

Returns:
bool: True if the file system is HFS.


def cancel_merge_when_pipeline_succeeds(self, **kwargs):
    path = ('%s/%s/cancel_merge_when_pipeline_succeeds' % (self.manager.path, self.get_id()))
    server_data = self.manager.gitlab.http_put(path, **kwargs)
    self._update_attrs(server_data)

Cancel merge when the pipeline succeeds.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabMROnBuildSuccessError: If the server could not handle the
request


def DecryptPrivateKey(self, encrypted_private_key):

        aes = AES.new(self._master_key, AES.MODE_CBC, self._iv)
        return aes.decrypt(encrypted_private_key)

Decrypt the provided ciphertext with the initialized private key.

Args:
encrypted_private_key (byte string): the ciphertext to be decrypted.

Returns:
bytes: the ciphertext.


def _list_inputs_or_outputs(self, recursive, node_name, depth, control, op_type, do_outputs=False):
    if do_outputs:
        tracker = self._debug_dump.node_recipients
        type_str = 'Recipients of'
        short_type_str = 'recipients'
    else:
        tracker = self._debug_dump.node_inputs
        type_str = 'Inputs to'
        short_type_str = 'inputs'
    lines = []
    font_attr_segs = {}
    node_name, _ = debug_graphs.parse_node_or_tensor_name(node_name)
    if not self._debug_dump.node_exists(node_name):
        return cli_shared.error('There is no node named "%s" in the partition graphs' % node_name)
    if recursive:
        max_depth = depth
    else:
        max_depth = 1
    if control:
        include_ctrls_str = ', control %s included' % short_type_str
    else:
        include_ctrls_str = ''
    line = '%s node "%s"' % (type_str, node_name)
    font_attr_segs[0] = [(len(line) - 1 - len(node_name), len(line) - 1, 'bold')]
    lines.append(line + ' (Depth limit = %d%s):' % (max_depth, include_ctrls_str))
    command_template = 'lo -c -r %s' if do_outputs else 'li -c -r %s'
    self._dfs_from_node(lines, font_attr_segs, node_name, tracker, max_depth, 1, [], control, op_type, command_template=command_template)
    lines.append('')
    lines.append('Legend:')
    lines.append('  (d): recursion depth = d.')
    if control:
        lines.append('  (Ctrl): Control input.')
    if op_type:
        lines.append('  [Op]: Input node has op type Op.')
    return debugger_cli_common.RichTextLines(lines, font_attr_segs=font_attr_segs)

Helper function used by list_inputs and list_outputs.

Format a list of lines to display the inputs or output recipients of a
given node.

Args:
recursive: Whether the listing is to be done recursively, as a boolean.
node_name: The name of the node in question, as a str.
depth: Maximum recursion depth, applies only if recursive == True, as an
int.
control: Whether control inputs or control recipients are included, as a
boolean.
op_type: Whether the op types of the nodes are to be included, as a
boolean.
do_outputs: Whether recipients, instead of input nodes are to be
listed, as a boolean.

Returns:
Input or recipient tree formatted as a RichTextLines object.


def rename_attribute(self, attribute: str, new_name: str) -> None:
    for (key_node, _) in self.yaml_node.value:
        if (key_node.value == attribute):
            key_node.value = new_name
            break

Renames an attribute.

Use only if is_mapping() returns true.

If the attribute does not exist, this will do nothing.

Args:
attribute: The (old) name of the attribute to rename.
new_name: The new name to rename it to.


def bounce(sequence):
    N = len(sequence)

    def f(i):
        (div, mod) = divmod(i, N)
        if ((div % 2) == 0):
            return sequence[mod]
        else:
            return sequence[((N - mod) - 1)]
    return partial(force, sequence=_advance(f))

Return a driver function that can advance a "bounced" sequence
of values.

.. code-block:: none

seq = [0, 1, 2, 3]

# bounce(seq) => [0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, ...]

Args:
sequence (seq) : a sequence of values for the driver to bounce


def add_event(self, event):

        if not isinstance(event, event_pb2.Event):
            raise TypeError("Expected an event_pb2.Event proto, "
                            " but got %s" % type(event))
        self._async_writer.write(event.SerializeToString())

Adds an event to the event file.

Args:
event: An `Event` protocol buffer.


def Match(self, artifact=None, os_name=None, cpe=None, label=None):
    return [c for c in self.conditions if c.Match(artifact, os_name, cpe, label)]

Test if host data should trigger a check.

Args:
artifact: An artifact name.
os_name: An OS string.
cpe: A CPE string.
label: A label string.

Returns:
A list of conditions that match.


def encode_value(value):

    if value is None:
        return document_pb2.Value(null_value=struct_pb2.NULL_VALUE)

    if isinstance(value, bool):
        return document_pb2.Value(boolean_value=value)

    if isinstance(value, six.integer_types):
        return document_pb2.Value(integer_value=value)

    if isinstance(value, float):
        return document_pb2.Value(double_value=value)

    if isinstance(value, DatetimeWithNanoseconds):
        return document_pb2.Value(timestamp_value=value.timestamp_pb())

    if isinstance(value, datetime.datetime):
        return document_pb2.Value(timestamp_value=_datetime_to_pb_timestamp(value))

    if isinstance(value, six.text_type):
        return document_pb2.Value(string_value=value)

    if isinstance(value, six.binary_type):
        return document_pb2.Value(bytes_value=value)

    document_path = getattr(value, "_document_path", None)
    if document_path is not None:
        return document_pb2.Value(reference_value=document_path)

    if isinstance(value, GeoPoint):
        return document_pb2.Value(geo_point_value=value.to_protobuf())

    if isinstance(value, list):
        value_list = [encode_value(element) for element in value]
        value_pb = document_pb2.ArrayValue(values=value_list)
        return document_pb2.Value(array_value=value_pb)

    if isinstance(value, dict):
        value_dict = encode_dict(value)
        value_pb = document_pb2.MapValue(fields=value_dict)
        return document_pb2.Value(map_value=value_pb)

    raise TypeError(
        "Cannot convert to a Firestore Value", value, "Invalid type", type(value)
    )

Converts a native Python value into a Firestore protobuf ``Value``.

Args:
value (Union[NoneType, bool, int, float, datetime.datetime, \
str, bytes, dict, ~google.cloud.Firestore.GeoPoint]): A native
Python value to convert to a protobuf field.

Returns:
~google.cloud.firestore_v1beta1.types.Value: A
value encoded as a Firestore protobuf.

Raises:
TypeError: If the ``value`` is not one of the accepted types.


def create_token_type_ids_from_sequences(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
    sep = [self.sep_token_id]
    cls_segment_id = [2]
    if token_ids_1 is None:
        return len(token_ids_0 + sep) * [0] + cls_segment_id
    return len(token_ids_0 + sep) * [0] + len(token_ids_1 + sep) * [1] + cls_segment_id

Create a mask from the two sequences passed to be used in a sequence-pair classification task. An XLNet
sequence pair mask has the following format:

```
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence    | second sequence |
```

If `token_ids_1` is `None`, this method only returns the first portion of the mask (0s).

Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.

Returns:
`List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s).


def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
    super(ProtocolVersion, self).read(input_stream, kmip_version=kmip_version)
    local_stream = utils.BytearrayStream(input_stream.read(self.length))
    if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MAJOR, local_stream):
        self._major = primitives.Integer(tag=enums.Tags.PROTOCOL_VERSION_MAJOR)
        self._major.read(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('Invalid encoding missing the major protocol version number.')
    if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MINOR, local_stream):
        self._minor = primitives.Integer(tag=enums.Tags.PROTOCOL_VERSION_MINOR)
        self._minor.read(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('Invalid encoding missing the minor protocol version number.')
    self.is_oversized(local_stream)

Read the data encoding the ProtocolVersion struct and decode it into
its constituent parts.

Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.

Raises:
ValueError: Raised if either the major or minor protocol versions
are missing from the encoding.


def process(self, batch, device=None):
    padded = self.pad(batch)
    tensor = self.numericalize(padded, device=device)
    return tensor

Process a list of examples to create a torch.Tensor.

Pad, numericalize, and postprocess a batch and create a tensor.

Args:
batch (list(object)): A list of object from a batch of examples.
Returns:
torch.autograd.Variable: Processed object given the input
and custom postprocessing Pipeline.


def split_window(self, fpath, vertical=False, size=None, bufopts=None):
    command = ('split {}'.format(fpath) if fpath else 'new')
    if vertical:
        command = ('v' + command)
    if size:
        command = (str(size) + command)
    self._vim.command(command)
    if bufopts:
        self.set_buffer_options(bufopts)

Open file in a new split window.

Args:
fpath (str): Path of the file to open. If ``None``, a new empty
split is created.
vertical (bool): Whether to open a vertical split.
size (Optional[int]): The height (or width) to set for the new window.
bufopts (Optional[dict]): Buffer-local options to set in the split window.
See :func:`.set_buffer_options`.


def simplify(self, assignments):
    if self.right in assignments:
        return self
    else:
        return self if self.right in assignments[self.left] else FALSE

Simplify this equality.

This will try to look up the values, and return FALSE if they're no longer
possible. Also, when comparing two variables, it will compute the
intersection, and return a disjunction of variable=value equalities instead.

Args:
assignments: Variable assignments (dict mapping strings to sets of
strings). Used to determine whether this equality is still possible, and
to compute intersections between two variables.

Returns:
A new BooleanTerm.


def input_elements(self, instruction_id, expected_inputs, abort_callback=None):
    received = self._receiving_queue(instruction_id)
    if received is None:
        raise RuntimeError('Instruction cleaned up already %s' % instruction_id)
    done_inputs = set()
    abort_callback = abort_callback or (lambda: False)
    log_interval_sec = 5 * 60
    try:
        start_time = time.time()
        next_waiting_log_time = start_time + log_interval_sec
        while len(done_inputs) < len(expected_inputs):
            try:
                element = received.get(timeout=1)
            except queue.Empty:
                if self._closed:
                    raise RuntimeError('Channel closed prematurely.')
                if abort_callback():
                    return
                if self._exception:
                    raise self._exception from None
                current_time = time.time()
                if next_waiting_log_time <= current_time:
                    _LOGGER.info('Detected input queue delay longer than %s seconds. Waiting to receive elements in input queue for instruction: %s for %.2f seconds.', log_interval_sec, instruction_id, current_time - start_time)
                    next_waiting_log_time = current_time + log_interval_sec
            else:
                start_time = time.time()
                next_waiting_log_time = start_time + log_interval_sec
                if isinstance(element, beam_fn_api_pb2.Elements.Timers):
                    if element.is_last:
                        done_inputs.add((element.transform_id, element.timer_family_id))
                    else:
                        yield element
                elif isinstance(element, beam_fn_api_pb2.Elements.Data):
                    if element.is_last:
                        done_inputs.add(element.transform_id)
                    else:
                        assert element.transform_id not in done_inputs
                        yield element
                else:
                    raise ValueError('Unexpected input element type %s' % type(element))
    finally:
        self._clean_receiving_queue(instruction_id)

Generator to retrieve elements for an instruction_id
input_elements should be called only once for an instruction_id

Args:
instruction_id(str): instruction_id for which data is read
expected_inputs(collection): expected inputs, include both data and timer.


def get_all_organization_names(configuration=None, **kwargs):
    organization = Organization(configuration=configuration)
    organization['id'] = 'all organizations'
    return organization._write_to_hdx('list', kwargs, 'id')

Get all organization names in HDX

Args:
configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration.
**kwargs: See below
sort (str): Sort the search results according to field name and sort-order. Allowed fields are ‘name’, ‘package_count’ and ‘title’. Defaults to 'name asc'.
organizations (List[str]): List of names of the groups to return.
all_fields (bool): Return group dictionaries instead of just names. Only core fields are returned - get some more using the include_* options. Defaults to False.
include_extras (bool): If all_fields, include the group extra fields. Defaults to False.
include_tags (bool): If all_fields, include the group tags. Defaults to False.
include_groups: If all_fields, include the groups the groups are in. Defaults to False.

Returns:
List[str]: List of all organization names in HDX


def device_coordinates(self):
    return self._device_coordinates

Describes the mapping from TPU devices to topology coordinates.

Returns:
A rank 3 int32 array with shape `[tasks, devices, axis]`.
`tasks` is the number of tasks in the TPU cluster, `devices` is the number
of TPU devices per task, and `axis` is the number of axes in the TPU
cluster topology. Each entry gives the `axis`-th coordinate in the
topology of a task/device pair. TPU topologies are 4-dimensional, with
dimensions `(x, y, z, core number)`.


def _psd_mask(x):

  eigenvalues, _ = tf.linalg.eigh(x)
  return tf.cast(
      tf.reduce_min(input_tensor=eigenvalues, axis=-1) >= 0, dtype=x.dtype)

Computes whether each square matrix in the input is positive semi-definite.

Args:
x: A floating-point `Tensor` of shape `[B1, ..., Bn, M, M]`.

Returns:
mask: A floating-point `Tensor` of shape `[B1, ... Bn]`.  Each
scalar is 1 if the corresponding matrix was PSD, otherwise 0.


def wrap_layer_objects(layer, serialization_cache):
    all_losses = layer._callable_losses[:]
    for child_layer in utils.list_all_layers(layer):
        all_losses.extend(child_layer._callable_losses)
    keras_loss_cache = serialization_cache.setdefault('keras_losses', {})
    wrapped_loss_functions = []
    for loss_fn in all_losses:
        if loss_fn in keras_loss_cache:
            wrapped_loss_functions.append(keras_loss_cache[loss_fn])
        else:
            wrapped_loss = _wrap_unconditional_loss(loss_fn, len(keras_loss_cache))
            keras_loss_cache[loss_fn] = wrapped_loss
            wrapped_loss_functions.append(wrapped_loss)
    wrapped_layer_losses = [keras_loss_cache[fn] for fn in layer._callable_losses[:]]
    layer_metrics = data_structures.wrap_or_unwrap({m.name: m for m in layer._metrics})
    return dict(variables=data_structures.wrap_or_unwrap(layer.variables), trainable_variables=data_structures.wrap_or_unwrap(layer.trainable_variables), non_trainable_variables=data_structures.wrap_or_unwrap(layer.non_trainable_variables), layers=data_structures.wrap_or_unwrap(utils.list_all_layers(layer)), metrics=data_structures.wrap_or_unwrap(layer.metrics), regularization_losses=data_structures.wrap_or_unwrap(wrapped_loss_functions), layer_regularization_losses=data_structures.wrap_or_unwrap(wrapped_layer_losses), layer_metrics=layer_metrics)

Returns extra trackable objects to attach to the serialized layer.

Args:
layer: Keras Layer object.
serialization_cache: Dictionary shared between all objects during
serialization.

Returns:
A dictionary containing all checkpointable objects from a
SerializedAttributes object. See LayerAttributes and ModelAttributes for
entire list of objects


def invite_by_email(self, email, user, organization, **kwargs):
    try:
        invitee = self.user_model.objects.get(email__iexact=email)
    except self.user_model.DoesNotExist:
        invitee = None
    user_invitation = self.invitation_model.objects.create(invitee=invitee, invitee_identifier=email.lower(), invited_by=user, organization=organization)
    self.send_invitation(user_invitation)
    return user_invitation

Primary interface method by which one user invites another to join

Args:
email:
request:
**kwargs:

Returns:
an invitation instance

Raises:
MultipleObjectsReturned if multiple matching users are found


def parse_args(args=None):

    parser = argparse.ArgumentParser(description="Main script to run LIVVkit.",
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                     fromfile_prefix_chars='@')

    parser.add_argument('-o', '--out-dir',
                        default=os.path.join(os.getcwd(), "vv_" + time.strftime("%Y-%m-%d")),
                        help='Location to output the LIVVkit webpages.'
                        )

    parser.add_argument('-v', '--verify',
                        nargs=2,
                        default=None,
                        help=' '.join(['Specify the locations of the test and bench bundle to',
                                       'compare (respectively).'
                                       ])
                        )

    parser.add_argument('-V', '--validate',
                        action='store',
                        nargs='+',
                        default=None,
                        help=' '.join(['Specify the location of the configuration files for',
                                       'validation tests.'
                                       ])
                        )

    parser.add_argument('-e', '--extension',
                        action='store',
                        nargs='+',
                        default=None,
                        dest='validate',
                        metavar='EXTENSION',
                        help=' '.join(['Specify the location of the configuration files for',
                                       'LIVVkit extensions.'
                                       ])
                        )

    parser.add_argument('-p', '--publish',
                        action='store_true',
                        help=' '.join(['Also produce a publication quality copy of the figure in',
                                       'the output directory (eps, 600d pi).'
                                       ])
                        )

    parser.add_argument('-s', '--serve',
                        nargs='?', type=int, const=8000,
                        help=' '.join(['Start a simple HTTP server for the output website specified',
                                       'by OUT_DIR on port SERVE.'
                                       ])
                        )

    parser.add_argument('--version',
                        action='version',
                        version='LIVVkit {}'.format(livvkit.__version__),
                        help="Show LIVVkit's version number and exit"
                        )

    return init(parser.parse_args(args))

Handles the parsing of options for LIVVkit's command line interface

Args:
args: The list of arguments, typically sys.argv[1:]


def call(self, input_ids: TFModelInputType | None=None, attention_mask: np.ndarray | tf.Tensor | None=None, decoder_input_ids: np.ndarray | tf.Tensor | None=None, decoder_attention_mask: np.ndarray | tf.Tensor | None=None, decoder_position_ids: np.ndarray | tf.Tensor | None=None, head_mask: np.ndarray | tf.Tensor | None=None, decoder_head_mask: np.ndarray | tf.Tensor | None=None, cross_attn_head_mask: np.ndarray | tf.Tensor | None=None, encoder_outputs: Optional[TFBaseModelOutput]=None, past_key_values: Optional[Tuple[Tuple[Union[np.ndarray, tf.Tensor]]]]=None, inputs_embeds: np.ndarray | tf.Tensor | None=None, decoder_inputs_embeds: np.ndarray | tf.Tensor | None=None, use_cache: Optional[bool]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, labels: tf.Tensor | None=None, training: Optional[bool]=False) -> Union[TFSeq2SeqLMOutput, Tuple[tf.Tensor]]:
    if labels is not None:
        labels = tf.where(labels == self.config.pad_token_id, tf.cast(tf.fill(shape_list(labels), -100), labels.dtype), labels)
        use_cache = False
        if decoder_input_ids is None and decoder_inputs_embeds is None:
            decoder_input_ids = shift_tokens_right(labels, self.config.pad_token_id, self.config.decoder_start_token_id)
    outputs = self.model(input_ids, attention_mask=attention_mask, decoder_input_ids=decoder_input_ids, encoder_outputs=encoder_outputs, decoder_attention_mask=decoder_attention_mask, decoder_position_ids=decoder_position_ids, head_mask=head_mask, decoder_head_mask=decoder_head_mask, cross_attn_head_mask=cross_attn_head_mask, past_key_values=past_key_values, inputs_embeds=inputs_embeds, decoder_inputs_embeds=decoder_inputs_embeds, use_cache=use_cache, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, training=training)
    lm_logits = tf.matmul(outputs[0], self.model.shared.weights, transpose_b=True)
    lm_logits = self.bias_layer(lm_logits)
    masked_lm_loss = None if labels is None else self.hf_compute_loss(labels, lm_logits)
    if not return_dict:
        output = (lm_logits,) + outputs[1:]
        return (masked_lm_loss,) + output if masked_lm_loss is not None else output
    return TFSeq2SeqLMOutput(loss=masked_lm_loss, logits=lm_logits, past_key_values=outputs.past_key_values, decoder_hidden_states=outputs.decoder_hidden_states, decoder_attentions=outputs.decoder_attentions, cross_attentions=outputs.cross_attentions, encoder_last_hidden_state=outputs.encoder_last_hidden_state, encoder_hidden_states=outputs.encoder_hidden_states, encoder_attentions=outputs.encoder_attentions)

labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.

Returns:


def _build_processor(cls, session: AppSession):
    web_processor = cls._build_web_processor(session)
    ftp_processor = cls._build_ftp_processor(session)
    delegate_processor = session.factory.new('Processor')
    delegate_processor.register('http', web_processor)
    delegate_processor.register('https', web_processor)
    delegate_processor.register('ftp', ftp_processor)

Create the Processor

Returns:
Processor: An instance of :class:`.processor.BaseProcessor`.


def delete_existing_cname(env, zone_id, dns_name):
    client = boto3.Session(profile_name=env).client('route53')
    startrecord = None
    newrecord_name = dns_name
    startrecord = find_existing_record(env, zone_id, newrecord_name, check_key='Type', check_value='CNAME')
    if startrecord:
        LOG.info('Deleting old record: %s', newrecord_name)
        _response = client.change_resource_record_sets(HostedZoneId=zone_id, ChangeBatch={'Changes': [{'Action': 'DELETE', 'ResourceRecordSet': startrecord}]})
        LOG.debug('Response from deleting %s: %s', dns_name, _response)

Delete an existing CNAME record.

This is used when updating to multi-region for deleting old records. The
record can not just be upserted since it changes types.

Args:
env (str): Deployment environment.
zone_id (str): Route53 zone id.
dns_name (str): FQDN of application's dns entry to add/update.


def _experiments_to_circuits(qobj):

    if qobj.experiments:
        circuits = []
        for x in qobj.experiments:
            quantum_registers = [QuantumRegister(i[1], name=i[0])
                                 for i in x.header.qreg_sizes]
            classical_registers = [ClassicalRegister(i[1], name=i[0])
                                   for i in x.header.creg_sizes]
            circuit = QuantumCircuit(*quantum_registers,
                                     *classical_registers,
                                     name=x.header.name)
            qreg_dict = {}
            creg_dict = {}
            for reg in quantum_registers:
                qreg_dict[reg.name] = reg
            for reg in classical_registers:
                creg_dict[reg.name] = reg
            for i in x.instructions:
                instr_method = getattr(circuit, i.name)
                qubits = []
                try:
                    for qubit in i.qubits:
                        qubit_label = x.header.qubit_labels[qubit]
                        qubits.append(
                            qreg_dict[qubit_label[0]][qubit_label[1]])
                except Exception:
                    pass
                clbits = []
                try:
                    for clbit in i.memory:
                        clbit_label = x.header.clbit_labels[clbit]
                        clbits.append(
                            creg_dict[clbit_label[0]][clbit_label[1]])
                except Exception:
                    pass
                params = []
                try:
                    params = i.params
                except Exception:
                    pass
                if i.name in ['snapshot']:
                    instr_method(
                        i.label,
                        snapshot_type=i.snapshot_type,
                        qubits=qubits,
                        params=params)
                elif i.name == 'initialize':
                    instr_method(params, qubits)
                else:
                    instr_method(*params, *qubits, *clbits)
            circuits.append(circuit)
        return circuits
    return None

Return a list of QuantumCircuit object(s) from a qobj

Args:
qobj (Qobj): The Qobj object to convert to QuantumCircuits
Returns:
list: A list of QuantumCircuit objects from the qobj


def print_schema_results(results, level=0):
    for error in results.errors:
        print_level(logger.error, (_RED + '[X] %s'), level, error)

Print JSON Schema validation errors to stdout.

Args:
results: An instance of ObjectValidationResults.
level: The level at which to print the results.


def _get_pmap_impl(f, devices, has_tpu):
    if has_tpu:
        output_is_list = [False]

        def recorder(args, kwargs, res):
            del args, kwargs
            output_is_list[0] = isinstance(res, list)
            return res
        f = _record_result_type(recorder, f)

    def tf_f(*tf_args):

        np_args = _tf_to_np(tf_args)
        np_out = f(*np_args)
        return np_out
    if has_tpu:

        @polymorphic_function.function(autograph=False)
        def fn(inputs):
            res = tpu.replicate(tf_f, inputs)
            if res and isinstance(res[0], list) and (len(res[0]) == 1) and (not output_is_list[0]):
                res = [x[0] for x in res]
            return res
        return fn
    else:
        jit_tf_f = polymorphic_function.function(tf_f, autograph=False)

        @polymorphic_function.function(autograph=False)
        def fn(all_per_device_args):

            results = []
            for per_device_args, device in zip(all_per_device_args, devices):
                with ops.device(device):
                    results.append(jit_tf_f(*per_device_args))
            return results
        return fn

This is a helper function to return the pmap impl.

Args:
f: a function that takes ndarrays and returns ndarrays.
devices: a list of strings; the device list.
has_tpu: boolean; whether `devices` contains TPU devices.

Returns:
A function that takes tensors and returns tensors.


def length_of_overlap(first_start, first_end, second_start, second_end):
    if ((first_end <= second_start) or (first_start >= second_end)):
        return 0.0
    if (first_start < second_start):
        if (first_end < second_end):
            return abs((first_end - second_start))
        else:
            return abs((second_end - second_start))
    if (first_start > second_start):
        if (first_end > second_end):
            return abs((second_end - first_start))
        else:
            return abs((first_end - first_start))

Find the length of the overlapping part of two segments.

Args:
first_start (float): Start of the first segment.
first_end (float): End of the first segment.
second_start (float): Start of the second segment.
second_end (float): End of the second segment.

Return:
float: The amount of overlap or 0 if they don't overlap at all.


def from_string(cls, public_key):
    public_key_data = _helpers.to_bytes(public_key)
    if (_CERTIFICATE_MARKER in public_key_data):
        cert = cryptography.x509.load_pem_x509_certificate(public_key_data, _BACKEND)
        pubkey = cert.public_key()
    else:
        pubkey = serialization.load_pem_public_key(public_key_data, _BACKEND)
    return cls(pubkey)

Construct an Verifier instance from a public key or public
certificate string.

Args:
public_key (Union[str, bytes]): The public key in PEM format or the
x509 public key certificate.

Returns:
Verifier: The constructed verifier.

Raises:
ValueError: If the public key can't be parsed.


def prepare_adiabatic_limit(slh, k=None):
    if (k is None):
        k = symbols('k', positive=True)
    Ld = slh.L.dag()
    LdL = (Ld * slh.L)[(0, 0)]
    K = (((- LdL) / 2) + (I * slh.H)).expand().simplify_scalar()
    N = slh.S.dag()
    (B, A, Y) = K.series_expand(k, 0, 2)
    (G, F) = Ld.series_expand(k, 0, 1)
    return (Y, A, B, F, G, N)

Prepare the adiabatic elimination on an SLH object

Args:
slh: The SLH object to take the limit for
k: The scaling parameter $k \rightarrow \infty$. The default is a
positive symbol 'k'

Returns:
tuple: The objects ``Y, A, B, F, G, N``
necessary to compute the limiting system.


def BuildDefaultValue(self, value_cls):

    try:
      return value_cls()
    except Exception as e:
      logging.exception(e)
      raise DefaultValueError(
          "Can't create default for value %s: %s" % (value_cls.__name__, e))

Renders default value of a given class.

Args:
value_cls: Default value 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:
An initialized default value.

Raises:
DefaultValueError: if something goes wrong.


def GetMap(self, cache_info, data):
    entries = collections.defaultdict(dict)
    for line in json.loads(cache_info.read()):
        key = line.get('Key', '').split('/')
        value = line.get('Value', '')
        if not value or not key:
            continue
        value = base64.b64decode(value)
        name = str(key[-2])
        entry_piece = key[-1]
        entries[name][entry_piece] = value
    for name, entry in list(entries.items()):
        map_entry = self._ReadEntry(name, entry)
        if map_entry is None:
            self.log.warning('Could not create entry from line %r in cache, skipping', entry)
            continue
        if not data.Add(map_entry):
            self.log.warning('Could not add entry %r read from line %r in cache', map_entry, entry)
    return data

Returns a map from a cache.

Args:
cache_info: file like object containing the cache.
data: a Map to populate.
Returns:
A child of Map containing the cache data.


def _anonymous_match(self, struct1, struct2, fu, s1_supercell=True,
                         use_rms=False, break_on_match=False, single_match=False):

        if not isinstance(self._comparator, SpeciesComparator):
            raise ValueError('Anonymous fitting currently requires SpeciesComparator')

        sp1 = struct1.composition.elements
        sp2 = struct2.composition.elements
        if len(sp1) != len(sp2):
            return None

        ratio = fu if s1_supercell else 1/fu
        swapped = len(struct1) * ratio < len(struct2)

        s1_comp = struct1.composition
        s2_comp = struct2.composition
        matches = []
        for perm in itertools.permutations(sp2):
            sp_mapping = dict(zip(sp1, perm))

            mapped_comp = Composition({sp_mapping[k]: v
                                       for k, v in s1_comp.items()})
            if (not self._subset) and (
                    self._comparator.get_hash(mapped_comp) !=
                    self._comparator.get_hash(s2_comp)):
                continue

            mapped_struct = struct1.copy()
            mapped_struct.replace_species(sp_mapping)
            if swapped:
                m = self._strict_match(struct2, mapped_struct, fu,
                                       (not s1_supercell), use_rms,
                                       break_on_match)
            else:
                m = self._strict_match(mapped_struct, struct2, fu, s1_supercell,
                                       use_rms, break_on_match)
            if m:
                matches.append((sp_mapping, m))
                if single_match:
                    break
        return matches

Tries all permutations of matching struct1 to struct2.
Args:
struct1, struct2 (Structure): Preprocessed input structures
Returns:
List of (mapping, match)


def release(self, connection: Connection, reuse: bool=True):
    (yield from self._condition.acquire())
    self.busy.remove(connection)
    if reuse:
        self.ready.add(connection)
    self._condition.notify()
    self._condition.release()

Unregister a connection.

Args:
connection: Connection instance returned from :meth:`acquire`.
reuse: If True, the connection is made available for reuse.

Coroutine.


def __init__(self, descriptor_db=None):

    self._internal_db = descriptor_database.DescriptorDatabase()
    self._descriptor_db = descriptor_db
    self._descriptors = {}
    self._enum_descriptors = {}
    self._service_descriptors = {}
    self._file_descriptors = {}
    self._toplevel_extensions = {}

    self._file_desc_by_toplevel_extension = {}

    self._extensions_by_name = collections.defaultdict(dict)
    self._extensions_by_number = collections.defaultdict(dict)

Initializes a Pool of proto buffs.

The descriptor_db argument to the constructor is provided to allow
specialized file descriptor proto lookup code to be triggered on demand. An
example would be an implementation which will read and compile a file
specified in a call to FindFileByName() and not require the call to Add()
at all. Results from this database will be cached internally here as well.

Args:
descriptor_db: A secondary source of file descriptors.


def resolve(self, method, path):
    if ((method in self._literal) and (path in self._literal[method])):
        return (self._literal[method][path], [], {})
    else:
        return self._resolve_non_literal_route(method, path)

Resolve a request to a route handler.

Arguments:
method (str): HTTP method, e.g. GET, POST, etc. (type: str)
path (str): Request path

Returns:
tuple or None: A tuple of three items:

1. Route handler (callable)
2. Positional arguments (list)
3. Keyword arguments (dict)

``None`` if no route matches the request.


def impad(img, shape, pad_val=0):

    if not isinstance(pad_val, (int, float)):
        assert len(pad_val) == img.shape[-1]
    if len(shape) < len(img.shape):
        shape = shape + (img.shape[-1], )
    assert len(shape) == len(img.shape)
    for i in range(len(shape) - 1):
        assert shape[i] >= img.shape[i]
    pad = np.empty(shape, dtype=img.dtype)
    pad[...] = pad_val
    pad[:img.shape[0], :img.shape[1], ...] = img
    return pad

Pad an image to a certain shape.

Args:
img (ndarray): Image to be padded.
shape (tuple): Expected padding shape.
pad_val (number or sequence): Values to be filled in padding areas.

Returns:
ndarray: The padded image.


def allsame(iterable, eq=operator.eq):
    iter_ = iter(iterable)
    try:
        first = next(iter_)
    except StopIteration:
        return True
    return all((eq(first, item) for item in iter_))

Determine if all items in a sequence are the same

Args:
iterable (Iterable): items to determine if they are all the same

eq (Callable, optional): function to determine equality
(default: operator.eq)

Example:
>>> allsame([1, 1, 1, 1])
True
>>> allsame([])
True
>>> allsame([0, 1])
False
>>> iterable = iter([0, 1, 1, 1])
>>> next(iterable)
>>> allsame(iterable)
True
>>> allsame(range(10))
False
>>> allsame(range(10), lambda a, b: True)
True


def _get_target_dtype(self, from_dtype: Optional[_NpDType]) -> Optional[_NpDType]:

Validate and normalize the numpy dtype.

Args:
from_dtype: DType of the array to cast

Returns:
to_dtype: DType of the array after casting


def wait_all(jobs, timeout=None):

    return Job._wait(jobs, timeout, concurrent.futures.ALL_COMPLETED)

Return when at all of the specified jobs have completed or timeout expires.

Args:
jobs: a Job or list of Jobs to wait on.
timeout: a timeout in seconds to wait for. None (the default) means no timeout.
Returns:
A list of the jobs that have now completed or None if there were no jobs.


def __call__(self, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]], text_pair: Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]]=None, boxes: Optional[Union[List[List[int]], List[List[List[int]]]]]=None, word_labels: Optional[Union[List[int], List[List[int]]]]=None, add_special_tokens: bool=True, padding: Union[bool, str, PaddingStrategy]=False, truncation: Union[bool, str, TruncationStrategy]=None, max_length: Optional[int]=None, stride: int=0, pad_to_multiple_of: Optional[int]=None, padding_side: Optional[str]=None, return_tensors: Optional[Union[str, TensorType]]=None, return_token_type_ids: Optional[bool]=None, return_attention_mask: Optional[bool]=None, return_overflowing_tokens: bool=False, return_special_tokens_mask: bool=False, return_offsets_mapping: bool=False, return_length: bool=False, verbose: bool=True, **kwargs) -> BatchEncoding:

    def _is_valid_text_input(t):
        if isinstance(t, str):
            return True
        elif isinstance(t, (list, tuple)):
            if len(t) == 0:
                return True
            elif isinstance(t[0], str):
                return True
            elif isinstance(t[0], (list, tuple)):
                return len(t[0]) == 0 or isinstance(t[0][0], str)
            else:
                return False
        else:
            return False
    if text_pair is not None:
        if not _is_valid_text_input(text):
            raise ValueError('text input must of type `str` (single example) or `List[str]` (batch of examples). ')
        if not isinstance(text_pair, (list, tuple)):
            raise ValueError('Words must be of type `List[str]` (single pretokenized example), or `List[List[str]]` (batch of pretokenized examples).')
    elif not isinstance(text, (list, tuple)):
        raise ValueError('Words must be of type `List[str]` (single pretokenized example), or `List[List[str]]` (batch of pretokenized examples).')
    if text_pair is not None:
        is_batched = isinstance(text, (list, tuple))
    else:
        is_batched = isinstance(text, (list, tuple)) and text and isinstance(text[0], (list, tuple))
    words = text if text_pair is None else text_pair
    if boxes is None:
        raise ValueError('You must provide corresponding bounding boxes')
    if is_batched:
        if len(words) != len(boxes):
            raise ValueError('You must provide words and boxes for an equal amount of examples')
        for words_example, boxes_example in zip(words, boxes):
            if len(words_example) != len(boxes_example):
                raise ValueError('You must provide as many words as there are bounding boxes')
    elif len(words) != len(boxes):
        raise ValueError('You must provide as many words as there are bounding boxes')
    if is_batched:
        if text_pair is not None and len(text) != len(text_pair):
            raise ValueError(f'batch length of `text`: {len(text)} does not match batch length of `text_pair`: {len(text_pair)}.')
        batch_text_or_text_pairs = list(zip(text, text_pair)) if text_pair is not None else text
        is_pair = bool(text_pair is not None)
        return self.batch_encode_plus(batch_text_or_text_pairs=batch_text_or_text_pairs, is_pair=is_pair, boxes=boxes, word_labels=word_labels, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, stride=stride, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)
    else:
        return self.encode_plus(text=text, text_pair=text_pair, boxes=boxes, word_labels=word_labels, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, stride=stride, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)

Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
sequences with word-level normalized bounding boxes and optional labels.

Args:
text (`str`, `List[str]`, `List[List[str]]`):
The sequence or batch of sequences to be encoded. Each sequence can be a string, a list of strings
(words of a single example or questions of a batch of examples) or a list of list of strings (batch of
words).
text_pair (`List[str]`, `List[List[str]]`):
The sequence or batch of sequences to be encoded. Each sequence should be a list of strings
(pretokenized string).
boxes (`List[List[int]]`, `List[List[List[int]]]`):
Word-level bounding boxes. Each bounding box should be normalized to be on a 0-1000 scale.
word_labels (`List[int]`, `List[List[int]]`, *optional*):
Word-level integer labels (for token classification tasks such as FUNSD, CORD).


def explore_package(module_name):
    packages = []
    loader = pkgutil.get_loader(module_name)
    for sub_module in pkgutil.walk_packages([os.path.dirname(loader.get_filename())], prefix=(module_name + '.')):
        (_, sub_module_name, _) = sub_module
        packages.append(sub_module_name)
    return packages

returns all the packages in the module

Args:
module_name: name of module

Returns:


def run(self, timeout=(- 1)):

    def target():
        self.process = subprocess.Popen(self.cmd, stdout=self.stdout_dest, stderr=self.stderr_dest, shell=self.shell)
        (stdout, stderr) = self.process.communicate()
        if self.decode_out:
            if stdout:
                self.stdout = stdout.decode('utf-8')
            if stderr:
                self.stderr = stderr.decode('utf-8')
    thread = threading.Thread(target=target)
    thread.start()
    if (timeout > 0):
        thread.join(timeout)
        if thread.is_alive():
            self.process.terminate()
            thread.join()
            raise SubprocessError('Reached timeout after {t} seconds'.format(t=timeout))
    else:
        thread.join()
    return (self.process.returncode, self.stdout, self.stderr)

Run the subprocess.

Arguments:
timeout (optional) If a positive real value, then timout after
the given number of seconds.

Raises:
SubprocessError If subprocess has not completed after "timeout"
seconds.


def search(self, tags=None):

        if isinstance(tags, str):
            tags = [tags]
        return self.workbench.generate_sample_set(tags)

Wrapper for the Workbench search method
Args:
tags: a single tag 'pcap' or a list of tags to search for ['bad','aptz13']
Returns:
A sample_set that contains the md5s for all matching samples


def AsRegEx(self):
    parts = self.__class__.REGEX_SPLIT_PATTERN.split(self._value)
    result = u''.join((self._ReplaceRegExPart(p) for p in parts))
    return rdf_standard.RegularExpression((u'(?i)\\A%s\\Z' % result))

Return the current glob as a simple regex.

Note: No interpolation is performed.

Returns:
A RegularExpression() object.


def handle_or_else(self, orelse, test):
    if isinstance(orelse[0], ast.If):
        control_flow_node = self.visit(orelse[0])
        control_flow_node.test.label = ('el' + control_flow_node.test.label)
        test.connect(control_flow_node.test)
        return control_flow_node.last_nodes
    else:
        else_connect_statements = self.stmt_star_handler(orelse, prev_node_to_avoid=self.nodes[(- 1)])
        test.connect(else_connect_statements.first_statement)
        return else_connect_statements.last_statements

Handle the orelse part of an if or try node.

Args:
orelse(list[Node])
test(Node)

Returns:
The last nodes of the orelse branch.


def egress(self, envelope, http_headers, operation, binding_options):

    custom_headers = self._header_handler.GetHTTPHeaders()
    http_headers.update(custom_headers)
    return envelope, http_headers

Overriding the egress function to set our headers.

Args:
envelope: An Element with the SOAP request data.
http_headers: A dict of the current http headers.
operation: The SoapOperation instance.
binding_options: An options dict for the SOAP binding.

Returns:
A tuple of the envelope and headers.


def update_asset(self, asset, asset_id, asset_name, asset_type):
    if (not self.can_update()):
        self._tcex.handle_error(910, [self.type])
    if (asset == 'PHONE'):
        return self.tc_requests.update_victim_phone_asset(self.unique_id, asset_id, asset_name)
    if (asset == 'EMAIL'):
        return self.tc_requests.update_victim_email_asset(self.unique_id, asset_id, asset_name, asset_type)
    if (asset == 'NETWORK'):
        return self.tc_requests.update_victim_network_asset(self.unique_id, asset_id, asset_name, asset_type)
    if (asset == 'SOCIAL'):
        return self.tc_requests.update_victim_social_asset(self.unique_id, asset_id, asset_name, asset_type)
    if (asset == 'WEB'):
        return self.tc_requests.update_victim_web_asset(self.unique_id, asset_id, asset_name)
    self._tcex.handle_error(925, ['asset_type', 'update_asset', 'asset_type', 'asset_type', asset_type])
    return None

Update a asset of a Victim

Valid asset_type:
+ PHONE
+ EMAIL
+ NETWORK
+ SOCIAL
+ WEB

Args:
asset:
asset_name:
asset_id:
asset_type: PHONE, EMAIL, NETWORK, SOCIAL, or WEB

Returns:


def _calculate_minimum_silent_period(baudrate):
    _checkNumerical(baudrate, minvalue=1, description='baudrate')
    BITTIMES_PER_CHARACTERTIME = 11
    MINIMUM_SILENT_CHARACTERTIMES = 3.5
    bittime = (1 / float(baudrate))
    return ((bittime * BITTIMES_PER_CHARACTERTIME) * MINIMUM_SILENT_CHARACTERTIMES)

Calculate the silent period length to comply with the 3.5 character silence between messages.

Args:
baudrate (numerical): The baudrate for the serial port

Returns:
The number of seconds (float) that should pass between each message on the bus.

Raises:
ValueError, TypeError.


def wait_for(self, pattern, timeout=None):

        should_continue = True

        if self.block:
            raise TypeError(NON_BLOCKING_ERROR_MESSAGE)

        def stop(signum, frame):
            nonlocal should_continue
            if should_continue:
                raise TimeoutError()

        if timeout:
            signal.signal(signal.SIGALRM, stop)
            signal.alarm(timeout)

        while should_continue:
            output = self.poll_output() + self.poll_error()
            filtered = [line for line in output if re.match(pattern, line)]
            if filtered:
                should_continue = False

Block until a pattern have been found in stdout and stderr

Args:
pattern(:class:`~re.Pattern`): The pattern to search
timeout(int): Maximum number of second to wait. If None, wait infinitely

Raises:
TimeoutError: When timeout is reach


def try_to_create_directory(directory_path):

    logger = logging.getLogger("ray")
    directory_path = os.path.expanduser(directory_path)
    if not os.path.exists(directory_path):
        try:
            os.makedirs(directory_path)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise e
            logger.warning(
                "Attempted to create '{}', but the directory already "
                "exists.".format(directory_path))

    try:
        os.chmod(directory_path, 0o0777)
    except OSError as e:

        if e.errno in [errno.EACCES, errno.EPERM]:
            pass
        else:
            raise

Attempt to create a directory that is globally readable/writable.

Args:
directory_path: The path of the directory to create.


def get_coordination_service_leader(self):
    return '/job:' + self.get_job_name() + '/task:0'

Returns the location for coordination service.

The coordination service should be located on TPU worker0.

Returns:
A string indicate the location path.


def set_global(cls, user_agent=None, user_agent_config_yaml=None,
                   user_agent_lookup=None, **kwargs):

        cls.user_agent = cls._create(user_agent, user_agent_config_yaml, user_agent_lookup, **kwargs)

Set global user agent string

Args:
user_agent (Optional[str]): User agent string. HDXPythonLibrary/X.X.X- is prefixed.
user_agent_config_yaml (Optional[str]): Path to YAML user agent configuration. Ignored if user_agent supplied. Defaults to ~/.useragent.yml.
user_agent_lookup (Optional[str]): Lookup key for YAML. Ignored if user_agent supplied.

Returns:
None


def GetVShadowStoreByPathSpec(self, path_spec):

    store_index = vshadow.VShadowPathSpecGetStoreIndex(path_spec)
    if store_index is None:
      return None

    return self._vshadow_volume.get_store(store_index)

Retrieves a VSS store for a path specification.

Args:
path_spec (PathSpec): path specification.

Returns:
pyvshadow.store: a VSS store or None if not available.


def connect_from(self, vertex, weight=1):

        for edge in self.edges_in:
            if vertex == edge.vertex_out:
                return edge
        return Edge(vertex, self, weight)

Connect another vertex to this one.

Args:
vertex (Vertex): vertex to connect from.
weight (int): weight of the edge.

Returns:
Edge: the newly created edge.


def find_furious_yaml(config_file=__file__):

    checked = set()
    result = _find_furious_yaml(os.path.dirname(config_file), checked)
    if not result:
        result = _find_furious_yaml(os.getcwd(), checked)
    return result

Traverse directory trees to find a furious.yaml file

Begins with the location of this file then checks the
working directory if not found

Args:
config_file: location of this file, override for
testing
Returns:
the path of furious.yaml or None if not found


def create_feature_map(features, feature_indices, output_dir):
    feature_map = []
    for (name, info) in feature_indices:
        transform_name = features[name]['transform']
        source_column = features[name]['source_column']
        if (transform_name in [IDENTITY_TRANSFORM, SCALE_TRANSFORM]):
            feature_map.append((info['index_start'], name))
        elif (transform_name in [ONE_HOT_TRANSFORM, MULTI_HOT_TRANSFORM]):
            (vocab, _) = read_vocab_file(os.path.join(output_dir, (VOCAB_ANALYSIS_FILE % source_column)))
            for (i, word) in enumerate(vocab):
                if (transform_name == ONE_HOT_TRANSFORM):
                    feature_map.append(((info['index_start'] + i), ('%s=%s' % (source_column, word))))
                elif (transform_name == MULTI_HOT_TRANSFORM):
                    feature_map.append(((info['index_start'] + i), ('%s has "%s"' % (source_column, word))))
        elif (transform_name == IMAGE_TRANSFORM):
            for i in range(info['size']):
                feature_map.append(((info['index_start'] + i), ('%s image feature %d' % (source_column, i))))
    return feature_map

Returns feature_map about the transformed features.

feature_map includes information such as:
1, cat1=0
2, cat1=1
3, numeric1
...
Returns:
List in the from
[(index, feature_description)]


def correlate(x1, x2, mode='valid'):
    if any_symbolic_tensors((x1, x2)):
        return Correlate(mode=mode).symbolic_call(x1, x2)
    return backend.numpy.correlate(x1, x2, mode=mode)

Compute the cross-correlation of two 1-dimensional tensors.

Args:
x1: First 1-dimensional input tensor of length M.
x2: Second 1-dimensional input tensor of length N.
mode: Either `valid`, `same` or `full`.
By default the mode is set to `valid`, which returns
an output of length max(M, N) - min(M, N) + 1.
`same` returns an output of length max(M, N).
`full` mode returns the convolution at each point of
overlap, with an output length of N+M-1

Returns:
Output tensor, cross-correlation of `x1` and `x2`.


def is_value_type_valid_for_exact_conditions(self, value):

    if isinstance(value, string_types) or isinstance(value, (numbers.Integral, float)):
      return True

    return False

Method to validate if the value is valid for exact match type evaluation.

Args:
value: Value to validate.

Returns:
Boolean: True if value is a string, boolean, or number. Otherwise False.


def merge(inputs, name=None):
    if any((inp is None for inp in inputs)):
        raise ValueError('At least one of the merge inputs is None: %s' % inputs)
    with ops.name_scope(name, 'Merge', inputs) as name:
        inputs = [ops.internal_convert_to_tensor_or_composite(inp, as_ref=True) for inp in inputs]
        if all((isinstance(v, tensor_lib.Tensor) for v in inputs)):
            if all((v.dtype._is_ref_dtype for v in inputs)):
                return gen_control_flow_ops.ref_merge(inputs, name)
            else:
                return gen_control_flow_ops.merge(inputs, name)
        else:
            if all((isinstance(v, (indexed_slices.IndexedSlices, tensor_lib.Tensor)) for v in inputs)):
                inputs = math_ops._as_indexed_slices_list(inputs, optimize=False)
            for v in inputs:
                if not isinstance(v, composite_tensor.CompositeTensor):
                    raise TypeError('Type %s not supported' % type(v))
            for v in inputs[1:]:
                nest.assert_same_structure(inputs[0], v, expand_composites=True)
            flat_inputs = [nest.flatten(v, expand_composites=True) for v in inputs]
            merged_results = [gen_control_flow_ops.merge(component) for component in zip(*flat_inputs)]
            flat_merged = [tensor for tensor, _ in merged_results]
            chosen_index = merged_results[0][1]
            merged_inputs = nest.pack_sequence_as(inputs[0], flat_merged, expand_composites=True)
            return (merged_inputs, chosen_index)

Returns the value of an available element of `inputs`.

This op tests each of the tensors in `inputs` in turn to determine if any of
them is available. If it finds an available tensor, it returns it and its
index in `inputs`.

It is an error if more than one tensor in `inputs` is available. If no tensor
in `inputs` is available, the returned tensor and index are not set.

This op handles both `Tensor`s and `IndexedSlices`. If inputs has a mix of
`Tensor`s and `IndexedSlices`, all inputs are converted to IndexedSlices
before merging.

Args:
inputs: The input tensors, at most one of which is available.
name: A name for this operation (optional).

Returns:
A tuple containing the chosen input tensor and its index in `inputs`.

Raises:
ValueError: If any of the inputs is None, or inputs are IndexedSlices and
some but not all have a dense_shape property.


def hkl_transformation(transf, miller_index):

    lcm = lambda a, b: a * b
    reduced_transf = reduce(lcm, [int(1 / i) for i in itertools.chain(*transf) if i != 0]) * transf
    reduced_transf = reduced_transf.astype(int)

    t_hkl = np.dot(reduced_transf, miller_index)
    d = abs(reduce(gcd, t_hkl))
    t_hkl = np.array([int(i / d) for i in t_hkl])

    if len([i for i in t_hkl if i < 0]) > 1:
        t_hkl *= -1

    return tuple(t_hkl)

Returns the Miller index from setting
A to B using a transformation matrix
Args:
transf (3x3 array): The transformation matrix
that transforms a lattice of A to B
miller_index ([h, k, l]): Miller index to transform to setting B


def MeshViewers(shape=(1, 1), titlebar='Mesh Viewers', keepalive=False, window_width=1280, window_height=960):
    if (not test_for_opengl()):
        return Dummy()
    mv = MeshViewerLocal(shape=shape, titlebar=titlebar, uid=None, keepalive=keepalive, window_width=window_width, window_height=window_height)
    return mv.get_subwindows()

Allows subplot-style inspection of primitives in multiple subwindows.

Args:
shape: a tuple indicating the number of vertical and horizontal windows requested

Returns: a list of lists of MeshViewer objects: one per window requested.


def get_propagator(name):
    from .sgp4 import Sgp4
    from .sgp4beta import Sgp4Beta
    scope = locals().copy()
    scope.update(globals())
    if (name not in scope):
        raise UnknownPropagatorError(name)
    return scope[name]

Retrieve a named propagator

Args:
name (str): Name of the desired propagator
Return:
Propagator class


def set_examples(self, examples):
    self.store('examples', examples)
    if (len(examples) > 0):
        self.store('are_sequence_examples', isinstance(examples[0], tf.train.SequenceExample))
    return self

Sets the examples to be displayed in WIT.

Args:
examples: List of example protos.

Returns:
self, in order to enabled method chaining.


def load_words(self, words):
    self._dictionary.update([word.lower() for word in words])
    self._update_dictionary()

Load a list of words from which to generate a word frequency list

Args:
words (list): The list of words to be loaded


def init_pool_generator(gens, random_seed=None, id_queue=None):
    global _SHARED_SEQUENCES
    _SHARED_SEQUENCES = gens
    worker_proc = multiprocessing.current_process()
    worker_proc.name = 'Keras_worker_{}'.format(worker_proc.name)
    if random_seed is not None:
        np.random.seed(random_seed + worker_proc.ident)
    if id_queue is not None:
        id_queue.put(worker_proc.ident, block=True, timeout=0.1)

Initializer function for pool workers.

Args:
gens: State which should be made available to worker processes.
random_seed: An optional value with which to seed child processes.
id_queue: A multiprocessing Queue of worker ids. This is used to indicate
that a worker process was created by Keras and can be terminated using
the cleanup_all_keras_forkpools utility.


def halted(self):
    result = int(self._dll.JLINKARM_IsHalted())
    if (result < 0):
        raise errors.JLinkException(result)
    return (result > 0)

Returns whether the CPU core was halted.

Args:
self (JLink): the ``JLink`` instance

Returns:
``True`` if the CPU core is halted, otherwise ``False``.

Raises:
JLinkException: on device errors.


def cli_cmd_to_string(args):
    if isinstance(args, basestring):
        return args
    return ' '.join([pipes.quote(arg) for arg in args])

Converts a cmd arg list to string.

Args:
args: list of strings, the arguments of a command.

Returns:
String representation of the command.


def list_offers(access_token, subscription_id, location, publisher):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/providers/Microsoft.Compute/',
                        'locations/', location,
                        '/publishers/', publisher,
                        '/artifacttypes/vmimage/offers?api-version=', COMP_API])
    return do_get(endpoint, access_token)

List available VM image offers from a publisher.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
location (str): Azure data center location. E.g. westus.
publisher (str): Publisher name, e.g. Canonical.

Returns:
HTTP response with JSON list of image offers.


def write_index(self, overwrite: bool = False, mock: bool = False) -> None:

        write_if_allowed(self.index_filename, self.index_content(),
                         overwrite=overwrite, mock=mock)

Writes the index file, if permitted.

Args:
overwrite: allow existing files to be overwritten?
mock: pretend to write, but don't


def parse_radl(data):
    if (data is None):
        return None
    elif os.path.isfile(data):
        f = open(data)
        data = ''.join(f.readlines())
        f.close()
    elif (data.strip() == ''):
        return RADL()
    data = (data + '\n')
    parser = RADLParser(lextab='radl')
    return parser.parse(data)

Parse a RADL document.

Args:
- data(str): filepath to a RADL content or a string with content.

Return: RADL object.


def _interactive_input_tensor_to_features_dict(feature_map, hparams):

  inputs = tf.convert_to_tensor(feature_map["inputs"])
  input_is_image = False if len(inputs.get_shape()) < 3 else True

  x = inputs
  if input_is_image:
    x = tf.image.resize_images(x, [299, 299])
    x = tf.reshape(x, [1, 299, 299, -1])
    x = tf.to_int32(x)
  else:

    num_samples = x[0]
    length = x[2]
    x = tf.slice(x, [3], tf.to_int32([length]))
    x = tf.reshape(x, [1, -1, 1, 1])

    x = tf.tile(x, tf.to_int32([num_samples, 1, 1, 1]))

  p_hparams = hparams.problem_hparams
  input_space_id = tf.constant(p_hparams.input_space_id)
  target_space_id = tf.constant(p_hparams.target_space_id)

  features = {}
  features["input_space_id"] = input_space_id
  features["target_space_id"] = target_space_id
  features["decode_length"] = (
      IMAGE_DECODE_LENGTH if input_is_image else inputs[1])
  features["inputs"] = x
  return features

Convert the interactive input format (see above) to a dictionary.

Args:
feature_map: dict with inputs.
hparams: model hyperparameters

Returns:
a features dictionary, as expected by the decoder.


def __init__(self, name: str, func: Callable[..., T], args: Iterable[Expression], proxy: Optional[T]=None, _id: Optional[str]=None, requires_partition_by: partitionings.Partitioning=partitionings.Index(), preserves_partition_by: partitionings.Partitioning=partitionings.Singleton()):
    if not _get_allow_non_parallel() and isinstance(requires_partition_by, partitionings.Singleton):
        reason = requires_partition_by.reason or f'Encountered non-parallelizable form of {name!r}.'
        raise NonParallelOperation(f"{reason}\nConsider using an allow_non_parallel_operations block if you're sure you want to do this. See https:
    args = tuple(args)
    if proxy is None:
        proxy = func(*(arg.proxy() for arg in args))
    super().__init__(name, proxy, _id)
    self._func = func
    self._args = args
    self._requires_partition_by = requires_partition_by
    self._preserves_partition_by = preserves_partition_by

Initialize a computed expression.

Args:
name: The name of this expression.
func: The function that will be used to compute the value of this
expression. Should accept arguments of the types returned when
evaluating the `args` expressions.
args: The list of expressions that will be used to produce inputs to
`func`.
proxy: (Optional) a proxy object with same type as the objects that this
ComputedExpression will produce at execution time. If not provided, a
proxy will be generated using `func` and the proxies of `args`.
_id: (Optional) a string to uniquely identify this expression.
requires_partition_by: The required (common) partitioning of the args.
preserves_partition_by: The level of partitioning preserved.


def __init__(self, matrix: np.ndarray) -> None:

        if matrix.shape != (2, 2) or not linalg.is_unitary(matrix):
            raise ValueError('Not a 2x2 unitary matrix: {}'.format(matrix))
        self._matrix = matrix

Initializes the 2-qubit matrix gate.

Args:
matrix: The matrix that defines the gate.


def update( self, jump ):

        atom = jump.initial_site.atom
        dr = jump.dr( self.cell_lengths )

        jump.final_site.occupation = atom.number
        jump.final_site.atom = atom
        jump.final_site.is_occupied = True
        jump.initial_site.occupation = 0
        jump.initial_site.atom = None
        jump.initial_site.is_occupied = False

        atom.site = jump.final_site
        atom.number_of_hops += 1
        atom.dr += dr
        atom.summed_dr2 += np.dot( dr, dr )

Update the lattice state by accepting a specific jump

Args:
jump (Jump): The jump that has been accepted.

Returns:
None.


def replace_output(self, output, tag=None):
    if isinstance(output, pvalue.DoOutputsTuple):
        self.replace_output(output[output._main_tag])
    elif isinstance(output, pvalue.PValue):
        self.outputs[tag] = output
    elif isinstance(output, dict):
        for output_tag, out in output.items():
            self.outputs[output_tag] = out
    else:
        raise TypeError('Unexpected output type: %s' % output)
    from apache_beam.transforms import external
    if isinstance(self.transform, external.ExternalTransform):
        self.transform.replace_named_outputs(self.named_outputs())

Replaces the output defined by the given tag with the given output.

Args:
output: replacement output
tag: tag of the output to be replaced.


def _parse_trunk_groups(self, config):
    values = TRUNK_GROUP_RE.findall(config)
    return dict(trunk_groups=values)

_parse_trunk_groups scans the provided configuration block and
extracts all the vlan trunk groups.  If no trunk groups are configured
an empty List is returned as the vlaue.  The return dict is intended
to be merged into the response dict.

Args:
config (str): The vlan configuration block form the node's
running configuration

Returns:
dict: resource dict attribute


def on_merge(self, to_be_merged, merge_result, context):
    pass

Called when multiple windows are merged.

Args:
to_be_merged: the set of windows to be merged
merge_result: the window into which the windows are being merged
context: a context (e.g. a TriggerContext instance) for managing state
and setting timers


def get_snapshot_by(self, volume_id_or_uri, field, value):

        uri = self.__build_volume_snapshot_uri(volume_id_or_uri)
        return self._client.get_by(field, value, uri=uri)

Gets all snapshots that match the filter.

The search is case-insensitive.

Args:
volume_id_or_uri: Can be either the volume id or the volume uri.
field: Field name to filter.
value: Value to filter.

Returns:
list: Snapshots


def cumprod(vari, axis=None):
    if isinstance(vari, Poly):
        if (np.prod(vari.shape) == 1):
            return vari.copy()
        if (axis is None):
            vari = chaospy.poly.shaping.flatten(vari)
            axis = 0
        vari = chaospy.poly.shaping.rollaxis(vari, axis)
        out = [vari[0]]
        for poly in vari[1:]:
            out.append((out[(- 1)] * poly))
        return Poly(out, vari.dim, vari.shape, vari.dtype)
    return np.cumprod(vari, axis)

Perform the cumulative product of a shapeable quantity over a given axis.

Args:
vari (chaospy.poly.base.Poly, numpy.ndarray):
Input data.
axis (int):
Axis over which the sum is taken. By default ``axis`` is None, and
all elements are summed.

Returns:
(chaospy.poly.base.Poly):
An array shaped as ``vari`` but with the specified axis removed.

Examples:
>>> vari = cp.prange(4)
>>> print(vari)
[1, q0, q0^2, q0^3]
>>> print(cp.cumprod(vari))
[1, q0, q0^3, q0^6]


Element-wise log.

Args:
x: Tensor or variable.

Returns:
A tensor.