def endpoint_from_production_variants(self, name, production_variants, tags=None, kms_key=None, wait=True):
    if (not _deployment_entity_exists((lambda : self.sagemaker_client.describe_endpoint_config(EndpointConfigName=name)))):
        config_options = {'EndpointConfigName': name, 'ProductionVariants': production_variants}
        if tags:
            config_options['Tags'] = tags
        if kms_key:
            config_options['KmsKeyId'] = kms_key
        self.sagemaker_client.create_endpoint_config(**config_options)
    return self.create_endpoint(endpoint_name=name, config_name=name, tags=tags, wait=wait)

Create an SageMaker ``Endpoint`` from a list of production variants.

Args:
name (str): The name of the ``Endpoint`` to create.
production_variants (list[dict[str, str]]): The list of production variants to deploy.
tags (list[dict[str, str]]): A list of key-value pairs for tagging the endpoint (default: None).
kms_key (str): The KMS key that is used to encrypt the data on the storage volume attached
to the instance hosting the endpoint.
wait (bool): Whether to wait for the endpoint deployment to complete before returning (default: True).

Returns:
str: The name of the created ``Endpoint``.


def _render_our_module_key_flags(self, module, output_lines, prefix=''):

    key_flags = self.get_key_flags_for_module(module)
    if key_flags:
      self._render_module_flags(module, key_flags, output_lines, prefix)

Returns a help string for the key flags of a given module.

Args:
module: module|str, the module to render key flags for.
output_lines: [str], a list of strings.  The generated help message
lines will be appended to this list.
prefix: str, a string that is prepended to each generated help line.


def generate_output_events(self, source, key, val, line='2', hr=True, show_name=False, colorize=True):
    output = generate_output(line=line, short=(HR_RDAP[source][key]['_short'] if hr else key), name=(HR_RDAP[source][key]['_name'] if (hr and show_name) else None), is_parent=(False if ((val is None) or (len(val) == 0)) else True), value=('None' if ((val is None) or (len(val) == 0)) else None), colorize=colorize)
    if (val is not None):
        count = 0
        for item in val:
            try:
                action = item['action']
            except KeyError:
                action = None
            try:
                timestamp = item['timestamp']
            except KeyError:
                timestamp = None
            try:
                actor = item['actor']
            except KeyError:
                actor = None
            if (count > 0):
                output += generate_output(line=str((int(line) + 1)), is_parent=True, colorize=colorize)
            output += generate_output(line=str((int(line) + 1)), short=(HR_RDAP_COMMON[key]['action']['_short'] if hr else 'action'), name=(HR_RDAP_COMMON[key]['action']['_name'] if (hr and show_name) else None), value=action, colorize=colorize)
            output += generate_output(line=str((int(line) + 1)), short=(HR_RDAP_COMMON[key]['timestamp']['_short'] if hr else 'timestamp'), name=(HR_RDAP_COMMON[key]['timestamp']['_name'] if (hr and show_name) else None), value=timestamp, colorize=colorize)
            output += generate_output(line=str((int(line) + 1)), short=(HR_RDAP_COMMON[key]['actor']['_short'] if hr else 'actor'), name=(HR_RDAP_COMMON[key]['actor']['_name'] if (hr and show_name) else None), value=actor, colorize=colorize)
            count += 1
    return output

The function for generating CLI output RDAP events results.

Args:
source (:obj:`str`): The parent key 'network' or 'objects'
(required).
key (:obj:`str`): The event key 'events' or 'events_actor'
(required).
val (:obj:`dict`): The event dictionary (required).
line (:obj:`str`): The line number (0-4). Determines indentation.
Defaults to '0'.
hr (:obj:`bool`): Enable human readable key translations. Defaults
to True.
show_name (:obj:`bool`): Show human readable name (default is to
only show short). Defaults to False.
colorize (:obj:`bool`): Colorize the console output with ANSI
colors. Defaults to True.

Returns:
str: The generated output.


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

Create a new product.

Args:
name: name of the new product.

Returns:
A new product instance.


def emit(self, record):

    try:
      message = self.format(record)
      log_record = LogRecord(
          record.levelno, record.name, os.path.basename(record.pathname),
          record.lineno, int(record.created * 1000), message,
      )
      self._test_record.add_log_record(log_record)
      self._notify_update()
    except Exception:
      self.handleError(record)

Save a logging.LogRecord to our test record.

Logs carry useful metadata such as the logger name and level information.
We capture this in a structured format in the test record to enable
filtering by client applications.

Args:
record: A logging.LogRecord to record.


def is_custom_device(device_name):
    return context().is_custom_device(device_name)

Calls TFE_IsCustomDevice.

Enables using C extensions specifying a custom device from Python. See the
experimental eager C API in tensorflow/c/eager/c_api_experimental.h for
details.

Args:
device_name: A string indicating the name to check whether it is a
registered custom device.

Returns:
A boolean.


def read_excel(filename, dataset_class=dataset.pandas_dataset.PandasDataset, expectations_config=None, autoinspect_func=None, *args, **kwargs):
    df = pd.read_excel(filename, *args, **kwargs)
    if isinstance(df, dict):
        for key in df:
            df[key] = _convert_to_dataset_class(df[key], dataset_class, expectations_config, autoinspect_func)
    else:
        df = _convert_to_dataset_class(df, dataset_class, expectations_config, autoinspect_func)
    return df

Read a file using Pandas read_excel and return a great_expectations dataset.

Args:
filename (string): path to file to read
dataset_class (Dataset class): class to which to convert resulting Pandas df
expectations_config (string): path to great_expectations config file

Returns:
great_expectations dataset or ordered dict of great_expectations datasets,
if multiple worksheets are imported


def get_energy_tersoff(structure, gulp_cmd='gulp'):

    gio = GulpIO()
    gc = GulpCaller(gulp_cmd)
    gin = gio.tersoff_input(structure)
    gout = gc.run(gin)
    return gio.get_energy(gout)

Compute the energy of a structure using Tersoff potential.

Args:
structure: pymatgen.core.structure.Structure
gulp_cmd: GULP command if not in standard place


def run(self, input_dir, output_dir, epsilon):

    logging.info('Running attack %s', self.submission_id)
    tmp_run_dir = self.temp_copy_extracted_submission()
    cmd = ['--network=none',
           '-m=24g',
           '--cpus=3.75',
           '-v', '{0}:/input_images:ro'.format(input_dir),
           '-v', '{0}:/output_images'.format(output_dir),
           '-v', '{0}:/code'.format(tmp_run_dir),
           '-w', '/code',
           self.container_name,
           './' + self.entry_point,
           '/input_images',
           '/output_images',
           str(epsilon)]
    elapsed_time_sec = self.run_with_time_limit(cmd)
    sudo_remove_dirtree(tmp_run_dir)
    return elapsed_time_sec

Runs attack inside Docker.

Args:
input_dir: directory with input (dataset).
output_dir: directory where output (adversarial images) should be written.
epsilon: maximum allowed size of adversarial perturbation,
should be in range [0, 255].

Returns:
how long it took to run submission in seconds


def fn(x: tuple[int, str]):
    return x

Test function

Args:
x: The input

Returns:
The output


def MergeMessage(self, source, destination, replace_message_field=False, replace_repeated_field=False):
    tree = _FieldMaskTree(self)
    tree.MergeMessage(source, destination, replace_message_field, replace_repeated_field)

Merges fields specified in FieldMask from source to destination.

Args:
source: Source message.
destination: The destination message to be merged into.
replace_message_field: Replace message field if True. Merge message
field if False.
replace_repeated_field: Replace repeated field if True. Append
elements of repeated field if False.


def get_size_with_aspect_ratio(image_size, size, max_size=None) -> Tuple[int, int]:
    height, width = image_size
    raw_size = None
    if max_size is not None:
        min_original_size = float(min((height, width)))
        max_original_size = float(max((height, width)))
        if max_original_size / min_original_size * size > max_size:
            raw_size = max_size * min_original_size / max_original_size
            size = int(round(raw_size))
    if height <= width and height == size or (width <= height and width == size):
        oh, ow = (height, width)
    elif width < height:
        ow = size
        if max_size is not None and raw_size is not None:
            oh = int(raw_size * height / width)
        else:
            oh = int(size * height / width)
    else:
        oh = size
        if max_size is not None and raw_size is not None:
            ow = int(raw_size * width / height)
        else:
            ow = int(size * width / height)
    return (oh, ow)

Computes the output image size given the input image size and the desired output size.

Args:
image_size (`Tuple[int, int]`):
The input image size.
size (`int`):
The desired output size.
max_size (`int`, *optional*):
The maximum allowed output size.


def gunzip_file(infile, outfile=None, outdir=None, delete_original=False, force_rerun_flag=False):
    if (not outfile):
        outfile = infile.replace('.gz', '')
    if (not outdir):
        outdir = ''
    else:
        outdir = op.dirname(infile)
    outfile = op.join(outdir, op.basename(outfile))
    if force_rerun(flag=force_rerun_flag, outfile=outfile):
        gz = gzip.open(infile, 'rb')
        decoded = gz.read()
        with open(outfile, 'wb') as new_file:
            new_file.write(decoded)
        gz.close()
        log.debug('{}: file unzipped'.format(outfile))
    else:
        log.debug('{}: file already unzipped'.format(outfile))
    if delete_original:
        os.remove(infile)
    return outfile

Decompress a gzip file and optionally set output values.

Args:
infile: Path to .gz file
outfile: Name of output file
outdir: Path to output directory
delete_original: If original .gz file should be deleted
force_rerun_flag: If file should be decompressed if outfile already exists

Returns:
str: Path to decompressed file


def subtree(self, root_path: Union[int, str, KeyPath]) -> Optional['KeyPathSet']:
    root_path = KeyPath.from_value(root_path)
    if not root_path:
        return self
    root = self._trie
    for key in root_path.keys:
        if key not in root:
            return None
        root = root[key]
    ret = KeyPathSet()
    ret._trie = root
    return ret

Returns the relative paths of the sub-tree rooted at the given path.

Args:
root_path: A KeyPath for the root of the sub-tree.

Returns:
A KeyPathSet that contains all the child paths of the given root path.
Please note that the returned value share the same trie as the current
value. So addition/removal of paths in the returned value will also
affect the current value. If there is no child path under the given root
path, None will be returned.


def get_min_max_value(self) -> tuple[float, float]:
    return (self._statistics.min_max_statistics.global_min, self._statistics.min_max_statistics.global_max)

Calculates the global min and max values.

Returns:
(min_value, max_value): Min and max calculated using MinMax


def _ConvertInteger(value):

  if isinstance(value, float) and not value.is_integer():
    raise ParseError('Couldn\'t parse integer: {0}.'.format(value))

  if isinstance(value, six.text_type) and value.find(' ') != -1:
    raise ParseError('Couldn\'t parse integer: "{0}".'.format(value))

  return int(value)

Convert an integer.

Args:
value: A scalar value to convert.

Returns:
The integer value.

Raises:
ParseError: If an integer couldn't be consumed.


def asset(self, asset_id, asset_type, action='GET'):

        if not self.can_update():
            self._tcex.handle_error(910, [self.type])

        if asset_type == 'PHONE':
            return self.tc_requests.victim_phone_asset(
                self.api_type, self.api_sub_type, self.unique_id, asset_id, action=action
            )
        if asset_type == 'EMAIL':
            return self.tc_requests.victim_email_asset(
                self.api_type, self.api_sub_type, self.unique_id, asset_id, action=action
            )
        if asset_type == 'NETWORK':
            return self.tc_requests.victim_network_asset(
                self.api_type, self.api_sub_type, self.unique_id, asset_id, action=action
            )
        if asset_type == 'SOCIAL':
            return self.tc_requests.victim_social_asset(
                self.api_type, self.api_sub_type, self.unique_id, asset_id, action=action
            )
        if asset_type == 'WEB':
            return self.tc_requests.victim_web_asset(
                self.api_type, self.api_sub_type, self.unique_id, asset_id, action=action
            )
        self._tcex.handle_error(
            925, ['asset_type', 'asset', 'asset_type', 'asset_type', asset_type]
        )
        return None

Gets a asset of a Victim

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

Args:
asset_type:
asset_id:
action:

Returns:


def _embedding_lookup_for_sparse_tensor(inp: sparse_tensor.SparseTensor, weight: Optional[sparse_tensor.SparseTensor], table: tf_variables.Variable, feature: tpu_embedding_v2_utils.FeatureConfig) -> tensor.Tensor:
    inp_rank = inp.shape.rank
    if not feature.output_shape and feature.max_sequence_length > 0 and (inp_rank is None or inp_rank == 2):
        batch_size = math_ops.cast(array_ops.shape(inp)[0], dtype=dtypes.int64)
        sparse_shape = array_ops_stack.stack([batch_size, feature.max_sequence_length], axis=0)
        truncated_inp = sparse_ops.sparse_slice(inp, start=[0, 0], size=sparse_shape)
        dense_output_shape = array_ops_stack.stack([batch_size, feature.max_sequence_length, feature.table.dim], axis=0)
        return array_ops.scatter_nd(truncated_inp.indices, array_ops.gather(table.read_value(), truncated_inp.values), dense_output_shape)
    else:
        if feature.max_sequence_length > 0:
            logging.warning('max_sequence_length setting will be ignored because the rank of the input tensor is %d which is not 2.', inp_rank)
        if not feature.validate_weights_and_indices and inp_rank is not None and (inp_rank <= 2):
            return embedding_ops.embedding_lookup_sparse_v2(table, inp, sp_weights=weight, combiner=feature.table.combiner)
        else:
            return embedding_ops.safe_embedding_lookup_sparse_v2(table, inp, sparse_weights=weight, combiner=feature.table.combiner)

Embedding lookup for sparse tensor based on its feature config.

Args:
inp: a single SparseTensor input.
weight: None or SparseTensor which has the same shape of the input.
table: a table variable.
feature: a feature config.

Returns:
Embedding lookup result.


def MakeHistFromList(t, name=''):

    hist = Hist(name=name)
    [hist.Incr(x) for x in t]
    return hist

Makes a histogram from an unsorted sequence of values.

Args:
t: sequence of numbers
name: string name for this histogram

Returns:
Hist object


def kill_all_processes(self, check_alive=True, allow_graceful=False):
    if (ray_constants.PROCESS_TYPE_RAYLET in self.all_processes):
        self._kill_process_type(ray_constants.PROCESS_TYPE_RAYLET, check_alive=check_alive, allow_graceful=allow_graceful)
    for process_type in list(self.all_processes.keys()):
        self._kill_process_type(process_type, check_alive=check_alive, allow_graceful=allow_graceful)

Kill all of the processes.

Note that This is slower than necessary because it calls kill, wait,
kill, wait, ... instead of kill, kill, ..., wait, wait, ...

Args:
check_alive (bool): Raise an exception if any of the processes were
already dead.


def do_reset_ids(concatenated_meta_df, data_df, concat_direction):

    if concat_direction == "horiz":

        assert concatenated_meta_df.index.equals(data_df.columns), (
            "cids in concatenated_meta_df do not agree with cids in data_df.")

        reset_ids_in_meta_df(concatenated_meta_df)

        data_df.columns = pd.Index(concatenated_meta_df.index.values)

    elif concat_direction == "vert":

        assert concatenated_meta_df.index.equals(data_df.index), (
            "rids in concatenated_meta_df do not agree with rids in data_df.")

        reset_ids_in_meta_df(concatenated_meta_df)

        data_df.index = pd.Index(concatenated_meta_df.index.values)

Reset ids in concatenated metadata and data dfs to unique integers and
save the old ids in a metadata column.

Note that the dataframes are modified in-place.

Args:
concatenated_meta_df (pandas df)
data_df (pandas df)
concat_direction (string): 'horiz' or 'vert'

Returns:
None (dfs modified in-place)


def _manual_repartition(self, axis, repartition_func, **kwargs):

        func = self._prepare_method(repartition_func, **kwargs)
        return self.data.manual_shuffle(axis, func)

This method applies all manual partitioning functions.

Args:
axis: The axis to shuffle data along.
repartition_func: The function used to repartition data.

Returns:
A `BaseFrameManager` object.


def __init__(self, source_dict, url, path, token):

        self._vault_url = url
        self._path = path
        self._token = token
        super(VaultLoader, self).__init__(source_dict)

Initializer.

Args:
source_dict: used to initialize the class. Use constructors to read from Vault.
url: Vault url
path: Vault path where secrets are stored
vault_token: token (must have access to vault path)


def run_parallel(self, para_func):
    if self.timer:
        start_timer = time.time()
    with mp.Pool(self.num_processors) as pool:
        print('start pool with {} processors: {} total processes.\n'.format(self.num_processors, len(self.args)))
        results = [pool.apply_async(para_func, arg) for arg in self.args]
        out = [r.get() for r in results]
        out = {key: np.concatenate([out_i[key] for out_i in out]) for key in out[0].keys()}
    if self.timer:
        print('SNR calculation time:', (time.time() - start_timer))
    return out

Run parallel calulation

This will run the parallel calculation on self.num_processors.

Args:
para_func (obj): Function object to be used in parallel.

Returns:
(dict): Dictionary with parallel results.


def _encode_fhir_path_builder(self, builder: expressions.Builder) -> Optional[str]:
    try:
        sql_expression = self._bq_interpreter.encode(builder)
    except Exception as e:
        self._error_reporter.report_fhir_path_error(self._abs_path_invocation(builder), str(builder), self._error_message_for_exception(e))
        return None
    return sql_expression

Returns a Standard SQL translation of the constraint `fhir_path_expression`.

If an error is encountered during encoding, the associated error reporter
will be notified, and this method will return `None`.

Args:
builder: Builder containing the information to be encoded to Standard SQL.

Returns:
A Standard SQL encoding of the constraint `fhir_path_expression` upon
successful completion. The SQL will evaluate to a single boolean
indicating whether the constraint is satisfied.


def _read_metrics(repo, metrics, branch):
    res = {}
    for (out, typ, xpath) in metrics:
        assert (out.scheme == 'local')
        if (not typ):
            typ = os.path.splitext(out.path.lower())[1].replace('.', '')
        if out.use_cache:
            open_fun = open
            path = repo.cache.local.get(out.checksum)
        else:
            open_fun = repo.tree.open
            path = out.path
        try:
            with open_fun(path) as fd:
                metric = _read_metric(fd, typ=typ, xpath=xpath, rel_path=out.rel_path, branch=branch)
        except IOError as e:
            if (e.errno == errno.ENOENT):
                logger.warning(NO_METRICS_FILE_AT_REFERENCE_WARNING.format(out.rel_path, branch))
                metric = None
            else:
                raise
        if (not metric):
            continue
        res[out.rel_path] = metric
    return res

Read the content of each metric file and format it.

Args:
metrics (list): List of metric touples
branch (str): Branch to look up for metrics.

Returns:
A dict mapping keys with metrics path name and content.
For example:

{'metric.csv': ("value_mse  deviation_mse   data_set\n"
"0.421601   0.173461        train\n"
"0.67528    0.289545        testing\n"
"0.671502   0.297848        validation\n")}


def check_response_code(response, expected_response_code):
    if (response.status_code == expected_response_code):
        pass
    elif (response.status_code == RATE_LIMIT_RESPONSE_CODE):
        raise RateLimitError(response)
    else:
        raise ApiError(response)

Check response code against the expected code; raise ApiError.

Checks the requests.response.status_code against the provided expected
response code (erc), and raises a ApiError if they do not match.

Args:
response(requests.response): The response object returned by a request
using the requests package.
expected_response_code(int): The expected response code (HTTP response
code).

Raises:
ApiError: If the requests.response.status_code does not match the
provided expected response code (erc).


async def send_message(
        self, request: str, response_expected: bool, **kwargs: Any
    ) -> Response:

        with async_timeout.timeout(self.timeout):
            async with self.session.post(
                self.endpoint, data=request, ssl=self.ssl
            ) as response:
                response_text = await response.text()
                return Response(response_text, raw=response)

Transport the message to the server and return the response.

Args:
request: The JSON-RPC request string.
response_expected: Whether the request expects a response.

Returns:
A Response object.


def _handle_failure_and_recovery(self, e, on_failure_fn, on_transient_failure_fn, on_recovery_fn, worker_device_name):
    if on_failure_fn:
        on_failure_fn(e)
    with self._cluster_update_lock:
        self._cluster_due_for_update_or_finish.set()
        self._worker_up_cond.wait(_WORKER_MAXIMUM_RECOVERY_SEC)
        if self._error_from_recovery:
            try:
                raise self._error_from_recovery
            finally:
                self._error_from_recovery = None
        logging.info('Worker %s has been recovered.', worker_device_name)
    if on_recovery_fn:
        logging.info('Worker %s calling on_recovery_fn', worker_device_name)
        with self.wait_on_failure(on_recovery_fn=on_recovery_fn, on_transient_failure_fn=on_transient_failure_fn, worker_device_name=worker_device_name):
            on_recovery_fn()

Call failure fn, wait for cluster to recover, then call recovery fn.

Args:
e: the Exception thrown during closure execution.
on_failure_fn: an optional function to run if preemption happens.
on_transient_failure_fn: an optional function to run if transient failure
happens.
on_recovery_fn: an optional function to run when a worker is recovered
from preemption.
worker_device_name: the device name of the worker instance that is passing
through the failure.


def _GetDaysPerMonth(self, year, month):

    if month not in range(1, 13):
      raise ValueError('Month value out of bounds.')

    days_per_month = self._DAYS_PER_MONTH[month - 1]
    if month == 2 and self._IsLeapYear(year):
      days_per_month += 1

    return days_per_month

Retrieves the number of days in a month of a specific year.

Args:
year (int): year e.g. 1970.
month (int): month, where 1 represents January.

Returns:
int: number of days in the month.

Raises:
ValueError: if the month value is out of bounds.


def merge_json_fhir_string_into_proto(raw_json: str, target: message.Message, *, validate: bool=True, default_timezone: str=_primitive_time_utils.SIMPLE_ZULU) -> None:
    json_value = load_json(raw_json)
    merge_json_fhir_object_into_proto(json_value, target, validate=validate, default_timezone=default_timezone)

Merges the provided raw_json string into a target Message.

Args:
raw_json: The JSON to parse and merge into target.
target: The Message instance to merge raw_json into.
validate: A Boolean value indicating if validation should be performed on
the resultant Message. Validation takes the form of ensuring that basic
checks such as cardinality guarantees, required field adherence, etc. are
met. Defaults to True.
default_timezone: A string specifying the timezone string to use for time-
like FHIR data during parsing. Defaults to 'Z' for UTC.

Raises:
fhir_errors.InvalidFhirError: In the event that validation fails after
parsing.


def parse_cscore(infile):

    cscore_dict = {}

    with open(infile, 'r') as f:
        for ll in f.readlines():

            if ll.lower().startswith('model1'):
                l = ll.split()

                cscore = l[1]
                tmscore_full = l[2].split('+-')
                tmscore = tmscore_full[0]
                tmscore_err = tmscore_full[1]
                rmsd_full = l[3].split('+-')
                rmsd = rmsd_full[0]
                rmsd_err = rmsd_full[1]

                cscore_dict['c_score'] = float(cscore)
                cscore_dict['tm_score'] = float(tmscore)
                cscore_dict['tm_score_err'] = float(tmscore_err)
                cscore_dict['rmsd'] = float(rmsd)
                cscore_dict['rmsd_err'] = float(rmsd_err)

    return cscore_dict

Parse the cscore file to return a dictionary of scores.

Args:
infile (str): Path to cscore

Returns:
dict: Dictionary of scores


def process_attributes_of_node(attrs, node_name, class_type):
    attrs['_nodes'] = {}
    attrs['_linked_models'] = defaultdict(list)
    attrs['_debug_linked_models'] = defaultdict(list)
    attrs['_lazy_linked_models'] = defaultdict(list)
    attrs['_fields'] = {}
    attrs['_uniques'] = []
    for (key, attr) in list(attrs.items()):
        if (hasattr(attr, '__base__') and (getattr(attr.__base__, '_TYPE', '') in ['Node', 'ListNode'])):
            attrs['_nodes'][key] = attrs[key]
        else:
            attr_type = getattr(attr, '_TYPE', '')
            if (attr_type == 'Model'):
                attrs[('%s_id' % key)] = ''
                lnk_mdl_ins = attrs[key]
                lnk = {'null': (lnk_mdl_ins.null or (class_type == 'ListNode')), 'link_source': True, 'mdl': lnk_mdl_ins.__class__, 'o2o': lnk_mdl_ins._is_one_to_one, 'm2m': (class_type == 'ListNode'), 'reverse': lnk_mdl_ins.reverse_name, 'verbose': lnk_mdl_ins.verbose_name, 'field': key, 'is_set': False}
                attrs['_linked_models'][attr.__class__.__name__].append(lnk)
                debug_lnk = lnk.copy()
                debug_lnk['lnksrc'] = 'process_attributes_of_node'
                attrs['_debug_linked_models'][attr.__class__.__name__].append(debug_lnk)
            elif (attr_type == 'Field'):
                attr.name = key
                attrs['_fields'][key] = attr
                if attr.unique:
                    attrs['_uniques'].append(key)
            elif (attr_type == 'Link'):
                attrs[('%s_id' % key)] = ''
                lzy_lnk = attrs[key]
                attrs['_lazy_linked_models'][key].append({'from': node_name, 'to': lzy_lnk.link_to, 'o2o': lzy_lnk.one_to_one, 'verbose': lzy_lnk.verbose_name, 'reverse': lzy_lnk.reverse_name, 'field': key})

prepare the model fields, nodes and relations

Args:
node_name (str): name of the node we are currently processing
attrs (dict): attribute dict
class_type (str): Type of class.
Can be one of these: 'ListNode', 'Model', 'Node'


def serialize(self):
    lines = []
    for criterion in self.filter_criteria:
        lines.append(criterion.name())
        lines.append(criterion.serialize())
    return '\n'.join(lines)

Return a string representing the subview with all of its filter criteria.

Returns:
str: String with subview definition.


def __init__(self, channel):

    self.ListEntityTypes = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/ListEntityTypes',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.ListEntityTypesRequest.SerializeToString,
        response_deserializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.ListEntityTypesResponse.FromString,
        )
    self.GetEntityType = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/GetEntityType',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.GetEntityTypeRequest.SerializeToString,
        response_deserializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.EntityType.FromString,
        )
    self.CreateEntityType = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/CreateEntityType',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.CreateEntityTypeRequest.SerializeToString,
        response_deserializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.EntityType.FromString,
        )
    self.UpdateEntityType = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/UpdateEntityType',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.UpdateEntityTypeRequest.SerializeToString,
        response_deserializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.EntityType.FromString,
        )
    self.DeleteEntityType = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/DeleteEntityType',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.DeleteEntityTypeRequest.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
    self.BatchUpdateEntityTypes = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/BatchUpdateEntityTypes',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.BatchUpdateEntityTypesRequest.SerializeToString,
        response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )
    self.BatchDeleteEntityTypes = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/BatchDeleteEntityTypes',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.BatchDeleteEntityTypesRequest.SerializeToString,
        response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )
    self.BatchCreateEntities = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/BatchCreateEntities',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.BatchCreateEntitiesRequest.SerializeToString,
        response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )
    self.BatchUpdateEntities = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/BatchUpdateEntities',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.BatchUpdateEntitiesRequest.SerializeToString,
        response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )
    self.BatchDeleteEntities = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.EntityTypes/BatchDeleteEntities',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_entity__type__pb2.BatchDeleteEntitiesRequest.SerializeToString,
        response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def analyze(fqdn, result, argl, argd):
    package = fqdn.split('.')[0]
    if (package not in _methods):
        _load_methods(package)
    if ((_methods[package] is not None) and (fqdn in _methods[package])):
        return _methods[package][fqdn](fqdn, result, *argl, **argd)

Analyzes the result from calling the method with the specified FQDN.

Args:
fqdn (str): full-qualified name of the method that was called.
result: result of calling the method with `fqdn`.
argl (tuple): positional arguments passed to the method call.
argd (dict): keyword arguments passed to the method call.


def create_tensorboard_process(self):
    port = 6006
    for _ in range(100):
        p = subprocess.Popen(['tensorboard', '--logdir', self.logdir, '--host', 'localhost', '--port', str(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        self.event.wait(5)
        if p.poll():
            port += 1
        else:
            return (port, p)
    raise OSError('No available ports to start TensorBoard. Attempted all ports between 6006 and 6105')

Create a TensorBoard process.

Returns:
tuple: A tuple containing:
int: The port number.
process: The TensorBoard process.

Raises:
OSError: If no ports between 6006 and 6105 are available for starting TensorBoard.


def filter_children(self, ctype: ContentType = None) -> List[SchemaNode]:

        if ctype is None:
            ctype = self.content_type()
        return [c for c in self.children if
                not isinstance(c, (RpcActionNode, NotificationNode)) and
                c.content_type().value & ctype.value != 0]

Return receiver's children based on content type.

Args:
ctype: Content type.


def _child(details):

	if isinstance(details, list):

		return OptionsNode(details)

	elif isinstance(details, dict):

		if '__array__' in details:
			return ArrayNode(details)

		elif '__hash__' in details:
			return HashNode(details)

		elif '__type__' in details:

			if isinstance(details['__type__'], (dict,list)):
				return _child(details['__type__'])

			else:
				return Node(details)

		else:
			return Parent(details)

	elif isinstance(details, basestring):

		return Node(details)

	else:
		raise TypeError('details')

Child

A private function to figure out the child node type

Arguments:
details {dict} -- A dictionary describing a data point

Returns:
_NodeInterface


def reformat_to_pretty_xml(doc_xml):

    assert isinstance(doc_xml, str)
    dom_obj = xml.dom.minidom.parseString(doc_xml)
    pretty_xml = dom_obj.toprettyxml(indent='  ')

    return re.sub(r'^\s*$\n', r'', pretty_xml, flags=re.MULTILINE)

Pretty print XML doc.

Args:
doc_xml : str
Well formed XML doc

Returns:
str: Pretty printed XML doc


def filter_moving_count(self: EventSetOrNode, window_length: Duration) -> EventSetOrNode:
    from temporian.core.operators.filter_moving_count import filter_moving_count
    return filter_moving_count(self, window_length=window_length)

Filters out events such that no more than one output event is within
a tailing time window of `window_length`.

Filtering is applied in chronological order: An event received at time t
is filtered out if there is a non-filtered out event in
(t-window_length, t].

This operator is different from `(evset.moving_count(window_length)
== 0).filter()`. In `filter_moving_count` a filtered event does not
block following events.

Usage example:
```python
>>> a = tp.event_set(timestamps=[1, 2, 3])
>>> b = a.filter_moving_count(window_length=1.5)
>>> b
indexes: []
features: []
events:
(2 events):
timestamps: [1. 3.]
...

```

Returns:
EventSet without features with the filtered events.


def _pool(inputs, initial_value, reduce_fn, pool_size, strides=None, padding='valid'):
    if padding not in ('same', 'valid'):
        raise ValueError(f"Invalid padding '{padding}', must be 'same' or 'valid'.")
    padding = padding.upper()
    return np.array(lax.reduce_window(inputs, initial_value, reduce_fn, pool_size, strides, padding))

Helper function to define pooling functions.

Args:
inputs: input data of shape `N+2`.
initial_value: the initial value for the reduction.
reduce_fn: a reduce function of the form `(T, T) -> T`.
pool_size: a sequence of `N` integers, representing the window size to
reduce over.
strides: a sequence of `N` integers, representing the inter-window
strides (default: `(1, ..., 1)`).
padding: either the string `same` or `valid`.

Returns:
The output of the reduction for each window slice.


def parse_gene_panel(path, institute='cust000', panel_id='test', panel_type='clinical', date=datetime.now(),
                     version=1.0, display_name=None, genes = None):

    LOG.info("Parsing gene panel %s", panel_id)
    gene_panel = {}

    gene_panel['path'] = path
    gene_panel['type'] = panel_type
    gene_panel['date'] = date
    gene_panel['panel_id'] = panel_id
    gene_panel['institute'] = institute
    version = version or 1.0
    gene_panel['version'] = float(version)
    gene_panel['display_name'] = display_name or panel_id

    if not path:
        panel_handle = genes
    else:
        panel_handle = get_file_handle(gene_panel['path'])
    gene_panel['genes'] = parse_genes(gene_lines=panel_handle)

    return gene_panel

Parse the panel info and return a gene panel

Args:
path(str): Path to panel file
institute(str): Name of institute that owns the panel
panel_id(str): Panel id
date(datetime.datetime): Date of creation
version(float)
full_name(str): Option to have a long name

Returns:
gene_panel(dict)


def patch(self, payload, append_to_arrays=True):
    if (not isinstance(payload, dict)):
        raise ValueError("The 'payload' parameter must be provided a dictionary object.")
    payload = self.__class__.set_id_in_fkeys(payload)
    if append_to_arrays:
        for key in payload:
            val = payload[key]
            if (type(val) == list):
                val.extend(getattr(self, key))
                payload[key] = list(set(val))
    payload = self.check_boolean_fields(payload)
    payload = self.__class__.add_model_name_to_payload(payload)
    self.debug_logger.debug('PATCHING payload {}'.format(json.dumps(payload, indent=4)))
    res = requests.patch(url=self.record_url, json=payload, headers=HEADERS, verify=False)
    self.write_response_html_to_file(res, 'bob.html')
    res.raise_for_status()
    json_res = res.json()
    self.debug_logger.debug('Success')
    self.attrs = json_res
    return json_res

Patches current record and udpates the current instance's 'attrs'
attribute to reflect the new changes.

Args:
payload - hash. This will be JSON-formatted prior to sending the request.

Returns:
`dict`. The JSON formatted response.

Raises:
`requests.exceptions.HTTPError`: The status code is not ok.


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

        tstream = BytearrayStream()

        self.application_namespace.write(tstream, kmip_version=kmip_version)
        self.application_data.write(tstream, kmip_version=kmip_version)

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

Write the data encoding the ApplicationSpecificInformation 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 add_annotation(self, state_or_vector, text, **kwargs):
    if (isinstance(state_or_vector, (list, np.ndarray, tuple)) and (len(state_or_vector) == 3)):
        vec = state_or_vector
    else:
        raise Exception(('Position needs to be specified by a qubit ' + 'state or a 3D vector.'))
    self.annotations.append({'position': vec, 'text': text, 'opts': kwargs})

Add a text or LaTeX annotation to Bloch sphere,
parametrized by a qubit state or a vector.

Args:
state_or_vector (array_like):
Position for the annotation.
Qobj of a qubit or a vector of 3 elements.
text (str):
Annotation text.
You can use LaTeX, but remember to use raw string
e.g. r"$\\langle x \\rangle$"
or escape backslashes
e.g. "$\\\\langle x \\\\rangle$".
**kwargs:
Options as for mplot3d.axes3d.text, including:
fontsize, color, horizontalalignment, verticalalignment.
Raises:
Exception: If input not array_like or tuple.


def put(self, resource_json: Dict[str, Any], parent_bundle: Optional[Dict[str, Any]]=None) -> None:
    if parent_bundle is None:
        self.resources_by_uri[resource_json['url']] = resource_json
    else:
        self.resources_by_uri[resource_json['url']] = parent_bundle

Puts the given resource into this collection.

Adds the resource represented by `resource_json` found inside
`parent_bundle` into this collection for subsequent lookup via the Get
method. `parent_bundle` may be None if `resource_json` is not located inside
a bundle.

Args:
resource_json: The JSON object representing the resource.
parent_bundle: The bundle `resource_json` is located inside, if any.


def extract_images(self, f):

        print('Extracting', f.name)
        with gzip.GzipFile(fileobj=f) as bytestream:
            magic = self._read32(bytestream)
            if magic != 2051:
                raise ValueError('Invalid magic number %d in MNIST image file: %s' %
                                 (magic, f.name))
            num_images = self._read32(bytestream)
            rows = self._read32(bytestream)
            cols = self._read32(bytestream)
            buf = bytestream.read(rows * cols * num_images)
            data = np.frombuffer(buf, dtype=np.uint8)
            data = data.reshape(num_images, rows, cols, 1)
            return data

Extract the images into a 4D uint8 numpy array [index, y, x, depth].
Args:
f: A file object that can be passed into a gzip reader.
Returns:
data: A 4D unit8 numpy array [index, y, x, depth].
Raises:
ValueError: If the bytestream does not start with 2051.


def get_stream_action_type(stream_arn):
    stream_type_map = {'kinesis': awacs.kinesis.Action, 'dynamodb': awacs.dynamodb.Action}
    stream_type = stream_arn.split(':')[2]
    try:
        return stream_type_map[stream_type]
    except KeyError:
        raise ValueError(("Invalid stream type '%s' in arn '%s'" % (stream_type, stream_arn)))

Returns the awacs Action for a stream type given an arn

Args:
stream_arn (str): The Arn of the stream.

Returns:
:class:`awacs.aws.Action`: The appropriate stream type awacs Action
class

Raises:
ValueError: If the stream type doesn't match kinesis or dynamodb.


def __fill_buffer(self, size=0):
    read_size = min(max(size, self.__buffer_size), MAX_BLOB_FETCH_SIZE)
    self.__buffer = fetch_data(self.__blob_key, self.__position, ((self.__position + read_size) - 1))
    self.__buffer_position = 0
    self.__eof = (len(self.__buffer) < read_size)

Fills the internal buffer.

Args:
size: Number of bytes to read. Will be clamped to
[self.__buffer_size, MAX_BLOB_FETCH_SIZE].


def _peek(self, chars=1):

        line = self._socket.recv(chars, socket.MSG_PEEK)
        logger.debug('Server sent (peek): ' + line.rstrip())
        return line

Peek at the data in the server response.

Peeking should only be done when the response can be predicted.
Make sure that the socket will not block by requesting too
much data from it while peeking.

Args:
chars -- the number of characters to peek.


def subgroup_tile(cls, tile_assignment, subgroup_modes):
    if not isinstance(tile_assignment, _np.ndarray):
        raise TypeError('SubgroupTile assignment must be of type np.ndarray')
    if not isinstance(subgroup_modes, list):
        raise TypeError('subgroup_modes in subgroup manual must be of type list')
    if len(tile_assignment.shape) < len(subgroup_modes):
        raise TypeError('SubgroupTile assignment must have rank larger than length of subgroup_modes')
    for sharding_type in subgroup_modes:
        if sharding_type not in [xla_data_pb2.OpSharding.REPLICATED, xla_data_pb2.OpSharding.MANUAL]:
            raise TypeError('Each sharding_type in subgroup_modes in subgroup manual must be of type xla_data_pb2.OpSharding.REPLICATED or xla_data_pb2.OpSharding.MANUAL')
    dims = list(tile_assignment.shape)
    flattened_devices = tile_assignment.reshape(-1, order='C')
    return Sharding(proto=xla_data_pb2.OpSharding(type=xla_data_pb2.OpSharding.OTHER, tile_assignment_dimensions=dims, tile_assignment_devices=list(flattened_devices), last_tile_dims=list(subgroup_modes)))

Returns a subgroup manual sharding attribute.

This is similar to tile(), but tile_assignment has one or more dimension
than the tensor, and subgroup_modes define the sharding types in the last
dimensions of tile_assignment.

Args:
tile_assignment: An np.ndarray describing the topology of the tiling and
which device will compute which part of the topology.
subgroup_modes: sharding types for the dimension more than the tensor
shape rank.

Raises:
TypeError: tile_assignment was not of np.array type or subgroup_modes
has unsupported sharding type.


def all_tokens(self, delimiter=' '):
    tokens = set()
    for label in self:
        tokens = tokens.union(set(label.tokenized(delimiter=delimiter)))
    return tokens

Return a list of all tokens occurring in the label-list.

Args:
delimiter (str): The delimiter used to split labels into tokens
(see :meth:`audiomate.annotations.Label.tokenized`).

Returns:
:class:`set`: A set of distinct tokens.


def initialize(self):
    return self._initializer

Initialize underlying iterators.

Returns:
A list of any initializer ops that should be run.


def residual_block_v1(x, filters, kernel_size=3, stride=1, conv_shortcut=True, name=None):
    if backend.image_data_format() == 'channels_last':
        bn_axis = 3
    else:
        bn_axis = 1
    if conv_shortcut:
        shortcut = layers.Conv2D(4 * filters, 1, strides=stride, name=name + '_0_conv')(x)
        shortcut = layers.BatchNormalization(axis=bn_axis, epsilon=1.001e-05, name=name + '_0_bn')(shortcut)
    else:
        shortcut = x
    x = layers.Conv2D(filters, 1, strides=stride, name=name + '_1_conv')(x)
    x = layers.BatchNormalization(axis=bn_axis, epsilon=1.001e-05, name=name + '_1_bn')(x)
    x = layers.Activation('relu', name=name + '_1_relu')(x)
    x = layers.Conv2D(filters, kernel_size, padding='SAME', name=name + '_2_conv')(x)
    x = layers.BatchNormalization(axis=bn_axis, epsilon=1.001e-05, name=name + '_2_bn')(x)
    x = layers.Activation('relu', name=name + '_2_relu')(x)
    x = layers.Conv2D(4 * filters, 1, name=name + '_3_conv')(x)
    x = layers.BatchNormalization(axis=bn_axis, epsilon=1.001e-05, name=name + '_3_bn')(x)
    x = layers.Add(name=name + '_add')([shortcut, x])
    x = layers.Activation('relu', name=name + '_out')(x)
    return x

A residual block for ResNet*_v1.

Args:
x: Input tensor.
filters: No of filters in the bottleneck layer.
kernel_size: Kernel size of the bottleneck layer. Defaults to `3`.
stride: Stride of the first layer. Defaults to `1`.
conv_shortcut: Use convolution shortcut if `True`, otherwise
use identity shortcut. Defaults to `True`
name(optional): Name of the block

Returns:
Output tensor for the residual block.


def reorder_resources(self, resource_ids, hxl_update=True):
    dataset_id = self.data.get('id')
    if (not dataset_id):
        raise HDXError('Dataset has no id! It must be read, created or updated first.')
    data = {'id': dataset_id, 'order': resource_ids}
    self._write_to_hdx('reorder', data, 'package_id')
    if hxl_update:
        self.hxl_update()

Reorder resources in dataset according to provided list.
If only some resource ids are supplied then these are
assumed to be first and the other resources will stay in
their original order.

Args:
resource_ids (List[str]): List of resource ids
hxl_update (bool): Whether to call package_hxl_update. Defaults to True.

Returns:
None


def merge_and_fit(self, segment):

        self.points = sort_segment_points(self.points, segment.points)
        return self

Merges another segment with this one, ordering the points based on a
distance heuristic

Args:
segment (:obj:`Segment`): Segment to merge with
Returns:
:obj:`Segment`: self


def remove_item(self, item):

        for idx, _item in enumerate(self.items):
            if item == _item:
                del self.items[idx]
                return True
        return False

Remove the specified item from the menu.

Args:
item (MenuItem): the item to be removed.

Returns:
bool: True if the item was removed; False otherwise.


def __expand_meta_datas(meta_datas, meta_datas_expanded):
    if isinstance(meta_datas, dict):
        meta_datas_expanded.append(meta_datas)
    elif isinstance(meta_datas, list):
        for meta_data in meta_datas:
            __expand_meta_datas(meta_data, meta_datas_expanded)

expand meta_datas to one level

Args:
meta_datas (dict/list): maybe in nested format

Returns:
list: expanded list in one level

Examples:
>>> meta_datas = [
[
dict1,
dict2
],
dict3
]
>>> meta_datas_expanded = []
>>> __expand_meta_datas(meta_datas, meta_datas_expanded)
>>> print(meta_datas_expanded)
[dict1, dict2, dict3]


def UpdateChainAndProcess(self, parser_mediator, registry_key, **kwargs):
    parser_mediator.AppendToParserChain(self)
    try:
        self.Process(parser_mediator, registry_key, **kwargs)
    finally:
        parser_mediator.PopFromParserChain()

Updates the parser chain and processes a Windows Registry key or value.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.

Raises:
ValueError: If the Windows Registry key is not set.


def draw(self, filename, color=True):

        verify_dependencies(['pgv'])
        if not hasattr(self, '_results'):
            raise RuntimeError("Graph cannot be drawn before it is executed. "
                               "Try calling run() first.")

        g = pgv.AGraph(directed=True)
        g.node_attr['colorscheme'] = 'set312'

        for elem in self._results:
            if not hasattr(elem, 'history'):
                continue
            log = elem.history

            while log:

                source_from = log.parent[6] if log.parent else ''
                s_node = hash((source_from, log[2]))
                s_color = stim_list.index(log[2])
                s_color = s_color % 12 + 1

                t_node = hash((log[6], log[7]))
                t_style = 'filled,' if color else ''
                t_style += 'dotted' if log.implicit else ''
                if log[6].endswith('Extractor'):
                    t_color = '
                elif log[6].endswith('Filter'):
                    t_color = '
                else:
                    t_color = '

                r_node = hash((log[6], log[5]))
                r_color = stim_list.index(log[5])
                r_color = r_color % 12 + 1

                if color:
                    g.add_node(s_node, label=log[2], shape='ellipse',
                               style='filled', fillcolor=s_color)
                    g.add_node(t_node, label=log[6], shape='box',
                               style=t_style, fillcolor=t_color)
                    g.add_node(r_node, label=log[5], shape='ellipse',
                               style='filled', fillcolor=r_color)
                else:
                    g.add_node(s_node, label=log[2], shape='ellipse')
                    g.add_node(t_node, label=log[6], shape='box',
                               style=t_style)
                    g.add_node(r_node, label=log[5], shape='ellipse')

                g.add_edge(s_node, t_node, style=t_style)
                g.add_edge(t_node, r_node, style=t_style)
                log = log.parent

        g.draw(filename, prog='dot')

Render a plot of the graph via pygraphviz.

Args:
filename (str): Path to save the generated image to.
color (bool): If True, will color graph nodes based on their type,
otherwise will draw a black-and-white graph.


def update_script(self, script_body):

        uri = "{}/script".format(self.data['uri'])

        return self._helper.update(script_body, uri=uri)

Updates the configuration script of the enclosure-group with the specified URI.

Args:
id_or_uri: Resource id or resource uri.
script_body:  Configuration script.

Returns:
dict: Updated enclosure group.


def map(self, map_fn: Callable[..., _Tout], *trees: Tree[_Tin], is_leaf: Optional[LeafFn]=None) -> Tree[_Tout]:
    return self.backend.map(map_fn, *trees, is_leaf=is_leaf)

Same as `tree.map_structure`.

Args:
map_fn: Worker function
*trees: Nested input to pass to the `map_fn`
is_leaf: Don't recurse into leaf if `is_leaf(node)` is `True`

Returns:
The nested structure after `map_fn` has been applied.


def fit_effective_mass(distances, energies, parabolic=True):
    if parabolic:
        fit = np.polyfit(distances, energies, 2)
        c = (2 * fit[0])
    else:

        def f(x, alpha, d):
            top = (np.sqrt(((((4 * alpha) * d) * (x ** 2)) + 1)) - 1)
            bot = (2 * alpha)
            return (top / bot)
        bounds = ((1e-08, (- np.inf)), (np.inf, np.inf))
        (popt, _) = curve_fit(f, distances, energies, p0=[1.0, 1.0], bounds=bounds)
        c = (2 * popt[1])
    eff_mass = (((angstrom_to_bohr ** 2) / eV_to_hartree) / c)
    return eff_mass

Fit the effective masses using either a parabolic or nonparabolic fit.

Args:
distances (:obj:`numpy.ndarray`): The x-distances between k-points in
reciprocal Angstroms, normalised to the band extrema.
energies (:obj:`numpy.ndarray`): The band eigenvalues normalised to the
eigenvalue of the band extrema.
parabolic (:obj:`bool`, optional): Use a parabolic fit of the band
edges. If ``False`` then nonparabolic fitting will be attempted.
Defaults to ``True``.

Returns:
float: The effective mass in units of electron rest mass, :math:`m_0`.


def _GetAttributeContainerByIndex(self, container_type, index):
    sequence_number = (index + 1)
    query = 'SELECT _data FROM {0:s} WHERE rowid = {1:d}'.format(container_type, sequence_number)
    try:
        self._cursor.execute(query)
    except sqlite3.OperationalError as exception:
        raise IOError('Unable to query storage file with error: {0!s}'.format(exception))
    row = self._cursor.fetchone()
    if row:
        identifier = identifiers.SQLTableIdentifier(container_type, sequence_number)
        if (self.compression_format == definitions.COMPRESSION_FORMAT_ZLIB):
            serialized_data = zlib.decompress(row[0])
        else:
            serialized_data = row[0]
        if self._storage_profiler:
            self._storage_profiler.Sample('read', container_type, len(serialized_data), len(row[0]))
        attribute_container = self._DeserializeAttributeContainer(container_type, serialized_data)
        attribute_container.SetIdentifier(identifier)
        return attribute_container
    count = self._CountStoredAttributeContainers(container_type)
    index -= count
    serialized_data = self._GetSerializedAttributeContainerByIndex(container_type, index)
    attribute_container = self._DeserializeAttributeContainer(container_type, serialized_data)
    if attribute_container:
        identifier = identifiers.SQLTableIdentifier(container_type, sequence_number)
        attribute_container.SetIdentifier(identifier)
    return attribute_container

Retrieves a specific attribute container.

Args:
container_type (str): attribute container type.
index (int): attribute container index.

Returns:
AttributeContainer: attribute container or None if not available.

Raises:
IOError: when there is an error querying the storage file.
OSError: when there is an error querying the storage file.


def _runDecodeProtoTests(self, fields, case_sizes, batch_shape, batch, message_type, message_format, sanitize, force_disordered=False):
    if force_disordered:
        assert not sanitize
        extra_fields = test_example_pb2.ExtraFields()
        extra_fields.string_value = 'IGNORE ME'
        extra_fields.bool_value = False
        extra_msg = extra_fields.SerializeToString()
        batch = [extra_msg + msg for msg in batch]
    batch = np.array(batch, dtype=object)
    batch = np.reshape(batch, batch_shape)
    field_names = [f.name for f in fields]
    output_types = [f.dtype for f in fields]
    with self.cached_session() as sess:
        sizes, vtensor = self._decode_module.decode_proto(batch, message_type=message_type, field_names=field_names, output_types=output_types, message_format=message_format, sanitize=sanitize)
        vlist = sess.run([sizes] + vtensor)
        sizes = vlist[0]
        value_tensors = vlist[1:]
        self.assertTrue(np.all(np.array(sizes.shape) == batch_shape + [len(field_names)]))
        self.assertEqual(len(sizes.flat), len(case_sizes))
        self.assertTrue(np.all(sizes.flat == np.array(case_sizes, dtype=np.int32)))
        field_dict = dict(zip(field_names, value_tensors))
        self._compareProtos(batch_shape, sizes, fields, field_dict)

Run decode tests on a batch of messages.

Args:
fields: list of test_example_pb2.FieldSpec (types and expected values)
case_sizes: expected sizes array
batch_shape: the shape of the input tensor of serialized messages
batch: list of serialized messages
message_type: descriptor name for messages
message_format: format of messages, 'text' or 'binary'
sanitize: whether to sanitize binary protobuf inputs
force_disordered: whether to force fields encoded out of order.


def ReadManyFromPath(filepath):

  with io.open(filepath, mode="r", encoding="utf-8") as filedesc:
    return ReadManyFromFile(filedesc)

Reads a Python object stored in a specified YAML file.

Args:
filepath: A filepath to the YAML file.

Returns:
A Python data structure corresponding to the YAML in the given file.


def console_print(con: tcod.console.Console, x: int, y: int, fmt: str) -> None:

    lib.TCOD_console_printf(_console(con), x, y, _fmt(fmt))

Print a color formatted string on a console.

Args:
con (Console): Any Console instance.
x (int): Character x position from the left.
y (int): Character y position from the top.
fmt (AnyStr): A unicode or bytes string optionaly using color codes.

.. deprecated:: 8.5
Use :any:`Console.print_` instead.


def set_clbit(self, clbit, element):

        self.clbit_layer[self.cregs.index(clbit)] = element

Sets the clbit to the element
Args:
clbit (cbit): Element of self.cregs.
element (DrawElement): Element to set in the clbit


def auto_shard_dataset(dataset, num_shards, index, num_replicas_in_sync=None):
    if isinstance(dataset, distribute_types.DistributedDatasetInterface):
        return dataset.auto_shard(num_shards, index)
    if dataset.options().experimental_distribute.auto_shard_policy != AutoShardPolicy.OFF:
        if num_replicas_in_sync is None:
            num_replicas_in_sync = 1
        if isinstance(dataset, data_types.DatasetV1):
            return distribute._AutoShardDatasetV1(dataset, num_shards, index, num_replicas_in_sync)
        else:
            return distribute._AutoShardDataset(dataset, num_shards, index, num_replicas_in_sync)
    else:
        return dataset

Shard the input pipeline by sharding the underlying list of files.

Args:
dataset: A `tf.data.Dataset` instance, typically the result of a bunch of
dataset transformations.
num_shards: A `tf.int64` scalar `tf.Tensor`, representing the number of
shards operating in parallel. Same usage as in `tf.data.Dataset.shard`.
index: A `tf.int64` scalar `tf.Tensor`, representing the worker index.
Same usage as in `tf.data.Dataset.shard`.
num_replicas_in_sync: An integer representing the total number of replicas
across all workers. This is used in the rewrite when sharding by data.

Returns:
A modified `Dataset` obtained by updating the pipeline sharded by the
files. The input dataset will be returned if we cannot automatically
determine a good way to shard the input dataset.


def _maybe_download_corpora(tmp_dir, dataset_split):

  cnn_filename = "cnn_stories.tgz"
  cnn_finalpath = os.path.join(tmp_dir, "cnn/stories/")
  dailymail_filename = "dailymail_stories.tgz"
  dailymail_finalpath = os.path.join(tmp_dir, "dailymail/stories/")
  if not tf.gfile.Exists(cnn_finalpath):
    cnn_file = generator_utils.maybe_download_from_drive(
        tmp_dir, cnn_filename, _CNN_STORIES_DRIVE_URL)
    with tarfile.open(cnn_file, "r:gz") as cnn_tar:
      cnn_tar.extractall(tmp_dir)
  if not tf.gfile.Exists(dailymail_finalpath):
    dailymail_file = generator_utils.maybe_download_from_drive(
        tmp_dir, dailymail_filename, _DAILYMAIL_STORIES_DRIVE_URL)
    with tarfile.open(dailymail_file, "r:gz") as dailymail_tar:
      dailymail_tar.extractall(tmp_dir)

  cnn_files = tf.gfile.Glob(cnn_finalpath + "*")
  dailymail_files = tf.gfile.Glob(dailymail_finalpath + "*")
  all_files = cnn_files + dailymail_files

  if dataset_split == problem.DatasetSplit.TRAIN:
    urls_path = generator_utils.maybe_download(tmp_dir, "all_train.txt",
                                               _TRAIN_URLS)
  elif dataset_split == problem.DatasetSplit.EVAL:
    urls_path = generator_utils.maybe_download(tmp_dir, "all_val.txt",
                                               _DEV_URLS)
  else:
    urls_path = generator_utils.maybe_download(tmp_dir, "all_test.txt",
                                               _TEST_URLS)

  return all_files, urls_path

Download corpora if necessary and unzip them.

Args:
tmp_dir: directory containing dataset.
dataset_split: whether we're in train/dev/test mode.

Returns:
List of all files generated and path to file containing
train/dev/test split info.


def AddAnalysisReport(self, analysis_report):

    self._RaiseIfNotWritable()

    analysis_report = self._PrepareAttributeContainer(analysis_report)

    self.analysis_reports.append(analysis_report)

Adds an analysis report.

Args:
analysis_report (AnalysisReport): analysis report.

Raises:
IOError: when the storage writer is closed.
OSError: when the storage writer is closed.


def CompileFilter(self, filter_expression):
    filter_parser = pfilter.BaseParser(filter_expression).Parse()
    matcher = filter_parser.Compile(pfilter.PlasoAttributeFilterImplementation)
    self._filter_expression = filter_expression
    self._matcher = matcher

Compiles the filter expression.

The filter expression contains an object filter expression.

Args:
filter_expression (str): filter expression.

Raises:
ParseError: if the filter expression cannot be parsed.


def history(self, image):
    res = self._get(self._url('/images/{0}/history', image))
    return self._result(res, True)

Show the history of an image.

Args:
image (str): The image to show history for

Returns:
(str): The history of the image

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def run(self, data, max_epochs=1):

        self.state = State(dataloader=data, epoch=0, max_epochs=max_epochs, metrics={})

        try:
            self._logger.info("Engine run starting with max_epochs={}.".format(max_epochs))
            start_time = time.time()
            self._fire_event(Events.STARTED)
            while self.state.epoch < max_epochs and not self.should_terminate:
                self.state.epoch += 1
                self._fire_event(Events.EPOCH_STARTED)
                hours, mins, secs = self._run_once_on_dataset()
                self._logger.info("Epoch[%s] Complete. Time taken: %02d:%02d:%02d", self.state.epoch, hours, mins, secs)
                if self.should_terminate:
                    break
                self._fire_event(Events.EPOCH_COMPLETED)

            self._fire_event(Events.COMPLETED)
            time_taken = time.time() - start_time
            hours, mins, secs = _to_hours_mins_secs(time_taken)
            self._logger.info("Engine run complete. Time taken %02d:%02d:%02d" % (hours, mins, secs))

        except BaseException as e:
            self._logger.error("Engine run is terminating due to exception: %s.", str(e))
            self._handle_exception(e)

        return self.state

Runs the process_function over the passed data.

Args:
data (Iterable): Collection of batches allowing repeated iteration (e.g., list or `DataLoader`).
max_epochs (int, optional): max epochs to run for (default: 1).

Returns:
State: output state.


def union_of_bboxes(height, width, bboxes, erosion_rate=0.0, to_int=False):

    x1, y1 = width, height
    x2, y2 = 0, 0
    for b in bboxes:
        w, h = b[2] - b[0], b[3] - b[1]
        lim_x1, lim_y1 = b[0] + erosion_rate * w, b[1] + erosion_rate * h
        lim_x2, lim_y2 = b[2] - erosion_rate * w, b[3] - erosion_rate * h
        x1, y1 = np.min([x1, lim_x1]), np.min([y1, lim_y1])
        x2, y2 = np.max([x2, lim_x2]), np.max([y2, lim_y2])
    return x1, y1, x2, y2

Calculate union of bounding boxes.

Args:
height (float): Height of image or space.
width (float): Width of image or space.
bboxes (list): List like bounding boxes. Format is `[x_min, y_min, x_max, y_max]`.
erosion_rate (float): How much each bounding box can be shrinked, useful for erosive cropping.
Set this in range [0, 1]. 0 will not be erosive at all, 1.0 can make any bbox to lose its volume.


def register_proto_function(collection_name, proto_type=None, to_proto=None, from_proto=None) -> None:
    if to_proto and (not callable(to_proto)):
        raise TypeError('to_proto must be callable.')
    if from_proto and (not callable(from_proto)):
        raise TypeError('from_proto must be callable.')
    _proto_function_registry.register((proto_type, to_proto, from_proto), collection_name)

Registers `to_proto` and `from_proto` functions for collection_name.

`to_proto` function converts a Python object to the corresponding protocol
buffer, and returns the protocol buffer.

`from_proto` function converts protocol buffer into a Python object, and
returns the object..

Args:
collection_name: Name of the collection.
proto_type: Protobuf type, such as `saver_pb2.SaverDef`,
`variable_pb2.VariableDef`, `queue_runner_pb2.QueueRunnerDef`..
to_proto: Function that implements Python object to protobuf conversion.
from_proto: Function that implements protobuf to Python object conversion.


def _check_root_tag(self, root):
    supported = self.supported_tags()
    if (root.tag in supported):
        return
    error = 'Document root element ({0}) not one of ({1})'
    raise UnsupportedRootElementError(message=error.format(root.tag, supported), expected=supported, found=root.tag)

Check that the XML element tree has a supported root element.

Args:
root (etree.Element)

Raises:
UnsupportedRootElementError


def get_client(self, name):

        mech = self.get(name)
        return mech if isinstance(mech, ClientMechanism) else None

Like :meth:`.get`, but only mechanisms inheriting
:class:`ClientMechanism` will be returned.

Args:
name: The SASL mechanism name.

Returns:
The mechanism object or ``None``


def check_mailfy(self, query, kwargs={}):

        data = self.launchQueryForMode(query=query, mode="mailfy")
        if self._somethingFound(data, mode="mailfy"):
            return data
        return None

Verifying a mailfy query in this platform.

This might be redefined in any class inheriting from Platform. The only
condition is that any of this should return a dictionary as defined.

Args:
-----
query: The element to be searched.
kwargs: Dictionary with extra parameters. Just in case.

Return:
-------
Returns the collected data if exists or None if not.


def _run(broker, graph=None, root=None, context=None, inventory=None):
    if (not root):
        context = (context or HostContext)
        broker[context] = context()
        return dr.run(graph, broker=broker)
    if os.path.isdir(root):
        return process_dir(broker, root, graph, context, inventory=inventory)
    else:
        with extract(root) as ex:
            return process_dir(broker, ex.tmp_dir, graph, context, inventory=inventory)

run is a general interface that is meant for stand alone scripts to use
when executing insights components.

Args:
root (str): None will causes a host collection in which command and
file specs are run. A directory or archive path will cause
collection from the directory or archive, and only file type specs
or those that depend on `insights.core.context.HostArchiveContext`
will execute.
component (function or class): The component to execute. Will only execute
the component and its dependency graph. If None, all components with
met dependencies will execute.

Returns:
broker: object containing the result of the evaluation.


def get_params_and_defaults(param_list, db):

    return [[p, d] for p, d in db.get_all_values_of_all_params().items()]

Deduce [parameter, default] pairs from simulations available in the db.

Args:
param_list (list): List of parameters to query for.
db (DatabaseManager): Database where to query for defaults.


def _dedup_strings(device_strs):
    new_device_strs = []
    for device_str, vals in itertools.groupby(device_strs):
        num = len(list(vals))
        if num == 1:
            new_device_strs.append(device_str)
        else:
            new_device_strs.append('%s (x%d)' % (device_str, num))
    return new_device_strs

Groups together consecutive identical strings.

For example, given:
['GPU 1', 'GPU 2', 'GPU 2', 'GPU 3', 'GPU 3', 'GPU 3']
This function returns:
['GPU 1', 'GPU 2 (x2)', 'GPU 3 (x3)']

Args:
device_strs: A list of strings, each representing a device.

Returns:
A copy of the input, but identical consecutive strings are merged into a
single string.


def add_skip_connection(self, u, v, connection_type):

        if connection_type not in [self.CONCAT_CONNECT, self.ADD_CONNECT]:
            raise ValueError(
                "connection_type should be NetworkDescriptor.CONCAT_CONNECT "
                "or NetworkDescriptor.ADD_CONNECT."
            )
        self.skip_connections.append((u, v, connection_type))

Add a skip-connection to the descriptor.
Args:
u: Number of convolutional layers before the starting point.
v: Number of convolutional layers before the ending point.
connection_type: Must be either CONCAT_CONNECT or ADD_CONNECT.


def _send(self, line):

        if not line.endswith('\r\n'):
            if line.endswith('\n'):
                logger.debug('Fixing bare LF before sending data to socket')
                line = line[0:-1] + '\r\n'
            else:
                logger.debug(
                    'Fixing missing CRLF before sending data to socket')
                line = line + '\r\n'
        logger.debug('Client sent: ' + line.rstrip())
        self._socket.send(line)

Write a line of data to the server.

Args:
line -- A single line of data to write to the socket.


def get_paths(self, key):

        final_paths = []

        if key in self.__cli:
            paths = self.__cli[key] or []
            from_conf = False
        else:
            paths = self.__config.get(key) or []
            from_conf = True

        for path in flatten_list(paths):
            final_path = self.__abspath(path, from_conf)
            if final_path:
                final_paths.append(final_path)

        return final_paths

Same as `ConfigParser.get_path` for a list of paths.

Args:
key: str, the key to lookup the paths with

Returns:
list: The paths.


class PerceiverMultimodalPostprocessor(nn.Module):

    def __init__(self, modalities: Mapping[str, PostprocessorType], input_is_dict: bool=False):
        super().__init__()
        self.modalities = nn.ModuleDict(modalities)
        self.input_is_dict = input_is_dict

    def forward(self, inputs: torch.Tensor, pos: Optional[torch.Tensor]=None, modality_sizes=None) -> Mapping[str, torch.Tensor]:
        if not self.input_is_dict:
            if modality_sizes is None:
                raise ValueError('Modality sizes should be specified if input is not a dictionary.')
            inputs = restructure(modality_sizes=modality_sizes, inputs=inputs)
        outputs = {modality: postprocessor(inputs[modality], pos=pos, modality_sizes=None) for modality, postprocessor in self.modalities.items()}
        return outputs

Multimodal postprocessing for Perceiver. Can be used to combine modality-specific postprocessors into a single
postprocessor.

Args:
modalities (`Mapping[str, PostprocessorType]`):
Dictionary mapping modality name to postprocessor class for that modality.
input_is_dict (`bool`, *optional*, defaults to `False`):
If True, input is assumed to be dictionary structured, and outputs keep the same dictionary shape. If
False, input is a tensor which is sliced up during postprocessing by *modality_sizes*.


def __init__(self, filename, events=None):

        self.filename = os.path.abspath(filename)
        self.stat = os.stat(self.filename)
        self.start_datetime, self.end_datetime = None, None

        self._events = []
        self._events_by_baseclass = collections.defaultdict(list)

        if events is not None:
            for ev in events:
                self.append(ev)

List of ABINIT events.

Args:
filename: Name of the file
events: List of Event objects


def auto_forward(auto=True):

    global __auto_forward_state
    prev = __auto_forward_state
    __auto_forward_state = auto
    yield
    __auto_forward_state = prev

Context for dynamic graph execution mode.

Args:
auto (bool): Whether forward computation is executed during a
computation graph construction.

Returns: bool


def get_value(self, tau):
    tau = np.asarray(tau)
    (alpha_real, beta_real, alpha_complex_real, alpha_complex_imag, beta_complex_real, beta_complex_imag) = self.coefficients
    k = get_kernel_value(alpha_real, beta_real, alpha_complex_real, alpha_complex_imag, beta_complex_real, beta_complex_imag, tau.flatten())
    return np.asarray(k).reshape(tau.shape)

Compute the value of the term for an array of lags

Args:
tau (array[...]): An array of lags where the term should be
evaluated.

Returns:
The value of the term for each ``tau``. This will have the same
shape as ``tau``.


def _ParseHeader(self, format_type, value_data):
    data_type_map_name = self._HEADER_DATA_TYPE_MAP_NAMES.get(format_type, None)
    if (not data_type_map_name):
        raise errors.ParseError('Unsupported format type: {0:d}'.format(format_type))
    data_type_map = self._GetDataTypeMap(data_type_map_name)
    try:
        header = self._ReadStructureFromByteStream(value_data, 0, data_type_map)
    except (ValueError, errors.ParseError) as exception:
        raise errors.ParseError('Unable to parse header value with error: {0!s}'.format(exception))
    header_data_size = data_type_map.GetByteSize()
    if (format_type == self._FORMAT_TYPE_10):
        header_data_size = header.signature
    cache_header = AppCompatCacheHeader()
    cache_header.header_size = header_data_size
    cache_header.number_of_cached_entries = getattr(header, 'number_of_cached_entries', 0)
    return cache_header

Parses the header.

Args:
format_type (int): format type.
value_data (bytes): value data.

Returns:
AppCompatCacheHeader: header.

Raises:
ParseError: if the value data could not be parsed.


def seek(self, offset: int, whence: Literal[0, 1, 2]=0) -> int:

Changes the current position of the file.

Args:
offset: Offset from the position to a reference point.
whence: The reference point, with 0 meaning the beginning of the file,
1 meaning the current position, or 2 meaning the end of the file.

Returns:
The position from the beginning of the file.


def clear_signature_defs(tflite_model):
    model = tflite_model
    if not isinstance(tflite_model, bytearray):
        model = bytearray(tflite_model)
    return signature_def_util.ClearSignatureDefs(model)

Clears SignatureDefs from the Metadata of a TfLite flatbuffer buffer.

Args:
tflite_model: TFLite model buffer to remove signature_defs.

Returns:
buffer: A TFLite model binary identical to model buffer with
no SignatureDef metadata.

Raises:
ValueError:
tflite_model buffer does not contain a valid TFLite model.


def restore(self, state):

        self.storage.restore(state.get('storage'))

        dump_walker = state.get('dump_walker')
        if dump_walker is not None:
            dump_walker = self.storage.restore_walker(dump_walker)

        self.dump_walker = dump_walker
        self.next_id = state.get('next_id', 1)

Restore the state of this subsystem from a prior call to dump().

Calling restore must be properly sequenced with calls to other
subsystems that include stream walkers so that their walkers are
properly restored.

Args:
state (dict): The results of a prior call to dump().


def delete_user_role(self, user, role):
    self.project_service.set_auth(self._token_project)
    self.project_service.delete_user_role(user, role)

Remove role from given user.

Args:
user (string): User name.
role (string): Role to remove.

Raises:
requests.HTTPError on failure.


def _DefaultValueConstructorForField(field):
    if _IsMapField(field):
        return _GetInitializeDefaultForMap(field)
    if (field.label == _FieldDescriptor.LABEL_REPEATED):
        if (field.has_default_value and (field.default_value != [])):
            raise ValueError(('Repeated field default value not empty list: %s' % field.default_value))
        if (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE):
            message_type = field.message_type

            def MakeRepeatedMessageDefault(message):
                return containers.RepeatedCompositeFieldContainer(message._listener_for_children, field.message_type)
            return MakeRepeatedMessageDefault
        else:
            type_checker = type_checkers.GetTypeChecker(field)

            def MakeRepeatedScalarDefault(message):
                return containers.RepeatedScalarFieldContainer(message._listener_for_children, type_checker)
            return MakeRepeatedScalarDefault
    if (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE):
        message_type = field.message_type

        def MakeSubMessageDefault(message):
            result = message_type._concrete_class()
            result._SetListener((_OneofListener(message, field) if (field.containing_oneof is not None) else message._listener_for_children))
            return result
        return MakeSubMessageDefault

    def MakeScalarDefault(message):
        return field.default_value
    return MakeScalarDefault

Returns a function which returns a default value for a field.

Args:
field: FieldDescriptor object for this field.

The returned function has one argument:
message: Message instance containing this field, or a weakref proxy
of same.

That function in turn returns a default value for this field.  The default
value may refer back to |message| via a weak reference.


def _DocPackageFromTop(self, packages, showprivate=False, showinh=False):

        appIndex = ''
        if not isinstance(packages, list):
            packages = [packages]

        if os.path.exists('content'):
            shutil.rmtree('content')
        os.makedirs('content')

        appIndex += r % ('API Index')

        for i in range(len(packages)):

            package = packages[i]
            try:
                name = package.__displayname__
            except AttributeError:
                name = package.__name__

            path = 'content/%s' % package.__name__
            if os.path.exists(path):
                shutil.rmtree(path)
            os.makedirs(path)

            meta = 'About %s\n%s\n' % (name, '='*len('About ' + name))
            author = getattr(package, "__author__", None)
            license = getattr(package, "__license__", None)
            copyright = getattr(package, "__copyright__", None)
            version = getattr(package, "__version__", None)
            if author: meta += '\n* Author: %s' % author
            if license: meta += '\n* License: %s' % license
            if copyright: meta += '\n* Copyright: %s' % copyright
            if version: meta += '\n* Version: %s' % version
            about = '%s/%s' % (path, 'index.rst')

            this_toc = r % (name)

            this_toc += self._MakePackagePages(package, showprivate=showprivate, showinh=showinh)
            this_toc = this_toc.replace('%s/' % path, '')

            with open(about, 'w') as f:
                f.write('%s\n\n' % meta)
                if package.__doc__:
                    f.write(package.__doc__)
                f.write(this_toc)

            appIndex += '\n   %s' % about

        return appIndex

Generates all of the documentation for given packages and
appends new tocrees to the index. All documentation pages will be under the
set relative path.

Args:
packages (list(module)): A package or list of packages that contain submodules to document
showprivate (bool): A flag for whether or not to display private members

Returns:
str: The new content to append to the index


def _make_tensor_trace_fun(self, tensor_name, tensor_trace_order):

    def _print_tensor(tensor_name, num_elements, tensor, output_tensor):

        if self._parameters.is_brief_mode():
            if tensor_name not in tensor_trace_order.tensorname_to_cache_idx:
                raise ValueError('Tensor %s with name %s is not in the tensorname_to_cache_idx' % (tensor, tensor_name))
            msg = '%d' % tensor_trace_order.tensorname_to_cache_idx[tensor_name]
        else:
            msg = '"%s"' % tensor_name
        if self._parameters.trace_dir:
            output_path = os.path.join(self._parameters.trace_dir, _TRACE_FILE_NAME + self._get_outfile_suffix())
            output_stream = _OUTPUT_STREAM_ESCAPE + output_path
        else:
            output_stream = sys.stderr
        return logging_ops.print_v2(msg, array_ops.shape(output_tensor), '@', self._replica_id, '\n', output_tensor, '\n', summarize=num_elements, output_stream=output_stream)

    def _show_part_tensor(tensor):

        return _print_tensor(tensor_name, _TRACE_MODE_PART_TENSOR_SIZE, tensor, tensor)

    def _show_full_tensor(tensor):

        return _print_tensor(tensor_name, -1, tensor, tensor)
    if self._parameters.trace_mode == tensor_tracer_flags.TRACE_MODE_PART_TENSOR:
        return _show_part_tensor
    if self._parameters.trace_mode in (tensor_tracer_flags.TRACE_MODE_NAN_INF, tensor_tracer_flags.TRACE_MODE_NORM, tensor_tracer_flags.TRACE_MODE_FULL_TENSOR, tensor_tracer_flags.TRACE_MODE_MAX_ABS, tensor_tracer_flags.TRACE_MODE_SUMMARY, tensor_tracer_flags.TRACE_MODE_HISTORY):
        return _show_full_tensor
    raise RuntimeError('Full tensor support is not available with trace mode %s' % self._parameters.trace_mode)

Makes the tensor tracing function called by outside compilation.

Args:
tensor_name: name of the tensor being traced.
tensor_trace_order: TensorTraceOrder object holding tensorname to id map.
Returns:
A function to be passed as the first argument to outside compilation.

Raises:
RuntimeError: If the trace mode is invalid.


def delete_metadata(self, resource, keys):
    self.metadata_service.set_auth(self._token_metadata)
    self.metadata_service.delete(resource, keys)

Deletes the given key-value pairs associated with the given resource.

Will attempt to delete all key-value pairs even if some fail.

Args:
resource (intern.resource.boss.BossResource)
keys (list)

Raises:
HTTPErrorList on failure.


def returns_collection(return_type: FhirPathDataType) -> bool:
    return return_type and return_type.returns_collection()

Indicates if return_type will evaluate to a collection.

Args:
return_type: The data type to describe.

Returns:
True in the following circumstances
- `return_type` represents an element with cardinality greater than one.
- `return_type` represents an element with a cardinality less than or
equal to one, but that element is a child of a collection and will
evaluate to a collection. For example, the path Patient.name.use will
return a collection, despite 'use' being a scalar, because it is a child
of the collection, 'name.'
False if `return_type` represents a scalar element whose parents are all
also scalars.


def create(cls, endpoint_name, json_body, original_response):

        if endpoint_name == "property/value_report":
            return ValueReportResponse(endpoint_name, json_body, original_response)

        if endpoint_name == "property/rental_report":
            return RentalReportResponse(endpoint_name, json_body, original_response)

        prefix = endpoint_name.split("/")[0]

        if prefix == "block":
            return BlockResponse(endpoint_name, json_body, original_response)

        if prefix == "zip":
            return ZipCodeResponse(endpoint_name, json_body, original_response)

        if prefix == "msa":
            return MsaResponse(endpoint_name, json_body, original_response)

        return PropertyResponse(endpoint_name, json_body, original_response)

Factory for creating the correct type of Response based on the data.
Args:
endpoint_name (str) - The endpoint of the request, such as "property/value"
json_body - The response body in json format.
original_response (response object) - server response returned from an http request.


def podcasts(self, *, device_id=None):
    if (device_id is None):
        device_id = self.device_id
    podcast_list = []
    for chunk in self.podcasts_iter(device_id=device_id, page_size=49995):
        podcast_list.extend(chunk)
    return podcast_list

Get a listing of subsribed podcast series.

Paramaters:
device_id (str, Optional): A mobile device ID.
Default: Use ``device_id`` of the :class:`MobileClient` instance.

Returns:
list: Podcast series dict.


def index_file(self, f, overwrite=False):
    if isinstance(f, six.string_types):
        f = self.layout.get_file(f)
    if ((f.path in self.file_index) and (not overwrite)):
        return
    if ('suffix' not in f.entities):
        return
    md = self._get_metadata(f.path)
    for (md_key, md_val) in md.items():
        if (md_key not in self.key_index):
            self.key_index[md_key] = {}
        self.key_index[md_key][f.path] = md_val
        self.file_index[f.path][md_key] = md_val

Index metadata for the specified file.

Args:
f (BIDSFile, str): A BIDSFile or path to an indexed file.
overwrite (bool): If True, forces reindexing of the file even if
an entry already exists.


def GetEventFormatter(self, event):
    data_type = getattr(event, 'data_type', None)
    if (not data_type):
        return None
    return formatters_manager.FormattersManager.GetFormatterObject(event.data_type)

Retrieves the event formatter for a specific event type.

Args:
event (EventObject): event.

Returns:
EventFormatter: event formatter or None.


def getCard(self, name):

        cards = self.projectCards

        for card in cards:
            if card.name.upper() == name.upper():
                return card

        return None

Retrieve card object for given card name.

Args:
name (str): Name of card to be retrieved.

Returns:
:class:`.ProjectCard` or None: Project card object. Will return None if the card is not available.


def add_payload(self, key, val, append=False):

        if append:
            self._payload.setdefault(key, []).append(val)
        else:
            self._payload[key] = val

Add a key value pair to payload for this request.

Args:
key (str): The payload key.
val (str): The payload value.
append (bool, default:False): Indicate whether the value should be appended or
overwritten.


def assert_broadcastable(weights, values):
    with ops.name_scope(None, 'assert_broadcastable', (weights, values)) as scope:
        with ops.name_scope(None, 'weights', (weights,)) as weights_scope:
            weights = ops.convert_to_tensor(weights, name=weights_scope)
            weights_shape = array_ops.shape(weights, name='shape')
            weights_rank = array_ops.rank(weights, name='rank')
        weights_rank_static = tensor_util.constant_value(weights_rank)
        with ops.name_scope(None, 'values', (values,)) as values_scope:
            values = ops.convert_to_tensor(values, name=values_scope)
            values_shape = array_ops.shape(values, name='shape')
            values_rank = array_ops.rank(values, name='rank')
        values_rank_static = tensor_util.constant_value(values_rank)
        if weights_rank_static is not None and values_rank_static is not None:
            if weights_rank_static == 0:
                return control_flow_ops.no_op(name='static_scalar_check_success')
            if weights_rank_static != values_rank_static:
                raise ValueError(f'{_ASSERT_BROADCASTABLE_ERROR_PREFIX} values.rank={values_rank_static}. weights.rank={weights_rank_static}. values.shape={values.shape}. weights.shape={weights.shape}. Received weights={weights}, values={values}')
            weights_shape_static = tensor_util.constant_value(weights_shape)
            values_shape_static = tensor_util.constant_value(values_shape)
            if weights_shape_static is not None and values_shape_static is not None:
                ndims = len(values_shape_static)
                assert ndims == len(weights_shape_static)
                for i in range(ndims):
                    if weights_shape_static[i] not in (1, values_shape_static[i]):
                        raise ValueError(f'{_ASSERT_BROADCASTABLE_ERROR_PREFIX} Mismatch at dim {i}. values.shape={values_shape_static}, weights.shape={weights_shape_static}. Received weights={weights}, values={values}')
                return control_flow_ops.no_op(name='static_dims_check_success')
        is_scalar = math_ops.equal(0, weights_rank, name='is_scalar')
        data = (_ASSERT_BROADCASTABLE_ERROR_PREFIX, 'weights.shape=', weights.name, weights_shape, 'values.shape=', values.name, values_shape, 'is_scalar=', is_scalar)
        is_valid_shape = cond.cond(is_scalar, lambda: is_scalar, lambda: _has_valid_nonscalar_shape(weights_rank, weights_shape, values_rank, values_shape), name='is_valid_shape')
        return control_flow_assert.Assert(is_valid_shape, data, name=scope)

Asserts `weights` can be broadcast to `values`.

In `tf.losses` and `tf.metrics`, we support limited weight broadcasting. We
let weights be either scalar, or the same rank as the target values, with each
dimension either 1, or the same as the corresponding values dimension.

Args:
weights: `Tensor` of weights.
values: `Tensor` of values to which weights are applied.

Returns:
`Operation` raising `InvalidArgumentError` if `weights` has incorrect shape.
`no_op` if static checks determine `weights` has correct shape.

Raises:
ValueError:  If static checks determine `weights` has incorrect shape.


def _get_parser_call_method(self, parser_to_method):

    def inner_call(args=None, instance=None):
        'Allows to call the method invoked from the command line or\n            provided argument.\n\n            Args:\n                args: list of arguments to parse, defaults to command line\n                arguments\n                instance: an instance of the decorated class. If instance is\n                None, the default, and __init__ is decorated the object will be\n                instantiated on the fly from the command line arguments\n            '
        parser = self._cls.parser
        namespace = parser.parse_args(_get_args_to_parse(args, sys.argv))
        if (instance is None):
            if ('__init__' not in parser_to_method):
                raise ParseThisError("'__init__' method is not decorated. Please provide an instance to '{}.parser.call' or decorate the '__init___' method with 'create_parser'".format(self._cls.__name__))
            instance = _call_method_from_namespace(self._cls, '__init__', namespace)
        method_name = parser_to_method[namespace.method]
        return _call_method_from_namespace(instance, method_name, namespace)
    return inner_call

Return the parser special method 'call' that handles sub-command
calling.

Args:
parser_to_method: mapping of the parser registered name
to the method it is linked to


def forward(self, x):
    embeddings = self.embedding_convPxP(x).flatten(2)
    embeddings = nn.functional.pad(embeddings, (1, 0))
    embeddings = embeddings.permute(0, 2, 1)
    batch_size, sequence_length, embedding_dim = embeddings.shape
    embeddings = embeddings + self.positional_encoding_1d(batch_size, sequence_length, embedding_dim, device=embeddings.device, dtype=embeddings.dtype)
    for i in range(4):
        embeddings = self.transformer_encoder[i](embeddings)
    return embeddings

Forward pass

Args:
x (torch.Tensor - NCHW): Input feature tensor

Returns:
torch.Tensor - Transformer output embeddings of shape (batch_size, sequence_length, embedding_dim)


def _parent_info(self):
    parent_doc = self.parent
    if (parent_doc is None):
        parent_path = _helpers.DOCUMENT_PATH_DELIMITER.join((self._client._database_string, 'documents'))
    else:
        parent_path = parent_doc._document_path
    expected_prefix = _helpers.DOCUMENT_PATH_DELIMITER.join((parent_path, self.id))
    return (parent_path, expected_prefix)

Get fully-qualified parent path and prefix for this collection.

Returns:
Tuple[str, str]: Pair of

* the fully-qualified (with database and project) path to the
parent of this collection (will either be the database path
or a document path).
* the prefix to a document in this collection.


def build(X_df=None, y_df=None):
    if (X_df is None):
        (X_df, _) = load_data()
    if (y_df is None):
        (_, y_df) = load_data()
    features = get_contrib_features()
    mapper_X = ballet.feature.make_mapper(features)
    X = mapper_X.fit_transform(X_df)
    encoder_y = get_target_encoder()
    y = encoder_y.fit_transform(y_df)
    return {'X_df': X_df, 'features': features, 'mapper_X': mapper_X, 'X': X, 'y_df': y_df, 'encoder_y': encoder_y, 'y': y}

Build features and target

Args:
X_df (DataFrame): raw variables
y_df (DataFrame): raw target

Returns:
dict with keys X_df, features, mapper_X, X, y_df, encoder_y, y


def matmul_without_tf32(a, b, *args, **kwargs):
    if config.tensor_float_32_execution_enabled() and a.dtype == 'float32':
        a = math_ops.cast(a, 'float64')
        b = math_ops.cast(b, 'float64')
        ret = math_ops.matmul(a, b, *args, **kwargs)
        return math_ops.cast(ret, a.dtype)
    elif config.tensor_float_32_execution_enabled() and a.dtype == 'complex64':
        a = math_ops.cast(a, 'complex128')
        b = math_ops.cast(b, 'complex128')
        ret = math_ops.matmul(a, b, *args, **kwargs)
        return math_ops.cast(ret, a.dtype)
    else:
        return math_ops.matmul(a, b, *args, **kwargs)

Run matmul but cast float32 inputs to float64 if TensorFloat-32 is enabled.

This effectively runs matmul without TensorFloat-32. It should only be used in
tests when verifying some other op or functions works correctly, e.g. to test
`tf.linalg.sqrtm` by matrix multiplying the output of the op by itself. In
such cases, the matmul itself is not being tested so it's OK to run it with
higher precision.

If a matmul itself is being tested, or some other op which uses matmul, use
`run_without_tensor_float_32` instead.

This also casts complex64 inputs to complex128, since TensorFloat-32 can also
be used with complex64

Args:
a: First input to tf.linalg.matmul
b: Second input to tf.linalg.matmul
args: Other positional arguments to tf.linalg.matmul
**kwargs: Other keyword arguments to tf.linalg.matmul

Returns:
A tensor with the same type as `a`.


def output_sector_csv(self, csv_path, file_dict_key, out_path):
    csv_file = (csv_path + '{0}_{1}_{2}_{3}.csv'.format(file_dict_key, self.ensemble_name, self.member, self.run_date.strftime(self.date_format)))
    if exists(csv_file):
        csv_data = pd.read_csv(csv_file)
        if (self.inds is None):
            lon_obj = csv_data.loc[(:, 'Centroid_Lon')]
            lat_obj = csv_data.loc[(:, 'Centroid_Lat')]
            self.inds = np.where(((((self.ne_lat >= lat_obj) & (self.sw_lat <= lat_obj)) & (self.ne_lon >= lon_obj)) & (self.sw_lon <= lon_obj)))[0]
        if (np.shape(self.inds)[0] > 0):
            csv_data = csv_data.reindex(np.array(self.inds))
            sector_csv_filename = (out_path + '{0}_{1}_{2}_{3}.csv'.format(file_dict_key, self.ensemble_name, self.member, self.run_date.strftime(self.date_format)))
            print(('Output sector csv file ' + sector_csv_filename))
            csv_data.to_csv(sector_csv_filename, na_rep='nan', float_format='%0.5f', index=False)
            os.chmod(sector_csv_filename, 438)
        else:
            print('No {0} {1} sector data found'.format(self.member, self.run_date.strftime('%Y%m%d')))
    else:
        print('No {0} {1} csv file found'.format(self.member, self.run_date.strftime('%Y%m%d')))
    return

Segment forecast tracks to only output data contined within a
region in the CONUS, as defined by the mapfile.

Args:
csv_path(str): Path to the full CONUS csv file.
file_dict_key(str): Dictionary key for the csv files,
currently either 'track_step' or 'track_total'
out_path (str): Path to output new segmented csv files.
Returns:
Segmented forecast tracks in a csv file.


def slice_element_urls(element_definition: ElementDefinition) -> List[str]:
    result: List[str] = []
    if proto_utils.field_is_set(element_definition, 'type'):
        type_refs: List[StructureDefinition] = proto_utils.get_value_at_field(element_definition, 'type')
        profile_lists = [cast(Any, t).profile for t in type_refs]
        urls = [cast(Any, profile).value for profile in itertools.chain.from_iterable(profile_lists)]
        result.extend(urls)
    return result

Returns the list of profile urls for the given slice element.

Args:
element_definition: The `ElementDefinition` whose profile urls we are
retrieving.

Returns:
A list of strings representing the element's profile urls.


def _validate_alias_command_level(alias, command):
    alias_collision_table = AliasManager.build_collision_table([alias])
    if (not alias_collision_table):
        return
    command_collision_table = AliasManager.build_collision_table([command])
    alias_collision_levels = alias_collision_table.get(alias.split()[0], [])
    command_collision_levels = command_collision_table.get(command.split()[0], [])
    if (set(alias_collision_levels) & set(command_collision_levels)):
        raise CLIError(COMMAND_LVL_ERROR.format(alias, command))

Make sure that if the alias is a reserved command, the command that the alias points to
in the command tree does not conflict in levels.

e.g. 'dns' -> 'network dns' is valid because dns is a level 2 command and network dns starts at level 1.
However, 'list' -> 'show' is not valid because list and show are both reserved commands at level 2.

Args:
alias: The name of the alias.
command: The command that the alias points to.


def from_versions(cls, versions):

        range = cls(None)
        range.bounds = []
        for version in dedup(sorted(versions)):
            lower = _LowerBound(version, True)
            upper = _UpperBound(version, True)
            bound = _Bound(lower, upper)
            range.bounds.append(bound)
        return range

Create a range from a list of versions.

This method creates a range that contains only the given versions and
no other. Typically the range looks like (for eg) "==3|==4|==5.1".

Args:
versions: List of Version objects.

Returns:
`VersionRange` object.