def _finished_callback(self, batch_fut, todo):
    self._running.remove(batch_fut)
    err = batch_fut.get_exception()
    if (err is not None):
        tb = batch_fut.get_traceback()
        for (fut, _) in todo:
            if (not fut.done()):
                fut.set_exception(err, tb)

Passes exception along.

Args:
batch_fut: the batch future returned by running todo_tasklet.
todo: (fut, option) pair. fut is the future return by each add() call.

If the batch fut was successful, it has already called fut.set_result()
on other individual futs. This method only handles when the batch fut
encountered an exception.


def convert_shape(params, w_name, scope_name, inputs, layers, weights, names):

    print('Converting shape ...')

    def target_layer(x):
        import tensorflow as tf
        return tf.shape(x)

    lambda_layer = keras.layers.Lambda(target_layer)
    layers[scope_name] = lambda_layer(layers[inputs[0]])

Convert shape operation.

Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers


def ch_stop_time(self, *channels: List[Channel]) -> int:

        return self.timeslots.ch_stop_time(*channels)

Return maximum start time for supplied channels.

Args:
*channels: Supplied channels


def acquire(self, host: str, port: int, use_ssl: bool=False,
                host_key: Optional[Any]=None) \
            -> Union[Connection, SSLConnection]:

        assert isinstance(port, int), 'Expect int. Got {}'.format(type(port))
        assert not self._closed

        yield from self._process_no_wait_releases()

        if use_ssl:
            connection_factory = functools.partial(
                self._ssl_connection_factory, hostname=host)
        else:
            connection_factory = functools.partial(
                self._connection_factory, hostname=host)

        connection_factory = functools.partial(
            HappyEyeballsConnection, (host, port), connection_factory,
            self._resolver, self._happy_eyeballs_table,
            is_ssl=use_ssl
        )

        key = host_key or (host, port, use_ssl)

        with (yield from self._host_pools_lock):
            if key not in self._host_pools:
                host_pool = self._host_pools[key] = HostPool(
                    connection_factory,
                    max_connections=self._max_host_count
                )
                self._host_pool_waiters[key] = 1
            else:
                host_pool = self._host_pools[key]
                self._host_pool_waiters[key] += 1

        _logger.debug('Check out %s', key)

        connection = yield from host_pool.acquire()
        connection.key = key

        with (yield from self._host_pools_lock):
            self._host_pool_waiters[key] -= 1

        return connection

Return an available connection.

Args:
host: A hostname or IP address.
port: Port number.
use_ssl: Whether to return a SSL connection.
host_key: If provided, it overrides the key used for per-host
connection pooling. This is useful for proxies for example.

Coroutine.


def tasks(self):
    if (not self.__tasks):
        self.__tasks = Tasks(self.__connection)
    return self.__tasks

Gets the Tasks API client.

Returns:
Tasks:


def shutdown(self, message=None):
    for (name, server) in self.servers.items():
        server.quit(message)

Disconnect all servers with a message.

Args:
message (str): Quit message to use on each connection.


def fix_variable(self, v, value):
    variables = self.variables
    try:
        idx = variables.index(v)
    except ValueError:
        raise ValueError('given variable {} is not part of the constraint'.format(v))
    if (value not in self.vartype.value):
        raise ValueError('expected value to be in {}, received {} instead'.format(self.vartype.value, value))
    configurations = frozenset(((config[:idx] + config[(idx + 1):]) for config in self.configurations if (config[idx] == value)))
    if (not configurations):
        raise UnsatError('fixing {} to {} makes this constraint unsatisfiable'.format(v, value))
    variables = (variables[:idx] + variables[(idx + 1):])
    self.configurations = configurations
    self.variables = variables

    def func(*args):
        return (args in configurations)
    self.func = func
    self.name = '{} ({} fixed to {})'.format(self.name, v, value)

Fix the value of a variable and remove it from the constraint.

Args:
v (variable):
Variable in the constraint to be set to a constant value.

val (int):
Value assigned to the variable. Values must match the :class:`.Vartype` of the
constraint.

Examples:
This example creates a constraint that :math:`a \\ne b` on binary variables,
fixes variable a to 0, and tests two candidate solutions.

>>> import dwavebinarycsp
>>> const = dwavebinarycsp.Constraint.from_func(operator.ne,
...             ['a', 'b'], dwavebinarycsp.BINARY)
>>> const.fix_variable('a', 0)
>>> const.check({'b': 1})
True
>>> const.check({'b': 0})
False


def entropy(rho: Density, base: float=None) -> float:
    op = asarray(rho.asoperator())
    probs = np.linalg.eigvalsh(op)
    probs = np.maximum(probs, 0.0)
    return scipy.stats.entropy(probs, base=base)

Returns the von-Neumann entropy of a mixed quantum state.

Args:
rho:    A density matrix
base:   Optional logarithm base. Default is base e, and entropy is
measures in nats. For bits set base to 2.

Returns:
The von-Neumann entropy of rho


def write(self, data, timeout_ms=None):
    timeout = timeouts.PolledTimeout.from_millis(timeout_ms)
    while data:
        self._transport.write(data[:self._transport.adb_connection.maxdata], timeout)
        data = data[self._transport.adb_connection.maxdata:]

Write data to this stream.

Args:
data: Data to write.
timeout_ms: Timeout to use for the write/Ack transaction, in
milliseconds (or as a PolledTimeout object).

Raises:
AdbProtocolError: If an ACK is not received.
AdbStreamClosedError: If the stream is already closed, or gets closed
before the write completes.


def MergeOrAddUser(self, kb_user):

    user = self.GetUser(
        sid=kb_user.sid, uid=kb_user.uid, username=kb_user.username)
    new_attrs = []
    merge_conflicts = []
    if not user:
      new_attrs = self._CreateNewUser(kb_user)
    else:
      for key, val in iteritems(kb_user.AsDict()):
        if user.Get(key) and user.Get(key) != val:
          merge_conflicts.append((key, user.Get(key), val))
        user.Set(key, val)
        new_attrs.append("users.%s" % key)

    return new_attrs, merge_conflicts

Merge a user into existing users or add new if it doesn't exist.

Args:
kb_user: A User rdfvalue.

Returns:
A list of strings with the set attribute names, e.g. ["users.sid"]


def get_bounds(changeset):

    try:
        return Polygon([
            (float(changeset.get('min_lon')), float(changeset.get('min_lat'))),
            (float(changeset.get('max_lon')), float(changeset.get('min_lat'))),
            (float(changeset.get('max_lon')), float(changeset.get('max_lat'))),
            (float(changeset.get('min_lon')), float(changeset.get('max_lat'))),
            (float(changeset.get('min_lon')), float(changeset.get('min_lat'))),
            ])
    except TypeError:
        return Polygon()

Get the bounds of the changeset and return it as a Polygon object. If
the changeset has not coordinates (case of the changesets that deal only
with relations), it returns an empty Polygon.

Args:
changeset: the XML string of the changeset.


def poly_energy(sample_like, poly):

    msg = ("poly_energy is deprecated and will be removed in dimod 0.9.0."
           "In the future, use BinaryPolynomial.energy")
    warnings.warn(msg, DeprecationWarning)

    return BinaryPolynomial(poly, 'SPIN').energy(sample_like)

Calculates energy of a sample from a higher order polynomial.

Args:
sample (samples_like):
A raw sample. `samples_like` is an extension of NumPy's
array_like structure. See :func:`.as_samples`.

poly (dict):
Polynomial as a dict of form {term: bias, ...}, where `term` is a
tuple of variables and `bias` the associated bias.

Returns:
float: The energy of the sample.


def __init__(self, filename, asarfile, files, baseoffset):

        self.filename = filename
        self.asarfile = asarfile
        self.files = files
        self.baseoffset = baseoffset

Initializes a new instance of the :see AsarArchive class.

Args:
filename (str):
The path to the *.asar file to read/write from/to.

asarfile (File):
A open *.asar file object.

files (dict):
Dictionary of files contained in the archive.
(The header that was read from the file).

baseoffset (int):
Base offset, indicates where in the file the header ends.


def postprocess(chunks: typing.List[str]) -> typing.List[str]:
    chunks = break_before_sequence(chunks, '（')
    chunks = break_before_sequence(chunks, 'もら')
    return chunks

Applies some processes to modify the extracted chunks.

Args:
chunks (List[str]): Source chunks.

Returns:
Processed chunks.


def notify_on_change(enabled: bool=True) -> ContextManager[None]:
    return thread_local.thread_local_value_scope(_TLS_ENABLE_CHANGE_NOTIFICATION, enabled, True)

Returns a context manager to enable or disable notification upon change.

`notify_on_change` is thread-safe and can be nested. For example, in the
following code, `_on_change` (thus `_on_bound`) method of `a` will be
triggered due to the rebind in the inner `with` statement, and those of `b`
will not be triggered as the outer `with` statement disables the
notification::

with pg.notify_on_change(False):
with pg.notify_on_change(True):
a.rebind(b=1)
b.rebind(x=2)

Args:
enabled: If True, enable change notification in current scope.
Otherwise, disable notification.

Returns:
A context manager for allowing/disallowing change notification in scope.


def template_string(
    task: Task, template: str, jinja_filters: FiltersDict = None, **kwargs: Any
) -> Result:

    jinja_filters = jinja_filters or {} or task.nornir.config.jinja2.filters
    text = jinja_helper.render_from_string(
        template=template, host=task.host, jinja_filters=jinja_filters, **kwargs
    )
    return Result(host=task.host, result=text)

Renders a string with jinja2. All the host data is available in the template

Arguments:
template (string): template string
jinja_filters (dict): jinja filters to enable. Defaults to nornir.config.jinja2.filters
**kwargs: additional data to pass to the template

Returns:
Result object with the following attributes set:
* result (``string``): rendered string


def delete_resource(self, resource, delete=True):

        if isinstance(resource, str):
            if is_valid_uuid(resource) is False:
                raise HDXError('%s is not a valid resource id!' % resource)
        return self._remove_hdxobject(self.resources, resource, delete=delete)

Delete a resource from the dataset and also from HDX by default

Args:
resource (Union[hdx.data.resource.Resource,Dict,str]): Either resource id or resource metadata from a Resource object or a dictionary
delete (bool): Whetehr to delete the resource from HDX (not just the dataset). Defaults to True.

Returns:
bool: True if resource removed or False if not


def unique(ar):
    import dask.array as da
    if isinstance(ar, da.core.Array):
        return da.unique(ar)
    return _unique(ar)

r"""Find the unique elements of an array.

It uses ``dask.array.unique`` if necessary.

Args:
ar (array_like): Input array.

Returns:
array_like: the sorted unique elements.


def torch_equals_ignore_index(tensor, tensor_other, ignore_index=None):
    if (ignore_index is not None):
        assert (tensor.size() == tensor_other.size())
        mask_arr = tensor.ne(ignore_index)
        tensor = tensor.masked_select(mask_arr)
        tensor_other = tensor_other.masked_select(mask_arr)
    return torch.equal(tensor, tensor_other)

Compute ``torch.equal`` with the optional mask parameter.

Args:
ignore_index (int, optional): Specifies a ``tensor`` index that is ignored.

Returns:
(bool) Returns ``True`` if target and prediction are equal.


def normalize_build_spec(self, build_spec):
    for cmd in build_spec:
        if (not cmd):
            continue
        cmd_name = cmd.keys()[0]
        cmd_options = cmd.values()[0]
        cmd_handler = self.get_cmd_handler(cmd_name)
        self.build_cmds.append(cmd_handler(cmd_options))

Convert a build spec into a list of Command tuples.
After running this command, self.build_cmds should hold all
the commands that should be run on the disk in self.disk_path.

Args:
build_spec (dict): The buildspec part from the init file


def list_bindings(site):

    ret = dict()
    sites = list_sites()

    if site not in sites:
        log.warning('Site not found: %s', site)
        return ret

    ret = sites[site]['bindings']

    if not ret:
        log.warning('No bindings found for site: %s', site)

    return ret

Get all configured IIS bindings for the specified site.

Args:
site (str): The name if the IIS Site

Returns:
dict: A dictionary of the binding names and properties.

CLI Example:

.. code-block:: bash

salt '*' win_iis.list_bindings site


def _extract_gcs_api_response_error(message):

  try:
    if len(message) == 3:

      data = json.loads(message[2])
      return data['error']['errors'][0]['message']
  except Exception:
    pass
  return message

A helper function to extract user-friendly error messages from service exceptions.

Args:
message: An error message from an exception. If this is from our HTTP client code, it
will actually be a tuple.

Returns:
A modified version of the message that is less cryptic.


def freeze(script_path, target_dir='frozen', **kw):

    cmds = []
    freeze_start_time = time.time()
    logging.debug('/\\%s%s Output%s/\\' % ('-' * 10, 'Pyinstaller', '-' * 10))
    orig_dir = os.path.abspath('.')
    script_path = os.path.abspath(script_path)
    try:
        os.chdir(target_dir)
        cmds += _freeze_config()
        pyinst_path = '%s/thirdparty/pyinstaller' % __path__[0]
        cur_cmd = 'python -O %s/pyinstaller.py %s --skip-configure' % (pyinst_path, script_path)
        cmds.append(cur_cmd)
        if _run(cur_cmd):
            _freeze_config(force=True)
            cur_cmd = 'python -O %s/pyinstaller.py %s' % (pyinst_path, script_path)
            _run(cur_cmd)
    finally:
        os.chdir(orig_dir)
    logging.debug('\\/%s%s Output%s\\/' % ('-' * 10, 'Pyinstaller', '-' * 10))
    logging.info('Pyinstaller took [%f] seconds' % (time.time() - freeze_start_time))
    return cmds

Wraps pyinstaller and provides an easy to use interface

Args:
script_path: Absolute path to python script to be frozen.

Returns:
List of freeze commands ran

Raises:
subprocess.CalledProcessError: Freeze error.
OSError: Freeze not found.


def parse_string_to_constructor(ctor_string):
    orig_ctor_string = ctor_string
    if ('.' not in ctor_string):
        ctor_string = ('sonnet.' + ctor_string)
    if ctor_string.startswith('snt.'):
        ctor_string = ('sonnet.' + ctor_string[len('snt.'):])
    (package_name, rest) = ctor_string.split('.', 1)
    package = importlib.import_module(package_name)
    try:
        return _recursive_getattr(package, rest)
    except AttributeError:
        raise ValueError('could not find `{}`, after normalizing to `{}`'.format(orig_ctor_string, ctor_string))

Returns a callable which corresponds to the constructor string.

Various modules (eg, ConvNet2D) take constructor arguments which are
callables, indicating a submodule to build. These can be passed as
actual constructors, eg `snt.LayerNorm`, however that makes the config
for that module not trivially serializable. This function tries to map
a string representation to the underlying callable, allowing configs to
remain serializable where necessary.

Args:
ctor_string: string representing some module in Sonnet. If the string is
provided with no dots, we assume it is a member of Sonnet available at
top level, i.e. "LayerNorm" maps to `snt.LayerNorm`.

Raises:
ValueError: if no matching constructor can be found.

Returns:
Callable constructor which corresponds to `ctor_string`.


def set_suite_info(self, suite_info=None):
    self._suite_info = suite_info or {}

Interface for sub-classes to set user defined extra info to test summary.

Args:
suite_info: dict, A dict of suite information. Keys and values must be
serializable.


def register_subcommand(parser: ArgumentParser):
    train_parser = parser.add_parser('train', help='CLI tool to train a model on a task.')
    train_parser.add_argument('--train_data', type=str, required=True, help='path to train (and optionally evaluation) dataset as a csv with tab separated labels and sentences.')
    train_parser.add_argument('--column_label', type=int, default=0, help='Column of the dataset csv file with example labels.')
    train_parser.add_argument('--column_text', type=int, default=1, help='Column of the dataset csv file with example texts.')
    train_parser.add_argument('--column_id', type=int, default=2, help='Column of the dataset csv file with example ids.')
    train_parser.add_argument('--skip_first_row', action='store_true', help='Skip the first row of the csv file (headers).')
    train_parser.add_argument('--validation_data', type=str, default='', help='path to validation dataset.')
    train_parser.add_argument('--validation_split', type=float, default=0.1, help='if validation dataset is not provided, fraction of train dataset to use as validation dataset.')
    train_parser.add_argument('--output', type=str, default='./', help='path to saved the trained model.')
    train_parser.add_argument('--task', type=str, default='text_classification', help='Task to train the model on.')
    train_parser.add_argument('--model', type=str, default='google-bert/bert-base-uncased', help="Model's name or path to stored model.")
    train_parser.add_argument('--train_batch_size', type=int, default=32, help='Batch size for training.')
    train_parser.add_argument('--valid_batch_size', type=int, default=64, help='Batch size for validation.')
    train_parser.add_argument('--learning_rate', type=float, default=3e-05, help='Learning rate.')
    train_parser.add_argument('--adam_epsilon', type=float, default=1e-08, help='Epsilon for Adam optimizer.')
    train_parser.set_defaults(func=train_command_factory)

Register this command to argparse so it's available for the transformer-cli

Args:
parser: Root parser to register command-specific arguments


def set_spacing(self, space):

        self.figure.spacing = space
        if 'subplots_adjust_kwargs' not in self.figure.__dict__:
            self.figure.subplots_adjust_kwargs = {}
        if space == 'wide':
            self.figure.subplots_adjust_kwargs['hspace'] = 0.3
            self.figure.subplots_adjust_kwargs['wspace'] = 0.3
        else:
            self.figure.subplots_adjust_kwargs['hspace'] = 0.0
            self.figure.subplots_adjust_kwargs['wspace'] = 0.0

        return

Set the figure spacing.

Sets whether in general there is space between subplots.
If all axes are shared, this can be `tight`. Default in code is `wide`.

The main difference is the tick labels extend to the ends if space==`wide`.
If space==`tight`, the edge tick labels are cut off for clearity.

Args:
space (str): Sets spacing for subplots. Either `wide` or `tight`.


def _CopyTimeFromString(self, time_string):
    time_string_length = len(time_string)
    if (time_string_length < 8):
        raise ValueError('Time string too short.')
    if ((time_string[2] != ':') or (time_string[5] != ':')):
        raise ValueError('Invalid time string.')
    try:
        hours = int(time_string[0:2], 10)
    except ValueError:
        raise ValueError('Unable to parse hours.')
    if (hours not in range(0, 24)):
        raise ValueError('Hours value: {0:d} out of bounds.'.format(hours))
    try:
        minutes = int(time_string[3:5], 10)
    except ValueError:
        raise ValueError('Unable to parse minutes.')
    if (minutes not in range(0, 60)):
        raise ValueError('Minutes value: {0:d} out of bounds.'.format(minutes))
    try:
        seconds = int(time_string[6:8], 10)
    except ValueError:
        raise ValueError('Unable to parse day of seconds.')
    if (seconds not in range(0, 60)):
        raise ValueError('Seconds value: {0:d} out of bounds.'.format(seconds))
    microseconds = None
    time_zone_offset = None
    time_zone_string_index = 8
    while (time_zone_string_index < time_string_length):
        if (time_string[time_zone_string_index] in ('+', '-')):
            break
        time_zone_string_index += 1
    if (time_zone_string_index == (time_string_length - 1)):
        time_zone_string_index += 1
    if ((time_string_length > 8) and (time_string[8] == '.')):
        time_fraction_length = (time_zone_string_index - 9)
        if (time_fraction_length not in (3, 6)):
            raise ValueError('Invalid time string.')
        try:
            time_fraction = time_string[9:time_zone_string_index]
            time_fraction = int(time_fraction, 10)
        except ValueError:
            raise ValueError('Unable to parse time fraction.')
        if (time_fraction_length == 3):
            time_fraction *= 1000
        microseconds = time_fraction
    if (time_zone_string_index < time_string_length):
        if (((time_string_length - time_zone_string_index) != 6) or (time_string[(time_zone_string_index + 3)] != ':')):
            raise ValueError('Invalid time string.')
        try:
            hours_from_utc = int(time_string[(time_zone_string_index + 1):(time_zone_string_index + 3)])
        except ValueError:
            raise ValueError('Unable to parse time zone hours offset.')
        if (hours_from_utc not in range(0, 15)):
            raise ValueError('Time zone hours offset value out of bounds.')
        try:
            minutes_from_utc = int(time_string[(time_zone_string_index + 4):(time_zone_string_index + 6)])
        except ValueError:
            raise ValueError('Unable to parse time zone minutes offset.')
        if (minutes_from_utc not in range(0, 60)):
            raise ValueError('Time zone minutes offset value out of bounds.')
        time_zone_offset = ((hours_from_utc * 60) + minutes_from_utc)
        if (time_string[time_zone_string_index] != '-'):
            time_zone_offset = (- time_zone_offset)
    return (hours, minutes, seconds, microseconds, time_zone_offset)

Copies a time from a string.

Args:
time_string (str): time value formatted as:
hh:mm:ss.######[+-]##:##

Where # are numeric digits ranging from 0 to 9 and the seconds
fraction can be either 3 or 6 digits. The seconds fraction and
time zone offset are optional.

Returns:
tuple[int, int, int, int, int]: hours, minutes, seconds, microseconds,
time zone offset in minutes.

Raises:
ValueError: if the time string is invalid or not supported.


def __init__(self,
                 object_type=None,
                 template_attribute=None):

        super(CreateRequestPayload, self).__init__(
            tag=enums.Tags.REQUEST_PAYLOAD
        )

        self._object_type = None
        self._template_attribute = None

        self.object_type = object_type
        self.template_attribute = template_attribute

Construct a Create request payload structure.

Args:
object_type (enum): An ObjectType enumeration specifying the type
of object to create. Optional, defaults to None. Required for
read/write.
template_attribute (TemplateAttribute): A TemplateAttribute
structure containing a set of attributes to set on the new
object. Optional, defaults to None. Required for read/write.


def new_product(self, name):

        n = self._product_cls(self, name, summary_cls=self._summary_cls)
        self.graph.add_node(n)
        self.products.append(n)
        return n

Create a new product.

Args:
name: name of the new product.

Returns:
A new product instance.


def _update_exit_code_from_error(self, error):
    for (error_type, exit_code) in self.ERROR_CODE_MAP.items():
        if isinstance(error, error_type):
            self.update_exit_code(exit_code)
            break
    else:
        self.update_exit_code(ExitStatus.generic_error)

Set the exit code based on the error type.

Args:
error (:class:`Exception`): An exception instance.


def _expand_sequence(self, seq: List[GridQubit]) -> List[GridQubit]:
    i = 1
    while (i < len(seq)):
        path = self._find_path_between(seq[(i - 1)], seq[i], set(seq))
        if path:
            seq = ((seq[:i] + path) + seq[i:])
        else:
            i += 1
    return seq

Tries to expand given sequence with more qubits.

Args:
seq: Linear sequence of qubits.

Returns:
New continuous linear sequence which contains all the qubits from
seq and possibly new qubits inserted in between.


def l2_distance(t1, t2, epsilon=1e-12, name=None):

  with tf.name_scope(name, 'l2_distance', [t1, t2]) as scope:
    t1 = tf.convert_to_tensor(t1, name='t1')
    t2 = tf.convert_to_tensor(t2, name='t2')
    return tf.sqrt(tf.maximum(l2_distance_sq(t1, t2, scope), epsilon))

l2 distance between t1 and t2 and caps the gradient of the Square Root.

Args:
t1: A tensor.
t2: A tensor that is the same size as t1.
epsilon: A lower bound for distance, useful to avoid sqrt of very small
values that can blow up gradients.
name: Optional name for this op.
Returns:
The l2 distance between t1 and t2.


def load_array_types(self, fname):

    type_defs = ''
    with open(fname, 'rt') as fh:
      type_defs = fh.read()

    try:
      type_defs = ast.literal_eval(type_defs)
    except SyntaxError:
      type_defs = {}

    self._add_array_types(type_defs)

Load file of previously extracted data types

Args:
fname (str): Name of file to load array database from


def get_parameter_vector(self, include_frozen=False):
    if include_frozen:
        return self.parameter_vector
    return self.parameter_vector[self.unfrozen_mask]

Get an array of the parameter values in the correct order

Args:
include_frozen (Optional[bool]): Should the frozen parameters be
included in the returned value? (default: ``False``)


def version_info(self):
    if (self._api_version is None):
        self.query_api_version()
    return (self._api_version['api-major-version'], self._api_version['api-minor-version'])

Returns API version information for the HMC.

This operation does not require authentication.

Returns:

:term:`HMC API version`: The HMC API version supported by the HMC.

Raises:

:exc:`~zhmcclient.HTTPError`
:exc:`~zhmcclient.ParseError`
:exc:`~zhmcclient.ConnectionError`


def delete(self, service):
    url = self._url_format(service)
    return self.rest_action(self._session.delete, url)

Generic DELETE operation for Learning Modules API.

Args:
service (str): The endpoint service to use, i.e. gradebook

Raises:
requests.RequestException: Exception connection error
ValueError: Unable to decode response content

Returns:
list: the json-encoded content of the response


def parse_selinux(parts):

    owner, group = parts[:2]
    selinux = parts[2].split(":")
    lsel = len(selinux)
    path, link = parse_path(parts[-1])
    result = {
        "owner": owner,
        "group": group,
        "se_user": selinux[0],
        "se_role": selinux[1] if lsel > 1 else None,
        "se_type": selinux[2] if lsel > 2 else None,
        "se_mls": selinux[3] if lsel > 3 else None,
        "name": path
    }
    if link:
        result["link"] = link
    return result

Parse part of an ls output line that is selinux.

Args:
parts (list): A four element list of strings representing the initial
parts of an ls line after the permission bits. The parts are owner
group, selinux info, and the path.

Returns:
A dict containing owner, group, se_user, se_role, se_type, se_mls, and
name. If the raw name was a symbolic link, link is always included.


def _analemma_suns(self):
    for h in xrange(0, 24):
        if (self._analemma_position(h) < 0):
            continue
        elif (self._analemma_position(h) == 0):
            chours = []
            prevhour = (self.latitude <= 0)
            num_of_days = (8760 if (not self.is_leap_year) else (8760 + 24))
            for hoy in xrange(h, num_of_days, 24):
                thishour = self.calculate_sun_from_hoy(hoy).is_during_day
                if (thishour != prevhour):
                    if (not thishour):
                        hoy -= 24
                    dt = DateTime.from_hoy(hoy, self.is_leap_year)
                    chours.append((dt.month, dt.day, dt.hour))
                prevhour = thishour
            tt = []
            for hcount in range(int((len(chours) / 2))):
                st = chours[(2 * hcount)]
                en = chours[((2 * hcount) + 1)]
                if (self.latitude >= 0):
                    tt = (((([self.calculate_sun(*st)] + [self.calculate_sun(st[0], d, h) for d in xrange((st[1] + 1), 29, 7)]) + [self.calculate_sun(m, d, h) for m in xrange((st[0] + 1), en[0]) for d in xrange(3, 29, 7)]) + [self.calculate_sun(en[0], d, h) for d in xrange(3, en[1], 7)]) + [self.calculate_sun(*en)])
                else:
                    tt = ((((([self.calculate_sun(*en)] + [self.calculate_sun(en[0], d, h) for d in xrange((en[1] + 1), 29, 7)]) + [self.calculate_sun(m, d, h) for m in xrange((en[0] + 1), 13) for d in xrange(3, 29, 7)]) + [self.calculate_sun(m, d, h) for m in xrange(1, st[0]) for d in xrange(3, 29, 7)]) + [self.calculate_sun(st[0], d, h) for d in xrange(3, st[1], 7)]) + [self.calculate_sun(*st)])
                (yield tt)
        else:
            (yield tuple((self.calculate_sun(((m % 12) + 1), d, h) for m in xrange(0, 13) for d in (7, 14, 21)))[:(- 2)])

Calculate times that should be used for drawing analemma_curves.

Returns:
A list of list of analemma suns.


def median(series):
    if np.issubdtype(series.dtype, np.number):
        return series.median()
    else:
        return np.nan

Returns the median value of a series.

Args:
series (pandas.Series): column to summarize.


def set_white(self, brightness, colourtemp):
    if (not (25 <= brightness <= 255)):
        raise ValueError('The brightness needs to be between 25 and 255.')
    if (not (0 <= colourtemp <= 255)):
        raise ValueError('The colour temperature needs to be between 0 and 255.')
    payload = self.generate_payload(SET, {self.DPS_INDEX_MODE: self.DPS_MODE_WHITE, self.DPS_INDEX_BRIGHTNESS: brightness, self.DPS_INDEX_COLOURTEMP: colourtemp})
    data = self._send_receive(payload)
    return data

Set white coloured theme of an rgb bulb.

Args:
brightness(int): Value for the brightness (25-255).
colourtemp(int): Value for the colour temperature (0-255).


def eq(left: Any, right: Any) -> bool:
    if left is right:
        return True
    if isinstance(left, list) and isinstance(right, list) or (isinstance(left, tuple) and isinstance(right, tuple)):
        if len(left) != len(right):
            return False
        for x, y in zip(left, right):
            if ne(x, y):
                return False
        return True
    elif isinstance(left, dict):
        if not isinstance(right, dict) or len(left) != len(right) or set(left.keys()) != set(right.keys()):
            return False
        left_items = left.sym_items if isinstance(left, Symbolic) else left.items
        right_item = right.sym_getattr if isinstance(right, Symbolic) else right.__getitem__
        for k, v in left_items():
            if ne(v, right_item(k)):
                return False
        return True
    elif hasattr(left, 'sym_eq') and (not inspect.isclass(left)) and (left.sym_eq.__code__ is not Symbolic.sym_eq.__code__):
        return left.sym_eq(right)
    elif hasattr(right, 'sym_eq') and (not inspect.isclass(right)) and (right.sym_eq.__code__ is not Symbolic.sym_eq.__code__):
        return right.sym_eq(left)
    return pg_typing.callable_eq(left, right)

Compares if two values are equal. Use symbolic equality if possible.

Example::

@pg.members([
('x', pg.typing.Any())
])
class A(pg.Object):
def sym_eq(self, right):
if super().sym_eq(right):
return True
return pg.eq(self.x, right)

class B:
pass

assert pg.eq(1, 1)
assert pg.eq(A(1), A(1))
# This is True since A has override `sym_eq`.
assert pg.eq(A(1), 1)
# Objects of B are compared by references.
assert not pg.eq(A(B()), A(B()))

Args:
left: The left-hand value to compare.
right: The right-hand value to compare.

Returns:
True if left and right is equal or symbolically equal. Otherwise False.


def _convert_to_eval_metric(metric_fn):

  def problem_metric_fn(*args):

    (scores, weights) = metric_fn(*args)

    return tf.metrics.mean(scores, weights)
  return problem_metric_fn

Wrap a metric fn that returns scores and weights as an eval metric fn.

The input metric_fn returns values for the current batch. The wrapper
aggregates the return values collected over all of the batches evaluated.

Args:
metric_fn: function that returns scores and weights for the current batch's
logits and predicted labels.

Returns:
function that aggregates the scores and weights from metric_fn.


def diversity(layer):

    def inner(T):
        layer_t = T(layer)
        (batch_n, _, _, channels) = layer_t.get_shape().as_list()
        flattened = tf.reshape(layer_t, [batch_n, (- 1), channels])
        grams = tf.matmul(flattened, flattened, transpose_a=True)
        grams = tf.nn.l2_normalize(grams, axis=[1, 2], epsilon=1e-10)
        return (sum([sum([tf.reduce_sum((grams[i] * grams[j])) for j in range(batch_n) if (j != i)]) for i in range(batch_n)]) / batch_n)
    return inner

Encourage diversity between each batch element.

A neural net feature often responds to multiple things, but naive feature
visualization often only shows us one. If you optimize a batch of images,
this objective will encourage them all to be different.

In particular, it caculuates the correlation matrix of activations at layer
for each image, and then penalizes cossine similarity between them. This is
very similar to ideas in style transfer, except we're *penalizing* style
similarity instead of encouraging it.

Args:
layer: layer to evaluate activation correlations on.

Returns:
Objective.


def apply_transformation(self, structure):
    if structure.is_ordered:
        return structure
    species = [dict(sp) for sp in structure.species_and_occu]
    for sp in species:
        for (k, v) in sp.items():
            old_occ = sp[k]
            new_occ = float(Fraction(old_occ).limit_denominator(self.max_denominator))
            if self.fix_denominator:
                new_occ = (around((old_occ * self.max_denominator)) / self.max_denominator)
            if (round(abs((old_occ - new_occ)), 6) > self.tol):
                raise RuntimeError('Cannot discretize structure within tolerance!')
            sp[k] = new_occ
    return Structure(structure.lattice, species, structure.frac_coords)

Discretizes the site occupancies in the structure.

Args:
structure: disordered Structure to discretize occupancies

Returns:
A new disordered Structure with occupancies discretized


def get_device_topology(self, id_or_uri):
    uri = (self._client.build_uri(id_or_uri) + '/deviceTopology')
    return self._client.get(uri)

Retrieves the topology information for the rack resource specified by ID or URI.

Args:
id_or_uri: Can be either the resource ID or the resource URI.

Return:
dict: Device topology.


def __init__(self, serial=None, **kwargs):

        self.__display = None
        serial = serial or getenvs('ATX_ADB_SERIALNO', 'ANDROID_SERIAL')
        self._host = kwargs.get('host') or getenvs(
            'ATX_ADB_HOST', 'ANDROID_ADB_SERVER_HOST') or '127.0.0.1'
        self._port = int(kwargs.get('port') or getenvs(
            'ATX_ADB_PORT', 'ANDROID_ADB_SERVER_PORT') or 5037)

        self._adb_client = adbkit.Client(self._host, self._port)
        self._adb_device = self._adb_client.device(serial)

        self._uiauto = uiautomator2.connect_usb(serial)
        if not self._uiauto.alive:
            self._uiauto.healthcheck(unlock=False)

        DeviceMixin.__init__(self)
        self._randid = base.id_generator(5)

        self.screen_rotation = None

        self.swipe = self._uiauto.swipe
        self.drag = self._uiauto.drag
        self.press = self._uiauto.press
        self.long_click = self._uiauto.long_click
        self.dump = self._uiauto.dump_hierarchy

Initial AndroidDevice
Args:
serial (str): serial or wlan ip

Returns:
AndroidDevice object

Raises:
EnvironmentError


def __call__(self, dumper: 'Dumper', data: Any) -> yaml.MappingNode:

        logger.info('Representing {} of class {}'.format(
            data, self.class_.__name__))
        if hasattr(data, 'yatiml_attributes'):
            logger.debug('Found yatiml_attributes()')
            attributes = data.yatiml_attributes()
            if attributes is None:
                raise RuntimeError(('{}.yatiml_attributes() returned None,'
                                    ' where a dict was expected.').format(
                                        self.class_.__name__))
        else:
            logger.debug(
                'No yatiml_attributes() found, using public attributes')
            argspec = inspect.getfullargspec(data.__init__)
            attribute_names = list(argspec.args[1:])
            attrs = [(name, getattr(data, name)) for name in attribute_names
                     if name != 'yatiml_extra']
            if 'yatiml_extra' in attribute_names:
                if not hasattr(data, 'yatiml_extra'):
                    raise RuntimeError(
                        ('Class {} takes yatiml_extra but has '
                         ' no yatiml_extra attribute, and no '
                         ' yatiml_attributes().').format(self.class_.__name__))
                attrs.extend(data.yatiml_extra.items())
            attributes = yaml.comments.CommentedMap(attrs)

        represented = dumper.represent_mapping('tag:yaml.org,2002:map',
                                               attributes)

        cnode = Node(represented)
        self.__sweeten(dumper, self.class_, cnode)
        represented = cnode.yaml_node

        logger.debug('End representing {}'.format(data))
        return represented

Represents the class as a MappingNode.

Args:
dumper: The dumper to use.
data: The user-defined object to dump.

Returns:
A yaml.Node representing the object.


def assertShapeEqual(self, input_a, input_b, msg=None):
    if not isinstance(input_a, (np.ndarray, np.generic, tensor_lib.Tensor)):
        raise TypeError(f'input_a must be a Numpy ndarray, Numpy scalar, or a Tensor.Instead received {type(input_a)}')
    if not isinstance(input_b, (np.ndarray, np.generic, tensor_lib.Tensor)):
        raise TypeError(f'input_b must be a Numpy ndarray, Numpy scalar, or a Tensor.Instead received {type(input_b)}')
    shape_a = input_a.get_shape().as_list() if isinstance(input_a, tensor_lib.Tensor) else input_a.shape
    shape_b = input_b.get_shape().as_list() if isinstance(input_b, tensor_lib.Tensor) else input_b.shape
    self.assertAllEqual(shape_a, shape_b, msg=msg)

Asserts that two Numpy or TensorFlow objects have the same shape.

For Tensors, this compares statically known shapes at compile time, not
dynamic shapes at runtime.

Args:
input_a: A Numpy ndarray, Numpy scalar, or a Tensor.
input_b: A Numpy ndarray, Numpy scalar, or a Tensor.
msg: Optional message to report on failure.

Raises:
TypeError: If the arguments have the wrong type.


def recommend(self, limit=10):
    expected_list = [(arm_id, beta_dist.expected_value()) for (arm_id, beta_dist) in self.__beta_dist_dict.items()]
    expected_list = sorted(expected_list, key=(lambda x: x[1]), reverse=True)
    return expected_list[:limit]

Listup arms and expected value.

Args:
limit:      Length of the list.

Returns:
[Tuple(`Arms master id`, `expected value`)]


def setup(self, *args, **kwargs):
    pass

Called to prepare an instance for combining.

This method can be useful if there is some state that needs to be loaded
before executing any of the other methods. The resources can then be
disposed of in ``CombineFn.teardown``.

If you are using Dataflow, you need to enable Dataflow Runner V2
before using this feature.

Args:
*args: Additional arguments and side inputs.
**kwargs: Additional arguments and side inputs.


def put(self, item):
    with self._not_full:
        if self._closed:
            raise QueueClosedError()
        if self._maxsize > 0:
            while len(self._queue) == self._maxsize:
                self._not_full.wait()
                if self._closed:
                    raise QueueClosedError()
        self._queue.append(item)
        self._not_empty.notify()

Put an item into the queue.

If the queue is closed, fails immediately.

If the queue is full, blocks until space is available or until the queue
is closed by a call to close(), at which point this call fails.

Args:
item: an item to add to the queue

Raises:
QueueClosedError: if insertion failed because the queue is closed


def get_path_str(self, sep=os.path.sep, type_str=None):
    return sep.join(list(reversed([v.label_str for v in self.parent_gen if (type_str in (None, v.type_str))])))

Get path from root to this node.

Args:
sep: str
One or more characters to insert between each element in the path.
Defaults to "/" on Unix and "\" on Windows.

type_str:
SUBJECT_NODE_TAG, TYPE_NODE_TAG or None. If set, only include
information from nodes of that type.

Returns:
str: String describing the path from the root to this node.


def _format_param_val(self, param_val):

        if isinstance(param_val, list):
            return ' '.join(str(x) for x in param_val)
        else:
            return str(param_val)

Internal method to format values in the packmol parameter dictionaries

Args:
param_val:
Some object to turn into String

Returns:
string representation of the object


def iterable_source(iterable, target):
    it = iter(iterable)
    for item in it:
        try:
            target.send(item)
        except StopIteration:
            return prepend(item, it)
    return empty_iter()

Convert an iterable into a stream of events.

Args:
iterable: A series of items which will be sent to the target one by one.
target: The target coroutine or sink.

Returns:
An iterator over any remaining items.


def choose_1_from_each(lists):
    if (len(lists) == 0):
        (yield [])
    else:
        for el in lists[0]:
            for next_list in choose_1_from_each(lists[1:]):
                (yield ([el] + next_list))

Takes a list of lists and returns a list of lists with one item
from each list.  This new list should be the length of each list multiplied
by the others.  18 for an list with lists of 3, 2 and 3.  Also the lenght
of each sub list should be same as the length of lists passed in.

Args:
lists(list of Lists):  A list of lists

Returns:
list of lists: returns a list of lists constructions of one item from each
list in lists.


def garbage_collect_exports(export_dir_base, exports_to_keep):

  if exports_to_keep is None:
    return
  version_paths = []
  for filename in tf_v1.gfile.ListDirectory(export_dir_base):
    path = os.path.join(
        tf.compat.as_bytes(export_dir_base),
        tf.compat.as_bytes(filename))
    if len(filename) == 10 and filename.isdigit():
      version_paths.append((int(filename), path))

  oldest_version_path = sorted(version_paths)[:-exports_to_keep]
  for _, path in oldest_version_path:
    try:
      tf_v1.gfile.DeleteRecursively(path)
    except tf.errors.NotFoundError as e:
      logging.warn("Can not delete %s recursively: %s", path, e)

Deletes older exports, retaining only a given number of the most recent.

Export subdirectories are assumed to be named with monotonically increasing
integers; the most recent are taken to be those with the largest values.

Args:
export_dir_base: the base directory under which each export is in a
versioned subdirectory.
exports_to_keep: Number of exports to keep. Older exports will be garbage
collected. Set to None to disable.


def load(filename):

    if not os.path.exists(filename):
        LOG.error("load object - File '%s' does not exist.", filename)
        return None

    obj = None
    with open(filename, 'rb') as obj_file:
        obj = dill.load(obj_file)
    return obj

Load a pickled obj from the filesystem.

You better know what you expect from the given pickle, because we don't check it.

Args:
filename (str): The filename we load the object from.

Returns:
The object we were able to unpickle, else None.


def forward(self, input_ids: torch.Tensor, cache_position: torch.Tensor) -> torch.Tensor:
    batch_size = input_ids.shape[0]
    position_ids = cache_position.unsqueeze(0).expand(batch_size, -1)
    outputs = self.model(input_ids=input_ids, attention_mask=None, position_ids=position_ids, past_key_values=self.cache, use_cache=True, cache_position=cache_position)
    return outputs.logits

Forward pass of the module, which is compatible with the ExecuTorch llm runner.

Args:
input_ids (`torch.Tensor`): Tensor representing current input token id to the module.
cache_position (`torch.Tensor`): Tensor representing current input position in the cache.

Returns:
torch.Tensor: Logits output from the model.


def lookup_replicas(self, task_id: int, logical_core: int) -> List[int]:
    try:
        return self._task_and_cores_to_replicas[task_id][logical_core]
    except KeyError:
        raise ValueError('Can not find any replica in task: {} contains logical_core: {} '.format(task_id, logical_core))

Lookup replica ids by task number and logical core.

Args:
task_id: TensorFlow task number.
logical_core: An integer, identifying a logical core.
Returns:
A sorted list of the replicas that are attached to that task and
logical_core.
Raises:
ValueError: If no replica exists in the task which contains the logical
core.


def add_listener(self, callback, event_type=None):
    listener_uid = uuid4()
    self.listeners.append({'uid': listener_uid, 'callback': callback, 'event_type': event_type})
    return listener_uid

Add a listener that will send a callback when the client recieves
an event.

Args:
callback (func(roomchunk)): Callback called when an event arrives.
event_type (str): The event_type to filter for.

Returns:
uuid.UUID: Unique id of the listener, can be used to identify the listener.


def get_requirements(requirements_file="requirements.txt"):

    with open(requirements_file) as fd:
        lines = fd.readlines()
    dependencies = []
    for line in lines:
        maybe_dep = line.strip()
        if maybe_dep.startswith("

            continue
        if maybe_dep.startswith("git+"):

            __, __, maybe_dep = maybe_dep.rpartition("
        else:

            maybe_dep, __, __ = maybe_dep.partition("

        maybe_dep = maybe_dep.strip()
        if maybe_dep:
            dependencies.append(maybe_dep)
    return dependencies

Get the contents of a file listing the requirements.

Args:
requirements_file (str): The path to the requirements file, relative
to this file.

Returns:
list: the list of requirements, or an empty list if
``requirements_file`` could not be opened or read.


def length_of_overlap(first_start, first_end, second_start, second_end):

    if first_end <= second_start or first_start >= second_end:
        return 0.0

    if first_start < second_start:
        if first_end < second_end:
            return abs(first_end - second_start)
        else:
            return abs(second_end - second_start)

    if first_start > second_start:
        if first_end > second_end:
            return abs(second_end - first_start)
        else:
            return abs(first_end - first_start)

Find the length of the overlapping part of two segments.

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

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


def fetch_tokens(self, client_id=None, client_secret=None, code=None,
                     redirect_uri=None, **kwargs):

        client_id = client_id or self.client_id
        client_secret = client_secret or self.client_secret
        redirect_uri = redirect_uri or self.redirect_uri
        data = {
           'grant_type': 'authorization_code',
           'client_id': client_id,
           'client_secret': client_secret,
           'code': code,
           'redirect_uri': redirect_uri
        }
        r = self._httpclient.request(
            method='POST',
            url=self.token_url,
            json=data,
            path='/api/oauth2/RequestToken',
            auth=None,
            **kwargs
        )
        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')
            self.jwt_exp = self._decode_exp(self.access_token_)
            self.refresh_token = r_json.get('refresh_token')
            self.write_credentials()
            return r_json

Exchange authorization code for token.

Args:
client_id (str): OAuth2 client ID. Defaults to ``None``.
client_secret (str): OAuth2 client secret. Defaults to ``None``.
code (str): Authorization code. Defaults to ``None``.
redirect_uri (str): Redirect URI. Defaults to ``None``.

Returns:
dict: Response from token URL.


def subscribe(object_type: str, subscriber: str, callback_handler: Callable=None) -> EventQueue:
    key = _keys.subscribers(object_type)
    DB.remove_from_list(key, subscriber)
    DB.append_to_list(key, subscriber)
    return EventQueue(object_type, subscriber, callback_handler)

Subscribe to the specified object type.

Returns an EventQueue object which can be used to query events
associated with the object type for this subscriber.

Args:
object_type (str): Object type
subscriber (str): Subscriber name
callback_handler (function, optional): Callback handler function.

Returns:
EventQueue, event queue object.


def ParseFileObject(self, parser_mediator, file_object):

    win_registry_reader = FileObjectWinRegistryFileReader()

    try:
      registry_file = win_registry_reader.Open(file_object)
    except IOError as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to open Windows Registry file with error: {0!s}'.format(
              exception))
      return

    win_registry = dfwinreg_registry.WinRegistry()

    key_path_prefix = win_registry.GetRegistryFileMapping(registry_file)
    registry_file.SetKeyPathPrefix(key_path_prefix)
    root_key = registry_file.GetRootKey()
    if not root_key:
      return

    registry_find_specs = getattr(
        parser_mediator.artifacts_filter_helper, 'registry_find_specs', None)

    if not registry_find_specs:
      try:
        self._ParseRecurseKeys(parser_mediator, root_key)
      except IOError as exception:
        parser_mediator.ProduceExtractionWarning('{0!s}'.format(exception))

    else:
      artifacts_filter_helper = artifact_filters.ArtifactDefinitionsFilterHelper
      if not artifacts_filter_helper.CheckKeyCompatibility(key_path_prefix):
        logger.warning((
            'Artifacts filters are not supported for Windows Registry file '
            'with key path prefix: "{0:s}".').format(key_path_prefix))

      else:
        try:
          win_registry.MapFile(key_path_prefix, registry_file)
          self._ParseKeysFromFindSpecs(
              parser_mediator, win_registry, registry_find_specs)
        except IOError as exception:
          parser_mediator.ProduceExtractionWarning('{0!s}'.format(exception))

Parses a Windows Registry file-like object.

Args:
parser_mediator (ParserMediator): parser mediator.
file_object (dfvfs.FileIO): a file-like object.


def get_conflicting_tools(self, request_only=False):
    from collections import defaultdict
    tool_sets = defaultdict(set)
    tools_dict = self.get_tools(request_only=request_only)
    for (variant, tools) in tools_dict.itervalues():
        for tool in tools:
            tool_sets[tool].add(variant)
    conflicts = dict(((k, v) for (k, v) in tool_sets.iteritems() if (len(v) > 1)))
    return conflicts

Returns tools of the same name provided by more than one package.

Args:
request_only: If True, only return the key from resolved packages
that were also present in the request.

Returns:
Dict of {tool-name: set([Variant])}.


def scalar_projection(v1, v2):

    return np.dot(v1, v2) / np.linalg.norm(v2)

compute the scalar projection of v1 upon v2

Args:
v1, v2: iterable
indices 0, 1, 2 corresponding to cartesian coordinates

Returns:
3-vector of the projection of point p onto the direction of v


def setup_engines(client=None):
    if (not client):
        try:
            client = ipyparallel.Client()
        except:
            raise DistobClusterError(u"Could not connect to an ipyparallel cluster. Make\n                 sure a cluster is started (e.g. to use the CPUs of a\n                 single computer, can type 'ipcluster start')")
    eids = client.ids
    if (not eids):
        raise DistobClusterError(u'No ipyparallel compute engines are available')
    nengines = len(eids)
    dv = client[eids]
    dv.use_dill()
    with dv.sync_imports(quiet=True):
        import distob
    ars = []
    for i in eids:
        dv.targets = i
        ars.append(dv.apply_async(_remote_setup_engine, i, nengines))
    dv.wait(ars)
    for ar in ars:
        if (not ar.successful()):
            raise ar.r
    if (distob.engine is None):
        distob.engine = ObjectHub((- 1), client)

Prepare all iPython engines for distributed object processing.

Args:
client (ipyparallel.Client, optional): If None, will create a client
using the default ipyparallel profile.


def remove_behaviour(self, behaviour):

        if not self.has_behaviour(behaviour):
            raise ValueError("This behaviour is not registered")
        index = self.behaviours.index(behaviour)
        self.behaviours[index].kill()
        self.behaviours.pop(index)

Removes a behaviour from the agent.
The behaviour is first killed.

Args:
behaviour (spade.behaviour.CyclicBehaviour): the behaviour instance to be removed


def gallery_section(images, title):

    imgs = []
    while True:
        img = yield marv.pull(images)
        if img is None:
            break
        imgs.append({'src': img.relpath})
    if not imgs:
        return

    widget = {'title': images.title, 'gallery': {'images': imgs}}
    section = {'title': title, 'widgets': [widget]}
    yield marv.push(section)

Create detail section with gallery.

Args:
title (str): Title to be displayed for detail section.
images: stream of marv image files

Returns
One detail section.


class JetMoeMoA(nn.Module):

    def __init__(self, config: JetMoeConfig):
        super(JetMoeMoA, self).__init__()
        self.num_experts = config.num_local_experts
        self.input_size = config.hidden_size
        self.hidden_size = config.kv_channels * config.num_key_value_heads
        self.top_k = config.num_experts_per_tok
        self.bias = torch.nn.Parameter(torch.empty(self.input_size))
        self.input_linear = JetMoeParallelExperts(self.num_experts, self.input_size, self.hidden_size)
        self.output_linear = JetMoeParallelExperts(self.num_experts, self.hidden_size, self.input_size)
        self.router = JetMoeTopKGating(input_size=self.input_size, num_experts=self.num_experts, top_k=self.top_k)

    def map(self, layer_input):

        bsz, length, emb_size = layer_input.size()
        layer_input = layer_input.reshape(-1, emb_size)
        index_sorted_experts, batch_index, batch_gates, expert_size, router_logits = self.router(layer_input)
        topo_info = (index_sorted_experts, batch_index, batch_gates, expert_size)
        expert_inputs = layer_input[batch_index]
        expert_outputs = self.input_linear(expert_inputs, expert_size)
        zeros = torch.zeros((bsz * length * self.top_k, self.hidden_size), dtype=expert_outputs.dtype, device=expert_outputs.device)
        layer_output = zeros.index_add(0, index_sorted_experts, expert_outputs)
        layer_output = layer_output.view(bsz, length, self.top_k, -1)
        return (layer_output, router_logits, topo_info)

    def reduce(self, layer_input, topo_info):

        bsz, length, k, hidden_size = layer_input.size()
        layer_input = layer_input.reshape(-1, hidden_size)
        index_sorted_experts, batch_index, batch_gates, expert_size = topo_info
        expert_inputs = layer_input[index_sorted_experts]
        expert_outputs = self.output_linear(expert_inputs, expert_size)
        expert_outputs = expert_outputs * batch_gates[:, None]
        zeros = torch.zeros((bsz * length, self.input_size), dtype=expert_outputs.dtype, device=expert_outputs.device)
        layer_output = zeros.index_add(0, batch_index, expert_outputs)
        layer_output = layer_output.view(bsz, length, self.input_size)
        layer_output = layer_output + self.bias
        return layer_output

    def forward(self, layer_input):
        raise NotImplementedError("This module doesn't support call and forward.")

A Sparsely gated mixture of attention layer with pairs of query- and output-projections as experts.

Args:
config:
Configuration object with model hyperparameters.


def dot(inputs, axes, normalize=False, **kwargs):
    return Dot(axes=axes, normalize=normalize, **kwargs)(inputs)

Functional interface to the `Dot` layer.

Args:
inputs: A list of input tensors (at least 2).
axes: Integer or tuple of integers,
axis or axes along which to take the dot product.
normalize: Whether to L2-normalize samples along the
dot product axis before taking the dot product.
If set to True, then the output of the dot product
is the cosine proximity between the two samples.
**kwargs: Standard layer keyword arguments.

Returns:
A tensor, the dot product of the samples from the inputs.


def print_probabilities(state: State, ndigits: int = 4,
                        file: TextIO = None) -> None:

    prob = bk.evaluate(state.probabilities())
    for index, prob in np.ndenumerate(prob):
        prob = round(prob, ndigits)
        if prob == 0.0:
            continue
        ket = "".join([str(n) for n in index])
        print(ket, ":", prob, file=file)

Pretty print state probabilities.

Args:
state:
ndigits: Number of digits of accuracy
file: Output stream (Defaults to stdout)


def get_summary_dict(self, include_msd_t=False, include_mscd_t=False):
    d = {'D': self.diffusivity, 'D_sigma': self.diffusivity_std_dev, 'D_charge': self.chg_diffusivity, 'D_charge_sigma': self.chg_diffusivity_std_dev, 'S': self.conductivity, 'S_sigma': self.conductivity_std_dev, 'S_charge': self.chg_conductivity, 'D_components': self.diffusivity_components.tolist(), 'S_components': self.conductivity_components.tolist(), 'D_components_sigma': self.diffusivity_components_std_dev.tolist(), 'S_components_sigma': self.conductivity_components_std_dev.tolist(), 'specie': str(self.specie), 'step_skip': self.step_skip, 'time_step': self.time_step, 'temperature': self.temperature, 'max_framework_displacement': self.max_framework_displacement, 'Haven_ratio': self.haven_ratio}
    if include_msd_t:
        d['msd'] = self.msd.tolist()
        d['msd_components'] = self.msd_components.tolist()
        d['dt'] = self.dt.tolist()
    if include_mscd_t:
        d['mscd'] = self.mscd.tolist()
    return d

Provides a summary of diffusion information.

Args:
include_msd_t (bool): Whether to include mean square displace and
time data with the data.
include_msd_t (bool): Whether to include mean square charge displace and
time data with the data.

Returns:
(dict) of diffusion and conductivity data.


def get_iso3_country_code(cls, country, use_live=True, exception=None):

        countriesdata = cls.countriesdata(use_live=use_live)
        countryupper = country.upper()
        len_countryupper = len(countryupper)
        if len_countryupper == 3:
            if countryupper in countriesdata['countries']:
                return countryupper
        elif len_countryupper == 2:
            iso3 = countriesdata['iso2iso3'].get(countryupper)
            if iso3 is not None:
                return iso3

        iso3 = countriesdata['countrynames2iso3'].get(countryupper)
        if iso3 is not None:
            return iso3

        for candidate in cls.expand_countryname_abbrevs(countryupper):
            iso3 = countriesdata['countrynames2iso3'].get(candidate)
            if iso3 is not None:
                return iso3

        if exception is not None:
            raise exception
        return None

Get ISO3 code for cls. Only exact matches or None are returned.

Args:
country (str): Country for which to get ISO3 code
use_live (bool): Try to get use latest data from web rather than file in package. Defaults to True.
exception (Optional[ExceptionUpperBound]): An exception to raise if country not found. Defaults to None.

Returns:
Optional[str]: ISO3 country code or None


def optimize(
        self,
        re_encoder_grads_list,
        decoder_grads_list,
        encoder_grads_list,
        learning_rate,
        epoch
    ):

        self.__retrospective_encoder.optimize(re_encoder_grads_list, learning_rate, epoch)
        self.__encoder_decoder_controller.optimize(
            decoder_grads_list,
            encoder_grads_list,
            learning_rate,
            epoch
        )

Back propagation.

Args:
re_encoder_grads_list:  re-encoder's `list` of graduations.
decoder_grads_list:     decoder's `list` of graduations.
encoder_grads_list:     encoder's `list` of graduations.
learning_rate:          Learning rate.
epoch:                  Now epoch.


def vrp_solver(path_graph, initial_solution=None, runtime_seconds=60):

    routing = pywrapcp.RoutingModel(path_graph.num_nodes(),
                                    1, path_graph.ORIGIN)

    for disjunction in path_graph.iter_disjunctions():
        routing.AddDisjunction(disjunction)

    COST_MULTIPLIER = 1e4

    def distance(i, j):
        return int(path_graph.cost(i, j) * COST_MULTIPLIER)
    routing.SetArcCostEvaluatorOfAllVehicles(distance)

    start_time = time()

    def found_solution():
        t = time() - start_time
        cost = routing.CostVar().Max() / COST_MULTIPLIER
        print('\rBest solution at {} seconds has cost {}        '.format(
            int(t), cost), end='')
    routing.AddAtSolutionCallback(found_solution)

    if not initial_solution:
        initial_solution = [i for i, _ in path_graph.iter_disjunctions()]

    initial_assignment = routing.ReadAssignmentFromRoutes([initial_solution],
                                                          True)

    search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters()
    search_parameters.time_limit_ms = runtime_seconds * 1000
    search_parameters.local_search_metaheuristic = (
        routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH)

    assignment = routing.SolveFromAssignmentWithParameters(initial_assignment,
                                                           search_parameters)
    print()

    solution = []
    index = routing.Start(0)
    while not routing.IsEnd(index):
        index = assignment.Value(routing.NextVar(index))
        node = routing.IndexToNode(index)
        if node != 0:

            solution.append(node)
    return solution

Solve a path using or-tools' Vehicle Routing Problem solver.
Params:
path_graph        the PathGraph representing the problem
initial_solution  a solution to start with (list of indices, not
including the origin)
runtime_seconds   how long to search before returning

Returns: an ordered list of indices in the graph representing a
solution.


def _publish_actor_class_to_key(self, key, actor_class_info):
    self._worker.redis_client.hmset(key, actor_class_info)
    self._worker.redis_client.rpush('Exports', key)

Push an actor class definition to Redis.

The is factored out as a separate function because it is also called
on cached actor class definitions when a worker connects for the first
time.

Args:
key: The key to store the actor class info at.
actor_class_info: Information about the actor class.


def _get_operand_name_and_index(self, numeric_verify_name: str) -> Tuple[str, int]:
    tensor_name, tensor_idx = numeric_verify_name.rsplit(':', 1)
    float_tensor_name = tensor_name[len(_NUMERIC_VERIFY_OP_NAME) + 1:]
    if re.match('\\d', float_tensor_name[-1]):
        float_tensor_name = float_tensor_name[:-1]
    return (float_tensor_name, int(tensor_idx))

Gets the index and name of NumericVerify Op's quantized input tensor.

Args:
numeric_verify_name: name of the NumericVerify op's output tensor. It has
format of `NumericVerify/{quantized_tensor_name}:{quantized_tensor_idx}`

Returns:
Tuple of (tensor_name, tensor_idx) for quantized op's output tensor.


def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None):

        init_params = super(MXNet, cls)._prepare_init_params_from_job_description(job_details, model_channel_name)
        image_name = init_params.pop('image')
        framework, py_version, tag, _ = framework_name_from_image(image_name)

        if not framework:

            init_params['image_name'] = image_name
            return init_params

        init_params['py_version'] = py_version

        init_params['framework_version'] = '0.12' if tag == '1.0' else framework_version_from_tag(tag)

        training_job_name = init_params['base_job_name']

        if framework != cls.__framework_name__:
            raise ValueError("Training job: {} didn't use image for requested framework".format(training_job_name))

        return init_params

Convert the job description to init params that can be handled by the class constructor

Args:
job_details: the returned job details from a describe_training_job API call.
model_channel_name (str): Name of the channel where pre-trained model data will be downloaded.

Returns:
dictionary: The transformed init_params


def constant_value_as_shape(tensor):
    if isinstance(tensor, core.Value):
        return tensor_shape.TensorShape([dim if dim != -1 else None for dim in tensor.numpy()])
    if tensor.get_shape().ndims == 0:
        value = constant_value(tensor)
        if value is None:
            raise ValueError("Received a scalar with unknown value as shape; require a statically known scalar with value '-1' to describe an unknown shape.")
        if value != -1:
            raise ValueError(f"Received a scalar value '{value}' as shape; require a statically known scalar with value '-1' to describe an unknown shape.")
        return tensor_shape.unknown_shape()
    shape = tensor.get_shape().with_rank(1)
    if shape == [0]:
        return tensor_shape.TensorShape([])
    elif tensor.op.type == 'Cast':
        pre_cast = constant_value_as_shape(tensor.op.inputs[0])
        if pre_cast.dims is None:
            return pre_cast
        cast_dtype = dtypes.as_dtype(tensor.op.get_attr('DstT'))
        if cast_dtype not in (dtypes.int32, dtypes.int64):
            return tensor_shape.unknown_shape(shape.dims[0].value)
        dest_dtype_shape_array = np.array([x if x is not None else -1 for x in pre_cast.as_list()]).astype(cast_dtype.as_numpy_dtype)
        return tensor_shape.TensorShape([x if x >= 0 else None for x in dest_dtype_shape_array])
    elif tensor.op.type == 'Shape':
        return tensor.op.inputs[0].get_shape()
    elif tensor.op.type == 'Pack':
        ret = tensor_shape.TensorShape([])
        assert tensor.op.get_attr('axis') == 0
        for pack_input in tensor.op.inputs:
            pack_input_val = constant_value(pack_input)
            if pack_input_val is None or pack_input_val < 0:
                new_dim = tensor_shape.Dimension(None)
            else:
                new_dim = tensor_shape.Dimension(pack_input_val)
            ret = ret.concatenate([new_dim])
        return ret
    elif tensor.op.type == 'Concat':
        ret = tensor_shape.TensorShape([])
        for concat_input in tensor.op.inputs[1:]:
            ret = ret.concatenate(constant_value_as_shape(concat_input))
        return ret
    elif tensor.op.type == 'ConcatV2':
        ret = tensor_shape.TensorShape([])
        for concat_input in tensor.op.inputs[:-1]:
            ret = ret.concatenate(constant_value_as_shape(concat_input))
        return ret
    elif tensor.op.type == 'StridedSlice':
        try:
            begin = constant_value(tensor.op.inputs[1])
            end = constant_value(tensor.op.inputs[2])
            strides = constant_value(tensor.op.inputs[3])
            if begin is not None and end is not None and (strides is not None):
                begin = begin[0]
                end = end[0]
                strides = strides[0]
                begin_mask = tensor.op.get_attr('begin_mask')
                if begin_mask == 1:
                    begin = None
                end_mask = tensor.op.get_attr('end_mask')
                if end_mask == 1:
                    end = None
                ellipsis_mask = tensor.op.get_attr('ellipsis_mask')
                new_axis_mask = tensor.op.get_attr('new_axis_mask')
                shrink_axis_mask = tensor.op.get_attr('shrink_axis_mask')
                valid_attributes = not ellipsis_mask and (not new_axis_mask) and (not shrink_axis_mask) and (not begin_mask or begin_mask == 1) and (not end_mask or end_mask == 1)
                if valid_attributes:
                    prev = constant_value_as_shape(tensor.op.inputs[0])
                    prev = prev[begin:end:strides]
                    ret = tensor_shape.TensorShape(prev)
                    return ret
        except ValueError:
            pass
        except TypeError:
            pass
    elif tensor.op.type == 'Placeholder' and tensor.op.graph.building_function and hasattr(tensor.op.graph, 'internal_captures'):
        for i, capture in enumerate(tensor.op.graph.internal_captures):
            if capture is tensor:
                external_capture = tensor.op.graph.external_captures[i]
                return constant_value_as_shape(external_capture)
    ret = tensor_shape.unknown_shape(shape.dims[0].value)
    value = constant_value(tensor)
    if value is not None:
        ret = ret.merge_with(tensor_shape.TensorShape([d if d >= 0 else None for d in value]))
    return ret

A version of `constant_value()` that returns a `TensorShape`.

This version should be used when a constant tensor value is
interpreted as a (possibly partial) shape, e.g. in the shape
function for `tf.reshape()`. By explicitly requesting a
`TensorShape` as the return value, it is possible to represent
unknown dimensions; by contrast, `constant_value()` is
all-or-nothing.

Args:
tensor: The rank-0 or rank-1 Tensor to be evaluated.

Returns:
A `TensorShape` based on the constant value of the given `tensor`.

Raises:
ValueError: If the shape is rank-0 and is not statically known to be -1.


def GetTARInfo(self):
    if (not self._tar_info):
        location = getattr(self.path_spec, 'location', None)
        if (location is None):
            raise errors.PathSpecError('Path specification missing location.')
        if (not location.startswith(self._file_system.LOCATION_ROOT)):
            raise errors.PathSpecError('Invalid location in path specification.')
        if (len(location) == 1):
            return None
        tar_file = self._file_system.GetTARFile()
        try:
            self._tar_info = tar_file.getmember(location[1:])
        except KeyError:
            pass
    return self._tar_info

Retrieves the TAR info.

Returns:
tarfile.TARInfo: TAR info or None if it does not exist.

Raises:
PathSpecError: if the path specification is incorrect.


def to_hdf(self, path, key, mode='a'):
    pd.DataFrame(self.serialize()).to_hdf(path, key, mode=mode, format='table', complib='zlib', complevel=9)
    f = h5py.File(path, 'r+')
    f[key].attrs['microns_per_pixel'] = (float(self.microns_per_pixel) if (self.microns_per_pixel is not None) else np.nan)
    f.close()

Save the CellDataFrame to an hdf5 file.

Args:
path (str): the path to save to
key (str): the name of the location to save it to
mode (str): write mode


def _ParseVValueString(
      self, parser_mediator, data, user_information_descriptor):

    data_start_offset = (
        user_information_descriptor.offset + self._V_VALUE_STRINGS_OFFSET)
    data_end_offset = data_start_offset + user_information_descriptor.size
    descriptor_data = data[data_start_offset:data_end_offset]

    try:
      username = descriptor_data.decode('utf-16-le')
    except (UnicodeDecodeError, UnicodeEncodeError) as exception:
      username = descriptor_data.decode('utf-16-le', errors='replace')
      parser_mediator.ProduceExtractionWarning((
          'unable to decode V value string with error: {0!s}. Characters '
          'that cannot be decoded will be replaced with "?" or '
          '"\\ufffd".').format(exception))

    return username

Parses a V value string.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
data (bytes): Windows Registry V value data.
user_information_descriptor (user_information_descriptor): V value
user information descriptor.

Returns:
str: string value stored in the Windows Registry V value data.


def get_step():
    return _summary_state.step

Returns the default summary step for the current thread.

Returns:
The step set by `tf.summary.experimental.set_step()` if one has been set,
otherwise None.


def _merge_assets_key_collection(saved_model_proto, path):
    for meta_graph in saved_model_proto.meta_graphs:
        node_asset_map = {}
        if (tf_v1.saved_model.constants.ASSETS_KEY in meta_graph.collection_def):
            assets_any_proto = meta_graph.collection_def[tf_v1.saved_model.constants.ASSETS_KEY].any_list.value
            for asset_any_proto in assets_any_proto:
                asset_proto = meta_graph_pb2.AssetFileDef()
                asset_any_proto.Unpack(asset_proto)
                asset_filename = _get_asset_filename(path, asset_proto.filename)
                node_asset_map[_get_node_name_from_tensor(asset_proto.tensor_info.name)] = asset_filename
            del meta_graph.collection_def[tf_v1.saved_model.constants.ASSETS_KEY]
        for node in meta_graph.graph_def.node:
            asset_filepath = node_asset_map.get(node.name)
            if asset_filepath:
                _check_asset_node_def(node)
                node.attr['value'].tensor.string_val[0] = asset_filepath

Merges the ASSETS_KEY collection into the GraphDefs in saved_model_proto.

Removes the ASSETS_KEY collection from the GraphDefs in the SavedModel and
modifies nodes with the assets filenames to point to the assets in `path`.
After this transformation, the SavedModel GraphDefs can be used without
feeding asset tensors.

Args:
saved_model_proto: SavedModel proto to be modified.
path: path where the SavedModel is being loaded from.


def lxml(self):
    import lxml.etree
    return lxml.etree.fromstring((e_views.XML_HEADER + self.xml()).encode('utf-8'))

render the record into a lxml document.
this is useful for querying data from the record using xpath, etc.

note: lxml must be installed.

Returns:
lxml.etree.ElementTree: the rendered and parsed xml document.

Raises:
ImportError: if lxml is not installed.


def GetConfiguredUsers(self):
    if os.path.exists(self.google_users_file):
        users = open(self.google_users_file).readlines()
    else:
        users = []
    return [user.strip() for user in users]

Retrieve the list of configured Google user accounts.

Returns:
list, the username strings of users congfigured by Google.


def _bind_length_handlers(tids, user_handler, lns):

    for tid in tids:
        for ln in lns:
            type_octet = _gen_type_octet(tid, ln)
            ion_type = _TID_VALUE_TYPE_TABLE[tid]
            if ln == 1 and ion_type is IonType.STRUCT:
                handler = partial(_ordered_struct_start_handler, partial(user_handler, ion_type))
            elif ln < _LENGTH_FIELD_FOLLOWS:

                handler = partial(user_handler, ion_type, ln)
            else:

                handler = partial(_var_uint_field_handler, partial(user_handler, ion_type))
            _HANDLER_DISPATCH_TABLE[type_octet] = handler

Binds a set of handlers with the given factory.

Args:
tids (Sequence[int]): The Type IDs to bind to.
user_handler (Callable): A function that takes as its parameters
:class:`IonType`, ``length``, and the ``ctx`` context
returning a co-routine.
lns (Sequence[int]): The low-nibble lengths to bind to.


def get_self_attention_bias(x):

  x_shape = common_layers.shape_list(x)
  self_attention_bias = common_attention.attention_bias_lower_triangle(
      x_shape[1])
  return self_attention_bias

Creates masked self attention bias.

Args:
x: A tensor of shape [batch, length, depth]

Returns:
self_attention_bias: A tensor of shape [length, length, 1]


def execute_script(self, script, *args):

        args = [arg.base if isinstance(arg, Base) else arg for arg in args]
        self.driver.execute_script(script, *args)

Execute the given script, not returning a result. This is useful for scripts that return
complex objects, such as jQuery statements. ``execute_script`` should be used over
:meth:`evaluate_script` whenever possible.

Args:
script (str): A string of JavaScript to execute.
*args: Variable length argument list to pass to the executed JavaScript string.


def convert_strtime_datetime(dt_str):

    dt, _, us = dt_str.partition(".")
    dt = datetime.datetime.strptime(dt, "%Y-%m-%dT%H:%M:%S")
    us = int(us.rstrip("Z"), 10)
    return dt + datetime.timedelta(microseconds=us)

Converts datetime isoformat string to datetime (dt) object

Args:
:dt_str (str): input string in '2017-12-30T18:48:00.353Z' form
or similar
Returns:
TYPE:  datetime object


def encoding_specs(self, spec):
    return spec._component_specs

Returns a list of `TensorSpec`(s) describing the encoding for `spec`.

See `encode` for a description of the default encoding.  Subclasses may
override this default definition, when necessary.

Args:
spec: The TypeSpec whose encoding should be described.

Returns:
A nest (as defined by `tf.nest) of `tf.TypeSpec`, describing the values
that are returned by `self.encode(spec, ...)`.  All TypeSpecs in this
nest must be batchable.


def to(self, new_unit):

        return FloatWithUnit(
            self * self.unit.get_conversion_factor(new_unit),
            unit_type=self._unit_type,
            unit=new_unit)

Conversion to a new_unit. Right now, only supports 1 to 1 mapping of
units of each type.

Args:
new_unit: New unit type.

Returns:
A FloatWithUnit object in the new units.

Example usage:
>>> e = Energy(1.1, "eV")
>>> e = Energy(1.1, "Ha")
>>> e.to("eV")
29.932522246 eV


def info(self, code, message, compressed=False):
    return ''.join([x for x in self.info_gen(code, message, compressed)])

The complete content of an info response.

This should only used for commands that return small or known amounts of
data.

Returns:
A the complete content of a textual response.


def ProcessConfigOverrides(filename):

  abs_filename = os.path.abspath(filename)
  cfg_filters = []
  keep_looking = True
  while keep_looking:
    abs_path, base_name = os.path.split(abs_filename)
    if not base_name:
      break

    cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
    abs_filename = abs_path
    if not os.path.isfile(cfg_file):
      continue

    try:
      with open(cfg_file) as file_handle:
        for line in file_handle:
          line, _, _ = line.partition('
          if not line.strip():
            continue

          name, _, val = line.partition('=')
          name = name.strip()
          val = val.strip()
          if name == 'set noparent':
            keep_looking = False
          elif name == 'filter':
            cfg_filters.append(val)
          elif name == 'exclude_files':

            if base_name:
              pattern = re.compile(val)
              if pattern.match(base_name):
                sys.stderr.write('Ignoring "%s": file excluded by "%s". '
                                 'File path component "%s" matches '
                                 'pattern "%s"\n' %
                                 (filename, cfg_file, base_name, val))
                return False
          elif name == 'linelength':
            global _line_length
            try:
                _line_length = int(val)
            except ValueError:
                sys.stderr.write('Line length must be numeric.')
          else:
            sys.stderr.write(
                'Invalid configuration option (%s) in file %s\n' %
                (name, cfg_file))

    except IOError:
      sys.stderr.write(
          "Skipping config file '%s': Can't open for reading\n" % cfg_file)
      keep_looking = False

  for filter in reversed(cfg_filters):
     _AddFilters(filter)

  return True

Loads the configuration files and processes the config overrides.

Args:
filename: The name of the file being processed by the linter.

Returns:
False if the current |filename| should not be processed further.


def list_jobs(config, *, status=JobStatus.Active, filter_by_type=None, filter_by_worker=None):
    celery_app = create_app(config)
    if (filter_by_worker is not None):
        inspect = celery_app.control.inspect(destination=(filter_by_worker if isinstance(filter_by_worker, list) else [filter_by_worker]))
    else:
        inspect = celery_app.control.inspect()
    if (status == JobStatus.Active):
        job_map = inspect.active()
    elif (status == JobStatus.Registered):
        job_map = inspect.registered()
    elif (status == JobStatus.Reserved):
        job_map = inspect.reserved()
    elif (status == JobStatus.Scheduled):
        job_map = inspect.scheduled()
    else:
        job_map = None
    if (job_map is None):
        return []
    result = []
    for (worker_name, jobs) in job_map.items():
        for job in jobs:
            try:
                job_stats = JobStats.from_celery(worker_name, job, celery_app)
                if ((filter_by_type is None) or (job_stats.type == filter_by_type)):
                    result.append(job_stats)
            except JobStatInvalid:
                pass
    return result

Return a list of Celery jobs.

Args:
config (Config): Reference to the configuration object from which the
settings are retrieved.
status (JobStatus): The status of the jobs that should be returned.
filter_by_type (list): Restrict the returned jobs to the types in this list.
filter_by_worker (list): Only return jobs that were registered, reserved or are
running on the workers given in this list of worker names. Using
this option will increase the performance.

Returns:
list: A list of JobStats.


def minimum(self, vars_list: List[str]) -> 'TensorFluent':
    return self._aggregation_op(tf.reduce_min, self, vars_list)

Returns the TensorFluent for the minimum aggregation function.

Args:
vars_list: The list of variables to be aggregated over.

Returns:
A TensorFluent wrapping the minimum aggregation function.


def relabel_variables(self, mapping, inplace=True):
    if (not inplace):
        return self.copy().relabel_variables(mapping, inplace=True)
    try:
        old_labels = set(mapping)
        new_labels = set(mapping.values())
    except TypeError:
        raise ValueError('mapping targets must be hashable objects')
    variables = self.variables
    for v in new_labels:
        if ((v in variables) and (v not in old_labels)):
            raise ValueError('A variable cannot be relabeled "{}" without also relabeling the existing variable of the same name'.format(v))
    shared = (old_labels & new_labels)
    if shared:
        (old_to_intermediate, intermediate_to_new) = resolve_label_conflict(mapping, old_labels, new_labels)
        self.relabel_variables(old_to_intermediate, inplace=True)
        self.relabel_variables(intermediate_to_new, inplace=True)
        return self
    for (oldterm, bias) in list(self.items()):
        newterm = frozenset((mapping.get(v, v) for v in oldterm))
        if (newterm != oldterm):
            self[newterm] = bias
            del self[oldterm]
    return self

Relabel variables of a binary polynomial as specified by mapping.

Args:
mapping (dict):
Dict mapping current variable labels to new ones. If an
incomplete mapping is provided, unmapped variables retain their
current labels.

inplace (bool, optional, default=True):
If True, the binary polynomial is updated in-place; otherwise, a
new binary polynomial is returned.

Returns:
:class:`.BinaryPolynomial`: A binary polynomial with the variables
relabeled. If `inplace` is set to True, returns itself.


async def _verify_examples(self, client: GRPCClient, examples: List[Example], origin: Origin):
    count_of_verified = 0
    verify_status_failed = False
    default_examples = []
    for example in examples:
        if example.tag.default_example:
            default_examples.append(example)
        if example.status not in Config.ERROR_STATUSES:
            count_of_verified += 1
            continue
        if example.status == STATUS_VALIDATION_ERROR:
            logging.error('Example: %s has validation error', example.filepath)
        elif example.status == STATUS_PREPARATION_ERROR:
            logging.error('Example: %s has preparation error', example.filepath)
        elif example.status == STATUS_ERROR:
            logging.error('Example: %s has error during setup run builder', example.filepath)
        elif example.status == STATUS_RUN_TIMEOUT:
            logging.error('Example: %s failed because of timeout', example.filepath)
        elif example.status == STATUS_COMPILE_ERROR:
            err = await client.get_compile_output(example.pipeline_id)
            logging.error('Example: %s has compilation error: %s', example.filepath, err)
        elif example.status == STATUS_RUN_ERROR:
            err = await client.get_run_error(example.pipeline_id)
            logging.error('Example: %s has execution error: %s', example.filepath, err)
        verify_status_failed = True
    logging.info('Number of verified Playground examples: %s / %s', count_of_verified, len(examples))
    logging.info('Number of Playground examples with some error: %s / %s', len(examples) - count_of_verified, len(examples))
    if origin == Origin.PG_EXAMPLES:
        if len(default_examples) == 0:
            logging.error('Default example not found')
            raise VerifyException('CI step failed due to finding an incorrect number of default examples. Default example not found')
        if len(default_examples) > 1:
            logging.error('Many default examples found')
            logging.error('Examples where the default_example field is true:')
            for example in default_examples:
                logging.error(example.filepath)
            raise VerifyException('CI step failed due to finding an incorrect number of default examples. Many default examples found')
    if verify_status_failed:
        raise VerifyException('CI step failed due to errors in the examples')

Verify statuses of beam examples and the number of found default examples.

Check example.status for each examples. If the status of the example is:
- STATUS_VALIDATION_ERROR/STATUS_PREPARATION_ERROR
/STATUS_ERROR/STATUS_RUN_TIMEOUT: log error
- STATUS_COMPILE_ERROR: get logs using GetCompileOutput request and
log them with error.
- STATUS_RUN_ERROR: get logs using GetRunError request and
log them with error.

Args:
examples: beam examples that should be verified


def assert_no_current_path(self, path, **kwargs):
    query = CurrentPathQuery(path, **kwargs)

    @self.document.synchronize
    def assert_no_current_path():
        if query.resolves_for(self):
            raise ExpectationNotMet(query.negative_failure_message)
    assert_no_current_path()
    return True

Asserts that the page doesn't have the given path.

Args:
path (str | RegexObject): The string or regex that the current "path" should match.
**kwargs: Arbitrary keyword arguments for :class:`CurrentPathQuery`.

Returns:
True

Raises:
ExpectationNotMet: If the assertion hasn't succeeded during the wait time.


def attach(self, engine, metric_names=None, output_transform=None, event_name=Events.ITERATION_COMPLETED, closing_event_name=Events.EPOCH_COMPLETED):
    desc = self.tqdm_kwargs.get('desc', 'Epoch')
    if (not ((event_name in Events) and (closing_event_name in Events))):
        raise ValueError('Logging and closing events should be only ignite.engine.Events')
    if (not self._compare_lt(event_name, closing_event_name)):
        raise ValueError('Logging event {} should be called before closing event {}'.format(event_name, closing_event_name))
    log_handler = _OutputHandler(desc, metric_names, output_transform, event_name=event_name, closing_event_name=closing_event_name)
    super(ProgressBar, self).attach(engine, log_handler, event_name)
    engine.add_event_handler(closing_event_name, self._close)

Attaches the progress bar to an engine object.

Args:
engine (Engine): engine object.
metric_names (list, optional): list of the metrics names to log as the bar progresses
output_transform (callable, optional): a function to select what you want to print from the engine's
output. This function may return either a dictionary with entries in the format of ``{name: value}``,
or a single scalar, which will be displayed with the default name `output`.
event_name: event's name on which the progress bar advances. Valid events are from
:class:`~ignite.engine.Events`.
closing_event_name: event's name on which the progress bar is closed. Valid events are from
:class:`~ignite.engine.Events`.


def add_package(self, pkg, action_type="Install"):

        if isinstance(pkg, Package):
            if action_type not in ("Install", "Cache", "Install Cached"):
                raise ValueError
            package = self.add_object_to_path(
                pkg, "package_configuration/packages")

            action = package.find("action")
            if not action:
                action = ElementTree.SubElement(package, "action")
            action.text = action_type
        else:
            raise ValueError("Please pass a Package object to parameter: "
                             "pkg.")

Add a Package object to the policy with action=install.

Args:
pkg: A Package object to add.
action_type (str, optional): One of "Install", "Cache", or
"Install Cached".  Defaults to "Install".


def produce_csv_output(filehandle: TextIO,
                       fields: Sequence[str],
                       values: Iterable[str]) -> None:

    output_csv(filehandle, fields)
    for row in values:
        output_csv(filehandle, row)

Produce CSV output, without using ``csv.writer``, so the log can be used
for lots of things.

- ... eh? What was I talking about?
- POOR; DEPRECATED.

Args:
filehandle: file to write to
fields: field names
values: values


def default_onnx_opset(self) -> int:
    return DEFAULT_ONNX_OPSET

Which onnx opset to use when exporting the model

Returns:
Integer ONNX Opset version


def create_with_secret(self, name, secret, encryption):

        try:
            encryption = encryption or DEFAULT_ENCRYPTION
            enc = ENCRYPTION_MAP[encryption]
        except KeyError:
            raise TypeError('encryption must be one of "cleartext", "md5"'
                            ' or "sha512"')

        cmd = 'username %s secret %s %s' % (name, enc, secret)
        return self.configure(cmd)

Creates a new user on the local node

Args:
name (str): The name of the user to craete

secret (str): The secret (password) to assign to this user

encryption (str): Specifies how the secret is encoded.  Valid
values are "cleartext", "md5", "sha512".  The default is
"cleartext"

Returns:
True if the operation was successful otherwise False


def clone(self, spec=None, **overrides):

        settings = dict(self.get_param_values(), **overrides)

        if spec is None:
            spec = (self.name, overrides.get('label', self.label))
        if 'label' in overrides and isinstance(spec, basestring) :
            spec = (spec, overrides['label'])
        elif 'label' in overrides and isinstance(spec, tuple) :
            if overrides['label'] != spec[1]:
                self.param.warning(
                    'Using label as supplied by keyword ({!r}), ignoring '
                    'tuple value {!r}'.format(overrides['label'], spec[1]))
            spec = (spec[0],  overrides['label'])
        return self.__class__(spec, **{k:v for k,v in settings.items()
                                       if k not in ['name', 'label']})

Clones the Dimension with new parameters

Derive a new Dimension that inherits existing parameters
except for the supplied, explicit overrides

Args:
spec (tuple, optional): Dimension tuple specification
**overrides: Dimension parameter overrides

Returns:
Cloned Dimension object


def _is_propertyable(names, attrs, annotations, attr):
    return ((attr in annotations) and (not attr.startswith('_')) and (not attr.isupper()) and ('__{}'.format(attr) not in names) and (not isinstance(getattr(attrs, attr, None), types.MethodType)))

Determine if an attribute can be replaced with a property.

Args:
names: The complete list of all attribute names for the class.
attrs: The attribute dict returned by __prepare__.
annotations: A mapping of all defined annotations for the class.
attr: The attribute to test.

Returns:
True if the attribute can be replaced with a property; else False.


def _in_multi_worker_mode(self):
    strategy = self._distribution_strategy
    if not strategy and distribute_lib.has_strategy():
        strategy = distribute_lib.get_strategy()
    return strategy and strategy.extended._in_multi_worker_mode()

Method to infer if this `Model` is working in multi-worker settings.

Multi-worker training refers to the setup where the training is
distributed across multiple workers, as opposed to the case where
only a local process performs the training. This function is
used to infer for example whether or not a distribute coordinator
should be run, and thus TensorFlow servers should be started for
communication with other servers in the cluster, or whether or not
saving/restoring checkpoints is relevant for preemption fault tolerance.

Experimental. Signature and implementation are subject to change.

Returns:
Whether this model indicates it's working in multi-worker settings.


def check_the_end_flag(self, state_arr):

        if self.__check_goal_flag(state_arr) is True or self.__check_crash_flag(state_arr):
            return True
        else:
            return False

Check the end flag.

If this return value is `True`, the learning is end.

As a rule, the learning can not be stopped.
This method should be overrided for concreate usecases.

Args:
state_arr:    `np.ndarray` of state in `self.t`.

Returns:
bool


def add(self, resource, provider_uri_or_id, timeout=-1):

        uri = self._provider_client.build_uri(provider_uri_or_id) + "/device-managers"
        return self._client.create(resource=resource, uri=uri, timeout=timeout)

Adds a Device Manager under the specified provider.

Args:
resource (dict): Object to add.
provider_uri_or_id: ID or URI of provider.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView, just stop waiting for its completion.

Returns:
dict: Added SAN Manager.


def AddPerformanceOptions(self, argument_group):

    argument_group.add_argument(
        '--buffer_size', '--buffer-size', '--bs', dest='buffer_size',
        action='store', default=0, help=(
            'The buffer size for the output (defaults to 196MiB).'))

    argument_group.add_argument(
        '--queue_size', '--queue-size', dest='queue_size', action='store',
        default=0, help=(
            'The maximum number of queued items per worker '
            '(defaults to {0:d})').format(self._DEFAULT_QUEUE_SIZE))

Adds the performance options to the argument group.

Args:
argument_group (argparse._ArgumentGroup): argparse argument group.


def set_status(self, status: Status, increment_try_count: bool=True,
                   filename: str=None):

        url = self.url_record.url
        assert not self._try_count_incremented, (url, status)

        if increment_try_count:
            self._try_count_incremented = True

        _logger.debug(__('Marking URL {0} status {1}.', url, status))

        url_result = URLResult()
        url_result.filename = filename

        self.app_session.factory['URLTable'].check_in(
            url,
            status,
            increment_try_count=increment_try_count,
            url_result=url_result,
        )

        self._processed = True

Mark the item with the given status.

Args:
status: a value from :class:`Status`.
increment_try_count: if True, increment the ``try_count``
value


def html_for_cgi_argument(argument, form):

    value = form[argument].value if argument in form else None
    return KEY_VALUE_TEMPLATE.format(argument, value)

Returns an HTML snippet for a CGI argument.

Args:
argument: A string representing an CGI argument name in a form.
form: A CGI FieldStorage object.

Returns:
String HTML representing the CGI value and variable.


def get(self, params=None):

        return self._call('get', url=self.endpoint, params=params)

Send a POST request and return the JSON decoded result.

Args:
params (dict, optional): Mapping of parameters to send in request.

Returns:
mixed: JSON decoded response data.


def from_params(cls, params):

        key_fn = lambda x: id(x[1].owner)
        streams = []
        for _, group in groupby(sorted(params.items(), key=key_fn), key_fn):
            group = list(group)
            inst = [p.owner for _, p in group][0]
            if not isinstance(inst, param.Parameterized):
                continue
            names = [p.name for _, p in group]
            rename = {p.name: n for n, p in group}
            streams.append(cls(inst, names, rename=rename))
        return streams

Returns Params streams given a dictionary of parameters

Args:
params (dict): Dictionary of parameters

Returns:
List of Params streams


def get_tensors(object_):

    if torch.is_tensor(object_):
        return [object_]
    elif isinstance(object_, (str, float, int)):
        return []

    tensors = set()

    if isinstance(object_, collections.abc.Mapping):
        for value in object_.values():
            tensors.update(get_tensors(value))
    elif isinstance(object_, collections.abc.Iterable):
        for value in object_:
            tensors.update(get_tensors(value))
    else:
        members = [
            value for key, value in inspect.getmembers(object_)
            if not isinstance(value, (collections.abc.Callable, type(None)))
        ]
        tensors.update(get_tensors(members))

    return tensors

Get all tensors associated with ``object_``

Args:
object_ (any): Any object to look for tensors.

Returns:
(list of torch.tensor): List of tensors that are associated with ``object_``.