def volatility_surface(self, currency: List[str], asset: List[str]) -> volatility_surface.VolatilitySurface:
    dates = []
    strikes = []
    implied_vols = []
    for cur, s in zip(currency, asset):
        if s not in self.supported_assets(cur):
            raise ValueError(f'No data for asset {s}')
        data_spot = self._market_data_dict['equities'][cur][s]
        if 'volatility_surface' not in data_spot:
            raise ValueError(f"No volatility surface 'volatility_surface' for asset {s}")
        vol_surface = data_spot['volatility_surface']
        vol_dates = dateslib.convert_to_date_tensor(vol_surface['dates'])
        vol_strikes = tf.convert_to_tensor(vol_surface['strikes'], dtype=self._dtype, name='strikes')
        vols = tf.convert_to_tensor(vol_surface['implied_volatilities'], dtype=self._dtype, name='implied_volatilities')
        dates.append(vol_dates)
        strikes.append(vol_strikes)
        implied_vols.append(vols)
    dates = math.pad.pad_date_tensors(dates)
    dates = dateslib.DateTensor.stack(dates, axis=0)
    implied_vols = math.pad.pad_tensors(implied_vols)
    implied_vols = tf.stack(implied_vols, axis=0)
    strikes = math.pad.pad_tensors(strikes)
    strikes = tf.stack(strikes, axis=0)
    vol_surface = volatility_surface.VolatilitySurface(self.date, dates, strikes, implied_vols)
    return vol_surface

The volatility surface object for the lsit of assets.

Args:
currency: A list of strings with currency names.
asset: A list of strings with asset names.

Returns:
An instance of `VolatilitySurface`.


def label(self, input_grid):

        marked = self.find_local_maxima(input_grid)
        marked = np.where(marked >= 0, 1, 0)

        markers = splabel(marked)[0]
        return markers

Labels input grid using enhanced watershed algorithm.

Args:
input_grid (numpy.ndarray): Grid to be labeled.

Returns:
Array of labeled pixels


def to_json(self, indent=4):
    agregate = {'metas': self.metas}
    agregate.update({k: getattr(self, k) for k in self._rule_attrs})
    return json.dumps(agregate, indent=indent)

Serialize metas and reference attributes to a JSON string.

Keyword Arguments:
indent (int): Space indentation, default to ``4``.

Returns:
string: JSON datas.


def register_gate(name, gateclass, allow_overwrite=False):
    if hasattr(Circuit, name):
        if allow_overwrite:
            warnings.warn(f'Circuit has attribute `{name}`.')
        else:
            raise ValueError(f'Circuit has attribute `{name}`.')
    if name.startswith('run_with_'):
        if allow_overwrite:
            warnings.warn(f'Gate name `{name}` may conflict with run of backend.')
        else:
            raise ValueError(f"Gate name `{name}` shall not start with 'run_with_'.")
    if (not allow_overwrite):
        if (name in GATE_SET):
            raise ValueError(f"Gate '{name}' is already exists in gate set.")
        if (name in GLOBAL_MACROS):
            raise ValueError(f"Macro '{name}' is already exists.")
    GATE_SET[name] = gateclass

Register new gate to gate set.

Args:
name (str): The name of gate.
gateclass (type): The type object of gate.
allow_overwrite (bool, optional): If True, allow to overwrite the existing gate.
Otherwise, raise the ValueError.

Raises:
ValueError: The name is duplicated with existing gate.
When `allow_overwrite=True`, this error is not raised.


def add(cls, model, commit=True):

        if not isinstance(model, cls):
            raise ValueError('%s is not of type %s' % (model, cls))
        cls.session.add(model)
        try:
            if commit:
                cls.session.commit()
            return model
        except:
            cls.session.rollback()
            raise

Adds a model instance to session and commits the
transaction.

Args:

model: The instance to add.

Examples:

>>> customer = Customer.new(name="hari", email="hari@gmail.com")

>>> Customer.add(customer)
hari@gmail.com


def create_or_update(cls, video, language_code, metadata, file_data=None):

        try:
            video_transcript = cls.objects.get(video=video, language_code=language_code)
            retrieved = True
        except cls.DoesNotExist:
            video_transcript = cls(video=video, language_code=language_code)
            retrieved = False

        for prop, value in six.iteritems(metadata):
            if prop in ['language_code', 'file_format', 'provider']:
                setattr(video_transcript, prop, value)

        transcript_name = metadata.get('file_name')

        try:
            if transcript_name:
                video_transcript.transcript.name = transcript_name
            elif file_data:
                with closing(file_data) as transcript_file_data:
                    file_name = '{uuid}.{ext}'.format(uuid=uuid4().hex, ext=video_transcript.file_format)
                    video_transcript.transcript.save(file_name, transcript_file_data)

            video_transcript.save()
        except Exception:
            logger.exception(
                '[VAL] Transcript save failed to storage for video_id "%s" language code "%s"',
                video.edx_video_id,
                language_code
            )
            raise

        return video_transcript, not retrieved

Create or update Transcript object.

Arguments:
video (Video): Video for which transcript is going to be saved.
language_code (str): language code for (to be created/updated) transcript
metadata (dict): A dict containing (to be overwritten) properties
file_data (InMemoryUploadedFile): File data to be saved

Returns:
Returns a tuple of (video_transcript, created).


def remove_binding(self, binding):

        query = { "binding_id" : binding.binding_id, "instance_id" : binding.instance.instance_id }

        try:
            result = self.broker.delete_one(query)
        except:
            raise ErrStorageMongoConnection("Remove Binding")

        if result is not None and result.deleted_count == 1:
            binding.provisioned = False
        else:
            raise ErrStorageRemoveBinding(binding.binding_id)

Remove a binding

Remove an object from the MongoDB storage for caching

Args:
binding (AtlasServiceBinding.Binding): binding

Raises:
ErrStorageMongoConnection: Error during MongoDB communication.
ErrStorageRemoveBinding: Failed to remove the binding


def confirmdir(self, target_directory):
    try:
        directory = self.resolve(target_directory)
    except IOError as exc:
        self.raise_os_error(exc.errno, target_directory)
    if (not (directory.st_mode & S_IFDIR)):
        if (self.is_windows_fs and IS_PY2):
            error_nr = errno.EINVAL
        else:
            error_nr = errno.ENOTDIR
        self.raise_os_error(error_nr, target_directory, 267)
    return directory

Test that the target is actually a directory, raising OSError
if not.

Args:
target_directory: Path to the target directory within the fake
filesystem.

Returns:
The FakeDirectory object corresponding to target_directory.

Raises:
OSError: if the target is not a directory.


def _group_sentences(total_nb_sentences, group_length):
    sentences_groups = []
    current_sentence_group = []
    for i in range(0, total_nb_sentences):
        if ((i % group_length) == 0):
            if (len(current_sentence_group) > 0):
                sentences_groups.append(current_sentence_group)
            current_sentence_group = [i]
        else:
            current_sentence_group.append(i)
    if (len(current_sentence_group) > 0):
        sentences_groups.append(current_sentence_group)
    return sentences_groups

Split sentences in groups, given a specific group length.

Args:
total_nb_sentences (int): Total available sentences.
group_length (int): Limit of length for each group.

Returns:
list: Contains groups (lists) of sentences.


def parse(self, requires_cfg=True):

        self._parse_default()
        self._parse_config(requires_cfg)
        self._parse_env()

Parse the configuration sources into `Bison`.

Args:
requires_cfg (bool): Specify whether or not parsing should fail
if a config file is not found. (default: True)


def latitude(self, value=0.0):
    if (value is not None):
        try:
            value = float(value)
        except ValueError:
            raise ValueError('value {} need to be of type float for field `latitude`'.format(value))
        if (value < (- 90.0)):
            raise ValueError('value need to be greater or equal -90.0 for field `latitude`')
        if (value > 90.0):
            raise ValueError('value need to be smaller 90.0 for field `latitude`')
    self._latitude = value

Corresponds to IDD Field `latitude`

+ is North, - is South, degree minutes represented in decimal (i.e. 30 minutes is .5)

Args:
value (float): value for IDD Field `latitude`
Unit: deg
Default value: 0.0
value >= -90.0
value <= 90.0
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

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


def p44(msg):

    d = hex2bin(data(msg))

    if d[34] == '0':
        return None

    p = bin2int(d[35:46])

    return p

Static pressure.

Args:
msg (String): 28 bytes hexadecimal message string

Returns:
int: static pressure in hPa


def is_file_opened(self, filename=None):

        if filename is None:

            return len(self.data) > 0
        else:
            return self.has_filename(filename)

Return if filename is in the editor stack.

Args:
filename: Name of the file to search for.  If filename is None,
then checks if any file is open.

Returns:
True: If filename is None and a file is open.
False: If filename is None and no files are open.
None: If filename is not None and the file isn't found.
integer: Index of file name in editor stack.


def add_to_writer(self,
                      writer: PdfFileWriter,
                      start_recto: bool = True) -> None:

        if self.is_html:
            pdf = get_pdf_from_html(
                html=self.html,
                header_html=self.header_html,
                footer_html=self.footer_html,
                wkhtmltopdf_filename=self.wkhtmltopdf_filename,
                wkhtmltopdf_options=self.wkhtmltopdf_options)
            append_memory_pdf_to_writer(pdf, writer, start_recto=start_recto)
        elif self.is_filename:
            if start_recto and writer.getNumPages() % 2 != 0:
                writer.addBlankPage()
            writer.appendPagesFromReader(PdfFileReader(
                open(self.filename, 'rb')))
        else:
            raise AssertionError("PdfPlan: shouldn't get here!")

Add the PDF described by this class to a PDF writer.

Args:
writer: a :class:`PyPDF2.PdfFileWriter`
start_recto: start a new right-hand page?


def prepare_run_debug_urls(self, fetches, feed_dict):
    return self._grpc_debug_server_urls

Implementation of abstract method in superclass.

See doc of `NonInteractiveDebugWrapperSession.prepare_run_debug_urls()`
for details.

Args:
fetches: Same as the `fetches` argument to `Session.run()`
feed_dict: Same as the `feed_dict` argument to `Session.run()`

Returns:
debug_urls: (`str` or `list` of `str`) file:// debug URLs to be used in
this `Session.run()` call.


def path_size(p: tcod.path.AStar) -> int:

    return int(lib.TCOD_path_size(p._path_c))

Return the current length of the computed path.

Args:
p (AStar): An AStar instance.
Returns:
int: Length of the path.


def with_device(self, new_device: devices.Device, qubit_mapping: Callable[([ops.Qid], ops.Qid)]=(lambda e: e)) -> 'Circuit':
    return Circuit(moments=[ops.Moment((operation.transform_qubits(qubit_mapping) for operation in moment.operations)) for moment in self._moments], device=new_device)

Maps the current circuit onto a new device, and validates.

Args:
new_device: The new device that the circuit should be on.
qubit_mapping: How to translate qubits from the old device into
qubits on the new device.

Returns:
The translated circuit.


def data_file(file_fmt, info=None, **kwargs):

    if isinstance(info, dict):
        kwargs['hash_key'] = hashlib.sha256(json.dumps(info).encode('utf-8')).hexdigest()
        kwargs.update(info)

    return utils.fstr(fmt=file_fmt, **kwargs)

Data file name for given infomation

Args:
file_fmt: file format in terms of f-strings
info: dict, to be hashed and then pass to f-string using 'hash_key'
these info will also be passed to f-strings
**kwargs: arguments for f-strings

Returns:
str: data file name


def output_classes(self):
    return nest.map_structure(lambda component_spec: component_spec._to_legacy_output_classes(), self.element_spec)

Returns the class of each component of an element of this dataset.

Returns:
A (nested) structure of Python `type` objects corresponding to each
component of an element of this dataset.


def structured_input_signature(self):
    return self._func_graph.structured_input_signature

Returns structured signature for this concrete function.

Returns:
A tuple `(args, kwargs)`, where:

* `args` is a tuple that specifies the expected type or value each for
positional argument.
* `kwargs` is a dictionary that specifies the expected type or value
for each keyword-only argument.

The type or value for each argument is specified using one of the
following:

* A `tf.TypeSpec`, indicating that a Tensor or other TensorFlow-native
value is expected.
* A Python value, such as an integer, indicating that an equal value
is expected.
* A nested structure of `tf.TypeSpec`s and Python values, indicating
that a corresponding nested structure is expected.


def _parse(self, stream):
    builddata = json.load(stream)
    log.debug('This is a JSON build file.')
    if ('targets' not in builddata):
        log.warn('Warning: No targets defined here.')
        return
    for tdata in builddata['targets']:
        target = address.new(target=tdata.pop('name'), repo=self.target.repo, path=self.target.path)
        if ((target in self.node) and ('target_obj' in self.node[target])):
            raise error.ButcherError('Target is defined more than once: %s', target)
        rule_obj = targets.new(name=target, ruletype=tdata.pop('type'), **tdata)
        log.debug('New target: %s', target)
        self.add_node(target, {'target_obj': rule_obj})
        for dep in (rule_obj.composed_deps() or []):
            d_target = address.new(dep)
            if (not d_target.repo):
                d_target.repo = self.target.repo
            if ((d_target.repo == self.target.repo) and (not d_target.path)):
                d_target.path = self.target.path
            if (d_target not in self.nodes()):
                self.add_node(d_target)
            log.debug('New dep: %s -> %s', target, d_target)
            self.add_edge(target, d_target)

Parse a JSON BUILD file.

Args:
builddata: dictionary of buildfile data
reponame: name of the repo that it came from
path: directory path within the repo


def Categories(unicode_dir=_UNICODE_DIR):
    categories = {}

    def DoLine(codes, fields):
        'Process single UnicodeData.txt line, updating categories.'
        category = fields[2]
        categories.setdefault(category, []).extend(codes)
        if (len(category) > 1):
            short = category[0]
            categories.setdefault(short, []).extend(codes)
    ReadUnicodeTable((unicode_dir + '/UnicodeData.txt'), 15, DoLine)
    return categories

Returns dict mapping category names to code lists.

Args:
unicode_dir: Unicode data directory

Returns:
dict mapping category names to code lists


def __method_descriptor(self, service, method_info,
                          rosy_method, protorpc_method_info):

    descriptor = {}

    request_message_type = (resource_container.ResourceContainer.
                            get_request_message(protorpc_method_info.remote))
    request_kind = self.__get_request_kind(method_info)
    remote_method = protorpc_method_info.remote

    descriptor['path'] = method_info.get_path(service.api_info)
    descriptor['httpMethod'] = method_info.http_method
    descriptor['rosyMethod'] = rosy_method
    descriptor['request'] = self.__request_message_descriptor(
        request_kind, request_message_type,
        method_info.method_id(service.api_info),
        descriptor['path'])
    descriptor['response'] = self.__response_message_descriptor(
        remote_method.response_type(), method_info.method_id(service.api_info))

    scopes = (method_info.scopes
              if method_info.scopes is not None
              else service.api_info.scopes)
    if scopes:
      descriptor['scopes'] = scopes
    audiences = (method_info.audiences
                 if method_info.audiences is not None
                 else service.api_info.audiences)
    if audiences:
      descriptor['audiences'] = audiences
    allowed_client_ids = (method_info.allowed_client_ids
                          if method_info.allowed_client_ids is not None
                          else service.api_info.allowed_client_ids)
    if allowed_client_ids:
      descriptor['clientIds'] = allowed_client_ids

    if remote_method.method.__doc__:
      descriptor['description'] = remote_method.method.__doc__

    auth_level = (method_info.auth_level
                  if method_info.auth_level is not None
                  else service.api_info.auth_level)
    if auth_level is not None:
      descriptor['authLevel'] = AUTH_LEVEL.reverse_mapping[auth_level]

    descriptor['useRequestUri'] = method_info.use_request_uri(service.api_info)

    return descriptor

Describes a method.

Args:
service: endpoints.Service, Implementation of the API as a service.
method_info: _MethodInfo, Configuration for the method.
rosy_method: string, ProtoRPC method name prefixed with the
name of the service.
protorpc_method_info: protorpc.remote._RemoteMethodInfo, ProtoRPC
description of the method.

Returns:
Dictionary describing the method.


def diff_cleanupEfficiency(self, diffs):

    changes = False
    equalities = []
    lastEquality = None
    pointer = 0
    pre_ins = False
    pre_del = False
    post_ins = False
    post_del = False
    while pointer < len(diffs):
      if diffs[pointer][0] == self.DIFF_EQUAL:
        if (len(diffs[pointer][1]) < self.Diff_EditCost and
            (post_ins or post_del)):

          equalities.append(pointer)
          pre_ins = post_ins
          pre_del = post_del
          lastEquality = diffs[pointer][1]
        else:

          equalities = []
          lastEquality = None

        post_ins = post_del = False
      else:
        if diffs[pointer][0] == self.DIFF_DELETE:
          post_del = True
        else:
          post_ins = True

        if lastEquality and ((pre_ins and pre_del and post_ins and post_del) or
                             ((len(lastEquality) < self.Diff_EditCost / 2) and
                              (pre_ins + pre_del + post_ins + post_del) == 3)):

          diffs.insert(equalities[-1], (self.DIFF_DELETE, lastEquality))

          diffs[equalities[-1] + 1] = (self.DIFF_INSERT,
              diffs[equalities[-1] + 1][1])
          equalities.pop()
          lastEquality = None
          if pre_ins and pre_del:

            post_ins = post_del = True
            equalities = []
          else:
            if len(equalities):
              equalities.pop()
            if len(equalities):
              pointer = equalities[-1]
            else:
              pointer = -1
            post_ins = post_del = False
          changes = True
      pointer += 1

    if changes:
      self.diff_cleanupMerge(diffs)

Reduce the number of edits by eliminating operationally trivial
equalities.

Args:
diffs: Array of diff tuples.


def get_well(self, uwi):
    if (uwi is None):
        raise ValueError('a UWI must be provided')
    matching_wells = [w for w in self if (w.uwi == uwi)]
    return (matching_wells[0] if (len(matching_wells) >= 1) else None)

Returns a Well object identified by UWI

Args:
uwi (string): the UWI string for the well.

Returns:
well


def _date_to_datetime(value):

  if not isinstance(value, datetime.date):
    raise TypeError('Cannot convert to datetime expected date value; '
                    'received %s' % value)
  return datetime.datetime(value.year, value.month, value.day)

Convert a date to a datetime for Cloud Datastore storage.

Args:
value: A datetime.date object.

Returns:
A datetime object with time set to 0:00.


def add_patch(ax, color, pts_per_edge, *edges):

    from matplotlib import patches
    from matplotlib import path as _path_mod

    s_vals = np.linspace(0.0, 1.0, pts_per_edge)

    all_points = []
    for edge in edges:
        points = edge.evaluate_multi(s_vals)

        all_points.append(points[:, 1:])

    first_edge = all_points[0]
    all_points.append(first_edge[:, [0]])

    polygon = np.asfortranarray(np.hstack(all_points))
    line, = ax.plot(polygon[0, :], polygon[1, :], color=color)

    color = line.get_color()

    path = _path_mod.Path(polygon.T)
    patch = patches.PathPatch(path, facecolor=color, alpha=0.625)
    ax.add_patch(patch)

Add a polygonal surface patch to a plot.

Args:
ax (matplotlib.artist.Artist): A matplotlib axis.
color (Tuple[float, float, float]): Color as RGB profile.
pts_per_edge (int): Number of points to use in polygonal
approximation of edge.
edges (Tuple[~bezier.curve.Curve, ...]): Curved edges defining
a boundary.


def xray_driver_removed_handler(self, unused_channel, data):
    gcs_entries = ray.gcs_utils.GcsTableEntry.GetRootAsGcsTableEntry(data, 0)
    driver_data = gcs_entries.Entries(0)
    message = ray.gcs_utils.DriverTableData.GetRootAsDriverTableData(driver_data, 0)
    driver_id = message.DriverId()
    logger.info('Monitor: XRay Driver {} has been removed.'.format(binary_to_hex(driver_id)))
    self._xray_clean_up_entries_for_driver(driver_id)

Handle a notification that a driver has been removed.

Args:
unused_channel: The message channel.
data: The message data.


def subtract_afromb(*inputs, **kwargs):
    try:
        value_a = inputs[0].pop()
        value_b = inputs[1].pop()
        return [IOTileReading(0, 0, (value_b.value - value_a.value))]
    except StreamEmptyError:
        return []

Subtract stream a from stream b.

Returns:
list(IOTileReading)


def __init__(self, metadata_list, registry=None):

    self._metrics = {}

    if registry is None:
      self._registry = prometheus_client.CollectorRegistry(auto_describe=True)
    else:
      self._registry = registry

    self.lock = threading.RLock()

    super(PrometheusStatsCollector, self).__init__(metadata_list)

Instantiates a new PrometheusStatsCollector.

Args:
metadata_list: A list of MetricMetadata objects describing the metrics
that the StatsCollector will track.
registry: An instance of prometheus_client.CollectorRegistry. If None, a
new CollectorRegistry is instantiated. Use prometheus_client.REGISTRY
for the global default registry.


def load(filenames, prepare_data_iterator=True, batch_size=None, exclude_parameter=False, parameter_only=False):

    class Info:
        pass
    info = Info()

    proto = nnabla_pb2.NNablaProtoBuf()
    for filename in filenames:
        _, ext = os.path.splitext(filename)

        if ext in ['.nntxt', '.prototxt']:
            if not parameter_only:
                with open(filename, 'rt') as f:
                    try:
                        text_format.Merge(f.read(), proto)
                    except:
                        logger.critical('Failed to read {}.'.format(filename))
                        logger.critical(
                            '2 byte characters may be used for file name or folder name.')
                        raise
            if len(proto.parameter) > 0:
                if not exclude_parameter:
                    nn.load_parameters(filename)
        elif ext in ['.protobuf', '.h5']:
            if not exclude_parameter:
                nn.load_parameters(filename)
            else:
                logger.info('Skip loading parameter.')

        elif ext == '.nnp':
            try:
                tmpdir = tempfile.mkdtemp()
                with zipfile.ZipFile(filename, 'r') as nnp:
                    for name in nnp.namelist():
                        _, ext = os.path.splitext(name)
                        if name == 'nnp_version.txt':
                            nnp.extract(name, tmpdir)
                            with open(os.path.join(tmpdir, name), 'rt') as f:
                                pass
                        elif ext in ['.nntxt', '.prototxt']:
                            nnp.extract(name, tmpdir)
                            if not parameter_only:
                                with open(os.path.join(tmpdir, name), 'rt') as f:
                                    text_format.Merge(f.read(), proto)
                            if len(proto.parameter) > 0:
                                if not exclude_parameter:
                                    nn.load_parameters(
                                        os.path.join(tmpdir, name))
                        elif ext in ['.protobuf', '.h5']:
                            nnp.extract(name, tmpdir)
                            if not exclude_parameter:
                                nn.load_parameters(os.path.join(tmpdir, name))
                            else:
                                logger.info('Skip loading parameter.')
            finally:
                shutil.rmtree(tmpdir)

    default_context = None
    if proto.HasField('global_config'):
        info.global_config = _global_config(proto)
        default_context = info.global_config.default_context
        if 'cuda' in default_context.backend:
            import nnabla_ext.cudnn
        elif 'cuda:float' in default_context.backend:
            try:
                import nnabla_ext.cudnn
            except:
                pass
    else:
        import nnabla_ext.cpu
        default_context = nnabla_ext.cpu.context()

    comm = current_communicator()
    if comm:
        default_context.device_id = str(comm.rank)
    if proto.HasField('training_config'):
        info.training_config = _training_config(proto)

    info.datasets = _datasets(
        proto, prepare_data_iterator if prepare_data_iterator is not None else info.training_config.max_epoch > 0)

    info.networks = _networks(proto, default_context, batch_size)

    info.optimizers = _optimizers(
        proto, default_context, info.networks, info.datasets)

    info.monitors = _monitors(
        proto, default_context, info.networks, info.datasets)

    info.executors = _executors(proto, info.networks)

    return info

load
Load network information from files.

Args:
filenames (list): List of filenames.
Returns:
dict: Network information.


def metadata(self):
    if (self._info is None):
        try:
            self._info = self._api.objects_get(self._bucket, self._key)
        except Exception as e:
            raise e
    return (ObjectMetadata(self._info) if self._info else None)

Retrieves metadata about the object.

Returns:
An ObjectMetadata instance with information about this object.
Raises:
Exception if there was an error requesting the object's metadata.


def singularize(plural):

    if plural in UNCOUNTABLES:
        return plural
    for i in IRREGULAR:
        if i[1] == plural:
            return i[0]
    for i in SINGULARIZE_PATTERNS:
        if re.search(i[0], plural):
            return re.sub(i[0], i[1], plural)
    return plural

Convert plural word to its singular form.

Args:
plural: A word in its plural form.
Returns:
The word in its singular form.


def persist_config(run, session, cfg):

    from benchbuild.utils import schema as s

    for cfg_elem in cfg:
        session.add(
            s.Config(name=cfg_elem, value=cfg[cfg_elem], run_id=run.id))

Persist the configuration in as key-value pairs.

Args:
run: The run we attach the config to.
session: The db transaction we belong to.
cfg: The configuration we want to persist.


def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):

        tstream = BytearrayStream()

        self.certificate_type.write(tstream, kmip_version=kmip_version)
        self.certificate_value.write(tstream, kmip_version=kmip_version)

        self.length = tstream.length()
        super(Certificate, self).write(ostream, kmip_version=kmip_version)
        ostream.write(tstream.buffer)

Write the data encoding the Certificate object to a stream.

Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.


def chempot_plot_addons(self, plt, xrange, ref_el, axes, pad=2.4, rect=[(- 0.047), 0, 0.84, 1], ylim=[]):
    plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.0)
    axes.set_xlabel(('Chemical potential $\\Delta\\mu_{%s}$ (eV)' % ref_el))
    ylim = (ylim if ylim else axes.get_ylim())
    plt.xticks(rotation=60)
    plt.ylim(ylim)
    xlim = axes.get_xlim()
    plt.xlim(xlim)
    plt.tight_layout(pad=pad, rect=rect)
    plt.plot([xrange[0], xrange[0]], ylim, '--k')
    plt.plot([xrange[1], xrange[1]], ylim, '--k')
    xy = [np.mean([xrange[1]]), np.mean(ylim)]
    plt.annotate(('%s-rich' % ref_el), xy=xy, xytext=xy, rotation=90, fontsize=17)
    xy = [np.mean([xlim[0]]), np.mean(ylim)]
    plt.annotate(('%s-poor' % ref_el), xy=xy, xytext=xy, rotation=90, fontsize=17)
    return plt

Helper function to a chempot plot look nicer.

Args:
plt (Plot) Plot to add things to.
xrange (list): xlim parameter
ref_el (str): Element of the referenced chempot.
axes(axes) Axes object from matplotlib
pad (float) For tight layout
rect (list): For tight layout
ylim (ylim parameter):

return (Plot): Modified plot with addons.
return (Plot): Modified plot with addons.


def get_controller_info_records(self):
    info_records = []
    for controller_module_name in self._controller_objects.keys():
        with expects.expect_no_raises(('Failed to collect controller info from %s' % controller_module_name)):
            record = self._create_controller_info_record(controller_module_name)
            if record:
                info_records.append(record)
    return info_records

Get the info records for all the controller objects in the manager.

New info records for each controller object are created for every call
so the latest info is included.

Returns:
List of records.ControllerInfoRecord objects. Each opject conatins
the info of a type of controller


def __get_vtt_angles(self, pvals, nvals):
    angles = (np.arctan2(pvals, nvals) - (np.pi / 4))
    norm = np.maximum(np.minimum(angles, (np.pi - angles)), (((- 1) * np.pi) - angles))
    norm = csr_matrix(norm)
    for (key, value) in self.B.items():
        norm[(0, key)] = 0.0
    return norm

Fit the angles to the model

Args:
pvals (array-like) : positive values
nvals (array-like) : negative values

Returns: normalized coef_ values


def bbox_transpose(bbox, axis, rows, cols):
    (x_min, y_min, x_max, y_max) = bbox
    if ((axis != 0) and (axis != 1)):
        raise ValueError('Axis must be either 0 or 1.')
    if (axis == 0):
        bbox = [y_min, x_min, y_max, x_max]
    if (axis == 1):
        bbox = [(1 - y_max), (1 - x_max), (1 - y_min), (1 - x_min)]
    return bbox

Transposes a bounding box along given axis.

Args:
bbox (tuple): A tuple (x_min, y_min, x_max, y_max).
axis (int): 0 - main axis, 1 - secondary axis.
rows (int): Image rows.
cols (int): Image cols.


def qc_curve_group(self, tests, alias=None):
    keys = [k for (k, v) in self.data.items() if isinstance(v, Curve)]
    if (not keys):
        return {}
    all_tests = tests.get('all', tests.get('All', tests.get('ALL', [])))
    data = {test.__name__: test(self, keys, alias) for test in all_tests}
    results = {}
    for (i, key) in enumerate(keys):
        this = {}
        for (test, result) in data.items():
            this[test] = result[i]
        results[key] = this
    return results

Run tests on a cohort of curves.

Args:
alias (dict): an alias dictionary, mapping mnemonics to lists of
mnemonics.

Returns:
dict.


def remove_from_queue(self, index):
    updid = '0'
    objid = ('Q:0/' + str((index + 1)))
    self.avTransport.RemoveTrackFromQueue([('InstanceID', 0), ('ObjectID', objid), ('UpdateID', updid)])

Remove a track from the queue by index. The index number is
required as an argument, where the first index is 0.

Args:
index (int): The (0-based) index of the track to remove


def __get_request(self, host, soup):

        url = URLHelper.make_absolute(host, self.__trim_grave_accent(soup["action"])) if soup.has_attr("action") else host
        method_original = soup["method"] if soup.has_attr("method") else "get"
        method = "post" if method_original.lower() == "post" else "get"
        data = self.__get_form_data(soup)

        return Request(url, method, data)

Build a request from the given soup form.

Args:
host str: The URL of the current queue item.
soup (obj): The BeautifulSoup form.

Returns:
:class:`nyawc.http.Request`: The new Request.


def __eq__(self, rhs):

        return self.key == rhs.key and self.sequence_equal(rhs)

Determine value equality with another grouping.

Args:
rhs: The object on the right-hand-side of the comparison must
support a property called 'key' and be iterable.

Returns:
True if the keys and sequences are equal, otherwise False.


def error_handler(self, handler):

        if not self.opened():
            handler = handler or util.noop
            self._error_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
            self._dll.JLINKARM_SetErrorOutHandler(self._error_handler)

Setter for the error handler function.

If the DLL is open, this function is a no-op, so it should be called
prior to calling ``open()``.

Args:
self (JLink): the ``JLink`` instance
handler (function): function to call on error messages

Returns:
``None``


def __init__(self, parser, pytype_single_args):
    self._parser = parser
    self.pytype_single_args = pytype_single_args
    self._pytype_arg_map = pytype_config.args_map()

Initialize a parser.

Args:
parser: An argparse.ArgumentParser or compatible object
pytype_single_args: Iterable of args that will be passed to pytype_single


def activate_async(fn, _engine):

    @coroutine
    @functools.wraps(fn)
    def wrapper(*args, **kw):
        _engine.activate()
        try:
            if iscoroutinefunction(fn):
                yield from fn(*args, **kw)
            else:
                fn(*args, **kw)
        finally:
            _engine.disable()

    return wrapper

Async version of activate decorator

Arguments:
fn (function): function that be wrapped by decorator.
_engine (Engine): pook engine instance

Returns:
function: decorator wrapper function.


def _CheckWindowsPath(self, filename, artifact_definition, source, path):

    result = True

    number_of_forward_slashes = path.count('/')
    number_of_backslashes = path.count('\\')
    if (number_of_forward_slashes < number_of_backslashes and
        source.separator != '\\'):
      logging.warning((
          'Incorrect path separator: {0:s} in path: {1:s} defined '
          'by artifact definition: {2:s} in file: {3:s}').format(
              source.separator, path, artifact_definition.name,
              filename))
      result = False

    if source.separator != '\\':
      return result

    path_lower = path.lower()
    path_segments = path_lower.split(source.separator)
    if not path_segments:
      logging.warning((
          'Empty path defined by artifact definition: {0:s} in file: '
          '{1:s}').format(artifact_definition.name, filename))
      result = False

    elif path_segments[0].startswith('%%users.') and path_segments[0] not in (
        '%%users.appdata%%', '%%users.homedir%%', '%%users.localappdata%%',
        '%%users.temp%%', '%%users.username%%', '%%users.userprofile%%'):
      logging.warning((
          'Unsupported "{0:s}" in path: {1:s} defined by artifact '
          'definition: {2:s} in file: {3:s}').format(
              path_segments[0], path, artifact_definition.name, filename))
      result = False

    elif path_segments[0] == '%%users.homedir%%':
      logging.warning((
          'Replace "%%users.homedir%%" by "%%users.userprofile%%" in path: '
          '{0:s} defined by artifact definition: {1:s} in file: '
          '{2:s}').format(path, artifact_definition.name, filename))
      result = False

    elif path_lower.startswith('%%users.userprofile%%\\appdata\\local\\'):
      logging.warning((
          'Replace "%%users.userprofile%%\\AppData\\Local" by '
          '"%%users.localappdata%%" in path: {0:s} defined by artifact '
          'definition: {1:s} in file: {2:s}').format(
              path, artifact_definition.name, filename))
      result = False

    elif path_lower.startswith('%%users.userprofile%%\\appdata\\roaming\\'):
      logging.warning((
          'Replace "%%users.userprofile%%\\AppData\\Roaming" by '
          '"%%users.appdata%%" in path: {0:s} defined by artifact '
          'definition: {1:s} in file: {2:s}').format(
              path, artifact_definition.name, filename))
      result = False

    elif path_lower.startswith('%%users.userprofile%%\\application data\\'):
      logging.warning((
          'Replace "%%users.userprofile%%\\Application Data" by '
          '"%%users.appdata%%" in path: {0:s} defined by artifact '
          'definition: {1:s} in file: {2:s}').format(
              path, artifact_definition.name, filename))
      result = False

    elif path_lower.startswith(
        '%%users.userprofile%%\\local settings\\application data\\'):
      logging.warning((
          'Replace "%%users.userprofile%%\\Local Settings\\Application Data" '
          'by "%%users.localappdata%%" in path: {0:s} defined by artifact '
          'definition: {1:s} in file: {2:s}').format(
              path, artifact_definition.name, filename))
      result = False

    for path_segment in path_segments:
      if path_segment.startswith('%%') and path_segment.endswith('%%'):
        if (path_segment.startswith('%%environ_') and
            path_segment not in self._SUPPORTED_WINDOWS_ENVIRONMENT_VARIABLES):
          result = False
          logging.warning((
              'Artifact definition: {0:s} in file: {1:s} contains Windows '
              'path that contains an unuspported environment variable: '
              '"{2:s}".').format(
                  artifact_definition.name, filename, path_segment))

        elif (path_segment.startswith('%%users.') and
              path_segment not in self._SUPPORTED_WINDOWS_USERS_VARIABLES):
          result = False
          logging.warning((
              'Artifact definition: {0:s} in file: {1:s} contains Windows '
              'path that contains an unsupported users variable: '
              '"{2:s}". ').format(
                  artifact_definition.name, filename, path_segment))

    return result

Checks if a path is a valid Windows path.

Args:
filename (str): name of the artifacts definition file.
artifact_definition (ArtifactDefinition): artifact definition.
source (SourceType): source definition.
path (str): path to validate.

Returns:
bool: True if the Windows path is valid.


def fully_qualify_alias_labels(label, aliases):

    for alias, full_name in aliases.items():
        if label == alias:
            return full_name
        elif label.startswith(alias+'.'):
            return full_name + label[len(alias):]
    return label

Replace any aliases in label with the fully qualified name.

Args:
label -- A label : str representing a name (e.g. myos.system)
aliases -- A dict of {alias: real_name} (e.g. {'myos': 'os'})

>>> fully_qualify_alias_labels('myos.mycall', {'myos':'os'})
'os.mycall'


def ExamineEvent(self, mediator, event):
    pathspec = getattr(event, 'pathspec', None)
    if (pathspec is None):
        return
    if self._paths_with_hashes.get(pathspec, None):
        return
    hash_attributes = {}
    for (attribute_name, attribute_value) in event.GetAttributes():
        if attribute_name.endswith('_hash'):
            hash_attributes[attribute_name] = attribute_value
    self._paths_with_hashes[pathspec] = hash_attributes

Analyzes an event and creates extracts hashes as required.

Args:
mediator (AnalysisMediator): mediates interactions between
analysis plugins and other components, such as storage and dfvfs.
event (EventObject): event to examine.


def processMailList(platformNames=[], emails=[]):
    platforms = platform_selection.getPlatformsByName(platformNames, mode='mailfy')
    results = []
    for e in emails:
        for pla in platforms:
            entities = pla.getInfo(query=e, mode='mailfy')
            if (entities != {}):
                results += json.loads(entities)
    return results

Method to perform the email search.

Args:
-----
platformNames: List of names of the platforms.
emails: List of numbers to be queried.

Return:
-------
A list of verified emails.


def env_problem(env_problem_name, **kwargs):

  ep_cls = Registries.env_problems[env_problem_name]
  ep = ep_cls()
  ep.initialize(**kwargs)
  return ep

Get and initialize the `EnvProblem` with the given name and batch size.

Args:
env_problem_name: string name of the registered env problem.
**kwargs: forwarded to env problem's initialize method.

Returns:
an initialized EnvProblem with the given batch size.


def compare(array, other, op, ty_str):

    weld_obj = WeldObject(encoder_, decoder_)

    array_var = weld_obj.update(array)
    if isinstance(array, WeldObject):
        array_var = array.obj_id
        weld_obj.dependencies[array_var] = array

    if isinstance(other, str) or isinstance(other, WeldObject):
        other_var = weld_obj.update(other)
        if isinstance(other, WeldObject):
            other_var = tmp.obj_id
            weld_obj.dependencies[other_var] = other
    else:
        other_var = "%s(%s)" % (ty_str, str(other))

    weld_template =
    weld_obj.weld_code = weld_template % {"array": array_var,
                                          "other": other_var,
                                          "op": op, "ty": ty_str}

    return weld_obj

Performs passed-in comparison op between every element in the passed-in
array and other, and returns an array of booleans.

Args:
array (WeldObject / Numpy.ndarray): Input array
other (WeldObject / Numpy.ndarray): Second input array
op (str): Op string used for element-wise comparison (== >= <= !=)
ty (WeldType): Type of each element in the input array

Returns:
A WeldObject representing this computation


def predict(self, X, break_ties='random', return_probs=False, **kwargs):
    Y_s = self.predict_proba(X, **kwargs)
    self._check(Y_s, typ=list)
    self._check(Y_s[0], typ=np.ndarray)
    Y_p = []
    for Y_ts in Y_s:
        Y_tp = self._break_ties(Y_ts, break_ties)
        Y_p.append(Y_tp.astype(np.int))
    if return_probs:
        return (Y_p, Y_s)
    else:
        return Y_p

Predicts int labels for an input X on all tasks

Args:
X: The input for the predict_proba method
break_ties: A tie-breaking policy
return_probs: Return the predicted probabilities as well

Returns:
Y_p: A t-length list of n-dim np.ndarrays of predictions in [1, K_t]
[Optionally: Y_s: A t-length list of [n, K_t] np.ndarrays of
predicted probabilities]


def min(self, value):

        if value == self._defaults['min'] and 'min' in self._values:
            del self._values['min']
        else:
            self._values['min'] = value

The min property.

Args:
value (float). the property value.


def TerminateFlow(client_id,
                  flow_id,
                  reason=None,
                  flow_state=rdf_flow_objects.Flow.FlowState.ERROR):

  to_terminate = [data_store.REL_DB.ReadFlowObject(client_id, flow_id)]

  while to_terminate:
    next_to_terminate = []
    for rdf_flow in to_terminate:
      _TerminateFlow(rdf_flow, reason=reason, flow_state=flow_state)
      next_to_terminate.extend(
          data_store.REL_DB.ReadChildFlowObjects(rdf_flow.client_id,
                                                 rdf_flow.flow_id))
    to_terminate = next_to_terminate

Terminates a flow and all of its children.

Args:
client_id: Client ID of a flow to terminate.
flow_id: Flow ID of a flow to terminate.
reason: String with a termination reason.
flow_state: Flow state to be assigned to a flow after termination. Defaults
to FlowState.ERROR.


def put(self, source, rel_path, metadata=None):

        if not isinstance(rel_path, basestring):
            rel_path = rel_path.cache_key

        sink = self.put_stream(rel_path, metadata=metadata)

        try:
            copy_file_or_flo(source, sink)
        except (KeyboardInterrupt, SystemExit):
            path_ = self.path(rel_path)
            if os.path.exists(path_):
                os.remove(path_)
            raise

        sink.close()

        return os.path.join(self.cache_dir, rel_path)

Copy a file to the repository

Args:
source: Absolute path to the source file, or a file-like object
rel_path: path relative to the root of the repository


def _check_module_is_image_embedding(module_spec):
    issues = []
    input_info_dict = module_spec.get_input_info_dict()
    if ((list(input_info_dict.keys()) != ['images']) or (input_info_dict['images'].dtype != tf.float32)):
        issues.append("Module 'default' signature must require a single input, which must have type float32 and name 'images'.")
    else:
        try:
            image_util.get_expected_image_size(module_spec)
        except ValueError as e:
            issues.append(('Module does not support hub.get_expected_image_size(); original error was:\n' + str(e)))
    output_info_dict = module_spec.get_output_info_dict()
    if ('default' not in output_info_dict):
        issues.append("Module 'default' signature must have a 'default' output.")
    else:
        output_type = output_info_dict['default'].dtype
        output_shape = output_info_dict['default'].get_shape()
        if (not ((output_type == tf.float32) and (output_shape.ndims == 2) and output_shape.dims[1].value)):
            issues.append("Module 'default' signature must have a 'default' output of tf.Tensor(shape=(_,K), dtype=float32).")
    if issues:
        raise ValueError(('Module is not usable as image embedding: %r' % issues))

Raises ValueError if `module_spec` is not usable as image embedding.

Args:
module_spec: A `_ModuleSpec` to test.

Raises:
ValueError: if `module_spec` default signature is not compatible with
mappingan "images" input to a Tensor(float32, shape=(_,K)).


def ParseInput(self, a_file):

    input_lines = a_file.read().splitlines()
    self.ParseLines(input_lines)

Consumes input extracting definitions.

Args:
a_file: The file like stream to parse.

Raises:
PDDMError if there are any issues.


def info(self, collector_id):
    cid = self.collector_id
    if collector_id:
        cid = collector_id
    url = '{0}/{1}'.format(self.url, cid)
    request = requests.get(url, auth=self.auth)
    return request.json()

Return a dict of collector.

Args:
collector_id (int): id of collector (optional)


def enqueue(self, priority: int, item: TItem) -> bool:
    if (self._drop_set is not None):
        if ((priority, item) in self._drop_set):
            return False
        self._drop_set.add((priority, item))
    if (not self._buckets):
        self._buckets.append([item])
        self._offset = priority
        self._len = 1
        return True
    i = (priority - self._offset)
    if (i < 0):
        self._buckets[:0] = [[] for _ in range((- i))]
        self._offset = priority
        i = 0
    while (i >= len(self._buckets)):
        self._buckets.append([])
    self._buckets[i].append(item)
    self._len += 1
    return True

Adds an entry to the priority queue.

If drop_duplicate_entries is set and there is already a (priority, item)
entry in the queue, then the enqueue is ignored. Check the return value
to determine if an enqueue was kept or dropped.

Args:
priority: The priority of the item. Lower priorities dequeue before
higher priorities.
item: The item associated with the given priority.

Returns:
True if the item was enqueued. False if drop_duplicate_entries is
set and the item is already in the queue.


def VerifyStructure(self, parser_mediator, line):
    structure = self.LOG_LINE
    try:
        parsed_structure = structure.parseString(line)
    except pyparsing.ParseException:
        logger.debug('Not a XChat scrollback log file')
        return False
    try:
        int(parsed_structure.timestamp, 10)
    except ValueError:
        logger.debug('Not a XChat scrollback log file, invalid timestamp string')
        return False
    return True

Verify that this file is a XChat scrollback log file.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
line (str): line from a text file.

Returns:
bool: True if the line was successfully parsed.


def delete(self, personId):

        check_type(personId, basestring, may_be_none=False)

        self._session.delete(API_ENDPOINT + '/' + personId)

Remove a person from the system.

Only an admin can remove a person.

Args:
personId(basestring): The ID of the person to be deleted.

Raises:
TypeError: If the parameter types are incorrect.
ApiError: If the Webex Teams cloud returns an error.


def user_set_string(namespace, name, metric, ptransform=None):
    labels = create_labels(ptransform=ptransform, namespace=namespace, name=name)
    if isinstance(metric, StringSetData):
        metric = metric.string_set
    if isinstance(metric, set):
        metric = list(metric)
    if isinstance(metric, list):
        metric = coders.IterableCoder(coders.StrUtf8Coder()).encode(metric)
    return create_monitoring_info(USER_STRING_SET_URN, STRING_SET_TYPE, metric, labels)

Return the string set monitoring info for the URN, metric and labels.

Args:
namespace: User-defined namespace of StringSet.
name: Name of StringSet.
metric: The StringSetData representing the metrics.
ptransform: The ptransform id used as a label.


def get_absorbing_atom_symbol_index(absorbing_atom, structure):

    if isinstance(absorbing_atom, str):
        return absorbing_atom, structure.indices_from_symbol(absorbing_atom)[0]
    elif isinstance(absorbing_atom, int):
        return str(structure[absorbing_atom].specie), absorbing_atom
    else:
        raise ValueError("absorbing_atom must be either specie symbol or site index")

Return the absorbing atom symboll and site index in the given structure.

Args:
absorbing_atom (str/int): symbol or site index
structure (Structure)

Returns:
str, int: symbol and site index


def get_numpy_to_framework_fn(arr) -> Callable:
    if isinstance(arr, np.ndarray):
        return np.array
    if is_tf_available() and is_tf_tensor(arr):
        import tensorflow as tf
        return tf.convert_to_tensor
    if is_torch_available() and is_torch_tensor(arr):
        import torch
        return torch.tensor
    if is_flax_available() and is_jax_tensor(arr):
        import jax.numpy as jnp
        return jnp.array
    raise ValueError(f'Cannot convert arrays of type {type(arr)}')

Returns a function that converts a numpy array to the framework of the input array.

Args:
arr (`np.ndarray`): The array to convert.


def newick(self):
    if (self.root.edge_length is None):
        suffix = ';'
    elif isinstance(self.root.edge_length, int):
        suffix = (':%d;' % self.root.edge_length)
    elif (isinstance(self.root.edge_length, float) and self.root.edge_length.is_integer()):
        suffix = (':%d;' % int(self.root.edge_length))
    else:
        suffix = (':%s;' % str(self.root.edge_length))
    if self.is_rooted:
        return ('[&R] %s%s' % (self.root.newick(), suffix))
    else:
        return ('%s%s' % (self.root.newick(), suffix))

Output this ``Tree`` as a Newick string

Returns:
``str``: Newick string of this ``Tree``


def _process_in_collection_filter_directive(filter_operation_info, location, context, parameters):
    filtered_field_type = filter_operation_info.field_type
    filtered_field_name = filter_operation_info.field_name
    argument_inferred_type = GraphQLList(strip_non_null_from_type(filtered_field_type))
    (argument_expression, non_existence_expression) = _represent_argument(location, context, parameters[0], argument_inferred_type)
    filter_predicate = expressions.BinaryComposition(u'contains', argument_expression, expressions.LocalField(filtered_field_name))
    if (non_existence_expression is not None):
        filter_predicate = expressions.BinaryComposition(u'||', non_existence_expression, filter_predicate)
    return blocks.Filter(filter_predicate)

Return a Filter basic block that checks for a value's existence in a collection.

Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this filter is used.
context: dict, various per-compilation data (e.g. declared tags, whether the current block
is optional, etc.). May be mutated in-place in this function!
parameters: list of 1 element, specifying the collection in which the value must exist;
if the collection is optional and missing, the check will return True

Returns:
a Filter basic block that performs the collection existence check


def buckingham_input(self, structure, keywords, library=None, uc=True, valence_dict=None):
    gin = self.keyword_line(*keywords)
    gin += self.structure_lines(structure, symm_flg=(not uc))
    if (not library):
        gin += self.buckingham_potential(structure, valence_dict)
    else:
        gin += self.library_line(library)
    return gin

Gets a GULP input for an oxide structure and buckingham potential
from library.

Args:
structure: pymatgen.core.structure.Structure
keywords: GULP first line keywords.
library (Default=None): File containing the species and potential.
uc (Default=True): Unit Cell Flag.
valence_dict: {El: valence}


def ping(hostname: str, timeout_s: int=5) -> bool:
    if (sys.platform == 'win32'):
        timeout_ms = (timeout_s * 1000)
        args = ['ping', hostname, '-n', '1', '-w', str(timeout_ms)]
    elif sys.platform.startswith('linux'):
        args = ['ping', hostname, '-c', '1', '-w', str(timeout_s)]
    else:
        raise AssertionError("Don't know how to ping on this operating system")
    proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    proc.communicate()
    retcode = proc.returncode
    return (retcode == 0)

Pings a host, using OS tools.

Args:
hostname: host name or IP address
timeout_s: timeout in seconds

Returns:
was the ping successful?


def from_config(cls, path, directory=None):

        if not exists(path):
            raise REPPError('REPP config file not found: {}'.format(path))
        confdir = dirname(path)

        conf = io.open(path, encoding='utf-8').read()
        conf = re.sub(r';.*', '', conf).replace('\n',' ')
        m = re.search(
            r'repp-modules\s*:=\s*((?:[-\w]+\s+)*[-\w]+)\s*\.', conf)
        t = re.search(
            r'repp-tokenizer\s*:=\s*([-\w]+)\s*\.', conf)
        a = re.search(
            r'repp-calls\s*:=\s*((?:[-\w]+\s+)*[-\w]+)\s*\.', conf)
        f = re.search(
            r'format\s*:=\s*(\w+)\s*\.', conf)
        d = re.search(
            r'repp-directory\s*:=\s*(.*)\.\s*$', conf)

        if m is None:
            raise REPPError('repp-modules option must be set')
        if t is None:
            raise REPPError('repp-tokenizer option must be set')

        mods = m.group(1).split()
        tok = t.group(1).strip()
        active = a.group(1).split() if a is not None else None
        fmt = f.group(1).strip() if f is not None else None

        if directory is None:
            if d is not None:
                directory = d.group(1).strip(' "')
            elif exists(joinpath(confdir, tok + '.rpp')):
                directory = confdir
            elif exists(joinpath(confdir, 'rpp', tok + '.rpp')):
                directory = joinpath(confdir, 'rpp')
            elif exists(joinpath(confdir, '../rpp', tok + '.rpp')):
                directory = joinpath(confdir, '../rpp')
            else:
                raise REPPError('Could not find a suitable REPP directory.')

        return REPP.from_file(
            joinpath(directory, tok + '.rpp'),
            directory=directory,
            active=active
        )

Instantiate a REPP from a PET-style `.set` configuration file.

The *path* parameter points to the configuration file.
Submodules are loaded from *directory*. If *directory* is not
given, it is the directory part of *path*.

Args:
path (str): the path to the REPP configuration file
directory (str, optional): the directory in which to search
for submodules


def __radd__(self, other):
    return self + other

Returns the sum of `other` and `self`.

Args:
other: Another Dimension, or a value accepted by `as_dimension`.

Returns:
A Dimension whose value is the sum of `self` and `other`.


def count_true_positive(truth, recommend):

    tp = 0
    for r in recommend:
        if r in truth:
            tp += 1
    return tp

Count number of true positives from given sets of samples.

Args:
truth (numpy 1d array): Set of truth samples.
recommend (numpy 1d array): Ordered set of recommended samples.

Returns:
int: Number of true positives.


def is_open(self):
    return bool(self._telnet_client.is_open)

This function returns the state of the telnet connection to the
underlying AttenuatorDevice.

Returns:
True if there is a successfully open connection to the
AttenuatorDevice.


def submit_snl(self, snl):
    try:
        snl = (snl if isinstance(snl, list) else [snl])
        jsondata = [s.as_dict() for s in snl]
        payload = {'snl': json.dumps(jsondata, cls=MontyEncoder)}
        response = self.session.post('{}/snl/submit'.format(self.preamble), data=payload)
        if (response.status_code in [200, 400]):
            resp = json.loads(response.text, cls=MontyDecoder)
            if resp['valid_response']:
                if resp.get('warning'):
                    warnings.warn(resp['warning'])
                return resp['inserted_ids']
            else:
                raise MPRestError(resp['error'])
        raise MPRestError('REST error with status code {} and error {}'.format(response.status_code, response.text))
    except Exception as ex:
        raise MPRestError(str(ex))

Submits a list of StructureNL to the Materials Project site.

.. note::

As of now, this MP REST feature is open only to a select group of
users. Opening up submissions to all users is being planned for
the future.

Args:
snl (StructureNL/[StructureNL]): A single StructureNL, or a list
of StructureNL objects

Returns:
A list of inserted submission ids.

Raises:
MPRestError


def NewFromJSON(data):
    return SharedFile(sharekey=data.get('sharekey', None), name=data.get('name', None), user=User.NewFromJSON(data.get('user', None)), title=data.get('title', None), description=data.get('description', None), posted_at=data.get('posted_at', None), permalink=data.get('permalink', None), width=data.get('width', None), height=data.get('height', None), views=data.get('views', 0), likes=data.get('likes', 0), saves=data.get('saves', 0), comments=data.get('comments', None), nsfw=data.get('nsfw', False), image_url=data.get('image_url', None), source_url=data.get('source_url', None), saved=data.get('saved', False), liked=data.get('liked', False))

Create a new SharedFile instance from a JSON dict.

Args:
data (dict): JSON dictionary representing a SharedFile.

Returns:
A SharedFile instance.


def start(self):
    server_sock = self.start_listening_socket()
    host = self.get_server_ip()
    port = server_sock.getsockname()[1]
    addr = (host, port)
    logging.info('listening for reservations at {0}'.format(addr))

    def _listen(self, sock):
        CONNECTIONS = []
        CONNECTIONS.append(sock)
        while (not self.done):
            (read_socks, write_socks, err_socks) = select.select(CONNECTIONS, [], [], 60)
            for sock in read_socks:
                if (sock == server_sock):
                    (client_sock, client_addr) = sock.accept()
                    CONNECTIONS.append(client_sock)
                    logging.debug('client connected from {0}'.format(client_addr))
                else:
                    try:
                        msg = self.receive(sock)
                        self._handle_message(sock, msg)
                    except Exception as e:
                        logging.debug(e)
                        sock.close()
                        CONNECTIONS.remove(sock)
        server_sock.close()
    t = threading.Thread(target=_listen, args=(self, server_sock))
    t.daemon = True
    t.start()
    return addr

Start listener in a background thread

Returns:
address of the Server as a tuple of (host, port)


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

Corresponds to IDD Field `depth_march_average_ground_temperature`

Args:
value (float): value for IDD Field `depth_march_average_ground_temperature`
Unit: C
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

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


def get_path(url):

    url = urlsplit(url)
    path = url.path
    if url.query:
        path += "?{}".format(url.query)
    return path

Get the path from a given url, including the querystring.

Args:
url (str)
Returns:
str


def _get_bounds(self, layers):
    extent_query = 'SELECT ST_EXTENT(the_geom) AS the_geom FROM ({query}) AS t{idx}\n'
    union_query = 'UNION ALL\n'.join([extent_query.format(query=layer.orig_query, idx=idx) for (idx, layer) in enumerate(layers) if (not layer.is_basemap)])
    extent = self.sql_client.send(utils.minify_sql(('SELECT', '    ST_XMIN(ext) AS west,', '    ST_YMIN(ext) AS south,', '    ST_XMAX(ext) AS east,', '    ST_YMAX(ext) AS north', 'FROM (', '    SELECT ST_Extent(the_geom) AS ext', '    FROM ({union_query}) AS _wrap1', ') AS _wrap2')).format(union_query=union_query), do_post=False)
    return extent['rows'][0]

Return the bounds of all data layers involved in a cartoframes map.

Args:
layers (list): List of cartoframes layers. See `cartoframes.layers`
for all types.

Returns:
dict: Dictionary of northern, southern, eastern, and western bounds
of the superset of data layers. Keys are `north`, `south`,
`east`, and `west`. Units are in WGS84.


def _build(self, inputs):
    input_shape = tuple(inputs.get_shape().as_list())
    if (len(input_shape) != 2):
        raise base.IncompatibleShapeError('{}: rank of shape must be 2 not: {}'.format(self.scope_name, len(input_shape)))
    if (input_shape[1] is None):
        raise base.IncompatibleShapeError('{}: Input size must be specified at module build time'.format(self.scope_name))
    if ((self._input_shape is not None) and (input_shape[1] != self._input_shape[1])):
        raise base.IncompatibleShapeError('{}: Input shape must be [batch_size, {}] not: [batch_size, {}]'.format(self.scope_name, self._input_shape[1], input_shape[1]))
    self._input_shape = input_shape
    dtype = inputs.dtype
    if ('w' not in self._initializers):
        self._initializers['w'] = create_linear_initializer(self._input_shape[1], dtype)
    if (('b' not in self._initializers) and self._use_bias):
        self._initializers['b'] = create_bias_initializer(self._input_shape[1], dtype)
    weight_shape = (self._input_shape[1], self.output_size)
    self._w = tf.get_variable('w', shape=weight_shape, dtype=dtype, initializer=self._initializers['w'], partitioner=self._partitioners.get('w', None), regularizer=self._regularizers.get('w', None))
    outputs = tf.matmul(inputs, self._w)
    if self._use_bias:
        bias_shape = (self.output_size,)
        self._b = tf.get_variable('b', shape=bias_shape, dtype=dtype, initializer=self._initializers['b'], partitioner=self._partitioners.get('b', None), regularizer=self._regularizers.get('b', None))
        outputs += self._b
    return outputs

Connects the Linear module into the graph, with input Tensor `inputs`.

If this is not the first time the module has been connected to the graph,
the Tensor provided here must have the same final dimension, in order for
the existing variables to be the correct size for the multiplication. The
batch size may differ for each connection.

Args:
inputs: A 2D Tensor of size [batch_size, input_size].

Returns:
A 2D Tensor of size [batch_size, output_size].

Raises:
base.IncompatibleShapeError: If the input is not a 2-D `Tensor` with
the size of the second dimension specified.
base.IncompatibleShapeError: If reconnecting an already connected module
into the graph, and the shape of the input is not compatible with
previous inputs.


def _is_variant_with_internal_stacking(t):
    type_id = _variant_type_id(t)
    return type_id in _INTERNAL_STACKING_TYPE_IDS

Identifies variant tensors which pfor always maintains as scalars.

For these, the pfor tensor is recorded as "stacked" if the content of the
variant tensor (e.g. the elements of a TensorList) are all stacked.

Args:
t: A tensor to identify.
Returns:
True if `t` is a TensorList/Optional, False not, None if unknown.


def add_controller_info_record(self, controller_info_record):
    self.controller_info.append(controller_info_record)

Adds a controller info record to results.

This can be called multiple times for each test class.

Args:
controller_info_record: ControllerInfoRecord object to be added to
the result.


def compile_cpfs(self,
                     scope: Dict[str, TensorFluent],
                     batch_size: Optional[int] = None,
                     noise: Optional[Noise] = None) -> Tuple[List[CPFPair], List[CPFPair]]:

        interm_fluents = self.compile_intermediate_cpfs(scope, batch_size, noise)
        scope.update(dict(interm_fluents))
        next_state_fluents = self.compile_state_cpfs(scope, batch_size, noise)
        return interm_fluents, next_state_fluents

Compiles the intermediate and next state fluent CPFs given the current `state` and `action` scope.

Args:
scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): The fluent scope for CPF evaluation.
batch_size (Optional[int]): The batch size.

Returns:
Tuple[List[CPFPair], List[CPFPair]]: A pair of lists of TensorFluent
representing the intermediate and state CPFs.


def _add_gmaf(self, variant_obj, info_dict):

        for transcript in variant_obj.transcripts:
            gmaf_raw = transcript.GMAF
            if gmaf_raw:
                gmaf = float(gmaf_raw.split(':')[-1])
                variant_obj.add_frequency('GMAF', gmaf)

                if not variant_obj.thousand_g:
                    variant_obj.thousand_g = gmaf

Add the gmaf frequency

Args:
variant_obj (puzzle.models.Variant)
info_dict (dict): A info dictionary


def extract_subtree(self, node):
    if (not isinstance(node, Node)):
        raise TypeError('node must be a Node')
    r = self.root
    self.root = node
    o = copy(self)
    self.root = r
    return o

Return a copy of the subtree rooted at ``node``

Args:
``node`` (``Node``): The root of the desired subtree

Returns:
``Tree``: A copy of the subtree rooted at ``node``


def variable(dims=1):
    if (dims == 1):
        return Poly({(1,): 1}, dim=1, shape=())
    return Poly({tuple(indices): indices for indices in numpy.eye(dims, dtype=int)}, dim=dims, shape=(dims,))

Simple constructor to create single variables to create polynomials.

Args:
dims (int):
Number of dimensions in the array.

Returns:
(Poly):
Polynomial array with unit components in each dimension.

Examples:
>>> print(variable())
q0
>>> print(variable(3))
[q0, q1, q2]


def run_example(example_coroutine, *extra_args):

    args = _get_parser(extra_args).parse_args()
    logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARNING)

    cookies = hangups.auth.get_auth_stdin(args.token_path)
    client = hangups.Client(cookies)
    loop = asyncio.get_event_loop()
    task = asyncio.ensure_future(_async_main(example_coroutine, client, args),
                                 loop=loop)

    try:
        loop.run_until_complete(task)
    except KeyboardInterrupt:
        task.cancel()
        loop.run_until_complete(task)
    finally:
        loop.close()

Run a hangups example coroutine.

Args:
example_coroutine (coroutine): Coroutine to run with a connected
hangups client and arguments namespace as arguments.
extra_args (str): Any extra command line arguments required by the
example.


def ReleaseRecords(cls, ids, token):

    with data_store.DB.GetMutationPool() as mutation_pool:
      mutation_pool.QueueReleaseRecords(ids)

Release records identified by subjects.

Releases any claim on the records identified by ids.

Args:
ids: A list of ids provided by ClaimRecords.
token: The database access token to write with.

Raises:
LockError: If the queue is not locked.


def _help_handler(self, args, screen_info=None):
    _ = screen_info
    if not args:
        return self.get_help()
    elif len(args) == 1:
        return self.get_help(args[0])
    else:
        return RichTextLines(['ERROR: help takes only 0 or 1 input argument.'])

Command handler for "help".

"help" is a common command that merits built-in support from this class.

Args:
args: Command line arguments to "help" (not including "help" itself).
screen_info: (dict) Information regarding the screen, e.g., the screen
width in characters: {"cols": 80}

Returns:
(RichTextLines) Screen text output.


def run_excel_to_html():
    parser = argparse.ArgumentParser(prog='excel_to_html')
    parser.add_argument('-p', nargs='?', help='Path to an excel file for conversion.')
    parser.add_argument('-s', nargs='?', help='The name of a sheet in our excel file. Defaults to "Sheet1".')
    parser.add_argument('-css', nargs='?', help='Space separated css classes to append to the table.')
    parser.add_argument('-m', action='store_true', help='Merge, attempt to combine merged cells.')
    parser.add_argument('-c', nargs='?', help='Caption for creating an accessible table.')
    parser.add_argument('-d', nargs='?', help='Two strings separated by a | character. The first string         is for the html "summary" attribute and the second string is for the html "details" attribute.         both values must be provided and nothing more.')
    parser.add_argument('-r', action='store_true', help='Row headers. Does the table have row headers?')
    args = parser.parse_args()
    inputs = {'p': args.p, 's': args.s, 'css': args.css, 'm': args.m, 'c': args.c, 'd': args.d, 'r': args.r}
    p = inputs['p']
    s = (inputs['s'] if inputs['s'] else 'Sheet1')
    css = (inputs['css'] if inputs['css'] else '')
    m = (inputs['m'] if inputs['m'] else False)
    c = (inputs['c'] if inputs['c'] else '')
    d = (inputs['d'].split('|') if inputs['d'] else [])
    r = (inputs['r'] if inputs['r'] else False)
    html = fp.excel_to_html(p, sheetname=s, css_classes=css, caption=c, details=d, row_headers=r, merge=m)
    print(html)

Run the excel_to_html function from the
command-line.

Args:
-p path to file
-s name of the sheet to convert
-css classes to apply
-m attempt to combine merged cells
-c caption for accessibility
-su summary for accessibility
-d details for accessibility

Example use:

excel_to_html -p myfile.xlsx -s SheetName -css diablo-python -m true


def execute(self):
    self.generate_workflow_description()
    if self.batch_values:
        self.id = self.workflow.launch_batch_workflow(self.definition)
    else:
        self.id = self.workflow.launch(self.definition)
    return self.id

Execute the workflow.

Args:
None

Returns:
Workflow_id


def update(self, settings):

        Instrument.update(self, settings)

        for key, value in settings.items():
            if key == 'test1':
                self._internal_state = value

updates the internal dictionary and sends changed values to instrument
Args:
settings: parameters to be set
# mabe in the future:
# Returns: boolean that is true if update successful


def _ParseKeysFromFindSpecs(self, parser_mediator, win_registry, find_specs):
    searcher = dfwinreg_registry_searcher.WinRegistrySearcher(win_registry)
    for registry_key_path in iter(searcher.Find(find_specs=find_specs)):
        if parser_mediator.abort:
            break
        registry_key = searcher.GetKeyByPath(registry_key_path)
        self._ParseKey(parser_mediator, registry_key)

Parses the Registry keys from FindSpecs.

Args:
parser_mediator (ParserMediator): parser mediator.
win_registry (dfwinreg.WinRegistryKey): root Windows Registry key.
find_specs (dfwinreg.FindSpecs): Keys to search for.


def build_wheel(dir_path: str, cwd: str, project_name: str, platform: str, collab: str=False) -> None:
    env = os.environ.copy()
    if is_windows():
        env['HOMEPATH'] = 'C:'
    env['project_name'] = project_name
    if collab == 'True':
        env['collaborator_build'] = True
    subprocess.run([sys.executable, 'tensorflow/tools/pip_package/setup.py', 'bdist_wheel', f'--dist-dir={dir_path}', f'--plat-name={platform}'], check=True, cwd=cwd, env=env)

Build the wheel in the target directory.

Args:
dir_path: directory where the wheel will be stored
cwd: path to directory with wheel source files
project_name: name to pass to setup.py.
platform: platform name to pass to setup.py.
collab: defines if this is a collab build


def SetLookupHash(self, lookup_hash):
    if (lookup_hash not in self.SUPPORTED_HASHES):
        raise ValueError('Unsupported lookup hash: {0!s}'.format(lookup_hash))
    self.lookup_hash = lookup_hash

Sets the hash to query.

Args:
lookup_hash (str): name of the hash attribute to look up.

Raises:
ValueError: if the lookup hash is not supported.


def deliver_tx(self, raw_transaction):
    self.abort_if_abci_chain_is_not_synced()
    logger.debug('deliver_tx: %s', raw_transaction)
    transaction = self.bigchaindb.is_valid_transaction(decode_transaction(raw_transaction), self.block_transactions)
    if (not transaction):
        logger.debug('deliver_tx: INVALID')
        return ResponseDeliverTx(code=CodeTypeError)
    else:
        logger.debug('storing tx')
        self.block_txn_ids.append(transaction.id)
        self.block_transactions.append(transaction)
        return ResponseDeliverTx(code=CodeTypeOk)

Validate the transaction before mutating the state.

Args:
raw_tx: a raw string (in bytes) transaction.


def FileEntryExistsByPathSpec(self, path_spec):

    volume_index = apfs_helper.APFSContainerPathSpecGetVolumeIndex(path_spec)

    if volume_index is None:
      location = getattr(path_spec, 'location', None)
      return location is not None and location == self.LOCATION_ROOT

    return 0 <= volume_index < self._fsapfs_container.number_of_volumes

Determines if a file entry for a path specification exists.

Args:
path_spec (PathSpec): a path specification.

Returns:
bool: True if the file entry exists.


def _ConvertFileProtoToFileDescriptor(self, file_proto):
    if (file_proto.name not in self._file_descriptors):
        built_deps = list(self._GetDeps(file_proto.dependency))
        direct_deps = [self.FindFileByName(n) for n in file_proto.dependency]
        public_deps = [direct_deps[i] for i in file_proto.public_dependency]
        file_descriptor = descriptor.FileDescriptor(pool=self, name=file_proto.name, package=file_proto.package, syntax=file_proto.syntax, options=_OptionsOrNone(file_proto), serialized_pb=file_proto.SerializeToString(), dependencies=direct_deps, public_dependencies=public_deps)
        scope = {}
        for dependency in built_deps:
            scope.update(self._ExtractSymbols(dependency.message_types_by_name.values()))
            scope.update(((_PrefixWithDot(enum.full_name), enum) for enum in dependency.enum_types_by_name.values()))
        for message_type in file_proto.message_type:
            message_desc = self._ConvertMessageDescriptor(message_type, file_proto.package, file_descriptor, scope, file_proto.syntax)
            file_descriptor.message_types_by_name[message_desc.name] = message_desc
        for enum_type in file_proto.enum_type:
            file_descriptor.enum_types_by_name[enum_type.name] = self._ConvertEnumDescriptor(enum_type, file_proto.package, file_descriptor, None, scope)
        for (index, extension_proto) in enumerate(file_proto.extension):
            extension_desc = self._MakeFieldDescriptor(extension_proto, file_proto.package, index, is_extension=True)
            extension_desc.containing_type = self._GetTypeFromScope(file_descriptor.package, extension_proto.extendee, scope)
            self._SetFieldType(extension_proto, extension_desc, file_descriptor.package, scope)
            file_descriptor.extensions_by_name[extension_desc.name] = extension_desc
        for desc_proto in file_proto.message_type:
            self._SetAllFieldTypes(file_proto.package, desc_proto, scope)
        if file_proto.package:
            desc_proto_prefix = _PrefixWithDot(file_proto.package)
        else:
            desc_proto_prefix = ''
        for desc_proto in file_proto.message_type:
            desc = self._GetTypeFromScope(desc_proto_prefix, desc_proto.name, scope)
            file_descriptor.message_types_by_name[desc_proto.name] = desc
        for (index, service_proto) in enumerate(file_proto.service):
            file_descriptor.services_by_name[service_proto.name] = self._MakeServiceDescriptor(service_proto, index, scope, file_proto.package, file_descriptor)
        self.Add(file_proto)
        self._file_descriptors[file_proto.name] = file_descriptor
    return self._file_descriptors[file_proto.name]

Creates a FileDescriptor from a proto or returns a cached copy.

This method also has the side effect of loading all the symbols found in
the file into the appropriate dictionaries in the pool.

Args:
file_proto: The proto to convert.

Returns:
A FileDescriptor matching the passed in proto.


def get_container_image_from_options(pipeline_options):
    worker_options = pipeline_options.view_as(WorkerOptions)
    if worker_options.sdk_container_image:
        return worker_options.sdk_container_image
    container_repo = names.DATAFLOW_CONTAINER_IMAGE_REPOSITORY
    image_name = '{repository}/beam_python{major}.{minor}_sdk'.format(repository=container_repo, major=sys.version_info[0], minor=sys.version_info[1])
    image_tag = _get_required_container_version()
    return image_name + ':' + image_tag

For internal use only; no backwards-compatibility guarantees.

Args:
pipeline_options (PipelineOptions): A container for pipeline options.

Returns:
str: Container image for remote execution.


def from_dict(cls, d):
    labels_dict = d['labels_dict']
    projections = {}
    structure = None
    if isinstance(list(d['bands'].values())[0], dict):
        eigenvals = {Spin(int(k)): np.array(d['bands'][k]['data']) for k in d['bands']}
    else:
        eigenvals = {Spin(int(k)): d['bands'][k] for k in d['bands']}
    if ('structure' in d):
        structure = Structure.from_dict(d['structure'])
    if d.get('projections'):
        projections = {Spin(int(spin)): np.array(v) for (spin, v) in d['projections'].items()}
    return BandStructure(d['kpoints'], eigenvals, Lattice(d['lattice_rec']['matrix']), d['efermi'], labels_dict, structure=structure, projections=projections)

Create from dict.

Args:
A dict with all data for a band structure object.

Returns:
A BandStructure object


def __init__(self, ascii_codepage='cp1252', key_path_prefix=''):

    super(FakeWinRegistryFile, self).__init__(
        ascii_codepage=ascii_codepage, key_path_prefix=key_path_prefix)
    self._root_key = None

Initializes a Windows Registry file.

Args:
ascii_codepage (str): ASCII string codepage.
key_path_prefix (str): Windows Registry key path prefix.


class ActivityRegularization(Layer):

    def __init__(self, l1=0.0, l2=0.0, **kwargs):
        super().__init__(activity_regularizer=regularizers.L1L2(l1=l1, l2=l2), **kwargs)
        self.supports_masking = True
        self.l1 = l1
        self.l2 = l2
        self._build_at_init()

    def call(self, inputs):
        return inputs

    def compute_output_shape(self, input_shape):
        return input_shape

    def get_config(self):
        base_config = super().get_config()
        base_config.pop('activity_regularizer', None)
        config = {'l1': self.l1, 'l2': self.l2}
        return {**base_config, **config}

Layer that applies an update to the cost function based input activity.

Args:
l1: L1 regularization factor (positive float).
l2: L2 regularization factor (positive float).

Input shape:
Arbitrary. Use the keyword argument `input_shape`
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.

Output shape:
Same shape as input.


def get_pages(self, url, params=None, **kwargs):
    check_type(url, basestring, may_be_none=False)
    check_type(params, dict)
    erc = kwargs.pop('erc', EXPECTED_RESPONSE_CODE['GET'])
    response = self.request('GET', url, erc, params=params, **kwargs)
    while True:
        (yield extract_and_parse_json(response))
        if response.links.get('next'):
            next_url = response.links.get('next').get('url')
            next_url = _fix_next_url(next_url)
            response = self.request('GET', next_url, erc, **kwargs)
        else:
            break

Return a generator that GETs and yields pages of data.

Provides native support for RFC5988 Web Linking.

Args:
url(basestring): The URL of the API endpoint.
params(dict): The parameters for the HTTP GET request.
**kwargs:
erc(int): The expected (success) response code for the request.
others: Passed on to the requests package.

Raises:
ApiError: If anything other than the expected response code is
returned by the Webex Teams API endpoint.


def _get_node_attribute_at_index(self, node_index, attr, attr_name):
    if not self._inbound_nodes:
        raise RuntimeError('The layer has never been called and thus has no defined ' + attr_name + '.')
    if not len(self._inbound_nodes) > node_index:
        raise ValueError('Asked to get ' + attr_name + ' at node ' + str(node_index) + ', but the layer has only ' + str(len(self._inbound_nodes)) + ' inbound nodes.')
    values = getattr(self._inbound_nodes[node_index], attr)
    if isinstance(values, list) and len(values) == 1:
        return values[0]
    else:
        return values

Private utility to retrieves an attribute (e.g. inputs) from a node.

This is used to implement the methods:
- get_input_shape_at
- get_output_shape_at
- get_input_at
etc...

Args:
node_index: Integer index of the node from which
to retrieve the attribute.
attr: Exact node attribute name.
attr_name: Human-readable attribute name, for error messages.

Returns:
The layer's attribute `attr` at the node of index `node_index`.

Raises:
RuntimeError: If the layer has no inbound nodes, or if called in Eager
mode.
ValueError: If the index provided does not match any node.


def lenet5(images, labels):
    images = pt.wrap(images)
    with pt.defaults_scope(activation_fn=tf.nn.relu, l2loss=1e-05):
        return images.conv2d(5, 20).max_pool(2, 2).conv2d(5, 50).max_pool(2, 2).flatten().fully_connected(500).softmax_classifier(10, labels)

Creates a multi layer convolutional network.

The architecture is similar to that defined in LeNet 5.
Please change this to experiment with architectures.

Args:
images: The input images.
labels: The labels as dense one-hot vectors.
Returns:
A softmax result.


def store_sample_set(self, md5_list):

        if not md5_list:
            print 'Warning: Trying to store an empty sample_set'
            return None

        md5_list = list(set(md5_list))

        for md5 in md5_list:
            if not self.has_sample(md5):
                raise RuntimeError('%s: Not found! All items in sample_set must be in the datastore' % (md5))
        set_md5 = hashlib.md5(str(md5_list)).hexdigest()
        self._store_work_results({'md5_list':md5_list}, 'sample_set', set_md5)
        return set_md5

Store a sample set (which is just a list of md5s).

Note: All md5s must already be in the data store.

Args:
md5_list: a list of the md5s in this set (all must exist in data store)

Returns:
The md5 of the set (the actual md5 of the set)


def run(self, xml, **kwargs):

        kwargs['output'] = self.__graph__()
        if isinstance(xml, str):
            try:
                self.source = etree.XML(xml)
            except ValueError:
                try:
                    self.source = etree.XML(xml.encode())
                except:
                    raise ValueError("Cannot run error {}".format(sys.exc_info()[0]))
        else:
            self.source = xml
        super(XMLProcessor, self).run(**kwargs)
        self.output = kwargs['output']
        return kwargs['output']

Method takes either an etree.ElementTree or raw XML text
as the first argument.

Args:
xml(etree.ElementTree or text


def parity(number):

    sval = -1
    if verbose:
        print(80*"*")
    try:
        assert number == int(round(number))
        m = Model()
        m.hideOutput()

        x = m.addVar("x", vtype="I", lb=None, ub=None)
        n = m.addVar("n", vtype="I", lb=None)
        s = m.addVar("s", vtype="B")

        m.addCons(x==number)

        m.addCons(s == x-2*n)
        m.setObjective(s)
        m.optimize()

        assert m.getStatus() == "optimal"
        boolmod = m.getVal(s) == m.getVal(x)%2
        if verbose:
            for v in m.getVars():
                print("%*s: %d" % (fmtlen, v,m.getVal(v)))
            print("%*d%%2 == %d?" % (fmtlen, m.getVal(x), m.getVal(s)))
            print("%*s" % (fmtlen, boolmod))

        xval = m.getVal(x)
        sval = m.getVal(s)
        sstr = sdic[sval]
        print("%*d is %s" % (fmtlen, xval, sstr))
    except (AssertionError, TypeError):
        print("%*s is neither even nor odd!" % (fmtlen, number.__repr__()))
    finally:
        if verbose:
            print(80*"*")
            print("")
    return sval

Prints if a value is even/odd/neither per each value in a example list

This example is made for newcomers and motivated by:
- modulus is unsupported for pyscipopt.scip.Variable and int
- variables are non-integer by default
Based on this: #172#issuecomment-394644046

Args:
number: value which parity is checked

Returns:
sval: 1 if number is odd, 0 if number is even, -1 if neither


def add_untagged(self, *responses: 'Response') -> None:

        for resp in responses:
            try:
                merge_key = resp.merge_key
            except TypeError:
                self._untagged.append(resp)
            else:
                key = (type(resp), merge_key)
                try:
                    untagged_idx = self._mergeable[key]
                except KeyError:
                    untagged_idx = len(self._untagged)
                    self._mergeable[key] = untagged_idx
                    self._untagged.append(resp)
                else:
                    merged = self._untagged[untagged_idx].merge(resp)
                    self._untagged[untagged_idx] = merged
        self._raw = None

Add an untagged response. These responses are shown before the
parent response.

Args:
responses: The untagged responses to add.


def partition(self, id_):

        from ..orm import Partition as OrmPartition
        from sqlalchemy import or_
        from ..identity import PartialPartitionName

        if isinstance(id_, PartitionIdentity):
            id_ = id_.id_
        elif isinstance(id_, PartialPartitionName):
            id_ = id_.promote(self.bundle.identity.name)

        session = self.bundle.dataset._database.session
        q = session\
            .query(OrmPartition)\
            .filter(OrmPartition.d_vid == self.bundle.dataset.vid)\
            .filter(or_(OrmPartition.id == str(id_).encode('ascii'),
                        OrmPartition.vid == str(id_).encode('ascii')))

        try:
            orm_partition = q.one()
            return self.bundle.wrap_partition(orm_partition)
        except NoResultFound:
            orm_partition = None

        if not orm_partition:
            q = session\
                .query(OrmPartition)\
                .filter(OrmPartition.d_vid == self.bundle.dataset.vid)\
                .filter(OrmPartition.name == str(id_).encode('ascii'))

            try:
                orm_partition = q.one()
                return self.bundle.wrap_partition(orm_partition)
            except NoResultFound:
                orm_partition = None

        return orm_partition

Get a partition by the id number.

Arguments:
id_ -- a partition id value

Returns:
A partitions.Partition object

Throws:
a Sqlalchemy exception if the partition either does not exist or
is not unique

Because this method works on the bundle, the id_ ( without version information )
is equivalent to the vid ( with version information )


def _OpenPathSpec(self, path_specification, ascii_codepage='cp1252'):
    if (not path_specification):
        return None
    file_entry = self._file_system.GetFileEntryByPathSpec(path_specification)
    if (file_entry is None):
        return None
    file_object = file_entry.GetFileObject()
    if (file_object is None):
        return None
    registry_file = dfwinreg_regf.REGFWinRegistryFile(ascii_codepage=ascii_codepage)
    try:
        registry_file.Open(file_object)
    except IOError as exception:
        logger.warning('Unable to open Windows Registry file with error: {0!s}'.format(exception))
        file_object.close()
        return None
    return registry_file

Opens the Windows Registry file specified by the path specification.

Args:
path_specification (dfvfs.PathSpec): path specification.
ascii_codepage (Optional[str]): ASCII string codepage.

Returns:
WinRegistryFile: Windows Registry file or None.


def fromcube(cube, template):
    array = dc.zeros_like(template)
    (y, x) = (array.y.values, array.x.values)
    (gy, gx) = (cube.y.values, cube.x.values)
    iy = interp1d(gy, np.arange(len(gy)))(y)
    ix = interp1d(gx, np.arange(len(gx)))(x)
    for ch in range(len(cube.ch)):
        array[(:, ch)] = map_coordinates(cube.values[(:, :, ch)], (ix, iy))
    return array

Covert a decode cube to a decode array.

Args:
cube (decode.cube): Decode cube to be cast.
template (decode.array): Decode array whose shape the cube is cast on.

Returns:
decode array (decode.array): Decode array.

Notes:
This functions is under development.


def invertible_flatten2_numpy(unflat_arrs, axis=0):
    cumlen_list = np.cumsum([arr.shape[axis] for arr in unflat_arrs])
    flat_list = np.concatenate(unflat_arrs, axis=axis)
    return (flat_list, cumlen_list)

more numpy version

TODO: move to vtool

Args:
unflat_arrs (list):  list of ndarrays

Returns:
tuple: (flat_list, cumlen_list)

CommandLine:
python -m utool.util_list --test-invertible_flatten2_numpy

Example:
>>> # ENABLE_DOCTET
>>> from utool.util_list import *  # NOQA
>>> unflat_arrs = [np.array([1, 2, 1]), np.array([5, 9]), np.array([4])]
>>> (flat_list, cumlen_list) = invertible_flatten2_numpy(unflat_arrs)
>>> result = str((flat_list, cumlen_list))
>>> print(result)
(array([1, 2, 1, 5, 9, 4]), array([3, 5, 6]))


def set_release_description(self, description, **kwargs):
    id = self.get_id().replace('/', '%2F')
    path = ('%s/%s/release' % (self.manager.path, id))
    data = {'description': description}
    if (self.release is None):
        try:
            server_data = self.manager.gitlab.http_post(path, post_data=data, **kwargs)
        except exc.GitlabHttpError as e:
            raise exc.GitlabCreateError(e.response_code, e.error_message)
    else:
        try:
            server_data = self.manager.gitlab.http_put(path, post_data=data, **kwargs)
        except exc.GitlabHttpError as e:
            raise exc.GitlabUpdateError(e.response_code, e.error_message)
    self.release = server_data

Set the release notes on the tag.

If the release doesn't exist yet, it will be created. If it already
exists, its description will be updated.

Args:
description (str): Description of the release.
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabCreateError: If the server fails to create the release
GitlabUpdateError: If the server fails to update the release


def load(fin, dtype=np.float32, max_vocab=None):
    vocab = {}
    arr = None
    i = 0
    for line in fin:
        if ((max_vocab is not None) and (i >= max_vocab)):
            break
        try:
            (token, v) = _parse_line(line, dtype)
        except (ValueError, IndexError):
            raise ParseError((b'Parsing error in line: ' + line))
        if (token in vocab):
            parse_warn((b'Duplicated vocabulary ' + token))
            continue
        if (arr is None):
            arr = np.array(v, dtype=dtype).reshape(1, (- 1))
        else:
            if (arr.shape[1] != len(v)):
                raise ParseError((b'Vector size did not match in line: ' + line))
            arr = np.append(arr, [v], axis=0)
        vocab[token] = i
        i += 1
    return (arr, vocab)

Load word embedding file.

Args:
fin (File): File object to read. File should be open for reading ascii.
dtype (numpy.dtype): Element data type to use for the array.
max_vocab (int): Number of vocabulary to read.

Returns:
numpy.ndarray: Word embedding representation vectors
dict: Mapping from words to vector indices.


def normal_mean(data, variance):
    if (not isinstance(data, np.ndarray)):
        data = np.array(data)
    i_variance_2 = (1 / (variance ** 2))
    cmm = [0.0]
    cmm.extend(np.cumsum(data))
    cmm2 = [0.0]
    cmm2.extend(np.cumsum(np.abs(data)))

    def cost(start, end):
        ' Cost function for normal distribution with variable mean\n\n        Args:\n            start (int): start index\n            end (int): end index\n        Returns:\n            float: Cost, from start to end\n        '
        cmm2_diff = (cmm2[end] - cmm2[start])
        cmm_diff = pow((cmm[end] - cmm[start]), 2)
        i_diff = (end - start)
        diff = (cmm2_diff - cmm_diff)
        return ((diff / i_diff) * i_variance_2)
    return cost

Creates a segment cost function for a time series with a
Normal distribution with changing mean

Args:
data (:obj:`list` of float): 1D time series data
variance (float): variance
Returns:
function: Function with signature
(int, int) -> float
where the first arg is the starting index, and the second
is the last arg. Returns the cost of that segment


def normalize(x, axis=-1, order=2):
    l2 = np.atleast_1d(np.linalg.norm(x, order, axis))
    l2[l2 == 0] = 1
    return x / np.expand_dims(l2, axis)

Normalizes a Numpy array.

Args:
x: Numpy array to normalize.
axis: axis along which to normalize.
order: Normalization order (e.g. `order=2` for L2 norm).

Returns:
A normalized copy of the array.


def _invalid_triple_quote(self, quote, row, col=None):
    self.add_message('invalid-triple-quote', line=row, args=(quote, TRIPLE_QUOTE_OPTS.get(self.config.triple_quote)), **self.get_offset(col))

Add a message for an invalid triple quote.

Args:
quote: The quote characters that were found.
row: The row number the quote characters were found on.
col: The column the quote characters were found on.


def __parse(self, raw_string):

        self._args = []

        def escape_braces(origin_string):
            return origin_string.replace("{", "{{").replace("}", "}}")

        try:
            match_start_position = raw_string.index("$", 0)
            begin_string = raw_string[0:match_start_position]
            self._string = escape_braces(begin_string)
        except ValueError:
            self._string = escape_braces(raw_string)
            return

        while match_start_position < len(raw_string):

            dollar_match = dolloar_regex_compile.match(raw_string, match_start_position)
            if dollar_match:
                match_start_position = dollar_match.end()
                self._string += "$"
                continue

            func_match = function_regex_compile.match(raw_string, match_start_position)
            if func_match:
                function_meta = parse_function_params(func_match.group(1))
                function_meta = {
                    "func_name": func_match.group(1)
                }
                function_meta.update(parse_function_params(func_match.group(2)))
                lazy_func = LazyFunction(
                    function_meta,
                    self.functions_mapping,
                    self.check_variables_set
                )
                self._args.append(lazy_func)
                match_start_position = func_match.end()
                self._string += "{}"
                continue

            var_match = variable_regex_compile.match(raw_string, match_start_position)
            if var_match:
                var_name = var_match.group(1) or var_match.group(2)

                if var_name not in self.check_variables_set:
                    raise exceptions.VariableNotFound(var_name)

                self._args.append(var_name)
                match_start_position = var_match.end()
                self._string += "{}"
                continue

            curr_position = match_start_position
            try:

                match_start_position = raw_string.index("$", curr_position+1)
                remain_string = raw_string[curr_position:match_start_position]
            except ValueError:
                remain_string = raw_string[curr_position:]

                match_start_position = len(raw_string)

            self._string += escape_braces(remain_string)

parse raw string, replace function and variable with {}

Args:
raw_string(str): string with functions or varialbes
e.g. "ABC${func2($a, $b)}DE$c"

Returns:
string: "ABC{}DE{}"
args: ["${func2($a, $b)}", "$c"]


def view(self, filename=None, directory=None, cleanup=False):
    return self.render(filename=filename, directory=directory, view=True, cleanup=cleanup)

Save the source to file, open the rendered result in a viewer.

Args:
filename: Filename for saving the source (defaults to ``name`` + ``'.gv'``)
directory: (Sub)directory for source saving and rendering.
cleanup (bool): Delete the source file after rendering.
Returns:
The (possibly relative) path of the rendered file.
Raises:
graphviz.ExecutableNotFound: If the Graphviz executable is not found.
subprocess.CalledProcessError: If the exit status is non-zero.
RuntimeError: If opening the viewer is not supported.

Short-cut method for calling :meth:`.render` with ``view=True``.