def _gather_all_deps(self, args, kwargs):
    depends = []
    count = 0
    for dep in args:
        if isinstance(dep, Future):
            if (self.tasks[dep.tid]['status'] not in FINAL_STATES):
                count += 1
            depends.extend([dep])
    for key in kwargs:
        dep = kwargs[key]
        if isinstance(dep, Future):
            if (self.tasks[dep.tid]['status'] not in FINAL_STATES):
                count += 1
            depends.extend([dep])
    for dep in kwargs.get('inputs', []):
        if isinstance(dep, Future):
            if (self.tasks[dep.tid]['status'] not in FINAL_STATES):
                count += 1
            depends.extend([dep])
    return (count, depends)

Count the number of unresolved futures on which a task depends.

Args:
- args (List[args]) : The list of args list to the fn
- kwargs (Dict{kwargs}) : The dict of all kwargs passed to the fn

Returns:
- count, [list of dependencies]


def write_csv_from_dict(filename, input_dict):
    f = open(PATH_TO_DIR + '/data/' + filename, 'w')
    for k, v in input_dict.items():
        line = k
        for item in v:
            line += ',' + item
        f.write(line + '\n')
    f.flush()
    print('Wrote to file %s' % filename)
    check_with_golden(filename)

Writes out a `.csv` file from an input dictionary.

After writing out the file, it checks the new list against the golden
to make sure golden file is up-to-date.

Args:
filename: String that is the output file name.
input_dict: Dictionary that is to be written out to a `.csv` file.


def Approve(self, request, global_params=None):
    config = self.GetMethodConfig('Approve')
    return self._RunMethod(config, request, global_params=global_params)

Approves or rejects a pending build. If approved, the returned LRO will be analogous to the LRO returned from a CreateBuild call. If rejected, the returned LRO will be immediately done.

Args:
request: (CloudbuildProjectsLocationsBuildsApproveRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(Operation) The response message.


def forward(self, inputs, expert_size):
    input_list = inputs.split(expert_size, dim=0)
    output_list = []
    for i in range(self.num_experts):
        output_list.append(F.linear(input_list[i], self.weight[i]))
    results = torch.cat(output_list, dim=0)
    return results

Forward pass of the JetMoeParallelExperts module.

Args:
inputs (Tensor):
Input tensor.
expert_size:
Expert size information.

Returns:
Tensor: Output tensor.


def SMGetJobDictionaries(self, domain='kSMDomainSystemLaunchd'):

    cfstring_launchd = ctypes.c_void_p.in_dll(self.dll, domain)
    return CFArray(self.dll.SMCopyAllJobDictionaries(cfstring_launchd))

Copy all Job Dictionaries from the ServiceManagement.

Args:
domain: The name of a constant in Foundation referencing the domain.
Will copy all launchd services by default.

Returns:
A marshalled python list of dicts containing the job dictionaries.


def decode_list(self, ids):
    decoded_ids = []
    for id_ in ids:
        if (0 <= id_ < self._num_reserved_ids):
            decoded_ids.append(RESERVED_TOKENS[int(id_)])
        else:
            decoded_ids.append((id_ - self._num_reserved_ids))
    return [str(d) for d in decoded_ids]

Transform a sequence of int ids into a their string versions.

This method supports transforming individual input/output ids to their
string versions so that sequence to/from text conversions can be visualized
in a human readable format.

Args:
ids: list of integers to be converted.

Returns:
strs: list of human-readable string.


def has_course_mode(self, course_run_id, mode):

        course_modes = self.get_course_modes(course_run_id)
        return any(course_mode for course_mode in course_modes if course_mode['slug'] == mode)

Query the Enrollment API to see whether a course run has a given course mode available.

Arguments:
course_run_id (str): The string value of the course run's unique identifier

Returns:
bool: Whether the course run has the given mode avaialble for enrollment.


def __call__(self, old, new):

        if not new or not self.precondition():
            return
        self.validate(old, new)

Validate the `new` translation against the `old` one.

No checks are needed for deleted translations

Args:
old: The old translation.
new: The new translation.
Raises:
A ValidationError with an appropriate message.


def merge_tree(dest: Any, src: Any, merge_fn: Optional[Callable[[KeyPath, Any, Any], Any]]=None, root_path: Optional[KeyPath]=None) -> Any:
    if not root_path:
        root_path = KeyPath()
    if isinstance(dest, dict) and isinstance(src, dict):
        return _merge_dict_into_dict(dest, src, merge_fn, root_path)
    if isinstance(dest, list) and isinstance(src, dict):
        return _merge_dict_into_list(dest, src, root_path)
    if merge_fn:
        return merge_fn(root_path, dest, src)
    return src

Deep merge two (maybe) hierarchical values.

Args:
dest: Destination value.
src: Source value. When source value is a dict, it's considered as a
patch (delta) to the destination when destination is a dict or list.
For other source types, it's considered as a new value that will replace
dest completely.
merge_fn: A function to handle value merge that will be called for updated
or added keys. If a branch is added/updated, the root of branch will be
passed to merge_fn.
the signature of function is: (path, left_value, right_value) ->
final_value
If a key is only present in src dict, old_value is MISSING_VALUE.
If a key is only present in dest dict, new_value is MISSING_VALUE.
Otherwise both new_value and old_value are filled.

If final value is MISSING_VALUE, it will be removed from its parent
collection.
root_path: KeyPath of dest.

Returns:
Merged value.

Raises:
KeyError: Dict keys are not integers when merging into a list.


def tabledata_list(self, table_name, start_index=None, max_results=None, page_token=None):
    url = (Api._ENDPOINT + (Api._TABLEDATA_PATH % table_name))
    args = {}
    if start_index:
        args['startIndex'] = start_index
    if max_results:
        args['maxResults'] = max_results
    if (page_token is not None):
        args['pageToken'] = page_token
    return datalab.utils.Http.request(url, args=args, credentials=self._credentials)

Retrieves the contents of a table.

Args:
table_name: the name of the table as a tuple of components.
start_index: the index of the row at which to start retrieval.
max_results: an optional maximum number of rows to retrieve.
page_token: an optional token to continue the retrieval.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.


def _ParseLogLine(self, parser_mediator, structure, key):

    time_elements_tuple = self._GetTimeElementsTuple(structure)

    try:
      date_time = dfdatetime_time_elements.TimeElements(
          time_elements_tuple=time_elements_tuple)
    except ValueError:
      parser_mediator.ProduceExtractionWarning(
          'invalid date time value: {0!s}'.format(structure.date_time))
      return

    self._last_month = time_elements_tuple[1]

    if key == 'logline':
      self._previous_structure = structure
    else:
      structure = self._previous_structure

    event_data = MacAppFirewallLogEventData()
    event_data.action = structure.action
    event_data.agent = structure.agent
    event_data.computer_name = structure.computer_name

    event_data.process_name = structure.process_name.strip()
    event_data.status = structure.status

    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_ADDED)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parse a single log line and produce an event object.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
key (str): identifier of the structure of tokens.
structure (pyparsing.ParseResults): structure of tokens derived from
a line of a text file.


def custom_licenses(self):
    buf = (ctypes.c_char * self.MAX_BUF_SIZE)()
    result = self._dll.JLINK_EMU_GetLicenses(buf, self.MAX_BUF_SIZE)
    if (result < 0):
        raise errors.JLinkException(result)
    return ctypes.string_at(buf).decode()

Returns a string of the installed licenses the J-Link has.

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

Returns:
String of the contents of the custom licenses the J-Link has.


def cast_to_floatx(x):
    if isinstance(x, (tensor_lib.Tensor, variables_module.Variable, sparse_tensor.SparseTensor)):
        return math_ops.cast(x, dtype=floatx())
    return numpy_compat.np_asarray(x, dtype=floatx())

Cast a Numpy array to the default Keras float type.

Args:
x: Numpy array or TensorFlow tensor.

Returns:
The same array (Numpy array if `x` was a Numpy array, or TensorFlow tensor
if `x` was a tensor), cast to its new type.

Example:

>>> tf.keras.backend.floatx()
'float32'
>>> arr = np.array([1.0, 2.0], dtype='float64')
>>> arr.dtype
dtype('float64')
>>> new_arr = cast_to_floatx(arr)
>>> new_arr
array([1.,  2.], dtype=float32)
>>> new_arr.dtype
dtype('float32')


def _ResolveVars(value):
    if isinstance(value, dict):
        resolved_value = {}
        for k, v in value.items():
            resolved_value[k] = MessageValue._ResolveVars(v)
        return resolved_value
    if isinstance(value, list):
        return [MessageValue._ResolveVars(v) for v in value]
    if isinstance(value, stl.base.QualifierValue.Resolved):
        return value.Generate()
    if isinstance(value, stl.base.LocalVar):
        if value.value is None:
            raise ValueError("LocalVar '%s' does not have a value." % value.name)
        return value.value
    if isinstance(value, stl.base.Func):
        return value.Run()
    if isinstance(value, MessageValue):
        return value._EncodeToString()
    return value

Resolve any variables or run any functions in |value|.

Args:
value: Value which may have variables or functions to resolve.
Returns:
Resolved value.
Raises:
ValueError: If a concrete value for |value| cannot be determined.


def from_file(cls, fp, format_=None, fps=None, **kwargs):
    if (format_ is None):
        text = fp.read()
        fragment = text[:10000]
        format_ = autodetect_format(fragment)
        fp = io.StringIO(text)
    impl = get_format_class(format_)
    subs = cls()
    subs.format = format_
    subs.fps = fps
    impl.from_file(subs, fp, format_, fps=fps, **kwargs)
    return subs

Read subtitle file from file object.

See :meth:`SSAFile.load()` for full description.

Note:
This is a low-level method. Usually, one of :meth:`SSAFile.load()`
or :meth:`SSAFile.from_string()` is preferable.

Arguments:
fp (file object): A file object, ie. :class:`io.TextIOBase` instance.
Note that the file must be opened in text mode (as opposed to binary).

Returns:
SSAFile


def inverseHistogram(hist, bin_range):
    data = (hist.astype(float) / np.min(hist[np.nonzero(hist)]))
    new_data = np.empty(shape=np.sum(data, dtype=int))
    i = 0
    xvals = np.linspace(bin_range[0], bin_range[1], len(data))
    for (d, x) in zip(data, xvals):
        new_data[i:(i + d)] = x
        i += int(d)
    return new_data

sample data from given histogram and min, max values within range

Returns:
np.array: data that would create the same histogram as given


def get_program_type_by_slug(self, slug):
    return self._load_data(self.PROGRAM_TYPES_ENDPOINT, resource_id=slug, default=None)

Get a program type by its slug.

Arguments:
slug (str): The slug to identify the program type.

Returns:
dict: A program type object.


def ParseReceiverData(
      self, parser_mediator, query, row, **unused_kwargs):

    query_hash = hash(query)

    data = {}
    key_url = self._GetRowValue(query_hash, row, 'request_key')

    data_dict = {}
    description = 'MacKeeper Entry'

    if key_url.endswith('plist'):
      description = 'Configuration Definition'
      data['text'] = 'Plist content added to cache.'

    elif key_url.startswith('http:
      description = 'MacKeeper Event'
      try:
        _, _, part = key_url.partition('?')
        data['text'] = part.replace('&', ' ')
      except UnicodeDecodeError:
        data['text'] = 'N/A'

    elif key_url.startswith('http:
      description = 'Account Activity'
      _, _, activity = key_url.partition('
      if activity:
        data['text'] = 'Action started: {0:s}'.format(activity)
      else:
        data['text'] = 'Unknown activity.'

    elif key_url.startswith('http:
      description = 'Chat '
      try:
        jquery = self._GetRowValue(query_hash, row, 'data')
        jquery = codecs.decode(jquery, 'utf-8')
      except UnicodeDecodeError:
        jquery = ''

      data_dict = self._ExtractJQuery(jquery)
      data = self._ParseChatData(data_dict)

      data['entry_type'] = data_dict.get('type', '')
      if data['entry_type'] == 'comment':
        description += 'Comment'
      elif data['entry_type'] == 'outgoing':
        description += 'Outgoing Message'
      elif data['entry_type'] == 'incoming':
        description += 'Incoming Message'
      else:

        description += 'Entry'
        data['text'] = ';'.join(self._DictToListOfStrings(data_dict))
        if not data['text']:
          data['text'] = 'No additional data.'

    event_data = MacKeeperCacheEventData()
    event_data.description = description
    event_data.event_type = data.get('event_type', None)
    event_data.offset = self._GetRowValue(query_hash, row, 'id')
    event_data.query = query
    event_data.record_id = data.get('id', None)
    event_data.room = data.get('room', None)
    event_data.text = data.get('text', None)
    event_data.url = key_url
    event_data.user_name = data.get('user', None)
    event_data.user_sid = data.get('sid', None)

    time_value = self._GetRowValue(query_hash, row, 'time_string')
    if isinstance(time_value, py2to3.INTEGER_TYPES):
      date_time = dfdatetime_java_time.JavaTime(timestamp=time_value)
      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_ADDED)

    else:
      try:
        timestamp = timelib.Timestamp.FromTimeString(time_value)
      except errors.TimestampError:
        parser_mediator.ProduceExtractionWarning(
            'Unable to parse time string: {0:s}'.format(time_value))
        return

      event = time_events.TimestampEvent(
          timestamp, definitions.TIME_DESCRIPTION_ADDED)

    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a single row from the receiver and cache response table.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row.


def _build_recursive_hd_gather(input_tensors, devices, red_op):
    num_devices = len(devices)
    num_hops = int(math.log(num_devices, 2))
    if num_devices != 2 ** num_hops:
        raise ValueError('num_devices must be a power of 2')
    chunks = input_tensors
    for h in range(0, num_hops):
        span = 2 ** h
        group_size = span * 2
        new_chunks = [[] for _ in devices]
        for d in range(0, num_devices):
            if d % group_size >= group_size / 2:
                continue
            left_dev = devices[d]
            right_dev = devices[d + span]
            left_split = array_ops.split(chunks[d], 2)
            right_split = array_ops.split(chunks[d + span], 2)
            with ops.device(left_dev):
                new_chunks[d] = red_op(left_split[0], right_split[0])
            with ops.device(right_dev):
                new_chunks[d + span] = red_op(left_split[1], right_split[1])
        chunks = new_chunks
    return chunks

Construct the gather phase of recursive halving-doubling all-reduce.

Args:
input_tensors: list of `tf.Tensor` to be elementwise reduced.
devices: a list of strings naming the devices hosting input_tensors,
which will also be used to host the (partial) reduction values.
red_op: a binary elementwise reduction Op.

Returns:
list of `tf.Tensor` which are the fully reduced tensor shards.

Raises:
ValueError: num_devices not a power of 2, or tensor len not divisible
by 2 the proper number of times.


def sheets_tab_create(config, auth, sheet_url_or_name, sheet_tab):
    sheet_id, tab_id = sheets_tab_id(config, auth, sheet_url_or_name, sheet_tab)
    if tab_id is None:
        sheets_batch_update(config, auth, sheet_url_or_name, {'requests': [{'addSheet': {'properties': {'title': sheet_tab}}}]})

Create a tab in a sheet.

Args:
config - see starthinker/util/configuration.py
auth - user or service
url_or_name - one of: URL, document title, or id
sheet_tab - name of tab to get id for

No Return


def compress_file(filepath, compression='gz'):
    if (compression not in ['gz', 'bz2']):
        raise ValueError("Supported compression formats are 'gz' and 'bz2'.")
    from monty.io import zopen
    if (not filepath.lower().endswith(('.%s' % compression))):
        with open(filepath, 'rb') as f_in, zopen(('%s.%s' % (filepath, compression)), 'wb') as f_out:
            f_out.writelines(f_in)
        os.remove(filepath)

Compresses a file with the correct extension. Functions like standard
Unix command line gzip and bzip2 in the sense that the original
uncompressed files are not retained.

Args:
filepath (str): Path to file.
compression (str): A compression mode. Valid options are "gz" or
"bz2". Defaults to "gz".


def sg_summary_image(tensor, prefix=None, name=None):
    r

    prefix = '' if prefix is None else prefix + '/'

    name = prefix + _pretty_name(tensor) if name is None else prefix + name

    if not tf.get_variable_scope().reuse:
        tf.summary.image(name + '-im', tensor)

r"""Register `tensor` to summary report as `image`

Args:
tensor: A tensor to log as image
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.

Returns:
None


def _Matches(path, pattern_list):
    return any((fnmatch.fnmatchcase(path, pattern) for pattern in pattern_list))

Returns true if path matches any patten found in pattern_list.

Args:
path: A dot separated path to a package, class, method or variable
pattern_list: A list of wildcard patterns

Returns:
True if path matches any wildcard found in pattern_list.


def readSchedules(self, tableset):
    self.setContext('readSchedules')
    try:
        req_table = binascii.hexlify(str(tableset).zfill(1))
        req_str = (('01523102303037' + req_table) + '282903')
        self.request(False)
        req_crc = self.calc_crc16(req_str[2:].decode('hex'))
        req_str += req_crc
        self.m_serial_port.write(req_str.decode('hex'))
        raw_ret = self.m_serial_port.getResponse(self.getContext())
        self.serialPostEnd()
        return_crc = self.calc_crc16(raw_ret[1:(- 2)])
        if (tableset == ReadSchedules.Schedules_1_To_4):
            unpacked_read = self.unpackStruct(raw_ret, self.m_schd_1_to_4)
            self.convertData(unpacked_read, self.m_schd_1_to_4, self.m_kwh_precision)
            if (str(return_crc) == str(self.m_schd_1_to_4['crc16'][MeterData.StringValue])):
                ekm_log('Schedules 1 to 4 CRC success (06 return')
                self.setContext('')
                return True
        elif (tableset == ReadSchedules.Schedules_5_To_6):
            unpacked_read = self.unpackStruct(raw_ret, self.m_schd_5_to_6)
            self.convertData(unpacked_read, self.m_schd_5_to_6, self.m_kwh_precision)
            if (str(return_crc) == str(self.m_schd_5_to_6['crc16'][MeterData.StringValue])):
                ekm_log('Schedules 5 to 8 CRC success (06 return)')
                self.setContext('')
                return True
    except:
        ekm_log(traceback.format_exc(sys.exc_info()))
    self.setContext('')
    return False

Serial call to read schedule tariffs buffer

Args:
tableset (int): :class:`~ekmmeters.ReadSchedules` buffer to return.

Returns:
bool: True on completion and ACK.


def load_extra_data(cls, data):
    try:
        cls._extra_config.update(json.loads(data))
    except ValueError as exception:
        sys.stderr.write('Could convert to JSON. {0:s}'.format(exception))
        exit((- 1))

Loads extra JSON configuration parameters from a data buffer.

The data buffer must represent a JSON object.

Args:
data: str, the buffer to load the JSON data from.


def aggregate_single_gradient(grad_and_vars, use_mean, check_inf_nan):
    grads = [g for (g, _) in grad_and_vars]
    grad = tf.add_n(grads)
    if (use_mean and (len(grads) > 1)):
        grad = tf.multiply(grad, (1.0 / len(grads)))
    v = grad_and_vars[0][1]
    if check_inf_nan:
        has_nan_or_inf = tf.logical_not(tf.reduce_all(tf.is_finite(grads)))
        return ((grad, v), has_nan_or_inf)
    else:
        return ((grad, v), None)

Calculate the average gradient for a shared variable across all towers.

Note that this function provides a synchronization point across all towers.

Args:
grad_and_vars: A list or tuple of (gradient, variable) tuples. Each
(gradient, variable) pair within the outer list represents the gradient
of the variable calculated for a single tower, and the number of pairs
equals the number of towers.
use_mean: if True, mean is taken, else sum of gradients is taken.
check_inf_nan: check grads for nans and infs.

Returns:
The tuple ([(average_gradient, variable),], has_nan_or_inf) where the
gradient has been averaged across all towers. The variable is chosen from
the first tower. The has_nan_or_inf indicates the grads has nan or inf.


def model_from_path(model_path, fuzziness=False):
    app_name = '.'.join(model_path.split('.')[:(- 1)])
    model_name = model_path.split('.')[(- 1)]
    if (not app_name):
        return None
    module = importlib.import_module(app_name)
    try:
        model = getattr(module, model_name)
    except AttributeError:
        try:
            model = getattr(getattr(module, 'models'), model_name)
        except AttributeError:
            model = get_model(model_name, app_name, fuzziness=fuzziness)
    return model

Find the model class for a given model path like 'project.app.model'

Args:
path (str): dot-delimited model path, like 'project.app.model'

Returns:
Django Model-based class


def _CreateRouteTripsFolder(self, parent, route, style_id=None, schedule=None):
    if (not route.trips):
        return None
    trips = list(route.trips)
    trips.sort(key=(lambda x: x.trip_id))
    trips_folder = self._CreateFolder(parent, 'Trips', visible=False)
    for trip in trips:
        if (self.date_filter and (not trip.service_period.IsActiveOn(self.date_filter))):
            continue
        if trip.trip_headsign:
            description = ('Headsign: %s' % trip.trip_headsign)
        else:
            description = None
        coordinate_list = []
        for (secs, stoptime, tp) in trip.GetTimeInterpolatedStops():
            if (self.altitude_per_sec > 0):
                coordinate_list.append((stoptime.stop.stop_lon, stoptime.stop.stop_lat, ((secs - (3600 * 4)) * self.altitude_per_sec)))
            else:
                coordinate_list.append((stoptime.stop.stop_lon, stoptime.stop.stop_lat))
        placemark = self._CreatePlacemark(trips_folder, trip.trip_id, style_id=style_id, visible=False, description=description)
        self._CreateLineString(placemark, coordinate_list)
    return trips_folder

Create a KML Folder containing all the trips in the route.

The folder contains a placemark for each of these trips. If there are no
trips in the route, no folder is created and None is returned.

Args:
parent: The parent ElementTree.Element instance.
route: The transitfeed.Route instance.
style_id: A style id string for the placemarks or None.

Returns:
The Folder ElementTree.Element instance or None.


def list_skus(access_token, subscription_id, location, publisher, offer):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.Compute/', 'locations/', location, '/publishers/', publisher, '/artifacttypes/vmimage/offers/', offer, '/skus?api-version=', COMP_API])
    return do_get(endpoint, access_token)

List available VM image skus for a publisher offer.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
location (str): Azure data center location. E.g. westus.
publisher (str): VM image publisher. E.g. MicrosoftWindowsServer.
offer (str): VM image offer. E.g. WindowsServer.

Returns:
HTTP response with JSON list of skus.


def split(self, value, lengths, name=None):
    return self._implementation.split(value, lengths, name=name)

Split the values of a `Tensor` into the TensorArray.

Args:
value: (N+1)-D.  Tensor of type `dtype`.  The Tensor to split.
lengths: 1-D.  int32 vector with the lengths to use when splitting `value`
along its first dimension.
name: A name for the operation (optional).

Returns:
A new TensorArray object with flow that ensures the split occurs.
Use this object for all subsequent operations.

Raises:
ValueError: if the shape inference fails.


def JoinKeyPath(path_segments):

  path_segments = [
      segment.split(definitions.KEY_PATH_SEPARATOR)
      for segment in path_segments]

  path_segments = [
      element for sublist in path_segments for element in sublist]

  path_segments = filter(None, path_segments)

  key_path = definitions.KEY_PATH_SEPARATOR.join(path_segments)
  if not key_path.startswith('HKEY_'):
    key_path = '{0:s}{1:s}'.format(definitions.KEY_PATH_SEPARATOR, key_path)
  return key_path

Joins the path segments into key path.

Args:
path_segments (list[str]): Windows Registry key path segments.

Returns:
str: key path.


def LoadConfig(configuration):
    parser = ConfigParser()
    configuration.log.debug('Attempting to parse configuration file: %s', configuration.config_file)
    parser.read(configuration.config_file)
    default = 'DEFAULT'
    default_source = FixValue(parser.get(default, Config.OPT_SOURCE))
    default_cache = FixValue(parser.get(default, Config.OPT_CACHE))
    configuration.timestamp_dir = FixValue(parser.get(default, Config.OPT_TIMESTAMP_DIR))
    if parser.has_option(default, Config.OPT_LOCKFILE):
        configuration.lockfile = FixValue(parser.get(default, Config.OPT_LOCKFILE))
    if not configuration.maps:
        maplist = FixValue(parser.get(default, Config.OPT_MAPS))
        if maplist:
            configuration.maps = [m.strip() for m in maplist.split(',')]
        else:
            configuration.maps = []
    for map_name in configuration.maps:
        map_options = MapOptions()
        source = default_source
        cache = default_cache
        if parser.has_section(map_name):
            if parser.has_option(map_name, Config.OPT_SOURCE):
                source = FixValue(parser.get(map_name, Config.OPT_SOURCE))
            if parser.has_option(map_name, Config.OPT_CACHE):
                cache = FixValue(parser.get(map_name, Config.OPT_CACHE))
        map_options.source = Options(parser.items(default), source)
        map_options.cache = Options(parser.items(default), cache)
        if parser.has_section(map_name):
            options = Options(parser.items(map_name), source)
            map_options.source.update(options)
            options = Options(parser.items(map_name), cache)
            map_options.cache.update(options)
        map_options.source['name'] = source
        map_options.cache['name'] = cache
        configuration.options[map_name] = map_options
    configuration.log.info('Configured maps are: %s', ', '.join(configuration.maps))
    configuration.log.debug('loaded configuration: %r', configuration)

Load the on-disk configuration file and merge it into config.

Args:
configuration: a config.Config object

Raises:
error.NoConfigFound: no configuration file was found


def ParseFileObject(self, parser_mediator, file_object):

    file_header_map = self._GetDataTypeMap('asl_file_header')

    try:
      file_header, _ = self._ReadStructureFromFileObject(
          file_object, 0, file_header_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.UnableToParseFile(
          'Unable to parse file header with error: {0!s}'.format(
              exception))

    if file_header.signature != self._FILE_SIGNATURE:
      raise errors.UnableToParseFile('Invalid file signature.')

    file_size = file_object.get_size()

    if file_header.first_log_entry_offset > 0:
      last_log_entry_offset = 0
      file_offset = file_header.first_log_entry_offset

      while file_offset < file_size:
        last_log_entry_offset = file_offset

        try:
          file_offset = self._ParseRecord(
              parser_mediator, file_object, file_offset)
        except errors.ParseError as exception:
          parser_mediator.ProduceExtractionWarning(
              'unable to parse record with error: {0!s}'.format(exception))
          return

        if file_offset == 0:
          break

      if last_log_entry_offset != file_header.last_log_entry_offset:
        parser_mediator.ProduceExtractionWarning(
            'last log entry offset does not match value in file header.')

Parses an ASL file-like object.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): file-like object.

Raises:
UnableToParseFile: when the file cannot be parsed.


def _on_channel_open(self, channel):

        channel.add_on_close_callback(self._on_channel_close)
        channel.add_on_cancel_callback(self._on_cancel)

        channel.basic_qos(callback=self._on_qosok, **config.conf["qos"])

Callback used when a channel is opened.

This registers all the channel callbacks.

Args:
channel (pika.channel.Channel): The channel that successfully opened.


def GetSubkeyByIndex(self, index):

    if not self._registry_key and self._registry:
      self._GetKeyFromRegistry()

    subkeys = list(self._subkeys.values())

    if index < 0 or index >= len(subkeys):
      raise IndexError('Index out of bounds.')

    return subkeys[index]

Retrieves a subkey by index.

Args:
index (int): index of the subkey.

Returns:
WinRegistryKey: Windows Registry subkey or None if not found.

Raises:
IndexError: if the index is out of bounds.


def partition(self, id_):
    from ..orm import Partition as OrmPartition
    from sqlalchemy import or_
    from ..identity import PartialPartitionName
    if isinstance(id_, PartitionIdentity):
        id_ = id_.id_
    elif isinstance(id_, PartialPartitionName):
        id_ = id_.promote(self.bundle.identity.name)
    session = self.bundle.dataset._database.session
    q = session.query(OrmPartition).filter((OrmPartition.d_vid == self.bundle.dataset.vid)).filter(or_((OrmPartition.id == str(id_).encode('ascii')), (OrmPartition.vid == str(id_).encode('ascii'))))
    try:
        orm_partition = q.one()
        return self.bundle.wrap_partition(orm_partition)
    except NoResultFound:
        orm_partition = None
    if (not orm_partition):
        q = session.query(OrmPartition).filter((OrmPartition.d_vid == self.bundle.dataset.vid)).filter((OrmPartition.name == str(id_).encode('ascii')))
        try:
            orm_partition = q.one()
            return self.bundle.wrap_partition(orm_partition)
        except NoResultFound:
            orm_partition = None
    return orm_partition

Get a partition by the id number.

Arguments:
id_ -- a partition id value

Returns:
A partitions.Partition object

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

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


def on_success(self, inv_plugin, emit_set_slot):
    self.dirty = set()
    self.apply(inv_plugin)
    for changed_slot in self.dirty:
        emit_set_slot(changed_slot)

Called when the click was successful
and should be applied to the inventory.

Args:
inv_plugin (InventoryPlugin): inventory plugin instance
emit_set_slot (func): function to signal a slot change,
should be InventoryPlugin().emit_set_slot


def housekeeping(self, **kwargs):
    path = ('/projects/%s/housekeeping' % self.get_id())
    self.manager.gitlab.http_post(path, **kwargs)

Start the housekeeping task.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabHousekeepingError: If the server failed to perform the
request


def assignHolidayDate(self, holiday, month, day):

        holiday += 1
        if (month > 12) or (month < 0) or (day > 31) or (day < 0) or (holiday < 1) or (holiday > Extents.Holidays):
            ekm_log("Out of bounds: month " + str(month) + " day " + str(day) + " holiday " + str(holiday))
            return False

        day_str = "Holiday_" + str(holiday) + "_Day"
        mon_str = "Holiday_" + str(holiday) + "_Month"
        if day_str not in self.m_holiday_date_params:
            ekm_log("Incorrect index: " + day_str)
            return False
        if mon_str not in self.m_holiday_date_params:
            ekm_log("Incorrect index: " + mon_str)
            return False
        self.m_holiday_date_params[day_str] = day
        self.m_holiday_date_params[mon_str] = month
        return True

Set a singe holiday day and month in object buffer.

There is no class style enum for holidays.

Args:
holiday (int): 0-19 or range(Extents.Holidays).
month (int): Month 1-12.
day (int): Day 1-31

Returns:
bool: True on completion.


def delete(self, **options):
    fut = delete_async(self.key(), **options)
    fut.get_result()

Permanently delete this blob from Blobstore.

Args:
**options: Options for create_rpc().


def send_msg_to_webhook(self, message):

        payload = {
            'content':message
        }

        header = {
            'Content-Type':'application/json'
        }

        try:
            request = requests.post(
                self.api_url,
                headers=header,
                json=payload
            )
            request.raise_for_status()
        except Exception as error_msg:
            warning_msg = (
                'EXCEPTION: UNABLE TO COMMIT LOG MESSAGE' +
                '\n\texception={0}'.format(repr(error_msg)) +
                '\n\tmessage={0}'.format(message)
            )
            warnings.warn(
                warning_msg,
                exceptions.WebhookFailedEmitWarning
            )

separated Requests logic for easier testing

Args:
message (str): actual logging string to be passed to REST endpoint

Todo:
* Requests.text/json return for better testing options


def _decompose_and_get_unitary(val: Union[('cirq.Operation', 'cirq.Gate')]) -> np.ndarray:
    from cirq.protocols.apply_unitary import apply_unitary, ApplyUnitaryArgs
    from cirq.protocols.decompose import decompose_once, decompose_once_with_qubits
    from cirq import Gate, LineQubit, Operation
    if isinstance(val, Operation):
        qubits = val.qubits
        decomposed_val = decompose_once(val, default=None)
    elif isinstance(val, Gate):
        qubits = tuple(LineQubit.range(val.num_qubits()))
        decomposed_val = decompose_once_with_qubits(val, qubits, default=None)
    if (decomposed_val is not None):
        n = len(qubits)
        state = np.eye((1 << n), dtype=np.complex128)
        state.shape = ((2,) * (2 * n))
        buffer = np.zeros(state.shape, dtype=np.complex128)
        qubit_map = {q: i for (i, q) in enumerate(qubits)}
        result = state
        for op in decomposed_val:
            indices = [qubit_map[q] for q in op.qubits]
            result = apply_unitary(unitary_value=op, args=ApplyUnitaryArgs(state, buffer, indices), default=None)
            if (result is None):
                return None
            if (result is buffer):
                buffer = state
            state = result
        if (result is not None):
            return result.reshape(((1 << n), (1 << n)))

Try to decompose a cirq.Operation or cirq.Gate, and return its unitary
if it exists.

Returns:
If `val` can be decomposed into unitaries, calculate the resulting
unitary and return it. If it doesn't exist, None is returned.


def CopyFromDateTimeString(self, time_string):
    date_time_values = self._CopyDateTimeFromString(time_string)
    year = date_time_values.get('year', 0)
    month = date_time_values.get('month', 0)
    day_of_month = date_time_values.get('day_of_month', 0)
    hours = date_time_values.get('hours', 0)
    minutes = date_time_values.get('minutes', 0)
    seconds = date_time_values.get('seconds', 0)
    microseconds = date_time_values.get('microseconds', None)
    if (year > 9999):
        raise ValueError('Unsupported year value: {0:d}.'.format(year))
    timestamp = self._GetNumberOfSecondsFromElements(year, month, day_of_month, hours, minutes, seconds)
    timestamp = (float(timestamp) / definitions.SECONDS_PER_DAY)
    timestamp += self._DELPHI_TO_POSIX_BASE
    if (microseconds is not None):
        timestamp += (float(microseconds) / definitions.MICROSECONDS_PER_DAY)
    self._normalized_timestamp = None
    self._timestamp = timestamp
    self.is_local_time = False

Copies a Delphi TDateTime timestamp from a string.

Args:
time_string (str): date and time value formatted as:
YYYY-MM-DD hh:mm:ss.######[+-]##:##

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

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


def set_local_interface(self, value=None, default=False, disable=False):

        return self._configure_mlag('local-interface', value, default, disable)

Configures the mlag local-interface value

Args:
value (str): The value to configure the local-interface
default (bool): Configures the local-interface using the
default keyword
disable (bool): Negates the local-interface using the no keyword

Returns:
bool: Returns True if the commands complete successfully


def match_date(date):

    date_pattern = re.compile("^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])")
    if re.match(date_pattern, date):
        return True

    return False

Check if a string is a valid date

Args:
date(str)

Returns:
bool


def profile_operations(self, options):
    opts = _build_options(options)
    tfprof_node = tfprof_output_pb2.MultiGraphNodeProto()
    try:
        tfprof_node.ParseFromString(print_mdl.Profile('op'.encode('utf-8'), opts.SerializeToString()))
    except message.DecodeError as e:
        sys.stderr.write('Cannot parse returned proto: %s.\n' % e)
    return tfprof_node

Profile the statistics of the Operation types (e.g.

MatMul, Conv2D).

Args:
options: A dict of options. See core/profiler/g3doc/options.md.

Returns:
a MultiGraphNodeProto that records the results.


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

        tstream = BytearrayStream()

        self.hashing_algorithm.write(tstream, kmip_version=kmip_version)
        self.digest_value.write(tstream, kmip_version=kmip_version)
        self.key_format_type.write(tstream, kmip_version=kmip_version)

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

Write the data encoding the Digest object to a stream.

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


def show(self, objtype, objid):

        url = self._object_url(objtype, int(objid))
        return self._make_request(url, method="get")

Query for a specific resource by ID

Args:
objtype (str): object type, e.g. 'device', 'interface'
objid (int): object ID (DeviceID, etc.)
Returns:
A dict with that object
Raises:
requests.exceptions.HTTPError


def wait_for_stop(self, timeout=None):
    return self._stop_event.wait(timeout)

Wait till the Coordinator is told to stop.

Args:
timeout: Float.  Sleep for up to that many seconds waiting for
should_stop() to become True.

Returns:
True if the Coordinator is told stop, False if the timeout expired.


Extracts pycrypto X509 objects from SSL certificates chain string.

Args:
certs_txt: SSL certificates chain string.

Returns:
result: List of pycrypto X509 objects.


def __init__(self, file_handle, schema):
    if not file_handle.writable():
        raise ValueError('Output stream must be writable')
    self._file_handle = file_handle
    avro_schema = fastavro.parse_schema(get_avro_schema_from_table_schema(schema))
    self._avro_writer = fastavro.write.Writer(self._file_handle, avro_schema)

Initialize an AvroRowWriter.

Args:
file_handle (io.IOBase): Output stream to write Avro records to.
schema (Dict[Text, Any]): BigQuery table schema.


def _ParseFileEntry(self, knowledge_base, file_entry):

    if file_entry.link:

      _, _, time_zone = file_entry.link.partition('zoneinfo/')

    else:

      file_object = file_entry.GetFileObject()

      time_zone = None
      try:
        time_zone_file = tz.tzfile(file_object)
        date_time = datetime.datetime(2017, 1, 1)
        time_zone = time_zone_file.tzname(date_time)

      except ValueError:

        logger.error('Unable to read time zone information file.')

      finally:
        file_object.close()

    if time_zone:
      try:
        knowledge_base.SetTimeZone(time_zone)
      except ValueError:

        logger.error('Unable to set time zone in knowledge base.')

Parses artifact file system data for a preprocessing attribute.

Args:
knowledge_base (KnowledgeBase): to fill with preprocessing information.
file_entry (dfvfs.FileEntry): file entry that contains the artifact
value data.

Raises:
errors.PreProcessFail: if the preprocessing fails.


def Merge(self, other):
    if type(self) != type(other):
        raise TypeError('Attempt to Merge() differently typed Maps: %r != %r' % (type(self), type(other)))
    if other.GetModifyTimestamp() and self.GetModifyTimestamp():
        if other.GetModifyTimestamp() < self.GetModifyTimestamp():
            raise error.InvalidMerge('Attempt to Merge a map with an older modify time into a newer one: other: %s, self: %s' % (other.GetModifyTimestamp(), self.GetModifyTimestamp()))
    if other.GetUpdateTimestamp() and self.GetUpdateTimestamp():
        if other.GetUpdateTimestamp() < self.GetUpdateTimestamp():
            raise error.InvalidMerge('Attempt to Merge a map with an older update time into a newer one: other: %s, self: %s' % (other.GetUpdateTimestamp(), self.GetUpdateTimestamp()))
    self.log.info('merging from a map of %d entries', len(other))
    merge_count = 0
    for their_entry in other:
        if their_entry not in self:
            if self.Add(their_entry):
                merge_count += 1
    self.log.info('%d of %d entries were new or modified', merge_count, len(other))
    if merge_count > 0:
        self.SetModifyTimestamp(other.GetModifyTimestamp())
    self.SetUpdateTimestamp(other.GetUpdateTimestamp())
    return merge_count > 0

Update this Map based on another Map.

Walk over other and for each entry, Add() it if it doesn't
exist -- this will update changed entries as well as adding
new ones.

Args:
other: A maps.Map instance.

Returns:
True if anything was added or modified, False if
nothing changed.

Raises:
TypeError: Merging differently typed Maps.
InvalidMerge: Attempt to Merge an older map into a newer one.


def ProcessNewBlock(self, block):
    added = set()
    changed = set()
    deleted = set()
    try:
        for tx in block.FullTransactions:
            for (index, output) in enumerate(tx.outputs):
                state = self.CheckAddressState(output.ScriptHash)
                if ((state & AddressState.InWallet) > 0):
                    key = CoinReference(tx.Hash, index)
                    if (key in self._coins.keys()):
                        coin = self._coins[key]
                        coin.State |= CoinState.Confirmed
                        changed.add(coin)
                    else:
                        newcoin = Coin.CoinFromRef(coin_ref=key, tx_output=output, state=CoinState.Confirmed, transaction=tx)
                        self._coins[key] = newcoin
                        added.add(newcoin)
                    if ((state & AddressState.WatchOnly) > 0):
                        self._coins[key].State |= CoinState.WatchOnly
                        changed.add(self._coins[key])
        for tx in block.FullTransactions:
            for input in tx.inputs:
                if (input in self._coins.keys()):
                    if (self._coins[input].Output.AssetId == Blockchain.SystemShare().Hash):
                        coin = self._coins[input]
                        coin.State |= (CoinState.Spent | CoinState.Confirmed)
                        changed.add(coin)
                    else:
                        deleted.add(self._coins[input])
                        del self._coins[input]
        for claimTx in [tx for tx in block.Transactions if (tx.Type == TransactionType.ClaimTransaction)]:
            for ref in claimTx.Claims:
                if (ref in self._coins.keys()):
                    deleted.add(self._coins[ref])
                    del self._coins[ref]
        self._current_height += 1
        self.OnProcessNewBlock(block, added, changed, deleted)
        if (((len(added) + len(deleted)) + len(changed)) > 0):
            self.BalanceChanged()
    except Exception as e:
        traceback.print_stack()
        traceback.print_exc()
        logger.error(('could not process %s ' % e))

Processes a block on the blockchain.  This should be done in a sequential order, ie block 4 should be
only processed after block 3.

Args:
block: (neo.Core.Block) a block on the blockchain.


def _GetStat(self):
    stat_object = vfs_stat.VFSStat()
    stat_object.size = self.path_spec.range_size
    stat_object.type = stat_object.TYPE_FILE
    return stat_object

Retrieves a stat object.

Returns:
VFSStat: a stat object.

Raises:
BackEndError: when the encoded stream is missing.


def from_celery(cls, worker_name, job_dict, celery_app):
    if ((not isinstance(job_dict, dict)) or ('id' not in job_dict)):
        raise JobStatInvalid('The job description is missing important fields.')
    async_result = AsyncResult(id=job_dict['id'], app=celery_app)
    a_info = (async_result.info if isinstance(async_result.info, dict) else None)
    return JobStats(name=(a_info.get('name', '') if (a_info is not None) else ''), job_id=job_dict['id'], job_type=(a_info.get('type', '') if (a_info is not None) else ''), workflow_id=(a_info.get('workflow_id', '') if (a_info is not None) else ''), queue=(a_info.get('queue', '') if (a_info is not None) else ''), start_time=(a_info.get('start_time', None) if (a_info is not None) else None), arguments=(a_info.get('arguments', {}) if (a_info is not None) else {}), acknowledged=job_dict['acknowledged'], func_name=job_dict['type'], hostname=job_dict['hostname'], worker_name=worker_name, worker_pid=job_dict['worker_pid'], routing_key=job_dict['delivery_info']['routing_key'])

Create a JobStats object from the dictionary returned by celery.

Args:
worker_name (str): The name of the worker this jobs runs on.
job_dict (dict): The dictionary as returned by celery.
celery_app: Reference to a celery application object.

Returns:
JobStats: A fully initialized JobStats object.


def get_metrics_namespace(self) -> str:
    return 'BeamML_Onnx'

Returns:
A namespace for metrics collected by the RunInference transform.


def initialize_schema(connection):

  cursor = connection.cursor()
  cursor.execute("PRAGMA application_id={}".format(_TENSORBOARD_APPLICATION_ID))
  cursor.execute("PRAGMA user_version={}".format(_TENSORBOARD_USER_VERSION))
  with connection:
    for statement in _SCHEMA_STATEMENTS:
      lines = statement.strip('\n').split('\n')
      message = lines[0] + ('...' if len(lines) > 1 else '')
      logger.debug('Running DB init statement: %s', message)
      cursor.execute(statement)

Initializes the TensorBoard sqlite schema using the given connection.

Args:
connection: A sqlite DB connection.


def create_datasets():
    if use_device:
        datasets = []
        for i in range(len(self.embedding_devices)):
            datasets.append(dataset_ops.DatasetV2.from_tensor_slices({'feature': [[[i % self._num_cores_per_replica]]]}).repeat())
        return datasets
    else:
        dataset = strategy.distribute_datasets_from_function(input_fn, options=distribute_lib.InputOptions(experimental_fetch_to_device=False))
        return [dataset]

Creates either a per-replica dataset, or multiple per-devices ones.

This function explicitly creates per-device datasets because the strategy
does not produce a distributed dataset in the model-parallel case; there
is only one replica. Without this consideration, the embeddings would be
read as [0, 0] instead of the expected [0, 1] since all the devices would
receive the same value.

Returns:
A list of one or more dataset(s).


def aggregate(self, dataset_ids=None, boundary='exact', side='left', func='mean', **dim_kwargs):
    new_scn = self.copy(datasets=dataset_ids)
    for (src_area, ds_ids) in new_scn.iter_by_area():
        if (src_area is None):
            for ds_id in ds_ids:
                new_scn.datasets[ds_id] = self[ds_id]
            continue
        if (boundary != 'exact'):
            raise NotImplementedError("boundary modes appart from 'exact' are not implemented yet.")
        target_area = src_area.aggregate(**dim_kwargs)
        resolution = max(target_area.pixel_size_x, target_area.pixel_size_y)
        for ds_id in ds_ids:
            res = self[ds_id].coarsen(boundary=boundary, side=side, func=func, **dim_kwargs)
            new_scn.datasets[ds_id] = getattr(res, func)()
            new_scn.datasets[ds_id].attrs['area'] = target_area
            new_scn.datasets[ds_id].attrs['resolution'] = resolution
    return new_scn

Create an aggregated version of the Scene.

Args:
dataset_ids (iterable): DatasetIDs to include in the returned
`Scene`. Defaults to all datasets.
func (string): Function to apply on each aggregation window. One of
'mean', 'sum', 'min', 'max', 'median', 'argmin',
'argmax', 'prod', 'std', 'var'.
'mean' is the default.
boundary: Not implemented.
side: Not implemented.
dim_kwargs: the size of the windows to aggregate.

Returns:
A new aggregated scene

See also:
xarray.DataArray.coarsen

Example:
`scn.aggregate(func='min', x=2, y=2)` will aggregate 2x2 pixels by
applying the `min` function.


def BuildDefaultValue(self, value_cls):
    try:
        return value_cls()
    except Exception as e:
        logging.exception(e)
        raise DefaultValueError(("Can't create default for value %s: %s" % (value_cls.__name__, e)))

Renders default value of a given class.

Args:
value_cls: Default value of this class will be rendered. This class has to
be (or to be a subclass of) a self.value_class (i.e. a class that this
renderer is capable of rendering).

Returns:
An initialized default value.

Raises:
DefaultValueError: if something goes wrong.


def remove(self, key):
    self.raise_error_if_not_open()
    if (key in self._file):
        del self._file[key]

Remove the data stored for the given key.

Args:
key (str): Key of the data to remove.

Note:
The container has to be opened in advance.


def load(config):

    if config.sys_path:
        logger.debug("Appending %s to sys.path.", config.sys_path)
        sys.path.append(config.sys_path)
        logger.debug("sys.path is now %s", sys.path)
    if config.lookups:
        for key, handler in config.lookups.items():
            register_lookup_handler(key, handler)

    return config

Loads a stacker configuration by modifying sys paths, loading lookups,
etc.

Args:
config (:class:`Config`): the stacker config to load.

Returns:
:class:`Config`: the stacker config provided above.


def parse_init_dat(infile):

    init_dict = {}

    log.debug('{}: reading file...'.format(infile))
    with open(infile, 'r') as f:

        head = [next(f).strip() for x in range(2)]

    summary = head[0].split()
    difficulty = summary[1]

    top_template_info = head[1].split()
    top_template_pdbchain = top_template_info[3]
    top_template_pdb = top_template_pdbchain[:4]
    top_template_chain = top_template_pdbchain[4:]

    init_dict['difficulty'] = difficulty
    init_dict['top_template_pdb'] = top_template_pdb
    init_dict['top_template_chain'] = top_template_chain

    return init_dict

Parse the main init.dat file which contains the modeling results

The first line of the file init.dat contains stuff like::

"120 easy  40   8"

The other lines look like this::

"     161   11.051   1  1guqA MUSTER"

and getting the first 10 gives you the top 10 templates used in modeling

Args:
infile (stt): Path to init.dat

Returns:
dict: Dictionary of parsed information


def resolve_mode(self, name):

        if name not in settings.CODEMIRROR_MODES:
            msg = ("Given config name '{}' does not exists in "
                   "'settings.CODEMIRROR_MODES'.")
            raise UnknowModeError(msg.format(name))

        return settings.CODEMIRROR_MODES.get(name)

From given mode name, return mode file path from
``settings.CODEMIRROR_MODES`` map.

Arguments:
name (string): Mode name.

Raises:
KeyError: When given name does not exist in
``settings.CODEMIRROR_MODES``.

Returns:
string: Mode file path.


class PatchTSMixerLinearHead(nn.Module):

    def __init__(self, config: PatchTSMixerConfig, distribution_output=None):
        super().__init__()
        self.head_aggregation = config.head_aggregation
        self.output_range = config.output_range
        if config.head_aggregation is None:
            mul_factor = config.num_patches
        else:
            mul_factor = 1
        self.distribution_output = distribution_output
        if distribution_output is None:
            self.projection = nn.Linear(config.d_model * config.num_input_channels * mul_factor, config.num_targets)
        else:
            self.projection = distribution_output.get_parameter_projection(config.d_model * config.num_input_channels * mul_factor)
        if config.head_aggregation is None:
            self.flatten = nn.Flatten(start_dim=-3)
        else:
            self.flatten = nn.Flatten(start_dim=-2)
        self.dropout = nn.Dropout(config.head_dropout)

    def forward(self, hidden_features):

        hidden_features = hidden_features.transpose(-1, -2)
        if self.head_aggregation == 'use_last':
            hidden_features = hidden_features[..., -1]
        elif self.head_aggregation == 'max_pool':
            hidden_features = hidden_features.max(dim=-1).values
        elif self.head_aggregation == 'avg_pool':
            hidden_features = hidden_features.mean(dim=-1)
        if self.flatten:
            hidden_features = self.flatten(hidden_features)
        hidden_features = self.dropout(hidden_features)
        hidden_features = self.projection(hidden_features)
        if self.distribution_output is None and self.output_range is not None:
            hidden_features = torch.sigmoid(hidden_features) * (self.output_range[1] - self.output_range[0]) + self.output_range[0]
        return hidden_features

Linear head for Classification and Regression.

Args:
config (`PatchTSMixerConfig`):
Configuration.


def field(*, validate: Optional[Callable[[_In], _OutT]]=None, **kwargs: Any) -> dataclasses.Field[_OutT]:
    if validate is None:
        return dataclasses.field(**kwargs)
    else:
        field_ = _Field(validate=validate, field_kwargs=kwargs)
        return typing.cast(dataclasses.Field, field_)

Like `dataclasses.field`, but allow `validator`.

Args:
validate: A callable `(x) -> x` called each time the variable is assigned.
**kwargs: Kwargs forwarded to `dataclasses.field`

Returns:
The field.


def for_new_graph(*args, **kwargs):

  graph = tf.Graph()
  with graph.as_default():
    return for_default_graph(*args, **kwargs)

Creates a Bookkeeper for a new graph.

You must use `m.g.as_default()` to put the graph in scope:

m = Bookkeeper.for_new_graph()
with m.g.as_default():
...

Args:
*args: Arguments to pass into Bookkeeper's constructor.
**kwargs: Arguments to pass into Bookkeeper's constructor.
Returns:
A new Bookkeeper.


def progress(self):
    return Progress(done=len(self._get_all_set_properties()), base=len(worker_mapping()))

Get progress.

Returns:
namedtuple: :class:`Progress`.


def inspect_node(self, node_id):
    url = self._url('/nodes/{0}', node_id)
    return self._result(self._get(url), True)

Retrieve low-level information about a swarm node

Args:
node_id (string): ID of the node to be inspected.

Returns:
A dictionary containing data about this node.

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


def __init__(self, match=Match(), table_id=0xff, out_port=Port.OFPP_NONE):

        super().__init__()
        self.match = match
        self.table_id = table_id
        self.out_port = out_port

Create a AggregateStatsRequest with the optional parameters below.

Args:
match (~pyof.v0x01.common.flow_match.Match): Fields to match.
table_id (int): ID of table to read (from pyof_table_stats) 0xff
for all tables or 0xfe for emergency.
out_port (int): Require matching entries to include this as an
output port. A value of OFPP_NONE indicates no restriction.


def expected_counts(dataframe, rownames, colnames):

    cont_table = contingency_table(dataframe, rownames=rownames, colnames=colnames, margins=True)
    row_counts = cont_table['All']
    column_counts = cont_table.loc['All']
    total_observations = cont_table['All']['All']

    for column in cont_table.columns:
        for row in cont_table.index:
            cont_table[column][row] = column_counts[column]*row_counts[row]/total_observations
    return cont_table

Expected counts of the multivariate frequency distribution of the variables given the
null hypothesis of complete independence between variables.
Args:
rownames: the column name or list of columns names that make the keys of the rows
colnames: the column name or list of columns names that make the keys of the columns


class PerceiverAudioPostprocessor(nn.Module):

    def __init__(self, config: PerceiverConfig, in_channels: int, postproc_type: str='patches') -> None:
        super().__init__()
        if postproc_type not in ('patches',):
            raise ValueError('Invalid postproc_type!')
        self.classifier = nn.Linear(in_channels, config.samples_per_patch)

    def forward(self, inputs: torch.Tensor, pos: Optional[torch.Tensor]=None, modality_sizes=None) -> torch.Tensor:
        logits = self.classifier(inputs)
        return torch.reshape(logits, [inputs.shape[0], -1])

Audio postprocessing for Perceiver. Can be used to convert the decoder output to audio features.

Args:
config ([*PerceiverConfig*]):
Model configuration.
in_channels (`int`):
Number of channels in the input.
postproc_type (`str`, *optional*, defaults to `"patches"`):
Postprocessor type to use. Currently, only "patches" is supported.


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(dict(x, problem_id=tf.constant([i])), hparams))) for (j, d) in enumerate(datasets)]
    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(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 set_number_of_partitions(self, number_of_partitions):
    if self._frozen:
        if self._number_of_partitions != number_of_partitions:
            raise ValueError(f"Can't set number_of_partitions to {number_of_partitions} since it has been frozen to use {self._number_of_partitions}.")
    else:
        self._number_of_partitions = number_of_partitions

Sets the number of partitions for the current policy.

If the policy has been frozen then shard_dimension must match the
existing setting.

Args:
number_of_partitions: The number of partitions to use in the policy.

Raises:
ValueError: If the policy has been frozen and shard_dimension
differs from the frozen value.


def to_script(self, wf_name='wf'):
    self._closed()
    script = []
    params = []
    returns = []
    for (name, typ) in self.wf_inputs.items():
        params.append("{}='{}'".format(name, typ))
        returns.append(name)
    script.append('{} = {}.add_inputs({})'.format(', '.join(returns), wf_name, ', '.join(params)))
    returns = []
    for (name, step) in self.wf_steps.items():
        pyname = step.python_name
        returns = ['{}_{}'.format(pyname, o) for o in step['out']]
        params = ['{}={}'.format(name, python_name(param)) for (name, param) in step['in'].items()]
        script.append('{} = {}.{}({})'.format(', '.join(returns), wf_name, pyname, ', '.join(params)))
    params = []
    for (name, details) in self.wf_outputs.items():
        params.append('{}={}'.format(name, python_name(details['outputSource'])))
    script.append('{}.add_outputs({})'.format(wf_name, ', '.join(params)))
    return '\n'.join(script)

Generated and print the scriptcwl script for the currunt workflow.

Args:
wf_name (str): string used for the WorkflowGenerator object in the
generated script (default: ``wf``).


def safe_indicator(self, indicator, errors='strict'):
    if (indicator is not None):
        try:
            indicator = quote(self.s(str(indicator), errors=errors), safe='~')
        except KeyError:
            indicator = quote(bytes(indicator), safe='~')
    return indicator

Indicator encode value for safe HTTP request.

Args:
indicator (string): Indicator to URL Encode
errors (string): The error handler type.

Returns:
(string): The urlencoded string


def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, output_attentions: Optional[bool]=False) -> Tuple[torch.FloatTensor]:
    residual = hidden_states
    hidden_states = self.layer_norm1(hidden_states)
    hidden_states, attn_weights = self.self_attn(hidden_states=hidden_states, attention_mask=attention_mask, output_attentions=output_attentions)
    hidden_states = residual + hidden_states
    residual = hidden_states
    hidden_states = self.layer_norm2(hidden_states)
    hidden_states = self.mlp(hidden_states)
    hidden_states = residual + hidden_states
    outputs = (hidden_states,)
    if output_attentions:
        outputs += (attn_weights,)
    return outputs

Args:
hidden_states (`torch.FloatTensor`):
Input to the layer of shape `(batch, seq_len, embed_dim)`.
attention_mask (`torch.FloatTensor`):
Attention mask of shape `(batch, 1, q_len, k_v_seq_len)` where padding elements are indicated by very large negative values.
output_attentions (`bool`, *optional*, defaults to `False`):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.


def __solve_for_scalar(expr, vars):

    var = solve(expr, vars).value
    try:
        scalar = repeated.getvalue(var)
    except TypeError:
        raise errors.EfilterTypeError(
            root=expr, query=expr.source,
            message="Wasn't expecting more than one value here. Got %r."
            % (var,))

    if isinstance(scalar, row_tuple.RowTuple):
        try:
            return scalar.get_singleton()
        except ValueError:
            raise errors.EfilterTypeError(
                root=expr, query=expr.source,
                message="Was expecting a scalar value here. Got %r."
                % (scalar,))
    else:
        return scalar

Helper: solve 'expr' always returning a scalar (not IRepeated).

If the output of 'expr' is a single value or a single RowTuple with a single
column then return the value in that column. Otherwise raise.

Arguments:
expr: Expression to solve.
vars: The scope.

Returns:
A scalar value (not an IRepeated).

Raises:
EfilterTypeError if it cannot get a scalar.


def safe_rt(resource_type, lower=False):

        if resource_type is not None:
            resource_type = resource_type.replace(' ', '_')
            if lower:
                resource_type = resource_type.lower()
        return resource_type

Format the Resource Type.

Takes Custom Indicator types with a space character and return a *safe* string.

(e.g. *User Agent* is converted to User_Agent or user_agent.)

Args:
resource_type (string): The resource type to format.
lower (boolean): Return type in all lower case

Returns:
(string): The formatted resource type.


def collection(self, collection_id):

        child_path = self._path + (collection_id,)
        return self._client.collection(*child_path)

Create a sub-collection underneath the current document.

Args:
collection_id (str): The sub-collection identifier (sometimes
referred to as the "kind").

Returns:
~.firestore_v1beta1.collection.CollectionReference: The
child collection.


def write(self, file_name):
    try:
        assert (file_name[(- 6):] == '.xhtml')
    except (AssertionError, IndexError):
        raise ValueError('filename must end with .xhtml')
    with open(file_name, 'wb') as f:
        f.write(self.content.encode('utf-8'))

Writes the chapter object to an xhtml file.

Args:
file_name (str): The full name of the xhtml file to save to.


def create_autoscale_setting(access_token, subscription_id, resource_group, setting_name, vmss_name, location, minval, maxval, default, autoscale_rules, notify=None):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/microsoft.insights/autoscaleSettings/', setting_name, '?api-version=', INSIGHTS_API])
    autoscale_setting = {'location': location}
    profile = {'name': 'Profile1'}
    capacity = {'minimum': str(minval)}
    capacity['maximum'] = str(maxval)
    capacity['default'] = str(default)
    profile['capacity'] = capacity
    profile['rules'] = autoscale_rules
    profiles = [profile]
    properties = {'name': setting_name}
    properties['profiles'] = profiles
    properties['targetResourceUri'] = ((((('/subscriptions/' + subscription_id) + '/resourceGroups/') + resource_group) + '/providers/Microsoft.Compute/virtualMachineScaleSets/') + vmss_name)
    properties['enabled'] = True
    if (notify is not None):
        notification = {'operation': 'Scale'}
        email = {'sendToSubscriptionAdministrato': False}
        email['sendToSubscriptionCoAdministrators'] = False
        email['customEmails'] = [notify]
        notification = {'email': email}
        properties['notifications'] = [notification]
    autoscale_setting['properties'] = properties
    body = json.dumps(autoscale_setting)
    return do_put(endpoint, body, access_token)

Create a new autoscale setting for a scale set.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
setting_name (str): Name of the autoscale setting.
vmss_name (str): Name of scale set to apply scale events to.
location (str): Azure data center location. E.g. westus.
minval (int): Minimum number of VMs.
maxval (int): Maximum number of VMs.
default (int): Default VM number when no data available.
autoscale_rules (list): List of outputs from create_autoscale_rule().
notify (str): Optional.
Returns:
HTTP response. JSON body of autoscale setting.


def isPortAvailable(port='/dev/ttyUSB0'):

        isPortAvailable = serial.tools.list_ports.grep(port)

        try:
            next(isPortAvailable)
            available = True
        except StopIteration:
            available = False

        return available

Checks whether specified port is available.

Source code derived from @lqdev suggestion per #38

Args:
port: Serial port location i.e. 'COM1'. Default is /dev/ttyUSB0

Returns:
available: Boolean value indicating presence of port


def export(bundle, force=False, force_restricted=False):
    if (not ckan):
        raise EnvironmentError(MISSING_CREDENTIALS_MSG)
    try:
        ckan.action.package_create(**_convert_bundle(bundle))
    except ckanapi.ValidationError:
        if force:
            logger.warning('{} dataset already exported, but new export forced. Continue to export dataset stuff.'.format(bundle.dataset))
        else:
            raise
    access = bundle.dataset.config.metadata.about.access
    if ((access == 'restricted') and force_restricted):
        access = 'private'
    assert access, 'CKAN publishing requires access level.'
    if (access in ('internal', 'controlled', 'restricted', 'census')):
        raise UnpublishedAccessError('{} dataset can not be published because of {} access.'.format(bundle.dataset.vid, bundle.dataset.config.metadata.about.access))
    elif (access == 'public'):
        user_roles = [{'user': 'visitor', 'domain_object': bundle.dataset.vid.lower(), 'roles': ['editor']}, {'user': 'logged_in', 'domain_object': bundle.dataset.vid.lower(), 'roles': ['editor']}]
    elif (access == 'registered'):
        user_roles = [{'user': 'visitor', 'domain_object': bundle.dataset.vid.lower(), 'roles': []}, {'user': 'logged_in', 'domain_object': bundle.dataset.vid.lower(), 'roles': ['editor']}]
    elif (access in ('private', 'licensed', 'test')):
        user_roles = [{'user': 'visitor', 'domain_object': bundle.dataset.vid.lower(), 'roles': []}, {'user': 'logged_in', 'domain_object': bundle.dataset.vid.lower(), 'roles': []}]
        organization_users = ckan.action.organization_show(id=CKAN_CONFIG.organization)['users']
        for user in organization_users:
            (user_roles.append({'user': user['id'], 'domain_object': bundle.dataset.vid.lower(), 'roles': ['editor']}),)
    for role in user_roles:
        ckan.action.user_role_update(**role)
    for partition in bundle.partitions:
        ckan.action.resource_create(**_convert_partition(partition))
    ckan.action.resource_create(**_convert_schema(bundle))
    for (name, external) in six.iteritems(bundle.dataset.config.metadata.external_documentation):
        ckan.action.resource_create(**_convert_external(bundle, name, external))

Exports bundle to ckan instance.

Args:
bundle (ambry.bundle.Bundle):
force (bool, optional): if True, ignore existance error and continue to export.
force_restricted (bool, optional): if True, then export restricted bundles as private (for debugging
purposes).

Raises:
EnvironmentError: if ckan credentials are missing or invalid.
UnpublishedAccessError: if dataset has unpublished access - one from ('internal', 'test',
'controlled', 'restricted', 'census').


def _batch_norm_op(self, input_batch, mean, variance, use_batch_stats, stat_dtype):
    if self._fused:
        (batch_norm_op, mean, variance) = self._fused_batch_norm_op(input_batch, self._moving_mean, self._moving_variance, use_batch_stats)
    else:
        batch_norm_op = tf.nn.batch_normalization(input_batch, mean, variance, self._beta, self._gamma, self._eps, name='batch_norm')
        if (input_batch.dtype.base_dtype != stat_dtype):
            mean = tf.cast(mean, stat_dtype)
            variance = tf.cast(variance, stat_dtype)
    return (batch_norm_op, mean, variance)

Creates a batch normalization op.

It uses the tf.nn.batch_normalization op by default and the
tf.nn.fused_batch_norm op to support fused batch normalization.

Args:
input_batch: A input Tensor of arbitrary dimension.
mean: A mean tensor, of the same dtype as `input_batch`.
variance: A variance tensor, of the same dtype as `input_batch`.
use_batch_stats: A bool value that indicates whether the operation should
use the batch statistics.
stat_dtype: TensorFlow datatype used for the moving mean and variance.

Returns:
A batch normalization operation.
The current mean tensor, of datatype `stat_dtype`.
The current variance tensor, of datatype `stat_dtype`.


def output(self, stream, value):

        if stream not in self.outputs:
            raise ValueError("Stream is not an output of this operator.")
        e = self.expression(value)
        e._stream = stream
        return e

SPL output port assignment expression.

Arguments:
stream(Stream): Output stream the assignment is for.
value(str): SPL expression used for an output assignment. This can be a string, a constant, or an :py:class:`Expression`.

Returns:
Expression: Output assignment expression that is valid as a the context of this operator.


def sentences(self, index = None):

        if index is None:
            return self.select(Sentence,None,True,default_ignore_structure)
        else:
            if index < 0:
                index = self.count(Sentence,None,True,default_ignore_structure) + index
            for i,e in enumerate(self.select(Sentence,None,True,default_ignore_structure)):
                if i == index:
                    return e
            raise IndexError

Returns a generator of Sentence elements found (recursively) under this element

Arguments:
index (int or None): If set to an integer, will retrieve and return the n'th element (starting at 0) instead of returning a generator of all


def start(self, input_data, output_data, transform_resources, **kwargs):

        self.transform_resources = transform_resources
        self.input_data = input_data
        self.output_data = output_data

        image = self.primary_container['Image']
        instance_type = transform_resources['InstanceType']
        instance_count = 1

        environment = self._get_container_environment(**kwargs)

        self.container = _SageMakerContainer(instance_type, instance_count, image, self.local_session)
        self.container.serve(self.primary_container['ModelDataUrl'], environment)

        serving_port = get_config_value('local.serving_port', self.local_session.config) or 8080
        _wait_for_serving_container(serving_port)

        endpoint_url = 'http:
        response, code = _perform_request(endpoint_url)
        if code == 200:
            execution_parameters = json.loads(response.read())

            for setting in ('BatchStrategy', 'MaxPayloadInMB'):
                if setting not in kwargs and setting in execution_parameters:
                    kwargs[setting] = execution_parameters[setting]

        kwargs.update(self._get_required_defaults(**kwargs))

        self.start_time = datetime.datetime.now()
        self.batch_strategy = kwargs['BatchStrategy']
        if 'Environment' in kwargs:
            self.environment = kwargs['Environment']

        self._perform_batch_inference(input_data, output_data, **kwargs)
        self.end_time = datetime.datetime.now()
        self.state = self._COMPLETED

Start the Local Transform Job

Args:
input_data (dict): Describes the dataset to be transformed and the location where it is stored.
output_data (dict): Identifies the location where to save the results from the transform job
transform_resources (dict): compute instances for the transform job. Currently only supports local or
local_gpu
**kwargs: additional arguments coming from the boto request object


def add_state(self, state_name, initial_state, batch_size=None):

    state_shape = initial_state.get_shape().as_list()
    full_shape = [batch_size] + state_shape
    if not batch_size:

      shape_proto = self._as_shape_proto([0] + state_shape)
      batch_size = 1
    else:
      shape_proto = self._as_shape_proto([batch_size] + state_shape)

    tiles = [batch_size] + ([1] * len(initial_state.get_shape()))
    feed_op = tf.placeholder_with_default(
        tf.tile(
            tf.expand_dims(initial_state, [0]), tiles),
        shape=full_shape,
        name='%s_feed' % state_name)
    s = {'feed_op': feed_op,
         'feed_type': initial_state.dtype,
         'feed_shape': shape_proto}
    self._states[state_name] = s

Adds a state to the state saver.

Args:
state_name: The name of this state.
initial_state: The initial state vector. Only zeros are supported.
batch_size: The batch_size or None for unknown.


def from_csv(cls, filename=None, text=None):
    if ((filename is None) and (text is None)):
        raise LegendError('You must provide a filename or CSV text.')
    if (filename is not None):
        with open(filename, 'r') as f:
            text = f.read()
    try:
        f = StringIO(text)
    except TypeError:
        f = StringIO(unicode(text))
    r = csv.DictReader(f, skipinitialspace=True)
    (list_of_Decors, components) = ([], [])
    kind = 'component'
    for row in r:
        (d, component) = ({}, {})
        for (k, v) in row.items():
            if (k in [None, '']):
                continue
            if (v in [None, '']):
                if (k.lower() not in ['color', 'colour']):
                    continue
            if (k[:4].lower() == 'comp'):
                prop = ' '.join(k.split()[1:])
                if (v.lower() == 'true'):
                    component[prop] = True
                elif (v.lower() == 'false'):
                    component[prop] = False
                else:
                    try:
                        component[prop] = float(v)
                    except ValueError:
                        component[prop] = v.lower()
            elif (k[:5].lower() == 'curve'):
                prop = ' '.join(k.split()[1:])
                component[prop] = v.lower()
                kind = 'curve'
            else:
                try:
                    d[k] = float(v)
                except ValueError:
                    d[k] = v.lower()
        this_component = Component(component)
        d[kind] = this_component
        if (this_component in components):
            with warnings.catch_warnings():
                warnings.simplefilter('always')
                w = 'This legend contains duplicate components.'
                warnings.warn(w)
        components.append(this_component)
        list_of_Decors.append(Decor(d))
    return cls(list_of_Decors)

Read CSV text and generate a Legend.

Args:
string (str): The CSV string.

In the first row, list the properties. Precede the properties of the
component with 'comp ' or 'component '. For example:

colour,  width, comp lithology, comp colour
#FFFFFF, 0, ,
#F7E9A6, 3, Sandstone, Grey
#FF99CC, 2, Anhydrite,
... etc

Note:
To edit a legend, the easiest thing to do is probably this:

- `legend.to_csv()`
- Edit the legend, call it `new_legend`.
- `legend = Legend.from_csv(text=new_legend)`


def list_metadata(self, resource):
    self.metadata_service.set_auth(self._token_metadata)
    return self.metadata_service.list(resource)

List all keys associated with the given resource.

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

Returns:
(list)

Raises:
requests.HTTPError on a failure.


def read_molden(inputfile, start_index=0, get_bonds=True):
    from chemcoord.cartesian_coordinates.cartesian_class_main import Cartesian
    with open(inputfile, 'r') as f:
        found = False
        while (not found):
            line = f.readline()
            if ('[N_GEO]' in line):
                found = True
                number_of_molecules = int(f.readline().strip())
        energies = []
        found = False
        while (not found):
            line = f.readline()
            if ('energy' in line):
                found = True
                for _ in range(number_of_molecules):
                    energies.append(float(f.readline().strip()))
        found = False
        while (not found):
            line = f.readline()
            if ('[GEOMETRIES] (XYZ)' in line):
                found = True
                current_line = f.tell()
                number_of_atoms = int(f.readline().strip())
                f.seek(current_line)
        cartesians = []
        for energy in energies:
            cartesian = Cartesian.read_xyz(f, start_index=start_index, get_bonds=get_bonds, nrows=number_of_atoms, engine='python')
            cartesian.metadata['energy'] = energy
            cartesians.append(cartesian)
    return cartesians

Read a molden file.

Args:
inputfile (str):
start_index (int):

Returns:
list: A list containing :class:`~chemcoord.Cartesian` is returned.


def do_patch(endpoint, body, access_token):

    headers = {"content-type": "application/json", "Authorization": 'Bearer ' + access_token}
    headers['User-Agent'] = get_user_agent()
    return requests.patch(endpoint, data=body, headers=headers)

Do an HTTP PATCH request and return JSON.

Args:
endpoint (str): Azure Resource Manager management endpoint.
body (str): JSON body of information to patch.
access_token (str): A valid Azure authentication token.

Returns:
HTTP response. JSON body.


def _new_open_bin(self, remaining_rect):
    factories_to_delete = set()
    new_bin = None
    for (key, binfac) in self._empty_bins.items():
        a_rectangle_fits = False
        for (_, rect) in remaining_rect.items():
            if binfac.fits_inside(rect[0], rect[1]):
                a_rectangle_fits = True
                break
        if (not a_rectangle_fits):
            factories_to_delete.add(key)
            continue
        new_bin = binfac.new_bin()
        if (new_bin is None):
            continue
        self._open_bins.append(new_bin)
        if binfac.is_empty():
            factories_to_delete.add(key)
        break
    for f in factories_to_delete:
        del self._empty_bins[f]
    return new_bin

Extract the next bin where at least one of the rectangles in
rem

Arguments:
remaining_rect (dict): rectangles not placed yet

Returns:
PackingAlgorithm: Initialized empty packing bin.
None: No bin big enough for the rectangle was found


def exchange(self, pubkey):

        try:
            return self.priv.exchange(c_ec.ECDH(), pubkey.publ)
        except ValueError as e:
            raise s_exc.BadEccExchange(mesg=str(e))

Perform a ECDH key exchange with a public key.

Args:
pubkey (PubKey): A PubKey to perform the ECDH with.

Returns:
bytes: The ECDH bytes. This is deterministic for a given pubkey
and private key.


def upload_from_url(cls, url, store=None, filename=None):
    if (store is None):
        store = 'auto'
    elif store:
        store = '1'
    else:
        store = '0'
    data = {'source_url': url, 'store': store}
    if filename:
        data['filename'] = filename
    result = uploading_request('POST', 'from_url/', data=data)
    if ('token' not in result):
        raise APIError('could not find token in result: {0}'.format(result))
    file_from_url = cls.FileFromUrl(result['token'])
    return file_from_url

Uploads file from given url and returns ``FileFromUrl`` instance.

Args:
- url (str): URL of file to upload to
- store (Optional[bool]): Should the file be automatically stored
upon upload. Defaults to None.
- False - do not store file
- True - store file (can result in error if autostore
is disabled for project)
- None - use project settings
- filename (Optional[str]): Name of the uploaded file. If this not
specified the filename will be obtained from response headers
or source URL. Defaults to None.

Returns:
``FileFromUrl`` instance


def _get_resource_view(self, resource_view):

        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 to_bytesize(value, default_unit=None, base=DEFAULT_BASE):
    if isinstance(value, (int, float)):
        return unitized(value, default_unit, base)
    if (value is None):
        return None
    try:
        if (value[(- 1)].lower() == 'b'):
            value = value[:(- 1)]
        unit = value[(- 1):].lower()
        if unit.isdigit():
            unit = default_unit
        else:
            value = value[:(- 1)]
        return unitized(to_number(float, value), unit, base)
    except (IndexError, TypeError, ValueError):
        return None

Convert `value` to bytes, accepts notations such as "4k" to mean 4096 bytes

Args:
value (str | unicode | int | None): Number of bytes optionally suffixed by a char from UNITS
default_unit (str | unicode | None): Default unit to use for unqualified values
base (int): Base to use (usually 1024)

Returns:
(int | None): Deduced bytesize value, if possible


def read_trailer(self):
    _logger.debug('Reading chunked trailer.')
    trailer_data_list = []
    while True:
        trailer_data = (yield from self._connection.readline())
        trailer_data_list.append(trailer_data)
        if (not trailer_data.strip()):
            break
    return b''.join(trailer_data_list)

Read the HTTP trailer fields.

Returns:
bytes: The trailer data.

Coroutine.


def show(self, *args, **kwargs):
    plt = self.get_pourbaix_plot(*args, **kwargs)
    plt.show()

Shows the pourbaix plot

Args:
*args: args to get_pourbaix_plot
**kwargs: kwargs to get_pourbaix_plot

Returns:
None


def random_square_mask(shape, fraction):
    mask = np.ones(shape)
    patch_area = ((shape[0] * shape[1]) * fraction)
    patch_dim = np.int(math.floor(math.sqrt(patch_area)))
    if ((patch_area == 0) or (patch_dim == 0)):
        return mask
    x = np.random.randint((shape[0] - patch_dim))
    y = np.random.randint((shape[1] - patch_dim))
    mask[(x:(x + patch_dim), y:(y + patch_dim), :)] = 0
    return mask

Create a numpy array with specified shape and masked fraction.

Args:
shape: tuple, shape of the mask to create.
fraction: float, fraction of the mask area to populate with `mask_scalar`.

Returns:
numpy.array: A numpy array storing the mask.


def non_trainable_variables(self):
    return tuple(self._flatten(predicate=_is_non_trainable_variable, expand_composites=True))

Sequence of non-trainable variables owned by this module and its submodules.

Note: this method uses reflection to find variables on the current instance
and submodules. For performance reasons you may wish to cache the result
of calling this method if you don't expect the return value to change.

Returns:
A sequence of variables for the current module (sorted by attribute
name) followed by variables from all submodules recursively (breadth
first).


def Cancel(self, request, global_params=None):
    config = self.GetMethodConfig('Cancel')
    return self._RunMethod(config, request, global_params=global_params)

Requests that a job be cancelled. This call will return immediately, and the client will need to poll for the job status to see if the cancel completed successfully. Cancelled jobs may still incur costs.

Args:
request: (BigqueryJobsCancelRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(JobCancelResponse) The response message.


def download_and_extract(path, url, input_filename, target_filename):
    logging.info(('Downloading and extracting data to: %s' % path))
    input_file = find_file(path, input_filename)
    target_file = find_file(path, target_filename)
    if (input_file and target_file):
        logging.info(('Already downloaded and extracted %s.' % url))
        return (input_file, target_file)
    compressed_file = download_from_url(path, url)
    logging.info(('Extracting %s.' % compressed_file))
    with tarfile.open(compressed_file, 'r:gz') as corpus_tar:
        corpus_tar.extractall(path)
    input_file = find_file(path, input_filename)
    target_file = find_file(path, target_filename)
    if (input_file and target_file):
        return (input_file, target_file)
    raise OSError(('Download/extraction failed for url %s to path %s' % (url, path)))

Extract files from downloaded compressed archive file.

Args:
path: string directory where the files will be downloaded
url: url containing the compressed input and target files
input_filename: name of file containing data in source language
target_filename: name of file containing data in target language

Returns:
Full paths to extracted input and target files.

Raises:
OSError: if the the download/extraction fails.


def expand_tile(units, axis):

    assert axis in (1, 2)
    n_time_steps = tf.shape(units)[1]
    repetitions = [1, 1, 1, 1]
    repetitions[axis] = n_time_steps
    return tf.tile(tf.expand_dims(units, axis), repetitions)

Expand and tile tensor along given axis
Args:
units: tf tensor with dimensions [batch_size, time_steps, n_input_features]
axis: axis along which expand and tile. Must be 1 or 2


def remove_location(self, location):
    res = self._remove_hdxobject(self.data.get('groups'), location, matchon='name')
    if (not res):
        res = self._remove_hdxobject(self.data.get('groups'), location.upper(), matchon='name')
    if (not res):
        res = self._remove_hdxobject(self.data.get('groups'), location.lower(), matchon='name')
    return res

Remove a location. If the location is already added, it is ignored.

Args:
location (str): Location to remove

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


def _add_dns_records(self, conf, mgmts):

        nets = conf['nets']
        dns_mgmt = mgmts[-1]
        LOGGER.debug('Using network %s as main DNS server', dns_mgmt)
        forward = conf['nets'][dns_mgmt].get('gw')
        dns_records = {}
        for net_name, net_spec in nets.iteritems():
            dns_records.update(net_spec['mapping'].copy())
            if net_name not in mgmts:
                net_spec['dns_forward'] = forward

        for mgmt in mgmts:
            if nets[mgmt].get('dns_records'):
                nets[mgmt]['dns_records'].update(dns_records)
            else:
                nets[mgmt]['dns_records'] = dns_records

Add DNS records dict('dns_records') to ``conf`` for each
management network. Add DNS forwarder IP('dns_forward') for each none
management network.

Args:
conf(spec): spec
mgmts(list): management networks names

Returns:
None


def get_answers_for_student(student_item):
    submissions = sub_api.get_submissions(student_item)
    if (not submissions):
        return Answers()
    latest_submission = submissions[0]
    latest_answer_item = latest_submission.get('answer', {})
    return Answers(latest_answer_item.get(ANSWER_LIST_KEY, []))

Retrieve answers from backend for a student and question

Args:
student_item (dict): The location of the problem this submission is
associated with, as defined by a course, student, and item.

Returns:
Answers: answers for the student


def _validate_recurse_directive_types(current_schema_type, field_schema_type, context):
    type_hints = context['type_equivalence_hints'].get(field_schema_type)
    type_hints_inverse = context['type_equivalence_hints_inverse'].get(field_schema_type)
    allowed_current_types = {field_schema_type}
    if (type_hints and isinstance(type_hints, GraphQLUnionType)):
        allowed_current_types.update(type_hints.types)
    if (type_hints_inverse and isinstance(type_hints_inverse, GraphQLUnionType)):
        allowed_current_types.update(type_hints_inverse.types)
    current_scope_is_allowed = (current_schema_type in allowed_current_types)
    is_implemented_interface = (isinstance(field_schema_type, GraphQLInterfaceType) and isinstance(current_schema_type, GraphQLObjectType) and (field_schema_type in current_schema_type.interfaces))
    if (not any((current_scope_is_allowed, is_implemented_interface))):
        raise GraphQLCompilationError(u'Edges expanded with a @recurse directive must either be of the same type as their enclosing scope, a supertype of the enclosing scope, or be of an interface type that is implemented by the type of their enclosing scope. Enclosing scope type: {}, edge type: {}'.format(current_schema_type, field_schema_type))

Perform type checks on the enclosing type and the recursed type for a recurse directive.

Args:
current_schema_type: GraphQLType, the schema type at the current location
field_schema_type: GraphQLType, the schema type at the inner scope
context: dict, various per-compilation data (e.g. declared tags, whether the current block
is optional, etc.). May be mutated in-place in this function!


def output_shapes(self):
    return nest.map_structure(lambda component_spec: component_spec._to_legacy_output_shapes(), self._element_spec)

Returns the shape of each component of an element of this iterator.

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


def subcomponents(self, subcomponents):
    for arg in self.args:
        if (arg.__class__.__name__ == 'Function'):
            subcomponents.append(arg.to_string())
            if (arg.function_type == 'primary'):
                arg.subcomponents(subcomponents)
        else:
            subcomponents.append(arg.to_string())
    return subcomponents

Generate subcomponents of the BEL subject or object

These subcomponents are used for matching parts of a BEL
subject or Object in the Edgestore.

Args:
AST
subcomponents:  Pass an empty list to start a new subcomponents request

Returns:
List[str]: subcomponents of BEL subject or object


def logistic(x: Union[float, np.ndarray],
             k: float,
             theta: float) -> Optional[float]:
    r

    if x is None or k is None or theta is None:
        return None

    return 1 / (1 + np.exp(-k * (x - theta)))

r"""
Standard logistic function.

.. math::

y = \frac {1} {1 + e^{-k (x - \theta)}}

Args:
x: :math:`x`
k: :math:`k`
theta: :math:`\theta`

Returns:
:math:`y`


def create(self, document_data):
    batch = self._client.batch()
    batch.create(self, document_data)
    write_results = batch.commit()
    return _first_write_result(write_results)

Create the current document in the Firestore database.

Args:
document_data (dict): Property names and values to use for
creating a document.

Returns:
google.cloud.firestore_v1beta1.types.WriteResult: The
write result corresponding to the committed document. A write
result contains an ``update_time`` field.

Raises:
~google.cloud.exceptions.Conflict: If the document already exists.


def getall(self):
    matches = ROUTES_RE.findall(self.config)
    routes = dict()
    for match in matches:
        ip_dest = match[0]
        next_hop = match[1]
        next_hop_ip = (None if (match[2] is '') else match[2])
        distance = int(match[3])
        data = {}
        data['tag'] = (None if (match[4] is '') else int(match[4]))
        data['route_name'] = (None if (match[5] is '') else match[5])
        ip_dict = routes[ip_dest] = routes.get(ip_dest, {})
        nh_dict = ip_dict[next_hop] = ip_dict.get(next_hop, {})
        nhip_dict = nh_dict[next_hop_ip] = nh_dict.get(next_hop_ip, {})
        nhip_dict[distance] = data
    return routes

Return all ip routes configured on the switch as a resource dict

Returns:
dict: An dict object of static route entries in the form::

{ ip_dest:
{ next_hop:
{ next_hop_ip:
{ distance:
{ 'tag': tag,
'route_name': route_name
}
}
}
}
}

If the ip address specified does not have any associated
static routes, then None is returned.

Notes:
The keys ip_dest, next_hop, next_hop_ip, and distance in
the returned dictionary are the values of those components
of the ip route specification. If a route does not contain
a next_hop_ip, then that key value will be set as 'None'.


def transformer_latent_decoder(x, encoder_output, ed_attention_bias, hparams, name=None):
    with tf.variable_scope(name, default_name='transformer_latent_dec'):
        batch_size = common_layers.shape_list(x)[0]
        compressed_img_len = (hparams.img_len
        x = tf.reshape(x, [batch_size, compressed_img_len, (compressed_img_len * hparams.num_latents), hparams.hidden_size])
        (decoder_input, _, _) = cia.prepare_decoder(x, hparams)
        decoder_output = cia.transformer_decoder_layers(decoder_input, encoder_output, (hparams.num_latent_layers or hparams.num_hidden_layers), hparams, attention_type=hparams.latent_attention_type, encoder_decoder_attention_bias=ed_attention_bias, name='decoder')
        decoder_output = tf.reshape(decoder_output, [batch_size, ((compressed_img_len ** 2) * hparams.num_latents), hparams.hidden_size])
        return decoder_output

Transformer decoder over latents using latent_attention_type.

Args:
x: Tensor of shape [batch, length_q, hparams.hidden_size]. length_q is the
latent length, which is
height * width * hparams.num_latents / (2**hparams.num_compress_steps).
encoder_output: Tensor of shape [batch, length_kv, hparams.hidden_size].
ed_attention_bias: Tensor which broadcasts with shape [batch,
hparams.num_heads, length_q, length_kv]. Encoder-decoder attention bias.
hparams: HParams.
name: string, variable scope.

Returns:
Tensor of shape [batch, length_q, hparams.hidden_size].