def CancelBatchJob(client, batch_job, max_poll_attempts=MAX_POLL_ATTEMPTS):

  batch_job_service = client.GetService('BatchJobService', 'v201809')
  batch_job['status'] = 'CANCELING'

  operation = {
      'operator': 'SET',
      'operand': batch_job
  }

  batch_job_service.mutate([operation])

  poll_attempt = 0

  while (poll_attempt in range(max_poll_attempts) and
         batch_job['status'] != 'CANCELED'):
    sleep_interval = (30 * (2 ** poll_attempt) +
                      (random.randint(0, 10000) / 1000))
    print ('Batch Job not finished canceling, sleeping for %s seconds.'
           % sleep_interval)
    time.sleep(sleep_interval)
    batch_job = GetBatchJob(client, batch_job['id'])
    poll_attempt += 1

  if batch_job['status'] == 'CANCELED':
    print ('Batch Job with ID "%d" has been successfully canceled.' %
           batch_job['id'])
  else:
    print ('Batch Job with ID "%d" failed to cancel after polling %d times.'
           % (batch_job['id'], max_poll_attempts))

Cancels the given BatchJob.

Args:
client: an instantiated AdWordsClient used to cancel the BatchJob.
batch_job: a BatchJob to be canceled.
max_poll_attempts: an int defining the number of times the BatchJob will be
checked to determine whether it has been canceled.


def override_args(**kwargs):

  override_kwargs = kwargs

  def custom_getter(getter, *args, **kwargs):

    kwargs.update(override_kwargs)
    return getter(*args, **kwargs)

  return custom_getter

Creates a custom getter that applies specified named arguments.

Args:
**kwargs: Overriding arguments for the custom getter to use in preference
the named arguments it's called with.

Returns:
Custom getter.


def raw(self, file_path, ref, streamed=False, action=None, chunk_size=1024, **kwargs):
    file_path = file_path.replace('/', '%2F').replace('.', '%2E')
    path = ('%s/%s/raw' % (self.path, file_path))
    query_data = {'ref': ref}
    result = self.gitlab.http_get(path, query_data=query_data, streamed=streamed, raw=True, **kwargs)
    return utils.response_content(result, streamed, action, chunk_size)

Return the content of a file for a commit.

Args:
ref (str): ID of the commit
filepath (str): Path of the file to return
streamed (bool): If True the data will be processed by chunks of
`chunk_size` and each chunk is passed to `action` for
treatment
action (callable): Callable responsible of dealing with chunk of
data
chunk_size (int): Size of each chunk
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the file could not be retrieved

Returns:
str: The file content


def floordiv(x, y, name=None):
    with ops.name_scope(name, 'floordiv', [x, y]) as name:
        return gen_math_ops.floor_div(x, y, name=name)

Divides `x / y` elementwise, rounding toward the most negative integer.

Mathematically, this is equivalent to floor(x / y). For example:
floor(8.4 / 4.0) = floor(2.1) = 2.0
floor(-8.4 / 4.0) = floor(-2.1) = -3.0
This is equivalent to the '//' operator in Python 3.0 and above.

Note: `x` and `y` must have the same type, and the result will have the same
type as well.

Args:
x: `Tensor` numerator of real numeric type.
y: `Tensor` denominator of real numeric type.
name: A name for the operation (optional).

Returns:
`x / y` rounded toward -infinity.

Raises:
TypeError: If the inputs are complex.


def get_sorted_source_files(
            self,
            source_filenames_or_globs: Union[str, List[str]],
            recursive: bool = True) -> List[str]:

        if isinstance(source_filenames_or_globs, str):
            source_filenames_or_globs = [source_filenames_or_globs]
        final_filenames = []
        for sfg in source_filenames_or_globs:
            sfg_expanded = expanduser(sfg)
            log.debug("Looking for: {!r}", sfg_expanded)
            for filename in glob.glob(sfg_expanded, recursive=recursive):
                log.debug("Trying: {!r}", filename)
                if self.should_exclude(filename):
                    log.info("Skipping file {!r}", filename)
                    continue
                final_filenames.append(filename)
        final_filenames.sort()
        return final_filenames

Returns a sorted list of filenames to process, from a filename,
a glob string, or a list of filenames/globs.

Args:
source_filenames_or_globs: filename/glob, or list of them
recursive: use :func:`glob.glob` in recursive mode?

Returns:
sorted list of files to process


def parse_mimetype(cls, value):
    match = re.match('([a-zA-Z0-9-]+/[a-zA-Z0-9-]+)', value)
    if match:
        return match.group(1)

Return the MIME type from a Content-Type string.

Returns:
str, None: A string in the form ``type/subtype`` or None.


def list_directory(dirname):
    return list_directory_v2(dirname)

Returns a list of entries contained within a directory.

The list is in arbitrary order. It does not contain the special entries "."
and "..".

Args:
dirname: string, path to a directory

Returns:
[filename1, filename2, ... filenameN] as strings

Raises:
errors.NotFoundError if directory doesn't exist


def FB(circuit, *, out_port=None, in_port=None):

    if out_port is None:
        out_port = circuit.cdim - 1
    if in_port is None:
        in_port = circuit.cdim - 1
    return Feedback.create(circuit, out_port=out_port, in_port=in_port)

Wrapper for :class:`.Feedback`, defaulting to last channel

Args:
circuit (Circuit): The circuit that undergoes self-feedback
out_port (int): The output port index, default = None --> last port
in_port (int): The input port index, default = None --> last port

Returns:
Circuit: The circuit with applied feedback operation.


def set_dft_grid(self, radical_points=128, angular_points=302, grid_type='Lebedev'):
    available_lebedev_angular_points = {6, 18, 26, 38, 50, 74, 86, 110, 146, 170, 194, 230, 266, 302, 350, 434, 590, 770, 974, 1202, 1454, 1730, 2030, 2354, 2702, 3074, 3470, 3890, 4334, 4802, 5294}
    if (grid_type.lower() == 'sg-0'):
        self.params['rem']['xc_grid'] = 0
    elif (grid_type.lower() == 'sg-1'):
        self.params['rem']['xc_grid'] = 1
    elif (grid_type.lower() == 'lebedev'):
        if (angular_points not in available_lebedev_angular_points):
            raise ValueError((str(angular_points) + ' is not a valid Lebedev angular points number'))
        self.params['rem']['xc_grid'] = '{rp:06d}{ap:06d}'.format(rp=radical_points, ap=angular_points)
    elif (grid_type.lower() == 'gauss-legendre'):
        self.params['rem']['xc_grid'] = '-{rp:06d}{ap:06d}'.format(rp=radical_points, ap=angular_points)
    else:
        raise ValueError((('Grid type ' + grid_type) + ' is not supported currently'))

Set the grid for DFT numerical integrations.

Args:
radical_points: Radical points. (Integer)
angular_points: Angular points. (Integer)
grid_type: The type of of the grid. There are two standard grids:
SG-1 and SG-0. The other two supported grids are "Lebedev" and
"Gauss-Legendre"


def disable_plugin(self, name):

        url = self._url('/plugins/{0}/disable', name)
        res = self._post(url)
        self._raise_for_status(res)
        return True

Disable an installed plugin.

Args:
name (string): The name of the plugin. The ``:latest`` tag is
optional, and is the default if omitted.

Returns:
``True`` if successful


def visualize_qualitative_analysis(inputs, model, samples=1, batch_size=3,
                                   length=8):

  average = lambda dist: tf.reduce_mean(
      input_tensor=dist.mean(), axis=0)
  with tf.compat.v1.name_scope("val_reconstruction"):
    reconstruct = functools.partial(model.reconstruct, inputs=inputs,
                                    samples=samples)
    visualize_reconstruction(inputs, average(reconstruct()))
    visualize_reconstruction(inputs, average(reconstruct(sample_static=True)),
                             name="static_prior")
    visualize_reconstruction(inputs, average(reconstruct(sample_dynamic=True)),
                             name="dynamic_prior")
    visualize_reconstruction(inputs, average(reconstruct(swap_static=True)),
                             name="swap_static")
    visualize_reconstruction(inputs, average(reconstruct(swap_dynamic=True)),
                             name="swap_dynamic")

  with tf.compat.v1.name_scope("generation"):
    generate = functools.partial(model.generate, batch_size=batch_size,
                                 length=length, samples=samples)
    image_summary(average(generate(fix_static=True)), "fix_static")
    image_summary(average(generate(fix_dynamic=True)), "fix_dynamic")

Visualizes a qualitative analysis of a given model.

Args:
inputs: A tensor of the original inputs, of shape [batch, timesteps,
h, w, c].
model: A DisentangledSequentialVAE model.
samples: Number of samples to draw from the latent distributions.
batch_size: Number of sequences to generate.
length: Number of timesteps to generate for each sequence.


def local(self):
    assert (self.name in CFG['container']['images'].value)
    tmp_dir = local.path(str(CFG['tmp_dir']))
    target_dir = (tmp_dir / self.name)
    if ((not target_dir.exists()) or (not is_valid(self, target_dir))):
        unpack(self, target_dir)
    return target_dir

Finds the current location of a container.
Also unpacks the project if necessary.

Returns:
target: The path, where the container lies in the end.


def merge(self, other):

        for attr in self.attrs:
            if not getattr(other, attr, None) is None:
                setattr(self, attr, getattr(other, attr))
        if other.raw:
            if not self.raw:
                self.raw = {}
            self.raw.update(other.raw)

Copy properties from other into self, skipping ``None`` values.  Also merges the raw data.

Args:
other (SkypeObj): second object to copy fields from


def get_padding(x, padding_value=0):

  with tf.name_scope("padding"):
    return tf.to_float(tf.equal(x, padding_value))

Return float tensor representing the padding values in x.

Args:
x: int tensor with any shape
padding_value: int value that

Returns:
flaot tensor with same shape as x containing values 0 or 1.
0 -> non-padding, 1 -> padding


def score(self, y_true, y_pred):

        score = f1_score(y_true, y_pred)
        print(' - f1: {:04.2f}'.format(score * 100))
        print(classification_report(y_true, y_pred, digits=4))
        return score

Calculate f1 score.

Args:
y_true (list): true sequences.
y_pred (list): predicted sequences.

Returns:
score: f1 score.


def HasDynamicInvoke(self):
    from neo.Core.State.ContractState import ContractPropertyState
    return ((self.ContractProperties & ContractPropertyState.HasDynamicInvoke) > 0)

Flag indicating if dynamic invocation is supported.

Returns:
bool: True if supported. False otherwise.


def __init__(self, old_module_name, new_module_name):
    super().__init__()
    if not old_module_name:
        raise ValueError('old_module_name must be a non empty string.')
    assert not old_module_name.endswith('.')
    assert not new_module_name.endswith('.')
    self._module_name = new_module_name
    self._old = old_module_name + '.' if old_module_name else ''
    self._new = new_module_name + '.' if new_module_name else ''

Constructor.

Args:
old_module_name: The old name of the module as a string, e.g.
"foo.bar.module1"
new_module_name: The new name of the module as a string, e.g.
"barfoo.module2"

Raises:
ValueError: If the old_module name is an empty string.


def _add_partition(self, connection, partition):
    logger.debug('Creating virtual table for partition.\n    partition: {}'.format(partition.name))
    sqlite_med.add_partition(connection, partition.datafile, (partition.vid + '_vt'))

Creates sqlite virtual table for mpr file of the given partition.

Args:
connection: connection to the sqlite db who stores mpr data.
partition (orm.Partition):


def get_actor(name):
    actor_name = _calculate_key(name)
    pickled_state = _internal_kv_get(actor_name)
    if (pickled_state is None):
        raise ValueError("The actor with name={} doesn't exist".format(name))
    handle = pickle.loads(pickled_state)
    return handle

Get a named actor which was previously created.

If the actor doesn't exist, an exception will be raised.

Args:
name: The name of the named actor.

Returns:
The ActorHandle object corresponding to the name.


def CheckDataStoreAccess(self, token, subjects, requested_access='r'):
    logging.debug('Checking %s: %s for %s', token, subjects, requested_access)
    raise NotImplementedError()

The main entry point for checking access to AFF4 resources.

Args:
token: An instance of ACLToken security token.

subjects: The list of subject URNs which the user is requesting access
to. If any of these fail, the whole request is denied.

requested_access: A string specifying the desired level of access ("r" for
read and "w" for write, "q" for query).

Raises:
UnauthorizedAccess: If the user is not authorized to perform the action
on any of the subject URNs.


def _convert_observ(self, observ):

    if not np.isfinite(observ).all():
      raise ValueError('Infinite observation encountered.')
    if observ.dtype == np.float64:
      return observ.astype(np.float32)
    if observ.dtype == np.int64:
      return observ.astype(np.int32)
    return observ

Convert the observation to 32 bits.

Args:
observ: Numpy observation.

Raises:
ValueError: Observation contains infinite values.

Returns:
Numpy observation with 32-bit data type.


def _write_move_counts(self, sess, h):

    def gen():
        for (k, v) in h.items():
            k = str(k, 'utf-8')
            vs = str(v)
            (yield ((k.replace('g_', 'ct_') + ('_%d' % v)), vs))
            (yield ((k + '_m_000'), vs))
    mc = tf.data.Dataset.from_generator(gen, (tf.string, tf.string))
    wr_op = self.tf_table.write(mc, column_families=[METADATA], columns=[MOVE_COUNT])
    sess.run(wr_op)

Add move counts from the given histogram to the table.

Used to update the move counts in an existing table.  Should
not be needed except for backfill or repair.

Args:
sess:  TF session to use for doing a Bigtable write.
tf_table:  TF Cloud Bigtable to use for writing.
h:  a dictionary keyed by game row prefix ("g_0023561") whose values
are the move counts for each game.


def from_specification(cls, specification, model, classical_gap, ground_energy):
    return cls(specification.graph, specification.decision_variables, specification.feasible_configurations, specification.vartype, model, classical_gap, ground_energy, ising_linear_ranges=specification.ising_linear_ranges, ising_quadratic_ranges=specification.ising_quadratic_ranges)

Construct a PenaltyModel from a Specification.

Args:
specification (:class:`.Specification`): A specification that was used
to generate the model.
model (:class:`dimod.BinaryQuadraticModel`): A binary quadratic model
that has ground states that match the feasible_configurations.
classical_gap (numeric): The difference in classical energy between the ground
state and the first excited state. Must be positive.
ground_energy (numeric): The minimum energy of all possible configurations.

Returns:
:class:`.PenaltyModel`


def upgrade_plugin(self, name, remote, privileges):
    url = self._url('/plugins/{0}/upgrade', name)
    params = {'remote': remote}
    headers = {}
    (registry, repo_name) = auth.resolve_repository_name(remote)
    header = auth.get_config_header(self, registry)
    if header:
        headers['X-Registry-Auth'] = header
    response = self._post_json(url, params=params, headers=headers, data=privileges, stream=True)
    self._raise_for_status(response)
    return self._stream_helper(response, decode=True)

Upgrade an installed plugin.

Args:
name (string): Name of the plugin to upgrade. The ``:latest``
tag is optional and is the default if omitted.
remote (string): Remote reference to upgrade to. The
``:latest`` tag is optional and is the default if omitted.
privileges (:py:class:`list`): A list of privileges the user
consents to grant to the plugin. Can be retrieved using
:py:meth:`~plugin_privileges`.

Returns:
An iterable object streaming the decoded API logs


def search(self, index_name, query):

        try:
            results = self.els_search.search(index=index_name, body=query)
            return results
        except Exception, error:
            error_str = 'Query failed: %s\n' % str(error)
            error_str += '\nIs there a dynamic script in the query?, see www.elasticsearch.org'
            print error_str
            raise RuntimeError(error_str)

Search the given index_name with the given ELS query.

Args:
index_name: Name of the Index
query: The string to be searched.

Returns:
List of results.

Raises:
RuntimeError: When the search query fails.


def get_keys(data_list, leading_columns=LEADING_COLUMNS):
    all_keys = set().union(*(list(d.keys()) for d in data_list))
    leading_keys = []
    for key in leading_columns:
        if (key not in all_keys):
            continue
        leading_keys.append(key)
        all_keys.remove(key)
    return (leading_keys + sorted(all_keys))

Gets all possible keys from a list of dicts, sorting by leading_columns first

Args:
data_list: list of dicts to pull keys from
leading_columns: list of keys to put first in the result

Returns:
list of keys to be included as columns in excel worksheet


def __getattr__(self, action):

        def _dispatcher(self, *args, **kwargs):

            return self.send_command(action, *args, **kwargs)

        _dispatcher.__name__ = action

        method = _dispatcher.__get__(self, self.__class__)

        setattr(self, action, method)
        log.debug("Dispatching method %s", action)

        return method

Called when a method on the instance cannot be found.

Causes an action to be sent to UPnP server. See also
`object.__getattr__`.

Args:
action (str): The name of the unknown method.
Returns:
callable: The callable to be invoked. .


class RepeatVector(Layer):

    def __init__(self, n, **kwargs):
        super(RepeatVector, self).__init__(**kwargs)
        self.n = n
        if not isinstance(n, int):
            raise TypeError(f'Expected an integer value for `n`, got {type(n)}.')
        self.input_spec = InputSpec(ndim=2)

    def compute_output_shape(self, input_shape):
        input_shape = tensor_shape.TensorShape(input_shape).as_list()
        return tensor_shape.TensorShape([input_shape[0], self.n, input_shape[1]])

    def call(self, inputs):
        return K.repeat(inputs, self.n)

    def get_config(self):
        config = {'n': self.n}
        base_config = super(RepeatVector, self).get_config()
        return dict(list(base_config.items()) + list(config.items()))

Repeats the input n times.

Example:

```python
model = Sequential()
model.add(Dense(32, input_dim=32))
# now: model.output_shape == (None, 32)
# note: `None` is the batch dimension

model.add(RepeatVector(3))
# now: model.output_shape == (None, 3, 32)
```

Args:
n: Integer, repetition factor.

Input shape:
2D tensor of shape `(num_samples, features)`.

Output shape:
3D tensor of shape `(num_samples, n, features)`.


def from_json(cls, data):

        assert 'header' in data, 'Required keyword "header" is missing!'
        assert 'values' in data, 'Required keyword "values" is missing!'
        assert 'datetimes' in data, 'Required keyword "datetimes" is missing!'
        collection = cls(Header.from_json(data['header']), data['values'],
                         [DateTime.from_json(dat) for dat in data['datetimes']])
        if 'validated_a_period' in data:
            collection._validated_a_period = data['validated_a_period']
        return collection

Create a Data Collection from a dictionary.

Args:
{
"header": A Ladybug Header,
"values": An array of values,
"datetimes": An array of datetimes,
"validated_a_period": Boolean for whether header analysis_period is valid
}


def chosen_angle_to_half_turns(half_turns: Optional[Union[(sympy.Basic, float)]]=None, rads: Optional[float]=None, degs: Optional[float]=None, default: float=1.0) -> Union[(sympy.Basic, float)]:
    if (len([1 for e in [half_turns, rads, degs] if (e is not None)]) > 1):
        raise ValueError('Redundant angle specification. Use ONE of half_turns, rads, or degs.')
    if (rads is not None):
        return (rads / np.pi)
    if (degs is not None):
        return (degs / 180)
    if (half_turns is not None):
        return half_turns
    return default

Returns a half_turns value based on the given arguments.

At most one of half_turns, rads, degs must be specified. If none are
specified, the output defaults to half_turns=1.

Args:
half_turns: The number of half turns to rotate by.
rads: The number of radians to rotate by.
degs: The number of degrees to rotate by
default: The half turns angle to use if nothing else is specified.

Returns:
A number of half turns.


def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):

        super(Authentication, self).read(
            input_stream,
            kmip_version=kmip_version
        )
        local_stream = utils.BytearrayStream(input_stream.read(self.length))

        credentials = []
        while self.is_tag_next(enums.Tags.CREDENTIAL, local_stream):
            credential = objects.Credential()
            credential.read(local_stream, kmip_version=kmip_version)
            credentials.append(credential)
        if len(credentials) == 0:
            raise ValueError("Authentication encoding missing credentials.")
        self._credentials = credentials

        self.is_oversized(local_stream)

Read the data encoding the Authentication 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.


def resize(self, size_gigabytes, region):

        return self.get_data(
            "volumes/%s/actions/" % self.id,
            type=POST,
            params={"type": "resize",
                    "size_gigabytes": size_gigabytes,
                    "region": region}
        )

Detach a Volume to a Droplet.

Args:
size_gigabytes: int - size of the Block Storage volume in GiB
region: string - slug identifier for the region


def _load_plugins(namespace, instantiate=True):

    mgr = ExtensionManager(
        namespace=namespace,
        on_load_failure_callback=(
            lambda _, ep, err: LOGGER.
            warning('Could not load plugin {}: {}'.format(ep.name, err))
        )
    )
    if instantiate:
        plugins = dict(
            (
                ext.name,
                ext.plugin if isinstance(ext.plugin, Plugin) else ext.plugin()
            ) for ext in mgr
        )
    else:
        plugins = dict((ext.name, ext.plugin) for ext in mgr)

    return plugins

Loads all the plugins for the given namespace

Args:
namespace(str): Namespace string, as in the setuptools entry_points
instantiate(bool): If true, will instantiate the plugins too

Returns:
dict of str, object: Returns the list of loaded plugins


def _upload(auth_http, project_id, bucket_name, file_path, object_name, acl):

    with open(file_path, 'rb') as f:
        data = f.read()
    content_type, content_encoding = mimetypes.guess_type(file_path)

    headers = {
        'x-goog-project-id': project_id,
        'x-goog-api-version': API_VERSION,
        'x-goog-acl': acl,
        'Content-Length': '%d' % len(data)
    }
    if content_type: headers['Content-Type'] = content_type
    if content_type: headers['Content-Encoding'] = content_encoding

    try:
        response, content = auth_http.request(
            'http:
            method='PUT',
            headers=headers,
            body=data)
    except httplib2.ServerNotFoundError, se:
        raise Error(404, 'Server not found.')

    if response.status >= 300:
        raise Error(response.status, response.reason)

    return content

Uploads a file to Google Cloud Storage.

Args:
auth_http: An authorized httplib2.Http instance.
project_id: The project to upload to.
bucket_name: The bucket to upload to.
file_path: Path to the file to upload.
object_name: The name within the bucket to upload to.
acl: The ACL to assign to the uploaded file.


def createEditor(self, parent, option, index):

        editor = QtGui.QDoubleSpinBox(parent)
        try:
            editor.setMinimum(self.minimum)
            editor.setMaximum(self.maximum)
            editor.setSingleStep(self.singleStep)
            editor.setDecimals(self.decimals)
        except TypeError as err:

            pass
        return editor

Returns the widget used to edit the item specified by index for editing. The parent widget and style option are used to control how the editor widget appears.

Args:
parent (QWidget): parent widget.
option (QStyleOptionViewItem): controls how editor widget appears.
index (QModelIndex): model data index.


def make_rhs(self, operator, adjoint, with_batch=True):
    raise NotImplementedError('make_rhs is not defined.')

Make a rhs appropriate for calling operator.solve(rhs).

Args:
operator:  A `LinearOperator`
adjoint:  Python `bool`.  If `True`, we are making a 'rhs' value for the
adjoint operator.
with_batch: Python `bool`. If `True`, create `rhs` with the same batch
shape as operator, and otherwise create a matrix without any batch
shape.

Returns:
A `Tensor`


def run_makeblastdb(infile, dbtype, outdir=''):

    og_dir, name, ext = utils.split_folder_and_path(infile)
    if not outdir:
        outdir = og_dir
    outfile_basename = op.join(outdir, name)

    if dbtype == 'nucl':
        outext = ['.nhr', '.nin', '.nsq']
    elif dbtype == 'prot':
        outext = ['.phr', '.pin', '.psq']
    else:
        raise ValueError('dbtype must be "nucl" or "prot"')
    outfile_all = [outfile_basename + x for x in outext]
    db_made = True
    for f in outfile_all:
        if not op.exists(f):
            db_made = False

    if db_made:
        log.debug('BLAST database already exists at {}'.format(outfile_basename))
        return outfile_all
    else:
        retval = subprocess.call('makeblastdb -in {} -dbtype {} -out {}'.format(infile, dbtype, outfile_basename), shell=True)
        if retval == 0:
            log.debug('Made BLAST database at {}'.format(outfile_basename))
            return outfile_all
        else:
            log.error('Error running makeblastdb, exit code {}'.format(retval))

Make the BLAST database for a genome file.

Args:
infile (str): path to genome FASTA file
dbtype (str): "nucl" or "prot" - what format your genome files are in
outdir (str): path to directory to output database files (default is original folder)

Returns:
Paths to BLAST databases.


def summary(self, stdout=True, plot=False):

        if stdout:
            print('Collinearity summary:')
            print(pd.concat([self.results['Eigenvalues'],
                             self.results['ConditionIndices'],
                             self.results['VIFs'],
                             self.results['CorrelationMatrix']],
                            axis=1))

            print('Outlier summary:')
            print(self.results['RowMahalanobisDistances'])
            print(self.results['ColumnMahalanobisDistances'])

            print('Validity summary:')
            print(self.results['Variances'])

        if plot:
            verify_dependencies('seaborn')
            for key, result in self.results.items():
                if key == 'CorrelationMatrix':
                    ax = plt.axes()
                    sns.heatmap(result, cmap='Blues', ax=ax)
                    ax.set_title(key)
                    sns.plt.show()
                else:
                    result.plot(kind='bar', title=key)
                    plt.show()

Displays diagnostics to the user

Args:
stdout (bool): print results to the console
plot (bool): use Seaborn to plot results


def ParseOptions(self, options):
    helpers_manager.ArgumentHelperManager.ParseOptions(options, self, names=['data_location'])
    self._ReadParserPresetsFromFile()
    self._ParseTimezoneOption(options)
    argument_helper_names = ['artifact_definitions', 'hashers', 'language', 'parsers']
    helpers_manager.ArgumentHelperManager.ParseOptions(options, self, names=argument_helper_names)
    self.list_hashers = (self._hasher_names_string == 'list')
    self.list_language_identifiers = (self._preferred_language == 'list')
    self.list_parsers_and_plugins = (self._parser_filter_expression == 'list')
    if (self.list_hashers or self.list_language_identifiers or self.list_parsers_and_plugins or self.list_timezones):
        return
    helpers_manager.ArgumentHelperManager.ParseOptions(options, self, names=['output_modules'])
    self.list_output_modules = (self._output_format == 'list')
    if self.list_output_modules:
        return
    self._ParseInformationalOptions(options)
    argument_helper_names = ['extraction', 'status_view']
    helpers_manager.ArgumentHelperManager.ParseOptions(options, self, names=argument_helper_names)
    self._ParseLogFileOptions(options)
    self._ParseStorageMediaOptions(options)
    self._ParsePerformanceOptions(options)
    self._ParseProcessingOptions(options)
    self._storage_file_path = getattr(options, 'storage_file', None)
    if (not self._storage_file_path):
        self._storage_file_path = self._GenerateStorageFileName()
    self._output_filename = getattr(options, 'write', None)
    if (not self._output_filename):
        raise errors.BadConfigOption('Output format: {0:s} requires an output file (-w OUTPUT_FILE)'.format(self._output_format))
    if os.path.exists(self._output_filename):
        raise errors.BadConfigOption('Output file already exists: {0:s}.'.format(self._output_filename))
    self._EnforceProcessMemoryLimit(self._process_memory_limit)
    self._output_module = self._CreateOutputModule(options)

Parses tool specific options.

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

Raises:
BadConfigOption: if the options are invalid.


def _calculateRegisterAddress( registertype, patternnumber, stepnumber = None):

    if stepnumber is None:
        stepnumber = 0

    _checkPatternNumber( patternnumber )
    _checkStepNumber( stepnumber )

    if not registertype in list(REGISTER_START.keys()):
        raise ValueError('Wrong register type: {0}. Allowed values: {1}'.format(
            repr(registertype), repr( list(REGISTER_START.keys()) )))

    address = REGISTER_START[registertype] + \
                patternnumber * REGISTER_OFFSET_PER_PATTERN[registertype] + \
                stepnumber * REGISTER_OFFSET_PER_STEP[registertype]

    return address

Calculate the register address for pattern related parameters.

Args:
* registertype (string): The type of parameter, for example 'cycles'.
Allowed are the keys from :data:`REGISTER_START`.
* patternnumber (int): The pattern number.
* stepnumber (int): The step number. Use None if it not should affect the calculation.

Returns:
The register address (int).

Raises:
TypeError, ValueError


def remove(self, obj):

        if type(obj) is AtlasServiceInstance.Instance:
            self.remove_instance(obj)
        elif type(obj) is AtlasServiceBinding.Binding:
            self.remove_binding(obj)
        else:
            raise ErrStorageTypeUnsupported(type(obj))

Remove

Remove an object from the MongoDB storage for caching

Args:
obj (AtlasServiceBinding.Binding or AtlasServiceInstance.Instance): instance or binding

Raises:
ErrStorageTypeUnsupported: Type unsupported.


def fileLoad(self, filePath=None, updatePath=True):

        if not filePath:
            filePath = self.filePath
        if not os.path.isfile(filePath):
            raise FileNotFoundError("Data file '%s' does not exist." % (filePath))
        else:
            print("Importing existing data file '%s' ... " % (filePath), end="", flush=True)
            with open(filePath, "r") as q:
                data_raw = q.read()
            print("Imported!")
            self.data = json.loads(data_raw)
            if updatePath:
                self.filePath = filePath

Load a JSON data file into the internal JSON data dictionary.

Current internal data will be overwritten.
If no file path is provided, the stored data file path will be used.

Args:
filePath (Optional[str]): A relative or absolute path to a
'.json' file. Defaults to None.
updatePath (Optional[bool]): Specifies whether or not to update
the stored data file path. Defaults to True.


def _get_prefix_length(number1, number2, bits):

    for i in range(bits):
        if number1 >> i == number2 >> i:
            return bits - i
    return 0

Get the number of leading bits that are same for two numbers.

Args:
number1: an integer.
number2: another integer.
bits: the maximum number of bits to compare.

Returns:
The number of leading bits that are the same for two numbers.


def prepare_image_question_encoder(image_feat, question, hparams):
    encoder_input = tf.concat([image_feat, question], axis=1)
    encoder_padding = common_attention.embedding_to_padding(encoder_input)
    ignore_padding = common_attention.attention_bias_ignore_padding(encoder_padding)
    encoder_self_attention_bias = ignore_padding
    encoder_decoder_attention_bias = ignore_padding
    if (hparams.pos == 'timing'):
        question = common_attention.add_timing_signal_1d(question)
    elif (hparams.pos == 'emb'):
        question = common_attention.add_positional_embedding(question, hparams.max_length, 'inputs_positional_embedding', None)
    encoder_input = tf.concat([image_feat, question], axis=1)
    return (encoder_input, encoder_self_attention_bias, encoder_decoder_attention_bias)

Prepare encoder.

Args:
image_feat: a Tensor.
question: a Tensor.
hparams: run hyperparameters

Returns:
encoder_input: a Tensor, bottom of encoder stack
encoder_self_attention_bias: a bias tensor for use in encoder self-attention


def rename_state_fluent(name: str) -> str:
    i = name.index('/')
    functor = name[:i]
    arity = name[(i + 1):]
    return "{}'/{}".format(functor, arity)

Returns current state fluent canonical name.

Args:
name (str): The next state fluent name.

Returns:
str: The current state fluent name.


def num_accelerators(self, task_type=None, task_id=None, config_proto=None):
    del task_type, task_id, config_proto
    if self._num_accelerators is None:
        return {}
    return self._num_accelerators

Returns the number of accelerator cores per worker.

The SimpleClusterResolver does not do automatic detection of accelerators,
and thus all arguments are unused and we simply return the value provided
in the constructor.

Args:
task_type: Unused.
task_id: Unused.
config_proto: Unused.


def _run_async(self, urls):
    loop = asyncio.get_event_loop()
    results = loop.run_until_complete(self._async_loop(urls))
    return results

Asynchronous event loop execution

Args:
urls (list): URLs to fetch

Returns:
results (obj): All URL requests' responses


def probe_characteristics(self, conn_id, handle, services):

        self._command_task.async_command(['_probe_characteristics', handle, services],
                                         self._probe_characteristics_finished, {'connection_id': conn_id,
                                                                                'handle': handle,
                                                                                'services': services})

Probe a device for all characteristics defined in its GATT table

This routine must be called after probe_services and passed the services dictionary
produced by that method.

Args:
handle (int): a handle to the connection on the BLED112 dongle
conn_id (int): a unique identifier for this connection on the DeviceManager
that owns this adapter.
services (dict): A dictionary of GATT services produced by probe_services()


def export(self, top=True):

        out = []
        if top:
            out.append(self._internal_name)
        out.append(str(len(self.typical_or_extreme_periods)))
        for obj in self.typical_or_extreme_periods:
            out.append(obj.export(top=False))
        return ",".join(out)

Exports object to its string representation.

Args:
top (bool):  if True appends `internal_name` before values.
All non list objects should be exported with value top=True,
all list objects, that are embedded in as fields inlist objects
should be exported with `top`=False

Returns:
str: The objects string representation


def block(self, **kwargs):
    path = ('/users/%s/block' % self.id)
    server_data = self.manager.gitlab.http_post(path, **kwargs)
    if (server_data is True):
        self._attrs['state'] = 'blocked'
    return server_data

Block the user.

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

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabBlockError: If the user could not be blocked

Returns:
bool: Whether the user status has been changed


def update_course_runs(self, course_runs, enterprise_customer, enterprise_context):

        updated_course_runs = []
        for course_run in course_runs:
            track_selection_url = utils.get_course_track_selection_url(
                course_run=course_run,
                query_parameters=dict(enterprise_context, **utils.get_enterprise_utm_context(enterprise_customer)),
            )

            enrollment_url = enterprise_customer.get_course_run_enrollment_url(course_run.get('key'))

            course_run.update({
                'enrollment_url': enrollment_url,
                'track_selection_url': track_selection_url,
            })

            marketing_url = course_run.get('marketing_url')
            if marketing_url:
                query_parameters = dict(enterprise_context, **utils.get_enterprise_utm_context(enterprise_customer))
                course_run.update({'marketing_url': utils.update_query_parameters(marketing_url, query_parameters)})

            updated_course_runs.append(course_run)
        return updated_course_runs

Update Marketing urls in course metadata and return updated course.

Arguments:
course_runs (list): List of course runs.
enterprise_customer (EnterpriseCustomer): enterprise customer instance.
enterprise_context (dict): The context to inject into URLs.

Returns:
(dict): Dictionary containing updated course metadata.


def full(shape, fill_value, dtype=None, **kwargs):

    return (dc.zeros(shape, **kwargs) + fill_value).astype(dtype)

Create an array of given shape and type, filled with `fill_value`.

Args:
shape (sequence of ints): 2D shape of the array.
fill_value (scalar or numpy.ndarray): Fill value or array.
dtype (data-type, optional): Desired data-type for the array.
kwargs (optional): Other arguments of the array (*coords, attrs, and name).

Returns:
array (decode.array): Decode array filled with `fill_value`.


def get_street(self, **kwargs):
    params = {'description': kwargs.get('street_name'), 'streetNumber': kwargs.get('street_number'), 'Radius': kwargs.get('radius'), 'Stops': kwargs.get('stops'), 'cultureInfo': util.language_code(kwargs.get('lang'))}
    result = self.make_request('geo', 'get_street', **params)
    if (not util.check_result(result, 'site')):
        return (False, 'UNKNOWN ERROR')
    values = util.response_list(result, 'site')
    return (True, [emtype.Site(**a) for a in values])

Obtain a list of nodes related to a location within a given radius.

Not sure of its use, but...

Args:
street_name (str): Name of the street to search.
street_number (int): Street number to search.
radius (int): Radius (in meters) of the search.
stops (int): Number of the stop to search.
lang (str): Language code (*es* or *en*).

Returns:
Status boolean and parsed response (list[Site]), or message string
in case of error.


def describe(self):
    return OrderedDict([(name, field.describe()) for (name, field) in self.fields.items()])

Describe all serialized fields.

It returns dictionary of all fields description defined for this
serializer using their own ``describe()`` methods with respect to order
in which they are defined as class attributes.

Returns:
OrderedDict: serializer description


def __init__(self, flags=MeterFlags.OFPMF_STATS, meter_id=None,
                 bands=None):

        super().__init__()
        self.flags = flags
        self.meter_id = meter_id
        self.bands = bands if bands else []

Create a MeterConfig with the optional parameters below.

Args:
flags (|MeterFlags_v0x04|):
Meter configuration flags.The default value is
MeterFlags.OFPMF_STATS
meter_id (|Meter_v0x04|):
Meter Indentify.The value Meter.OFPM_ALL is used to
refer to all Meters on the switch.
bands(list): List of MeterBandHeader instances.


def sleep(sleep_microseconds):

    def _apply_fn(dataset):
        return _SleepDataset(dataset, sleep_microseconds)
    return _apply_fn

Sleeps for `sleep_microseconds` before producing each input element.

Args:
sleep_microseconds: The number of microseconds to sleep before producing an
input element.

Returns:
A `Dataset` transformation function, which can be passed to
`tf.data.Dataset.apply`.


def fmttime(tin):
    (aaa, bbb) = '{:.2e}'.format(tin).split('e')
    bbb = int(bbb)
    return '$t={} \\times 10^{{{}}}$'.format(aaa, bbb)

Return LaTeX expression with time in scientific notation.

Args:
tin (float): the time.
Returns:
str: the LaTeX expression.


class SamplePatchTSMixerPredictionOutput(ModelOutput):
    sequences: Optional[torch.FloatTensor] = None

Base class for time series model's predictions outputs that contains the sampled values from the chosen
distribution.

Args:
sequences (`torch.FloatTensor` of shape `(batch_size, num_samples, prediction_length, number_channels)`):
Sampled values from the chosen distribution.


def load_configuration(yaml: yaml.ruamel.yaml.YAML, filename: str) -> DictLike:

    with open(filename, "r") as f:
        config = yaml.load(f)

    return config

Load an analysis configuration from a file.

Args:
yaml: YAML object to use in loading the configuration.
filename: Filename of the YAML configuration file.
Returns:
dict-like object containing the loaded configuration


def get_send_request_correct_body(self, path, action):

        path_name, path_spec = self.get_path_spec(path)

        if path_spec is not None and action in path_spec.keys():
                for name, spec in path_spec[action]['parameters'].items():
                    if spec['in'] == 'body':
                        if 'type' in spec.keys():

                            return self.get_example_from_prop_spec(spec)
                        elif 'schema' in spec.keys():
                            if 'type' in spec['schema'].keys() and spec['schema']['type'] == 'array':

                                if '$ref' in spec['schema']['items']:
                                    definition_name = self.get_definition_name_from_ref(spec['schema']
                                                                                ['items']['$ref'])
                                    return [self.definitions_example[definition_name]]
                                else:
                                    definition_name = self.get_definition_name_from_ref(spec['schema']
                                                                                ['items']['type'])
                                    return [definition_name]
                            elif 'type' in spec['schema'].keys():

                                return self.get_example_from_prop_spec(spec['schema'])
                            else:

                                definition_name = self.get_definition_name_from_ref(spec['schema']['$ref'])
                                return self.definitions_example[definition_name]

Get an example body which is correct to send to the given path with the given action.

Args:
path: path of the request
action: action of the request (get, post, put, delete)

Returns:
A dict representing a correct body for the request or None if no
body is required.


def set_result(self, result, from_tree=False):
    if self._read_only:
        if (not from_tree):
            LOGGER.warning('Tried to set address %s on a read-only context.', self.address)
        return
    with self._condition:
        if self._read_only:
            if (not from_tree):
                LOGGER.warning('Tried to set address %s on a read-only context.', self.address)
            return
        if from_tree:
            if (not self._result_set_in_context):
                self._result = result
                self._tree_has_set = True
        else:
            self._result = result
            self._result_set_in_context = True
            self._deleted = False
        self._condition.notify_all()

Set the addresses's value unless the future has been declared
read only.

Args:
result (bytes): The value at an address.
from_tree (bool): Whether the value is being set by a read from
the merkle tree.

Returns:
None


def calculate_checksum(isbn):

    isbn = [int(i) for i in _isbn_cleanse(isbn, checksum=False)]
    if len(isbn) == 9:
        products = [x * y for x, y in zip(isbn, range(1, 10))]
        check = sum(products) % 11
        if check == 10:
            check = 'X'
    else:

        products = []
        for i in range(12):
            if i % 2 == 0:
                products.append(isbn[i])
            else:
                products.append(isbn[i] * 3)
        check = 10 - sum(products) % 10
        if check == 10:
            check = 0
    return str(check)

Calculate ISBN checksum.

Args:
isbn (str): SBN, ISBN-10 or ISBN-13

Returns:
``str``: Checksum for given ISBN or SBN


def from_rotation_and_translation(
            rotation_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)),
            translation_vec=(0, 0, 0), tol=0.1):

        rotation_matrix = np.array(rotation_matrix)
        translation_vec = np.array(translation_vec)
        if rotation_matrix.shape != (3, 3):
            raise ValueError("Rotation Matrix must be a 3x3 numpy array.")
        if translation_vec.shape != (3,):
            raise ValueError("Translation vector must be a rank 1 numpy array "
                             "with 3 elements.")
        affine_matrix = np.eye(4)
        affine_matrix[0:3][:, 0:3] = rotation_matrix
        affine_matrix[0:3][:, 3] = translation_vec
        return SymmOp(affine_matrix, tol)

Creates a symmetry operation from a rotation matrix and a translation
vector.

Args:
rotation_matrix (3x3 array): Rotation matrix.
translation_vec (3x1 array): Translation vector.
tol (float): Tolerance to determine if rotation matrix is valid.

Returns:
SymmOp object


def victims_from_tag(self, victim, tag_name, filters=None, params=None):

        for t in self.pivot_from_tag(victim, tag_name, filters=filters, params=params):
            yield t

Args:
victim:
tag_name:
filters:
params:

Return:


def MySend1(request_path, payload=None,
				content_type="application/octet-stream",
				timeout=None, force_auth=True,
				**kwargs):

	global rpc
	if rpc == None:
		rpc = GetRpcServer(upload_options)
	self = rpc
	if not self.authenticated and force_auth:
		self._Authenticate()
	if request_path is None:
		return
	if timeout is None:
		timeout = 30

	old_timeout = socket.getdefaulttimeout()
	socket.setdefaulttimeout(timeout)
	try:
		tries = 0
		while True:
			tries += 1
			args = dict(kwargs)
			url = "https:
			if args:
				url += "?" + urllib.urlencode(args)
			req = self._CreateRequest(url=url, data=payload)
			req.add_header("Content-Type", content_type)
			try:
				f = self.opener.open(req)
				response = f.read()
				f.close()

				response = response.replace('\r\n', '\n')

				if type(response) == unicode:
					response = response.encode("utf-8")
				typecheck(response, str)
				return response
			except urllib2.HTTPError, e:
				if tries > 3:
					raise
				elif e.code == 401:
					self._Authenticate()
				elif e.code == 302:
					loc = e.info()["location"]
					if not loc.startswith('https:
						return ''
					self._Authenticate()
				else:
					raise
	finally:
		socket.setdefaulttimeout(old_timeout)

Sends an RPC and returns the response.

Args:
request_path: The path to send the request to, eg /api/appversion/create.
payload: The body of the request, or None to send an empty request.
content_type: The Content-Type header to use.
timeout: timeout in seconds; default None i.e. no timeout.
(Note: for large requests on OS X, the timeout doesn't work right.)
kwargs: Any keyword arguments are converted into query string parameters.

Returns:
The response body, as a string.


def ensure_exe(exe_name: str, *paths: str):
    if (not elib_run.find_executable(exe_name, *paths)):
        LOGGER.error('could not find "%s.exe" on this system', exe_name)
        sys.exit((- 1))

Makes sure that an executable can be found on the system path.
Will exit the program if the executable cannot be found

Args:
exe_name: name of the executable
paths: optional path(s) to be searched; if not specified, search the whole system


def _AbortJoin(self, timeout=None):
    for (pid, process) in iter(self._processes_per_pid.items()):
        logger.debug('Waiting for process: {0:s} (PID: {1:d}).'.format(process.name, pid))
        process.join(timeout=timeout)
        if (not process.is_alive()):
            logger.debug('Process {0:s} (PID: {1:d}) stopped.'.format(process.name, pid))

Aborts all registered processes by joining with the parent process.

Args:
timeout (int): number of seconds to wait for processes to join, where
None represents no timeout.


def create(self, **kwargs):

        resource = self.resource.create(kwargs)
        if 'admin_token' in kwargs:
            resource.context.authorize('Gem-Application',
                                       api_token=resource.api_token,
                                       admin_token=kwargs['admin_token'])
        app = self.wrap(resource)
        return self.add(app)

Create a new Application.

Args:
**kwargs: Arbitrary keyword arguments, including:
name (str): A name for the new Application.

Returns:
A round.Application object if successful.


def _GetCurrentControlSet(self, key_path_suffix):

    select_key_path = 'HKEY_LOCAL_MACHINE\\System\\Select'
    select_key = self.GetKeyByPath(select_key_path)
    if not select_key:
      return None

    control_set = None
    for value_name in ('Current', 'Default', 'LastKnownGood'):
      value = select_key.GetValueByName(value_name)
      if not value or not value.DataIsInteger():
        continue

      control_set = value.GetDataAsObject()

      if control_set > 0 or control_set <= 999:
        break

    if not control_set or control_set <= 0 or control_set > 999:
      return None

    control_set_path = 'HKEY_LOCAL_MACHINE\\System\\ControlSet{0:03d}'.format(
        control_set)

    key_path = ''.join([control_set_path, key_path_suffix])
    return self.GetKeyByPath(key_path)

Virtual key callback to determine the current control set.

Args:
key_path_suffix (str): current control set Windows Registry key path
suffix with leading path separator.

Returns:
WinRegistryKey: the current control set Windows Registry key or None
if not available.


def EvalAdjustingSchedule(history, constant=0.1, steps_to_decrease=20, improvement_margin=0.001, decrease_rate=1.5, history_mode='eval', metric='metrics/accuracy'):
    metrics = history.get(history_mode, metric)
    adjusted = constant
    if (len(metrics) < 2):
        return MultifactorSchedule(history, constant=adjusted)
    steps_without_improvement = 0
    cur = metrics.pop()[1]
    while (len(metrics) > 1):
        prev = metrics.pop()[1]
        if (cur < (prev * (1 + improvement_margin))):
            steps_without_improvement += 1
        else:
            cur = prev
            steps_without_improvement = 0
        if (steps_without_improvement >= steps_to_decrease):
            adjusted /= decrease_rate
            cur = prev
            steps_without_improvement = 0
    return MultifactorSchedule(history, constant=adjusted)

Learning rate that decreases when eval metric stalls.

If the chosen metric does not improve by improvement_margin for as many as
steps_to_decrease steps, then the constant gets decreased by decrease rate.
Finally, the MultifactorSchedule gets called with the adjusted constant.

Args:
history: trax.history.History, the history of training and evaluation.
constant: float, the starting constant for the learning rate schedule.
steps_to_decrease: int, after how many steps without improvement
should we decrease the constant.
improvement_margin: how much we need to improve to consider the metric
improved.
decrease_rate: by what fraction to decrease (i.e. lr /= decrease_rate).
history_mode: str, which mode of the history to use.
metric: which evaluation metric to use for adjustments.

Returns:
a function learning_rate(step): float -> float, the step-dependent lr.


def line_line_collide(line1, line2):
    (s, t, success) = segment_intersection(line1[(:, 0)], line1[(:, 1)], line2[(:, 0)], line2[(:, 1)])
    if success:
        return (_helpers.in_interval(s, 0.0, 1.0) and _helpers.in_interval(t, 0.0, 1.0))
    else:
        (disjoint, _) = parallel_lines_parameters(line1[(:, 0)], line1[(:, 1)], line2[(:, 0)], line2[(:, 1)])
        return (not disjoint)

Determine if two line segments meet.

This is a helper for :func:`convex_hull_collide` in the
special case that the two convex hulls are actually
just line segments. (Even in this case, this is only
problematic if both segments are on a single line.)

Args:
line1 (numpy.ndarray): ``2 x 2`` array of start and end nodes.
line2 (numpy.ndarray): ``2 x 2`` array of start and end nodes.

Returns:
bool: Indicating if the line segments collide.


def del_instance(self, obj):
    to_remove = set()
    for (wrkey, _obj) in self.iter_instances():
        if (obj is _obj):
            to_remove.add(wrkey)
    for wrkey in to_remove:
        del self[wrkey]

Remove any stored instance methods that belong to an object

Args:
obj: The instance object to remove


def json(value: Json, expanded: bool=False) -> None:
    id_ = uuid.uuid1().hex
    css_content = '\n  json-viewer {\n    padding:1px 1.5em 1px 1.5em;\n    --background-color:
    html_content = html.escape(json_std.dumps(value))
    expand_line = f'viewer{id_}.expandAll();\n' if expanded else ''
    html_content = f"""\n  <script src="https:
    IPython.display.display(IPython.display.HTML(html_content))

Display the Json `dict` / `list` interactivelly (with collapsible elems).

Examples:

```python
ecolab.json({'a': [1, 2, 3], 'b': {'x': True, 'y': False}})
```

The dict keys and list indices can be filtered from the display field using
regex (e.g. `a.[0-9]` in the above example).

Args:
value: Json `dict` or `list` to inspect.
expanded: Whether the elements start as expanded or as collapsed.


def Validate(self, value):

    if value is None:
      return

    if not isinstance(value, self.rdfclass):

      try:
        return self.rdfclass(value)
      except rdfvalue.InitializeError:
        raise TypeValueError("Value for arg %s should be an %s" %
                             (self.name, self.rdfclass.__name__))

    return value

Validate an RDFValue instance.

Args:
value: An RDFValue instance or something which may be used to instantiate
the correct instance.

Raises:
TypeValueError: If the value is not a valid RDFValue instance or the
required type.

Returns:
A Valid RDFValue instance.


def _check_version(self, root):
    version = self._get_version(root)
    supported = [StrictVersion(x) for x in self.supported_versions(root.tag)]
    if (version in supported):
        return
    error = 'Document version ({0}) not in supported versions ({1})'
    raise UnsupportedVersionError(message=error.format(version, supported), expected=supported, found=version)

Ensure the root element is a supported version.

Args:
root (etree.Element)

Raises:
UnsupportedVersionError


def read_from_directory(self, dataset_info_dir):
    if (not dataset_info_dir):
        raise ValueError('Calling read_from_directory with undefined dataset_info_dir.')
    json_filename = self._dataset_info_filename(dataset_info_dir)
    parsed_proto = read_from_json(json_filename)
    self._set_splits(splits_lib.SplitDict.from_proto(parsed_proto.splits))
    if self.features:
        self.features.load_metadata(dataset_info_dir)
    for (field_name, field) in self.as_proto.DESCRIPTOR.fields_by_name.items():
        field_value = getattr(self._info_proto, field_name)
        field_value_restored = getattr(parsed_proto, field_name)
        try:
            is_defined = self._info_proto.HasField(field_name)
        except ValueError:
            is_defined = bool(field_value)
        try:
            is_defined_in_restored = parsed_proto.HasField(field_name)
        except ValueError:
            is_defined_in_restored = bool(field_value_restored)
        if is_defined:
            if (field_value != field_value_restored):
                logging.info('Field info.%s from disk and from code do not match. Keeping the one from code.', field_name)
            continue
        if (not is_defined_in_restored):
            continue
        if (field.type == field.TYPE_MESSAGE):
            field_value.MergeFrom(field_value_restored)
        else:
            setattr(self._info_proto, field_name, field_value_restored)
    if (self._builder._version != self.version):
        raise AssertionError('The constructed DatasetInfo instance and the restored proto version do not match. Builder version: {}. Proto version: {}'.format(self._builder._version, self.version))
    self._fully_initialized = True

Update DatasetInfo from the JSON file in `dataset_info_dir`.

This function updates all the dynamically generated fields (num_examples,
hash, time of creation,...) of the DatasetInfo.

This will overwrite all previous metadata.

Args:
dataset_info_dir: `str` The directory containing the metadata file. This
should be the root directory of a specific dataset version.


def lookup_rest_method(self, orig_request):
    (method_name, method, params) = self.config_manager.lookup_rest_method(orig_request.path, orig_request.request_uri, orig_request.http_method)
    orig_request.method_name = method_name
    return (method, params)

Looks up and returns rest method for the currently-pending request.

Args:
orig_request: An ApiRequest, the original request from the user.

Returns:
A tuple of (method descriptor, parameters), or (None, None) if no method
was found for the current request.


def aggregate(self, dimensions=None, function=None, spreadfn=None, **kwargs):
    if (function is None):
        raise ValueError('The aggregate method requires a function to be specified')
    if (dimensions is None):
        dimensions = self.kdims
    elif (not isinstance(dimensions, list)):
        dimensions = [dimensions]
    kdims = [self.get_dimension(d, strict=True) for d in dimensions]
    if (not len(self)):
        if spreadfn:
            spread_name = spreadfn.__name__
            vdims = [d for vd in self.vdims for d in [vd, vd('_'.join([vd.name, spread_name]))]]
        else:
            vdims = self.vdims
        return self.clone([], kdims=kdims, vdims=vdims)
    vdims = self.vdims
    (aggregated, dropped) = self.interface.aggregate(self, kdims, function, **kwargs)
    aggregated = self.interface.unpack_scalar(self, aggregated)
    vdims = [vd for vd in vdims if (vd not in dropped)]
    ndims = len(dimensions)
    (min_d, max_d) = self.params('kdims').bounds
    generic_type = (((min_d is not None) and (ndims < min_d)) or ((max_d is not None) and (ndims > max_d)))
    if spreadfn:
        (error, _) = self.interface.aggregate(self, dimensions, spreadfn)
        spread_name = spreadfn.__name__
        ndims = len(vdims)
        error = self.clone(error, kdims=kdims, new_type=Dataset)
        combined = self.clone(aggregated, kdims=kdims, new_type=Dataset)
        for (i, d) in enumerate(vdims):
            dim = d('_'.join([d.name, spread_name]))
            dvals = error.dimension_values(d, flat=False)
            combined = combined.add_dimension(dim, (ndims + i), dvals, True)
        return combined.clone(new_type=(Dataset if generic_type else type(self)))
    if np.isscalar(aggregated):
        return aggregated
    else:
        try:
            return self.clone(aggregated, kdims=kdims, vdims=vdims)
        except:
            datatype = self.params('datatype').default
            return self.clone(aggregated, kdims=kdims, vdims=vdims, new_type=(Dataset if generic_type else None), datatype=datatype)

Aggregates data on the supplied dimensions.

Aggregates over the supplied key dimensions with the defined
function.

Args:
dimensions: Dimension(s) to aggregate on
Default to all key dimensions
function: Aggregation function to apply, e.g. numpy.mean
spreadfn: Secondary reduction to compute value spread
Useful for computing a confidence interval, spread, or
standard deviation.
**kwargs: Keyword arguments passed to the aggregation function

Returns:
Returns the aggregated Dataset


def visit_versions(self, func):
    for bound in self.bounds:
        if (bound.lower is not _LowerBound.min):
            result = func(bound.lower.version)
            if isinstance(result, Version):
                bound.lower.version = result
        if (bound.upper is not _UpperBound.inf):
            result = func(bound.upper.version)
            if isinstance(result, Version):
                bound.upper.version = result

Visit each version in the range, and apply a function to each.

This is for advanced usage only.

If `func` returns a `Version`, this call will change the versions in
place.

It is possible to change versions in a way that is nonsensical - for
example setting an upper bound to a smaller version than the lower bound.
Use at your own risk.

Args:
func (callable): Takes a `Version` instance arg, and is applied to
every version in the range. If `func` returns a `Version`, it
will replace the existing version, updating this `VersionRange`
instance in place.


def extract_changelog_items(text, tags):
    patterns = {x['header']: tag_re(x['tag']) for x in tags}
    items = {x['header']: [] for x in tags}
    curr_tag = None
    curr_text = ''
    for line in text.splitlines():
        if (not line.strip()):
            if (curr_tag is not None):
                items[curr_tag].append(curr_text)
                curr_text = ''
            curr_tag = None
        for tag in tags:
            m = patterns[tag['header']].match(line)
            if m:
                if (curr_tag is not None):
                    items[curr_tag].append(curr_text)
                    curr_text = ''
                curr_tag = tag['header']
                line = m.group('text')
                break
        if (curr_tag is not None):
            curr_text = '{} {}'.format(curr_text.strip(), line.strip()).strip()
    if (curr_tag is not None):
        items[curr_tag].append(curr_text)
    return items

Extract all tagged items from text.

Args:
text (str):
Text to extract the tagged items from. Each tagged item is a
paragraph that starts with a tag. It can also be a text list item.

Returns:
tuple[list[str], list[str], list[str]]:
A tuple of `(features, changes, fixes)` extracted from the given
text.

The tagged items are usually features/changes/fixes but it can be configured
through `pelconf.yaml`.


def value_tensors(self, shape_and_slices: Optional[str]=None) -> Mapping[str, tensor.Tensor]:
    value_tensors = {}
    for serialized_tensor in self.object_proto.attributes:
        checkpoint_key = serialized_tensor.checkpoint_key
        io_device = self._checkpoint.options.experimental_io_device or 'cpu:0'
        with ops.init_scope():
            with ops.device(io_device):
                if shape_and_slices is not None and serialized_tensor.name in shape_and_slices:
                    shape_and_slice = shape_and_slices[serialized_tensor.name]
                else:
                    shape_and_slice = ''
                checkpoint_keys, full_shape_and_slices = self.callback.update_restore_inputs(checkpoint_key, shape_and_slice)
                dtypes = []
                for key in checkpoint_keys:
                    dtype = self._checkpoint.dtype_map[key]
                    dtypes.append(dtype.base_dtype)
                restored_values = io_ops.restore_v2(prefix=self._checkpoint.save_path_tensor, tensor_names=checkpoint_keys, shape_and_slices=full_shape_and_slices, dtypes=dtypes, name='%s_checkpoint_read' % (serialized_tensor.name,))
                value = self.callback.reshard(restored_values, shape_and_slice)
            value_tensors[serialized_tensor.name] = array_ops.identity(value)
    return value_tensors

Create value `Tensor`s for this object's attributes.

Does not require that the Python object has been created. Used for
restore-on-create when executing eagerly.

Args:
shape_and_slices: A dict mapping from object attribute names to a shape
and slice string that will be passed to a RestoreV2 op. If the dict is
None or if an object attribute is not in the dict, the full tensor will
be restored.

Returns:
A dictionary mapping from object attribute names to `Tensor`s.


def variational_dropout(units, keep_prob, fixed_mask_dims=(1,)):
    units_shape = tf.shape(units)
    noise_shape = [units_shape[n] for n in range(len(units.shape))]
    for dim in fixed_mask_dims:
        noise_shape[dim] = 1
    return tf.nn.dropout(units, keep_prob, noise_shape)

Dropout with the same drop mask for all fixed_mask_dims

Args:
units: a tensor, usually with shapes [B x T x F], where
B - batch size
T - tokens dimension
F - feature dimension
keep_prob: keep probability
fixed_mask_dims: in these dimensions the mask will be the same

Returns:
dropped units tensor


def _get_musts(options):
    if (options.version == '2.0'):
        return musts20.list_musts(options)
    else:
        return musts21.list_musts(options)

Return the list of 'MUST' validators for the correct version of STIX.

Args:
options: ValidationOptions instance with validation options for this
validation run, including the STIX spec version.


def load_batch(fpath, label_key='labels'):
    with open(fpath, 'rb') as f:
        d = cPickle.load(f, encoding='bytes')
        d_decoded = {}
        for k, v in d.items():
            d_decoded[k.decode('utf8')] = v
        d = d_decoded
    data = d['data']
    labels = d[label_key]
    data = data.reshape(data.shape[0], 3, 32, 32)
    return (data, labels)

Internal utility for parsing CIFAR data.

Args:
fpath: path the file to parse.
label_key: key for label data in the retrieve
dictionary.

Returns:
A tuple `(data, labels)`.


def __init__(self, c_in, c_hidden, no_heads, starting=True, inf=1000000000.0):
    super().__init__()
    self.c_in = c_in
    self.c_hidden = c_hidden
    self.no_heads = no_heads
    self.starting = starting
    self.inf = inf
    self.layer_norm = LayerNorm(self.c_in)
    self.linear = EsmFoldLinear(c_in, self.no_heads, bias=False, init='normal')
    self.mha = EsmFoldAttention(self.c_in, self.c_in, self.c_in, self.c_hidden, self.no_heads)

Args:
c_in:
Input channel dimension
c_hidden:
Overall hidden channel dimension (not per-head)
no_heads:
Number of attention heads


def truncate(string, maxchar):
    if (maxchar < 4):
        raise TruncateError('Maxchar must be > 3')
    if (len(string) <= maxchar):
        return string
    else:
        return (string[:(maxchar - 3)] + '...')

Truncate a string to a maximum number of characters.

If the string is longer than maxchar, then remove excess
characters and append an ellipses.

Arguments:

string (str): String to truncate.
maxchar (int): Maximum length of string in characters. Must be >= 4.

Returns:

str: Of length <= maxchar.

Raises:

TruncateError: In case of an error.


def losses(self):
    collected_losses = []
    all_layers = self._flatten_layers()
    for layer in all_layers:
        collected_losses.extend(layer._losses)
        for regularizer in layer._callable_losses:
            loss_tensor = regularizer()
            if loss_tensor is not None:
                collected_losses.append(loss_tensor)
    return collected_losses

Losses which are associated with this `Layer`.

Variable regularization tensors are created when this property is accessed,
so it is eager safe: accessing `losses` under a `tf.GradientTape` will
propagate gradients back to the corresponding variables.

Returns:
A list of tensors.


def __init__(self, validate: Callable[[_InT], _OutT], field_kwargs: dict[str, Any]) -> None:
    self._attribute_name: Optional[str] = None
    self._objtype: Optional[Type[_Dataclass]] = None
    self._validate_fn = validate
    self._field_kwargs = field_kwargs
    self._first_getattr_call: bool = True

Constructor.

Args:
validate: A callable called each time the variable is assigned.
field_kwargs: Kwargs forwarded to `dataclasses.field`


def rst_underline(heading: str, underline_char: str) -> str:
    assert ('\n' not in heading)
    assert (len(underline_char) == 1)
    return ((heading + '\n') + (underline_char * len(heading)))

Underlines a heading for RST files.

Args:
heading: text to underline
underline_char: character to use

Returns:
underlined heading, over two lines (without a final terminating
newline)


def _set_save_slice_info(self, save_slice_info):
    self._save_slice_info = save_slice_info

Sets the slice info for this `Variable`.

Args:
save_slice_info: A `Variable.SaveSliceInfo` object.


def remove_image(self, image, force=False, noprune=False):
    params = {'force': force, 'noprune': noprune}
    res = self._delete(self._url('/images/{0}', image), params=params)
    return self._result(res, True)

Remove an image. Similar to the ``docker rmi`` command.

Args:
image (str): The image to remove
force (bool): Force removal of the image
noprune (bool): Do not delete untagged parents


def get_body(name):

    try:

        body, propag = _bodies[name.lower()]

        body.propagate = propag.propagate
    except KeyError as e:
        raise UnknownBodyError(e.args[0])

    return body

Retrieve a given body orbits and parameters

Args:
name (str): Object name
Return:
Body:


def apply_cut(self, cut):
    return Subsystem(self.network, self.state, self.node_indices, cut=cut, mice_cache=self._mice_cache)

Return a cut version of this |Subsystem|.

Args:
cut (Cut): The cut to apply to this |Subsystem|.

Returns:
Subsystem: The cut subsystem.


def unload_snippet(self, name):
    self.services.snippets.remove_snippet_client(name)

Stops a snippet apk.

Args:
name: The attribute name the snippet server is attached with.

Raises:
SnippetError: The given snippet name is not registered.


def GetMessages(self, formatter_mediator, event):

    if self.DATA_TYPE != event.data_type:
      raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
          event.data_type))

    event_values = event.CopyToDict()

    file_reference = event_values.get('file_reference', None)
    if file_reference:
      event_values['file_reference'] = '{0:d}-{1:d}'.format(
          file_reference & 0xffffffffffff, file_reference >> 48)

    parent_file_reference = event_values.get('parent_file_reference', None)
    if parent_file_reference:
      event_values['parent_file_reference'] = '{0:d}-{1:d}'.format(
          parent_file_reference & 0xffffffffffff, parent_file_reference >> 48)

    update_reason_flags = event_values.get('update_reason_flags', 0)
    update_reasons = []
    for bitmask, description in sorted(self._USN_REASON_FLAGS.items()):
      if bitmask & update_reason_flags:
        update_reasons.append(description)

    event_values['update_reason'] = ', '.join(update_reasons)

    update_source_flags = event_values.get('update_source_flags', 0)
    update_sources = []
    for bitmask, description in sorted(self._USN_SOURCE_FLAGS.items()):
      if bitmask & update_source_flags:
        update_sources.append(description)

    event_values['update_source'] = ', '.join(update_sources)

    return self._ConditionalFormatMessages(event_values)

Determines the formatted message strings for an event object.

Args:
formatter_mediator (FormatterMediator): mediates the interactions
between formatters and other components, such as storage and Windows
EventLog resources.
event (EventObject): event.

Returns:
tuple(str, str): formatted message string and short message string.

Raises:
WrongFormatter: if the event object cannot be formatted by the formatter.


def retry_handler(retries=0, delay=timedelta(), conditions=[]):
    delay_in_seconds = delay.total_seconds()
    return partial(retry_loop, retries, delay_in_seconds, conditions)

A simple wrapper function that creates a handler function by using
on the retry_loop function.

Args:
retries (Integral): The number of times to retry if a failure occurs.
delay (timedelta, optional, 0 seconds): A timedelta representing
the amount time to delay between retries.
conditions (list): A list of retry conditions.
Returns:
function: The retry_loop function partialed.


def __init__(self, path, stat_obj):

    self._path = path
    self._stat = stat_obj
    self._flags_linux = None
    self._flags_osx = None

Wrap an existing stat result in a `filesystem.Stat` instance.

Args:
path: the path of `stat_obj`.
stat_obj: an instance of os.stat_result with information about `path`.


def _WsdlHasMethod(self, method_name):

    return method_name in self.suds_client.wsdl.services[0].ports[0].methods

Determine if the wsdl contains a method.

Args:
method_name: The name of the method to search.

Returns:
True if the method is in the WSDL, otherwise False.


def __init__(self, entries, working_ion_entry):

        self._entries = entries
        self._working_ion = working_ion_entry.composition.elements[0]
        self._working_ion_entry = working_ion_entry

        elements = set()
        for entry in entries:
            elements.update(entry.composition.elements)

        element_energy = max([entry.energy_per_atom for entry in entries]) + 10

        pdentries = []
        pdentries.extend(entries)
        pdentries.extend([PDEntry(Composition({el: 1}), element_energy)
                          for el in elements])

        pd = PhaseDiagram(pdentries)

        lifrac = lambda e: e.composition.get_atomic_fraction(self._working_ion)

        self._stable_entries = tuple(sorted([e for e in pd.stable_entries
                                             if e in entries], key=lifrac))

        self._unstable_entries = tuple(sorted([e for e in pd.unstable_entries
                                               if e in entries], key=lifrac))

        self._vpairs = tuple([InsertionVoltagePair(self._stable_entries[i],
                                                   self._stable_entries[i + 1],
                                                   working_ion_entry)
                              for i in range(len(self._stable_entries) - 1)])

Create a new InsertionElectrode.

Args:
entries: A list of ComputedStructureEntries (or subclasses)
representing the different topotactic states of the battery,
e.g. TiO2 and LiTiO2.
working_ion_entry: A single ComputedEntry or PDEntry
representing the element that carries charge across the
battery, e.g. Li.


def parse(cls, data: bytes) -> 'MessageContent':

        lines = cls._find_lines(data)
        view = memoryview(data)
        return cls._parse(data, view, lines)

Parse the bytestring into message content.

Args:
data: The bytestring to parse.


def set(self, name, value):

        name = str(name)
        if name not in self._properties:
            raise ArgumentError("Unknown property in DeviceModel", name=name)

        self._properties[name] = value

Set a device model property.

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


def display_table_dataset_map(cmd: str) -> None:
    cmd_parts = cmd.split(' ')
    if len(cmd_parts) == 2:
        if cmd_parts[1] in table_dataset_map:
            print(f'{cmd_parts[1]}  =>  {table_dataset_map[cmd_parts[1]]}')
        else:
            list_key_values(table_dataset_map)
    else:
        list_key_values(table_dataset_map)

Display information from the table_dataset_map.

Args:
cmd (str): The command string.


def take_ownership(self, **kwargs):

        path = '%s/%s/take_ownership' % (self.manager.path, self.get_id())
        server_data = self.manager.gitlab.http_post(path, **kwargs)
        self._update_attrs(server_data)

Update the owner of a pipeline schedule.

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

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabOwnershipError: If the request failed


def host(self, hostname, owner=None, **kwargs):
    return Host(self.tcex, hostname, owner=owner, **kwargs)

Create the Host TI object.

Args:
owner:
hostname:
**kwargs:

Return:


def build_from_queue(cls, input_queue, replay_size, batch_size):

    return cls(
        lambda: input_queue.dequeue_many(batch_size),
        replay_size,
        batch_size=batch_size)

Builds a `ReplayableQueue` that draws from a regular `input_queue`.

Args:
input_queue: The queue to draw from.
replay_size: The size of the replay buffer.
batch_size: The size of each batch.

Returns:
A ReplayableQueue.


def build_options_str(self, options):

        opts = []
        for name in iter(list(self._SUPPORTED_OPTS.values())):
            if name in options:
                key = name.replace('_', '-')
                if key in self._BOOLEAN_OPTIONS:
                    if options[name]:
                        opts.append('--{}'.format(key))
                else:
                    opts.append('--{}={}'.format(key, options[name]))

        return self.__str2bytes(' '.join(opts))

Returns a string concatenation of the MeCab options.

Args:
options: dictionary of options to use when instantiating the MeCab
instance.

Returns:
A string concatenation of the options used when instantiating the
MeCab instance, in long-form.


def BindScope(self, scope_id, values):
    if (scope_id not in self._scopes):
        raise KeyError(scope_id)
    keys = set(iterkeys(values))
    if (keys != self._scopes[scope_id]):
        raise KeyError((keys ^ self._scopes[scope_id]))
    self._scope_bindings[scope_id].append(values)

Associates given values with given scope.

This can be called multiple times to associate multiple values.

Args:
scope_id: A scope id to bind the values to.
values: A mapping from scope variable ids to values to bind in scope.

Raises:
KeyError: If given scope or scope variable is not specified in the
pattern.


def from_string(data_str):

        lines = data_str.strip().split('\n')
        err_msg = ("Invalid input string format. Is this string generated by "
                   "MonsoonData class?")
        conditions = [
            len(lines) <= 4, "Average Current:" not in lines[1],
            "Voltage: " not in lines[2], "Total Power: " not in lines[3],
            "samples taken at " not in lines[4],
            lines[5] != "Time" + ' ' * 7 + "Amp"
        ]
        if any(conditions):
            raise MonsoonError(err_msg)
        hz_str = lines[4].split()[2]
        hz = int(hz_str[:-2])
        voltage_str = lines[2].split()[1]
        voltage = int(voltage_str[:-1])
        lines = lines[6:]
        t = []
        v = []
        for l in lines:
            try:
                timestamp, value = l.split(' ')
                t.append(int(timestamp))
                v.append(float(value))
            except ValueError:
                raise MonsoonError(err_msg)
        return MonsoonData(v, t, hz, voltage)

Creates a MonsoonData object from a string representation generated
by __str__.

Args:
str: The string representation of a MonsoonData.

Returns:
A MonsoonData object.


def extract_blocks(ubi):
    blocks = {}
    ubi.file.seek(ubi.file.start_offset)
    peb_count = 0
    cur_offset = 0
    bad_blocks = []
    for i in range(ubi.file.start_offset, ubi.file.end_offset, ubi.file.block_size):
        try:
            buf = ubi.file.read(ubi.file.block_size)
        except Exception as e:
            if settings.warn_only_block_read_errors:
                error(extract_blocks, 'Error', ('PEB: %s: %s' % ((ubi.first_peb_num + peb_count), str(e))))
                continue
            else:
                error(extract_blocks, 'Fatal', ('PEB: %s: %s' % ((ubi.first_peb_num + peb_count), str(e))))
        if buf.startswith(UBI_EC_HDR_MAGIC):
            blk = description(buf)
            blk.file_offset = i
            blk.peb_num = (ubi.first_peb_num + peb_count)
            blk.size = ubi.file.block_size
            blocks[blk.peb_num] = blk
            peb_count += 1
            log(extract_blocks, blk)
            verbose_log(extract_blocks, ('file addr: %s' % ubi.file.last_read_addr()))
            ec_hdr_errors = ''
            vid_hdr_errors = ''
            if blk.ec_hdr.errors:
                ec_hdr_errors = ','.join(blk.ec_hdr.errors)
            if (blk.vid_hdr and blk.vid_hdr.errors):
                vid_hdr_errors = ','.join(blk.vid_hdr.errors)
            if (ec_hdr_errors or vid_hdr_errors):
                if (blk.peb_num not in bad_blocks):
                    bad_blocks.append(blk.peb_num)
                    log(extract_blocks, ('PEB: %s has possible issue EC_HDR [%s], VID_HDR [%s]' % (blk.peb_num, ec_hdr_errors, vid_hdr_errors)))
            verbose_display(blk)
        else:
            cur_offset += ubi.file.block_size
            ubi.first_peb_num = (cur_offset / ubi.file.block_size)
            ubi.file.start_offset = cur_offset
    return blocks

Get a list of UBI block objects from file

Arguments:.
Obj:ubi    -- UBI object.

Returns:
Dict -- Of block objects keyed by PEB number.


def GetFileObject(self, data_stream_name=''):

    if not self.IsFile():
      raise IOError('Cannot open non-file.')

    if data_stream_name:
      return None

    location = getattr(self.path_spec, 'location', None)
    if location is None:
      return None

    file_data = self._file_system.GetDataByPath(location)
    file_object = fake_file_io.FakeFile(self._resolver_context, file_data)
    file_object.open(path_spec=self.path_spec)
    return file_object

Retrieves the file-like object.

Args:
data_stream_name (Optional[str]): name of the data stream, where an empty
string represents the default data stream.

Returns:
FakeFileIO: a file-like object or None if not available.

Raises:
IOError: if the file entry is not a file.
OSError: if the file entry is not a file.


def _compute_merkle_root(self, required_state_root):

        state_hash = None
        if self._previous_valid_batch_c_id is not None:
            publishing_or_genesis = self._always_persist or \
                required_state_root is None
            state_hash = self._squash(
                state_root=self._previous_state_hash,
                context_ids=[self._previous_valid_batch_c_id],
                persist=self._always_persist, clean_up=publishing_or_genesis)
            if self._always_persist is True:
                return state_hash
            if state_hash == required_state_root:
                self._squash(state_root=self._previous_state_hash,
                             context_ids=[self._previous_valid_batch_c_id],
                             persist=True, clean_up=True)
        return state_hash

Computes the merkle root of the state changes in the context
corresponding with _last_valid_batch_c_id as applied to
_previous_state_hash.

Args:
required_state_root (str): The merkle root that these txns
should equal.

Returns:
state_hash (str): The merkle root calculated from the previous
state hash and the state changes from the context_id


def _set_scripts(self, host_metadata, scripts):

        scripts_key = 'deploy-scripts'
        if 'ovirt-scritps' in host_metadata:
            scripts_key = 'ovirt-scripts'

        host_metadata[scripts_key] = scripts
        return host_metadata

Temporary method to set the host scripts

TODO:
remove once the "ovirt-scripts" option gets deprecated

Args:
host_metadata(dict): host metadata to set scripts in

Returns:
dict: the updated metadata


def make_iterable(value):

    if sys.version_info <= (3, 0):

        if isinstance(value, unicode):
            value = str(value)
    if isinstance(value, str) or isinstance(value, dict):
        value = [value]

    if not isinstance(value, collections.Iterable):
        raise TypeError('value must be an iterable object')

    return value

Converts the supplied value to a list object

This function will inspect the supplied value and return an
iterable in the form of a list.

Args:
value (object): An valid Python object

Returns:
An iterable object of type list


def from_api_repr(cls, api_repr):
    mode = api_repr.get('mode', 'NULLABLE')
    description = api_repr.get('description')
    fields = api_repr.get('fields', ())
    return cls(field_type=api_repr['type'].upper(), fields=[cls.from_api_repr(f) for f in fields], mode=mode.upper(), description=description, name=api_repr['name'])

Return a ``SchemaField`` object deserialized from a dictionary.

Args:
api_repr (Mapping[str, str]): The serialized representation
of the SchemaField, such as what is output by
:meth:`to_api_repr`.

Returns:
google.cloud.biquery.schema.SchemaField:
The ``SchemaField`` object.


def create_segment_token_type_ids_from_sequences(self, query_ids: List[int], table_values: List[TableValue]) -> List[int]:
    table_ids = list(zip(*table_values))[0] if table_values else []
    return [0] * (1 + len(query_ids) + 1) + [1] * len(table_ids)

Creates the segment token type IDs according to the query token IDs and a list of table values.

Args:
query_ids (`List[int]`): list of token IDs corresponding to the ID.
table_values (`List[TableValue]`): lift of table values, which are named tuples containing the
token value, the column ID and the row ID of said token.

Returns:
`List[int]`: List of ints containing the segment token type IDs values.


def _PrintAnalysisReportsDetails(self, storage_reader):
    if (not storage_reader.HasAnalysisReports()):
        self._output_writer.Write('No analysis reports stored.\n\n')
        return
    for (index, analysis_report) in enumerate(storage_reader.GetAnalysisReports()):
        title = 'Analysis report: {0:d}'.format(index)
        table_view = views.ViewsFactory.GetTableView(self._views_format_type, title=title)
        table_view.AddRow(['String', analysis_report.GetString()])
        table_view.Write(self._output_writer)

Prints the details of the analysis reports.

Args:
storage_reader (StorageReader): storage reader.


def refresh(self, access_token=None, **kwargs):
    if (not self.token_lock.locked()):
        with self.token_lock:
            if ((access_token == self.access_token) or (access_token is None)):
                if (self.developer_token is not None):
                    r = self._httpclient.request(method='POST', url=self.developer_token_url, path='/request_token', headers={'Authorization': 'Bearer {}'.format(self.developer_token)}, timeout=30, raise_for_status=True)
                elif all([self.client_id, self.client_secret, self.refresh_token]):
                    data = {'client_id': self.client_id, 'client_secret': self.client_secret, 'refresh_token': self.refresh_token, 'grant_type': 'refresh_token'}
                    r = self._httpclient.request(method='POST', url=self.token_url, json=data, path='/api/oauth2/RequestToken', **kwargs)
                else:
                    raise PartialCredentialsError('Missing one or more required credentials')
                if r:
                    if (not r.ok):
                        raise PanCloudError(('%s %s: %s' % (r.status_code, r.reason, r.text)))
                    try:
                        r_json = r.json()
                    except ValueError as e:
                        raise PanCloudError(('Invalid JSON: %s' % e))
                    else:
                        if (r.json().get('error_description') or r.json().get('error')):
                            raise PanCloudError(r.text)
                        self.access_token = r_json.get('access_token', None)
                        self.jwt_exp = self._decode_exp(self.access_token_)
                        if r_json.get('refresh_token', None):
                            self.refresh_token = r_json.get('refresh_token')
                        self.write_credentials()
                    return self.access_token_

Refresh access and refresh tokens.

Args:
access_token (str): Access token to refresh. Defaults to ``None``.

Returns:
str: Refreshed access token.


def _get_val_str(obj, path_list=None, reverse=False):
    val_list = _get_val_list(obj, (path_list or []), reverse)
    return ('<not found>' if (obj is None) else ' / '.join(map(str, val_list)))

Extract values from nested objects by attribute names and concatenate their
string representations.

Args:
obj: object
Any type of object

path_list: list
Attribute names

reverse: bool
Reverse the list of values before concatenation.

Returns:
str: Concatenated extracted values.


def assemble(self, header_json, metadata_json, content_json):
    header = json_decode(header_json)
    if ('msgtype' not in header):
        log.error('Bad header with no msgtype was: %r', header)
        raise ProtocolError("No 'msgtype' in header")
    return self._messages[header['msgtype']].assemble(header_json, metadata_json, content_json)

Create a Message instance assembled from json fragments.

Args:
header_json (``JSON``) :

metadata_json (``JSON``) :

content_json (``JSON``) :

Returns:
message


def _ReadTablesArray(self, file_object, tables_array_offset):
    data_type_map = self._GetDataTypeMap('keychain_tables_array')
    (tables_array, _) = self._ReadStructureFromFileObject(file_object, tables_array_offset, data_type_map)
    tables = collections.OrderedDict()
    for table_offset in tables_array.table_offsets:
        self._ReadTable(tables, file_object, (tables_array_offset + table_offset))
    return tables

Reads the tables array.

Args:
file_object (file): file-like object.
tables_array_offset (int): offset of the tables array relative to
the start of the file.

Returns:
dict[int, KeychainDatabaseTable]: tables per identifier.

Raises:
ParseError: if the tables array cannot be read.


def create_composite_loss(losses=None,
                          regularize=True,
                          include_marked=True,
                          name='cost'):

  books = for_default_graph()
  return books.create_composite_loss(losses,
                                     regularize,
                                     include_marked=include_marked,
                                     name=name)

Creates a loss that is the sum of all specified losses.

Args:
losses: A sequence of losses to include.
regularize: Whether or not to include regularization losses.
include_marked: Whether or not to use the marked losses.
name: The name for this variable.
Returns:
A single tensor that is the sum of all losses.


def _lookup_op_type(self, graph_id, op_name):
    return self._graph_by_id[graph_id].get_op_creation_digest(op_name).op_type

Lookup the type of an op by name and the immediately enclosing graph.

Args:
graph_id: Debugger-generated ID of the immediately-enclosing graph.
op_name: Name of the op.

Returns:
Op type as a str.


def query(query, ts, **kwargs):

    queryobj = _parse_query(query)

    if queryobj['querytype'] in ('select', 'retrieve'):
        return _select(
            queryobj['projection'],
            queryobj['tables'],
            queryobj['where'],
            ts,
            mode=kwargs.get('mode', 'list'),
            cast=kwargs.get('cast', True))
    else:

        raise TSQLSyntaxError(queryobj['querytype'] +
                              ' queries are not supported')

Perform *query* on the testsuite *ts*.

Note: currently only 'select' queries are supported.

Args:
query (str): TSQL query string
ts (:class:`delphin.itsdb.TestSuite`): testsuite to query over
kwargs: keyword arguments passed to the more specific query
function (e.g., :func:`select`)
Example:
>>> list(tsql.query('select i-id where i-length < 4', ts))
[[142], [1061]]


def _resource_apply_dense(self, grad, handle, apply_state):
    raise NotImplementedError('Must be implemented in subclasses.')

Add ops to apply dense gradients to the variable `handle`.

Args:
grad: a `Tensor` representing the gradient.
handle: a `Tensor` of dtype `resource` which points to the variable to be
updated.
apply_state: A dict which is used across multiple apply calls.

Returns:
An `Operation` which updates the value of the variable.


def at(self, row, col):

        if not (isinstance(row, int) and isinstance(col, int)):
            raise TypeError(row, col)
        return self._values[row][col]

Return the value at the given cell position.

Args:
row (int): zero-based row number
col (int): zero-based column number
Returns:
cell value
Raises:
TypeError: if ``row`` or ``col`` is not an ``int``
IndexError: if the position is out of range


def transfer_project(self, to_namespace, **kwargs):
    path = ('/projects/%s/transfer' % (self.id,))
    self.manager.gitlab.http_put(path, post_data={'namespace': to_namespace}, **kwargs)

Transfer a project to the given namespace ID

Args:
to_namespace (str): ID or path of the namespace to transfer the
project to
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabTransferProjectError: If the project could not be transfered


def find_write_predecessors(self, address):

        predecessors = set()

        enclosing_writer = None

        node_stream = self._tree.walk(address)

        address_len = len(address)

        try:
            for node_address, node in node_stream:
                if node is not None:
                    predecessors.update(node.readers)

                    if node.writer is not None:
                        enclosing_writer = node.writer

                    if len(node_address) >= address_len:
                        break

        except AddressNotInTree as err:
            if err.match is not None:
                return self.find_write_predecessors(err.match)

            return predecessors

        finally:
            if enclosing_writer is not None:
                predecessors.add(enclosing_writer)

        for _, node in node_stream:
            if node is not None:
                if node.writer is not None:
                    predecessors.add(node.writer)

                predecessors.update(node.readers)

        return predecessors

Returns all predecessor transaction ids for a write of the provided
address.

Arguments:
address (str): the radix address

Returns: a set of transaction ids


def featurize_row(self, x, y):

        x = x.ravel()
        y = y.ravel()
        b = np.ones(x.shape)
        dx = np.cos(np.dot(self.W2, np.vstack((x, b)))).mean(1)
        dy = np.cos(np.dot(self.W2, np.vstack((y, b)))).mean(1)
        if(sum(dx) > sum(dy)):
            return np.hstack((dx, dy,
                              np.cos(np.dot(self.W, np.vstack((x, y, b)))).mean(1)))
        else:
            return np.hstack((dx, dy,
                              np.cos(np.dot(self.W, np.vstack((y, x, b)))).mean(1)))

Projects the causal pair to the RKHS using the sampled kernel approximation.

Args:
x (np.ndarray): Variable 1
y (np.ndarray): Variable 2

Returns:
np.ndarray: projected empirical distributions into a single fixed-size vector.


def get_special_tokens_mask(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None, already_has_special_tokens: bool=False) -> List[int]:
    if already_has_special_tokens:
        return super().get_special_tokens_mask(token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True)
    if token_ids_1 is None:
        return [0] * len(token_ids_0) + [1]
    return [0] * len(token_ids_0) + [1] + [0] * len(token_ids_1) + [1]

Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer `prepare_for_model` method.

Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.
already_has_special_tokens (`bool`, *optional*, defaults to `False`):
Whether or not the token list is already formatted with special tokens for the model.

Returns:
`List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.


def bind_parameters(self, value_dict):

        new_circuit = self.copy()

        if value_dict.keys() > self.parameters:
            raise QiskitError('Cannot bind parameters ({}) not present in the circuit.'.format(
                [str(p) for p in value_dict.keys() - self.parameters]))

        for parameter, value in value_dict.items():
            new_circuit._bind_parameter(parameter, value)

        for parameter in value_dict:
            del new_circuit._parameter_table[parameter]
        return new_circuit

Assign parameters to values yielding a new circuit.

Args:
value_dict (dict): {parameter: value, ...}

Raises:
QiskitError: If value_dict contains parameters not present in the circuit

Returns:
QuantumCircuit: copy of self with assignment substitution.


def __call__(self, orbit, new_form):

        if isinstance(new_form, Form):
            new_form = new_form.name

        coord = orbit.copy()
        if new_form != orbit.form.name:
            for a, b in self.steps(new_form):

                coord = getattr(self, "_{}_to_{}".format(a.name.lower(), b.name.lower()))(coord, orbit.frame.center)

        return coord

Gives the result of the transformation without in-place modifications

Args:
orbit (Orbit):
new_form (str or Form):
Returns:
Coord


def deleted(self):
    return ((self.timestamps.deleted is not None) and (self.timestamps.deleted > NodeTimestamps.int_to_dt(0)))

Get the deleted state.

Returns:
bool: Whether this item is deleted.


def from_voxels(voxels):
    dimensions = len(voxels[0])
    for d in range(len(dimensions)):
        size.append(max([i[d] for i in voxels]))
    result = numpy.zeros(dimensions)
    for v in voxels:
        result[v] = 1
    return result

Converts a voxel list to an ndarray.

Arguments:
voxels (tuple[]): A list of coordinates indicating coordinates of
populated voxels in an ndarray.

Returns:
numpy.ndarray The result of the transformation.


def WriteEventBody(self, event):

    row = self._GetSanitizedEventValues(event)

    self._cursor.execute(self._INSERT_QUERY, row)
    self._count += 1

    if self._count % 10000 == 0:
      self._connection.commit()
      if self._set_status:
        self._set_status('Inserting event: {0:d}'.format(self._count))

Writes the body of an event to the output.

Args:
event (EventObject): event.