def complete_acquaintance_strategy(qubit_order: Sequence[ops.Qid],
                                   acquaintance_size: int=0,
                                   ) -> circuits.Circuit:

    if acquaintance_size < 0:
        raise ValueError('acquaintance_size must be non-negative.')
    elif acquaintance_size == 0:
        return circuits.Circuit(device=UnconstrainedAcquaintanceDevice)

    if acquaintance_size > len(qubit_order):
        return circuits.Circuit(device=UnconstrainedAcquaintanceDevice)
    if acquaintance_size == len(qubit_order):
        return circuits.Circuit.from_ops(
                acquaint(*qubit_order), device=UnconstrainedAcquaintanceDevice)

    strategy = circuits.Circuit.from_ops(
            (acquaint(q) for q in qubit_order),
            device=UnconstrainedAcquaintanceDevice)
    for size_to_acquaint in range(2, acquaintance_size + 1):
        expose_acquaintance_gates(strategy)
        replace_acquaintance_with_swap_network(
                strategy, qubit_order, size_to_acquaint)
    return strategy

Returns an acquaintance strategy capable of executing a gate corresponding
to any set of at most acquaintance_size qubits.

Args:
qubit_order: The qubits on which the strategy should be defined.
acquaintance_size: The maximum number of qubits to be acted on by
an operation.

Returns:
An circuit capable of implementing any set of k-local
operation.


def softplus(x):
    return ops.softplus(x)

Softplus activation function.

It is defined as: `softplus(x) = log(exp(x) + 1)`.

Args:
x: Input tensor.


def get_dag(nodes, downstream_fn) -> Tuple[Dict, Dict]:

    dag = {}
    node_by_ids = {}
    for node in nodes:
        downstream_ops = downstream_fn(node)
        dag[node.id] = set(downstream_ops)
        node_by_ids[node.id] = node

    return dag, node_by_ids

Return a dag representation of the nodes passed.

This is equally used for pipelines and pipeline runs.

Params:
nodes: an instance of `Operation` | `OperationRun` the nodes to represent en dag.
downstream_fn: a function that returns the downstream nodes of the a node.

Returns:
tuple: (dag, dict(node_id: node))


def GetDisplayName(self, file_entry=None):

    if file_entry is None:
      file_entry = self._file_entry

    if file_entry is None:
      raise ValueError('Missing file entry')

    path_spec = getattr(file_entry, 'path_spec', None)

    relative_path = path_helper.PathHelper.GetRelativePathForPathSpec(
        path_spec, mount_path=self._mount_path)
    if not relative_path:
      return file_entry.name

    return self.GetDisplayNameForPathSpec(path_spec)

Retrieves the display name for a file entry.

Args:
file_entry (Optional[dfvfs.FileEntry]): file entry object, where None
will return the display name of self._file_entry.

Returns:
str: human readable string that describes the path to the file entry.

Raises:
ValueError: if the file entry is missing.


def create_frames(until=None):
    now = Date.now()
    if until:
        get_orbit(until, now)
    else:
        for body in list_bodies():
            get_orbit(body.name, now)

Create frames available in the JPL files

Args:
until (str): Name of the body you want to create the frame of, and all frames in between.
If ``None`` all the frames available in the .bsp files will be created

Example:

.. code-block:: python

# All frames between Earth and Mars are created (Earth, EarthBarycenter,
# SolarSystemBarycenter, MarsBarycenter and Mars)
create_frames(until='Mars')

# All frames between Earth and Phobos are created (Earth, EarthBarycenter,
# SolarSystemBarycenter, MarsBarycenter and Phobos)
create_frames(until='Phobos')

# All frames available in the .bsp files are created
create_frames()


def uniprot_reviewed_checker_batch(uniprot_ids):

    uniprot_ids = ssbio.utils.force_list(uniprot_ids)

    invalid_ids = [i for i in uniprot_ids if not is_valid_uniprot_id(i)]
    uniprot_ids = [i for i in uniprot_ids if is_valid_uniprot_id(i)]

    if invalid_ids:
        warnings.warn("Invalid UniProt IDs {} will be ignored".format(invalid_ids))

    Nmax = 200
    N, rest = divmod(len(uniprot_ids), Nmax)

    uni_rev_dict = {}

    if rest > 0:
        N += 1
    for i in range(0, N):
        i1 = i * Nmax
        i2 = (i + 1) * Nmax
        if i2 > len(uniprot_ids):
            i2 = len(uniprot_ids)

        query = uniprot_ids[i1:i2]

        query_string = ''
        for x in query:
            query_string += 'id:' + x + '+OR+'
        query_string = query_string.strip('+OR+')

        uni_rev_raw = StringIO(bsup.search(query_string, columns='id,reviewed', frmt='tab'))
        uni_rev_df = pd.read_table(uni_rev_raw, sep='\t', index_col=0)
        uni_rev_df = uni_rev_df.fillna(False)

        uni_rev_df = uni_rev_df[pd.notnull(uni_rev_df.Status)]

        uni_rev_df = uni_rev_df.replace(to_replace="reviewed", value=True)
        uni_rev_df = uni_rev_df.replace(to_replace="unreviewed", value=False)
        uni_rev_dict_adder = uni_rev_df.to_dict()['Status']
        uni_rev_dict.update(uni_rev_dict_adder)

    return uni_rev_dict

Batch check if uniprot IDs are reviewed or not

Args:
uniprot_ids: UniProt ID or list of UniProt IDs

Returns:
A dictionary of {UniProtID: Boolean}


def probability_density(self, X):
    self.check_fit()
    return norm.pdf(X, loc=self.mean, scale=self.std)

Compute probability density.

Arguments:
X: `np.ndarray` of shape (n, 1).

Returns:
np.ndarray


def get_reference(root):

    reference = {}
    elem = root.find('bibliographyLink')
    if elem is None:
        raise MissingElementError('bibliographyLink')

    ref_doi = elem.get('doi', None)
    ref_key = elem.get('preferredKey', None)

    if ref_doi is not None:
        try:
            ref = crossref_api.works(ids=ref_doi)['message']
        except (HTTPError, habanero.RequestError, ConnectionError):
            if ref_key is None:
                raise KeywordError('DOI not found and preferredKey attribute not set')
            else:
                warn('Missing doi attribute in bibliographyLink or lookup failed. '
                     'Setting "detail" key as a fallback; please update to the appropriate fields.'
                     )
                reference['detail'] = ref_key
                if reference['detail'][-1] != '.':
                    reference['detail'] += '.'
        else:
            if ref_key is not None:
                warn('Using DOI to obtain reference information, rather than preferredKey.')
            reference['doi'] = elem.attrib['doi']

            reference['journal'] = ref.get('container-title')[0]
            ref_year = ref.get('published-print') or ref.get('published-online')
            reference['year'] = int(ref_year['date-parts'][0][0])
            reference['volume'] = int(ref.get('volume'))
            reference['pages'] = ref.get('page')
            reference['authors'] = []
            for author in ref['author']:
                auth = {}
                auth['name'] = ' '.join([author['given'], author['family']])

                orcid = author.get('ORCID')
                if orcid:
                    auth['ORCID'] = orcid.lstrip('http:
                reference['authors'].append(auth)

    elif ref_key is not None:
        warn('Missing doi attribute in bibliographyLink. '
             'Setting "detail" key as a fallback; please update to the appropriate fields.'
             )
        reference['detail'] = ref_key
        if reference['detail'][-1] != '.':
            reference['detail'] += '.'
    else:

        raise MissingAttributeError('preferredKey', 'bibliographyLink')

    return reference

Read reference info from root of ReSpecTh XML file.

Args:
root (`~xml.etree.ElementTree.Element`): Root of ReSpecTh XML file

Returns:
properties (`dict`): Dictionary with reference information


def __valueKeyWithHeaderIndex(self, values):
    machingIndexes = {}
    for (index, name) in enumerate(self.header):
        if (name in values):
            machingIndexes[index] = values[name]
    return machingIndexes

This is hellper function, so that we can mach decision values with row index
as represented in header index.

Args:
values (dict): Normaly this will have dict of header values and values from decision

Return:
>>> return()
{
values[headerName] : int(headerName index in header array),
...
}


def set_record(self, name, record_id, record):

        if name not in self._cache:
            self._cache[name] = {}
        self._cache[name][record_id] = record

Save a record into the cache.

Args:
name (string): The name to save the model under.
record_id (int): The record id.
record (:class:`cinder_data.model.CinderModel`): The model


def cost(self, t_node, branch_length, multiplicity=2.0):
    merger_time = (t_node + branch_length)
    return ((self.integral_merger_rate(merger_time) - self.integral_merger_rate(t_node)) - ((np.log(self.total_merger_rate(merger_time)) * (multiplicity - 1.0)) / multiplicity))

returns the cost associated with a branch starting at t_node
t_node is time before present, the branch goes back in time

Args:
- t_node:           time of the node
- branch_length:    branch length, determines when this branch merges with sister
- multiplicity:     2 if merger is binary, higher if this is a polytomy


def has_implicit_access_to_catalog(user, obj):
    request = get_request_or_stub()
    decoded_jwt = get_decoded_jwt_from_request(request)
    return request_user_has_implicit_access_via_jwt(decoded_jwt, ENTERPRISE_CATALOG_ADMIN_ROLE, obj)

Check that if request user has implicit access to `ENTERPRISE_CATALOG_ADMIN_ROLE` feature role.

Returns:
boolean: whether the request user has access or not


def dispatch(self, inp):

    inp = tf.reshape(inp, [self._batch * self._length, -1])

    ret = tf.gather(inp, self._flat_indices)
    return ret

Send the inputs to the experts.

Args:
inp: a `Tensor` of shape "[batch, length, depth]`
Returns:
a tensor with shape [batch, num_experts, expert_capacity, depth]


def __rmtree(path):

    logger.info("rmtree: %s" % path)
    try:
        shutil.rmtree(path)
        return True
    except Exception as e:
        logger.error("rmtree: %s failed! Error: %s" % (path, e))
        return False

Recursively delete a directory tree.

Args:
path (str): Path to the directory that needs to be deleted.

Returns:
bool: True if the operation is successful, False otherwise.


def pop_events(self, regex_pattern, timeout):
    if (not self.started):
        raise IllegalStateError('Dispatcher needs to be started before popping.')
    deadline = (time.time() + timeout)
    while True:
        results = self._match_and_pop(regex_pattern)
        if ((len(results) != 0) or (time.time() > deadline)):
            break
        time.sleep(1)
    if (len(results) == 0):
        raise queue.Empty('Timeout after {}s waiting for event: {}'.format(timeout, regex_pattern))
    return sorted(results, key=(lambda event: event['time']))

Pop events whose names match a regex pattern.

If such event(s) exist, pop one event from each event queue that
satisfies the condition. Otherwise, wait for an event that satisfies
the condition to occur, with timeout.

Results are sorted by timestamp in ascending order.

Args:
regex_pattern: The regular expression pattern that an event name
should match in order to be popped.
timeout: Number of seconds to wait for events in case no event
matching the condition exits when the function is called.

Returns:
Events whose names match a regex pattern.
Empty if none exist and the wait timed out.

Raises:
IllegalStateError: Raised if pop is called before the dispatcher
starts polling.
queue.Empty: Raised if no event was found before time out.


def __init__(self, cronfile):

        options = Options()
        options.day_of_week_start_index_zero = False
        options.use_24hour_time_format = True
        with open(cronfile) as f:
            for line in f.readlines():
                parsed_line = self.parse_cron_line(line)
                if parsed_line:
                    print("{} -> {}".format(parsed_line, ExpressionDescriptor(parsed_line, options)))

Initialize CrontabReader

Args:
cronfile: Path to cronfile
Returns:
None


def is_variable_initialized(variable):
    from tensorflow.python.ops import state_ops
    return state_ops.is_variable_initialized(variable)

Tests if a variable has been initialized.

Args:
variable: A `Variable`.

Returns:
Returns a scalar boolean Tensor, `True` if the variable has been
initialized, `False` otherwise.


def get_region_vcf(self, case_obj, chrom=None, start=None, end=None, gene_obj=None, variant_type='clinical', category='snv', rank_threshold=None):
    rank_threshold = (rank_threshold or (- 100))
    variant_file = None
    if (variant_type == 'clinical'):
        if (category == 'snv'):
            variant_file = case_obj['vcf_files'].get('vcf_snv')
        elif (category == 'sv'):
            variant_file = case_obj['vcf_files'].get('vcf_sv')
        elif (category == 'str'):
            variant_file = case_obj['vcf_files'].get('vcf_str')
    elif (variant_type == 'research'):
        if (category == 'snv'):
            variant_file = case_obj['vcf_files'].get('vcf_snv_research')
        elif (category == 'sv'):
            variant_file = case_obj['vcf_files'].get('vcf_sv_research')
    if (not variant_file):
        raise SyntaxError('Vcf file does not seem to exist')
    vcf_obj = VCF(variant_file)
    region = ''
    if gene_obj:
        chrom = gene_obj['chromosome']
        start = gene_obj['start']
        end = gene_obj['end']
    if chrom:
        if (start and end):
            region = '{0}:{1}-{2}'.format(chrom, start, end)
        else:
            region = '{0}'.format(chrom)
    else:
        rank_threshold = (rank_threshold or 5)
    with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp:
        file_name = str(pathlib.Path(temp.name))
        for header_line in vcf_obj.raw_header.split('\n'):
            if (len(header_line) > 3):
                temp.write((header_line + '\n'))
        for variant in vcf_obj(region):
            temp.write(str(variant))
    return file_name

Produce a reduced vcf with variants from the specified coordinates
This is used for the alignment viewer.

Args:
case_obj(dict): A case from the scout database
variant_type(str): 'clinical' or 'research'. Default: 'clinical'
category(str): 'snv' or 'sv'. Default: 'snv'
rank_threshold(float): Only load variants above this score. Default: 5
chrom(str): Load variants from a certain chromosome
start(int): Specify the start position
end(int): Specify the end position
gene_obj(dict): A gene object from the database

Returns:
file_name(str): Path to the temporary file


def parse_text(text):
    span_dict = collections.defaultdict(list)
    for match in _NUMBER_PATTERN.finditer(text):
        span_text = text[match.start():match.end()]
        number = _parse_number(span_text)
        if number is not None:
            span_dict[match.span()].append(_get_numeric_value_from_float(number))
    for begin_index, end_index in get_all_spans(text, max_ngram_length=1):
        if (begin_index, end_index) in span_dict:
            continue
        span_text = text[begin_index:end_index]
        number = _parse_number(span_text)
        if number is not None:
            span_dict[begin_index, end_index].append(_get_numeric_value_from_float(number))
        for number, word in enumerate(_NUMBER_WORDS):
            if span_text == word:
                span_dict[begin_index, end_index].append(_get_numeric_value_from_float(float(number)))
                break
        for number, word in enumerate(_ORDINAL_WORDS):
            if span_text == word:
                span_dict[begin_index, end_index].append(_get_numeric_value_from_float(float(number)))
                break
    for begin_index, end_index in get_all_spans(text, max_ngram_length=_MAX_DATE_NGRAM_SIZE):
        span_text = text[begin_index:end_index]
        date = _parse_date(span_text)
        if date is not None:
            span_dict[begin_index, end_index].append(date)
    spans = sorted(span_dict.items(), key=lambda span_value: _get_span_length_key(span_value[0]), reverse=True)
    selected_spans = []
    for span, value in spans:
        for selected_span, _ in selected_spans:
            if selected_span[0] <= span[0] and span[1] <= selected_span[1]:
                break
        else:
            selected_spans.append((span, value))
    selected_spans.sort(key=lambda span_value: span_value[0][0])
    numeric_value_spans = []
    for span, values in selected_spans:
        numeric_value_spans.append(NumericValueSpan(begin_index=span[0], end_index=span[1], values=values))
    return numeric_value_spans

Extracts longest number and date spans.

Args:
text: text to annotate

Returns:
List of longest numeric value spans.


def cos(duration: int, amp: complex, freq: float = None,
        phase: float = 0, name: str = None) -> SamplePulse:

    if freq is None:
        freq = 1/duration

    return _sampled_cos_pulse(duration, amp, freq, phase=phase, name=name)

Generates cosine wave `SamplePulse`.

Applies `left` sampling strategy to generate discrete pulse from continuous function.

Args:
duration: Duration of pulse. Must be greater than zero.
amp: Pulse amplitude.
freq: Pulse frequency, units of 1/dt. If `None` defaults to single cycle.
phase: Pulse phase.
name: Name of pulse.


def parse_key(key):

    hkey, lkey = struct.unpack('<II',key[0:UBIFS_SK_LEN])
    ino_num = hkey & UBIFS_S_KEY_HASH_MASK
    key_type = lkey >> UBIFS_S_KEY_BLOCK_BITS
    khash = lkey

    return {'type':key_type, 'ino_num':ino_num, 'khash': khash}

Parse node key

Arguments:
Str:key    -- Hex string literal of node key.

Returns:
Int:key_type   -- Type of key, data, ino, dent, etc.
Int:ino_num    -- Inode number.
Int:khash      -- Key hash.


def fetch(self, subscription_id, data={}, **kwargs):

        return super(Subscription, self).fetch(subscription_id, data, **kwargs)

Fetch Subscription for given Id

Args:
subscription_id : Id for which subscription object is retrieved

Returns:
Subscription dict for given subscription Id


def validate_file(fpath, file_hash, algorithm='auto', chunk_size=65535):
    hasher = resolve_hasher(algorithm, file_hash)
    if str(hash_file(fpath, hasher, chunk_size)) == str(file_hash):
        return True
    else:
        return False

Validates a file against a sha256 or md5 hash.

Args:
fpath: path to the file being validated
file_hash:  The expected hash string of the file.
The sha256 and md5 hash algorithms are both supported.
algorithm: Hash algorithm, one of `"auto"`, `"sha256"`, or `"md5"`.
The default `"auto"` detects the hash algorithm in use.
chunk_size: Bytes to read at a time, important for large files.

Returns:
Boolean, whether the file is valid.


def group_systems(self, group_name, systems):

        api_group_id = None
        headers = {'Content-Type': 'application/json'}
        group_path = self.api_url + '/v1/groups'
        group_get_path = group_path + ('?display_name=%s' % quote(group_name))

        logger.debug("GET group: %s", group_get_path)
        net_logger.info("GET %s", group_get_path)
        get_group = self.session.get(group_get_path)
        logger.debug("GET group status: %s", get_group.status_code)
        if get_group.status_code == 200:
            api_group_id = get_group.json()['id']

        if get_group.status_code == 404:

            logger.debug("POST group")
            data = json.dumps({'display_name': group_name})
            net_logger.info("POST", group_path)
            post_group = self.session.post(group_path,
                                           headers=headers,
                                           data=data)
            logger.debug("POST group status: %s", post_group.status_code)
            logger.debug("POST Group: %s", post_group.json())
            self.handle_fail_rcs(post_group)
            api_group_id = post_group.json()['id']

        logger.debug("PUT group")
        data = json.dumps(systems)
        net_logger.info("PUT %s", group_path + ('/%s/systems' % api_group_id))
        put_group = self.session.put(group_path +
                                     ('/%s/systems' % api_group_id),
                                     headers=headers,
                                     data=data)
        logger.debug("PUT group status: %d", put_group.status_code)
        logger.debug("PUT Group: %s", put_group.json())

Adds an array of systems to specified group

Args:
group_name: Display name of group
systems: Array of {'machine_id': machine_id}


def setDataFrame(self, dataFrame, copyDataFrame=False, filePath=None):
    if (not isinstance(dataFrame, pandas.core.frame.DataFrame)):
        raise TypeError('not of type pandas.core.frame.DataFrame')
    self.layoutAboutToBeChanged.emit()
    if copyDataFrame:
        self._dataFrame = dataFrame.copy()
    else:
        self._dataFrame = dataFrame
    self._columnDtypeModel = ColumnDtypeModel(dataFrame)
    self._columnDtypeModel.dtypeChanged.connect(self.propagateDtypeChanges)
    self._columnDtypeModel.changeFailed.connect((lambda columnName, index, dtype: self.changingDtypeFailed.emit(columnName, index, dtype)))
    if (filePath is not None):
        self._filePath = filePath
    self.layoutChanged.emit()
    self.dataChanged.emit()
    self.dataFrameChanged.emit()

Setter function to _dataFrame. Holds all data.

Note:
It's not implemented with python properties to keep Qt conventions.

Raises:
TypeError: if dataFrame is not of type pandas.core.frame.DataFrame.

Args:
dataFrame (pandas.core.frame.DataFrame): assign dataFrame to _dataFrame. Holds all the data displayed.
copyDataFrame (bool, optional): create a copy of dataFrame or use it as is. defaults to False.
If you use it as is, you can change it from outside otherwise you have to reset the dataFrame
after external changes.


def make_serializable(json):
    new_dict = dict()
    for (key, value) in iteritems(json):
        if is_valid_json(value):
            new_dict[key] = value
    return new_dict

This function ensures that the dictionary is JSON serializable. If not,
keys with non-serializable values are removed from the return value.

Args:
json (dict): Dictionary to convert to serializable

Returns:
new_dict (dict): New dictionary with non JSON serializable values removed


def predictPhenos(self,use_fixed=None,use_random=None):

        assert self.noisPos is not None,      'No noise element'
        assert self.init,               'GP not initialised'
        assert self.Ntest is not None,        'VarianceDecomposition:: specify Ntest for predictions (method VarianceDecomposition::setTestSampleSize)'

        use_fixed  = list(range(self.n_fixedEffs))
        use_random = list(range(self.n_randEffs))

        KiY = self.gp.agetKEffInvYCache()

        if self.fast==False:
            KiY = KiY.reshape(self.P,self.N).T

        Ypred = sp.zeros((self.Ntest,self.P))

        for term_i in use_random:
            if term_i!=self.noisPos:
                Kstar = self.Kstar[term_i]
                if Kstar is None:
                    warnings.warn('warning: random effect term %d not used for predictions as it has None cross covariance'%term_i)
                    continue
                term  = sp.dot(Kstar.T,KiY)
                if self.P>1:
                    C    = self.getTraitCovar(term_i)
                    term = sp.dot(term,C)
                else:
                    term *= self.getVarianceComps()[0,term_i]
                Ypred += term

        weights = self.getWeights()
        w_i = 0
        for term_i in use_fixed:
            Fstar = self.Fstar[term_i]
            if Fstar is None:
                warnings.warn('warning: fixed effect term %d not used for predictions as it has None test sample design'%term_i)
                continue
            if self.P==1:    A = sp.eye(1)
            else:            A = self.vd.getDesign(term_i)
            Fstar = self.Fstar[term_i]
            W = weights[w_i:w_i+A.shape[0],0:1].T
            term = sp.dot(Fstar,sp.dot(W,A))
            w_i += A.shape[0]
            Ypred += term

        return Ypred

predict the conditional mean (BLUP)

Args:
use_fixed:        list of fixed effect indeces to use for predictions
use_random:        list of random effect indeces to use for predictions
Returns:
predictions (BLUP)


def score_one(self, x: beam.Row) -> Optional[float]:
    if len(x.__dict__) != 1:
        raise ValueError('ZScore.score_one expected univariate input, but got %s', str(x))
    v = next(iter(x))
    if v is None or math.isnan(v):
        return None
    sub_stat = self._sub_stat_tracker.get()
    stdev = self._stdev_tracker.get()
    if math.isnan(stdev) or math.isnan(sub_stat):
        return float('NaN')
    if abs(stdev) < EPSILON:
        return 0.0
    return abs((v - sub_stat) / stdev)

Scores a data point using the Z-Score.

Args:
x: A `beam.Row` containing a single numerical value.

Returns:
float | None: The Z-Score.


def set_logfile(self, filename, max_bytes=0, backup_count=0):

        _logger = logging.getLogger("neo-python")

        if not filename and not self.rotating_filehandler:
            _logger.removeHandler(self.rotating_filehandler)
        else:
            self.rotating_filehandler = RotatingFileHandler(filename, mode='a', maxBytes=max_bytes, backupCount=backup_count, encoding=None)
            self.rotating_filehandler.setLevel(logging.DEBUG)
            self.rotating_filehandler.setFormatter(LogFormatter(color=False))
            _logger.addHandler(self.rotating_filehandler)

Setup logging to a (rotating) logfile.

Args:
filename (str): Logfile. If filename is None, disable file logging
max_bytes (int): Maximum number of bytes per logfile. If used together with backup_count,
logfile will be rotated when it reaches this amount of bytes.
backup_count (int): Number of rotated logfiles to keep


def enum_to_yaml(cls: Type[T_EnumToYAML], representer: Representer, data: T_EnumToYAML) -> ruamel.yaml.nodes.ScalarNode:
    return representer.represent_scalar(f'!{cls.__name__}', f'{str(data)}')

Encodes YAML representation.

This is a mixin method for writing enum values to YAML. It needs to be added to the enum
as a classmethod. See the module docstring for further information on this approach and how
to implement it.

This method writes whatever is used in the string representation of the YAML value.
Usually, this will be the unique name of the enumeration value. If the name is used,
the corresponding ``EnumFromYAML`` mixin can be used to recreate the value. If the name
isn't used, more care may be necessary, so a ``from_yaml`` method for that particular
enumeration may be necessary.

Note:
This method assumes that the name of the enumeration value should be stored as a scalar node.

Args:
representer: Representation from YAML.
data: Enumeration value to be encoded.
Returns:
Scalar representation of the name of the enumeration value.


def children(cls, obj, save_type=base.SaveType.CHECKPOINT, **kwargs):
    obj._maybe_initialize_trackable()
    children = {}
    for name, ref in obj._trackable_children(save_type, **kwargs).items():
        ref = converter.convert_to_trackable(ref, parent=obj)
        children[name] = ref
    return children

Returns all child trackables attached to obj.

Args:
obj: A `Trackable` object.
save_type: A string, can be 'savedmodel' or 'checkpoint'.
**kwargs: kwargs to use when retrieving the object's children.

Returns:
Dictionary of all children attached to the object with name to trackable.


def kill_raylet_monitor(self, check_alive=True):

        self._kill_process_type(
            ray_constants.PROCESS_TYPE_RAYLET_MONITOR, check_alive=check_alive)

Kill the raylet monitor.

Args:
check_alive (bool): Raise an exception if the process was already
dead.


def get_general_case_info(adapter, institute_id=None, slice_query=None):
    general = {}
    name_query = slice_query
    cases = adapter.cases(owner=institute_id, name_query=name_query)
    phenotype_cases = 0
    causative_cases = 0
    pinned_cases = 0
    cohort_cases = 0
    pedigree = {1: {'title': 'Single', 'count': 0}, 2: {'title': 'Duo', 'count': 0}, 3: {'title': 'Trio', 'count': 0}, 'many': {'title': 'Many', 'count': 0}}
    case_ids = set()
    total_cases = 0
    for (total_cases, case) in enumerate(cases, 1):
        if institute_id:
            case_ids.add(case['_id'])
        if case.get('phenotype_terms'):
            phenotype_cases += 1
        if case.get('causatives'):
            causative_cases += 1
        if case.get('suspects'):
            pinned_cases += 1
        if case.get('cohorts'):
            cohort_cases += 1
        nr_individuals = len(case.get('individuals', []))
        if (nr_individuals == 0):
            continue
        if (nr_individuals > 3):
            pedigree['many']['count'] += 1
        else:
            pedigree[nr_individuals]['count'] += 1
    general['total_cases'] = total_cases
    general['phenotype_cases'] = phenotype_cases
    general['causative_cases'] = causative_cases
    general['pinned_cases'] = pinned_cases
    general['cohort_cases'] = cohort_cases
    general['pedigree'] = pedigree
    general['case_ids'] = case_ids
    return general

Return general information about cases

Args:
adapter(adapter.MongoAdapter)
institute_id(str)
slice_query(str):   Query to filter cases to obtain statistics for.

Returns:
general(dict)


def merge(self, other):
    if ((self.m != other.m) or (self.p != other.p)):
        raise ValueError('Cannot merge HyperLogLog with different                    precisions.')
    self.reg = np.maximum(self.reg, other.reg)

Merge the other HyperLogLog with this one, making this the union of the
two.

Args:
other (datasketch.HyperLogLog):


def SelectComponent(ds, idxs):

    return MapData(ds, lambda dp: [dp[i] for i in idxs])

Select / reorder components from datapoints.

Args:
ds (DataFlow): input DataFlow.
idxs (list[int]): a list of component indices.

Example:

.. code-block:: none

original df produces: [c1, c2, c3]
idxs: [2,1]
this df: [c3, c2]


def __contains__(self, temp_ver):

        return os.path.exists(self._prefixed(temp_ver.name))

Checks if a given version is in this store

Args:
temp_ver (TemplateVersion): Version to look for

Returns:
bool: ``True`` if the version is in this store


def append(self, *values):

        for value in values:
            list.append(self, value)
        return self

Append values at the end of the list

Allow chaining.

Args:
values: values to be appened at the end.

Example:

>>> from ww import l
>>> lst = l([])
>>> lst.append(1)
[1]
>>> lst
[1]
>>> lst.append(2, 3).append(4,5)
[1, 2, 3, 4, 5]
>>> lst
[1, 2, 3, 4, 5]


Compute the Moon position at a given date

Args:
date (~beyond.utils.date.Date)
Return:
~beyond.orbits.orbit.Orbit: Position of the Moon in EME2000 frame
Example:

.. code-block:: python

from beyond.utils.date import Date
MoonPropagator.propagate(Date(1994, 4, 28))
# Orbit =
#   date = 1994-04-28T00:00:00 UTC
#   form = Cartesian
#   frame = EME2000
#   propag = MoonPropagator
#   coord =
#     x = -134181157.317
#     y = -311598171.54
#     z = -126699062.437
#     vx = 0.0
#     vy = 0.0
#     vz = 0.0


def get_path_str(self, sep=os.path.sep, type_str=None):

        return sep.join(
            list(
                reversed(
                    [
                        v.label_str
                        for v in self.parent_gen
                        if type_str in (None, v.type_str)
                    ]
                )
            )
        )

Get path from root to this node.

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

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

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


def shannon_entropy(pvec, base=2):

    if base == 2:
        def logfn(x):
            return - x * np.log2(x)
    elif base == np.e:
        def logfn(x):
            return - x * np.log(x)
    else:
        def logfn(x):
            return -x * np.log(x) / np.log(base)

    h = 0.
    for x in pvec:
        if 0 < x < 1:
            h += logfn(x)
    return h

Compute the Shannon entropy of a probability vector.

The shannon entropy of a probability vector pv is defined as
$H(pv) = - \\sum_j pv[j] log_b (pv[j])$ where $0 log_b 0 = 0$.

Args:
pvec (array_like): a probability vector.
base (int): the base of the logarith

Returns:
float: The Shannon entropy H(pvec).


def ShowUnspentCoins(wallet, asset_id=None, from_addr=None, watch_only=False, do_count=False):
    if (wallet is None):
        print('Please open a wallet.')
        return
    watch_only_flag = (64 if watch_only else 0)
    if asset_id:
        unspents = wallet.FindUnspentCoinsByAsset(asset_id, from_addr=from_addr, watch_only_val=watch_only_flag)
    else:
        unspents = wallet.FindUnspentCoins(from_addr=from_addr, watch_only_val=watch_only)
    if do_count:
        print('\n-----------------------------------------------')
        print(('Total Unspent: %s' % len(unspents)))
        return unspents
    for unspent in unspents:
        print('\n-----------------------------------------------')
        print(json.dumps(unspent.ToJson(), indent=4))
    if (not unspents):
        print('No unspent assets matching the arguments.')
    return unspents

Show unspent coin objects in the wallet.

Args:
wallet (neo.Wallet): wallet to show unspent coins from.
asset_id (UInt256): a bytearray (len 32) representing an asset on the blockchain.
from_addr (UInt160): a bytearray (len 20) representing an address.
watch_only (bool): indicate if this shows coins that are in 'watch only' addresses.
do_count (bool): if True only show a count of unspent assets.

Returns:
list: a list of unspent ``neo.Wallet.Coin`` in the wallet


def _encode_value(self, value):

        if isinstance(value, (int, float, str, bool, datetime)):
            return value
        elif isinstance(value, list):
            return [self._encode_value(item) for item in value]
        elif isinstance(value, dict):
            result = {}
            for key, item in value.items():
                result[key] = self._encode_value(item)
            return result
        else:
            return self._gridfs.put(Binary(pickle.dumps(value)),
                                    workflow_id=self._workflow_id)

Encodes the value such that it can be stored into MongoDB.

Any primitive types are stored directly into MongoDB, while non-primitive types
are pickled and stored as GridFS objects. The id pointing to a GridFS object
replaces the original value.

Args:
value (object): The object that should be encoded for storing in MongoDB.

Returns:
object: The encoded value ready to be stored in MongoDB.


def update_metadata(self, resource, keys_vals):
    self.metadata_service.set_auth(self._token_metadata)
    self.metadata_service.update(resource, keys_vals)

Updates key-value pairs with the given resource.

Will attempt to update all key-value pairs even if some fail.
Keys must already exist.

Args:
resource (intern.resource.boss.BossResource)
keys_vals (dictionary): Collection of key-value pairs to update on
the given resource.

Raises:
HTTPErrorList on failure.


def set_device_state(self, device, state, id_override=None, type_override=None):
    _LOGGER.info('Setting state via online API')
    object_id = (id_override or device.object_id())
    object_type = (type_override or device.object_type())
    url_string = '{}/{}s/{}'.format(self.BASE_URL, object_type, object_id)
    if ((state is None) or (object_type == 'group')):
        url_string += '/activate'
        if (state is None):
            arequest = requests.post(url_string, headers=API_HEADERS)
        else:
            arequest = requests.post(url_string, data=json.dumps(state), headers=API_HEADERS)
    else:
        arequest = requests.put(url_string, data=json.dumps(state), headers=API_HEADERS)
    if (arequest.status_code == 401):
        new_token = refresh_access_token()
        if new_token:
            arequest = requests.put(url_string, data=json.dumps(state), headers=API_HEADERS)
        else:
            raise WinkAPIException('Failed to refresh access token.')
    response_json = arequest.json()
    _LOGGER.debug('%s', response_json)
    return response_json

Set device state via online API.

Args:
device (WinkDevice): The device the change is being requested for.
state (Dict): The state being requested.
id_override (String, optional): A device ID used to override the
passed in device's ID. Used to make changes on sub-devices.
i.e. Outlet in a Powerstrip. The Parent device's ID.
type_override (String, optional): Used to override the device type
when a device inherits from a device other than WinkDevice.
Returns:
response_json (Dict): The API's response in dictionary format


def is_initialized(self, name=None):
    if values_util.is_saving_non_distributed():
        return self._primary.is_initialized()
    if self._use_packed_variable():
        return self._packed_var.is_initialized()
    result = self._primary.is_initialized()
    for v in self._values[1:-1]:
        result = math_ops.logical_and(result, v.is_initialized())
    result = math_ops.logical_and(result, self._values[-1].is_initialized(), name=name)
    return result

Identifies if all the component variables are initialized.

Args:
name: Name of the final `logical_and` op.

Returns:
The op that evaluates to True or False depending on if all the
component variables are initialized.


def __init__(self, pred=None, pivot=None, branch=None, name='cond_text', context_def=None, import_scope=None):
    self._name = ops.get_default_graph().unique_name(name)
    if context_def:
        self._init_from_proto(context_def, import_scope=import_scope)
    else:
        ControlFlowContext.__init__(self)
        self._pred = pred
        self._pivot = pivot
        self._branch = branch
        self._values.add(pred.name)
        self._external_values[pred.name] = pred
        self._values.add(pivot.name)
        pivot.op._set_control_flow_context(self)

Creates a `CondContext`.

Args:
pred: The `boolean` tensor for the conditional predicate.
pivot: The predicate tensor in this branch.
branch: 0 or 1 representing this branch.
name: Name of the `CondContext` python object.
context_def: Optional `ContextDef` protocol buffer to initialize the
`CondContext` object from.
import_scope: Optional `string`. Name scope to add. Only used when
initialing from protocol buffer.


def get_states(self, n):
    return self.states[len(self.new_states):(len(self.new_states) + n)]

Get the next n recurrent states.

Called by layers in "incremental" mode.

Args:
n: an integer
Returns:
a list of n Tensors


def _unflatten_dict(flat_dict, prefixes):

  original_dict = {}
  for key, value in flat_dict.items():
    prefix_found = False
    for prefix in prefixes:
      full_prefix = "__" + prefix + "_"
      if key.startswith(full_prefix):

        if prefix not in original_dict:
          original_dict[prefix] = {}
        original_dict[prefix][key[len(full_prefix):]] = value
        prefix_found = True
        break
    if not prefix_found:

      original_dict[key] = value

  return original_dict

Returns a dict of dicts if any prefixes match keys in the flat dict.

The function handles the case where the prefix may not be a dict.

Args:
flat_dict: A dict without any nesting.
prefixes: A list of strings which may have been dicts in the
original structure.


def __init__(self, filter=None):

    self._filter = filter
    self._context = datalab.Context.default()
    self._api = discovery.build('ml', 'v1', credentials=self._context.credentials)
    self._page_size = 0

Initializes an instance of a CloudML Job list that is iteratable ("for job in jobs()").

Args:
filter: filter string for retrieving jobs, such as "state=FAILED"
context: an optional Context object providing project_id and credentials.
api: an optional CloudML API client.


def _fulfillment_to_details(fulfillment):
    if (fulfillment.type_name == 'ed25519-sha-256'):
        return {'type': 'ed25519-sha-256', 'public_key': base58.b58encode(fulfillment.public_key).decode()}
    if (fulfillment.type_name == 'threshold-sha-256'):
        subconditions = [_fulfillment_to_details(cond['body']) for cond in fulfillment.subconditions]
        return {'type': 'threshold-sha-256', 'threshold': fulfillment.threshold, 'subconditions': subconditions}
    raise UnsupportedTypeError(fulfillment.type_name)

Encode a fulfillment as a details dictionary

Args:
fulfillment: Crypto-conditions Fulfillment object


def __init__(self, report_type):

    self._report_type = report_type
    self.categories = dict([(x, {}) for x in self.active_days])

Constructor.

Args:
report_type: rdf_stats.ClientGraphSeries.ReportType for the client stats
to track.


def __init__(self, port=2223, task_type=None, task_id=None, rpc_layer=None, environment=None):
    self._task_type = task_type
    self._task_id = task_id
    self._rpc_layer = rpc_layer
    self._environment = environment
    self._port = str(port)

Creates a new SageMakerClusterResolver.

Args:
port: (integer, optional) Override default port usage of 2223
task_type: (String, optional) Overrides the task type.
task_id: (Integer, optional) Overrides the task index.
rpc_layer: (String, optional) Overrides the rpc layer TensorFlow uses.
environment: (String, optional) Overrides the environment TensorFlow
operates in.


def do_batch(args):
    if (args.subcommand == 'list'):
        do_batch_list(args)
    if (args.subcommand == 'show'):
        do_batch_show(args)
    if (args.subcommand == 'status'):
        do_batch_status(args)
    if (args.subcommand == 'submit'):
        do_batch_submit(args)

Runs the batch list, batch show or batch status command, printing output
to the console

Args:
args: The parsed arguments sent to the command at runtime


def stitch_images(images, margin=5, cols=5):
    if (len(images) == 0):
        return None
    (h, w, c) = images[0].shape
    n_rows = int(math.ceil((len(images) / cols)))
    n_cols = min(len(images), cols)
    out_w = ((n_cols * w) + ((n_cols - 1) * margin))
    out_h = ((n_rows * h) + ((n_rows - 1) * margin))
    stitched_images = np.zeros((out_h, out_w, c), dtype=images[0].dtype)
    for row in range(n_rows):
        for col in range(n_cols):
            img_idx = ((row * cols) + col)
            if (img_idx >= len(images)):
                break
            stitched_images[(((h + margin) * row):(((h + margin) * row) + h), ((w + margin) * col):(((w + margin) * col) + w), :)] = images[img_idx]
    return stitched_images

Utility function to stitch images together with a `margin`.

Args:
images: The array of 2D images to stitch.
margin: The black border margin size between images (Default value = 5)
cols: Max number of image cols. New row is created when number of images exceed the column size.
(Default value = 5)

Returns:
A single numpy image array comprising of input images.


def _open_file(filename):
    if (filename is None):
        raise DataSourceError('Trace filename is not defined')
    try:
        trace_file = open(filename, 'r')
    except IOError as e:
        raise DataSourceError(('Unable to open trace file %s' % filename), e)
    else:
        LOG.debug('Opened trace file %s', filename)
        return trace_file

Attempt to open the the file at ``filename`` for reading.

Raises:
DataSourceError, if the file cannot be opened.


def init_log(logger, loglevel=0):

    global log_tmp_dir, log_tmp_fn
    log_tmp_dir = tempfile.mkdtemp()
    log_tmp_fn = os.path.join(log_tmp_dir, 'multiqc.log')

    debug_template = '[%(asctime)s] %(name)-50s [%(levelname)-7s]  %(message)s'
    info_template = '[%(levelname)-7s] %(module)15s : %(message)s'

    logger.setLevel(getattr(logging, 'DEBUG'))

    console = logging.StreamHandler()
    console.setLevel(getattr(logging, loglevel))
    if loglevel == 'DEBUG':
        console.setFormatter(logging.Formatter(debug_template))
    else:
        console.setFormatter(logging.Formatter(info_template))
    logger.addHandler(console)

    file_handler = logging.FileHandler(log_tmp_fn, encoding='utf-8')
    file_handler.setLevel(getattr(logging, 'DEBUG'))
    file_handler.setFormatter(logging.Formatter(debug_template))
    logger.addHandler(file_handler)

Initializes logging.
Prints logs to console with level defined by loglevel
Also prints verbose log to the multiqc data directory if available.
(multiqc_data/multiqc.log)

Args:
loglevel (str): Determines the level of the log output.


def post_process_generation(self, generation: Union[str, List[str]], fix_markdown: bool=True, num_workers: Optional[int]=None) -> Union[str, List[str]]:
    requires_backends(self, ['nltk', 'levenshtein'])
    if isinstance(generation, list):
        if num_workers is not None and isinstance(num_workers, int):
            with Pool(num_workers) as p:
                return p.map(partial(self.post_process_single, fix_markdown=fix_markdown), generation)
        else:
            return [self.post_process_single(s, fix_markdown=fix_markdown) for s in generation]
    else:
        return self.post_process_single(generation, fix_markdown=fix_markdown)

Postprocess a generated text or a list of generated texts.

This function can be used to perform postprocessing on generated text, such as fixing Markdown formatting.

Postprocessing is quite slow so it is recommended to use multiprocessing to speed up the process.

Args:
generation (Union[str, List[str]]):
The generated text or a list of generated texts.
fix_markdown (`bool`, *optional*, defaults to `True`):
Whether to perform Markdown formatting fixes.
num_workers (`int`, *optional*):
Optional number of workers to pass to leverage multiprocessing (postprocessing several texts in
parallel).

Returns:
Union[str, List[str]]: The postprocessed text or list of postprocessed texts.


def SCM(root_dir, repo=None):

    if Git.is_repo(root_dir) or Git.is_submodule(root_dir):
        return Git(root_dir, repo=repo)

    return NoSCM(root_dir, repo=repo)

Returns SCM instance that corresponds to a repo at the specified
path.

Args:
root_dir (str): path to a root directory of the repo.
repo (dvc.repo.Repo): dvc repo instance that root_dir belongs to.

Returns:
dvc.scm.base.Base: SCM instance.


def __init__(self, filename,f_start=None, f_stop=None,t_start=None, t_stop=None, load_data=True, max_load=1.):

        super(FilReader, self).__init__()

        self.header_keywords_types = sigproc.header_keyword_types

        if filename and os.path.isfile(filename):
            self.filename = filename
            self.load_data = load_data
            self.header = self.read_header()
            self.file_size_bytes = os.path.getsize(self.filename)
            self.idx_data = sigproc.len_header(self.filename)
            self.n_channels_in_file  = self.header[b'nchans']
            self.n_beams_in_file = self.header[b'nifs']
            self.n_pols_in_file = 1
            self._n_bytes = int(self.header[b'nbits'] / 8)
            self._d_type = self._setup_dtype()
            self._setup_n_ints_in_file()
            self.file_shape = (self.n_ints_in_file,self.n_beams_in_file,self.n_channels_in_file)

            if self.header[b'foff'] < 0:
                self.f_end  = self.header[b'fch1']
                self.f_begin  = self.f_end + self.n_channels_in_file*self.header[b'foff']
            else:
                self.f_begin  = self.header[b'fch1']
                self.f_end  = self.f_begin + self.n_channels_in_file*self.header[b'foff']

            self.t_begin = 0
            self.t_end = self.n_ints_in_file

            self._setup_selection_range(f_start=f_start, f_stop=f_stop, t_start=t_start, t_stop=t_stop, init=True)

            self._setup_chans()

            self._setup_freqs()

            self.freq_axis = 2
            self.time_axis = 0
            self.beam_axis = 1

            if max_load is not None:
                if max_load > 1.0:
                    logger.warning('Setting data limit != 1GB, please handle with care!')
                self.MAX_DATA_ARRAY_SIZE = max_load * MAX_DATA_ARRAY_SIZE_UNIT
            else:
                self.MAX_DATA_ARRAY_SIZE = MAX_DATA_ARRAY_SIZE_UNIT

            if self.file_size_bytes > self.MAX_DATA_ARRAY_SIZE:
                self.large_file = True
            else:
                self.large_file = False

            if self.load_data:
                if self.large_file:
                    if self.f_start or self.f_stop or self.t_start or self.t_stop:
                        if self.isheavy():
                            logger.warning("Selection size of %.2f GB, exceeding our size limit %.2f GB. Instance created, header loaded, but data not loaded, please try another (t,v) selection." % (self._calc_selection_size() / (1024. ** 3), self.MAX_DATA_ARRAY_SIZE / (1024. ** 3)))
                            self._init_empty_selection()
                        else:
                            self.read_data()
                    else:
                        logger.warning("The file is of size %.2f GB, exceeding our size limit %.2f GB. Instance created, header loaded, but data not loaded. You could try another (t,v) selection."%(self.file_size_bytes/(1024.**3), self.MAX_DATA_ARRAY_SIZE/(1024.**3)))
                        self._init_empty_selection()
                else:
                    self.read_data()
            else:
                logger.info("Skipping loading data ...")
                self._init_empty_selection()
        else:
            raise IOError("Need a file to open, please give me one!")

Constructor.

Args:
filename (str): filename of blimpy file.
f_start (float): start frequency, in MHz
f_stop (float): stop frequency, in MHz
t_start (int): start time bin
t_stop (int): stop time bin


def mkdir(path):
    try:
        os.makedirs(path)
        if (not os.path.isdir(path)):
            raise IOError('path is not a directory')
    except OSError as e:
        if ((e.errno == 17) and os.path.isdir(path)):
            return
        raise

Make a directory and its parents.

Args:
path (str): path to create

Returns:
None

Raises:
OSError if the directory cannot be created.


def delete_bq_table(project, dataset_id, table_id):
    _LOGGER.info('Clean up a BigQuery table with project: %s, dataset: %s, table: %s.', project, dataset_id, table_id)
    client = bigquery.Client(project=project)
    table_ref = client.dataset(dataset_id).table(table_id)
    try:
        client.delete_table(table_ref)
    except gexc.NotFound:
        raise GcpTestIOError('BigQuery table does not exist: %s' % table_ref)

Delete a BiqQuery table.

Args:
project: Name of the project.
dataset_id: Name of the dataset where table is.
table_id: Name of the table.


def from_config(cls, config):
    return cls(**config)

Instantiates a `Loss` from its config (output of `get_config()`).

Args:
config: Output of `get_config()`.

Returns:
A `Loss` instance.


def get_percentage_lattice_parameter_changes(self):
    initial_latt = self.initial.lattice
    final_latt = self.final.lattice
    d = {l: ((getattr(final_latt, l) / getattr(initial_latt, l)) - 1) for l in ['a', 'b', 'c']}
    return d

Returns the percentage lattice parameter changes.

Returns:
A dict of the percentage change in lattice parameter, e.g.,
{'a': 0.012, 'b': 0.021, 'c': -0.031} implies a change of 1.2%,
2.1% and -3.1% in the a, b and c lattice parameters respectively.


def execute_only_once():
    f = inspect.currentframe().f_back
    ident = (f.f_code.co_filename, f.f_lineno)
    if (ident in _EXECUTE_HISTORY):
        return False
    _EXECUTE_HISTORY.add(ident)
    return True

Each called in the code to this function is guaranteed to return True the
first time and False afterwards.

Returns:
bool: whether this is the first time this function gets called from this line of code.

Example:
.. code-block:: python

if execute_only_once():
# do something only once


def iterator_product(variables: VarType, parent: str=None) -> Iterable[VarMatrix]:
    logger.debug('Yielding from product iterator')
    if isinstance(variables, list):
        raise ValueError(f'Product only takes mappings of values, got {variables} of type {type(variables)}')
    (yield list(variable_matrix(variables, parent, 'product')))

Apply the product operator to a set of variables.

This uses the python itertools.product iterator to combine multiple variables
such that all possible combinations are generated. This is the default iterator
however this is a method of manually specifying the option.

Args:
variables: The variables object
parent: Unused


def __init__(self, points, add_bounding_box=False):

        self.points = list(points)
        dim = [len(i) for i in self.points]
        if max(dim) != min(dim):
            raise ValueError("Input points must all have the same dimension!")
        self.dim = dim[0]
        if add_bounding_box:
            coord_ranges = zip(np.amin(points, 0), np.amax(points, 0))
            for coord in itertools.product(*coord_ranges):
                self.points.append(coord)
        output = qvoronoi("o Fv", self.points)
        output.pop(0)
        nvertices, nregions, i = [int(i) for i in output.pop(0).split()]
        self.vertices = [[float(j) for j in output.pop(0).split()]
                         for i in range(nvertices)]
        self.regions = [[int(j) for j in output.pop(0).split()[1:]]
                        for i in range(nregions)]

        output.pop(0)
        ridges = {}
        for line in output:
            val = [int(i) for i in line.split()]
            ridges[tuple(val[1:3])] = val[3:]
        self.ridges = ridges

Initializes a VoronoiTess from points.

Args:
points ([[float]]): All the points as a sequence of sequences.
e.g., [[-0.5, -0.5], [-0.5, 0.5], [0.5, -0.5], [0.5, 0.5]]
add_bounding_box (bool): If True, a hypercube corresponding to
the extremes of each coordinate will be added to the list of
points.


def setMAC(self, xEUI):

        print '%s call setMAC' % self.port

        address64 = ''
        try:
            if not xEUI:
                address64 = self.mac

            if not isinstance(xEUI, str):
                address64 = self.__convertLongToString(xEUI)

                if len(address64) < 16:
                    address64 = address64.zfill(16)
                    print address64
            else:
                address64 = xEUI

            cmd = WPANCTL_CMD + 'setprop NCP:MACAddress %s' % address64

            if self.__sendCommand(cmd)[0] != 'Fail':
                self.mac = address64
                return True
            else:
                return False
        except Exception, e:
            ModuleHelper.WriteIntoDebugLogger('setMAC() Error: ' + str(e))

set the extended addresss of Thread device

Args:
xEUI: extended address in hex format

Returns:
True: successful to set the extended address
False: fail to set the extended address


def _build_late_dispatcher(func_name):

    def _late_dynamic_dispatcher(obj, *args):
        method = getattr(obj, func_name, None)
        if (not callable(method)):
            raise NotImplementedError(('Instance method %r is not implemented by %r.' % (func_name, obj)))
        return method(*args)
    return _late_dynamic_dispatcher

Return a function that calls method 'func_name' on objects.

This is useful for building late-bound dynamic dispatch.

Arguments:
func_name: The name of the instance method that should be called.

Returns:
A function that takes an 'obj' parameter, followed by *args and
returns the result of calling the instance method with the same
name as the contents of 'func_name' on the 'obj' object with the
arguments from *args.


def rebuild(self, image_id=None, return_dict=True):

        if not image_id:
            image_id = self.image['id']

        return self._perform_action(
            {"type": "rebuild", "image": image_id},
            return_dict
        )

Restore the droplet to an image ( snapshot or backup )

Args:
image_id (int): id of image

Optional Args:
return_dict (bool): Return a dict when True (default),
otherwise return an Action.

Returns dict or Action


def visit_Import(self, node):
    for import_alias in node.names:
        full_import = (import_alias.name, import_alias.asname)
        detection = self._api_analysis_spec.imports_to_detect.get(full_import, None)
        if detection:
            self.add_result(detection)
            self.add_log(detection.log_level, node.lineno, node.col_offset, detection.log_message)
    self.generic_visit(node)

Handle visiting an import node in the AST.

Args:
node: Current Node


def append(self, event, category=None):
    date = datetime.datetime.now()
    self.store.insert(0, (date, event, category))
    if (len(self.store) > self.size):
        del self.store[(- 1)]

Adds a new event to the trace store.
The event may hava a category

Args:
event (spade.message.Message): the event to be stored
category (str, optional): a category to classify the event (Default value = None)


def get_programs_dict(pkgname_only=None, flag_protected=False):

    ___ret = _get_programs_dict()
    __ret = ___ret if pkgname_only is None else OrderedDict(((pkgname_only, ___ret[pkgname_only]),))
    if flag_protected:
        _ret = __ret
    else:
        _ret = copy.deepcopy(__ret)
        for value in _ret.values():
            value["exeinfo"] = [exeinfo for exeinfo in value["exeinfo"] if not exeinfo.filename.startswith("_")]

    ret = _ret if pkgname_only is None and flag_protected is None else \
        OrderedDict(((key, value) for key, value in _ret.items() if len(value["exeinfo"]) > 0))

    return ret

Scans COLLABORATORS_S packages for scripts, eventually filtering if arguments passed

Args:
pkgname_only: name of single package within COLLABORATORS_S
flag_protected: include scripts starting with "_"?

Returns:
dictionary: {"packagename0": {"exeinfo": [ExeInfo00, ...], "description": description0}, ...}


def transform_absolute_coords(self, width, height):

		if self.type != EventType.POINTER_MOTION_ABSOLUTE:
			raise AttributeError(_wrong_meth.format(self.type))
		abs_x = self._libinput \
			.libinput_event_pointer_get_absolute_x_transformed(
				self._handle, width)
		abs_y = self._libinput \
			.libinput_event_pointer_get_absolute_y_transformed(
				self._handle, height)
		return abs_x, abs_y

Return the current absolute coordinates of the pointer event,
transformed to screen coordinates.

For pointer events that are not of type
:attr:`~libinput.constant.EventType.POINTER_MOTION_ABSOLUTE`,
this method raises :exc:`AttributeError`.

Args:
width (int): The current output screen width.
height (int): The current output screen height.
Returns:
(float, float): The current absolute (x, y) coordinates transformed
to a screen coordinates.
Raises:
AttributeError


def get_structure_from_id(self, task_id, final_structure=True):

        args = {'task_id': task_id}
        field = 'output.crystal' if final_structure else 'input.crystal'
        results = tuple(self.query([field], args))

        if len(results) > 1:
            raise QueryError("More than one result found for task_id {}!".format(task_id))
        elif len(results) == 0:
            raise QueryError("No structure found for task_id {}!".format(task_id))
        c = results[0]
        return Structure.from_dict(c[field])

Returns a structure from the database given the task id.

Args:
task_id:
The task_id to query for.
final_structure:
Whether to obtain the final or initial structure. Defaults to
True.


def split(cls, tensor, split_dimension, num_devices, input_shape=None):
    if input_shape:
        shape = input_shape
    else:
        shape = tensor.shape.as_list()
    if shape[split_dimension] is not None and shape[split_dimension] < num_devices:
        raise ValueError('Split dimension was smaller than the required number of splits: shape=%r, dimension=%r, num_devices=%r' % (shape, split_dimension, num_devices))
    tile_assignment_dims = [1] * len(shape)
    tile_assignment_dims[split_dimension] = num_devices
    return Sharding(proto=xla_data_pb2.OpSharding(type=xla_data_pb2.OpSharding.OTHER, tile_assignment_dimensions=tile_assignment_dims, tile_assignment_devices=range(num_devices)))

Returns a Sharding that splits a tensor across a dimension.

This creates a Tiled attribute, similar to tile(), but easier to use for the
common case of tiling a tensor N ways in one dimension.

Args:
tensor: A tf.Tensor to split.
split_dimension: The dimension number to split.
num_devices: The number of cores to split `tensor` over.
input_shape: The shape of the original tensor.

Raises:
ValueError: The tensor to split was smaller in the split dimension than
the number of devices to split over.


def locate(desktop_filename_or_name):

	paths = [
		os.path.expanduser('~/.local/share/applications'),
		'/usr/share/applications']

	result = []

	for path in paths:
		for file in os.listdir(path):
			if desktop_filename_or_name in file.split(
					'.') or desktop_filename_or_name == file:

				result.append(os.path.join(path, file))

			else:
				file_parsed = parse(os.path.join(path, file))

				try:
					if desktop_filename_or_name.lower() == file_parsed[
							'Name'].lower():
						result.append(file)
					elif desktop_filename_or_name.lower() == file_parsed[
							'Exec'].split(' ')[0]:
						result.append(file)
				except KeyError:
					pass

	for res in result:
		if not res.endswith('.desktop'):
			result.remove(res)

	if not result and not result.endswith('.desktop'):
		result.extend(locate(desktop_filename_or_name + '.desktop'))

	return result

Locate a .desktop from the standard locations.
Find the path to the .desktop file of a given .desktop filename or application name.
Standard locations:
- ``~/.local/share/applications/``
- ``/usr/share/applications``
Args:
desktop_filename_or_name (str): Either the filename of a .desktop file or the name of an application.
Returns:
list: A list of all matching .desktop files found.


def record_operation_forwardprop_only(op_type, output_tensors, input_tensors, backward_function, forwardprop_output_indices):
    pywrap_tfe.TFE_Py_TapeSetRecordOperationForwardprop(op_type, output_tensors, input_tensors, backward_function, forwardprop_output_indices)

Records the operation on all forward accumulators in the stack.

Args:
op_type: a string for the operation type, used in the backprop code
output_tensors: a list of Python Tensor objects output by the operation
input_tensors: a list of input Tensors to the recorded operation
backward_function: the function to be called to, given the gradients of the
output tensors, produce the gradients of the input tensors. This function
is automatically transposed to produce output gradients given input
gradients.
forwardprop_output_indices: indicates any output_tensors which contain JVPs.
Typically these will have come from TFE_Py_PackForwardGradients. May be
None or an empty sequence if there are no JVP outputs from the operation.


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

        init_params = super(Framework, cls)._prepare_init_params_from_job_description(job_details, model_channel_name)

        init_params['entry_point'] = json.loads(init_params['hyperparameters'].get(SCRIPT_PARAM_NAME))
        init_params['source_dir'] = json.loads(init_params['hyperparameters'].get(DIR_PARAM_NAME))
        init_params['enable_cloudwatch_metrics'] = json.loads(
            init_params['hyperparameters'].get(CLOUDWATCH_METRICS_PARAM_NAME))
        init_params['container_log_level'] = json.loads(
            init_params['hyperparameters'].get(CONTAINER_LOG_LEVEL_PARAM_NAME))

        hyperparameters = {}
        for k, v in init_params['hyperparameters'].items():

            if k == '_tuning_objective_metric':
                if v.startswith('"') and v.endswith('"'):
                    v = v.strip('"')
                hyperparameters[k] = v
            else:
                hyperparameters[k] = json.loads(v)

        init_params['hyperparameters'] = hyperparameters

        return init_params

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

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

Returns:
dictionary: The transformed init_params


def implicit_static(cls, for_type=None, for_types=None):
    for type_ in cls.__get_type_args(for_type, for_types):
        implementations = {}
        for function in cls.required():
            method = getattr(type_, function.__name__, None)
            if (not callable(method)):
                raise TypeError(('%s.implicit invokation on type %r is missing instance method %r.' % (cls.__name__, type_, function.__name__)))
            implementations[function] = method
        for function in cls.optional():
            method = getattr(type_, function.__name__, None)
            if callable(method):
                implementations[function] = method
        return cls.implement(for_type=type_, implementations=implementations)

Automatically generate implementations for a type.

Implement the protocol for the 'for_type' type by dispatching each
member function of the protocol to an instance method of the same name
declared on the type 'for_type'.

Arguments:
for_type: The type to implictly implement the protocol with.

Raises:
TypeError if not all implementations are provided by 'for_type'.


def sh(cmd, ignore_error=False, cwd=None, shell=False, **kwargs):
    kwargs.update({'shell': shell, 'cwd': cwd, 'stderr': subprocess.STDOUT, 'stdout': subprocess.PIPE})
    log.debug((('cmd', cmd), ('kwargs', kwargs)))
    p = subprocess.Popen(cmd, universal_newlines=True, **kwargs)
    p_stdout = p.communicate()[0]
    if (p.returncode and (not ignore_error)):
        raise subprocess.CalledProcessError(p.returncode, cmd, p_stdout)
    return p_stdout

Execute a command with subprocess.Popen and block until output

Args:
cmd (tuple or str): same as subprocess.Popen args

Keyword Arguments:
ignore_error (bool): if False, raise an Exception if p.returncode is
not 0
cwd (str): current working directory path to run cmd with
shell (bool): subprocess.Popen ``shell`` kwarg

Returns:
str: stdout output of wrapped call to ``sh`` (``subprocess.Popen``)

Raises:
Exception: if ignore_error is true and returncode is not zero

.. note:: this executes commands with ``shell=True``: careful with
shell-escaping.


def subscribe_sns_topic_to_sqs(self, region):

        sns = self.session.resource('sns', region_name=region)
        topic = sns.Topic('arn:aws:sns:{}:{}:{}'.format(region, self.account.account_number, self.topic_name))

        topic.subscribe(Protocol='sqs', Endpoint=self.sqs_queue)

        auditlog(
            event='cloudtrail.subscribe_sns_topic_to_sqs',
            actor=self.ns,
            data={
                'account': self.account.account_name,
                'region': region
            }
        )

        return topic.attributes['TopicArn']

Subscribe SQS to the SNS topic. Returns the ARN of the SNS Topic subscribed

Args:
region (`str`): Name of the AWS region

Returns:
`str`


def _eventual_warn_about_too_long_sequence(self, ids: List[int], max_length: Optional[int], verbose: bool):
    if max_length is None and len(ids) > self.model_max_length and verbose and (self.model_max_length != 0):
        if not self.deprecation_warnings.get('sequence-length-is-longer-than-the-specified-maximum', False):
            logger.warning(f'Token indices sequence length is longer than the specified maximum sequence length for this model ({len(ids)} > {self.model_max_length}). Running this sequence through the model will result in indexing errors')
        self.deprecation_warnings['sequence-length-is-longer-than-the-specified-maximum'] = True

Depending on the input and internal state we might trigger a warning about a sequence that is too long for its
corresponding model

Args:
ids (`List[str]`): The ids produced by the tokenization
max_length (`int`, *optional*): The max_length desired (does not trigger a warning if it is set)
verbose (`bool`): Whether or not to print more information and warnings.


def __call__(self, fn):

        def output(app, *args, **kwargs):

            data = fn(app, *args, **kwargs)
            index = '{}-{}'.format(self.key, self.variable_type)
            if self.value is not None:

                app.tcex.playbook.add_output(self.key, self.value, self.variable_type)
            elif app.tcex.playbook.output_data.get(index) and not self.overwrite:

                pass
            else:

                app.tcex.playbook.add_output(self.key, data, self.variable_type)
            return data

        return output

Implement __call__ function for decorator.

Args:
fn (function): The decorated function.

Returns:
function: The custom decorator function.


async def verify_docker_image_task(chain, link):

    errors = []

    worker_type = get_worker_type(link.task)
    if worker_type not in chain.context.config['valid_docker_image_worker_types']:
        errors.append("{} is not a valid docker-image workerType!".format(worker_type))
    raise_on_errors(errors)

Verify the docker image Link.

Args:
chain (ChainOfTrust): the chain we're operating on.
link (LinkOfTrust): the task link we're checking.


def _DefaultGradYs(grad_ys, ys, colocate_gradients_with_ops, gradient_uid='__unsupported__'):
    if len(grad_ys) != len(ys):
        raise ValueError(f'Length mismatch. Passed {len(grad_ys)} grad_ys for {len(ys)} ys')
    grad_ys = indexed_slices.convert_n_to_tensor_or_indexed_slices(grad_ys, name='grad_y')
    new_grad_ys = []
    for i, (y, grad_y) in enumerate(zip(ys, grad_ys)):
        with _maybe_colocate_with(y.op, gradient_uid, colocate_gradients_with_ops):
            if grad_y is None:
                if y.dtype.is_complex:
                    raise TypeError(f'Gradients of complex tensors ({y}) must set grad_ys (y.dtype = {dtypes.as_dtype(y.dtype).name})')
                new_grad_ys.append(array_ops.ones(array_ops.shape(y), dtype=y.dtype, name='grad_ys_%d' % i))
                continue
            if y.dtype.is_floating or y.dtype.is_integer:
                if not grad_y.dtype.is_floating and (not grad_y.dtype.is_integer):
                    raise TypeError(f'Gradient type {dtypes.as_dtype(grad_y.dtype).name} generated for real or integer-valued tensor {y} with type {dtypes.as_dtype(y.dtype).name} must be real or integer')
            elif y.dtype.is_complex:
                if not grad_y.dtype.is_complex:
                    raise TypeError(f'Gradient type {dtypes.as_dtype(grad_y.dtype).name} generated for complex-valued tensor {y} with type {dtypes.as_dtype(y.dtype).name} must be real')
            elif y.dtype == dtypes.variant:
                if grad_y.dtype != dtypes.variant:
                    raise TypeError(f'Gradient type {dtypes.as_dtype(grad_y.dtype).name} generated for variant tensor {y} with type {dtypes.as_dtype(y.dtype).name} must be variant')
            elif y.dtype == dtypes.resource:
                if grad_y.dtype == dtypes.resource:
                    raise TypeError(f'Input gradient {grad_y} for resource tensor {y} should not be a resource')
            else:
                raise TypeError(f'Tensor {y} with type {dtypes.as_dtype(y.dtype).name} must be numeric to obtain a default gradient')
            if isinstance(grad_y, indexed_slices.IndexedSlices):
                new_grad_ys.append(indexed_slices.IndexedSlices(indices=array_ops.identity(grad_y.indices, name='grad_ys_%d_indices' % i) if isinstance(grad_y.indices, tensor_lib.Tensor) else grad_y.indices, values=array_ops.identity(grad_y.values, name='grad_ys_%d_values' % i) if isinstance(grad_y.values, tensor_lib.Tensor) else grad_y.values, dense_shape=array_ops.identity(grad_y.dense_shape, name='grad_ys_%d_shape' % i) if isinstance(grad_y.dense_shape, tensor_lib.Tensor) else grad_y.dense_shape))
            else:
                new_grad_ys.append(array_ops.identity(grad_y, name='grad_ys_%d' % i))
    return new_grad_ys

Fill in default values for grad_ys.

Args:
grad_ys: List of gradients, can contain None.
ys: List of tensors.
colocate_gradients_with_ops: If True, try colocating gradients with
the corresponding op.
gradient_uid: A unique identifier within the graph indicating
which invocation of gradients is being executed. Used to cluster
ops for compilation.

Returns:
A list of gradients to use, without None.

Raises:
ValueError: If sizes of gradients and inputs don't match
TypeError: If type of any gradient is not valid for its input.


def file_crc32(filename, block_size=_DEFAULT_BLOCK_SIZE):
    crc = 0
    with FileIO(filename, mode='rb') as f:
        chunk = f.read(n=block_size)
        while chunk:
            crc = binascii.crc32(chunk, crc)
            chunk = f.read(n=block_size)
    return hex(crc & 4294967295)

Get the crc32 of the passed file.

The crc32 of a file can be used for error checking; two files with the same
crc32 are considered equivalent. Note that the entire file must be read
to produce the crc32.

Args:
filename: string, path to a file
block_size: Integer, process the files by reading blocks of `block_size`
bytes. Use -1 to read the file as once.

Returns:
hexadecimal as string, the crc32 of the passed file.


def convertTime(self, time):

        m_format = ""
        if time.minute:
            m_format = ":%M"

        timeString = time.strftime("%I" + m_format + " %p")

        if not int(timeString[0]):
            timeString = timeString[1:]

        return timeString

Convert a datetime object representing a time into a human-ready
string that can be read, spoken aloud, etc.

Args:
time (datetime.date): A datetime object to be converted into text.

Returns:
A string representation of the input time, ignoring any day-related
information.


def create_mutation_file(self, list_of_tuples):
    self.mutation_infile = op.join(self.foldx_dir, 'individual_list.txt')
    idx = 1
    with open(self.mutation_infile, 'w') as f:
        for mutant_group in list_of_tuples:
            mutstring = ''.join(list(map((lambda x: '{}{}{}{};'.format(x[0], x[1], x[2], x[3])), mutant_group)))
            f.write((mutstring + '\n'))
            self.mutation_index_to_group[idx] = mutant_group
            idx += 1

Create the FoldX file 'individual_list.txt' to run BuildModel upon.

Args:
list_of_tuples (list): A list of tuples indicating mutation groups to carry out BuildModel upon. Example::

[
(('N', 'A', 308, 'S'), ('S', 'A', 320, 'T'), ('S', 'A', 321, 'H')),  # Mutation group 1
(('S', 'A', 321, 'R'), ('T', 'A', 345, 'S'))  # Mutation group 2
]


def get_backend(backend_class=None):
    cache_name = '_backend_instance'
    if (not hasattr(get_backend, cache_name)):
        backend_class = (backend_class or settings.ROUGHPAGES_BACKEND)
        if isinstance(backend_class, basestring):
            (module_path, class_name) = backend_class.rsplit('.', 1)
            module = import_module(module_path)
            backend_class = getattr(module, class_name)
        setattr(get_backend, cache_name, backend_class())
    return getattr(get_backend, cache_name)

Get backend instance

If no `backend_class` is specified, the backend class is determined from
the value of `settings.ROUGHPAGES_BACKEND`.
`backend_class` can be a class object or dots separated python import path

Returns:
backend instance


def api_server(api_services, **kwargs):
    if ('protocols' in kwargs):
        raise TypeError("__init__() got an unexpected keyword argument 'protocols'")
    from . import _logger as endpoints_logger
    from . import __version__ as endpoints_version
    endpoints_logger.info('Initializing Endpoints Framework version %s', endpoints_version)
    apis_app = _ApiServer(api_services, **kwargs)
    dispatcher = endpoints_dispatcher.EndpointsDispatcherMiddleware(apis_app)
    service_name = os.environ.get('ENDPOINTS_SERVICE_NAME')
    if (not service_name):
        _logger.warn('Did not specify the ENDPOINTS_SERVICE_NAME environment variable so service control is disabled.  Please specify the name of service in ENDPOINTS_SERVICE_NAME to enable it.')
        return dispatcher
    if control_wsgi.running_on_devserver():
        _logger.warn('Running on local devserver, so service control is disabled.')
        return dispatcher
    from endpoints_management import _logger as management_logger
    from endpoints_management import __version__ as management_version
    management_logger.info('Initializing Endpoints Management Framework version %s', management_version)
    controller = control_client.Loaders.DEFAULT.load(service_name)
    control_client.use_gae_thread()
    controller.start()
    return control_wsgi.add_all(dispatcher, app_identity.get_application_id(), controller)

Create an api_server.

The primary function of this method is to set up the WSGIApplication
instance for the service handlers described by the services passed in.
Additionally, it registers each API in ApiConfigRegistry for later use
in the BackendService.getApiConfigs() (API config enumeration service).
It also configures service control.

Args:
api_services: List of protorpc.remote.Service classes implementing the API
or a list of _ApiDecorator instances that decorate the service classes
for an API.
**kwargs: Passed through to protorpc.wsgi.service.service_handlers except:
protocols - ProtoRPC protocols are not supported, and are disallowed.

Returns:
A new WSGIApplication that serves the API backend and config registry.

Raises:
TypeError: if protocols are configured (this feature is not supported).


def restore_saveables(self, tensor_saveables, python_positions, registered_savers=None, reader=None):
    if reader is None:
        reader = py_checkpoint_reader.NewCheckpointReader(self.save_path_string)
    restore_ops = []
    for position in python_positions:
        key = position.object_proto.attributes[0].checkpoint_key
        position.trackable.deserialize(reader.get_tensor(key))
    if tensor_saveables or registered_savers:
        flat_saveables = saveable_object_util.validate_and_slice_inputs(tensor_saveables)
        new_restore_ops = functional_saver.MultiDeviceSaver.from_saveables(flat_saveables, registered_savers).restore(self.save_path_tensor, self.options)
        if not context.executing_eagerly():
            for name, restore_op in sorted(new_restore_ops.items()):
                restore_ops.append(restore_op)
                assert name not in self.restore_ops_by_name
                self.restore_ops_by_name[name] = restore_op
    return restore_ops

Run or build restore operations for SaveableObjects.

Args:
tensor_saveables: `SaveableObject`s which correspond to Tensors.
python_positions: List of CheckpointPositions bound to `PythonState`
objects which must be restored eagerly.
registered_savers: a dict mapping saver names-> object name -> Trackable.
reader: A `CheckpointReader`. If None, a new instance will be created.

Returns:
When graph building, a list of restore operations, either cached or newly
created, to restore `tensor_saveables`.


def merge_with(self, other):

        other = as_shape(other)
        if self._dims is None:
            return other
        else:
            try:
                self.assert_same_rank(other)
                new_dims = []
                for i, dim in enumerate(self._dims):
                    new_dims.append(dim.merge_with(other[i]))
                return TensorShape(new_dims)
            except ValueError:
                raise ValueError("Shapes %s and %s are not convertible" % (self, other))

Returns a `TensorShape` combining the information in `self` and `other`.

The dimensions in `self` and `other` are merged elementwise,
according to the rules defined for `Dimension.merge_with()`.

Args:
other: Another `TensorShape`.

Returns:
A `TensorShape` containing the combined information of `self` and
`other`.

Raises:
ValueError: If `self` and `other` are not convertible.


def resize_volumes(x, depth_factor, height_factor, width_factor, data_format):
    if data_format == 'channels_first':
        output = repeat_elements(x, depth_factor, axis=2)
        output = repeat_elements(output, height_factor, axis=3)
        output = repeat_elements(output, width_factor, axis=4)
        return output
    elif data_format == 'channels_last':
        output = repeat_elements(x, depth_factor, axis=1)
        output = repeat_elements(output, height_factor, axis=2)
        output = repeat_elements(output, width_factor, axis=3)
        return output
    else:
        raise ValueError('Invalid data_format: ' + str(data_format))

Resizes the volume contained in a 5D tensor.

Args:
x: Tensor or variable to resize.
depth_factor: Positive integer.
height_factor: Positive integer.
width_factor: Positive integer.
data_format: One of `"channels_first"`, `"channels_last"`.

Returns:
A tensor.

Raises:
ValueError: if `data_format` is neither
`channels_last` or `channels_first`.


def IsRValueAllowed(clean_lines, linenum, typenames):

  for i in xrange(linenum, 0, -1):
    line = clean_lines.elided[i]
    if Match(r'GOOGLE_ALLOW_RVALUE_REFERENCES_(?:PUSH|POP)', line):
      if not line.endswith('PUSH'):
        return False
      for j in xrange(linenum, clean_lines.NumLines(), 1):
        line = clean_lines.elided[j]
        if Match(r'GOOGLE_ALLOW_RVALUE_REFERENCES_(?:PUSH|POP)', line):
          return line.endswith('POP')

  line = clean_lines.elided[linenum]
  if Search(r'\boperator\s*=\s*\(', line):
    return IsDeletedOrDefault(clean_lines, linenum)

  match = Match(r'\s*(?:[\w<>]+::)*([\w<>]+)\s*::\s*([\w<>]+)\s*\(', line)
  if match and match.group(1) == match.group(2):
    return IsDeletedOrDefault(clean_lines, linenum)
  if Search(r'\b(?:explicit|inline)\s+[\w<>]+\s*\(', line):
    return IsDeletedOrDefault(clean_lines, linenum)

  if Match(r'\s*[\w<>]+\s*\(', line):
    previous_line = 'ReturnType'
    if linenum > 0:
      previous_line = clean_lines.elided[linenum - 1]
    if Match(r'^\s*$', previous_line) or Search(r'[{}:;]\s*$', previous_line):
      return IsDeletedOrDefault(clean_lines, linenum)

  while line:
    match = Match(r'^.*?(\w+)\s*&&(.*)$', line)
    if not match:
      break
    if match.group(1) not in typenames:
      return False
    line = match.group(2)

  return line.find('&&') < 0

Check if RValue reference is allowed on a particular line.

Args:
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
typenames: set of type names from template-argument-list.
Returns:
True if line is within the region where RValue references are allowed.


def __init__(self, name, type, description=''):

        self._name = name
        self._type = type
        self._description = description

Filter constructor.

Args:
name (str): Filter name.
type (str): Type of the filter (boolean, int, etc.).
description (str): Filter description.


def __init__(self, lat=None, lng=None, name=None, stop_id=None,
               field_dict=None, stop_code=None):

    self._schedule = None
    if field_dict:
      if isinstance(field_dict, self.__class__):

        for k, v in field_dict.iteritems():
          self.__dict__[k] = v
      else:
        self.__dict__.update(field_dict)
    else:
      if lat is not None:
        self.stop_lat = lat
      if lng is not None:
        self.stop_lon = lng
      if name is not None:
        self.stop_name = name
      if stop_id is not None:
        self.stop_id = stop_id
      if stop_code is not None:
        self.stop_code = stop_code

Initialize a new Stop object.

Args:
field_dict: A dictionary mapping attribute name to unicode string
lat: a float, ignored when field_dict is present
lng: a float, ignored when field_dict is present
name: a string, ignored when field_dict is present
stop_id: a string, ignored when field_dict is present
stop_code: a string, ignored when field_dict is present


def res_arg(self, ns, types_ns, f_name, name, type_anno, f_is_local):
    raise NotImplementedError('subclasses must implement')

Resolves the type of a (possibly annotated) function argument.

Args:
ns: namespace
types_ns: types namespace
f_name: str, the function name
name: str, the argument name
type_anno: the type annotating the argument, if any
f_is_local: bool, whether the function is a local function
Returns:
Set of the argument types.


def visualize(logdir, outdir, num_agents, num_episodes, checkpoint=None, env_processes=True):
    config = utility.load_config(logdir)
    with tf.device('/cpu:0'):
        batch_env = utility.define_batch_env((lambda : _create_environment(config, outdir)), num_agents, env_processes)
        graph = utility.define_simulation_graph(batch_env, config.algorithm, config)
        total_steps = (num_episodes * config.max_length)
        loop = _define_loop(graph, total_steps)
    saver = utility.define_saver(exclude=('.*_temporary.*', 'global_step'))
    sess_config = tf.ConfigProto(allow_soft_placement=True)
    sess_config.gpu_options.allow_growth = True
    with tf.Session(config=sess_config) as sess:
        utility.initialize_variables(sess, saver, config.logdir, checkpoint, resume=True)
        for unused_score in loop.run(sess, saver, total_steps):
            pass
    batch_env.close()

Recover checkpoint and render videos from it.

Args:
logdir: Logging directory of the trained algorithm.
outdir: Directory to store rendered videos in.
num_agents: Number of environments to simulate in parallel.
num_episodes: Total number of episodes to simulate.
checkpoint: Checkpoint name to load; defaults to most recent.
env_processes: Whether to step environments in separate processes.


def incr(self, counter_name, delta=1):

    self._state.counters_map.increment(counter_name, delta)

Changes counter by delta.

Args:
counter_name: the name of the counter to change. str.
delta: int.


def _comparison_functions(cls, partial=False):

        def prerelease_cmp(a, b):

            if a and b:
                return identifier_list_cmp(a, b)
            elif a:

                return -1
            elif b:
                return 1
            else:
                return 0

        def build_cmp(a, b):

            if a == b:
                return 0
            else:
                return NotImplemented

        def make_optional(orig_cmp_fun):

            @functools.wraps(orig_cmp_fun)
            def alt_cmp_fun(a, b):
                if a is None or b is None:
                    return 0
                return orig_cmp_fun(a, b)

            return alt_cmp_fun

        if partial:
            return [
                base_cmp,
                make_optional(base_cmp),
                make_optional(base_cmp),
                make_optional(prerelease_cmp),
                make_optional(build_cmp),
            ]
        else:
            return [
                base_cmp,
                base_cmp,
                base_cmp,
                prerelease_cmp,
                build_cmp,
            ]

Retrieve comparison methods to apply on version components.

This is a private API.

Args:
partial (bool): whether to provide 'partial' or 'strict' matching.

Returns:
5-tuple of cmp-like functions.


def _process(self, input):

        input = re.sub("<[^>]*>", " ", input)
        punct = list(string.punctuation)
        for symbol in punct:
            input = input.replace(symbol, " %s " % symbol)
        input = filter(lambda x: x != u'', input.lower().split(' '))
        return input

Takes in html-mixed body text as a string and returns a list of strings,
lower case and with punctuation given spacing.

Called by self._gen_sentence()

Args:
inpnut (string): body text


async def get_event(self, stream: str, event_number: int, resolve_links=True, require_master=False, correlation_id: uuid.UUID=None) -> msg.Event:
    correlation_id = (correlation_id or uuid.uuid4())
    cmd = convo.ReadEvent(stream, event_number, resolve_links, require_master, conversation_id=correlation_id)
    result = (await self.dispatcher.start_conversation(cmd))
    return (await result)

Get a single event by stream and event number.

Args:
stream: The name of the stream containing the event.
event_number: The sequence number of the event to read.
resolve_links (optional): True if eventstore should
automatically resolve Link Events, otherwise False.
required_master (optional): True if this command must be
sent direct to the master node, otherwise False.
correlation_id (optional): A unique identifer for this
command.

Returns:
The resolved event if found, else None.

Examples:

>>> async with connection() as conn:
>>>     await conn.publish("inventory_item-1", "item_created")
>>>     event = await conn.get_event("inventory_item-1", 1)
>>>     print(event)


def visit_comparison(self, comparison: _evaluation.ComparisonNode) -> _sql_data_types.Select:
    lhs_result = self.visit(comparison.left)
    rhs_result = self.visit(comparison.right)
    lhs_subquery = lhs_result.as_operand()
    rhs_subquery = rhs_result.as_operand()
    sql_value = f'{lhs_subquery} {comparison.op} {rhs_subquery}'
    return _sql_data_types.Select(select_part=_sql_data_types.RawExpression(sql_value, _sql_data_type=_sql_data_types.Boolean, _sql_alias='comparison_'), from_part=None, sql_dialect=_sql_data_types.SqlDialect.SPARK)

Translates a FHIRPath comparison to Spark SQL.

Each operand is expected to be a collection of a single element. Operands
can be strings, integers, decimals, dates, datetimes, and times. Comparison
will perform implicit conversion between applicable types.

Args:
comparison: The `Comparison` Expression node.

Returns:
A compiled Spark SQL expression.


def _psum(tensor, axis_name=None):
    if axis_name != _pmap_config.axis_name():
        raise ValueError('axis_name (%s) is not equal to that of the surrounding pmap (%s)' % (axis_name, _pmap_config.axis_name()))
    devices = _pmap_config.devices()
    if devices is None:
        raise ValueError("Can't retrieve the device list from the surrounding pmap")
    tensor = tf_np.asarray(tensor)
    if tpu_devices(devices):
        is_int64 = False
        is_float64 = False
        if tensor.dtype == np.int64:
            is_int64 = True
            tensor = tensor.astype(np.int32)
        elif tensor.dtype == np.float64:
            is_float64 = True
            tensor = tensor.astype(np.float32)
        tensor = tpu_ops.cross_replica_sum(tensor)
        if is_int64:
            tensor = math_ops.cast(tensor, dtypes.int64)
        elif is_float64:
            tensor = math_ops.cast(tensor, dtypes.float64)
    else:
        tensor = gen_collective_ops.collective_reduce(input=tensor, group_size=len(devices), group_key=_GROUP_KEY, instance_key=_get_instance_key(), merge_op='Add', final_op='Id', subdiv_offsets=(0,))
    return tf_np.asarray(tensor)

Sum all-reduction.

Args:
tensor: A tensor.
axis_name: The axis name to reduce. Must equal to that of the surrounding
pmap.

Returns:
The sum of the `tensor` replicas on each participating devices.


def add_arguments(self, parser):

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument('-d', '--downgrade', action='store_true',
                           help='downgrade the J-Link firmware')
        group.add_argument('-u', '--upgrade', action='store_true',
                           help='upgrade the J-Link firmware')
        return self.add_common_arguments(parser, False)

Adds the arguments for the firmware command.

Args:
self (FirmwareCommand): the ``FirmwareCommand`` instance
parser (argparse.ArgumentParser): parser to add the commands to

Returns:
``None``


def find_log_dir(log_dir=None):

  if log_dir:

    dirs = [log_dir]
  elif FLAGS['log_dir'].value:

    dirs = [FLAGS['log_dir'].value]
  else:
    dirs = ['/tmp/', './']

  for d in dirs:
    if os.path.isdir(d) and os.access(d, os.W_OK):
      return d
  _absl_logger.fatal("Can't find a writable directory for logs, tried %s", dirs)

Returns the most suitable directory to put log files into.

Args:
log_dir: str|None, if specified, the logfile(s) will be created in that
directory.  Otherwise if the --log_dir command-line flag is provided,
the logfile will be created in that directory.  Otherwise the logfile
will be created in a standard location.


def min(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs):

        axis = self._get_axis_number(axis) if axis is not None else 0
        data = self._validate_dtypes_min_max(axis, numeric_only)
        return data._reduce_dimension(
            data._query_compiler.min(
                axis=axis,
                skipna=skipna,
                level=level,
                numeric_only=numeric_only,
                **kwargs
            )
        )

Perform min across the DataFrame.

Args:
axis (int): The axis to take the min on.
skipna (bool): True to skip NA values, false otherwise.

Returns:
The min of the DataFrame.


def atomic_write_string_to_file(filename, contents, overwrite):
    temp_pathname = ((tf.compat.as_bytes(filename) + tf.compat.as_bytes('.tmp')) + tf.compat.as_bytes(uuid.uuid4().hex))
    with tf_v1.gfile.GFile(temp_pathname, mode='w') as f:
        f.write(contents)
    try:
        tf_v1.gfile.Rename(temp_pathname, filename, overwrite)
    except tf.errors.OpError:
        tf_v1.gfile.Remove(temp_pathname)
        raise

Writes to `filename` atomically.

This means that when `filename` appears in the filesystem, it will contain
all of `contents`. With write_string_to_file, it is possible for the file
to appear in the filesystem with `contents` only partially written.

Accomplished by writing to a temp file and then renaming it.

Args:
filename: string, pathname for a file
contents: string, contents that need to be written to the file
overwrite: boolean, if false it's an error for `filename` to be occupied by
an existing file.


def push_file(self, source, dest_dir):
    local_dest = ((dest_dir + '/') + os.path.basename(source))
    if (os.path.dirname(source) != dest_dir):
        try:
            shutil.copyfile(source, local_dest)
            os.chmod(local_dest, 511)
        except OSError as e:
            raise FileCopyException(e, self.hostname)
    return local_dest

If the source files dirpath is the same as dest_dir, a copy
is not necessary, and nothing is done. Else a copy is made.

Args:
- source (string) : Path to the source file
- dest_dir (string) : Path to the directory to which the files is to be copied

Returns:
- destination_path (String) : Absolute path of the destination file

Raises:
- FileCopyException : If file copy failed.


def add_subassistants_to(cls, parser, assistant_tuple, level, alias=None):
    name = (alias or assistant_tuple[0].name)
    p = parser.add_parser(name, description=assistant_tuple[0].description, argument_default=argparse.SUPPRESS)
    for arg in assistant_tuple[0].args:
        arg.add_argument_to(p)
    if (len(assistant_tuple[1]) > 0):
        subparsers = cls._add_subparsers_required(p, dest=settings.SUBASSISTANT_N_STRING.format(level), title=cls.subparsers_str, description=cls.subparsers_desc)
        for subas_tuple in sorted(assistant_tuple[1], key=(lambda x: x[0].name)):
            cls.add_subassistants_to(subparsers, subas_tuple, (level + 1))
    elif (level == 1):
        subparsers = cls._add_subparsers_required(p, dest=settings.SUBASSISTANT_N_STRING.format(level), title=cls.subparsers_str, description=devassistant_argparse.ArgumentParser.no_assistants_msg)

Adds assistant from given part of assistant tree and all its subassistants to
a given argument parser.

Args:
parser: instance of devassistant_argparse.ArgumentParser
assistant_tuple: part of assistant tree (see generate_argument_parser doc)
level: level of subassistants that given assistant is at


def get_schema_node(self, path: SchemaPath) -> Optional[SchemaNode]:
    return self.schema.get_schema_descendant(self.schema_data.path2route(path))

Return the schema node addressed by a schema path.

Args:
path: Schema path.

Returns:
Schema node if found in the schema, or ``None``.

Raises:
InvalidSchemaPath: If the schema path is invalid.


def _create(cls, user_agent=None, user_agent_config_yaml=None, user_agent_lookup=None, **kwargs):
    kwargs = UserAgent._environment_variables(**kwargs)
    if ('user_agent' in kwargs):
        user_agent = kwargs['user_agent']
        del kwargs['user_agent']
    prefix = kwargs.get('prefix')
    if prefix:
        del kwargs['prefix']
    else:
        prefix = ('HDXPythonUtilities/%s' % get_utils_version())
    if (not user_agent):
        ua = cls._load(prefix, user_agent_config_yaml, user_agent_lookup)
    else:
        ua = cls._construct(kwargs, prefix, user_agent)
    return ua

Get full user agent string

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

Returns:
str: Full user agent string


def connect(self):
    if self.is_connected():
        raise tornado.gen.Return(True)
    cb1 = self._read_callback
    cb2 = self._close_callback
    self.__callback_queue = collections.deque()
    self._reply_list = []
    self.__reader = hiredis.Reader(replyError=ClientError)
    kwargs = self.connection_kwargs
    self.__connection = Connection(cb1, cb2, **kwargs)
    connection_status = (yield self.__connection.connect())
    if (connection_status is not True):
        raise tornado.gen.Return(False)
    if (self.password is not None):
        authentication_status = (yield self._call('AUTH', self.password))
        if (authentication_status != b'OK'):
            LOG.warning('impossible to connect: bad password')
            self.__connection.disconnect()
            raise tornado.gen.Return(False)
    if (self.db != 0):
        db_status = (yield self._call('SELECT', self.db))
        if (db_status != b'OK'):
            LOG.warning("can't select db %s", self.db)
            raise tornado.gen.Return(False)
    raise tornado.gen.Return(True)

Connects the client object to redis.

It's safe to use this method even if you are already connected.
Note: this method is useless with autoconnect mode (default).

Returns:
a Future object with True as result if the connection was ok.


def get_regularization_loss(scope=None, name='total_regularization_loss'):
    losses = get_regularization_losses(scope)
    if losses:
        return math_ops.add_n(losses, name=name)
    else:
        return constant_op.constant(0.0)

Gets the total regularization loss.

Args:
scope: An optional scope name for filtering the losses to return.
name: The name of the returned tensor.

Returns:
A scalar regularization loss.