def add_node(self, node_descriptor):

        if self._max_nodes is not None and len(self.nodes) >= self._max_nodes:
            raise ResourceUsageError("Maximum number of nodes exceeded", max_nodes=self._max_nodes)

        node, inputs, processor = parse_node_descriptor(node_descriptor, self.model)

        in_root = False

        for i, input_data in enumerate(inputs):
            selector, trigger = input_data

            walker = self.sensor_log.create_walker(selector)

            # Constant walkers begin life initialized to 0 so they always read correctly
            if walker.selector.inexhaustible:
                walker.reading = IOTileReading(0xFFFFFFFF, walker.selector.as_stream(), 0)

            node.connect_input(i, walker, trigger)

            if selector.input and not in_root:
                self.roots.append(node)
                in_root = True  # Make sure we only add to root list once
            else:
                found = False
                for other in self.nodes:
                    if selector.matches(other.stream):
                        other.connect_output(node)
                        found = True

                if not found and selector.buffered:
                    raise NodeConnectionError("Node has input that refers to another node that has not been created yet", node_descriptor=node_descriptor, input_selector=str(selector), input_index=i)

        # Also make sure we add this node's output to any other existing node's inputs
        # this is important for constant nodes that may be written from multiple places
        # FIXME: Make sure when we emit nodes, they are topologically sorted
        for other_node in self.nodes:
            for selector, trigger in other_node.inputs:
                if selector.matches(node.stream):
                    node.connect_output(other_node)

        # Find and load the processing function for this node
        func = self.find_processing_function(processor)
        if func is None:
            raise ProcessingFunctionError("Could not find processing function in installed packages", func_name=processor)

        node.set_func(processor, func)
        self.nodes.append(node)

Add a node to the sensor graph based on the description given.

    The node_descriptor must follow the sensor graph DSL and describe
    a node whose input nodes already exist.

Args:
        node_descriptor (str): A description of the node to be added
            including its inputs, triggering conditions, processing function
            and output stream.


def print_res(data):

    print('===================================')
    main_part = data['data']
    print(main_part['word_name'])
    symbols = main_part['symbols'][0]
    print("美式音标：[" + symbols['ph_am'] + "]")
    print("英式音标：[" + symbols['ph_en'] + "]")
    print('-----------------------------------')
    parts = symbols['parts']
    for part in parts:
        print(part['part'])
        for mean in part['means']:
            print("    ", mean)
    print('===================================')

Print translate result in a better format

Args:
        data(str): result


def __init__(self, option_strings, dest, help, metavar, flag_instance):  # pylint: disable=redefined-builtin

    del dest
    self._flag_instance = flag_instance
    super(_FlagAction, self).__init__(
        option_strings=option_strings,
        dest=argparse.SUPPRESS,
        help=help,
        metavar=metavar)

Initializes _FlagAction.

Args:
        option_strings: See argparse.Action.
        dest: Ignored. The flag is always defined with dest=argparse.SUPPRESS.
        help: See argparse.Action.
        metavar: See argparse.Action.
        flag_instance: absl.flags.Flag, the absl flag instance.


def remove_room_alias(self, room_alias):

        try:
            self.api.remove_room_alias(room_alias)
            return True
        except MatrixRequestError:
            return False

Remove mapping of an alias

Args:
        room_alias(str): The alias to be removed.

Returns:
        bool: True if the alias is removed, False otherwise.


def sort_resources(cls, request, resources, fail_enum, header_proto=None):

        if not request.sorting:
            return resources

        value_handlers = cls._get_handler_set(request, fail_enum, header_proto)

        def sorter(resource_a, resource_b):
            for handler in value_handlers:
                val_a, val_b = handler.get_sort_values(resource_a, resource_b)

                if val_a < val_b:
                    return handler.xform_result(-1)
                if val_a > val_b:
                    return handler.xform_result(1)

            return 0

        return sorted(resources, key=cmp_to_key(sorter))

Sorts a list of resources based on a list of sort controls

Args:
        request (object): The parsed protobuf request object
        resources (list of objects): The resources to be sorted
        fail_enum (int, enum): The enum status to raise with invalid keys
        header_proto(class): Class to decode a resources header

Returns:
        list: The sorted list of resources


def generate_defect_structure(self, supercell=(1, 1, 1)):

        defect_structure = self.bulk_structure.copy()
        defect_structure.make_supercell(supercell)

        #create a trivial defect structure to find where supercell transformation moves the lattice
        struct_for_defect_site = Structure( self.bulk_structure.copy().lattice,
                                             [self.site.specie],
                                             [self.site.frac_coords],
                                             to_unit_cell=True)
        struct_for_defect_site.make_supercell(supercell)
        defect_site = struct_for_defect_site[0]

        poss_deflist = sorted(
            defect_structure.get_sites_in_sphere(defect_site.coords, 2, include_index=True), key=lambda x: x[1])
        defindex = poss_deflist[0][2]
        defect_structure.remove_sites([defindex])
        defect_structure.set_charge(self.charge)
        return defect_structure

Returns Defective Vacancy structure, decorated with charge

Args:
        supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix


def ReadResponsesForRequestId(self, session_id, request_id, timestamp=None):

    request = rdf_flow_runner.RequestState(id=request_id, session_id=session_id)
    for _, responses in self.ReadResponses([request], timestamp=timestamp):
      return responses

Reads responses for one request.

Args:
        session_id: The session id to use.
        request_id: The id of the request.
        timestamp: A timestamp as used in the data store.

Yields:
        fetched responses for the request


def idcode(msg):

    if df(msg) not in [5, 21]:
        raise RuntimeError("Message must be Downlink Format 5 or 21.")

    mbin = hex2bin(msg)

    C1 = mbin[19]
    A1 = mbin[20]
    C2 = mbin[21]
    A2 = mbin[22]
    C4 = mbin[23]
    A4 = mbin[24]
    # _ = mbin[25]
    B1 = mbin[26]
    D1 = mbin[27]
    B2 = mbin[28]
    D2 = mbin[29]
    B4 = mbin[30]
    D4 = mbin[31]

    byte1 = int(A4+A2+A1, 2)
    byte2 = int(B4+B2+B1, 2)
    byte3 = int(C4+C2+C1, 2)
    byte4 = int(D4+D2+D1, 2)

    return str(byte1) + str(byte2) + str(byte3) + str(byte4)

Computes identity (squawk code) from DF5 or DF21 message, bit 20-32.
    credit: @fbyrkjeland

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

Returns:
        string: squawk code


def CheckForHeaderGuard(filename, clean_lines, error):

  # Don't check for header guards if there are error suppression
  # comments somewhere in this file.
  #
  # Because this is silencing a warning for a nonexistent line, we
  # only support the very specific NOLINT(build/header_guard) syntax,
  # and not the general NOLINT or NOLINT(*) syntax.
  raw_lines = clean_lines.lines_without_raw_strings
  for i in raw_lines:
    if Search(r'//\s*NOLINT\(build/header_guard\)', i):
      return

  # Allow pragma once instead of header guards
  for i in raw_lines:
    if Search(r'^\s*#pragma\s+once', i):
      return

  cppvar = GetHeaderGuardCPPVariable(filename)

  ifndef = ''
  ifndef_linenum = 0
  define = ''
  endif = ''
  endif_linenum = 0
  for linenum, line in enumerate(raw_lines):
    linesplit = line.split()
    if len(linesplit) >= 2:
      # find the first occurrence of #ifndef and #define, save arg
      if not ifndef and linesplit[0] == '#ifndef':
        # set ifndef to the header guard presented on the #ifndef line.
        ifndef = linesplit[1]
        ifndef_linenum = linenum
      if not define and linesplit[0] == '#define':
        define = linesplit[1]
    # find the last occurrence of #endif, save entire line
    if line.startswith('#endif'):
      endif = line
      endif_linenum = linenum

  if not ifndef or not define or ifndef != define:
    error(filename, 0, 'build/header_guard', 5,
          'No #ifndef header guard found, suggested CPP variable is: %s' %
          cppvar)
    return

  # The guard should be PATH_FILE_H_, but we also allow PATH_FILE_H__
  # for backward compatibility.
  if ifndef != cppvar:
    error_level = 0
    if ifndef != cppvar + '_':
      error_level = 5

    ParseNolintSuppressions(filename, raw_lines[ifndef_linenum], ifndef_linenum,
                            error)
    error(filename, ifndef_linenum, 'build/header_guard', error_level,
          '#ifndef header guard has wrong style, please use: %s' % cppvar)

  # Check for "//" comments on endif line.
  ParseNolintSuppressions(filename, raw_lines[endif_linenum], endif_linenum,
                          error)
  match = Match(r'#endif\s*//\s*' + cppvar + r'(_)?\b', endif)
  if match:
    if match.group(1) == '_':
      # Issue low severity warning for deprecated double trailing underscore
      error(filename, endif_linenum, 'build/header_guard', 0,
            '#endif line should be "#endif  // %s"' % cppvar)
    return

  # Didn't find the corresponding "//" comment.  If this file does not
  # contain any "//" comments at all, it could be that the compiler
  # only wants "/**/" comments, look for those instead.
  no_single_line_comments = True
  for i in xrange(1, len(raw_lines) - 1):
    line = raw_lines[i]
    if Match(r'^(?:(?:\'(?:\.|[^\'])*\')|(?:"(?:\.|[^"])*")|[^\'"])*//', line):
      no_single_line_comments = False
      break

  if no_single_line_comments:
    match = Match(r'#endif\s*/\*\s*' + cppvar + r'(_)?\s*\*/', endif)
    if match:
      if match.group(1) == '_':
        # Low severity warning for double trailing underscore
        error(filename, endif_linenum, 'build/header_guard', 0,
              '#endif line should be "#endif  /* %s */"' % cppvar)
      return

  # Didn't find anything
  error(filename, endif_linenum, 'build/header_guard', 5,
        '#endif line should be "#endif  // %s"' % cppvar)

Checks that the file contains a header guard.

    Logs an error if no #ifndef header guard is present.  For other
    headers, checks that the full pathname is used.

Args:
        filename: The name of the C++ header file.
        clean_lines: A CleansedLines instance containing the file.
        error: The function to call with any errors found.


def delta_E( self ):

        site_delta_E = self.final_site.energy - self.initial_site.energy
        if self.nearest_neighbour_energy:
            site_delta_E += self.nearest_neighbour_delta_E()
        if self.coordination_number_energy:
            site_delta_E += self.coordination_number_delta_E()
        return site_delta_E

The change in system energy if this jump were accepted.

Args:
        None

Returns:
        (Float): delta E


def _Open(self, path_spec, mode='rb'):

    if not path_spec.HasParent():
      raise errors.PathSpecError(
          'Unsupported path specification without parent.')

    resolver.Resolver.key_chain.ExtractCredentialsFromPathSpec(path_spec)

    bde_volume = pybde.volume()
    file_object = resolver.Resolver.OpenFileObject(
        path_spec.parent, resolver_context=self._resolver_context)

    try:
      bde.BDEVolumeOpen(
          bde_volume, path_spec, file_object, resolver.Resolver.key_chain)
    except:
      file_object.close()
      raise

    self._bde_volume = bde_volume
    self._file_object = file_object

Opens the file system defined by path specification.

Args:
        path_spec (PathSpec): path specification.
        mode (Optional[str]): file access mode. The default is 'rb'
        read-only binary.

Raises:
        AccessError: if the access to open the file was denied.
        IOError: if the file system could not be opened.
        PathSpecError: if the path specification is incorrect.
        ValueError: if the path specification is invalid.


def group_id(self, resource_id):

        if self._name != 'group':
            self._request_uri = '{}/{}'.format(self._api_uri, resource_id)

Update the request URI to include the Group ID for specific group retrieval.

Args:
        resource_id (string): The group id.


def get_gain(data, attr, class_attr,
    method=DEFAULT_DISCRETE_METRIC,
    only_sub=0, prefer_fewer_values=False, entropy_func=None):

    entropy_func = entropy_func or entropy
    val_freq = defaultdict(float)
    subset_entropy = 0.0

    # Calculate the frequency of each of the values in the target attribute
    for record in data:
        val_freq[record.get(attr)] += 1.0

    # Calculate the sum of the entropy for each subset of records weighted
    # by their probability of occuring in the training set.
    for val in val_freq.keys():
        val_prob = val_freq[val] / sum(val_freq.values())
        data_subset = [record for record in data if record.get(attr) == val]
        e = entropy_func(data_subset, class_attr, method=method)
        subset_entropy += val_prob * e

    if only_sub:
        return subset_entropy

    # Subtract the entropy of the chosen attribute from the entropy of the
    # whole data set with respect to the target attribute (and return it)
    main_entropy = entropy_func(data, class_attr, method=method)

    # Prefer gains on attributes with fewer values.
    if prefer_fewer_values:
#        n = len(val_freq)
#        w = (n+1)/float(n)/2
        #return (main_entropy - subset_entropy)*w
        return ((main_entropy - subset_entropy), 1./len(val_freq))
    else:
        return (main_entropy - subset_entropy)

Calculates the information gain (reduction in entropy) that would
    result by splitting the data on the chosen attribute (attr).

    Parameters:

    prefer_fewer_values := Weights the gain by the count of the attribute's
        unique values. If multiple attributes have the same gain, but one has
        slightly fewer attributes, this will cause the one with fewer
        attributes to be preferred.


def get(cls, issue_type):

        if isinstance(issue_type, str):
            obj = getattr(db, cls.__name__).find_one(cls.issue_type == issue_type)

        elif isinstance(issue_type, int):
            obj = getattr(db, cls.__name__).find_one(cls.issue_type_id == issue_type)

        elif isinstance(issue_type, cls):
            return issue_type

        else:
            obj = None

        if not obj:
            obj = cls()
            obj.issue_type = issue_type

            db.session.add(obj)
            db.session.commit()
            db.session.refresh(obj)

        return obj

Returns the IssueType object for `issue_type`. If no existing object was found, a new type will
    be created in the database and returned

Args:
        issue_type (str,int,IssueType): Issue type name, id or class

Returns:
        :obj:`IssueType`


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

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

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

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

            # Update marketing urls in course metadata to include enterprise related info.
            marketing_url = course_run.get('marketing_url')
            if marketing_url:
                query_parameters = dict(enterprise_context, **utils.get_enterprise_utm_context(enterprise_customer))
                course_run.update({'marketing_url': utils.update_query_parameters(marketing_url, query_parameters)})

            # Add updated course run to the list.
            updated_course_runs.append(course_run)
        return updated_course_runs

Update Marketing urls in course metadata and return updated course.

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

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


def insert_infocontent_data(germanet_db):

    gnet           = germanet.GermaNet(germanet_db)
    # use add one smoothing
    gn_counts      = defaultdict(lambda: 1.)
    total_count    = 1
    input_file     = gzip.open(os.path.join(os.path.dirname(__file__),
                                            WORD_COUNT_FILE))
    num_lines_read = 0
    num_lines      = 0
    for line in input_file:
        line       = line.decode('utf-8').strip().split('\t')
        num_lines += 1
        if len(line) != 3:
            continue
        count, pos, word = line
        num_lines_read += 1
        count           = int(count)
        synsets         = set(gnet.synsets(word, pos))
        if not synsets:
            continue
        # Although Resnik (1995) suggests dividing count by the number
        # of synsets, Patwardhan et al (2003) argue against doing
        # this.
        count = float(count) / len(synsets)
        for synset in synsets:
            total_count += count
            paths = synset.hypernym_paths
            scount = float(count) / len(paths)
            for path in paths:
                for ss in path:
                    gn_counts[ss._id] += scount
    print('Read {0} of {1} lines from count file.'.format(num_lines_read,
                                                          num_lines))
    print('Recorded counts for {0} synsets.'.format(len(gn_counts)))
    print('Total count is {0}'.format(total_count))
    input_file.close()
    # update all the synset records in GermaNet
    num_updates = 0
    for synset in germanet_db.synsets.find():
        synset['infocont'] = gn_counts[synset['_id']] / total_count
        germanet_db.synsets.save(synset)
        num_updates += 1
    print('Updated {0} synsets.'.format(num_updates))

For every synset in GermaNet, inserts count information derived
    from SDEWAC.

Args:
    - `germanet_db`: a pymongo.database.Database object


def initialize(self, map_arr, start_point_label="S", end_point_label="G", wall_label="#", agent_label="@"):

        np.set_printoptions(threshold=np.inf)

        self.__agent_label = agent_label
        self.__map_arr = map_arr
        self.__start_point_label = start_point_label
        start_arr_tuple = np.where(self.__map_arr == self.__start_point_label)
        x_arr, y_arr = start_arr_tuple
        self.__start_point_tuple = (x_arr[0], y_arr[0])
        end_arr_tuple = np.where(self.__map_arr == self.__end_point_label)
        x_arr, y_arr = end_arr_tuple
        self.__end_point_tuple = (x_arr[0], y_arr[0])
        self.__wall_label = wall_label

        for x in range(self.__map_arr.shape[1]):
            for y in range(self.__map_arr.shape[0]):
                if (x, y) == self.__start_point_tuple or (x, y) == self.__end_point_tuple:
                    continue
                arr_value = self.__map_arr[y][x]
                if arr_value == self.__wall_label:
                    continue

                self.save_r_df((x, y), float(arr_value))

Initialize map of maze and setup reward value.

Args:
        map_arr:              Map. the 2d- `np.ndarray`.
        start_point_label:    Label of start point.
        end_point_label:      Label of end point.
        wall_label:           Label of wall.
        agent_label:          Label of agent.


def configs_for_writer(writer=None, ppp_config_dir=None):

    search_paths = (ppp_config_dir,) if ppp_config_dir else tuple()
    if writer is not None:
        if not isinstance(writer, (list, tuple)):
            writer = [writer]
        # given a config filename or writer name
        config_files = [w if w.endswith('.yaml') else w + '.yaml' for w in writer]
    else:
        writer_configs = glob_config(os.path.join('writers', '*.yaml'),
                                     *search_paths)
        config_files = set(writer_configs)

    for config_file in config_files:
        config_basename = os.path.basename(config_file)
        writer_configs = config_search_paths(
            os.path.join("writers", config_basename), *search_paths)

        if not writer_configs:
            LOG.warning("No writer configs found for '%s'", writer)
            continue

        yield writer_configs

Generator of writer configuration files for one or more writers

Args:
        writer (Optional[str]): Yield configs only for this writer
        ppp_config_dir (Optional[str]): Additional configuration directory
            to search for writer configuration files.

    Returns: Generator of lists of configuration files


def new(self, length, fp, manage_fp, offset):
        # type: (int, BinaryIO, bool, int) -> None

        if self._initialized:
            raise pycdlibexception.PyCdlibInternalError('Inode is already initialized')

        self.data_length = length

        self.data_fp = fp
        self.manage_fp = manage_fp
        self.fp_offset = offset
        self.original_data_location = self.DATA_IN_EXTERNAL_FP

        self._initialized = True

Initialize a new Inode.

    Parameters:
    None.

Returns:
    Nothing.


def needkwargs(*argnames):

    required = set(argnames)

    def decorator(func):
        def inner(*args, **kwargs):
            missing = required - set(kwargs)
            if missing:
                err = "%s kwargs are missing." % list(missing)
                raise ValueError(err)
            return func(*args, **kwargs)
        return inner
    return decorator

Function decorator which checks that the decorated function is called
    with a set of required kwargs.

Args:
        *argnames: String keyword argument names.

Raises:
        ValueError: If a required kwarg is missing in the decorated function
            call.


def __init__(self, editor):

        self.editor = editor
        self.timer = QTimer(self.editor)
        self.timer.setSingleShot(True)
        self.timer.timeout.connect(self.do_autosave)
        self._enabled = False  # Can't use setter here
        self._interval = self.DEFAULT_AUTOSAVE_INTERVAL

Constructor.

    Autosave is disabled after construction and needs to be enabled
    explicitly if required.

Args:
        editor (Editor): editor plugin.


def _activation_summary(x):

  # Remove 'tower_[0-9]/' from the name in case this is a multi-GPU training
  # session. This helps the clarity of presentation on tensorboard.
  tensor_name = re.sub('%s_[0-9]*/' % TOWER_NAME, '', x.op.name)
  tf.summary.histogram(tensor_name + '/activations', x)
  tf.summary.scalar(tensor_name + '/sparsity',
                                       tf.nn.zero_fraction(x))

Helper to create summaries for activations.

    Creates a summary that provides a histogram of activations.
    Creates a summary that measures the sparsity of activations.

Args:
        x: Tensor

Returns:
        nothing


def check_runtime_errors(cmd_derived_from_alias, pos_args_table):

    for placeholder, value in pos_args_table.items():
        exec('{} = "{}"'.format(placeholder, value))  # pylint: disable=exec-used

    expressions = get_placeholders(cmd_derived_from_alias)
    for expression in expressions:
        try:
            exec(expression)  # pylint: disable=exec-used
        except Exception as exception:  # pylint: disable=broad-except
            error_msg = PLACEHOLDER_EVAL_ERROR.format(expression, exception)
            raise CLIError(error_msg)

Validate placeholders and their expressions in cmd_derived_from_alias to make sure
    that there is no runtime error (such as index out of range).

Args:
        cmd_derived_from_alias: The command derived from the alias
            (include any positional argument placehodlers)
        pos_args_table: The positional argument table.


def __init__(self, prefix, section, filename=None):

        options = dict(prefix=prefix, section=section, filename=filename)

        super(Settings, self).__init__(**options)

Will try to read configuration from environment variables and ini
    files, if no value found in either of those ``None`` is
    returned.

Args:
        prefix: The environment variable prefix.
        section: The ini file section this configuration is scoped to
        filename: The path to the ini file to use


def has_all_nonzero_section_lengths(neuron, threshold=0.0):

    bad_ids = [s.id for s in _nf.iter_sections(neuron.neurites)
               if section_length(s.points) <= threshold]

    return CheckResult(len(bad_ids) == 0, bad_ids)

Check presence of neuron sections with length not above threshold

Args:
        neuron(Neuron): The neuron object to test
        threshold(float): value above which a section length is considered
        to be non-zero

Returns:
        CheckResult with result including list of ids of bad sections


def ConfigureLogging(
    debug_output=False, filename=None, mode='w', quiet_mode=False):

  # Remove all possible log handlers. The log handlers cannot be reconfigured
  # and therefore must be recreated.
  for handler in logging.root.handlers:
    logging.root.removeHandler(handler)

  logger = logging.getLogger()

  if filename and filename.endswith('.gz'):
    handler = CompressedFileHandler(filename, mode=mode)
  elif filename:
    handler = logging.FileHandler(filename, mode=mode)
  else:
    handler = logging.StreamHandler()

  format_string = (
      '%(asctime)s [%(levelname)s] (%(processName)-10s) PID:%(process)d '
      '<%(module)s> %(message)s')

  formatter = logging.Formatter(format_string)
  handler.setFormatter(formatter)

  if debug_output:
    level = logging.DEBUG
  elif quiet_mode:
    level = logging.WARNING
  else:
    level = logging.INFO

  logger.setLevel(level)
  handler.setLevel(level)

  logger.addHandler(handler)

Configures the logging root logger.

Args:
        debug_output (Optional[bool]): True if the logging should include debug
        output.
        filename (Optional[str]): log filename.
        mode (Optional[str]): log file access mode.
        quiet_mode (Optional[bool]): True if the logging should not include
        information output. Note that debug_output takes precedence over
        quiet_mode.


def normalise(self, to_currency):

        out = Money(currency=to_currency)
        for money in self._money_obs:
            out += converter.convert(money, to_currency)
        return Balance([out])

Normalise this balance into a single currency

Args:
        to_currency (str): Destination currency

Returns:
        (Balance): A new balance object containing a single Money value in the specified currency


def delete_namespace(self, name, ignore_errors=False):

        if self.has_namespace(name):
            del self.namespaces[name]
            return True
        elif ignore_errors:
            return True
        else:
            raise RuntimeError("namespace '%s' does not exist" % name)

deletes a namespace

Args:
        name: the name of the namespace
        ignore_errors(bool): Will ignore if a namespace doesn not exist or
                there is an error deleting the namespace

Returns:
        True if deleted
        False if not deleted
        error if namespace already exists


def _GetPathSegmentIndexForSimilarityWeights(
      self, similarity_weights, occurrence_weights, value_weights):

    largest_weight = similarity_weights.GetLargestWeight()

    if largest_weight > 0:
      similarity_weight_indexes = similarity_weights.GetIndexesForWeight(
          largest_weight)
      number_of_similarity_indexes = len(similarity_weight_indexes)
    else:
      number_of_similarity_indexes = 0

    path_segment_index = None
    if number_of_similarity_indexes == 0:
      path_segment_index = self._GetPathSegmentIndexForOccurrenceWeights(
          occurrence_weights, value_weights)

    elif number_of_similarity_indexes == 1:
      path_segment_index = similarity_weight_indexes[0]

    else:
      largest_weight = 0
      largest_value_weight = 0

      for similarity_index in similarity_weight_indexes:
        occurrence_weight = occurrence_weights.GetWeightForIndex(
            similarity_index)

        if largest_weight > 0 and largest_weight == occurrence_weight:
          value_weight = value_weights.GetWeightForIndex(similarity_index)

          if largest_value_weight < value_weight:
            largest_weight = 0

        if not path_segment_index or largest_weight < occurrence_weight:
          largest_weight = occurrence_weight
          path_segment_index = similarity_index

          largest_value_weight = value_weights.GetWeightForIndex(
              similarity_index)

    return path_segment_index

Retrieves the index of the path segment based on similarity weights.

Args:
        similarity_weights: the similarity weights object (instance of
                        _PathSegmentWeights).
        occurrence_weights: the occurrence weights object (instance of
                        _PathSegmentWeights).
        value_weights: the value weights object (instance of _PathSegmentWeights).

Returns:
        An integer containing the path segment index.


def to_add_skip_model(self, start_id, end_id):

        self.operation_history.append(("to_add_skip_model", start_id, end_id))
        filters_end = self.layer_list[end_id].output.shape[-1]
        filters_start = self.layer_list[start_id].output.shape[-1]
        start_node_id = self.layer_id_to_output_node_ids[start_id][0]

        pre_end_node_id = self.layer_id_to_input_node_ids[end_id][0]
        end_node_id = self.layer_id_to_output_node_ids[end_id][0]

        skip_output_id = self._insert_pooling_layer_chain(start_node_id, end_node_id)

        # Add the conv layer
        new_conv_layer = get_conv_class(self.n_dim)(filters_start, filters_end, 1)
        skip_output_id = self.add_layer(new_conv_layer, skip_output_id)

        # Add the add layer.
        add_input_node_id = self._add_node(deepcopy(self.node_list[end_node_id]))
        add_layer = StubAdd()

        self._redirect_edge(pre_end_node_id, end_node_id, add_input_node_id)
        self._add_edge(add_layer, add_input_node_id, end_node_id)
        self._add_edge(add_layer, skip_output_id, end_node_id)
        add_layer.input = [
            self.node_list[add_input_node_id],
            self.node_list[skip_output_id],
        ]
        add_layer.output = self.node_list[end_node_id]
        self.node_list[end_node_id].shape = add_layer.output_shape

        # Set weights to the additional conv layer.
        if self.weighted:
            filter_shape = (1,) * self.n_dim
            weights = np.zeros((filters_end, filters_start) + filter_shape)
            bias = np.zeros(filters_end)
            new_conv_layer.set_weights(
                (add_noise(weights, np.array([0, 1])), add_noise(bias, np.array([0, 1])))
            )

Add a weighted add skip-connection from after start node to end node.

Args:
        start_id: The convolutional layer ID, after which to start the skip-connection.
        end_id: The convolutional layer ID, after which to end the skip-connection.


def crcMeterRead(self, raw_read, def_buf):

        try:
            if len(raw_read) == 0:
                ekm_log("(" + self.m_context + ") Empty return read.")
                return False
            sent_crc = self.calc_crc16(raw_read[1:-2])
            logstr = "(" + self.m_context + ")CRC sent = " + str(def_buf["crc16"][MeterData.StringValue])
            logstr += " CRC calc = " + sent_crc
            ekm_log(logstr)
            if int(def_buf["crc16"][MeterData.StringValue], 16) == int(sent_crc, 16):
                return True

        # A cross simple test lines on a USB serial adapter, these occur every
        # 1000 to 2000 reads, and they show up here as a bad unpack or
        # a bad crc type call.  In either case, we suppress them a log will
        # become quite large.  ekmcrc errors come through as type errors.
        # Failures of int type conversion in 16 bit conversion occur as value
        # errors.
        except struct.error:
            ekm_log(str(sys.exc_info()))
            for frame in traceback.extract_tb(sys.exc_info()[2]):
                fname, lineno, fn, text = frame
                ekm_log("Error in %s on line %d" % (fname, lineno))
            return False

        except TypeError:
            ekm_log(str(sys.exc_info()))
            for frame in traceback.extract_tb(sys.exc_info()[2]):
                fname, lineno, fn, text = frame
                ekm_log("Error in %s on line %d" % (fname, lineno))
            return False

        except ValueError:
            ekm_log(str(sys.exc_info()))
            for frame in traceback.extract_tb(sys.exc_info()[2]):
                fname, lineno, fn, text = frame
                ekm_log("Error in %s on line %d" % (fname, lineno))
            return False

        return False

Internal read CRC wrapper.

Args:
        raw_read (str): Bytes with implicit string cast from serial read
        def_buf (SerialBlock): Populated read buffer.

Returns:
        bool:  True if passed CRC equals calculated CRC.


def dfa(self, ttab: TransitionTable, init: int = 0) -> int:

        state = init
        while True:
            disp = ttab[state]
            ch = self.peek()
            state = disp.get(ch, disp[""])()
            if state < 0:
                return state
            self.offset += 1

Run a DFA and return the final (negative) state.

Args:
        ttab: Transition table (with possible side-effects).
        init: Initial state.

Raises:
        EndOfInput: If past the end of `self.input`.


def _get_resource_view(self, resource_view):
        # type: (Union[ResourceView,Dict]) -> ResourceView

        if isinstance(resource_view, dict):
            resource_view = ResourceView(resource_view, configuration=self.configuration)
        if isinstance(resource_view, ResourceView):
            return resource_view
        raise HDXError('Type %s is not a valid resource view!' % type(resource_view).__name__)

Get resource view id

Args:
        resource_view (Union[ResourceView,Dict]): ResourceView metadata from a ResourceView object or dictionary

Returns:
        ResourceView: ResourceView object


def GetRequestXML(self, method, *args):

    self.suds_client.set_options(nosend=True)
    service_request = (getattr(self, method))(*args).envelope
    self.suds_client.set_options(nosend=False)
    return lxml.etree.fromstring(service_request)

Get the raw SOAP XML for a request.

Args:
        method: The method name.
        *args: A list of arguments to be passed to the method.

Returns:
        An element containing the raw XML that would be sent as the request.


def __eq__(self, other):

        res = False
        if type(self) is type(other) and \
                self.name == other.name and \
                self.size == other.size:
            res = True
        return res

Two Registers are the same if they are of the same type
    (i.e. quantum/classical), and have the same name and size.

Args:
        other (Register): other Register

Returns:
        bool: are self and other equal.


def remove(self, path, dir_fd=None):

        path = self._path_with_dir_fd(path, self.remove, dir_fd)
        self.filesystem.remove(path)

Remove the FakeFile object at the specified file path.

Args:
        path: Path to file to be removed.
        dir_fd: If not `None`, the file descriptor of a directory,
            with `path` being relative to this directory.
            New in Python 3.3.

Raises:
        OSError: if path points to a directory.
        OSError: if path does not exist.
        OSError: if removal failed.


def sum(x, axis=None, keepdims=False):

    from .function_bases import sum as sum_base
    if axis is None:
        axis = range(x.ndim)
    elif not hasattr(axis, '__iter__'):
        axis = [axis]
    return sum_base(x, axis, keepdims)

Reduction along axes with sum operation.

Args:
        x (Variable): An input variable.
        axis (None, int or tuple of ints): Axis or axes along which the sum is
            calculated. Passing the default value `None` will reduce all dimensions.
        keepdims (bool): Flag whether the reduced axes are kept as a dimension with 1 element.

Returns:
        ~nnabla.Variable: N-D array.


def attribute(*args, **kw):

    return operator(kind=Operator.Type.ATTRIBUTE, *args, **kw)

Registers a new attribute only operator function in the test engine.

Args:
        *args: variadic arguments.
        **kw: variadic keyword arguments.

Returns:
        function


def peersDF(symbol, token='', version=''):

    p = peers(symbol, token, version)
    df = _peersToDF(p)
    return df

Peers of ticker

    https://iexcloud.io/docs/api/#peers
    8am UTC daily

Args:
        symbol (string); Ticker to request
        token (string); Access token
        version (string); API version

Returns:
        DataFrame: result


def post(self, request, enterprise_customer_uuid):

        transmit_courses_metadata_form = TransmitEnterpriseCoursesForm(request.POST)

        # check that form data is well-formed
        if transmit_courses_metadata_form.is_valid():
            channel_worker_username = transmit_courses_metadata_form.cleaned_data['channel_worker_username']

            # call `transmit_content_metadata` management command to trigger
            # transmission of enterprise courses metadata
            call_command(
                'transmit_content_metadata',
                '--catalog_user', channel_worker_username,
                enterprise_customer=enterprise_customer_uuid
            )

            # Redirect to GET
            return HttpResponseRedirect('')

        context = self._build_context(request, enterprise_customer_uuid)
        context.update({self.ContextParameters.TRANSMIT_COURSES_METADATA_FORM: transmit_courses_metadata_form})
        return render(request, self.template, context)

Handle POST request - handle form submissions.

Args:
        request (django.http.request.HttpRequest): Request instance
        enterprise_customer_uuid (str): Enterprise Customer UUID


def start_app(self, bundle_id):

        # if self._session is not None:
        #     self.stop_app()
        self._bundle_id = bundle_id
        self._session = self._wda.session(bundle_id)
        return self._session

Start an application

Args:
        - bundle_id: (string) apk bundle ID

Returns:
        WDA session object


def _remove_hidden_parts(projected_surface):

    surface = np.copy(projected_surface)
    surface[~_make_occlusion_mask(projected_surface)] = np.nan
    return surface

Removes parts of a projected surface that are not visible.

Args:
        projected_surface (surface): the surface to use

Returns:
        surface: A projected surface.


def safe_call(request: Request, methods: Methods, *, debug: bool) -> Response:

    with handle_exceptions(request, debug) as handler:
        result = call(methods.items[request.method], *request.args, **request.kwargs)
        handler.response = SuccessResponse(result=result, id=request.id)
    return handler.response

Call a Request, catching exceptions to ensure we always return a Response.

Args:
        request: The Request object.
        methods: The list of methods that can be called.
        debug: Include more information in error responses.

Returns:
        A Response object.


def create_bmi_config_file(self, filename: str = "bmi_config.txt") -> None:

        s0 = self.construct_default_initial_state()
        s0.to_csv(filename, index_label="variable")

Create a BMI config file to initialize the model.

Args:
        filename: The filename with which the config file should be saved.


def __init__(self, _args):

        super(TcExInit, self).__init__(_args)

        # properties
        self.base_url = (
            'https://raw.githubusercontent.com/ThreatConnect-Inc/tcex/{}/app_init/'
        ).format(self.args.branch)

Initialize Class properties.

Args:
        _args (namespace): The argparser args Namespace.


def l2_loss(tensor, weight=1.0, scope=None):

  with tf.name_scope(scope, 'L2Loss', [tensor]):
    weight = tf.convert_to_tensor(weight,
                                  dtype=tensor.dtype.base_dtype,
                                  name='loss_weight')
    loss = tf.multiply(weight, tf.nn.l2_loss(tensor), name='value')
    tf.add_to_collection(LOSSES_COLLECTION, loss)
    return loss

Define a L2Loss, useful for regularize, i.e. weight decay.

Args:
        tensor: tensor to regularize.
        weight: an optional weight to modulate the loss.
        scope: Optional scope for name_scope.

Returns:
        the L2 loss op.


def gene_filter(self, query, mongo_query):

        LOG.debug('Adding panel and genes-related parameters to the query')

        gene_query = []

        if query.get('hgnc_symbols') and query.get('gene_panels'):
            gene_query.append({'hgnc_symbols': {'$in': query['hgnc_symbols']}})
            gene_query.append({'panels': {'$in': query['gene_panels']}})
            mongo_query['$or']=gene_query
        else:
            if query.get('hgnc_symbols'):
                hgnc_symbols = query['hgnc_symbols']
                mongo_query['hgnc_symbols'] = {'$in': hgnc_symbols}
                LOG.debug("Adding hgnc_symbols: %s to query" %
                             ', '.join(hgnc_symbols))

            if query.get('gene_panels'):
                gene_panels = query['gene_panels']
                mongo_query['panels'] = {'$in': gene_panels}

        return gene_query

Adds gene-related filters to the query object

Args:
        query(dict): a dictionary of query filters specified by the users
        mongo_query(dict): the query that is going to be submitted to the database

Returns:
        mongo_query(dict): returned object contains gene and panel-related filters


def register(self, token, regexp):

        self._tokens.append((token, re.compile(regexp)))

Register a token.

Args:
        token (Token): the token class to register
        regexp (str): the regexp for that token


def _process_rules(self, rules):

        cidr = []
        non_cidr = []

        for rule in rules:
            if '.' in rule['app']:
                self.log.debug('Custom CIDR rule: %s', rule)
                self._validate_cidr(rule)
                cidr.append(rule)
            else:
                self.log.debug('SG reference rule: %s', rule)
                non_cidr.append(rule)

        self.log.debug('Custom CIDR rules: %s', cidr)
        self.log.debug('SG reference rules: %s', non_cidr)
        return non_cidr, cidr

Process rules into cidr and non-cidr lists.

Args:
        rules (list): Allowed Security Group ports and protocols.

Returns:
        (list, list): Security Group reference rules and custom CIDR rules.


def cols_strip(df,col_list, dest = False):

    if not dest:
        return _pd.DataFrame({col_name:col_strip(df,col_name) for col_name in col_list})
    for col_name in col_list:
        col_strip(df,col_name,dest)

Performs str.strip() a column of a DataFrame
    Parameters:
    df - DataFrame
        DataFrame to operate on
    col_list - list of strings
        names of columns to strip
    dest - bool, default False
        Whether to apply the result to the DataFrame or return it.
        True is apply, False is return.


def deserialize_pem(cert_pem):

    if isinstance(cert_pem, str):
        cert_pem = cert_pem.encode("utf-8")
    return cryptography.x509.load_pem_x509_certificate(
        data=cert_pem, backend=cryptography.hazmat.backends.default_backend()
    )

Deserialize PEM (Base64) encoded X.509 v3 certificate.

Args:
        cert_pem: str or bytes
        PEM (Base64) encoded X.509 v3 certificate

Returns:
        cert_obj: cryptography.Certificate


def _get_record(self, model_class, record_id):

        url = '{host}/{namespace}/{model}/{id}'.format(
            host=self._host,
            namespace=self._namespace,
            model=self._translate_name(model_class.__name__),
            id=record_id
        )
        data = self._get_json(url)['data']
        fresh_model = model_class(data['attributes'])
        fresh_model.id = data['id']
        fresh_model.validate()
        if self._cache is not None:
            self._cache.set_record(model_class.__name__, fresh_model.id, fresh_model)
        return fresh_model

Get a single record from the API.

Args:
        model_class (:class:`cinder_data.model.CinderModel`): A subclass of
            :class:`cinder_data.model.CinderModel` of your chosen model.
        record_id (int): The id of the record requested.

Returns:
        :class:`cinder_data.model.CinderModel`: An instance of model_class or None.


def set_timezone(self, timezone: str):

        data = {"timezoneId": timezone}
        return self._restCall("home/setTimezone", body=json.dumps(data))

sets the timezone for the AP. e.g. "Europe/Berlin"

Args:
        timezone(str): the new timezone


def length(ext_id, ext_des, ext_src):
        # type: (bytes, bytes, bytes) -> int

        return 8 + len(ext_id) + len(ext_des) + len(ext_src)

Static method to return the length of the Rock Ridge Extensions Reference
    record.

    Parameters:
    ext_id - The extension identifier to use.
    ext_des - The extension descriptor to use.
    ext_src - The extension specification source to use.

Returns:
    The length of this record in bytes.


def GetMessages(self, formatter_mediator, event):

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

    event_values = event.CopyToDict()

    document_type = event_values.get('document_type', None)
    if document_type:
      event_values['document_type'] = self._DOC_TYPES.get(
          document_type, 'UNKNOWN')

    shared = event_values.get('shared', False)
    if shared:
      event_values['shared'] = 'Shared'
    else:
      event_values['shared'] = 'Private'

    return self._ConditionalFormatMessages(event_values)

Determines the formatted message strings for an event object.

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

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

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


def read(self, size=None):

    if not self._is_open:
      raise IOError('Not opened.')

    if self._current_offset < 0:
      raise IOError(
          'Invalid current offset: {0:d} value less than zero.'.format(
              self._current_offset))

    if self._decrypted_stream_size is None:
      self._decrypted_stream_size = self._GetDecryptedStreamSize()

    if self._decrypted_stream_size < 0:
      raise IOError('Invalid decrypted stream size.')

    if self._current_offset >= self._decrypted_stream_size:
      return b''

    if self._realign_offset:
      self._AlignDecryptedDataOffset(self._current_offset)
      self._realign_offset = False

    if size is None:
      size = self._decrypted_stream_size
    if self._current_offset + size > self._decrypted_stream_size:
      size = self._decrypted_stream_size - self._current_offset

    decrypted_data = b''

    if size == 0:
      return decrypted_data

    while size > self._decrypted_data_size:
      decrypted_data = b''.join([
          decrypted_data,
          self._decrypted_data[self._decrypted_data_offset:]])

      remaining_decrypted_data_size = (
          self._decrypted_data_size - self._decrypted_data_offset)

      self._current_offset += remaining_decrypted_data_size
      size -= remaining_decrypted_data_size

      if self._current_offset >= self._decrypted_stream_size:
        break

      read_count = self._ReadEncryptedData(self._ENCRYPTED_DATA_BUFFER_SIZE)
      self._decrypted_data_offset = 0
      if read_count == 0:
        break

    if size > 0:
      slice_start_offset = self._decrypted_data_offset
      slice_end_offset = slice_start_offset + size

      decrypted_data = b''.join([
          decrypted_data,
          self._decrypted_data[slice_start_offset:slice_end_offset]])

      self._decrypted_data_offset += size
      self._current_offset += size

    return decrypted_data

Reads a byte string from the file-like object at the current offset.

    The function will read a byte string of the specified size or
    all of the remaining data if no size was specified.

Args:
        size (Optional[int]): number of bytes to read, where None is all
        remaining data.

Returns:
        bytes: data read.

Raises:
        IOError: if the read failed.
        OSError: if the read failed.


def uniprot_ec(uniprot_id):

    r = requests.post('http://www.uniprot.org/uniprot/?query=%s&columns=ec&format=tab' % uniprot_id)
    ec = r.content.decode('utf-8').splitlines()[1]

    if len(ec) == 0:
        ec = None

    return ec

Retrieve the EC number annotation for a UniProt ID.

Args:
        uniprot_id: Valid UniProt ID

    Returns:


def italic(self, action):

        if action =='on':
            action = '4'
        elif action=='off':
            action = '5'
        else:
            raise RuntimeError('Invalid action for function italic. Options are on and off')
        self.send(chr(27)+action)

Enable/cancel italic printing

Args:
        action: Enable or disable italic printing. Options are 'on' and 'off'

Returns:
        None

Raises:
        RuntimeError: Invalid action.


def pairwise_intersection(boxlist1, boxlist2):

    x_min1, y_min1, x_max1, y_max1 = tf.split(boxlist1, 4, axis=1)
    x_min2, y_min2, x_max2, y_max2 = tf.split(boxlist2, 4, axis=1)
    all_pairs_min_ymax = tf.minimum(y_max1, tf.transpose(y_max2))
    all_pairs_max_ymin = tf.maximum(y_min1, tf.transpose(y_min2))
    intersect_heights = tf.maximum(0.0, all_pairs_min_ymax - all_pairs_max_ymin)
    all_pairs_min_xmax = tf.minimum(x_max1, tf.transpose(x_max2))
    all_pairs_max_xmin = tf.maximum(x_min1, tf.transpose(x_min2))
    intersect_widths = tf.maximum(0.0, all_pairs_min_xmax - all_pairs_max_xmin)
    return intersect_heights * intersect_widths

Compute pairwise intersection areas between boxes.

Args:
        boxlist1: Nx4 floatbox
        boxlist2: Mx4

Returns:
        a tensor with shape [N, M] representing pairwise intersections


def Match(self, registry_key):

    value_names = frozenset([
        registry_value.name for registry_value in registry_key.GetValues()])

    return self._value_names.issubset(value_names)

Determines if a Windows Registry key matches the filter.

Args:
        registry_key (dfwinreg.WinRegistryKey): Windows Registry key.

Returns:
        bool: True if the keys match.


def WriteSessionCompletion(self, aborted=False):

    self._RaiseIfNotWritable()

    if self._storage_type != definitions.STORAGE_TYPE_SESSION:
      raise IOError('Unsupported storage type.')

    self._session.aborted = aborted
    session_completion = self._session.CreateSessionCompletion()
    self._storage_file.WriteSessionCompletion(session_completion)

Writes session completion information.

Args:
        aborted (Optional[bool]): True if the session was aborted.

Raises:
        IOError: if the storage type is not supported or
        when the storage writer is closed.
        OSError: if the storage type is not supported or
        when the storage writer is closed.


def fetch_ensembl_exons(build='37'):

    LOG.info("Fetching ensembl exons build %s ...", build)
    if build == '37':
        url = 'http://grch37.ensembl.org'
    else:
        url = 'http://www.ensembl.org'

    dataset_name = 'hsapiens_gene_ensembl'

    dataset = pybiomart.Dataset(name=dataset_name, host=url)

    attributes = [
        'chromosome_name',
        'ensembl_gene_id',
        'ensembl_transcript_id',
        'ensembl_exon_id',
        'exon_chrom_start',
        'exon_chrom_end',
        '5_utr_start',
        '5_utr_end',
        '3_utr_start',
        '3_utr_end',
        'strand',
        'rank'
    ]

    filters = {
        'chromosome_name': CHROMOSOMES,
    }

    result = dataset.query(
        attributes = attributes,
        filters = filters
    )

    return result

Fetch the ensembl genes

Args:
        build(str): ['37', '38']


def swo_speed_info(self):

        info = structs.JLinkSWOSpeedInfo()
        res = self._dll.JLINKARM_SWO_Control(enums.JLinkSWOCommands.GET_SPEED_INFO,
                                             ctypes.byref(info))
        if res < 0:
            raise errors.JLinkException(res)

        return info

Retrieves information about the supported SWO speeds.

Args:
        self (JLink): the ``JLink`` instance

Returns:
        A ``JLinkSWOSpeedInfo`` instance describing the target's supported
        SWO speeds.

Raises:
        JLinkException: on error


def saveRecords(self, path='myOutput'):

    numRecords = self.fields[0].numRecords
    assert (all(field.numRecords==numRecords for field in self.fields))

    import csv
    with open(path+'.csv', 'wb') as f:
      writer = csv.writer(f)
      writer.writerow(self.getAllFieldNames())
      writer.writerow(self.getAllDataTypes())
      writer.writerow(self.getAllFlags())
      writer.writerows(self.getAllRecords())
    if self.verbosity>0:
      print '******', numRecords,'records exported in numenta format to file:',\
                path,'******\n'

Export all the records into a csv file in numenta format.

    Example header format:
    fieldName1    fieldName2    fieldName3
    date          string        float
    T             S

    Parameters:
    --------------------------------------------------------------------
    path:      Relative path of the file to which the records are to be exported


def write_message(self, message, timeout):

    with self._writer_lock:
      self._transport.write(message.header, timeout.remaining_ms)

      # Use any remaining time to send the data.  Note that if we get this far,
      # we always at least try to send the data (with a minimum of 10ms timeout)
      # because we don't want the remote end to get out of sync because we sent
      # a header but no data.
      if timeout.has_expired():
        _LOG.warning('Timed out between AdbMessage header and data, sending '
                     'data anyway with 10ms timeout')
        timeout = timeouts.PolledTimeout.from_millis(10)
      self._transport.write(message.data, timeout.remaining_ms)

Send the given message over this transport.

Args:
        message: The AdbMessage to send.
        timeout: Use this timeout for the entire write operation, it should be an
        instance of timeouts.PolledTimeout.


def localopt(self, forcefield='mmff94', steps=500):

        pbmol = pb.Molecule(self._obmol)
        pbmol.localopt(forcefield=forcefield, steps=steps)
        self._obmol = pbmol.OBMol

A wrapper to pybel's localopt method to optimize a Molecule.

Args:
        forcefield: Default is mmff94. Options are 'gaff', 'ghemical',
            'mmff94', 'mmff94s', and 'uff'.
        steps: Default is 500.


def proto_refactor_files(dest_dir, namespace, namespace_path):

    for dn, dns, fns in os.walk(dest_dir):
        for fn in fns:
            fn = os.path.join(dn, fn)
            if fnmatch.fnmatch(fn, '*.proto'):
                data = proto_refactor(fn, namespace, namespace_path)
                with open(fn, 'w') as f:
                    f.write(data)

This method runs the refactoring on all the Protobuf files in the
    Dropsonde repo.

Args:
        dest_dir (str): directory where the Protobuf files lives.
        namespace (str): the desired package name (i.e. "dropsonde.py2")
        namespace_path (str): the desired path corresponding to the package
                            name (i.e. "dropsonde/py2")


def add_child(self, key, value):

        if type(value) in (list, tuple, dict):
            if type(value)==dict:
                for k in value.keys():
                    self.add_child(k, value[k])
                return
            i = 0
            for child in value:
                self.add_child(key[i], child)
                i = i + 1
            return

        if hasattr(value, 'attributes'):
            value.attributes['data-parent-widget'] = self.identifier
            value._parent = self

        if key in self.children:
            self._render_children_list.remove(key)
        self._render_children_list.append(key)

        self.children[key] = value

Adds a child to the Tag

    To retrieve the child call get_child or access to the Tag.children[key] dictionary.

Args:
        key (str):  Unique child's identifier, or iterable of keys
        value (Tag, str): can be a Tag, an iterable of Tag or a str. In case of iterable
            of Tag is a dict, each item's key is set as 'key' param


def _RunAction(self, rule, client_id):

    actions_count = 0

    try:
      if self._CheckIfHuntTaskWasAssigned(client_id, rule.hunt_id):
        logging.info(
            "Foreman: ignoring hunt %s on client %s: was started "
            "here before", client_id, rule.hunt_id)
      else:
        logging.info("Foreman: Starting hunt %s on client %s.", rule.hunt_id,
                     client_id)

        # hunt_name is only used for legacy hunts.
        if rule.hunt_name:
          flow_cls = registry.AFF4FlowRegistry.FlowClassByName(rule.hunt_name)
          hunt_urn = rdfvalue.RDFURN("aff4:/hunts/%s" % rule.hunt_id)
          flow_cls.StartClients(hunt_urn, [client_id])
        else:
          hunt.StartHuntFlowOnClient(client_id, rule.hunt_id)

        actions_count += 1

    # There could be all kinds of errors we don't know about when starting the
    # hunt so we catch everything here.
    except Exception as e:  # pylint: disable=broad-except
      logging.exception("Failure running foreman action on client %s: %s",
                        rule.hunt_id, e)

    return actions_count

Run all the actions specified in the rule.

Args:
        rule: Rule which actions are to be executed.
        client_id: Id of a client where rule's actions are to be executed.

Returns:
        Number of actions started.


def comment_delete(self, comment_id):

        return self._get('comments/{0}.json'.format(comment_id),
                         method='DELETE', auth=True)

Remove a specific comment (Requires login).

    Parameters:
        comment_id (int): The id number of the comment to remove.


def print_debug(*args, **kwargs):

    if WTF_CONFIG_READER.get("debug", False) == True:
        print(*args, **kwargs)

Print if and only if the debug flag is set true in the config.yaml file.

Args:
        args : var args of print arguments.


def get(self, s):

        ret = []
        search_by_expression = self._valid_search(s)
        for l in self.lines:
            if search_by_expression(l):
                ret.append(self._parse_line(l))
        return ret

Returns all lines that contain `s` anywhere and wrap them in a list of
    dictionaries.  `s` can be either a single string or a string list. For
    list, all keywords in the list must be found in each line.

    Parameters:
        s(str or list): one or more strings to search for.

Returns:
        (list): list of dictionaries corresponding to the parsed lines
        contain the `s`.


def FlagCxx11Features(filename, clean_lines, linenum, error):

  line = clean_lines.elided[linenum]

  # Flag unapproved C++11 headers.
  include = Match(r'\s*#\s*include\s+[<"]([^<"]+)[">]', line)
  if include and include.group(1) in ('cfenv',
                                      'condition_variable',
                                      'fenv.h',
                                      'future',
                                      'mutex',
                                      'thread',
                                      'chrono',
                                      'ratio',
                                      'regex',
                                      'system_error',
                                     ):
    error(filename, linenum, 'build/c++11', 5,
          ('<%s> is an unapproved C++11 header.') % include.group(1))

  # The only place where we need to worry about C++11 keywords and library
  # features in preprocessor directives is in macro definitions.
  if Match(r'\s*#', line) and not Match(r'\s*#\s*define\b', line): return

  # These are classes and free functions.  The classes are always
  # mentioned as std::*, but we only catch the free functions if
  # they're not found by ADL.  They're alphabetical by header.
  for top_name in (
      # type_traits
      'alignment_of',
      'aligned_union',
      ):
    if Search(r'\bstd::%s\b' % top_name, line):
      error(filename, linenum, 'build/c++11', 5,
            ('std::%s is an unapproved C++11 class or function.  Send c-style '
             'an example of where it would make your code more readable, and '
             'they may let you use it.') % top_name)

Flag those c++11 features that we only allow in certain places.

Args:
        filename: The name of the current file.
        clean_lines: A CleansedLines instance containing the file.
        linenum: The number of the line to check.
        error: The function to call with any errors found.


def fit_transform(self, X, y=None):

        self.label_encoders = [None] * X.shape[1]
        self.label_maxes = [None] * X.shape[1]

        for i, col in enumerate(X.columns):
            self.label_encoders[i], self.label_maxes[i] = \
                self._get_label_encoder_and_max(X[col])

            X.loc[:, col] = X[col].fillna(NAN_INT).map(self.label_encoders[i]).fillna(0)

        return X

Encode categorical columns into label encoded columns

Args:
        X (pandas.DataFrame): categorical columns to encode

Returns:
        X (pandas.DataFrame): label encoded columns


def strip_errors(obj):

    rtn_obj = copy.deepcopy(obj)
    try:
        del rtn_obj["__error_keys__"]
    except KeyError:
        pass
    for key in obj.get('__error_keys__', []):
        rtn_obj[key] = rtn_obj[key]['value']
    return rtn_obj

Reads through and error object and replaces the error dict with the
    value

Args:
        obj: the error object/dictionary


def link(target, link_to):

    assert isinstance(target, str)
    assert os.path.exists(target)
    assert isinstance(link_to, str)

    # Create the path to the link if it does not exists
    abs_path = os.path.dirname(os.path.abspath(link_to))
    if not os.path.isdir(abs_path):
        os.makedirs(abs_path)

    # Make sure the file or folder recursively has the good mode
    chmod(target)

    # Create the link to target
    os.symlink(target, link_to)

Create a link to a target file or a folder.

    For simplicity sake, both target and link_to must be absolute path and must
    include the filename of the file or folder.
    Also do not include any trailing slash.

    e.g. link('/path/to/file', '/path/to/link')

    But not: link('/path/to/file', 'path/to/')
    or link('/path/to/folder/', '/path/to/link')

Args:
        target (str): file or folder the link will point to
        link_to (str): Link to create


def verify(self, obj):

        if obj != self._literal:
            raise ValidationError("Object is not equal to literal",
                                  reason='%s is not equal to %s' % (str(obj), str(self._literal)), object=obj)

        return obj

Verify that the object conforms to this verifier's schema

Args:
        obj (object): A python object to verify

Raises:
        ValidationError: If there is a problem verifying the dictionary, a
            ValidationError is thrown with at least the reason key set indicating
            the reason for the lack of validation.


def write_log(self, message):

        if self._is_write_log and self.log_file and not self.log_file.closed:
            self.log_file.write(message + '\n')

Write a line to the VM instruction log file.

Args:
        message (str): string message to write to file.


def dataset(self, mode, hparams=None, global_step=None, **kwargs):

    datasets = [p.dataset(mode, **kwargs) for p in self.problems]
    datasets = [
        d.map(lambda x, i=j: self.normalize_example(  # pylint: disable=g-long-lambda
            dict(x, problem_id=tf.constant([i])), hparams))
        for j, d in enumerate(datasets)  # Tag examples with a problem_id.
    ]
    if mode is problem.DatasetSplit.TRAIN:
      if global_step is None:
        global_step = tf.train.get_or_create_global_step()
      pmf = get_schedule_distribution(self.schedule, global_step)
      return get_multi_dataset(datasets, pmf)
    elif self.only_eval_first_problem:
      return datasets[0]
    else:
      datasets = [d.repeat() for d in datasets]
      return tf.data.Dataset.zip(tuple(datasets)).flat_map(
          lambda *x: functools.reduce(  # pylint: disable=g-long-lambda
              tf.data.Dataset.concatenate,
              map(tf.data.Dataset.from_tensors, x)))

Returns a dataset containing examples from multiple problems.

Args:
        mode: A member of problem.DatasetSplit.
        hparams: A tf.HParams object, the model hparams.
        global_step: A scalar tensor used to compute the sampling distribution.
        If global_step is None, we call tf.train.get_or_create_global_step by
        default.
        **kwargs: Keywords for problem.Problem.Dataset.

Returns:
        A dataset containing examples from multiple problems.


def _map_across_full_axis_select_indices(
        self, axis, func, indices, keep_remaining=False
    ):

        return self.data.apply_func_to_select_indices_along_full_axis(
            axis, func, indices, keep_remaining
        )

Maps function to select indices along full axis.

Args:
        axis: 0 for columns and 1 for rows.
        func: Callable mapping function over the BlockParitions.
        indices: indices along axis to map over.
        keep_remaining: True if keep indices where function was not applied.

Returns:
        BaseFrameManager containing the result of mapping func over axis on indices.


def reciprocal_lattice_from_outcar( filename ): # from https://github.com/MaterialsDiscovery/PyChemia

    outcar = open(filename, "r").read()
    # just keeping the last component
    recLat = re.findall(r"reciprocal\s*lattice\s*vectors\s*([-.\s\d]*)",
                        outcar)[-1]
    recLat = recLat.split()
    recLat = np.array(recLat, dtype=float)
    # up to now I have, both direct and rec. lattices (3+3=6 columns)
    recLat.shape = (3, 6)
    recLat = recLat[:, 3:]
    return recLat

Finds and returns the reciprocal lattice vectors, if more than
    one set present, it just returns the last one.

Args:
        filename (Str): The name of the outcar file to be read

Returns:
        List(Float): The reciprocal lattice vectors.


def cooccurrences(self, domains):

        api_name = 'opendns-cooccurrences'
        fmt_url_path = u'recommendations/name/{0}.json'
        return self._multi_get(api_name, fmt_url_path, domains)

Get the domains related to input domains.

Args:
        domains: an enumerable of strings domain names

Returns:
        An enumerable of string domain names


def add_profile_variants(self, profile_variants):

        results = self.db.profile_variant.insert_many(profile_variants)

        return results

Add several variants to the profile_variant collection in the
    database

Args:
        profile_variants(list(models.ProfileVariant))


def __init__(self, parent):

        super(ModuleFrame, self).__init__(parent)
        logger.debug("Initialising module tabs")

        # Setup styles
        style = ttk.Style()
        style.configure("Module.TFrame", background="white")

        self.module_buttons = {}
        self.current_button = None

        # Module view
        self.module_list = ttk.Frame(self, width=150, style="Module.TFrame")
        self.module_list.grid(column=0, row=0, padx=0, pady=0, sticky="W E N S")
        self.module_list.columnconfigure(0, weight=1)
        self.module_list.rowconfigure(0, weight=0)
        self.module_list.rowconfigure(1, weight=1)
        # Header
        header = tk.Label(self.module_list, text="Modules", bg="white", fg="#484848")
        header.grid(column=0, row=0, padx=0, pady=0, sticky="W E N")
        # Module selection list
        self.module_selection = ttk.Frame(self.module_list, style="Module.TFrame")
        self.module_selection.grid(column=0, row=1, padx=0, pady=0, sticky="W E N S")
        self.module_selection.columnconfigure(0, weight=1)
        # Module UI view
        self.module_ui = ttk.Frame(self)
        self.module_ui.grid(column=1, row=0, padx=0, pady=0, sticky="W E N S")
        self.module_ui.columnconfigure(0, weight=1)
        self.module_ui.rowconfigure(0, weight=1)

        self.clear_modules()

        # Configure stretch ratios
        self.columnconfigure(0, minsize=150)
        self.columnconfigure(1, weight=1)
        self.rowconfigure(0, weight=1)

Create a new module frame and add it to the given parent.

Args:
        parent: A tk or ttk object


def _cumprod(l):

  ret = [1]
  for item in l:
    ret.append(ret[-1] * item)
  return ret

Cumulative product of a list.

Args:
        l: a list of integers

Returns:
        a list with one more element (starting with 1)


def _enum_from_direction(direction):

    if isinstance(direction, int):
        return direction

    if direction == Query.ASCENDING:
        return enums.StructuredQuery.Direction.ASCENDING
    elif direction == Query.DESCENDING:
        return enums.StructuredQuery.Direction.DESCENDING
    else:
        msg = _BAD_DIR_STRING.format(direction, Query.ASCENDING, Query.DESCENDING)
        raise ValueError(msg)

Convert a string representation of a direction to an enum.

Args:
        direction (str): A direction to order by. Must be one of
            :attr:`~.firestore.Query.ASCENDING` or
            :attr:`~.firestore.Query.DESCENDING`.

Returns:
        int: The enum corresponding to ``direction``.

Raises:
        ValueError: If ``direction`` is not a valid direction.


def _GetEnableOsLoginValue(self, metadata_dict):

    instance_data, project_data = self._GetInstanceAndProjectAttributes(
        metadata_dict)
    instance_value = instance_data.get('enable-oslogin')
    project_value = project_data.get('enable-oslogin')
    value = instance_value or project_value or ''

    return value.lower() == 'true'

Get the value of the enable-oslogin metadata key.

Args:
        metadata_dict: json, the deserialized contents of the metadata server.

Returns:
        bool, True if OS Login is enabled for VM access.


def process_data(data, number_to_keep):

    result = dict()

    if number_to_keep != 0:
        data_temp = dict(Counter(data).most_common(number_to_keep))
        data_temp['rest'] = sum(data.values()) - sum(data_temp.values())
        data = data_temp

    labels = data
    values = np.array([data[key] for key in labels], dtype=float)
    pvalues = values / sum(values)
    for position, label in enumerate(labels):
        result[label] = round(pvalues[position], 5)

    return result

Prepare received data for representation.

Args:
        data (dict): values to represent (ex. {'001' : 130})
        number_to_keep (int): number of elements to show individually.

Returns:
        dict: processed data to show.


def get_item(dictionary, tuple_key, default_value):

    u, v = tuple_key

    # Grab tuple-values from dictionary
    tuple1 = dictionary.get((u, v), None)
    tuple2 = dictionary.get((v, u), None)

    # Return the first value that is not {None, 0, False}
    return tuple1 or tuple2 or default_value

Grab values from a dictionary using an unordered tuple as a key.

    Dictionary should not contain None, 0, or False as dictionary values.

Args:
        dictionary: Dictionary that uses two-element tuple as keys
        tuple_key: Unordered tuple of two elements
        default_value: Value that is returned when the tuple_key is not found in the dictionary


def num_nodes(self, leaves=True, internal=True):

        if not isinstance(leaves, bool):
            raise TypeError("leaves must be a bool")
        if not isinstance(internal, bool):
            raise TypeError("internal must be a bool")
        num = 0
        for node in self.traverse_preorder():
            if (leaves and node.is_leaf()) or (internal and not node.is_leaf()):
                num += 1
        return num

Compute the total number of selected nodes in this ``Tree``

Args:
        ``leaves`` (``bool``): ``True`` to include leaves, otherwise ``False``

        ``internal`` (``bool``): ``True`` to include internal nodes, otherwise ``False``

Returns:
        ``int``: The total number of selected nodes in this ``Tree``


def refresh(self, refresh_binary=True):

		updated_self = self.repo.get_resource(self.uri)

		# if resource type of updated_self != self, raise exception
		if not isinstance(self, type(updated_self)):
			raise Exception('Instantiated %s, but repository reports this resource is %s' % (type(updated_self), type(self)) )

		if updated_self:

			# update attributes
			self.status_code = updated_self.status_code
			self.rdf.data = updated_self.rdf.data
			self.headers = updated_self.headers
			self.exists = updated_self.exists

			# update graph if RDFSource
			if type(self) != NonRDFSource:
				self._parse_graph()

			# empty versions
			self.versions = SimpleNamespace()

			# if NonRDF, set binary attributes
			if type(updated_self) == NonRDFSource and refresh_binary:
				self.binary.refresh(updated_self)

			# fire resource._post_create hook if exists
			if hasattr(self,'_post_refresh'):
				self._post_refresh()

			# cleanup
			del(updated_self)

		else:
			logger.debug('resource %s not found, dumping values')
			self._empty_resource_attributes()

Performs GET request and refreshes RDF information for resource.

Args:
    None

Returns:
    None


def view_structure(self, only_chains=None, opacity=1.0, recolor=False, gui=False):

        # TODO: show_structure_file does not work for MMTF files - need to check for that and load accordingly

        if ssbio.utils.is_ipynb():
            import nglview as nv
        else:
            raise EnvironmentError('Unable to display structure - not running in a Jupyter notebook environment')

        if not self.structure_file:
            raise ValueError("Structure file not loaded")

        only_chains = ssbio.utils.force_list(only_chains)
        to_show_chains = '( '
        for c in only_chains:
            to_show_chains += ':{} or'.format(c)
        to_show_chains = to_show_chains.strip(' or ')
        to_show_chains += ' )'

        if self.file_type == 'mmtf' or self.file_type == 'mmtf.gz':
            view = nv.NGLWidget()
            view.add_component(self.structure_path)
        else:
            view = nv.show_structure_file(self.structure_path, gui=gui)

        if recolor:
            view.clear_representations()
            if only_chains:
                view.add_cartoon(selection='{} and (not hydrogen)'.format(to_show_chains), color='silver', opacity=opacity)
            else:
                view.add_cartoon(selection='protein', color='silver', opacity=opacity)
        elif only_chains:
            view.clear_representations()
            view.add_cartoon(selection='{} and (not hydrogen)'.format(to_show_chains), color='silver', opacity=opacity)

        return view

Use NGLviewer to display a structure in a Jupyter notebook

Args:
        only_chains (str, list): Chain ID or IDs to display
        opacity (float): Opacity of the structure
        recolor (bool): If structure should be cleaned and recolored to silver
        gui (bool): If the NGLview GUI should show up

Returns:
        NGLviewer object


def set_key_color(self, color: Tuple[int, int, int]) -> None:

        lib.TCOD_image_set_key_color(self.image_c, color)

Set a color to be transparent during blitting functions.

Args:
        color (Union[Tuple[int, int, int], Sequence[int]]):
            An (r, g, b) sequence or Color instance.


def get_box_threads(self, box_key):

		uri = '/'.join([
						self.api_uri,
						self.boxes_suffix,
						box_key,
						self.threads_suffix
						])
		return self._req('get', uri)

Gets all threads in a specified box

Args:
    box_key 		box to look in
    returns 		a list of thread dicts


def download_as_pem(
    base_url=d1_common.const.URL_DATAONE_ROOT,
    timeout_sec=d1_common.const.DEFAULT_HTTP_TIMEOUT,
):

    return ssl.DER_cert_to_PEM_cert(download_as_der(base_url, timeout_sec))

Download public certificate from a TLS/SSL web server as PEM encoded string.

    Also see download_as_der().

Args:
        base_url : str
        A full URL to a DataONE service endpoint or a server hostname
        timeout_sec : int or float
        Timeout for the SSL socket operations

Returns:
        str: The certificate as a PEM encoded string.


def write_version(name=None, path=None):

    # Written like this for coverage purposes.
    # http://stackoverflow.com/questions/5850268/how-to-test-or-mock-if-name-main-contents/27084447#27084447
    if name in (None, '__main__'):
        path = path or os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
                                    "version.json")
        contents = {
            'version': __version__,
            'version_string': __version_string__,
        }
        with open(path, 'w') as filehandle:
            filehandle.write(json.dumps(contents, sort_keys=True, indent=4))

Write the version info to ../version.json, for setup.py.

Args:
        name (Optional[str]): this is for the ``write_version(name=__name__)``
        below.  That's one way to both follow the
        ``if __name__ == '__main__':`` convention but also allow for full
        coverage without ignoring parts of the file.

        path (Optional[str]): the path to write the version json to.  Defaults
        to ../version.json


def ParseEnum(field, value):

  enum_descriptor = field.enum_type
  try:
    number = int(value, 0)
  except ValueError:
    # Identifier.
    enum_value = enum_descriptor.values_by_name.get(value, None)
    if enum_value is None:
      raise ValueError('Enum type "%s" has no value named %s.' %
                       (enum_descriptor.full_name, value))
  else:
    # Numeric value.
    enum_value = enum_descriptor.values_by_number.get(number, None)
    if enum_value is None:
      raise ValueError('Enum type "%s" has no value with number %d.' %
                       (enum_descriptor.full_name, number))
  return enum_value.number

Parse an enum value.

    The value can be specified by a number (the enum value), or by
    a string literal (the enum name).

Args:
        field: Enum field descriptor.
        value: String value.

Returns:
        Enum value number.

Raises:
        ValueError: If the enum value could not be parsed.


def dispatch(self, inp):

    inp = tf.reshape(inp, [self._batch * self._length, -1])
    # [batch, num_experts, expert_capacity, depth]
    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 _verify_required_claims_exist(jwt_claims):

    for claim_name in [u"aud", u"exp", u"iss", u"sub"]:
        if claim_name not in jwt_claims:
            raise suppliers.UnauthenticatedException(u'Missing "%s" claim' % claim_name)

Verifies that the required claims exist.

Args:
        jwt_claims: the JWT claims to be verified.

Raises:
        UnauthenticatedException: if some claim doesn't exist.


def get_groups(self, **kwargs):

        # Endpoint parameters
        params = {
            'cultureInfo': util.language_code(kwargs.get('lang'))
        }

        # Request
        result = self.make_request('geo', 'get_groups', **params)

        if not util.check_result(result):
            return False, result.get('resultDescription', 'UNKNOWN ERROR')

        # Parse
        values = util.response_list(result, 'resultValues')
        return True, [emtype.GeoGroupItem(**a) for a in values]

Obtain line types and details.

Args:
        lang (str): Language code (*es* or *en*).

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


def initialize_environments(self, batch_size=1):

    assert batch_size >= 1
    self._batch_size = batch_size

    self._envs = [gym.make(self.base_env_name) for _ in range(batch_size)]
    if self._env_wrapper_fn is not None:
      self._envs = list(map(self._env_wrapper_fn, self._envs))

    # If self.observation_space and self.action_space aren't None, then it means
    # that this is a re-initialization of this class, in that case make sure
    # that this matches our previous behaviour.
    if self._observation_space:
      assert str(self._observation_space) == str(
          self._envs[0].observation_space)
    else:
      # This means that we are initializing this class for the first time.
      #
      # We set this equal to the first env's observation space, later on we'll
      # verify that all envs have the same observation space.
      self._observation_space = self._envs[0].observation_space

    # Similarly for action_space
    if self._action_space:
      assert str(self._action_space) == str(self._envs[0].action_space)
    else:
      self._action_space = self._envs[0].action_space

    self._verify_same_spaces()

    # If self.reward_range is None, i.e. this means that we should take the
    # reward range of the env.
    if self.reward_range is None:
      self._reward_range = self._envs[0].reward_range

    # This data structure stores the history of each env.
    #
    # NOTE: Even if the env is a NN and can step in all batches concurrently, it
    # is still valuable to store the trajectories separately.
    self._trajectories = trajectory.BatchTrajectory(batch_size=batch_size)

Initializes the environments and trajectories.

    Subclasses can override this if they don't want a default implementation
    which initializes `batch_size` environments, but must take care to
    initialize self._trajectories (this is checked in __init__ anyways).

Args:
        batch_size: (int) Number of `self.base_env_name` envs to initialize.


def encode_fetch_request(cls, payloads=(), max_wait_time=100, min_bytes=4096):

        return kafka.protocol.fetch.FetchRequest[0](
            replica_id=-1,
            max_wait_time=max_wait_time,
            min_bytes=min_bytes,
            topics=[(
                topic,
                [(
                    partition,
                    payload.offset,
                    payload.max_bytes)
                for partition, payload in topic_payloads.items()])
            for topic, topic_payloads in group_by_topic_and_partition(payloads).items()])

Encodes a FetchRequest struct

Args:
        payloads: list of FetchRequestPayload
        max_wait_time (int, optional): ms to block waiting for min_bytes
            data. Defaults to 100.
        min_bytes (int, optional): minimum bytes required to return before
            max_wait_time. Defaults to 4096.

    Return: FetchRequest


def start_naive_bayes(automated_run, session, path):

    module = functions.import_string_code_as_module(automated_run.source)
    random_state = 8 if not hasattr(module, 'random_state') else module.random_state
    assert module.metric_to_optimize in automated_run.base_learner_origin.metric_generators

    # get non-searchable parameters
    base_estimator = automated_run.base_learner_origin.return_estimator()
    base_estimator.set_params(**module.default_params)
    default_params = functions.make_serializable(base_estimator.get_params())
    non_searchable_params = dict((key, val) for key, val in iteritems(default_params)
                                 if key not in module.pbounds)

    # get already calculated base learners in search space
    existing_base_learners = []
    for base_learner in automated_run.base_learner_origin.base_learners:
        if not base_learner.job_status == 'finished':
            continue
        in_search_space = True
        for key, val in iteritems(non_searchable_params):
            if base_learner.hyperparameters[key] != val:
                in_search_space = False
                break  # If no match, move on to the next base learner
        if in_search_space:
            existing_base_learners.append(base_learner)

    # build initialize dictionary
    target = []
    initialization_dict = dict((key, list()) for key in module.pbounds.keys())
    for base_learner in existing_base_learners:
        # check if base learner's searchable hyperparameters are all numerical
        all_numerical = True
        for key in module.pbounds.keys():
            if not isinstance(base_learner.hyperparameters[key], numbers.Number):
                all_numerical = False
                break
        if not all_numerical:
            continue  # if there is a non-numerical hyperparameter, skip this.

        for key in module.pbounds.keys():
            initialization_dict[key].append(base_learner.hyperparameters[key])
        target.append(base_learner.individual_score[module.metric_to_optimize])
    initialization_dict['target'] = target if not module.invert_metric \
        else list(map(lambda x: -x, target))
    print('{} existing in initialization dictionary'.
          format(len(initialization_dict['target'])))

    # Create function to be optimized
    func_to_optimize = return_func_to_optimize(
        path, session, automated_run.base_learner_origin, module.default_params,
        module.metric_to_optimize, module.invert_metric, set(module.integers)
    )

    # Create Bayes object
    bo = BayesianOptimization(func_to_optimize, module.pbounds)

    bo.initialize(initialization_dict)

    np.random.seed(random_state)

    bo.maximize(**module.maximize_config)

Starts naive bayes automated run

Args:
        automated_run (xcessiv.models.AutomatedRun): Automated run object

        session: Valid SQLAlchemy session

        path (str, unicode): Path to project folder


Convert the color from YIQ coordinates to RGB.

    Parameters:
        :y:
        Tte Y component value [0...1]
        :i:
        The I component value [0...1]
        :q:
        The Q component value [0...1]

Returns:
        The color as an (r, g, b) tuple in the range:
        r[0...1],
        g[0...1],
        b[0...1]

    >>> '({}, {}, {})'.format(*[round(v, 6) for v in yiq_to_rgb(0.592263, 0.458874, -0.0499818)])
    '(1.0, 0.5, 1e-06)'


def set_video_pos(self, x1, y1, x2, y2):

        position = "%s %s %s %s" % (str(x1),str(y1),str(x2),str(y2))
        self._player_interface.VideoPos(ObjectPath('/not/used'), String(position))

Set the video position on the screen

Args:
        x1 (int): Top left x coordinate (px)
        y1 (int): Top left y coordinate (px)
        x2 (int): Bottom right x coordinate (px)
        y2 (int): Bottom right y coordinate (px)


def upsert_variant(self, variant_obj):

        LOG.debug("Upserting variant %s", variant_obj['_id'])
        try:
            result = self.variant_collection.insert_one(variant_obj)
        except DuplicateKeyError as err:
            LOG.debug("Variant %s already exists in database", variant_obj['_id'])
            result = self.variant_collection.find_one_and_update(
                {'_id': variant_obj['_id']},
                {
                    '$set': {
                        'compounds': variant_obj.get('compounds',[])
                    }
                }
            )
            variant = self.variant_collection.find_one({'_id': variant_obj['_id']})
        return result

Load a variant object, if the object already exists update compounds.

Args:
        variant_obj(dict)

Returns:
        result


def make_lda_variational(activation, num_topics, layer_sizes):

  encoder_net = tf.keras.Sequential()
  for num_hidden_units in layer_sizes:
    encoder_net.add(
        tf.keras.layers.Dense(
            num_hidden_units,
            activation=activation,
            kernel_initializer=tf.compat.v1.glorot_normal_initializer()))
  encoder_net.add(
      tf.keras.layers.Dense(
          num_topics,
          activation=tf.nn.softplus,
          kernel_initializer=tf.compat.v1.glorot_normal_initializer()))

  def lda_variational(bag_of_words):
    concentration = _clip_dirichlet_parameters(encoder_net(bag_of_words))
    return ed.Dirichlet(concentration=concentration, name="topics_posterior")

  return lda_variational

Creates the variational distribution for LDA.

Args:
        activation: Activation function to use.
        num_topics: The number of topics.
        layer_sizes: The number of hidden units per layer in the encoder.

Returns:
        lda_variational: A function that takes a bag-of-words Tensor as
        input and returns a distribution over topics.


def compare(expr, value, regex_expr=False):

    # Strict equality comparison
    if expr == value:
        return True

    # Infer negate expression to match, if needed
    negate = False
    if isinstance(expr, str):
        negate = expr.startswith(NEGATE)
        expr = strip_negate(expr) if negate else expr

    try:
        # RegExp or strict equality comparison
        test(expr, value, regex_expr=regex_expr)
    except Exception as err:
        if negate:
            return True
        else:
            raise err

    return True

Compares an string or regular expression againast a given value.

Args:
        expr (str|regex): string or regular expression value to compare.
        value (str): value to compare against to.
        regex_expr (bool, optional): enables string based regex matching.

Raises:
        AssertionError: in case of assertion error.

Returns:
        bool


def _kl_half_normal_half_normal(a, b, name=None):

  with tf.name_scope(name or "kl_half_normal_half_normal"):
    # Consistent with
    # http://www.mast.queensu.ca/~communications/Papers/gil-msc11.pdf, page 119
    return (tf.math.log(b.scale) - tf.math.log(a.scale) +
            (a.scale**2 - b.scale**2) / (2 * b.scale**2))

Calculate the batched KL divergence KL(a || b) with a and b `HalfNormal`.

Args:
        a: Instance of a `HalfNormal` distribution object.
        b: Instance of a `HalfNormal` distribution object.
        name: (optional) Name to use for created operations.
        default is "kl_half_normal_half_normal".

Returns:
        Batchwise KL(a || b)


def __init__(self, conv_sizes, dense_sizes, scope='cnn-baseline', summary_labels=()):

        network = []
        for size in conv_sizes:
            network.append(dict(type='conv2d', size=size))

        # First layer has a larger window.
        network[0]['window'] = 5

        network.append(dict(type='flatten'))  # TODO: change to max pooling!
        for size in dense_sizes:
            network.append(dict(type='dense', size=size))

        super(CNNBaseline, self).__init__(network=network, scope=scope, summary_labels=summary_labels)

CNN baseline.

Args:
        conv_sizes: List of convolutional layer sizes
        dense_sizes: List of dense layer sizes


def extremum_icohpvalue(self, summed_spin_channels=True, spin=Spin.up):

        if not self._are_coops:
            extremum = sys.float_info.max
        else:
            extremum = -sys.float_info.max

        if not self._is_spin_polarized:
            if spin == Spin.down:
                warnings.warn("This spin channel does not exist. I am switching to Spin.up")
            spin = Spin.up

        for value in self._icohplist.values():
            if not value.is_spin_polarized or not summed_spin_channels:
                if not self._are_coops:
                    if value.icohpvalue(spin) < extremum:
                        extremum = value.icohpvalue(spin)
                        # print(extremum)
                else:
                    if value.icohpvalue(spin) > extremum:
                        extremum = value.icohpvalue(spin)
                        # print(extremum)
            else:
                if not self._are_coops:
                    if value.summed_icohp < extremum:
                        extremum = value.summed_icohp
                        # print(extremum)
                else:
                    if value.summed_icohp > extremum:
                        extremum = value.summed_icohp
                        # print(extremum)
        return extremum

get ICOHP/ICOOP of strongest bond

Args:
        summed_spin_channels: Boolean to indicate whether the ICOHPs/ICOOPs of both spin channels should be summed

        spin: if summed_spin_channels is equal to False, this spin indicates which spin channel should be returned

Returns:
        lowest ICOHP/largest ICOOP value (i.e. ICOHP/ICOOP value of strongest bond)


def _base_query(self, session):

        return session.query(ORMTargetMarker) \
            .filter(ORMTargetMarker.name == self.name) \
            .filter(ORMTargetMarker.params == self.params)

Base query for a target.

Args:
        session: database session to query in


def entry(bucket, key):

    if key is None:
        return urlsafe_base64_encode('{0}'.format(bucket))
    else:
        return urlsafe_base64_encode('{0}:{1}'.format(bucket, key))

计算七牛API中的数据格式:

    entry规格参考 https://developer.qiniu.com/kodo/api/1276/data-format

Args:
        bucket: 待操作的空间名
        key:    待操作的文件名

Returns:
        符合七牛API规格的数据格式


def flp_nonlinear_soco(I,J,d,M,f,c):

    model = Model("nonlinear flp -- soco formulation")

    x,X,u = {},{},{}
    for j in J:
        X[j] = model.addVar(ub=M[j], vtype="C", name="X(%s)"%j) # for sum_i x_ij
        u[j] = model.addVar(vtype="C", name="u(%s)"%j) # for replacing sqrt sum_i x_ij in soco
        for i in I:
            x[i,j] = model.addVar(vtype="B", name="x(%s,%s)"%(i,j))  # i's demand satisfied from j

    # constraints for customer's demand satisfaction
    for i in I:
        model.addCons(quicksum(x[i,j] for j in J) == 1, "Demand(%s)"%i)

    for j in J:
        model.addCons(quicksum(d[i]*x[i,j] for i in I) == X[j], "Capacity(%s)"%j)
        model.addQConstr(quicksum(f[j]**2*d[i]*x[i,j]*x[i,j] for i in I) <= u[j]*u[j], "SOC(%s)"%j)

    model.setObjective(quicksum(u[j] for j in J) +\
                       quicksum(c[i,j]*d[i]*x[i,j] for j in J for i in I),\
                       "minimize")

    model.data = x,u
    return model

flp_nonlinear_soco --  use
    Parameters:
        - I: set of customers
        - J: set of facilities
        - d[i]: demand for product i
        - M[j]: capacity of facility j
        - f[j]: fixed cost for using a facility in point j
        - c[i,j]: unit cost of servicing demand point i from facility j
    Returns a model, ready to be solved.


def StatEntryFromStat(stat,
                      pathspec,
                      ext_attrs = True):

  result = rdf_client_fs.StatEntry(pathspec=pathspec)

  for attr in _STAT_ATTRS:
    value = getattr(stat.GetRaw(), attr, None)
    if value is None:
      continue

    # TODO(hanuszczak): Why are we doing this?
    value = int(value)
    if value < 0:
      value &= 0xFFFFFFFF

    setattr(result, attr, value)

  result.st_flags_linux = stat.GetLinuxFlags()
  result.st_flags_osx = stat.GetOsxFlags()
  if ext_attrs:
    # TODO(hanuszczak): Can we somehow incorporate extended attribute getter to
    # the `Stat` class? That would make the code a lot prettier but would force
    # `utils` to depend on `xattrs`.
    result.ext_attrs = list(GetExtAttrs(stat.GetPath()))

  return result

Build a stat entry object from a given stat object.

Args:
        stat: A `Stat` object.
        pathspec: A `PathSpec` from which `stat` was obtained.
        ext_attrs: Whether to include extended file attributes in the result.

Returns:
        `StatEntry` object.


def show_inputs(self, varnames=None, nids=None, wslice=None, stream=sys.stdout):

        if varnames is not None:
            # Build dictionary varname --> [(task1, value), (task2, value), ...]
            varnames = [s.strip() for s in list_strings(varnames)]
            dlist = collections.defaultdict(list)
            for task in self.select_tasks(nids=nids, wslice=wslice):
                dstruct = task.input.structure.as_dict(fmt="abivars")

                for vname in varnames:
                    value = task.input.get(vname, None)
                    if value is None: # maybe in structure?
                        value = dstruct.get(vname, None)
                    if value is not None:
                        dlist[vname].append((task, value))

            for vname in varnames:
                tv_list = dlist[vname]
                if not tv_list:
                    stream.write("[%s]: Found 0 tasks with this variable\n" % vname)
                else:
                    stream.write("[%s]: Found %s tasks with this variable\n" % (vname, len(tv_list)))
                    for i, (task, value) in enumerate(tv_list):
                        stream.write("   %s --> %s\n" % (str(value), task))
                stream.write("\n")

        else:
            lines = []
            for task in self.select_tasks(nids=nids, wslice=wslice):
                s = task.make_input(with_header=True)

                # Add info on dependencies.
                if task.deps:
                    s += "\n\nDependencies:\n" + "\n".join(str(dep) for dep in task.deps)
                else:
                    s += "\n\nDependencies: None"

                lines.append(2*"\n" + 80 * "=" + "\n" + s + 2*"\n")

            stream.writelines(lines)

Print the input of the tasks to the given stream.

Args:
        varnames:
            List of Abinit variables. If not None, only the variable in varnames
            are selected and printed.
        nids:
            List of node identifiers. By defaults all nodes are shown
        wslice:
            Slice object used to select works.
        stream:
            File-like object, Default: sys.stdout


def QA_SU_save_index_min(engine, client=DATABASE):

    engine = select_save_engine(engine)
    engine.QA_SU_save_index_min(client=client)

save index_min

Args:
        engine {[type]} -- [description]

    Keyword Arguments:
        client {[type]} -- [description] (default: {DATABASE})