def create_temp_grad(node, namer, tangent=False):

  if not isinstance(node, (gast.Subscript, gast.Name)):
    raise TypeError

  def _name_temp_grad(node):
    name = namer.temp_grad(node.id, tangent)
    temp_node = gast.Name(id=name, annotation=None, ctx=None)
    return temp_node
  if isinstance(node, gast.Subscript):
    temp_node = _name_temp_grad(node.value)
  else:
    temp_node = _name_temp_grad(node)
  anno.setanno(temp_node, 'temp_adjoint_var', node)
  return temp_node

Create a variable to store partial gradients.

Args:
node: See `create_grad`.
namer: See `create_grad`.
tangent: See `create_grad`.

Returns:
node: See `create_grad`. Returns a node representing the partial gradient.
Note that this is always a simple variable e.g. the temporary partial
of `x[i]` can be something like `_dxi`.

Nodes are given an annotation `temp_adjoint_var`.


def SetConfiguredUsers(self, users):

    prefix = self.logger.name + '-'
    with tempfile.NamedTemporaryFile(
        mode='w', prefix=prefix, delete=True) as updated_users:
      updated_users_file = updated_users.name
      for user in users:
        updated_users.write(user + '\n')
      updated_users.flush()
      if not os.path.exists(self.google_users_dir):
        os.makedirs(self.google_users_dir)
      shutil.copy(updated_users_file, self.google_users_file)

    file_utils.SetPermissions(self.google_users_file, mode=0o600, uid=0, gid=0)

Set the list of configured Google user accounts.

Args:
users: list, the username strings of the Linux accounts.


def call_remoteckan(self, *args, **kwargs):
    requests_kwargs = kwargs.get('requests_kwargs', dict())
    credentials = self._get_credentials()
    if credentials:
        requests_kwargs['auth'] = credentials
    kwargs['requests_kwargs'] = requests_kwargs
    apikey = kwargs.get('apikey', self.get_api_key())
    kwargs['apikey'] = apikey
    return self.remoteckan().call_action(*args, **kwargs)

Calls the remote CKAN

Args:
*args: Arguments to pass to remote CKAN call_action method
**kwargs: Keyword arguments to pass to remote CKAN call_action method

Returns:
Dict: The response from the remote CKAN call_action method


def filepaths_in_dir(path):

    filepaths = []
    for root, directories, filenames in os.walk(path):
        for filename in filenames:
            filepath = os.path.join(root, filename)
            filepath = filepath.replace(path, '').lstrip('/')
            filepaths.append(filepath)
    return filepaths

Find all files in a directory, and return the relative paths to those files.

Args:
path (str): the directory path to walk

Returns:
list: the list of relative paths to all files inside of ``path`` or its
subdirectories.


def DeregisterCredentials(cls, credentials):

    if credentials.type_indicator not in cls._credentials:
      raise KeyError(
          'Credential object not set for type indicator: {0:s}.'.format(
              credentials.type_indicator))

    del cls._credentials[credentials.type_indicator]

Deregisters a path specification credentials.

Args:
credentials (Credentials): credentials.

Raises:
KeyError: if credential object is not set for the corresponding
type indicator.


def get_unscaled_gradients(self, grads):
    loss_scale_reciprocal = 1.0 / self.loss_scale
    return [_multiply_gradient(g, loss_scale_reciprocal) if g is not None else None for g in grads]

Unscales the gradients by the loss scale.

This method is only needed if you compute gradients manually, e.g. with
`tf.GradientTape`. In that case, call this method to unscale the gradients
after computing them with `tf.GradientTape`. If you use
`LossScaleOptimizer.minimize` or `LossScaleOptimizer.get_gradients`, loss
scaling is automatically applied and this method is unneeded.

If this method is called, `get_scaled_loss` should also be called. See
the `tf.keras.mixed_precision.LossScaleOptimizer` doc for an
example.

Args:
grads: A list of tensors, each which will be divided by the loss scale.
Can have None values, which are ignored.

Returns:
A new list the same size as `grads`, where every non-None value in `grads`
is divided by `LossScaleOptimizer.loss_scale`.


def get_fieldset_index(fieldsets, index_or_name):
    if isinstance(index_or_name, six.integer_types):
        return index_or_name
    for (key, value) in enumerate(fieldsets):
        if (value[0] == index_or_name):
            return key
    raise KeyError("Key not found: '{}'.".format(index_or_name))

Return the index of a fieldset in the ``fieldsets`` list.

Args:
fieldsets (list): The original ``fieldsets`` list.
index_or_name (int or str): The value of the reference element, or directly its numeric index.

Returns:
(int) The index of the fieldset in the ``fieldsets`` list.


def make_ordered_column_names(include_label=True):
    result = ['clicked'] if include_label else []
    for name in _INTEGER_COLUMN_NAMES:
        result.append(name)
    for name in _CATEGORICAL_COLUMN_NAMES:
        result.append(name)
    return result

Returns the column names in the dataset in the order as they appear.

Args:
include_label: Indicates whether the label feature should be included.
Returns:
A list of column names in the dataset.


def input_defs(self, transitive: bool=True) -> List['SymbolDefinition']:
    parent_func = self.parent_func()
    var_producers: Dict[str, Set[SymbolDefinition]] = {arg: set() for arg in parent_func.args}
    var_producers[parent_func.name] = set()

    def analyze_var_producers(k: pg.KeyPath, v: Any, p: pg.Symbolic):
        del k, p
        if v is self:
            return pg.TraverseAction.STOP
        if isinstance(v, SymbolDefinition):
            var_entry = set([v])
            if transitive:
                for var_name in v.input_vars():
                    var_entry.update(var_producers[var_name])
            var_producers[v.name] = var_entry
        if v is not parent_func and isinstance(v, Function):
            return pg.TraverseAction.CONTINUE
        return pg.TraverseAction.ENTER
    pg.traverse(parent_func, analyze_var_producers)
    dependencies: Set[SymbolDefinition] = set()
    for var_name in self.input_vars():
        if var_name not in var_producers:
            raise ValueError(f"Undefined variable {repr(var_name)} found in function '{parent_func.name}' line
        dependencies.update(var_producers[var_name])
    return sorted(dependencies, key=lambda x: x.line_number())

Returns the symbol definitions for the inputs of this code entity.

Args:
transitive: If True, transitive inputs will be included.
Otherwise, only the direct dependencies will be included.

Returns:
A list of `SymbolDefinition` in their declaration order that produce
the inputs required for current code entity.


def replace_case(self, case_obj):
    LOG.info('Saving case %s', case_obj['_id'])
    case_obj['updated_at'] = (datetime.datetime.now(),)
    updated_case = self.case_collection.find_one_and_replace({'_id': case_obj['_id']}, case_obj, return_document=pymongo.ReturnDocument.AFTER)
    return updated_case

Replace a existing case with a new one

Keeps the object id

Args:
case_obj(dict)

Returns:
updated_case(dict)


def register_extension(self, group, name, extension):

        if isinstance(extension, str):
            name, extension = self.load_extension(extension)[0]

        if group not in self._registered_extensions:
            self._registered_extensions[group] = []

        self._registered_extensions[group].append((name, extension))

Register an extension.

Args:
group (str): The type of the extension
name (str): A name for the extension
extension (str or class): If this is a string, then it will be
interpreted as a path to import and load.  Otherwise it
will be treated as the extension object itself.


def serve(self, server=None):

        if server is None:
            from wsgiref.simple_server import make_server
            server = lambda app: make_server('', 8000, app).serve_forever()
            print('Listening on 0.0.0.0:8000')
        try:
            server(self)
        finally:
            server.socket.close()

Serve app using wsgiref or provided server.

Args:
- server (callable): An callable


def _log_submission(submission, student_item):

    logger.info(
        u"Created submission uuid={submission_uuid} for "
        u"(course_id={course_id}, item_id={item_id}, "
        u"anonymous_student_id={anonymous_student_id})"
        .format(
            submission_uuid=submission["uuid"],
            course_id=student_item["course_id"],
            item_id=student_item["item_id"],
            anonymous_student_id=student_item["student_id"]
        )
    )

Log the creation of a submission.

Args:
submission (dict): The serialized submission model.
student_item (dict): The serialized student item model.

Returns:
None


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

Corresponds to IDD Field `db_en020`
mean coincident dry-bulb temperature to
Enthalpy corresponding to 2.0% annual cumulative frequency of occurrence

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

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


def total_covariance_fn(self):
    return self._total_covariance_fn

The total covariance of the process between two times.

Returns:
A Python callable returning the integrated covariances between two times.
The callable accepts two real `Tensor` arguments. The first argument
is the left end point and the second is the right end point of the time
interval for which the total covariance is needed.

The shape of the two input arguments and their dtypes must match.
The output of the callable is a `Tensor` of shape
`times_shape + [dim, dim]` containing the integrated covariance matrix
between the start times and end times.


def run(self, dag):
    num_dag_qubits = sum([qreg.size for qreg in dag.qregs.values()])
    if (num_dag_qubits > self.coupling_map.size()):
        raise TranspilerError('Number of qubits greater than device.')
    self.property_set['layout'] = Layout.generate_trivial_layout(*dag.qregs.values())

Pick a layout by assigning n circuit qubits to device qubits 0, .., n-1.

Args:
dag (DAGCircuit): DAG to find layout for.

Raises:
TranspilerError: if dag wider than self.coupling_map


def __init__(self,
                 input_file="mol.qin",
                 output_file="mol.qout",
                 rca_gdm_thresh=1.0E-3,
                 scf_max_cycles=200):

        self.input_file = input_file
        self.output_file = output_file
        self.scf_max_cycles = scf_max_cycles
        self.geom_max_cycles = geom_max_cycles
        self.qcinp = QCInput.from_file(self.input_file)
        self.outdata = None
        self.errors = None
        self.qchem_job = qchem_job

Initializes the error handler from a set of input and output files.

Args:
input_file (str): Name of the QChem input file.
output_file (str): Name of the QChem output file.
rca_gdm_thresh (float): The threshold for the prior scf algorithm.
If last deltaE is larger than the threshold try RCA_DIIS
first, else, try DIIS_GDM first.
scf_max_cycles (int): The max iterations to set to fix SCF failure.


def from_file(filename, file_format="xyz"):

        mols = list(pb.readfile(str(file_format), str(filename)))
        return BabelMolAdaptor(mols[0].OBMol)

Uses OpenBabel to read a molecule from a file in all supported formats.

Args:
filename: Filename of input file
file_format: String specifying any OpenBabel supported formats.

Returns:
BabelMolAdaptor object


def output(self, value):

        return super(Source, self).output(self.stream, value)

SPL output port assignment expression.

Arguments:
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 AddArguments(cls, argument_group):

    argument_group.add_argument(
        '--name', '--timeline_name', '--timeline-name',
        dest='timeline_name', type=str, action='store',
        default=cls._DEFAULT_NAME, required=False, help=(
            'The name of the timeline in Timesketch. Default: '
            'hostname if present in the storage file. If no hostname '
            'is found then manual input is used.'))

    argument_group.add_argument(
        '--index', dest='index', type=str, action='store',
        default=cls._DEFAULT_UUID, required=False, help=(
            'The name of the Elasticsearch index. Default: Generate a random '
            'UUID'))

    argument_group.add_argument(
        '--flush_interval', '--flush-interval', dest='flush_interval',
        type=int, action='store', default=cls._DEFAULT_FLUSH_INTERVAL,
        required=False, help=(
            'The number of events to queue up before sent in bulk '
            'to Elasticsearch.'))

    argument_group.add_argument(
        '--doc_type', dest='document_type', type=str,
        action='store', default=cls._DEFAULT_DOCUMENT_TYPE, help=(
            'Name of the document type that will be used in ElasticSearch.'))

    argument_group.add_argument(
        '--username', dest='username', type=str,
        action='store', default=cls._DEFAULT_USERNAME, help=(
            'Username of a Timesketch user that will own the timeline.'))

Adds command line arguments the helper supports to an argument group.

This function takes an argument parser or an argument group object and adds
to it all the command line arguments this helper supports.

Args:
argument_group (argparse._ArgumentGroup|argparse.ArgumentParser):
argparse group.


def get(self, vrf=None):
    match = '^router ospf .*'
    if vrf:
        match += (' vrf %s' % vrf)
    config = self.get_block(match)
    if (not config):
        return None
    response = dict()
    response.update(self._parse_router_id(config))
    response.update(self._parse_vrf(config))
    response.update(self._parse_networks(config))
    response.update(self._parse_ospf_process_id(config))
    response.update(self._parse_redistribution(config))
    response.update(self._parse_shutdown(config))
    return response

Returns the OSPF routing configuration

Args:
vrf (str): VRF name to return OSPF routing config for
Returns:
dict:
keys: router_id (int): OSPF router-id
vrf (str): VRF of the OSPF process
networks (dict): All networks that
are advertised in OSPF
ospf_process_id (int): OSPF proc id
redistribution (dict): All protocols that
are configured to be
redistributed in OSPF
shutdown (bool): Gives the current shutdown
off the process


def MapFile(self, key_path_prefix, registry_file):
    self._registry_files[key_path_prefix.upper()] = registry_file
    registry_file.SetKeyPathPrefix(key_path_prefix)

Maps the Windows Registry file to a specific key path prefix.

Args:
key_path_prefix (str): key path prefix.
registry_file (WinRegistryFile): Windows Registry file.


def _shape_union(shapes):
    return Shape(sorted(list(set(sum([s.dims for s in shapes], [])))))

A shape containing the union of all dimensions in the input shapes.

Args:
shapes: a list of Shapes

Returns:
a Shape


def get_problem_name(base_name, was_reversed=False, was_copy=False):

  if any(base_name.endswith(suffix) for suffix in ("_rev", "_copy")):
    raise ValueError("`base_name` cannot end in '_rev' or '_copy'")
  name = base_name
  if was_copy:
    name = "%s_copy" % name
  if was_reversed:
    name = "%s_rev" % name
  return name

Construct a problem name from base and reversed/copy options.

Inverse of `parse_problem_name`.

Args:
base_name: base problem name. Should not end in "_rev" or "_copy"
was_reversed: if the problem is to be reversed
was_copy: if the problem is to be copied

Returns:
string name consistent with use with `parse_problem_name`.

Raises:
ValueError if `base_name` ends with "_rev" or "_copy"


def raw_dict_factory(cursor, row):

        d = {}
        for idx, col in enumerate(cursor.description):
            val = row[idx]
            name = col[0]
            if name == Field.Time_Stamp or name == Field.Meter_Address:
                d[name] = str(val)
                continue
            if name == "Raw_A" or name == "Raw_B":
                d[name] = str(val)
                continue
        return d

Sqlite callback accepting the cursor and the original row as a tuple.

Simple return of JSON safe types, including raw read hex strings.

Args:
cursor (sqlite cursor):  Original cursory
row (sqlite row tuple): Original row.

Returns:
dict: modified row.


def fetch(args: List[str], env: Dict[str, str] = None,
          encoding: str = sys.getdefaultencoding()) -> str:

    stdout, _ = run(args, env=env, capture_stdout=True,
                    echo_stdout=False, encoding=encoding)
    log.debug(stdout)
    return stdout

Run a command and returns its stdout.

Args:
args: the command-line arguments
env: the operating system environment to use
encoding: the encoding to use for ``stdout``

Returns:
the command's ``stdout`` output


def SetUpdateTimestamp(self, value):
    if value is None or isinstance(value, int):
        self._last_update_timestamp = value
    else:
        raise TypeError('timestamp can only be int or None, not %r', value)

Set the last update timestamp of this map.

Args:
value:  An int containing seconds since epoch, or None.

Raises:
TypeError: The argument is not an int or None.


def repl_member_add(self, params):

        repl_config = self.config
        member_id = max([member['_id'] for member in repl_config['members']]) + 1
        member_config = self.member_create(params, member_id)
        repl_config['members'].append(member_config)
        if not self.repl_update(repl_config):
            self.member_del(member_id, reconfig=True)
            raise ReplicaSetError("Could not add member to ReplicaSet.")
        return member_id

create new mongod instances and add it to the replica set.
Args:
params - mongod params
return True if operation success otherwise False


async def pull(self, from_image: str, *, auth: Optional[Union[(MutableMapping, str, bytes)]]=None, tag: str=None, repo: str=None, stream: bool=False) -> Mapping:
    image = from_image
    params = {'fromImage': image}
    headers = {}
    if repo:
        params['repo'] = repo
    if tag:
        params['tag'] = tag
    if (auth is not None):
        (registry, has_registry_host, _) = image.partition('/')
        if (not has_registry_host):
            raise ValueError('Image should have registry host when auth information is provided')
        headers['X-Registry-Auth'] = compose_auth_header(auth, registry)
    response = (await self.docker._query('images/create', 'POST', params=params, headers=headers))
    return (await json_stream_result(response, stream=stream))

Similar to `docker pull`, pull an image locally

Args:
fromImage: name of the image to pull
repo: repository name given to an image when it is imported
tag: if empty when pulling an image all tags
for the given image to be pulled
auth: special {'auth': base64} pull private repo


def from_filenames(filenames, transformations=None, primitive=True, extend_collection=False):
    allcifs = []
    for fname in filenames:
        with open(fname, 'r') as f:
            allcifs.append(f.read())
    return CifTransmuter('\n'.join(allcifs), transformations, primitive=primitive, extend_collection=extend_collection)

Generates a TransformedStructureCollection from a cif, possibly
containing multiple structures.

Args:
filenames: List of strings of the cif files
transformations: New transformations to be applied to all
structures
primitive: Same meaning as in __init__.
extend_collection: Same meaning as in __init__.


async def run_commentator(video_mode: str) -> None:
    pya = pyaudio.PyAudio()
    video_mode_enum = video.VideoMode(video_mode)
    input_processor = video.VideoIn(video_mode=video_mode_enum) + audio_io.PyAudioIn(pya)

    async def input_stream():

        try:
            while True:
                await asyncio.sleep(1)
        finally:
            yield content_api.ProcessorPart('Ending the stream')
    commentator_processor = commentator.create_live_commentator(API_KEY)
    consume_output = audio_io.PyAudioOut(pya)
    live_commentary_agent = input_processor + commentator_processor + consume_output
    async for _ in live_commentary_agent(input_stream()):
        pass

Runs a live commentator in a CLI environment.

The commentator is run from a CLI environment. The audio and video input and
output are connected to the local machine's default input and output devices.

Args:
video_mode: The video mode to use for the video. Can be CAMERA or SCREEN.


def _CheckIsFile(self, file_entry):
    if (definitions.FILE_ENTRY_TYPE_FILE not in self._file_entry_types):
        return False
    return file_entry.IsFile()

Checks the is_file find specification.

Args:
file_entry (FileEntry): file entry.

Returns:
bool: True if the file entry matches the find specification, False if not.


def attribute_string(self):
    escape_map = {ord('='): '%3D', ord(','): '%2C', ord(';'): '%3B', ord('&'): '%26', ord('\t'): '%09'}
    list_type = type(list())
    attrs = self.attributes
    if (type(attrs) is OrderedDict):
        reserved_attrs = []
        other_attrs = []
        for (name, value) in attrs.items():
            name = name.translate(escape_map)
            if (type(value) == list_type):
                value = ','.join([i.translate(escape_map) for i in value])
            else:
                value = value.translate(escape_map)
            out_attr = '{0}={1}'.format(name, value)
            if name[0].isupper():
                reserved_attrs.append(out_attr)
            else:
                other_attrs.append(out_attr)
        out_attrs = ';'.join((reserved_attrs + other_attrs))
    else:
        out_attrs = attrs
    return out_attrs

Restore an entries attributes in original format, escaping reserved
characters when necessary

Returns:
str: escaped attributes as tag=value pairs, separated by semi-colon


def _deserialization_helper(self, state, ray_forking):

        worker = ray.worker.get_global_worker()
        worker.check_connected()

        if state["ray_forking"]:
            actor_handle_id = state["actor_handle_id"]
        else:

            actor_handle_id = compute_actor_handle_id_non_forked(
                state["actor_handle_id"], worker.current_task_id)

        self.__init__(
            state["actor_id"],
            state["module_name"],
            state["class_name"],
            state["actor_cursor"],
            state["actor_method_names"],
            state["method_signatures"],
            state["method_num_return_vals"],
            state["actor_creation_dummy_object_id"],
            state["actor_method_cpus"],

            state["actor_driver_id"],
            actor_handle_id=actor_handle_id)

This is defined in order to make pickling work.

Args:
state: The serialized state of the actor handle.
ray_forking: True if this is being called because Ray is forking
the actor handle and false if it is being called by pickling.


def samefile(path1, path2):

    path1, path1_is_storage = format_and_is_storage(path1)
    path2, path2_is_storage = format_and_is_storage(path2)

    if not path1_is_storage and not path2_is_storage:
        return os_path_samefile(path1, path2)

    if not path1_is_storage or not path2_is_storage:
        return False

    with handle_os_exceptions():

        system = get_instance(path1)
        if system is not get_instance(path2):
            return False

        elif system.relpath(path1) != system.relpath(path2):
            return False

    return True

Return True if both pathname arguments refer to the same file or directory.

Equivalent to "os.path.samefile".

Args:
path1 (path-like object): Path or URL.
path2 (path-like object): Path or URL.

Returns:
bool: True if same file or directory.


def main(jlink_serial, device):
    buf = StringIO.StringIO()
    jlink = pylink.JLink(log=buf.write, detailed_log=buf.write)
    jlink.open(serial_no=jlink_serial)
    jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
    jlink.connect(device, verbose=True)
    sys.stdout.write(('ARM Id: %d\n' % jlink.core_id()))
    sys.stdout.write(('CPU Id: %d\n' % jlink.core_cpu()))
    sys.stdout.write(('Core Name: %s\n' % jlink.core_name()))
    sys.stdout.write(('Device Family: %d\n' % jlink.device_family()))

Prints the core's information.

Args:
jlink_serial (str): the J-Link serial number
device (str): the target CPU

Returns:
Always returns ``0``.

Raises:
JLinkException: on error


def from_graph(cls, graph, linear_energy_ranges, quadratic_energy_ranges):
    get_env().enable_infix_notation = True
    theta = cls.empty(dimod.SPIN)
    theta.add_offset(Symbol('offset', REAL))

    def Linear(v):
        'Create a Symbol for the linear bias including the energy range\n            constraints.'
        bias = Symbol('h_{}'.format(v), REAL)
        (min_, max_) = linear_energy_ranges[v]
        theta.assertions.add(LE(bias, limitReal(max_)))
        theta.assertions.add(GE(bias, limitReal(min_)))
        return bias

    def Quadratic(u, v):
        'Create a Symbol for the quadratic bias including the energy range\n            constraints.'
        bias = Symbol('J_{},{}'.format(u, v), REAL)
        if ((v, u) in quadratic_energy_ranges):
            (min_, max_) = quadratic_energy_ranges[(v, u)]
        else:
            (min_, max_) = quadratic_energy_ranges[(u, v)]
        theta.assertions.add(LE(bias, limitReal(max_)))
        theta.assertions.add(GE(bias, limitReal(min_)))
        return bias
    for v in graph.nodes:
        theta.add_variable(v, Linear(v))
    for (u, v) in graph.edges:
        theta.add_interaction(u, v, Quadratic(u, v))
    return theta

Create Theta from a graph and energy ranges.

Args:
graph (:obj:`networkx.Graph`):
Provides the structure for Theta.

linear_energy_ranges (dict):
A dict of the form {v: (min, max), ...} where min and max are the
range of values allowed to v.
quadratic_energy_ranges (dict):
A dict of the form {(u, v): (min, max), ...} where min and max
are the range of values allowed to (u, v).

Returns:
:obj:`.Theta`


def from_dict(cls, pwinput_dict):

        pwinput = cls(structure=Structure.from_dict(pwinput_dict['structure']),
                          pseudo=pwinput_dict['pseudo'],
                          control=pwinput_dict['sections']['control'],
                          system=pwinput_dict['sections']['system'],
                          electrons=pwinput_dict['sections']['electrons'],
                          ions=pwinput_dict['sections']['ions'],
                          cell=pwinput_dict['sections']['cell'],
                          kpoints_mode=pwinput_dict['kpoints_mode'],
                          kpoints_grid=pwinput_dict['kpoints_grid'],
                          kpoints_shift=pwinput_dict['kpoints_shift'])
        return pwinput

Load a PWInput object from a dictionary.

Args:
pwinput_dict (dict): dictionary with PWInput data

Returns:
PWInput object


def _check_positional_parameters(method_signature, base_signature, is_subtype, ctx):
    check_types = True
    for base_param_pos, base_param_name in enumerate(base_signature.param_names):
        if base_param_pos == 0 or base_param_pos < base_signature.posonly_count:
            continue
        if base_param_name == '_':
            continue
        if base_param_pos < method_signature.posonly_count:
            return SignatureError(SignatureErrorType.POSITIONAL_PARAMETER_COUNT_MISMATCH, 'Too many positional-only parameters in overriding method.')
        elif base_param_pos < len(method_signature.param_names):
            method_param_name = method_signature.param_names[base_param_pos]
        else:
            if method_signature.varargs_name:
                break
            return SignatureError(SignatureErrorType.POSITIONAL_PARAMETER_COUNT_MISMATCH, 'Not enough positional parameters in overriding method.')
        method_param_name = method_signature.param_names[base_param_pos]
        if method_param_name not in (base_param_name, '_'):
            log.warning('Name mismatch for parameter %r.', base_param_name)
            if not ctx.options.overriding_renamed_parameter_count_checks:
                return None
            check_types = False
    remaining_method_params = method_signature.param_names[len(base_signature.param_names):] if not base_signature.varargs_name else []
    for method_param_name in remaining_method_params:
        if method_param_name in base_signature.kwonly_params:
            continue
        if method_param_name not in method_signature.defaults:
            return SignatureError(SignatureErrorType.DEFAULT_PARAMETER_MISMATCH, f"Parameter '{method_param_name}' must have a default value.")
    if not check_types:
        return None
    return _check_positional_parameter_annotations(method_signature, base_signature, is_subtype)

Checks that the positional parameters of the overriding method match.

Args:
method_signature: signature of the overriding method.
base_signature: signature of the overridden method.
is_subtype: a binary function to compare types.
ctx: Context

Returns:
SignatureError if a mismatch is detected. Otherwise returns None.


def new_space(self, name=None, bases=None, formula=None, refs=None):
    space = self._impl.model.currentspace = self._impl.new_space(name=name, bases=get_impls(bases), formula=formula, refs=refs)
    return space.interface

Create a child space.

Args:
name (str, optional): Name of the space. Defaults to ``SpaceN``,
where ``N`` is a number determined automatically.
bases (optional): A space or a sequence of spaces to be the base
space(s) of the created space.
formula (optional): Function to specify the parameters of
dynamic child spaces. The signature of this function is used
for setting parameters for dynamic child spaces.
This function should return a mapping of keyword arguments
to be passed to this method when the dynamic child spaces
are created.

Returns:
The new child space.


def stream_matching(self, address, name):

        matching = [x for x in self.entries if x.valid and x.target.matches(address, name)]

        rpc_list = []
        for var in matching:
            rpc_list.extend(var.generate_rpcs(address))

        return rpc_list

Return the RPCs needed to stream matching config variables to the given tile.

This function will return a list of tuples suitable for passing to
EmulatedDevice.deferred_rpc.

Args:
address (int): The address of the tile that we wish to stream to
name (str or bytes): The 6 character name of the target tile.

Returns:
list of tuple: The list of RPCs to send to stream these variables to a tile.


def DeleteFeaturesFromFeatureLayer(self, url, sql, chunksize=0):
    fl = None
    try:
        fl = FeatureLayer(url=url, securityHandler=self._securityHandler)
        totalDeleted = 0
        if (chunksize > 0):
            qRes = fl.query(where=sql, returnIDsOnly=True)
            if ('error' in qRes):
                print(qRes)
                return qRes
            elif ('objectIds' in qRes):
                oids = qRes['objectIds']
                total = len(oids)
                if (total == 0):
                    return {'success': True, 'message': 'No features matched the query'}
                i = 0
                print(('%s features to be deleted' % total))
                while (i <= len(oids)):
                    oidsDelete = ','.join((str(e) for e in oids[i:(i + chunksize)]))
                    if (oidsDelete == ''):
                        continue
                    else:
                        results = fl.deleteFeatures(objectIds=oidsDelete)
                    if ('deleteResults' in results):
                        totalDeleted += len(results['deleteResults'])
                        print(('%s%% Completed: %s/%s ' % (int(((totalDeleted / float(total)) * 100)), totalDeleted, total)))
                        i += chunksize
                    else:
                        print(results)
                        return {'success': True, 'message': ('%s deleted' % totalDeleted)}
                qRes = fl.query(where=sql, returnIDsOnly=True)
                if ('objectIds' in qRes):
                    oids = qRes['objectIds']
                    if (len(oids) > 0):
                        print(('%s features to be deleted' % len(oids)))
                        results = fl.deleteFeatures(where=sql)
                        if ('deleteResults' in results):
                            totalDeleted += len(results['deleteResults'])
                            return {'success': True, 'message': ('%s deleted' % totalDeleted)}
                        else:
                            return results
                return {'success': True, 'message': ('%s deleted' % totalDeleted)}
            else:
                print(qRes)
        else:
            results = fl.deleteFeatures(where=sql)
            if (results is not None):
                if ('deleteResults' in results):
                    return {'success': True, 'message': (totalDeleted + len(results['deleteResults']))}
                else:
                    return results
    except:
        (line, filename, synerror) = trace()
        raise common.ArcRestHelperError({'function': 'DeleteFeaturesFromFeatureLayer', 'line': line, 'filename': filename, 'synerror': synerror})
    finally:
        fl = None
        del fl
        gc.collect()

Removes features from a hosted feature service layer by SQL query.

Args:
url (str): The URL of the feature service layer.
sql (str): The SQL query to apply against the feature service.
Those features that satisfy the query will be deleted.
chunksize (int): The maximum amount of features to remove at a time. Defaults to 0.
Returns:
The result from :py:func:`arcrest.agol.services.FeatureLayer.deleteFeatures`.
Notes:
If you want to delete all features, it is suggested to use the SQL query ``"1=1"``.


def convert_upsample_bilinear(params, w_name, scope_name, inputs, layers, weights, names):
    print('Converting upsample...')
    if (names == 'short'):
        tf_name = ('UPSL' + random_string(4))
    elif (names == 'keep'):
        tf_name = w_name
    else:
        tf_name = (w_name + str(random.random()))
    output_size = params['output_size']
    align_corners = (params['align_corners'] > 0)

    def target_layer(x, size=output_size, align_corners=align_corners):
        import tensorflow as tf
        x = tf.transpose(x, [0, 2, 3, 1])
        x = tf.image.resize_images(x, size, align_corners=align_corners)
        x = tf.transpose(x, [0, 3, 1, 2])
        return x
    lambda_layer = keras.layers.Lambda(target_layer)
    layers[scope_name] = lambda_layer(layers[inputs[0]])

Convert upsample_bilinear2d layer.

Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers


def xmlstring(self, pretty_print=False):
    s = ElementTree.tostring(self.xml(), xml_declaration=False, pretty_print=pretty_print, encoding='utf-8')
    if (sys.version < '3'):
        if isinstance(s, str):
            s = unicode(s, 'utf-8')
    elif isinstance(s, bytes):
        s = str(s, 'utf-8')
    s = s.replace('ns0:', '')
    s = s.replace(':ns0', '')
    return s

Serialises this FoLiA element and all its contents to XML.

Returns:
str: a string with XML representation for this element and all its children


def from_json(cls, json, image_config=None):

        cls.image_config = image_config
        return cls(**{
            attr: json.get(attr if key is None else key)
            for attr, key in cls.JSON_MAPPING.items()
        })

Create a model instance

Arguments:
json (:py:class:`dict`): The parsed JSON data.
image_config (:py:class:`dict`): The API image configuration
data.

Returns:
:py:class:`BaseModel`: The model instance.


def _update_context_field_binary_composition(present_locations, expression):
    if (not any((isinstance(expression.left, ContextField), isinstance(expression.right, ContextField)))):
        raise AssertionError(u'Received a BinaryComposition {} without any ContextField operands. This should never happen.'.format(expression))
    if isinstance(expression.left, ContextField):
        context_field = expression.left
        (location_name, _) = context_field.location.get_location_name()
        if (location_name not in present_locations):
            return TrueLiteral
    if isinstance(expression.right, ContextField):
        context_field = expression.right
        (location_name, _) = context_field.location.get_location_name()
        if (location_name not in present_locations):
            return TrueLiteral
    return expression

Lower BinaryCompositions involving non-existent ContextFields to True.

Args:
present_locations: set of all locations in the current MatchQuery that have not been pruned
expression: BinaryComposition with at least one ContextField operand

Returns:
TrueLiteral iff either ContextField operand is not in `present_locations`,
and the original expression otherwise


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

Corresponds to IDD Field `wind_speed`

Args:
value (float): value for IDD Field `wind_speed`
Unit: m/s
value >= 0.0
value <= 40.0
Missing value: 999.0
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

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


def __new__(cls, name, bases, attrs):

        new_class = super(PipelineFormMediaMetaClass, cls).__new__(
            cls, name, bases, attrs)

        if 'css_packages' in attrs:
            new_class.css = PipelineFormMediaProperty(
                cls._get_css_files, new_class, attrs.get('css') or {})

        if 'js_packages' in attrs:
            new_class.js = PipelineFormMediaProperty(
                cls._get_js_files, new_class, attrs.get('js') or [])

        return new_class

Construct the class.

Args:
name (bytes):
The name of the class.

bases (tuple):
The base classes for the class.

attrs (dict):
The attributes going into the class.

Returns:
type:
The new class.


def google_api_build_errors(config, auth, api_call, errors):
    if 'bigquery' in errors:
        errors['bigquery']['schema'] = ERROR_SCHEMA
        errors['bigquery']['format'] = 'JSON'
        errors['bigquery']['skip_rows'] = 0
        errors['bigquery']['disposition'] = 'WRITE_TRUNCATE'
        table_create(config, errors['bigquery'].get('auth', auth), config.project, errors['bigquery']['dataset'], errors['bigquery']['table'], errors['bigquery']['schema'], overwrite=False)
    return errors

Builds the BigQuery table to house the Google API call errors.

Optional piece of the recipe, will create a BigQuery table for errors.
Takes errors, which defines a bigquery endpoint, and adds fields.

Args:
auth (string): either "user" or "service" to make the BigQuery call.
api_call (dict): the JSON for the API call as defined in recipe.
errors (dict): defines where the data will be written

Returns (dict):
A modified results JSON with additional API values added.

Raises:
ValueError: If a required key in the recipe is missing.


def logical_and(x1, x2):
    if any_symbolic_tensors((x1, x2)):
        return LogicalAnd().symbolic_call(x1, x2)
    return backend.numpy.logical_and(x1, x2)

Computes the element-wise logical AND of the given input tensors.

Zeros are treated as `False` and non-zeros are treated as `True`.

Args:
x1: Input tensor.
x2: Input tensor.

Returns:
Output tensor, element-wise logical AND of the inputs.


def _update_state_from_shard_states(self, state, shard_states, control):

    state.active_shards, state.aborted_shards, state.failed_shards = 0, 0, 0
    total_shards = 0
    processed_counts = []
    processed_status = []
    state.counters_map.clear()

    for s in shard_states:
      total_shards += 1
      status = 'unknown'
      if s.active:
        state.active_shards += 1
        status = 'running'
      if s.result_status == model.ShardState.RESULT_SUCCESS:
        status = 'success'
      elif s.result_status == model.ShardState.RESULT_ABORTED:
        state.aborted_shards += 1
        status = 'aborted'
      elif s.result_status == model.ShardState.RESULT_FAILED:
        state.failed_shards += 1
        status = 'failed'

      state.counters_map.add_map(s.counters_map)
      processed_counts.append(s.counters_map.get(context.COUNTER_MAPPER_CALLS))
      processed_status.append(status)

    state.set_processed_counts(processed_counts, processed_status)
    state.last_poll_time = datetime.datetime.utcfromtimestamp(self._time())

    spec = state.mapreduce_spec

    if total_shards != spec.mapper.shard_count:
      logging.error("Found %d shard states. Expect %d. "
                    "Issuing abort command to job '%s'",
                    total_shards, spec.mapper.shard_count,
                    spec.mapreduce_id)

      model.MapreduceControl.abort(spec.mapreduce_id)

    state.active = bool(state.active_shards)
    if not control and (state.failed_shards or state.aborted_shards):

      model.MapreduceControl.abort(spec.mapreduce_id)

    if not state.active:

      if state.failed_shards or not total_shards:
        state.result_status = model.MapreduceState.RESULT_FAILED

      elif state.aborted_shards:
        state.result_status = model.MapreduceState.RESULT_ABORTED
      else:
        state.result_status = model.MapreduceState.RESULT_SUCCESS
      self._finalize_outputs(spec, state)
      self._finalize_job(spec, state)
    else:
      @db.transactional(retries=5)
      def _put_state():

        fresh_state = model.MapreduceState.get_by_job_id(spec.mapreduce_id)

        if not fresh_state.active:
          logging.warning(
              "Job %s is not active. Looks like spurious task execution. "
              "Dropping controller task.", spec.mapreduce_id)
          return
        config = util.create_datastore_write_config(spec)
        state.put(config=config)

      _put_state()

Update mr state by examing shard states.

Args:
state: current mapreduce state as MapreduceState.
shard_states: an iterator over shard states.
control: model.MapreduceControl entity.


def check_and_update_resources(num_cpus, num_gpus, resources):

    if resources is None:
        resources = {}
    resources = resources.copy()
    assert "CPU" not in resources
    assert "GPU" not in resources
    if num_cpus is not None:
        resources["CPU"] = num_cpus
    if num_gpus is not None:
        resources["GPU"] = num_gpus

    if "CPU" not in resources:

        resources["CPU"] = multiprocessing.cpu_count()

    gpu_ids = ray.utils.get_cuda_visible_devices()

    if ("GPU" in resources and gpu_ids is not None
            and resources["GPU"] > len(gpu_ids)):
        raise Exception("Attempting to start raylet with {} GPUs, "
                        "but CUDA_VISIBLE_DEVICES contains {}.".format(
                            resources["GPU"], gpu_ids))

    if "GPU" not in resources:

        resources["GPU"] = _autodetect_num_gpus()

        if gpu_ids is not None:
            resources["GPU"] = min(resources["GPU"], len(gpu_ids))

    resources = {
        resource_label: resource_quantity
        for resource_label, resource_quantity in resources.items()
        if resource_quantity != 0
    }

    for _, resource_quantity in resources.items():
        assert (isinstance(resource_quantity, int)
                or isinstance(resource_quantity, float))
        if (isinstance(resource_quantity, float)
                and not resource_quantity.is_integer()):
            raise ValueError(
                "Resource quantities must all be whole numbers. Received {}.".
                format(resources))
        if resource_quantity < 0:
            raise ValueError(
                "Resource quantities must be nonnegative. Received {}.".format(
                    resources))
        if resource_quantity > ray_constants.MAX_RESOURCE_QUANTITY:
            raise ValueError("Resource quantities must be at most {}.".format(
                ray_constants.MAX_RESOURCE_QUANTITY))

    return resources

Sanity check a resource dictionary and add sensible defaults.

Args:
num_cpus: The number of CPUs.
num_gpus: The number of GPUs.
resources: A dictionary mapping resource names to resource quantities.

Returns:
A new resource dictionary.


def _UpdateSudoer(self, user, sudoer=False):
    if sudoer:
        self.logger.info('Adding user %s to the Google sudoers group.', user)
        command = self.gpasswd_add_cmd.format(user=user, group=self.google_sudoers_group)
    else:
        self.logger.info('Removing user %s from the Google sudoers group.', user)
        command = self.gpasswd_remove_cmd.format(user=user, group=self.google_sudoers_group)
    try:
        subprocess.check_call(command.split(' '))
    except subprocess.CalledProcessError as e:
        self.logger.warning('Could not update user %s. %s.', user, str(e))
        return False
    else:
        self.logger.debug('Removed user %s from the Google sudoers group.', user)
        return True

Update sudoer group membership for a Linux user account.

Args:
user: string, the name of the Linux user account.
sudoer: bool, True if the user should be a sudoer.

Returns:
bool, True if user update succeeded.


def stage_tc_batch(self, owner, staging_data):

        batch = self.tcex.batch(owner)
        for group in staging_data.get('group') or []:

            variable = group.pop('variable', None)
            path = group.pop('path', None)
            data = self.path_data(group, path)

            if group.get('xid') is None:

                group['xid'] = self.stage_tc_batch_xid(group.get('type'), group.get('name'), owner)

            group['ownerName'] = owner

            batch.add_group(group)

            if variable is not None and data is not None:
                self.stage_redis(variable, self.stage_tc_group_entity(data))
        for indicator in staging_data.get('indicator') or []:

            variable = indicator.pop('variable', None)
            path = indicator.pop('path', None)
            if indicator.get('xid') is None:
                indicator['xid'] = self.stage_tc_batch_xid(
                    indicator.get('type'), indicator.get('summary'), owner
                )
            indicator['ownerName'] = owner

            batch.add_indicator(indicator)
            data = self.path_data(dict(indicator), path)
            if variable is not None and data is not None:

                self.stage_redis(variable, self.stage_tc_indicator_entity(data))

        batch_results = batch.submit()
        self.log.debug('[stage] Batch Results: {}'.format(batch_results))
        for error in batch_results.get('errors') or []:
            self.log.error('[stage] {}'.format(error))

Stage data in ThreatConnect Platform using batch API.

Args:
owner (str): The ThreatConnect owner to submit batch job.
staging_data (dict): A dict of ThreatConnect batch data.


def __new__(mcls, name, parents, attributes):

    return type.__new__(mcls, name, parents, attributes)

Creates a new Type object (an instance of TypeMetaclass).
Args:
name (str): the name of the new type.
parents (list(str)): a list of superclasses.
attributes: (???): a map from name to value for "parameters" for defining
the new type.


def get_video_transcript_url(video_id, language_code):

    video_transcript = VideoTranscript.get_or_none(video_id, language_code)
    if video_transcript:
        return video_transcript.url()

Returns course video transcript url or None if no transcript

Arguments:
video_id: it can be an edx_video_id or an external_id extracted from external sources in a video component.
language_code: language code of a video transcript


def _create_node(self, index: int, name: str, external_id: Optional[str] = None) -> IGraphNode:

        return IGraphNode(graph=self._graph, index=index, name=name, external_id=external_id)

Returns a new `IGraphNode` instance with the given index and name.

Arguments:
index (int): The index of the node to create.
name (str): The name of the node to create.
external_id (Optional[str]): The external ID of the node.


def sym_jsonify(self, compact: bool=True, type_info: bool=True, **kwargs) -> Any:
    if not compact:
        json_value = super().sym_jsonify(**kwargs)
        assert isinstance(json_value, dict), json_value
        if self._cloneable_metadata_keys:
            json_value['_cloneable_metadata_keys'] = list(self._cloneable_metadata_keys)
        return json_value
    if self.children:
        child_nodes = [c.sym_jsonify(compact, type_info=False, **kwargs) for c in self.children]
        if self.value is not None:
            if len(child_nodes) == 1:
                single_choice = child_nodes[0]
                if isinstance(single_choice, tuple):
                    value = (self.value,) + single_choice
                else:
                    value = (self.value, single_choice)
            else:
                value = (self.value, child_nodes)
        else:
            value = child_nodes
    else:
        value = self.value
    if type_info:
        json_value = {utils.JSONConvertible.TYPE_NAME_KEY: self.__class__.__serialization_key__, 'format': 'compact', 'value': symbolic.to_json(value)}
        if self.metadata:
            json_value['metadata'] = symbolic.to_json(self.metadata)
        if self._cloneable_metadata_keys:
            json_value['_cloneable_metadata_keys'] = list(self._cloneable_metadata_keys)
        return json_value
    else:
        return value

Convert DNA to JSON object.

Args:
compact: Whether use compact form. If compact, the nested number structure
in DNA.parse will be used, otherwise members will be rendered out as
regular symbolic Object.
type_info: If True, type information will be included in output, otherwise
type information will not be included. Applicable when compact is set
to True.
**kwargs: Keyword arguments that will be passed to symbolic.Object if
compact is False.

Returns:
JSON representation of DNA.


def make_graph_def_with_constant_nodes(node_sizes: Sequence[int], dtype: Optional[dtypes.DType]=None, **function_node_sizes) -> graph_pb2.GraphDef:
    dtype = dtypes.float32
    graph_def = graph_pb2.GraphDef()
    n = 0

    def add_nodes(node_list, sizes):
        nonlocal n
        for s in sizes:
            node = node_list.add(name=f'Const_{n}', op='Const')
            node.attr['value'].tensor.MergeFrom(tensor_util.make_tensor_proto(np.ones([]), dtype=dtype))
            remaining_size = s - node.ByteSize()
            if remaining_size < 0:
                raise ValueError(f'Unable to create node of size {s} bytes.')
            constant_size = [math.ceil(remaining_size / dtype.size)]
            node.attr['value'].tensor.Clear()
            node.attr['value'].tensor.MergeFrom(tensor_util.make_tensor_proto(np.random.random_sample(constant_size), dtype=dtype))
            n += 1
    add_nodes(graph_def.node, node_sizes)
    for fn_name, fn_sizes in function_node_sizes.items():
        fn = graph_def.library.function.add()
        fn.signature.name = fn_name
        add_nodes(fn.node_def, fn_sizes)
    return graph_def

Creates a GraphDef with approximate node sizes.

Args:
node_sizes: list of ints, the approximate desired sizes of the nodes in the
GraphDef.
dtype: Dtype of encoded constant values (float32 or float64).
**function_node_sizes: Map of function name to FunctionDef node sizes (see
`node_sizes`).

Returns:
A GraphDef proto.


def split(self, amount):
    split_objs = list(self.all())
    if (not split_objs):
        raise NoSplitsFoundForRecurringCost()
    portions = [split_obj.portion for split_obj in split_objs]
    split_amounts = ratio_split(amount, portions)
    return [(split_objs[i], split_amount) for (i, split_amount) in enumerate(split_amounts)]

Split the value given by amount according to the RecurringCostSplit's portions

Args:
amount (Decimal):

Returns:
list[(RecurringCostSplit, Decimal)]: A list with elements in the form (RecurringCostSplit, Decimal)


def save_model(self, fname, pretty=False):
    with open(fname, 'w') as f:
        xml_str = ET.tostring(self.root, encoding='unicode')
        if pretty:
            parsed_xml = xml.dom.minidom.parseString(xml_str)
            xml_str = parsed_xml.toprettyxml(newl='')
        f.write(xml_str)

Saves the xml to file.

Args:
fname: output file location
pretty: attempts!! to pretty print the output


def add_execution_event(self, context_id, event):

        if context_id not in self._contexts:
            LOGGER.warning("Context_id not in contexts, %s", context_id)
            return False

        context = self._contexts.get(context_id)
        context.add_execution_event(event)
        return True

Within a context, append data to the execution result.

Args:
context_id (str): the context id returned by create_context
data_type (str): type of data to append
data (bytes): data to append

Returns:
(bool): True if the operation is successful, False if
the context_id doesn't reference a known context.


class EosTokenCriteria(StoppingCriteria):

    def __init__(self, eos_token_id: Union[int, List[int], torch.Tensor]):
        if not isinstance(eos_token_id, torch.Tensor):
            if isinstance(eos_token_id, int):
                eos_token_id = [eos_token_id]
            eos_token_id = torch.tensor(eos_token_id)
        self.eos_token_id = eos_token_id

    @add_start_docstrings(STOPPING_CRITERIA_INPUTS_DOCSTRING)
    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> torch.BoolTensor:
        self.eos_token_id = self.eos_token_id.to(input_ids.device)
        is_done = isin_mps_friendly(input_ids[:, -1], self.eos_token_id)
        return is_done

This class can be used to stop generation whenever the "end-of-sequence" token is generated.
By default, it uses the `model.generation_config.eos_token_id`.

Args:
eos_token_id (`Union[int, List[int], torch.Tensor]`):
The id(s) of the *end-of-sequence* token.


def AssertIterableType(iterable, expected_item_type):

  if isinstance(iterable, collections.Iterator):
    message = "Expected iterable container but got iterator `%s` instead"
    message %= iterable
    raise TypeError(message)

  AssertType(iterable, collections.Iterable)
  for item in iterable:
    AssertType(item, expected_item_type)

Ensures that given iterable container has certain type.

Args:
iterable: An iterable container to assert the type for.
expected_item_type: An expected type of the container items.

Raises:
TypeError: If given container does is not an iterable or its items do not
have the expected type.


def filecmp(filename_a, filename_b):
    size_a = FileIO(filename_a, 'rb').size()
    size_b = FileIO(filename_b, 'rb').size()
    if size_a != size_b:
        return False
    crc_a = file_crc32(filename_a)
    crc_b = file_crc32(filename_b)
    return crc_a == crc_b

Compare two files, returning True if they are the same, False otherwise.

We check size first and return False quickly if the files are different sizes.
If they are the same size, we continue to generating a crc for the whole file.

You might wonder: why not use Python's `filecmp.cmp()` instead? The answer is
that the builtin library is not robust to the many different filesystems
TensorFlow runs on, and so we here perform a similar comparison with
the more robust FileIO.

Args:
filename_a: string path to the first file.
filename_b: string path to the second file.

Returns:
True if the files are the same, False otherwise.


def registration_info_request(self, registration_id):

        return self.requests_session.get(
            self.INFO_END_POINT + registration_id,
            params={'details': 'true'}
        )

Makes a request for registration info and returns the response object

Args:
registration_id: id to be checked

Returns:
response of registration info request


def json(self) -> dict:
    content = {}
    content['name'] = self.name
    content['callback'] = self.callback
    self.control_json['content'] = content
    return self.control_json

Returns json compatible state of the Button instance.

Returns:
control_json: Json representation of Button state.


def __init__(self, dns_ip):

        self._dns_ip = dns_ip
        self._resolver = ProxyResolver()
        try:
            self._resolver.set_proxies([self._dns_ip])
        except async_dns.address.InvalidHost as e:
            msg = f'RecordChecker got invalid DNS server IP: {e}.'
            raise exceptions.InvalidDNSHost(msg)

Setup RecordChecker object.

Args:
dns_ip: DNS server IP to query.


def extract_object_files(archive_file: io.BufferedIOBase, dest_dir: str) -> None:
    if not os.path.exists(dest_dir):
        os.makedirs(dest_dir)
    _check_archive_signature(archive_file)
    extracted_files = dict()
    for name, file_content in _extract_next_file(archive_file):
        digest = hashlib.md5(file_content).digest()
        for final_name in _generate_modified_filenames(name):
            if final_name not in extracted_files:
                extracted_files[final_name] = digest
                with open(os.path.join(dest_dir, final_name), 'wb') as object_file:
                    object_file.write(file_content)
                break
            elif extracted_files[final_name] == digest:
                break

Extracts object files from the archive path to the destination directory.

Extracts object files from the given BSD variant archive file. The extracted
files are written to the destination directory, which will be created if the
directory does not exist.

Colliding object file names are automatically renamed upon extraction in order
to avoid unintended overwriting.

Args:
archive_file: The archive file object pointing at its beginning.
dest_dir: The destination directory path in which the extracted object files
will be written. The directory will be created if it does not exist.


def check_valid_values(function):

    def decorated(self, X, *args, **kwargs):

        if isinstance(X, pd.DataFrame):
            W = X.values

        else:
            W = X

        if not len(W):
            raise ValueError('Your dataset is empty.')

        if W.dtype not in [np.dtype('float64'), np.dtype('int64')]:
            raise ValueError('There are non-numerical values in your data.')

        if np.isnan(W).any().any():
            raise ValueError('There are nan values in your data.')

        return function(self, X, *args, **kwargs)

    return decorated

Raises an exception if the given values are not supported.

Args:
function(callable): Method whose unique argument is a numpy.array-like object.

Returns:
callable: Decorated function

Raises:
ValueError: If there are missing or invalid values or if the dataset is empty.


def _convert_as_saved_model(self):
    temp_dir = tempfile.mkdtemp()
    try:
        self._freeze_keras_model(temp_dir)
        if self.saved_model_dir:
            return super(TFLiteKerasModelConverter, self).convert()
    finally:
        shutil.rmtree(temp_dir, True)

Converts a Keras model as a saved model.

Returns:
The converted data in serialized format.


def _init_from_args(self, maximum_iterations, parallel_iterations, back_prop, swap_memory, name):
    if not isinstance(parallel_iterations, int) or parallel_iterations <= 0:
        raise ValueError("'parallel_iterations' must be a positive integer: %s" % parallel_iterations)
    self._name = ops.get_default_graph().unique_name(name)
    self._maximum_iterations = maximum_iterations
    self._parallel_iterations = parallel_iterations
    self._back_prop = back_prop
    self._swap_memory = swap_memory
    self._pivot_for_pred = None
    self._pivot_for_body = None
    self._pivot = None
    self._loop_exits = []
    self._loop_enters = []
    self._graph = ops.get_default_graph()

Creates a new `WhileContext` from arguments.

Args:
maximum_iterations: Optional upper bound on number of loop iterations.
parallel_iterations: The number of iterations allowed to run in parallel.
back_prop: Whether backprop is enabled for this while loop.
swap_memory: Whether GPU-CPU memory swap is enabled for this loop.
name: Optional name prefix for the returned tensors.

Raises:
ValueError: If `parallel_iterations` has invalid value.


def setup(app):
    for (name, (default, rebuild, _)) in ref.CONFIG_VALUES.iteritems():
        app.add_config_value(name, default, rebuild)
    app.add_directive('javaimport', ref.JavarefImportDirective)
    app.add_role('javaref', ref.JavarefRole(app))
    app.connect('builder-inited', initialize_env)
    app.connect('env-purge-doc', ref.purge_imports)
    app.connect('env-merge-info', ref.merge_imports)
    app.connect('build-finished', ref.cleanup)

Register the extension with Sphinx.

Args:
app: The Sphinx application.


def average(self, selector=identity):
    if self.closed():
        raise ValueError('Attempt to call average() on a closed Queryable.')
    if (not is_callable(selector)):
        raise TypeError('average() parameter selector={0} is not callable'.format(repr(selector)))
    total = 0
    count = 0
    for item in self.select(selector):
        total += item
        count += 1
    if (count == 0):
        raise ValueError('Cannot compute average() of an empty sequence.')
    return (total / count)

Return the arithmetic mean of the values in the sequence..

All of the source sequence will be consumed.

Note: This method uses immediate execution.

Args:
selector: An optional single argument function which will be used
to project the elements of the sequence. If omitted, the
identity function is used.

Returns:
The arithmetic mean value of the projected sequence.

Raises:
ValueError: If the Queryable has been closed.
ValueError: I the source sequence is empty.


def sas_interconnects(self):
    if (not self.__sas_interconnects):
        self.__sas_interconnects = SasInterconnects(self.__connection)
    return self.__sas_interconnects

Gets the SAS Interconnects API client.

Returns:
SasInterconnects:


def keras_model_summary(name, data, step=None):
    import tensorflow.summary as summary
    from tensorflow.compat.v1 import SummaryMetadata
    summary_metadata = SummaryMetadata()
    summary_metadata.plugin_data.plugin_name = 'graph_keras_model'
    summary_metadata.plugin_data.content = b'1'
    try:
        json_string = data.to_json()
    except Exception as exc:
        warnings.warn(f'Model failed to serialize as JSON. Ignoring... {exc}')
        return False
    with summary.experimental.summary_scope(name, 'graph_keras_model', [data, step]) as (tag, _):
        return summary.write(tag=tag, tensor=json_string, step=step, metadata=summary_metadata)

Writes a Keras model as JSON to as a Summary.

Writing the Keras model configuration allows the TensorBoard graph plugin to
render a conceptual graph, as opposed to graph of ops. In case the model
fails to serialize as JSON, it ignores and returns False.

Args:
name: A name for this summary. The summary tag used for TensorBoard will
be this name prefixed by any active name scopes.
data: A Keras Model to write.
step: Explicit `int64`-castable monotonic step value for this summary.
If omitted, this defaults to `tf.summary.experimental.get_step()`,
which must not be `None`.

Returns:
True on success, or False if no summary was written because no default
summary writer was available.

Raises:
ValueError: if a default writer exists, but no step was provided and
`tf.summary.experimental.get_step()` is `None`.


def to_soft(self, path_or_handle, as_gzip=False):

        if isinstance(path_or_handle, str):
            if as_gzip:
                with gzip.open(path_or_handle, 'wt') as outfile:
                    outfile.write(self._get_object_as_soft())
            else:
                with open(path_or_handle, 'w') as outfile:
                    outfile.write(self._get_object_as_soft())
        else:
            path_or_handle.write(self._get_object_as_soft())

Save the object in a SOFT format.

Args:
path_or_handle (:obj:`str` or :obj:`file`): Path or handle to
output file
as_gzip (:obj:`bool`): Save as gzip


def do_labels_update(self, info, labels):

        if self.update_label_func:
            self.update_label_func(self.label_name, info, labels)

Updates a dictionary of labels using the assigned update_op_func

Args:
info (:class:`endpoints_management.control.report_request.Info`): the
info instance to update
labels (dict[string[string]]): the labels dictionary

Return:
`True` if desc is supported, otherwise `False`


def set_organization(self, organization):

        if isinstance(organization, hdx.data.organization.Organization) or isinstance(organization, dict):
            if 'id' not in organization:
                organization = hdx.data.organization.Organization.read_from_hdx(organization['name'], configuration=self.configuration)
            organization = organization['id']
        elif not isinstance(organization, str):
            raise HDXError('Type %s cannot be added as a organization!' % type(organization).__name__)
        if is_valid_uuid(organization) is False and organization != 'hdx':
            raise HDXError('%s is not a valid organization id!' % organization)
        self.data['owner_org'] = organization

Set the dataset's organization.

Args:
organization (Union[Organization,Dict,str]): Either an Organization id or Organization metadata from an Organization object or dictionary.
Returns:
None


def namespace(self, mid: ModuleId) -> YangIdentifier:

        try:
            mdata = self.modules[mid]
        except KeyError:
            raise ModuleNotRegistered(*mid) from None
        return mdata.main_module[0]

Return the namespace corresponding to a module or submodule.

Args:
mid: Module identifier.

Raises:
ModuleNotRegistered: If `mid` is not registered in the data model.


def __init__(self, src, raw_traces, trace_factory, filename):
    self.text = src
    self.traces = _collect_traces(raw_traces, trace_factory)
    self.filename = filename
    self._lines = src.split('\n')
    self._offsets = []
    self._init_byte_offsets()

Initializer.

Args:
src: The source text.
raw_traces: Raw (opcode, symbol, types) values.
trace_factory: A subclass of source.AbstractTrace that will be used to
instantiate traces from raw values.
filename: The filename.


def to_html(self):
    if (self.items is None):
        return
    else:
        html = ('
\n' % self.html_attributes())
        for item in self.items:
            html += ('
%s
\n' % item.to_html())
        html += '
'
        return html

Render a Text MessageElement as html

Args:
None

Returns:
Str the html representation of the Text MessageElement

Raises:
Errors are propagated


def call_rpc(self, address, rpc_id, payload=b""):

        return self.emulator.call_rpc_external(address, rpc_id, payload)

Call an RPC by its address and ID.

This will send the RPC to the background rpc dispatch thread and
synchronously wait for the response.

Args:
address (int): The address of the mock tile this RPC is for
rpc_id (int): The number of the RPC
payload (bytes): A byte string of payload parameters up to 20 bytes

Returns:
bytes: The response payload from the RPC


def getitem_column_array(self, key):

        numeric_indices = list(self.columns.get_indexer_for(key))

        def getitem(df, internal_indices=[]):
            return df.iloc[:, internal_indices]

        result = self.data.apply_func_to_select_indices(
            0, getitem, numeric_indices, keep_remaining=False
        )

        new_columns = self.columns[numeric_indices]
        new_dtypes = self.dtypes[numeric_indices]
        return self.__constructor__(result, self.index, new_columns, new_dtypes)

Get column data for target labels.

Args:
key: Target labels by which to retrieve data.

Returns:
A new QueryCompiler.


def compile_files(raw_dir, raw_files, tag):
    tf.logging.info(('Compiling files with tag %s.' % tag))
    filename = ('%s-%s' % (_PREFIX, tag))
    input_compiled_file = os.path.join(raw_dir, (filename + '.lang1'))
    target_compiled_file = os.path.join(raw_dir, (filename + '.lang2'))
    with tf.gfile.Open(input_compiled_file, mode='w') as input_writer:
        with tf.gfile.Open(target_compiled_file, mode='w') as target_writer:
            for i in range(len(raw_files['inputs'])):
                input_file = raw_files['inputs'][i]
                target_file = raw_files['targets'][i]
                tf.logging.info(('Reading files %s and %s.' % (input_file, target_file)))
                write_file(input_writer, input_file)
                write_file(target_writer, target_file)
    return (input_compiled_file, target_compiled_file)

Compile raw files into a single file for each language.

Args:
raw_dir: Directory containing downloaded raw files.
raw_files: Dict containing filenames of input and target data.
{"inputs": list of files containing data in input language
"targets": list of files containing corresponding data in target language
}
tag: String to append to the compiled filename.

Returns:
Full path of compiled input and target files.


def _represent_argument(directive_location, context, argument, inferred_type):
    argument_name = argument[1:]
    validate_safe_string(argument_name)
    if is_variable_argument(argument):
        existing_type = context['inputs'].get(argument_name, inferred_type)
        if (not inferred_type.is_same_type(existing_type)):
            raise GraphQLCompilationError(u'Incompatible types inferred for argument {}. The argument cannot simultaneously be {} and {}.'.format(argument, existing_type, inferred_type))
        context['inputs'][argument_name] = inferred_type
        return (expressions.Variable(argument, inferred_type), None)
    elif is_tag_argument(argument):
        argument_context = context['tags'].get(argument_name, None)
        if (argument_context is None):
            raise GraphQLCompilationError(u'Undeclared argument used: {}'.format(argument))
        location = argument_context['location']
        optional = argument_context['optional']
        tag_inferred_type = argument_context['type']
        if (location is None):
            raise AssertionError(u'Argument declared without location: {}'.format(argument_name))
        if (location.field is None):
            raise AssertionError(u'Argument location is not a property field: {}'.format(location))
        if (not inferred_type.is_same_type(tag_inferred_type)):
            raise GraphQLCompilationError(u'The inferred type of the matching @tag directive does not match the inferred required type for this filter: {} vs {}'.format(tag_inferred_type, inferred_type))
        field_is_local = (directive_location.at_vertex() == location.at_vertex())
        non_existence_expression = None
        if optional:
            if field_is_local:
                non_existence_expression = expressions.FalseLiteral
            else:
                non_existence_expression = expressions.BinaryComposition(u'=', expressions.ContextFieldExistence(location.at_vertex()), expressions.FalseLiteral)
        if field_is_local:
            representation = expressions.LocalField(argument_name)
        else:
            representation = expressions.ContextField(location, tag_inferred_type)
        return (representation, non_existence_expression)
    else:
        raise GraphQLCompilationError(u'Non-argument type found: {}'.format(argument))

Return a two-element tuple that represents the argument to the directive being processed.

Args:
directive_location: Location where the directive is used.
context: dict, various per-compilation data (e.g. declared tags, whether the current block
is optional, etc.). May be mutated in-place in this function!
argument: string, the name of the argument to the directive
inferred_type: GraphQL type object specifying the inferred type of the argument

Returns:
(argument_expression, non_existence_expression)
- argument_expression: an Expression object that captures the semantics of the argument
- non_existence_expression: None or Expression object;
If the current block is not optional, this is set to None. Otherwise, it is an
expression that will evaluate to True if the argument is skipped as optional and
therefore not present, and False otherwise.


def _get_example_from_basic_type(type):

        if type == 'integer':
            return [42, 24]
        elif type == 'number':
            return [5.5, 5.5]
        elif type == 'string':
            return ['string', 'string2']
        elif type == 'datetime':
            return ['2015-08-28T09:02:57.481Z', '2015-08-28T09:02:57.481Z']
        elif type == 'boolean':
            return [False, True]
        elif type == 'null':
            return ['null', 'null']

Get example from the given type.

Args:
type: the type you want an example of.

Returns:
An array with two example values of the given type.


def add_function(self, call_fn, name, match_layer_training_arg):
    fn = LayerCall(self, self._maybe_wrap_with_training_arg(call_fn, match_layer_training_arg), name, input_signature=self.fn_input_signature)
    self._functions[name] = fn.wrapped_call
    return fn

Adds a layer call function to the collection.

Args:
call_fn: a python function
name: Name of call function
match_layer_training_arg: If True, removes the `training` from the
function arguments when calling `call_fn`.

Returns:
LayerCall (tf.function)


def non_fluents_scope(self) -> Dict[(str, TensorFluent)]:
    if (self.__dict__.get('non_fluents') is None):
        self._initialize_non_fluents()
    return dict(self.non_fluents)

Returns a partial scope with non-fluents.

Returns:
A mapping from non-fluent names to :obj:`rddl2tf.fluent.TensorFluent`.


def sg_all(tensor, opt):
    r
    return tf.reduce_all(tensor, axis=opt.axis, keep_dims=opt.keep_dims, name=opt.name)

r"""Computes the "logical and" of elements across axis of a tensor.

See `tf.reduce_all()` in tensorflow.

Args:
tensor: A `Tensor` (automatically given by chain).
opt:
axis : A tuple/list of integers or an integer. The axis to reduce.
keep_dims: If true, retains reduced dimensions with length 1.
name: If provided, replace current tensor's name.

Returns:
A `Tensor`.


def _urllib_post(self, url, json='', data='', username='', password='', headers=None, timeout=30):
    if (headers is None):
        headers = {}
    raw_store = json
    raw_request = (json_lib.dumps(json) if json else urlencode(data))
    url_request = Request(url, data=raw_request.encode('utf8'))
    if json:
        url_request.add_header('Content-Type', 'application/json')
    elif (not data):
        raise ValueError('Please provide either a json or a data field.')
    headers['User-Agent'] = self.user_agent
    raw_request = raw_store
    if (username and password):
        if (sys.version_info[0] >= 3):
            basic_authstring = base64.encodebytes(('%s:%s' % (username, password)).encode()).decode().replace('\n', '')
        else:
            basic_authstring = base64.encodestring(('%s:%s' % (username, password))).replace('\n', '')
        url_request.add_header('Authorization', ('Basic %s' % basic_authstring))
    for (key, value) in headers.items():
        url_request.add_header(key, str(value))
    try:
        response = urlopen(url_request, timeout=timeout)
    except HTTPError as e:
        raw_response = e.read()
        return (raw_response, raw_request, e.getcode(), e.headers)
    else:
        raw_response = response.read()
        response.close()
        return (raw_response, raw_request, response.getcode(), dict(response.info()))

This function will POST to the url endpoint using urllib2. returning
an AdyenResult object on 200 HTTP responce. Either json or data has to
be provided. If username and password are provided, basic auth will be
used.

Args:
url (str):                  url to send the POST
json (dict, optional):      Dict of the JSON to POST
data (dict, optional):      Dict, presumed flat structure of
key/value of request to place as
www-form
username (str, optional):    Username for basic auth. Must be
uncluded as part of password.
password (str, optional):   Password for basic auth. Must be
included as part of username.
headers (dict, optional):   Key/Value pairs of headers to include
timeout (int, optional): Default 30. Timeout for the request.

Returns:
str:    Raw response received
str:    Raw request placed
int:    HTTP status code, eg 200,404,401
dict:   Key/Value pairs of the headers received.


def diff(self, other):
    similar_param = {}
    different_param = {}
    for (k1, v1) in self.items():
        if (k1 not in other):
            different_param[k1] = {'INCAR1': v1, 'INCAR2': None}
        elif (v1 != other[k1]):
            different_param[k1] = {'INCAR1': v1, 'INCAR2': other[k1]}
        else:
            similar_param[k1] = v1
    for (k2, v2) in other.items():
        if ((k2 not in similar_param) and (k2 not in different_param)):
            if (k2 not in self):
                different_param[k2] = {'INCAR1': None, 'INCAR2': v2}
    return {'Same': similar_param, 'Different': different_param}

Diff function for Incar.  Compares two Incars and indicates which
parameters are the same and which are not. Useful for checking whether
two runs were done using the same parameters.

Args:
other (Incar): The other Incar object to compare to.

Returns:
Dict of the following format:
{"Same" : parameters_that_are_the_same,
"Different": parameters_that_are_different}
Note that the parameters are return as full dictionaries of values.
E.g. {"ISIF":3}


def destination(self, bearing, distance):

        return (segment.destination(bearing, distance) for segment in self)

Calculate destination locations for given distance and bearings.

Args:
bearing (float): Bearing to move on in degrees
distance (float): Distance in kilometres

Returns:
list of list of Point: Groups of points shifted by ``distance``
and ``bearing``


def matches(self, desc):

        desc_value_type = desc.valueType or ValueType.STRING
        return (self.label_name == desc.key and
                self.value_type == desc_value_type)

Determines if a given label descriptor matches this enum instance

Args:
desc (:class:`endpoints_management.gen.servicemanagement_v1_messages.LabelDescriptor`):
the instance to test

Return:
`True` if desc is supported, otherwise `False`


def compute_metrics(self, previous):
    delta_t = self.time_difference(previous)
    delta_x = self.distance(previous)
    vel = 0
    delta_v = 0
    acc = 0
    if (delta_t != 0):
        vel = (delta_x / delta_t)
        delta_v = (vel - previous.vel)
        acc = (delta_v / delta_t)
    self.dt = delta_t
    self.dx = delta_x
    self.acc = acc
    self.vel = vel
    return self

Computes the metrics of this point

Computes and updates the dt, vel and acc attributes.

Args:
previous (:obj:`Point`): Point before
Returns:
:obj:`Point`: Self


def without_operations_touching(self, qubits: Iterable[raw_types.Qid]):
    qubits = frozenset(qubits)
    if (not self.operates_on(qubits)):
        return self
    return Moment((operation for operation in self.operations if qubits.isdisjoint(frozenset(operation.qubits))))

Returns an equal moment, but without ops on the given qubits.

Args:
qubits: Operations that touch these will be removed.

Returns:
The new moment.


def get_authorization_url(self, client_id=None, instance_id=None, redirect_uri=None, region=None, scope=None, state=None):
    client_id = (client_id or self.client_id)
    instance_id = (instance_id or self.instance_id)
    redirect_uri = (redirect_uri or self.redirect_uri)
    region = (region or self.region)
    scope = (scope or self.scope)
    state = (state or str(uuid.uuid4()))
    self.state = state
    return (Request('GET', self.auth_base_url, params={'client_id': client_id, 'instance_id': instance_id, 'redirect_uri': redirect_uri, 'region': region, 'response_type': 'code', 'scope': scope, 'state': state}).prepare().url, state)

Generate authorization URL.

Args:
client_id (str): OAuth2 client ID. Defaults to ``None``.
instance_id (str): App Instance ID. Defaults to ``None``.
redirect_uri (str): Redirect URI. Defaults to ``None``.
region (str): App Region. Defaults to ``None``.
scope (str): Permissions. Defaults to ``None``.
state (str): UUID to detect CSRF. Defaults to ``None``.

Returns:
str, str: Auth URL, state


def from_api_repr(cls, resource):

        this = cls(None)

        resource = copy.deepcopy(resource)
        for training_run in resource.get("trainingRuns", ()):
            start_time = training_run.get("startTime")
            if not start_time or "-" in start_time:
                continue
            start_time = datetime_helpers.from_microseconds(1e3 * float(start_time))
            training_run["startTime"] = datetime_helpers.to_rfc3339(start_time)

        this._proto = json_format.ParseDict(resource, types.Model())
        for key in six.itervalues(cls._PROPERTY_TO_API_FIELD):

            if key in resource:
                this._properties[key] = resource[key]
        return this

Factory: construct a model resource given its API representation

Args:
resource (Dict[str, object]):
Model resource representation from the API

Returns:
google.cloud.bigquery.model.Model: Model parsed from ``resource``.


def create_in_hdx(self):
    capacity = self.data.get('capacity')
    if (capacity is not None):
        del self.data['capacity']
    self._create_in_hdx('user', 'id', 'name')
    if (capacity is not None):
        self.data['capacity'] = capacity

Check if user exists in HDX and if so, update it, otherwise create user

Returns:
None


def execute(self, sensor_graph, scope_stack):

        parent = scope_stack[-1]

        try:
            slot = parent.resolve_identifier('current_slot', SlotIdentifier)
        except UnresolvedIdentifierError:
            raise SensorGraphSemanticError("set config statement used outside of config block")

        if self.explicit_type is None or not isinstance(self.identifier, int):
            raise SensorGraphSemanticError("Config variable type definitions are not yet supported")

        if isinstance(self.value, (bytes, bytearray)) and not self.explicit_type == 'binary':
            raise SensorGraphSemanticError("You must pass the binary variable type when using encoded binary data")

        if not isinstance(self.value, (bytes, bytearray)) and self.explicit_type == 'binary':
            raise SensorGraphSemanticError("You must pass an encoded binary value with binary type config variables")

        sensor_graph.add_config(slot, self.identifier, self.explicit_type, self.value)

Execute this statement on the sensor_graph given the current scope tree.

This adds a single config variable assignment to the current sensor graph

Args:
sensor_graph (SensorGraph): The sensor graph that we are building or
modifying
scope_stack (list(Scope)): A stack of nested scopes that may influence
how this statement allocates clocks or other stream resources.


def checkAndRaise(pageNum, itemsPerPage):

        if pageNum < 1:
            raise ErrPaginationLimits(ErrPaginationLimits.ERR_PAGE_NUM)

        if itemsPerPage < Settings.itemsPerPageMin or itemsPerPage > Settings.itemsPerPageMax:
            raise ErrPaginationLimits(ErrPaginationLimits.ERR_ITEMS_PER_PAGE)

Check and Raise an Exception if needed

Args:
pageNum (int): Page number
itemsPerPage (int): Number of items per Page

Raises:
ErrPaginationLimits: If we are out of limits


def get(self, key, default_value=__NoDefaultSpecified__):

        os_env_string = ConfigReader.ENV_PREFIX + key
        os_env_string = os_env_string.replace(".", "_")
        if type(os.getenv(os_env_string)) != NoneType:
            return os.getenv(os_env_string)

        for data_map in self._dataMaps:
            try:
                if "." in key:

                    namespaces = key.split(".")
                    temp_var = data_map
                    for name in namespaces:
                        temp_var = temp_var[name]
                    return temp_var
                else:
                    value = data_map[key]
                    return value
            except (AttributeError, TypeError, KeyError):
                pass

        if default_value == self.__NoDefaultSpecified__:
            raise KeyError(u("Key '{0}' does not exist").format(key))
        else:
            return default_value

Gets the value from the yaml config based on the key.

No type casting is performed, any type casting should be
performed by the caller.

Args:
key (str) - Config setting key.

Kwargs:
default_value - Default value to return if config is not specified.

Returns:
Returns value stored in config file.


def create_from_wkt(self, wkt, item_type, ingest_source, **attributes):
    geojson = load_wkt(wkt).__geo_interface__
    vector = {'type': 'Feature', 'geometry': geojson, 'properties': {'item_type': item_type, 'ingest_source': ingest_source, 'attributes': attributes}}
    return self.create(vector)[0]

Create a single vector in the vector service

Args:
wkt (str): wkt representation of the geometry
item_type (str): item_type of the vector
ingest_source (str): source of the vector
attributes: a set of key-value pairs of attributes

Returns:
id (str): string identifier of the vector created


def __init__(self, input_circuit: circuit.QuantumCircuit, name: Union[None, str]=None):
    super().__init__(name=name)
    input_circuit.build([])
    self._circuit = input_circuit

Initializes a generic QuantumInference layer.

Args:
input_circuit: The parameterized quantum circuit on which to do inference.
name: Identifier for this inference engine.


def load_file_to_base64_str(f_path):

    path = abs_path(f_path)
    with io.open(path, 'rb') as f:
        f_bytes = f.read()
        base64_str = base64.b64encode(f_bytes).decode("utf-8")
        return base64_str

Loads the content of a file into a base64 string.

Args:
f_path: full path to the file including the file name.

Returns:
A base64 string representing the content of the file in utf-8 encoding.


def overwrite_view_source(project, dir_path):
    project_html_location = ((dir_path / project) / HTML_LOCATION)
    if (not project_html_location.exists()):
        return
    files_to_overwrite = [f for f in project_html_location.iterdir() if ('html' in f.suffix)]
    for html_file in files_to_overwrite:
        with open(html_file, 'r') as f:
            html = f.readlines()
        for (i, l) in enumerate(html):
            if (TO_REPLACE_WITH_HOME in l):
                html[i] = NEW_HOME_LINK
                break
        with open(html_file, 'w') as f:
            f.writelines(html)

In the project's index.html built file, replace the top "source"
link with a link to the documentation's home, which is mkdoc's home

Args:
project (str): project to update
dir_path (pathlib.Path): this file's path


def draw_text(img, pos, text, color, font_scale=0.4):

    img = img.astype(np.uint8)
    x0, y0 = int(pos[0]), int(pos[1])

    font = cv2.FONT_HERSHEY_SIMPLEX
    ((text_w, text_h), _) = cv2.getTextSize(text, font, font_scale, 1)

    if x0 + text_w > img.shape[1]:
        x0 = img.shape[1] - text_w
    if y0 - int(1.15 * text_h) < 0:
        y0 = int(1.15 * text_h)
    back_topleft = x0, y0 - int(1.3 * text_h)
    back_bottomright = x0 + text_w, y0
    cv2.rectangle(img, back_topleft, back_bottomright, color, -1)

    text_bottomleft = x0, y0 - int(0.25 * text_h)
    cv2.putText(img, text, text_bottomleft, font, font_scale, (222, 222, 222), lineType=cv2.LINE_AA)
    return img

Draw text on an image.

Args:
pos (tuple): x, y; the position of the text
text (str):
font_scale (float):
color (tuple): a 3-tuple BGR color in [0, 255]


def add_value(self, line):
    if line.strip():
        self._empty = False
    if self.current_key in self.known_keys:
        self.known_keys[self.current_key].append(line)
    else:
        self.unknown_keys[self.current_key].append(line)

Adds unstructured or multi-line value output to the current parsed
instrumentation block for outputting later.

Usually, this will add extra lines to the value list for the current
key-value pair. However, sometimes, such as when instrumentation
failed to start, output does not follow the structured prefix format.
In this case, adding all of the output is still useful so that a user
can debug the issue.

Args:
line: string, the raw instrumentation line to append to the value
list.


def _ParseRecordString(
      self, record_strings_data, record_strings_data_offset, string_offset):

    if string_offset == 0:
      return None

    if string_offset & self._STRING_OFFSET_MSB:
      if (string_offset >> 60) != 8:
        raise errors.ParseError('Invalid inline record string flag.')

      string_size = (string_offset >> 56) & 0x0f
      if string_size >= 8:
        raise errors.ParseError('Invalid inline record string size.')

      string_data = bytes(bytearray([
          string_offset >> (8 * byte_index) & 0xff
          for byte_index in range(6, -1, -1)]))

      try:
        return string_data[:string_size].decode('utf-8')
      except UnicodeDecodeError as exception:
        raise errors.ParseError(
            'Unable to decode inline record string with error: {0!s}.'.format(
                exception))

    data_offset = string_offset - record_strings_data_offset
    record_string_map = self._GetDataTypeMap('asl_record_string')

    try:
      record_string = self._ReadStructureFromByteStream(
          record_strings_data[data_offset:], string_offset, record_string_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.ParseError((
          'Unable to parse record string at offset: 0x{0:08x} with error: '
          '{1!s}').format(string_offset, exception))

    return record_string.string.rstrip('\x00')

Parses a record string.

Args:
record_strings_data (bytes): record strings data.
record_strings_data_offset (int): offset of the record strings data
relative to the start of the file.
string_offset (int): offset of the string relative to the start of
the file.

Returns:
str: record string or None if string offset is 0.

Raises:
ParseError: if the record string cannot be parsed.


def fftn(x):
    out = x
    for axis in reversed(range(x.ndim)[1:]):
        out = torch.fft.fft(out, axis=axis)
    return out

Applies n-dimensional Fast Fourier Transform (FFT) to input array.

Args:
x: Input n-dimensional array.

Returns:
n-dimensional Fourier transform of input n-dimensional array.


def get_image_features(self, pixel_values: torch.FloatTensor, **kwargs):
    patch_embeddings = [self.vision_embed_tokens(patch.to(self.vision_embed_tokens.weight.dtype)).squeeze(0) for patch in pixel_values]
    return patch_embeddings

Encodes images into continuous embeddings that can be forwarded to the language model.

Args:
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
The tensors corresponding to the input images.


def DownloadReportToFile(self, report_job_id, export_format, outfile, include_report_properties=False, include_totals_row=None, use_gzip_compression=True):
    service = self._GetReportService()
    if (include_totals_row is None):
        include_totals_row = (True if (export_format != 'CSV_DUMP') else False)
    opts = {'exportFormat': export_format, 'includeReportProperties': include_report_properties, 'includeTotalsRow': include_totals_row, 'useGzipCompression': use_gzip_compression}
    report_url = service.getReportDownloadUrlWithOptions(report_job_id, opts)
    _data_downloader_logger.info('Request Summary: Report job ID: %s, %s', report_job_id, opts)
    response = self.url_opener.open(report_url)
    _data_downloader_logger.debug('Incoming response: %s %s REDACTED REPORT DATA', response.code, response.msg)
    while True:
        chunk = response.read(_CHUNK_SIZE)
        if (not chunk):
            break
        outfile.write(chunk)

Downloads report data and writes it to a file.

The report job must be completed before calling this function.

Args:
report_job_id: The ID of the report job to wait for, as a string.
export_format: The export format for the report file, as a string.
outfile: A writeable, file-like object to write to.
include_report_properties: Whether or not to include the report
properties (e.g. network, user, date generated...)
in the generated report.
include_totals_row: Whether or not to include the totals row.
use_gzip_compression: Whether or not to use gzip compression.


def show_qouts(self, nids=None, stream=sys.stdout):
    lines = []
    for task in self.iflat_tasks(status=self.S_QCRITICAL, nids=nids):
        header = (('=== ' + task.qout_file.path) + '===')
        lines.append(header)
        if task.qout_file.exists:
            with open(task.qout_file.path, 'rt') as fh:
                lines += fh.readlines()
        else:
            lines.append('File does not exist!')
        lines.append((('=' * len(header)) + (2 * '\n')))
    return stream.writelines(lines)

Write to the given stream the content of the queue output file for all tasks whose status is S_QCRITICAL.

Args:
nids: optional list of node identifiers used to filter the tasks.
stream: File-like object. Default: sys.stdout


def _should_stop(state, stopping_policy_fn):
    return tf.convert_to_tensor(stopping_policy_fn(state.finished), name='should_stop', dtype=tf.bool)

Indicates whether the overall Brent search should continue.

Args:
state: A Python `_BrentSearchState` namedtuple.
stopping_policy_fn: Python `callable` controlling the algorithm termination.

Returns:
A boolean value indicating whether the overall search should continue.


Reconnects to the server after the device was disconnected.

Instead of creating a new instance of the client:
- Uses the given port (or finds a new available host port if 0 or None is
given).
- Tries to connect to the remote server with the selected port.

Args:
port: int, if given, this is the host port from which to connect to the
remote device port. Otherwise, finds a new available port as host
port.

Raises:
errors.ServerRestoreConnectionError: when failed to restore the connection
to the snippet server.


def build_position_encoding(position_encoding_type, out_channels=None, project_pos_dim=-1, trainable_position_encoding_kwargs=None, fourier_position_encoding_kwargs=None):
    if position_encoding_type == 'trainable':
        if not trainable_position_encoding_kwargs:
            raise ValueError('Make sure to pass trainable_position_encoding_kwargs')
        output_pos_enc = PerceiverTrainablePositionEncoding(**trainable_position_encoding_kwargs)
    elif position_encoding_type == 'fourier':
        if not fourier_position_encoding_kwargs:
            raise ValueError('Make sure to pass fourier_position_encoding_kwargs')
        output_pos_enc = PerceiverFourierPositionEncoding(**fourier_position_encoding_kwargs)
    else:
        raise ValueError(f'Unknown position encoding type: {position_encoding_type}.')
    positions_projection = nn.Linear(out_channels, project_pos_dim) if project_pos_dim > 0 else nn.Identity()
    return (output_pos_enc, positions_projection)

Builds the position encoding.

Args:
- out_channels: refers to the number of channels of the position encodings.
- project_pos_dim: if specified, will project the position encodings to this dimension.


def get_nn(self, structure, n):
    return [e['site'] for e in self.get_nn_info(structure, n)]

Get near neighbors of site with index n in structure.

Args:
structure (Structure): input structure.
n (integer): index of site in structure for which to determine
neighbors.
Returns:
sites (list of Site objects): near neighbors.


def has_axis(self, axis):

		if self.type != EventType.POINTER_AXIS:
			raise AttributeError(_wrong_meth.format(self.type))
		return self._libinput.libinput_event_pointer_has_axis(
			self._handle, axis)

Check if the event has a valid value for the given axis.

If this method returns True for an axis and :meth:`get_axis_value`
returns a value of 0, the event is a scroll stop event.

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

Args:
axis (~libinput.constant.PointerAxis): The axis to check.
Returns:
bool: True if this event contains a value for this axis.
Raises:
AttributeError


def move_to_destination(source, destination, job_name, sagemaker_session):
    parsed_uri = urlparse(destination)
    if (parsed_uri.scheme == 'file'):
        recursive_copy(source, parsed_uri.path)
        final_uri = destination
    elif (parsed_uri.scheme == 's3'):
        bucket = parsed_uri.netloc
        path = ('%s%s' % (parsed_uri.path.lstrip('/'), job_name))
        final_uri = ('s3:
        sagemaker_session.upload_data(source, bucket, path)
    else:
        raise ValueError(('Invalid destination URI, must be s3:
    shutil.rmtree(source)
    return final_uri

move source to destination. Can handle uploading to S3

Args:
source (str): root directory to move
destination (str): file:// or s3:// URI that source will be moved to.
job_name (str): SageMaker job name.
sagemaker_session (sagemaker.Session): a sagemaker_session to interact with S3 if needed

Returns:
(str): destination URI


def Open(self):
    if (not self._filename):
        raise ValueError('Missing filename.')
    if os.path.isfile(self._filename):
        raise IOError('Unable to use an already existing file for output [{0:s}]'.format(self._filename))
    options = {'constant_memory': True, 'strings_to_urls': False, 'strings_to_formulas': False, 'default_date_format': self._timestamp_format}
    self._workbook = xlsxwriter.Workbook(self._filename, options)
    self._sheet = self._workbook.add_worksheet('Sheet')
    self._current_row = 0

Creates a new workbook.

Raises:
IOError: if the specified output file already exists.
OSError: if the specified output file already exists.
ValueError: if the filename is not set.


def alias_tool(self, context_name, tool_name, tool_alias):

        data = self._context(context_name)
        aliases = data["tool_aliases"]
        if tool_name in aliases:
            raise SuiteError("Tool %r in context %r is already aliased to %r"
                             % (tool_name, context_name, aliases[tool_name]))
        self._validate_tool(context_name, tool_name)
        aliases[tool_name] = tool_alias
        self._flush_tools()

Register an alias for a specific tool.

Note that a tool alias takes precedence over a context prefix/suffix.

Args:
context_name (str): Context containing the tool.
tool_name (str): Name of tool to alias.
tool_alias (str): Alias to give the tool.