def removeUserData(self, users=None):

        admin = None
        portal = None
        user = None
        adminusercontent = None
        userFolder = None
        userContent = None
        userItem = None
        folderContent = None
        try:
            admin = arcrest.manageorg.Administration(securityHandler=self._securityHandler)
            if users is None:
                print ("You have selected to remove all users data, you must modify the code to do this")
                usersObj = []
                commUsers = admin.portals.portalSelf.users(start=1, num=100)
                commUsers = commUsers['users']
                for user in commUsers:
                    usersObj.append(user.userContent)
                return
            else:
                usersObj = []
                userStr = users.split(',')
                for user in userStr:
                    try:
                        user = admin.content.users.user(str(user).strip())
                        usersObj.append(user)
                    except:
                        print ("%s does not exist" % str(user).strip())

            if usersObj:
                for user in usersObj:
                    print ("Loading content for user: %s" % user.username)

                    itemsToDel = []
                    for userItem in user.items:
                        itemsToDel.append(userItem.id)
                    if len(itemsToDel) > 0:
                        print (user.deleteItems(items=",".join(itemsToDel)))
                    if user.folders:
                        for userFolder in user.folders:
                            if (user.currentFolder['title'] != userFolder['title']):
                                user.currentFolder = userFolder['title']
                                itemsToDel = []
                                for userItem in user.items:
                                    itemsToDel.append(userItem.id)
                                if len(itemsToDel) > 0:
                                    print (user.deleteItems(items=",".join(itemsToDel)))

                                print (user.deleteFolder())

        except:
            line, filename, synerror = trace()
            raise common.ArcRestHelperError({
                        "function": "removeUserData",
                        "line": line,
                        "filename":  filename,
                        "synerror": synerror,
                                        }
                                        )
        finally:
            admin = None
            portal = None
            user = None
            adminusercontent = None
            userFolder = None
            userContent = None
            userItem = None
            folderContent = None

            del admin
            del portal
            del user
            del adminusercontent
            del userFolder
            del userContent
            del userItem
            del folderContent

            gc.collect()

Removes users' content and data.

Args:
users (str): A comma delimited list of user names.
Defaults to ``None``.

Warning:
When ``users`` is not provided (``None``), all users
in the organization will have their data deleted!


def _wait_on_metadata(self, topic, max_wait):

        self._sender.add_topic(topic)
        begin = time.time()
        elapsed = 0.0
        metadata_event = None
        while True:
            partitions = self._metadata.partitions_for_topic(topic)
            if partitions is not None:
                return partitions

            if not metadata_event:
                metadata_event = threading.Event()

            log.debug("Requesting metadata update for topic %s", topic)

            metadata_event.clear()
            future = self._metadata.request_update()
            future.add_both(lambda e, *args: e.set(), metadata_event)
            self._sender.wakeup()
            metadata_event.wait(max_wait - elapsed)
            elapsed = time.time() - begin
            if not metadata_event.is_set():
                raise Errors.KafkaTimeoutError(
                    "Failed to update metadata after %.1f secs." % (max_wait,))
            elif topic in self._metadata.unauthorized_topics:
                raise Errors.TopicAuthorizationFailedError(topic)
            else:
                log.debug("_wait_on_metadata woke after %s secs.", elapsed)

Wait for cluster metadata including partitions for the given topic to
be available.

Arguments:
topic (str): topic we want metadata for
max_wait (float): maximum time in secs for waiting on the metadata

Returns:
set: partition ids for the topic

Raises:
KafkaTimeoutError: if partitions for topic were not obtained before
specified max_wait timeout


def combo_exhaustive_label_definition_check(self, ontology: pd.DataFrame, label_predicate: str, definition_predicates: str, diff=True) -> List[List[dict]]:
    (inside, outside) = ([], [])
    header = (['Index'] + list(ontology.columns))
    for row in ontology.itertuples():
        row = {header[i]: val for (i, val) in enumerate(row)}
        label_obj = row[label_predicate]
        if isinstance(label_obj, list):
            if (len(label_obj) != 1):
                exit('Need to have only 1 label in the cell from the onotology.')
            else:
                label_obj = label_obj[0]
        entity_label = self.local_degrade(label_obj)
        label_search_results = self.label2rows.get(entity_label)
        label_ilx_rows = (label_search_results if label_search_results else [])
        definition_ilx_rows = []
        for definition_predicate in definition_predicates:
            definition_objs = row[definition_predicate]
            if (not definition_objs):
                continue
            definition_objs = ([definition_objs] if (not isinstance(definition_objs, list)) else definition_objs)
            for definition_obj in definition_objs:
                definition_obj = self.local_degrade(definition_obj)
                definition_search_results = self.definition2rows.get(definition_obj)
                if definition_search_results:
                    definition_ilx_rows.extend(definition_search_results)
        ilx_rows = [dict(t) for t in {tuple(d.items()) for d in (label_ilx_rows + definition_ilx_rows)}]
        if ilx_rows:
            inside.append({'external_ontology_row': row, 'ilx_rows': ilx_rows})
        else:
            outside.append(row)
    if diff:
        diff = self.__exhaustive_diff(inside)
        return (inside, outside, diff)
    return (inside, outside)

Combo of label & definition exhaustive check out of convenience

Args:
ontology: pandas DataFrame created from an ontology where the colnames are predicates
and if classes exist it is also thrown into a the colnames.
label_predicate: usually in qname form and is the colname of the DataFrame for the label
diff: complete exhaustive diff if between curie matches... will take FOREVER if there are a lot -> n^2
Returns:
inside: entities that are inside of InterLex
outside: entities NOT in InterLex
diff (optional): List[List[dict]]... so complicated but usefull diff between matches only


def entity_to_bulk(entities, resource_type_parent):

        if not isinstance(entities, list):
            entities = [entities]

        bulk_array = []
        for e in entities:
            bulk = {'type': e.get('type'), 'ownerName': e.get('ownerName')}
            if resource_type_parent in ['Group', 'Task', 'Victim']:
                bulk['name'] = e.get('value')
            elif resource_type_parent in ['Indicator']:
                bulk['confidence'] = e.get('confidence')
                bulk['rating'] = e.get('rating')
                bulk['summary'] = e.get('value')

            bulk_array.append(bulk)

        if len(bulk_array) == 1:
            return bulk_array[0]
        return bulk_array

Convert Single TC Entity to Bulk format.

.. Attention:: This method is subject to frequent changes

Args:
entities (dictionary): TC Entity to be converted to Bulk.
resource_type_parent (string): The resource parent type of the tc_data provided.

Returns:
(dictionary): A dictionary representing TC Bulk format.


def getSwarmModelParams(modelID):

  cjDAO = ClientJobsDAO.get()

  (jobID, description) = cjDAO.modelsGetFields(
    modelID,
    ["jobId", "genDescription"])

  (baseDescription,) = cjDAO.jobGetFields(jobID, ["genBaseDescription"])

  descriptionDirectory = tempfile.mkdtemp()
  try:
    baseDescriptionFilePath = os.path.join(descriptionDirectory, "base.py")
    with open(baseDescriptionFilePath, mode="wb") as f:
      f.write(baseDescription)

    descriptionFilePath = os.path.join(descriptionDirectory, "description.py")
    with open(descriptionFilePath, mode="wb") as f:
      f.write(description)

    expIface = helpers.getExperimentDescriptionInterfaceFromModule(
      helpers.loadExperimentDescriptionScriptFromDir(descriptionDirectory))

    return json.dumps(
      dict(
        modelConfig=expIface.getModelDescription(),
        inferenceArgs=expIface.getModelControl().get("inferenceArgs", None)))
  finally:
    shutil.rmtree(descriptionDirectory, ignore_errors=True)

Retrieve the Engine-level model params from a Swarm model

Args:
modelID - Engine-level model ID of the Swarm model

Returns:
JSON-encoded string containing Model Params


def _write_handle(self, conn, handle, ack, value, timeout=1.0):

        conn_handle = conn
        char_handle = handle

        def write_handle_acked(event):
            if event.command_class == 4 and event.command == 1:
                conn, _, char = unpack("<BHH", event.payload)

                return conn_handle == conn and char_handle == char

        data_len = len(value)
        if data_len > 20:
            return False, {'reason': 'Data too long to write'}

        payload = struct.pack("<BHB%ds" % data_len, conn_handle, char_handle, data_len, value)

        try:
            if ack:
                response = self._send_command(4, 5, payload)
            else:
                response = self._send_command(4, 6, payload)
        except InternalTimeoutError:
            return False, {'reason': 'Timeout waiting for response to command in _write_handle'}

        _, result = unpack("<BH", response.payload)
        if result != 0:
            return False, {'reason': 'Error writing to handle', 'error_code': result}

        if ack:
            events = self._wait_process_events(timeout, lambda x: False, write_handle_acked)
            if len(events) == 0:
                return False, {'reason': 'Timeout waiting for acknowledge on write'}

            _, result, _ = unpack("<BHH", events[0].payload)
            if result != 0:
                return False, {'reason': 'Error received during write to handle', 'error_code': result}

        return True, None

Write to a BLE device characteristic by its handle

Args:
conn (int): The connection handle for the device we should read from
handle (int): The characteristics handle we should read
ack (bool): Should this be an acknowledges write or unacknowledged
timeout (float): How long to wait before failing
value (bytearray): The value that we should write


def actions(self):
    if (self._actions is None):
        self._actions = list(self.iter_actions())
    return self._actions

The service's actions with their arguments.

Returns:
list(`Action`): A list of Action namedtuples, consisting of
action_name (str), in_args (list of Argument namedtuples,
consisting of name and argtype), and out_args (ditto).

The return value looks like this::
[
Action(
name='GetMute',
in_args=[
Argument(name='InstanceID', ...),
Argument(
name='Channel',
vartype='string',
list=['Master', 'LF', 'RF', 'SpeakerOnly'],
range=None
)
],
out_args=[
Argument(name='CurrentMute, ...)
]
)
Action(...)
]

Its string representation will look like this::
GetMute(InstanceID: ui4, Channel: [Master, LF, RF, SpeakerOnly]) \
-> {CurrentMute: boolean}


def get_course_enrollment(self, username, course_id):

        endpoint = getattr(
            self.client.enrollment,
            '{username},{course_id}'.format(username=username, course_id=course_id)
        )
        try:
            result = endpoint.get()
        except HttpNotFoundError:

            LOGGER.error(
                'Course enrollment details not found for invalid username or course; username=[%s], course=[%s]',
                username,
                course_id
            )
            return None

        if not result:
            LOGGER.info('Failed to find course enrollment details for user [%s] and course [%s]', username, course_id)
            return None

        return result

Query the enrollment API to get information about a single course enrollment.

Args:
username (str): The username by which the user goes on the OpenEdX platform
course_id (str): The string value of the course's unique identifier

Returns:
dict: A dictionary containing details of the enrollment, including course details, mode, username, etc.


def get(self, key):

    key = self._service_key(key)
    return self._service_ops['get'](key)

Return the object in `service` named by `key` or None.

Args:
key: Key naming the object to retrieve.

Returns:
object or None


def call(self, hidden_states: tf.Tensor, attention_mask: np.ndarray | tf.Tensor | None, layer_head_mask: tf.Tensor | None, training: Optional[bool]=False) -> tf.Tensor:
    residual = hidden_states
    hidden_states, self_attn_weights, _ = self.self_attn(hidden_states=hidden_states, attention_mask=attention_mask, layer_head_mask=layer_head_mask)
    tf.debugging.assert_equal(shape_list(hidden_states), shape_list(residual), message=f'Self attn modified the shape of query {shape_list(residual)} to {shape_list(hidden_states)}')
    hidden_states = self.dropout(hidden_states, training=training)
    hidden_states = residual + hidden_states
    hidden_states = self.self_attn_layer_norm(hidden_states)
    residual = hidden_states
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = self.activation_dropout(hidden_states, training=training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = self.dropout(hidden_states, training=training)
    hidden_states = residual + hidden_states
    hidden_states = self.final_layer_norm(hidden_states)
    return (hidden_states, self_attn_weights)

Args:
hidden_states (`tf.Tensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`tf.Tensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
layer_head_mask (`tf.Tensor`): mask for attention heads in a given layer of size
`(encoder_attention_heads,)`


def crop_margin(self, image: np.array, gray_threshold: int=200, data_format: Optional[ChannelDimension]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> np.array:
    if input_data_format is None:
        input_data_format = infer_channel_dimension_format(image)
    image = to_pil_image(image, input_data_format=input_data_format)
    data = np.array(image.convert('L')).astype(np.uint8)
    max_val = data.max()
    min_val = data.min()
    if max_val == min_val:
        image = np.array(image)
        image = to_channel_dimension_format(image, data_format, input_data_format) if data_format is not None else image
        return image
    data = (data - min_val) / (max_val - min_val) * 255
    gray = data < gray_threshold
    coords = self.python_find_non_zero(gray)
    x_min, y_min, width, height = self.python_bounding_rect(coords)
    image = image.crop((x_min, y_min, x_min + width, y_min + height))
    image = np.array(image).astype(np.uint8)
    image = to_channel_dimension_format(image, input_data_format, ChannelDimension.LAST)
    image = to_channel_dimension_format(image, data_format, input_data_format) if data_format is not None else image
    return image

Crops the margin of the image. Gray pixels are considered margin (i.e., pixels with a value below the
threshold).

Args:
image (`np.array`):
The image to be cropped.
gray_threshold (`int`, *optional*, defaults to `200`)
Value below which pixels are considered to be gray.
data_format (`ChannelDimension`, *optional*):
The channel dimension format of the output image. If unset, will use the inferred format from the
input.
input_data_format (`ChannelDimension`, *optional*):
The channel dimension format of the input image. If unset, will use the inferred format from the input.


def value(self):
    if (not self.filled):
        raise SlotNotFilledError(('Slot with name "%s", key "%s" not yet filled.' % (self.name, self.key)))
    return self._value

Returns the current value of this slot.

Returns:
The value of the slot (a serializable Python type).

Raises:
SlotNotFilledError if the value hasn't been filled yet.


def uniform_labels(self, mol1, mol2):
    obmol1 = BabelMolAdaptor(mol1).openbabel_mol
    obmol2 = BabelMolAdaptor(mol2).openbabel_mol
    h1 = self.get_molecule_hash(obmol1)
    h2 = self.get_molecule_hash(obmol2)
    if (h1 != h2):
        return (None, None)
    query = ob.CompileMoleculeQuery(obmol1)
    isomapper = ob.OBIsomorphismMapper.GetInstance(query)
    isomorph = ob.vvpairUIntUInt()
    isomapper.MapAll(obmol2, isomorph)
    sorted_isomorph = [sorted(x, key=(lambda morp: morp[0])) for x in isomorph]
    label2_list = tuple([tuple([(p[1] + 1) for p in x]) for x in sorted_isomorph])
    vmol1 = obmol1
    aligner = ob.OBAlign(True, False)
    aligner.SetRefMol(vmol1)
    least_rmsd = float('Inf')
    best_label2 = None
    label1 = list(range(1, (obmol1.NumAtoms() + 1)))
    elements1 = InchiMolAtomMapper._get_elements(vmol1, label1)
    for label2 in label2_list:
        elements2 = InchiMolAtomMapper._get_elements(obmol2, label2)
        if (elements1 != elements2):
            continue
        vmol2 = ob.OBMol()
        for i in label2:
            vmol2.AddAtom(obmol2.GetAtom(i))
        aligner.SetTargetMol(vmol2)
        aligner.Align()
        rmsd = aligner.GetRMSD()
        if (rmsd < least_rmsd):
            least_rmsd = rmsd
            best_label2 = copy.copy(label2)
    return (label1, best_label2)

Pair the geometrically equivalent atoms of the molecules.
Calculate RMSD on all possible isomorphism mappings and return mapping
with the least RMSD

Args:
mol1: First molecule. OpenBabel OBMol or pymatgen Molecule object.
mol2: Second molecule. OpenBabel OBMol or pymatgen Molecule object.

Returns:
(list1, list2) if uniform atom order is found. list1 and list2
are for mol1 and mol2, respectively. Their length equal
to the number of atoms. They represents the uniform atom order
of the two molecules. The value of each element is the original
atom index in mol1 or mol2 of the current atom in uniform atom
order.
(None, None) if unform atom is not available.


def _scale_boxes(boxes, target_sizes):
    if isinstance(target_sizes, (list, tuple)):
        image_height = torch.tensor([i[0] for i in target_sizes])
        image_width = torch.tensor([i[1] for i in target_sizes])
    elif isinstance(target_sizes, torch.Tensor):
        image_height, image_width = target_sizes.unbind(1)
    else:
        raise ValueError('`target_sizes` must be a list, tuple or torch.Tensor')
    max_size = torch.max(image_height, image_width)
    scale_factor = torch.stack([max_size, max_size, max_size, max_size], dim=1)
    scale_factor = scale_factor.unsqueeze(1).to(boxes.device)
    boxes = boxes * scale_factor
    return boxes

Scale batch of bounding boxes to the target sizes.

Args:
boxes (`torch.Tensor` of shape `(batch_size, num_boxes, 4)`):
Bounding boxes to scale. Each box is expected to be in (x1, y1, x2, y2) format.
target_sizes (`List[Tuple[int, int]]` or `torch.Tensor` of shape `(batch_size, 2)`):
Target sizes to scale the boxes to. Each target size is expected to be in (height, width) format.

Returns:
`torch.Tensor` of shape `(batch_size, num_boxes, 4)`: Scaled bounding boxes.


def tokenize(self, text: 'TextInput', **kwargs) -> List[str]:
    return super().tokenize(text, **kwargs)

Args:
text: TextInput
Simply calls PreTrainedTokenizer's method


def getlibversion():
    (status, major_v, minor_v, release, info) = _C.Hgetlibversion()
    _checkErr('getlibversion', status, 'cannot get lib version')
    return (major_v, minor_v, release, info)

Get the library version info.

Args:
no argument
Returns:
4-element tuple with the following components:
-major version number (int)
-minor version number (int)
-complete library version number (int)
-additional information (string)

C library equivalent : Hgetlibversion


def __init__(self, values=[]):

        self.values = values
        self.score = None
        self.probability = 0
        self.failed_trials = 0
        self.id = uuid.uuid4()
        self.error = None

EmployerBee object: stores individual employer bee information such
as ID, position (current values), fitness function return value,
fitness score, and probability of being chosen during the onlooker
phase

Args:
values (list): position/current values for the bee


def get_vm_extension(access_token, subscription_id, resource_group, vm_name, extension_name):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Compute/virtualMachines/', vm_name, '/extensions/', extension_name, '?api-version=', COMP_API])
    return do_get(endpoint, access_token)

Get details about a VM extension.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vm_name (str): Name of the virtual machine.
extension_name (str): VM extension name.

Returns:
HTTP response. JSON body of VM extension properties.


def readTable(self, tableName):

        lock_and_call(
            lambda: self._impl.readTable(tableName),
            self._lock
        )

Read the table corresponding to the specified name, equivalent to the
AMPL statement:

.. code-block:: ampl

read table tableName;

Args:
tableName: Name of the table to be read.


def make_value_from_datastore(self, value):
    if (value is None):
        return None
    _json = json.loads(value, cls=JsonDecoder)
    if (self.data_type == dict):
        return _json
    return self.data_type.from_json(_json)

Convert value from datastore representation.

Args:
value: datastore value.

Returns:
value to store in the model.


def empty_function(function: _evaluation.EmptyFunction, operand_result: Optional[_sql_data_types.Select], params_result: Collection[_sql_data_types.StandardSqlExpression]) -> _sql_data_types.Select:
    del params_result
    if operand_result is None:
        raise ValueError('empty() cannot be called without an operand.')
    sql_alias = 'empty_'
    sql_data_type = _sql_data_types.Boolean
    if not _fhir_path_data_types.returns_collection(function.parent_node.return_type):
        return dataclasses.replace(operand_result, select_part=operand_result.select_part.is_null(_sql_alias=sql_alias))
    else:
        return _sql_data_types.Select(select_part=_sql_data_types.RawExpression('CASE WHEN COUNT(*) = 0 THEN TRUE ELSE FALSE END', _sql_data_type=sql_data_type, _sql_alias=sql_alias), from_part=str(operand_result.to_subquery()), where_part=f'{operand_result.sql_alias} IS NOT NULL', sql_dialect=_sql_data_types.SqlDialect.SPARK)

Generates Spark SQL representing the FHIRPath empty() function.

Returns `TRUE` if the input collection is empty and `FALSE` otherwise.

This is the opposite of `_ExistsFunction`. If the operand is empty, then the
result is `TRUE`.

The returned SQL expression is a table of cardinality 1, whose value is of
`BOOL` type. By default, `_EmptyFunction` will return `FALSE` if given no
operand.

Args:
function: The FHIRPath AST `EmptyFunction` node
operand_result: The expression which is being evaluated
params_result: The parameter passed in to function

Returns:
A compiled Spark SQL expression.

Raises:
ValueError: When the function is called without an operand


def drag_and_drop(self, source_selector, destination_selector, **kwargs):

        self.info_log(
            "Drag and drop: source (%s); destination (%s)" %
            (source_selector, destination_selector)
        )

        use_javascript_dnd = kwargs.get(
            "use_javascript_dnd",
            "proxy_driver:use_javascript_dnd"
        )

        source_el = self.find(source_selector)
        destination_el = self.find(destination_selector)

        if use_javascript_dnd:
            try:
                dnd_script = [
                    "function simulate(f,c,d,e){var b,a=null;for(b in eventMatchers)if(eventMatchers[b].test(c)){a=b;break}if(!a)return!1;document.createEvent?(b=document.createEvent(a),a=='HTMLEvents'?b.initEvent(c,!0,!0):b.initMouseEvent(c,!0,!0,document.defaultView,0,d,e,d,e,!1,!1,!1,!1,0,null),f.dispatchEvent(b)):(a=document.createEventObject(),a.detail=0,a.screenX=d,a.screenY=e,a.clientX=d,a.clientY=e,a.ctrlKey=!1,a.altKey=!1,a.shiftKey=!1,a.metaKey=!1,a.button=1,f.fireEvent('on'+c,a));return!0} var eventMatchers={HTMLEvents:/^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,MouseEvents:/^(?:click|dblclick|mouse(?:down|up|over|move|out))$/};",
                    "var source = arguments[0],destination = arguments[1];",
                    "simulate(source, 'mousedown', 0, 0);",
                    "simulate(source, 'mousemove', destination.offsetLeft, destination.offsetTop);",
                    "simulate(source, 'mouseup', destination.offsetLeft, destination.offsetTop);"
                ]
                self._driver.execute_script(
                    '\n'.join(dnd_script),
                    source_el._element,
                    destination_el._element
                )

            except Exception as e:
                self.error_log(u'drag_and_drop exception: %s' % str(e))
                raise
        else:
            try:
                ActionChains(self._driver).drag_and_drop(
                    source_el,
                    destination_el
                ).perform()
            except Exception as e:
                self.error_log(u'drag_and_drop exception: %s' % str(e))
                raise

Drag and drop

Args:
source_selector: (str)
destination_selector: (str)

Kwargs:
use_javascript_dnd: bool; default:
config proxy_driver:use_javascript_dnd


def _CreateMethod(self, method_name):

    soap_service_method = getattr(self.suds_client.service, method_name)

    def MakeSoapRequest(*args):

      AddToUtilityRegistry('suds')
      self.SetHeaders(
          self._header_handler.GetSOAPHeaders(self.CreateSoapElementForType),
          self._header_handler.GetHTTPHeaders())

      try:
        return soap_service_method(
            *[_PackForSuds(arg, self.suds_client.factory,
                           self._packer) for arg in args])
      except suds.WebFault as e:
        if _logger.isEnabledFor(logging.WARNING):
          _logger.warning('Response summary - %s',
                          _ExtractResponseSummaryFields(e.document))

        _logger.debug('SOAP response:\n%s', e.document.str())

        if not hasattr(e.fault, 'detail'):
          exc = (googleads.errors.
                 GoogleAdsServerFault(e.document, message=e.fault.faultstring))
          raise exc

        fault = e.fault.detail.ApiExceptionFault
        if not hasattr(fault, 'errors') or fault.errors is None:
          exc = (googleads.errors.
                 GoogleAdsServerFault(e.document, message=e.fault.faultstring))
          raise exc

        obj = fault.errors
        if not isinstance(obj, list):
          fault.errors = [obj]

        exc = googleads.errors.GoogleAdsServerFault(e.document, fault.errors,
                                                    message=e.fault.faultstring)
        raise exc

    return MakeSoapRequest

Create a method wrapping an invocation to the SOAP service.

Args:
method_name: A string identifying the name of the SOAP method to call.

Returns:
A callable that can be used to make the desired SOAP request.


def get_phenotype(self, individual_id):

        phenotype = 0
        if individual_id in self.individuals:
            phenotype = self.individuals[individual_id].phenotype

        return phenotype

Return the phenotype of an individual

If individual does not exist return 0

Arguments:
individual_id (str): Represents the individual id

Returns:
int : Integer that represents the phenotype


def getModelSummaryAsWkt(self, session, withStreamNetwork=True, withNodes=False):

        watershedMaskCard = self.getCard('WATERSHED_MASK')
        maskFilename = watershedMaskCard.value
        maskExtension = maskFilename.strip('"').split('.')[1]

        maskMap = session.query(RasterMapFile).\
                          filter(RasterMapFile.projectFile == self).\
                          filter(RasterMapFile.fileExtension == maskExtension).\
                          one()

        statement = .format('raster', maskMap.tableName, maskMap.id)

        result = session.execute(statement)

        maskMapTextPolygon = ''
        for row in result:
            maskMapTextPolygon = row.polygon

        wktString = 'GEOMCOLLECTION ({0})'.format(maskMapTextPolygon)

        if withStreamNetwork:

            channelInputFile = self.channelInputFile

            if channelInputFile is not None:

                wktStreamNetwork = channelInputFile.getStreamNetworkAsWkt(session=session, withNodes=withNodes)

                wktStreamNetwork = wktStreamNetwork.replace('GEOMCOLLECTION (', '')

                wktString = 'GEOMCOLLECTION ({0}, {1}'.format(maskMapTextPolygon, wktStreamNetwork)

        return wktString

Retrieve a Well Known Text representation of the model. Includes polygonized mask map and vector stream network.

Args:
session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session object bound to PostGIS enabled database
withStreamNetwork (bool, optional): Include stream network. Defaults to True.
withNodes (bool, optional): Include nodes. Defaults to False.

Returns:
str: Well Known Text string


def heightmap_add_voronoi(hm: np.ndarray, nbPoints: Any, nbCoef: int, coef: Sequence[float], rnd: Optional[tcod.random.Random]=None) -> None:
    nbPoints = len(coef)
    ccoef = ffi.new('float[]', coef)
    lib.TCOD_heightmap_add_voronoi(_heightmap_cdata(hm), nbPoints, nbCoef, ccoef, (rnd.random_c if rnd else ffi.NULL))

Add values from a Voronoi diagram to the heightmap.

Args:
hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
nbPoints (Any): Number of Voronoi sites.
nbCoef (int): The diagram value is calculated from the nbCoef
closest sites.
coef (Sequence[float]): The distance to each site is scaled by the
corresponding coef.
Closest site : coef[0],
second closest site : coef[1], ...
rnd (Optional[Random]): A Random instance, or None.


def nearest_neighbor(x, tSet):

    assert isinstance(x, tuple) and isinstance(tSet, dict)
    current_key = ()
    min_d = float('inf')
    for key in tSet:
        d = distance(x, key)
        if d < min_d:
            min_d = d
            current_key = key
    return tSet[current_key]

[summary]
Implements the nearest neighbor algorithm

Arguments:
x {[tupel]} -- [vector]
tSet {[dict]} -- [training set]

Returns:
[type] -- [result of the AND-function]


def __init__(self):

        super(JLinkDataEvent, self).__init__()
        self.SizeOfStruct = ctypes.sizeof(self)
        self.Type = enums.JLinkEventTypes.BREAKPOINT

Initializes the ``JLinkDataEvent`` instance.

Sets the size of the structure.

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

Returns:
``None``


def write(grp, out_path):

    with open(out_path, "w") as f:
        for x in grp:
            f.write(str(x) + "\n")

Write a GRP to a text file.

Args:
grp (list): GRP object to write to new-line delimited text file
out_path (string): output path

Returns:
None


def partial_derivative(self, X, y=0):

        self.check_fit()

        U, V = self.split_matrix(X)

        if self.theta == 0:
            return V

        else:
            A = np.power(V, -self.theta - 1)
            B = np.power(V, -self.theta) + np.power(U, -self.theta) - 1
            h = np.power(B, (-1 - self.theta) / self.theta)
            return np.multiply(A, h) - y

Compute partial derivative :math:`C(u|v)` of cumulative distribution.

Args:
X: `np.ndarray`
y: `float`

Returns:
np.ndarray: Derivatives


def _restore_path(table):

    name = None
    splited = table.split('___')
    path = splited[0]
    if len(splited) == 2:
        name = splited[1]
    path = path.replace('__', os.path.sep)
    path += '.csv'
    return path, name

Restore resource's path and name from storage's table.

Args:
table (str): table name

Returns:
(str, str): resource path and name


def circuit_to_dag(circuit):

    dagcircuit = DAGCircuit()
    dagcircuit.name = circuit.name
    for register in circuit.qregs:
        dagcircuit.add_qreg(register)
    for register in circuit.cregs:
        dagcircuit.add_creg(register)

    for instruction, qargs, cargs in circuit.data:

        if instruction.control is None:
            control = None
        else:
            control = (instruction.control[0], instruction.control[1])

        dagcircuit.apply_operation_back(instruction.copy(),
                                        qargs, cargs, control)

    return dagcircuit

Build a ``DAGCircuit`` object from a ``QuantumCircuit``.

Args:
circuit (QuantumCircuit): the input circuit.

Return:
DAGCircuit: the DAG representing the input circuit.


def send_message(contacts, message):
    if (type(contacts) == str):
        contacts = [contacts]
    recipients = list(set(contacts))
    send_notification(subsystem='UNKNOWN', recipients=[NotificationContact('slack', x) for x in recipients], subject=None, body_html=message, body_text=message)

List of contacts the send the message to. You can send messages either to channels and private groups by
using the following formats

#channel-name
@username-direct-message

If the channel is the name of a private group / channel, you must first invite the bot to the channel to ensure
it is allowed to send messages to the group.

Returns true if the message was sent, else `False`

Args:
contacts (:obj:`list` of `str`,`str`): List of contacts
message (str): Message to send

Returns:
`bool`


def call(self, hidden_states: tf.Tensor, attention_mask: tf.Tensor, output_attentions: Optional[bool]=False, training: Optional[bool]=None) -> Tuple[tf.Tensor]:
    residual = hidden_states
    hidden_states = self.layer_norm1(hidden_states)
    hidden_states, attn_weights = self.self_attn(hidden_states=hidden_states, head_mask=attention_mask, output_attentions=output_attentions, training=training)
    hidden_states = hidden_states + residual
    residual = hidden_states
    hidden_states = self.layer_norm2(hidden_states)
    hidden_states = self.mlp(hidden_states)
    hidden_states = hidden_states + residual
    outputs = (hidden_states,)
    if output_attentions:
        outputs += (attn_weights,)
    return outputs

Args:
hidden_states (`tf.Tensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`tf.Tensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
`(config.encoder_attention_heads,)`.
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.


def _rot90_3D(image, k, name_scope):

    def _rot90():
        return array_ops.transpose(array_ops.reverse_v2(image, [1]), [1, 0, 2])

    def _rot180():
        return array_ops.reverse_v2(image, [0, 1])

    def _rot270():
        return array_ops.reverse_v2(array_ops.transpose(image, [1, 0, 2]), [1])
    cases = [(math_ops.equal(k, 1), _rot90), (math_ops.equal(k, 2), _rot180), (math_ops.equal(k, 3), _rot270)]
    result = control_flow_case.case(cases, default=lambda: image, exclusive=True, name=name_scope)
    result.set_shape([None, None, image.get_shape()[2]])
    return result

Rotate image counter-clockwise by 90 degrees `k` times.

Args:
image: 3-D Tensor of shape `[height, width, channels]`.
k: A scalar integer. The number of times the image is rotated by 90 degrees.
name_scope: A valid TensorFlow name scope.

Returns:
A 3-D tensor of the same type and shape as `image`.


def put(self, item: T, context: PipelineContext=None) -> None:
    LOGGER.info('Converting item "{item}" for sink "{sink}"'.format(item=item, sink=self._sink))
    item = self._transform(data=item, context=context)
    LOGGER.info('Puting item "{item}" into sink "{sink}"'.format(item=item, sink=self._sink))
    self._sink.put(self._store_type, item, context)

Puts an objects into the data sink. The objects may be transformed into a new type for insertion if necessary.

Args:
item: The objects to be inserted into the data sink.
context: The context of the insertion (mutable).


def RunOnce(self, token=None, force=False, names=None):

    names = names or self.ListJobs(token=token)
    urns = [self.CRON_JOBS_PATH.Add(name) for name in names]

    for cron_job_urn in urns:
      try:
        with aff4.FACTORY.OpenWithLock(
            cron_job_urn, blocking=False, token=token,
            lease_time=600) as cron_job:
          try:
            logging.info("Running cron job: %s", cron_job.urn)
            cron_job.Run(force=force)
          except Exception as e:
            logging.exception("Error processing cron job %s: %s", cron_job.urn,
                              e)
            stats_collector_instance.Get().IncrementCounter(
                "cron_internal_error")

      except aff4.LockError:
        pass

Tries to lock and run cron jobs.

Args:
token: security token
force: If True, force a run
names: List of job names to run.  If unset, run them all


def get_managed_ports(self, id_or_uri, port_id_or_uri=''):
    if port_id_or_uri:
        uri = self._client.build_uri(port_id_or_uri)
        if ('/managedPorts' not in uri):
            uri = (((self._client.build_uri(id_or_uri) + '/managedPorts') + '/') + port_id_or_uri)
    else:
        uri = (self._client.build_uri(id_or_uri) + '/managedPorts')
    return self._client.get_collection(uri)

Gets all ports or a specific managed target port for the specified storage system.

Args:
id_or_uri: Can be either the storage system id or the storage system uri.
port_id_or_uri: Can be either the port id or the port uri.

Returns:
dict: Managed ports.


def add_api_key(key, value):

    if key is None or key == "":
        logger.error("Key cannot be empty")

    if value is None or value == "":
        logger.error("Value cannot be empty")

    from .. import datatools
    data = datatools.get_data()

    if "keys" not in data["discord"]:
        data["discord"]["keys"] = {}

    is_key_new = False
    if key not in data["discord"]["keys"]:
        is_key_new = True
    elif data["discord"]["keys"][key] == value:
        logger.info("API key '{}' already has value '{}'".format(key, value))
        return

    data["discord"]["keys"][key] = value
    datatools.write_data(data)

    key_text = "added" if is_key_new else "updated"
    logger.info("API key '{}' {} with value '{}'".format(key, key_text, value))

Adds a key to the bot's data

Args:
key: The name of the key to add
value: The value for the key


def AddWarning(self, warning):

    self._RaiseIfNotWritable()

    warning = self._PrepareAttributeContainer(warning)

    self._warnings.append(warning)
    self.number_of_warnings += 1

Adds a warnings.

Args:
warning (ExtractionWarning): warning.

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


def safe_round(self, x):

        val = x[self.col_name]

        if np.isposinf(val):
            val = sys.maxsize

        elif np.isneginf(val):
            val = -sys.maxsize

        if np.isnan(val):
            val = self.default_val

        if self.subtype == 'integer':
            return int(round(val))

        return val

Returns a converter that takes in a value and turns it into an integer, if necessary.

Args:
col_name(str): Name of the column.
subtype(str): Numeric subtype of the values.

Returns:
function


def run_commands(commands, settings):
    sprint = settings['sprint']
    quiet = settings['quiet']
    error = settings['error']
    enhanced_errors = True
    the_shell = None
    if settings['no_enhanced_errors']:
        enhanced_errors = False
    if ('shell' in settings):
        the_shell = settings['shell']
    windows_p = (sys.platform == 'win32')
    STDOUT = None
    STDERR = None
    if quiet:
        STDOUT = PIPE
        STDERR = PIPE
    commands = commands.rstrip()
    sprint("About to run commands '{}'".format(commands), level='verbose')
    if (not quiet):
        sprint(commands)
    if the_shell:
        tmp = shlex.split(the_shell)
        the_shell = tmp[0]
        tmp = tmp[1:]
        if (enhanced_errors and (not windows_p)):
            tmp.append('-e')
        tmp.append(commands)
        commands = tmp
    elif (enhanced_errors and (not windows_p)):
        commands = ['-e', commands]
    p = Popen(commands, shell=True, stdout=STDOUT, stderr=STDERR, executable=the_shell)
    (out, err) = p.communicate()
    if p.returncode:
        if quiet:
            error(err.decode(locale.getpreferredencoding()))
        error('Command failed to run')
        sys.exit(1)

Runs the commands supplied as an argument
It will exit the program if the commands return a
non-zero code

Args:
the commands to run
The settings dictionary


def configure(access_key=None, secret_key=None, logger=None):
    if (not logger):
        logger = log.get_logger('s3')
    if (not all([access_key, secret_key])):
        logger.info('')
        access_key = input('AWS Access Key: ')
        secret_key = input('AWS Secret Key: ')
    _write_config(access_key, secret_key)
    logger.info('')
    logger.info('Completed writing S3 config file.')
    logger.info('')

Configures s3cmd prior to first use.

If no arguments are provided, you will be prompted to enter
the access key and secret key interactively.

Args:

access_key (str): AWS access key

secret_key (str): AWS secret key


def update_version_in_file(fname: str, version: str, file_type: str):
    with open(fname, 'r', encoding='utf-8', newline='\n') as f:
        code = f.read()
    re_pattern, replace = REPLACE_PATTERNS[file_type]
    replace = replace.replace('VERSION', version)
    code = re_pattern.sub(replace, code)
    with open(fname, 'w', encoding='utf-8', newline='\n') as f:
        f.write(code)

Update the version of Transformers in one file.

Args:
fname (`str`): The path to the file where we want to update the version.
version (`str`): The new version to set in the file.
file_type (`str`): The type of the file (should be a key in `REPLACE_PATTERNS`).


def join(self, base_url, *paths):
    server, basepath = self._parse_url(base_url)
    return _HDFS_PREFIX + self._join(server, basepath, *paths)

Join two or more pathname components.

Args:
base_url: string path of the first component of the path.
Must start with hdfs://.
paths: path components to be added

Returns:
Full url after combining all the passed components.


def _validate_type(self, properties_spec, value):
    if ('type' not in properties_spec.keys()):
        def_name = self.get_definition_name_from_ref(properties_spec['$ref'])
        return self.validate_definition(def_name, value)
    elif (properties_spec['type'] == 'array'):
        if (not isinstance(value, list)):
            return False
        if (('type' in properties_spec['items'].keys()) and any(((not self.check_type(item, properties_spec['items']['type'])) for item in value))):
            return False
        elif ('$ref' in properties_spec['items'].keys()):
            def_name = self.get_definition_name_from_ref(properties_spec['items']['$ref'])
            if any(((not self.validate_definition(def_name, item)) for item in value)):
                return False
    elif (not self.check_type(value, properties_spec['type'])):
        return False
    return True

Validate the given value with the given property spec.

Args:
properties_dict: specification of the property to check (From definition not route).
value: value to check.

Returns:
True if the value is valid for the given spec.


def write_int32(self, value, little_endian=True):

        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.pack('%si' % endian, value)

Pack the value as a signed integer and write 4 bytes to the stream.

Args:
value:
little_endian (bool): specify the endianness. (Default) Little endian.

Returns:
int: the number of bytes written.


def load(self):
    if (self._leaser is None):
        return 0
    return max([(self._leaser.message_count / self._flow_control.max_messages), (self._leaser.bytes / self._flow_control.max_bytes)])

Return the current load.

The load is represented as a float, where 1.0 represents having
hit one of the flow control limits, and values between 0.0 and 1.0
represent how close we are to them. (0.5 means we have exactly half
of what the flow control setting allows, for example.)

There are (currently) two flow control settings; this property
computes how close the manager is to each of them, and returns
whichever value is higher. (It does not matter that we have lots of
running room on setting A if setting B is over.)

Returns:
float: The load value.


def get_cached_data(self, url):

        key = self.get_key_from_url(url)

        with self.conn as conn:
            cursor = conn.cursor()
            cursor.execute("SELECT * FROM ensembl WHERE key=? AND genome_build=?",
                (key, self.genome_build))
        row = cursor.fetchone()

        if row is not None:
            api_version = row["api_version"]
            data = zlib.decompress(row["data"])
            if IS_PYTHON3:
                data = data.decode("utf-8")

            date = datetime.strptime(row["cache_date"], "%Y-%m-%d")
            diff = self.today - date

            if diff.days < 180 and self.api_version == api_version:
                return data

        return None

get cached data for a url if stored in the cache and not outdated

Args:
url: URL for the Ensembl REST service

Returns:
data if data in cache, else None


def tokens(cls, tokens):

        return cls(Lnk.TOKENS, tuple(map(int, tokens)))

Create a Lnk object for a token range.

Args:
tokens: a list of token identifiers


def accept(self):
    accept = self.headers.get('Accept')
    if ((not accept) or (accept == _content_types.ANY)):
        return self._default_accept
    else:
        return accept

The content-type for the response to the client.

Returns:
(str): The value of the header 'Accept' or the user-supplied SAGEMAKER_DEFAULT_INVOCATIONS_ACCEPT
environment variable.


Simulate initiating an interaction event.

This method should initiate an interaction from |context.source| directed to
|context.target|. Examples include sending a message over a TCP connection
or invoking an API call.

Args:
context: Context of this event.
context.source: Source role for this event. Use the attributes of
the source role to initiate the simulated interaction.
context.target: Target role for this event. Use the attributes of
the target role to direct the event to the appropriate place.
*args: Additional arguments required for the event. These arguments are
passed as an event invocation within the STL.

Returns:
True if the event was fired successfully.


def response_headers():

    headers = MultiDict(request.args.items(multi=True))
    response = jsonify(list(headers.lists()))

    while True:
        original_data = response.data
        d = {}
        for key in response.headers.keys():
            value = response.headers.get_all(key)
            if len(value) == 1:
                value = value[0]
            d[key] = value
        response = jsonify(d)
        for key, value in headers.items(multi=True):
            response.headers.add(key, value)
        response_has_changed = response.data != original_data
        if not response_has_changed:
            break
    return response

Returns a set of response headers from the query string.
---
tags:
- Response inspection
parameters:
- in: query
name: freeform
explode: true
allowEmptyValue: true
schema:
type: object
additionalProperties:
type: string
style: form
produces:
- application/json
responses:
200:
description: Response headers


def from_overlays(overlays):
    jc = JobConfig()
    jc.comment = overlays.get('comment')
    if ('jobConfigOverlays' in overlays):
        if (len(overlays['jobConfigOverlays']) >= 1):
            jco = copy.deepcopy(overlays['jobConfigOverlays'][0])
            if ('jobConfig' in jco):
                _jc = jco['jobConfig']
                jc.job_name = _jc.pop('jobName', None)
                jc.job_group = _jc.pop('jobGroup', None)
                jc.preload = _jc.pop('preloadApplicationBundles', False)
                jc.data_directory = _jc.pop('dataDirectory', None)
                jc.tracing = _jc.pop('tracing', None)
                for sp in _jc.pop('submissionParameters', []):
                    jc.submission_parameters[sp['name']] = sp['value']
                if (not _jc):
                    del jco['jobConfig']
            if ('deploymentConfig' in jco):
                _dc = jco['deploymentConfig']
                if ('manual' == _dc.get('fusionScheme')):
                    if ('fusionTargetPeCount' in _dc):
                        jc.target_pe_count = _dc.pop('fusionTargetPeCount')
                    if (len(_dc) == 1):
                        del jco['deploymentConfig']
            if jco:
                jc.raw_overlay = jco
    return jc

Create a `JobConfig` instance from a full job configuration
overlays object.

All logical items, such as ``comment`` and ``job_name``, are
extracted from `overlays`. The remaining information in the
single job config overlay in ``overlays`` is set as ``raw_overlay``.

Args:
overlays(dict): Full job configuration overlays object.

Returns:
JobConfig: Instance representing logical view of `overlays`.

.. versionadded:: 1.9


def _full_reduce(self, axis, map_func, reduce_func=None):
    if (reduce_func is None):
        reduce_func = map_func
    mapped_parts = self.data.map_across_blocks(map_func)
    full_frame = mapped_parts.map_across_full_axis(axis, reduce_func)
    if (axis == 0):
        columns = self.columns
        return self.__constructor__(full_frame, index=['__reduced__'], columns=columns)
    else:
        index = self.index
        return self.__constructor__(full_frame, index=index, columns=['__reduced__'])

Apply function that will reduce the data to a Pandas Series.

Args:
axis: 0 for columns and 1 for rows. Default is 0.
map_func: Callable function to map the dataframe.
reduce_func: Callable function to reduce the dataframe. If none,
then apply map_func twice.

Return:
A new QueryCompiler object containing the results from map_func and
reduce_func.


def get_stable_entry_at_u(self, miller_index, delu_dict=None, delu_default=0, no_doped=False, no_clean=False):
    all_delu_dict = self.set_all_variables(delu_dict, delu_default)

    def get_coeffs(e):
        coeffs = []
        for du in all_delu_dict.keys():
            if (type(self.as_coeffs_dict[e]).__name__ == 'float'):
                coeffs.append(self.as_coeffs_dict[e])
            elif (du in self.as_coeffs_dict[e].keys()):
                coeffs.append(self.as_coeffs_dict[e][du])
            else:
                coeffs.append(0)
        return np.array(coeffs)
    (all_entries, all_coeffs) = ([], [])
    for entry in self.all_slab_entries[miller_index].keys():
        if (not no_clean):
            all_entries.append(entry)
            all_coeffs.append(get_coeffs(entry))
        if (not no_doped):
            for ads_entry in self.all_slab_entries[miller_index][entry]:
                all_entries.append(ads_entry)
                all_coeffs.append(get_coeffs(ads_entry))
    du_vals = np.array(list(all_delu_dict.values()))
    all_gamma = list(np.dot(all_coeffs, du_vals.T))
    return (all_entries[all_gamma.index(min(all_gamma))], float(min(all_gamma)))

Returns the entry corresponding to the most stable slab for a particular
facet at a specific chempot. We assume that surface energy is constant
so all free variables must be set with delu_dict, otherwise they are
assumed to be equal to delu_default.

Args:
miller_index ((h,k,l)): The facet to find the most stable slab in
delu_dict (Dict): Dictionary of the chemical potentials to be set as
constant. Note the key should be a sympy Symbol object of the
format: Symbol("delu_el") where el is the name of the element.
delu_default (float): Default value for all unset chemical potentials
no_doped (bool): Consider stability of clean slabs only.
no_clean (bool): Consider stability of doped slabs only.

Returns:
SlabEntry, surface_energy (float)


def _make_cluster_device_filters(self):
    self._cluster_device_filters = device_filters_pb2.ClusterDeviceFilters()
    for job_name, tasks in sorted(self._device_filters.items()):
        try:
            job_name = compat.as_bytes(job_name)
        except TypeError:
            raise TypeError('Job name %r must be bytes or unicode' % job_name)
        jdf = self._cluster_device_filters.jobs.add()
        jdf.name = job_name
        for i, task_device_filters in sorted(tasks.items()):
            for tdf in task_device_filters:
                try:
                    tdf = compat.as_bytes(tdf)
                except TypeError:
                    raise TypeError('Device filter %r must be bytes or unicode' % tdf)
                jdf.tasks[i].device_filters.append(tdf)

Creates `ClusterDeviceFilters` proto based on the `_device_filters`.

Raises:
TypeError: If `_device_filters` is not a dictionary mapping strings to
a map of task indices and device filters.


def _get_all_set_properties(self):
    return set((property_name for property_name in worker_mapping().keys() if (getattr(self, property_name) is not None)))

Collect names of set properties.

Returns:
set: Set containing names of all properties, which are set to \
non-None value.


def ValidateSyntax(rdf_artifact):

  if not rdf_artifact.doc:
    raise rdf_artifacts.ArtifactSyntaxError(rdf_artifact, "missing doc")

  for supp_os in rdf_artifact.supported_os:
    valid_os = rdf_artifact.SUPPORTED_OS_LIST
    if supp_os not in valid_os:
      detail = "invalid `supported_os` ('%s' not in %s)" % (supp_os, valid_os)
      raise rdf_artifacts.ArtifactSyntaxError(rdf_artifact, detail)

  for condition in rdf_artifact.conditions:

    try:
      of = objectfilter.Parser(condition).Parse()
      of.Compile(objectfilter.BaseFilterImplementation)
    except rdf_artifacts.ConditionError as e:
      detail = "invalid condition '%s'" % condition
      raise rdf_artifacts.ArtifactSyntaxError(rdf_artifact, detail, e)

  for label in rdf_artifact.labels:
    if label not in rdf_artifact.ARTIFACT_LABELS:
      raise rdf_artifacts.ArtifactSyntaxError(rdf_artifact,
                                              "invalid label '%s'" % label)

  valid_provides = rdf_client.KnowledgeBase().GetKbFieldNames()
  for kb_var in rdf_artifact.provides:
    if kb_var not in valid_provides:
      detail = "broken `provides` ('%s' not in %s)" % (kb_var, valid_provides)
      raise rdf_artifacts.ArtifactSyntaxError(rdf_artifact, detail)

  for dep in GetArtifactPathDependencies(rdf_artifact):
    if dep not in valid_provides:
      detail = "broken path dependencies ('%s' not in %s)" % (dep,
                                                              valid_provides)
      raise rdf_artifacts.ArtifactSyntaxError(rdf_artifact, detail)

  for source in rdf_artifact.sources:
    try:
      source.Validate()
    except rdf_artifacts.ArtifactSourceSyntaxError as e:
      raise rdf_artifacts.ArtifactSyntaxError(rdf_artifact, "bad source", e)

Validates artifact syntax.

This method can be used to validate individual artifacts as they are loaded,
without needing all artifacts to be loaded first, as for Validate().

Args:
rdf_artifact: RDF object artifact.

Raises:
ArtifactSyntaxError: If artifact syntax is invalid.


def convert_old_publication_info_to_new(publication_infos):
    result = []
    hidden_publication_infos = []
    for publication_info in publication_infos:
        _publication_info = copy.deepcopy(publication_info)
        journal_title = _publication_info.get('journal_title')
        try:
            journal_title = _JOURNALS_RENAMED_OLD_TO_NEW[journal_title]
            _publication_info['journal_title'] = journal_title
            result.append(_publication_info)
            continue
        except KeyError:
            pass
        journal_volume = _publication_info.get('journal_volume')
        if ((journal_title in _JOURNALS_WITH_YEAR_ADDED_TO_VOLUME) and journal_volume and (len(journal_volume) == 4)):
            try:
                was_last_century = (int(journal_volume[:2]) > 50)
            except ValueError:
                pass
            else:
                _publication_info['year'] = int((('19' + journal_volume[:2]) if was_last_century else ('20' + journal_volume[:2])))
                _publication_info['journal_volume'] = journal_volume[2:]
            result.append(_publication_info)
            continue
        if (journal_title and journal_volume and (journal_title.lower() not in JOURNALS_IGNORED_IN_OLD_TO_NEW)):
            volume_starts_with_a_letter = _RE_VOLUME_STARTS_WITH_A_LETTER.match(journal_volume)
            volume_ends_with_a_letter = _RE_VOLUME_ENDS_WITH_A_LETTER.match(journal_volume)
            match = (volume_starts_with_a_letter or volume_ends_with_a_letter)
            if match:
                _publication_info.pop('journal_record', None)
                if (journal_title in _JOURNALS_RENAMED_OLD_TO_NEW.values()):
                    _publication_info['journal_title'] = journal_title
                else:
                    _publication_info['journal_title'] = ''.join([journal_title, ('' if journal_title.endswith('.') else ' '), match.group('letter')])
                _publication_info['journal_volume'] = match.group('volume')
        hidden = _publication_info.pop('hidden', None)
        if hidden:
            hidden_publication_infos.append(_publication_info)
        else:
            result.append(_publication_info)
    for publication_info in hidden_publication_infos:
        if (publication_info not in result):
            publication_info['hidden'] = True
            result.append(publication_info)
    return result

Convert a ``publication_info`` value from the old format to the new.

On Legacy different series of the same journal were modeled by adding the
letter part of the name to the journal volume. For example, a paper published
in Physical Review D contained::

{
'publication_info': [
{
'journal_title': 'Phys.Rev.',
'journal_volume': 'D43',
},
],
}

On Labs we instead represent each series with a different journal record. As
a consequence, the above example becomes::

{
'publication_info': [
{
'journal_title': 'Phys.Rev.D',
'journal_volume': '43',
},
],
}

This function handles this translation from the old format to the new. Please
also see the tests for various edge cases that this function also handles.

Args:
publication_infos: a ``publication_info`` in the old format.

Returns:
list(dict): a ``publication_info`` in the new format.


def find_examples(root_dir: str, subdirs: List[str], sdk: SdkEnum) -> List[Example]:
    has_errors = False
    examples = []
    _check_no_nested(subdirs)
    for subdir in subdirs:
        subdir = os.path.join(root_dir, subdir)
        logging.info('subdir: %s', subdir)
        for root, _, files in os.walk(subdir):
            for filename in files:
                filepath = os.path.join(root, filename)
                try:
                    try:
                        example = _load_example(filename=filename, filepath=filepath, sdk=sdk)
                        if example is not None:
                            examples.append(example)
                    except pydantic.ValidationError as err:
                        if len(err.errors()) > 1:
                            raise
                        if err.errors()[0]['msg'] == 'multifile is True but no files defined':
                            logging.warning('incomplete multifile example ignored %s', filepath)
                            continue
                        raise
                except Exception:
                    logging.exception('error loading example at %s', filepath)
                    has_errors = True
    if has_errors:
        raise ValueError('Some of the beam examples contain beam playground tag with an incorrect format')
    return examples

Find and return beam examples.

Search throws all child files of work_dir directory files with beam tag:
Beam-playground:
name: NameOfExample
description: Description of NameOfExample.
multifile: false
default_example: false
context_line: 10
categories:
- category-1
- category-2
pipeline_options: --inputFile your_file --outputFile your_output_file
complexity: MEDIUM
tags:
- example
If some example contains beam tag with incorrect format raise an error.

Args:
root_dir: project root dir
subdirs: sub-directories where to search examples.
sdk: sdk that using to find examples for the specific sdk.

Returns:
List of Examples.


def set_size(self, width, height):

        if width is not None:
            try:
                width = to_pix(int(width))
            except ValueError:

                pass
            self.style['width'] = width

        if height is not None:
            try:
                height = to_pix(int(height))
            except ValueError:

                pass
            self.style['height'] = height

Set the widget size.

Args:
width (int or str): An optional width for the widget (es. width=10 or width='10px' or width='10%').
height (int or str): An optional height for the widget (es. height=10 or height='10px' or height='10%').


def occurs_in_type(v, type2):

    pruned_type2 = prune(type2)
    if pruned_type2 == v:
        return True
    elif isinstance(pruned_type2, TypeOperator):
        return occurs_in(v, pruned_type2.types)
    return False

Checks whether a type variable occurs in a type expression.

Note: Must be called with v pre-pruned

Args:
v:  The TypeVariable to be tested for
type2: The type in which to search

Returns:
True if v occurs in type2, otherwise False


def energy_prof(step):
    (diff, rad) = diffs_prof(step)
    (adv, _) = advts_prof(step)
    return ((diff + np.append(adv, 0)), rad)

Energy flux.

This computation takes sphericity into account if necessary.

Args:
step (:class:`~stagpy.stagyydata._Step`): a step of a StagyyData
instance.
Returns:
tuple of :class:`numpy.array`: the energy flux and the radial position
at which it is evaluated.


def create_message(self, channel_id, text):

        baseurl = self.rest_baseurl + \
            '/channels/{}/messages'.format(channel_id)
        requests.post(baseurl,
                      headers=self.headers,
                      data=json.dumps({'content': text}))

Sends a message to a Discord channel or user via REST API

Args:
channel_id (string): ID of destingation Discord channel
text (string): Content of message


def _NormalizeKeyPath(self, key_path):

    normalized_key_path = key_path.lower()

    if (len(normalized_key_path) < 39 or
        not normalized_key_path.startswith(self._CONTROL_SET_PREFIX)):
      return normalized_key_path

    return ''.join([
        self._NORMALIZED_CONTROL_SET_PREFIX, normalized_key_path[39:]])

Normalizes a Windows Registry key path.

Args:
key_path (str): Windows Registry key path.

Returns:
str: normalized Windows Registry key path.


def theta_str(theta, taustr=TAUSTR, fmtstr='{coeff:,.1f}{taustr}'):
    coeff = (theta / TAU)
    theta_str = fmtstr.format(coeff=coeff, taustr=taustr)
    return theta_str

r"""
Format theta so it is interpretable in base 10

Args:
theta (float) angle in radians
taustr (str): default 2pi

Returns:
str : theta_str - the angle in tau units

Example1:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import *  # NOQA
>>> theta = 3.1415
>>> result = theta_str(theta)
>>> print(result)
0.5*2pi

Example2:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import *  # NOQA
>>> theta = 6.9932
>>> taustr = 'tau'
>>> result = theta_str(theta, taustr)
>>> print(result)
1.1tau


def codemirror_script(self, inputid):

        varname = "{}_codemirror".format(inputid)
        html = self.get_codemirror_field_js()
        opts = self.codemirror_config()

        return html.format(varname=varname, inputid=inputid,
                           settings=json.dumps(opts, sort_keys=True))

Build CodeMirror HTML script tag which contains CodeMirror init.

Arguments:
inputid (string): Input id.

Returns:
string: HTML for field CodeMirror instance.


def resolveExpression(self, retina_name, body, sparsity=1.0):

        resourcePath = '/expressions'
        method = 'POST'

        queryParams = {}
        headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}
        postData = None

        queryParams['retina_name'] = retina_name
        queryParams['sparsity'] = sparsity
        postData = body
        response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)
        return fingerprint.Fingerprint(**response.json())

Resolve an expression
Args:
retina_name, str: The retina name (required)
body, ExpressionOperation: The JSON formatted encoded to be evaluated (required)
sparsity, float: Sparsify the resulting expression to this percentage (optional)
Returns: Fingerprint


def _get_stack_depth(package, fqdn, defdepth=_def_stackdepth):

    global _stack_config
    if package not in _stack_config:
        from acorn.config import settings
        spack = settings(package)
        _stack_config[package] = {}

        secname = "logging.depth"
        if spack.has_section(secname):
            for ofqdn in spack.options(secname):
                _stack_config[package][ofqdn] = spack.getint(secname, ofqdn)

    usedef = True
    if fqdn in _stack_config[package]:
        result = _stack_config[package][fqdn]
        usedef = False
    elif "*" in _stack_config[package]:
        result = _stack_config[package]["*"]
        usedef = False
    else:
        result = defdepth

    if not usedef:
        msg.gen("Using {} for {} stack depth.".format(result, fqdn), 3)
    return result

Loads the stack depth settings from the config file for the specified
package.

Args:
package (str): name of the package to get stack depth info for.
fqdn (str): fully qualified domain name of the member in the package.
defdepth (int): default depth when one has not been configured.


def get_html_titles(index_page):
    dom = dhtmlparser.parseString(index_page)
    title_tags = dom.find('title')
    return [SourceString(tag.getContent().strip(), 'HTML') for tag in title_tags if tag.getContent().strip()]

Return list of titles parsed from HTML.

Args:
index_page (str): HTML content of the page you wish to analyze.

Returns:
list: List of :class:`.SourceString` objects.


def add_triangle(self, neighbors, color, center=None, opacity=0.4,
                     draw_edges=False, edges_color=[0.0, 0.0, 0.0],
                     edges_linewidth=2):

        points = vtk.vtkPoints()
        triangle = vtk.vtkTriangle()
        for ii in range(3):
            points.InsertNextPoint(neighbors[ii].x, neighbors[ii].y,
                                   neighbors[ii].z)
            triangle.GetPointIds().SetId(ii, ii)
        triangles = vtk.vtkCellArray()
        triangles.InsertNextCell(triangle)

        trianglePolyData = vtk.vtkPolyData()
        trianglePolyData.SetPoints( points )
        trianglePolyData.SetPolys( triangles )

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(trianglePolyData)

        ac = vtk.vtkActor()
        ac.SetMapper(mapper)
        ac.GetProperty().SetOpacity(opacity)
        if color == 'element':
            if center is None:
                raise ValueError(
                    'Color should be chosen according to the central atom, '
                    'and central atom is not provided')

            myoccu = 0.0
            for specie, occu in center.species.items():
                if occu > myoccu:
                    myspecie = specie
                    myoccu = occu
            color = [i / 255 for i in self.el_color_mapping[myspecie.symbol]]
            ac.GetProperty().SetColor(color)
        else:
            ac.GetProperty().SetColor(color)
        if draw_edges:
            ac.GetProperty().SetEdgeColor(edges_color)
            ac.GetProperty().SetLineWidth(edges_linewidth)
            ac.GetProperty().EdgeVisibilityOn()
        self.ren.AddActor(ac)

Adds a triangular surface between three atoms.

Args:
atoms: Atoms between which a triangle will be drawn.
color: Color for triangle as RGB.
center: The "central atom" of the triangle
opacity: opacity of the triangle
draw_edges: If set to True, the a line will be  drawn at each edge
edges_color: Color of the line for the edges
edges_linewidth: Width of the line drawn for the edges


def __getattr__(self, __key: Hashable) -> Any:

        try:
            return self[__key]
        except KeyError:
            raise AttributeError(__key)

Support item access via dot notation.

Args:
__key: Key to fetch


def head(self, n=5):

        if n >= len(self.index):
            return self.copy()
        return self.__constructor__(query_compiler=self._query_compiler.head(n))

Get the first n rows of the DataFrame.

Args:
n (int): The number of rows to return.

Returns:
A new DataFrame with the first n rows of the DataFrame.


def geosgeometry_str_to_struct(value):
    result = geos_ptrn.match(value)
    if (not result):
        return None
    return {'srid': result.group(1), 'x': result.group(2), 'y': result.group(3)}

Parses a geosgeometry string into struct.

Example:
SRID=5432;POINT(12.0 13.0)
Returns:
>> [5432, 12.0, 13.0]


def quad_genz_keister_16(order):

    order = sorted(GENZ_KEISTER_16.keys())[order]

    abscissas, weights = GENZ_KEISTER_16[order]
    abscissas = numpy.array(abscissas)
    weights = numpy.array(weights)

    weights /= numpy.sum(weights)
    abscissas *= numpy.sqrt(2)

    return abscissas, weights

Hermite Genz-Keister 16 rule.

Args:
order (int):
The quadrature order. Must be in the interval (0, 8).

Returns:
(:py:data:typing.Tuple[numpy.ndarray, numpy.ndarray]):
Abscissas and weights

Examples:
>>> abscissas, weights = quad_genz_keister_16(1)
>>> print(numpy.around(abscissas, 4))
[-1.7321  0.      1.7321]
>>> print(numpy.around(weights, 4))
[0.1667 0.6667 0.1667]


def pad_to_square(self, images: 'torch.Tensor', background_color: Union[int, Tuple[int, int, int]]=0) -> 'torch.Tensor':
    height, width = get_image_size(images, ChannelDimension.FIRST)
    if height == width:
        return images
    num_channels = images.shape[1] if len(images.shape) == 4 else images.shape[0]
    if isinstance(background_color, int):
        background_color = [background_color] + [0] * (num_channels - 1)
    elif len(background_color) != num_channels:
        raise ValueError(f'background_color must have no more than {num_channels} elements to match the number of channels')
    max_dim = max(height, width)
    paste_x_left = (max_dim - width)
    paste_y_left = (max_dim - height)
    paste_x_right = max_dim - width - paste_x_left
    paste_y_right = max_dim - height - paste_y_left
    padded_images = F.pad(images, padding=[paste_x_left, paste_y_left, paste_x_right, paste_y_right], fill=background_color)
    return padded_images

Pads an image to a square based on the longest edge.

Args:
images (`np.ndarray`):
The images to pad.
background_color (`int` or `Tuple[int, int, int]`, *optional*, defaults to 0):
The color to use for the padding. Can be an integer for single channel or a
tuple of integers representing for multi-channel images. If passed as integer
in mutli-channel mode, it will default to `0` in subsequent channels.
Returns:
`torch.Tensor`: The padded images.


def rargmax(x, eps=1e-8):

    idxs = np.where(abs(x - np.max(x, axis=0)) < eps)[0]
    return np.random.choice(idxs)

Argmax with random tie-breaking

Args:
x: a 1-dim numpy array
Returns:
the argmax index


def maybe_check_scalar_distribution(distribution, expected_base_dtype, validate_args):
    if (distribution.dtype != expected_base_dtype):
        raise TypeError('dtype mismatch; distribution.dtype="{}" is not "{}"'.format(dtype_util.name(distribution.dtype), dtype_util.name(expected_base_dtype)))
    if (validate_args and (distribution.reparameterization_type != reparameterization.FULLY_REPARAMETERIZED)):
        raise ValueError('Base distribution should be reparameterized or be a function of non-trainable variables; distribution.reparameterization_type = "{}" != "FULLY_REPARAMETERIZED".'.format(distribution.reparameterization_type))
    with tf.name_scope('check_distribution'):
        assertions = []

        def check_is_scalar(is_scalar, name):
            is_scalar_ = tf.get_static_value(is_scalar)
            if (is_scalar_ is not None):
                if (not is_scalar_):
                    raise ValueError('distribution must be scalar; distribution.{}=False is not True'.format(name))
            elif validate_args:
                assertions.append(assert_util.assert_equal(is_scalar, True, message='distribution must be scalar; distribution.{}=False is not True'.format(name)))
        check_is_scalar(distribution.is_scalar_event(), 'is_scalar_event')
        check_is_scalar(distribution.is_scalar_batch(), 'is_scalar_batch')
        return assertions

Helper which checks validity of a scalar `distribution` init arg.

Valid here means:

* `distribution` has scalar batch and event shapes.
* `distribution` is `FULLY_REPARAMETERIZED`
* `distribution` has expected dtype.

Args:
distribution:  `Distribution`-like object.
expected_base_dtype:  `TensorFlow` `dtype`.
validate_args:  Python `bool`.  Whether to do additional checks: (i)  check
that reparameterization_type is `FULLY_REPARAMETERIZED`. (ii) add
`tf.Assert` ops to the graph to enforce that distribution is scalar in the
event that this cannot be determined statically.

Returns:
List of `tf.Assert` ops to run to enforce validity checks that could not
be statically determined.  Empty if `not validate_args`.

Raises:
ValueError:  If validate_args and distribution is not FULLY_REPARAMETERIZED
ValueError:  If distribution is statically determined to not have both
scalar batch and scalar event shapes.


def weCanCheckTheseDomains(email):

    notWorking = [
        "@aol.com",
        "@bk.ru",
        "@breakthru.com",
        "@gmx.",
        "@hotmail.co",
        "@inbox.com",
        "@latinmail.com",
        "@libero.it",
        "@mail.ru",
        "@mail2tor.com",
        "@outlook.com",
        "@rambler.ru",
        "@rocketmail.com",
        "@starmedia.com",
        "@ukr.net"
        "@yahoo.",
        "@ymail."
    ]

    for n in notWorking:
        if n in email:
            print("\t[*] Verification of '{}' aborted. Details:\n\t\t{}".format(general.warning(email), "This domain CANNOT be verified using mailfy."))
            return False

    emailDomains = EMAIL_DOMAINS
    safe = False

    for e in EMAIL_DOMAINS:
        if e in email:
            safe =  True

    if not safe:
        print("\t[*] Verification of '{}' aborted. Details:\n\t\t{}".format(general.warning(email), "This domain CANNOT be verified using mailfy."))
        return False
    return True

Method that verifies if a domain can be safely verified.

Args:
-----
email: the email whose domain will be verified.

Returns:
--------
bool: it represents whether the domain can be verified.


def for_fetch(fetch):
    if fetch is None:
        raise TypeError(f'Argument `fetch` = {fetch} has invalid type "{type(fetch).__name__}". Cannot be None')
    elif isinstance(fetch, (list, tuple)):
        return _ListFetchMapper(fetch)
    elif isinstance(fetch, collections_abc.Mapping):
        return _DictFetchMapper(fetch)
    elif _is_attrs_instance(fetch):
        return _AttrsFetchMapper(fetch)
    else:
        for tensor_type, fetch_fn, _, _ in _REGISTERED_EXPANSIONS:
            if isinstance(fetch, tensor_type):
                fetches, contraction_fn = fetch_fn(fetch)
                return _ElementFetchMapper(fetches, contraction_fn)
    raise TypeError(f'Argument `fetch` = {fetch} has invalid type "{type(fetch).__name__}"')

Creates fetch mapper that handles the structure of `fetch`.

The default graph must be the one from which we want to fetch values when
this function is called.

Args:
fetch: An arbitrary fetch structure: singleton, list, tuple, namedtuple,
or dict.

Returns:
An instance of a subclass of `_FetchMapper` that handles the shape.


def service_unavailable(cls, errors=None):
    if cls.expose_status:
        cls.response.content_type = 'application/json'
        cls.response._status_line = '503 Service Unavailable'
    return cls(503, None, errors).to_json

Shortcut API for HTTP 503 `Service Unavailable` response.

Args:
errors (list): Response key/value data.

Returns:
WSResponse Instance.


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

Adds a delay to an [`EventSet`][temporian.EventSet]'s timestamps.

In other words, shifts the timestamp values forwards in time.

Usage example:
```python
>>> a = tp.event_set(
...     timestamps=[0, 1, 5, 6],
...     features={"value": [0, 1, 5, 6]},
... )

>>> b = a.lag(tp.duration.seconds(2))
>>> b
indexes: ...
(4 events):
timestamps: [2. 3. 7. 8.]
'value': [0 1 5 6]
...

```

Args:
duration: Duration to lag by.

Returns:
Lagged EventSet.


def reverse_transform(self, col):

        output = pd.DataFrame(index=col.index)
        output[self.col_name] = col.apply(self.safe_round, axis=1)

        if self.subtype == 'int':
            output[self.col_name] = output[self.col_name].astype(int)

        return output

Converts data back into original format.

Args:
col(pandas.DataFrame): Data to transform.

Returns:
pandas.DataFrame


def add_all(cls, models, commit=True, check_type=False):
    if check_type:
        for model in models:
            if (not isinstance(model, cls)):
                raise ValueError('%s is not of type %s'(model, cls))
    if (None in models):
        cls.session.add_all([m for m in models if (m is not None)])
    else:
        cls.session.add_all(models)
    try:
        if commit:
            cls.session.commit()
        return models
    except:
        cls.session.rollback()
        raise

Batch method for adding a list of model instances
to the db in one get_or_404.

Args:

models (list): A list of the instances to add.
commit (bool, optional): Defaults to True. If False, the
transaction won't get committed.
check_type (bool, optional) :  If True, each instance
is type checked and exception is thrown if it is
not an instance of the model. By default, False.

Returns:
list: A list of `Model` instances


def copy_single(src, dst, overwrite=True, verbose=True, deeplink=True,
                dryrun=False):
    r
    try:
        if exists(src):
            if not isdir(src) and isdir(dst):

                dst = join(dst, basename(src))
            if exists(dst):
                if overwrite:
                    prefix = 'C+O'
                    if verbose:
                        print('[util_path] [Copying + Overwrite]:')
                else:
                    prefix = 'Skip'
                    if verbose:
                        print('[%s] ->%s' % (prefix, dst))
                    return
            else:
                prefix = 'C'
                if verbose:
                    if dryrun:
                        print('[util_path] [DryRun]: ')
                    else:
                        print('[util_path] [Copying]: ')
            if verbose:
                print('[%s] | %s' % (prefix, src))
                print('[%s] ->%s' % (prefix, dst))
            if not dryrun:
                if not deeplink and islink(src):
                    linkto = os.readlink(src)
                    symlink(linkto, dst)
                elif isdir(src):
                    print('isdir')
                    shutil.copytree(src, dst)
                else:
                    shutil.copy2(src, dst)
        else:
            prefix = 'Miss'
            if verbose:
                print('[util_path] [Cannot Copy]: ')
                print('[%s] src=%s does not exist!' % (prefix, src))
                print('[%s] dst=%s' % (prefix, dst))
    except Exception as ex:
        from utool import util_dbg
        util_dbg.printex(ex, 'Error copying single', keys=['src', 'dst'])
        raise

r"""
Args:
src (str): file or directory to copy
dst (str): directory or new file to copy to

Copies src file or folder to dst.

If src is a folder this copy is recursive.


def set(self, name, valu):
    byts = s_msgpack.en(valu)
    lkey = (self.pref + name.encode('utf8'))
    self.slab.put(lkey, byts, db=self.db)
    self.info[name] = valu

Set a name in the SlabDict.

Args:
name (str): The key name.
valu (obj): A msgpack compatible value.

Returns:
None


def get_documents(self, doc_format='dict'):

    def get_doc_id(root, rel_path):
        if (not rel_path):
            return root.text
        else:
            child = root.find(rel_path[0])
            if (child is None):
                return None
            return get_doc_id(child, rel_path[1:])
    if (doc_format == 'dict'):
        return dict([(get_doc_id(document, self._id_xpath), etree_to_dict(document)['document']) for document in self._get_doc_list()])
    elif (doc_format == 'etree'):
        return dict([(get_doc_id(document, self._id_xpath), document) for document in self._get_doc_list()])
    elif (doc_format == 'list-etree'):
        return self._get_doc_list()
    elif (doc_format == 'list-string'):
        return list([ET.tostring(document) for document in self._get_doc_list()])
    elif (doc_format in ('', None, 'string')):
        return dict([(get_doc_id(document, self._id_xpath), ET.tostring(document)) for document in self._get_doc_list()])
    else:
        raise ParameterError(('doc_format=' + doc_format))

Get the documents returned from Storege in this response.

Keyword args:
doc_format -- Specifies the doc_format for the returned documents.
Can be 'dict', 'etree' or 'string'. Default is 'dict'.

Returns:
A dict where keys are document ids and values depending of the required doc_format:
A dict representations of documents (see etree_to_dict());
A etree Element representing the document;
A raw XML document string.

Raises:
ParameterError -- The doc_format value is not allowed.


def update(self, task_name, task_json):

        r = self.gbdx_connection.put(self._base_url + '/' + task_name, json=task_json)
        raise_for_status(r)

        return r.json()

Updates a GBDX task.

Args:
task_name (str): Task name.
task_json (dict): Dictionary representing updated task definition.

Returns:
Dictionary representing the updated task definition.


def seek(self, offset, whence=os.SEEK_SET):

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

    if whence == os.SEEK_CUR:
      offset += self._current_offset
    elif whence == os.SEEK_END:
      offset += self._cpio_archive_file_entry.data_size
    elif whence != os.SEEK_SET:
      raise IOError('Unsupported whence.')

    if offset < 0:
      raise IOError('Invalid offset value less than zero.')

    self._current_offset = offset

Seeks to an offset within the file-like object.

Args:
offset (int): offset to seek to.
whence (Optional(int)): value that indicates whether offset is an absolute
or relative position within the file.

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


def use_options(allowed):

    def update_docstring(f):
        _update_option_docstring(f, allowed)

        @functools.wraps(f)
        def check_options(*args, **kwargs):
            options = kwargs.get('options', {})
            not_allowed = [option for option in options if ((option not in allowed) and (not option.startswith('_')))]
            if not_allowed:
                logging.warning('The following options are not supported by this function and will likely result in undefined behavior: {}.'.format(not_allowed))
            return f(*args, **kwargs)
        return check_options
    return update_docstring

Decorator that logs warnings when unpermitted options are passed into its
wrapped function.

Requires that wrapped function has an keyword-only argument named
`options`. If wrapped function has {options} in its docstring, fills in
with the docs for allowed options.

Args:
allowed (list str): list of option keys allowed. If the wrapped
function is called with an option not in allowed, log a warning.
All values in allowed must also be present in `defaults`.

Returns:
Wrapped function with options validation.

>>> @use_options(['title'])
... def test(*, options={}): return options['title']

>>> test(options={'title': 'Hello'})
'Hello'

>>> # test(options={'not_allowed': 123}) # Also logs error message
''


def from_authorized_user_file(cls, filename, scopes=None):
    with io.open(filename, 'r', encoding='utf-8') as json_file:
        data = json.load(json_file)
        return cls.from_authorized_user_info(data, scopes)

Creates a Credentials instance from an authorized user json file.

Args:
filename (str): The path to the authorized user json file.
scopes (Sequence[str]): Optional list of scopes to include in the
credentials.

Returns:
google.oauth2.credentials.Credentials: The constructed
credentials.

Raises:
ValueError: If the file is not in the expected format.


def convert_to_sliceable(arrays, target_backend=None):

    def convert_single_array(x):
        if x is None:
            return x
        if isinstance(x, np.ndarray) and str(x.dtype) == 'object' and (backend.backend() == 'tensorflow') and all((isinstance(e, str) for e in x)):
            x = tf.convert_to_tensor(x, dtype='string')
        if isinstance(x, np.ndarray):
            sliceable_class = NumpySliceable
        elif data_adapter_utils.is_tensorflow_tensor(x):
            if data_adapter_utils.is_tensorflow_ragged(x):
                sliceable_class = TensorflowRaggedSliceable
            elif data_adapter_utils.is_tensorflow_sparse(x):
                sliceable_class = TensorflowSparseSliceable
            else:
                sliceable_class = TensorflowSliceable
        elif data_adapter_utils.is_jax_array(x):
            if data_adapter_utils.is_jax_sparse(x):
                sliceable_class = JaxSparseSliceable
            else:
                x = np.asarray(x)
                sliceable_class = NumpySliceable
        elif data_adapter_utils.is_torch_tensor(x):
            sliceable_class = TorchSliceable
        elif pandas is not None and isinstance(x, pandas.DataFrame):
            sliceable_class = PandasDataFrameSliceable
        elif pandas is not None and isinstance(x, pandas.Series):
            sliceable_class = PandasSeriesSliceable
        elif data_adapter_utils.is_scipy_sparse(x):
            sliceable_class = ScipySparseSliceable
        elif hasattr(x, '__array__'):
            x = np.asarray(x)
            sliceable_class = NumpySliceable
        else:
            raise ValueError(f'Expected a NumPy array, tf.Tensor, tf.RaggedTensor, tf.SparseTensor, jax.np.ndarray, jax.experimental.sparse.JAXSparse, torch.Tensor, Pandas Dataframe, or Pandas Series. Received invalid input: {x} (of type {type(x)})')

        def is_non_floatx_float(dtype):
            return dtype is not object and backend.is_float_dtype(dtype) and (not backend.standardize_dtype(dtype) == backend.floatx())
        cast_dtype = None
        if pandas is not None and isinstance(x, pandas.DataFrame):
            if any((is_non_floatx_float(d) for d in x.dtypes.values)):
                cast_dtype = backend.floatx()
        elif is_non_floatx_float(x.dtype):
            cast_dtype = backend.floatx()
        if cast_dtype is not None:
            x = sliceable_class.cast(x, cast_dtype)
        if target_backend is None:
            return sliceable_class(x)
        if target_backend == 'tensorflow':
            return sliceable_class.convert_to_tf_dataset_compatible(x)
        if target_backend == 'jax' and sliceable_class in (TensorflowSliceable, TorchSliceable):
            x = np.asarray(x)
            sliceable_class = NumpySliceable
        return sliceable_class(x)
    return tree.map_structure(convert_single_array, arrays)

Convert a structure of arrays into `Sliceable` instances

Args:
arrays: the arrays to convert.
target_backend: the target backend for the output:
- `None` indicates that `arrays` will be wrapped into `Sliceable`s
as-is without using a different representation. This is used by
`train_validation_split()`.
- `tensorflow` indicates that
`Sliceable.convert_to_tf_dataset_compatible` will be called. The
returned structure therefore contains arrays, not `Sliceable`s.
- `numpy`, `jax` or `torch` indices that the arrays will eventually
be converted to this backend type after slicing. In this case,
the intermediary `Sliceable`s may use a different representation
from the input `arrays` for better performance.
Returns: the same structure with `Sliceable` instances or arrays.


def make_class_weight_map_fn(class_weight):
    from keras.src.utils.module_utils import tensorflow as tf
    class_weight_tensor = tf.convert_to_tensor([class_weight.get(int(c), 1.0) for c in range(max(class_weight.keys()) + 1)])

    def class_weights_map_fn(*data):

        x, y, sw = data_adapter_utils.unpack_x_y_sample_weight(data)
        if sw is not None:
            raise ValueError('You cannot `class_weight` and `sample_weight` at the same time.')
        if tree.is_nested(y):
            raise ValueError('`class_weight` is only supported for Models with a single output.')
        if y.shape.rank >= 2:
            y_classes = tf.__internal__.smart_cond.smart_cond(tf.shape(y)[-1] > 1, lambda: tf.argmax(y, axis=-1, output_type=tf.int32), lambda: tf.cast(tf.round(tf.squeeze(y, axis=-1)), tf.int32))
        else:
            y_classes = tf.cast(tf.round(y), tf.int32)
        cw = tf.gather(class_weight_tensor, y_classes)
        return (x, y, cw)
    return class_weights_map_fn

Applies class weighting to a `Dataset`.

The `Dataset` is assumed to be in format `(x, y)` or `(x, y, sw)`, where
`y` must be a single `Tensor`.

Args:
class_weight: A map where the keys are integer class ids and values are
the class weights, e.g. `{0: 0.2, 1: 0.6, 2: 0.3}`

Returns:
A function that can be used with `tf.data.Dataset.map` to apply class
weighting.


def get_checkpoint_path(model_path):

    if os.path.basename(model_path) == model_path:
        model_path = os.path.join('.', model_path)
    if os.path.basename(model_path) == 'checkpoint':
        assert tfv1.gfile.Exists(model_path), model_path
        model_path = tf.train.latest_checkpoint(os.path.dirname(model_path))

    new_path = model_path
    if '00000-of-00001' in model_path:
        new_path = model_path.split('.data')[0]
    elif model_path.endswith('.index'):
        new_path = model_path.split('.index')[0]
    if new_path != model_path:
        logger.info(
            "Checkpoint path {} is auto-corrected to {}.".format(model_path, new_path))
        model_path = new_path
    assert tfv1.gfile.Exists(model_path) or tfv1.gfile.Exists(model_path + '.index'), model_path
    return model_path

Work around TF problems in checkpoint path handling.

Args:
model_path: a user-input path
Returns:
str: the argument that can be passed to NewCheckpointReader


def getTickTock(self, vals):
    (val0, val1) = vals
    try:
        _tick = self._getLiftValu(val0)
    except ValueError as e:
        raise s_exc.BadTypeValu(name=self.name, valu=val0, mesg='Unable to process the value for val0 in getTickTock.')
    sortval = False
    if isinstance(val1, str):
        if val1.startswith(('+-', '-+')):
            sortval = True
            delt = s_time.delta(val1[2:])
            _tock = (_tick + delt)
            _tick = (_tick - delt)
        elif val1.startswith('-'):
            sortval = True
            _tock = self._getLiftValu(val1, relto=_tick)
        else:
            _tock = self._getLiftValu(val1, relto=_tick)
    else:
        _tock = self._getLiftValu(val1, relto=_tick)
    if (sortval and (_tick >= _tock)):
        tick = min(_tick, _tock)
        tock = max(_tick, _tock)
        return (tick, tock)
    return (_tick, _tock)

Get a tick, tock time pair.

Args:
vals (list): A pair of values to norm.

Returns:
(int, int): A ordered pair of integers.


def __ne__(self, other):

        is_equals = self == other
        if is_equals != NotImplemented:
            return not is_equals
        return is_equals

Check if `self` != `other` via a comparison of the hash of
their contents.
If `other` is not a :class:`FrameSet`, but is a set, frozenset, or
is iterable, it will be cast to a :class:`FrameSet`.

Args:
other (:class:`FrameSet`): Also accepts an object that can be cast to a :class:`FrameSet`

Returns:
bool:
:class:`NotImplemented`: if `other` fails to convert to a :class:`FrameSet`


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

Corresponds to IDD Field `liquid_precipitation_quantity`

Args:
value (float): value for IDD Field `liquid_precipitation_quantity`
Unit: hr
Missing value: 99.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 get_log_device_placement():
    return context().log_device_placement

Get if device placements are logged.

Returns:
If device placements are logged.


def get_enricher(config, metrics, **kwargs):
    builder = enricher.GCEEnricherBuilder(config, metrics, **kwargs)
    return builder.build_enricher()

Get a GCEEnricher client.

A factory function that validates configuration and returns an
enricher client (:interface:`gordon.interfaces.IMessageHandler`)
provider.

Args:
config (dict): Google Compute Engine API related configuration.
metrics (obj): :interface:`IMetricRelay` implementation.
kwargs (dict): Additional keyword arguments to pass to the
enricher.
Returns:
A :class:`GCEEnricher` instance.


def deploy_template_uri(access_token, subscription_id, resource_group, deployment_name, template_uri, parameters):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourcegroups/', resource_group, '/providers/Microsoft.Resources/deployments/', deployment_name, '?api-version=', DEPLOYMENTS_API])
    properties = {'templateLink': {'uri': template_uri}}
    properties['mode'] = 'Incremental'
    properties['parameters'] = parameters
    template_body = {'properties': properties}
    body = json.dumps(template_body)
    return do_put(endpoint, body, access_token)

Deploy a template referenced by a URI, with parameters as a JSON string.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
deployment_name (str): A name you give to the deployment.
template_uri (str): URI which points to a JSON template (e.g. github raw location).
parameters (str): String representation of a JSON template parameters body.

Returns:
HTTP response.


def purity(state):
    rho = np.array(state)
    if (rho.ndim == 1):
        return 1.0
    return np.real(np.trace(rho.dot(rho)))

Calculate the purity of a quantum state.

Args:
state (ndarray): a quantum state
Returns:
float: purity.


def __init__(self, tcex, data):

        self._data = data

        self._indexes = {}
        self._master_index = {}
        self._tcex = tcex

        self._build_indexes()

Initialize default class values.

.. Note:: The method only supports one level of nesting in the provided data.

Args:
tcex (obj): Instance of TcEx.
data (list): List of Dictionary.


def _update_assignment_email_status(offer_assignment_id, send_id, status, site_code=None):

    api = get_ecommerce_client(url_postfix='assignment-email/', site_code=site_code)
    post_data = {
        'offer_assignment_id': offer_assignment_id,
        'send_id': send_id,
        'status': status,
    }
    try:
        api_response = api.status().post(post_data)
    except RequestException:
        logger.exception(
            '[Offer Assignment] An error occurred while updating offer assignment email status for '
            'offer id {token_offer} and message id {token_send_id} via the Ecommerce API.'.format(
                token_offer=offer_assignment_id,
                token_send_id=send_id
            )
        )
        return False
    return True if api_response.get('status') == 'updated' else False

Update the offer_assignment and offer_assignment_email model using the Ecommerce assignmentemail api.
Arguments:
offer_assignment_id (str): Key of the entry in the offer_assignment model.
send_id (str): Unique message id from Sailthru
status (str): status to be sent to the api
site_code (str): site code
Returns:
True or False based on model update status from Ecommerce api


def setup_model(x, y, model_type='random_forest', seed=None, **kwargs):

    assert len(x) > 1 and len(y) > 1, 'Not enough data objects to train on (minimum is at least two, you have (x: {0}) and (y: {1}))'.format(len(x), len(y))

    sets = namedtuple('Datasets', ['train', 'test'])
    x_train, x_test, y_train, y_test = train_test_split(x,
                                                        y,
                                                        random_state=seed,
                                                        shuffle=False)
    x = sets(x_train, x_test)
    y = sets(y_train, y_test)

    if model_type == 'random_forest' or model_type == 'rf':
        model = rf.RandomForest(x, y, random_state=seed, **kwargs)
    elif model_type == 'deep_neural_network' or model_type == 'dnn':
        model = dnn.DeepNeuralNetwork(x, y, **kwargs)
    else:
        raise ValueError('Invalid model type kwarg')
    return model

Initializes a machine learning model

Args:
x: Pandas DataFrame, X axis of features
y: Pandas Series, Y axis of targets
model_type: Machine Learning model to use
Valid values: 'random_forest'
seed: Random state to use when splitting sets and creating the model
**kwargs: Scikit Learn's RandomForestClassifier kwargs

Returns:
Trained model instance of model_type