quantnn/models/pytorch/common.py
def _get_x_y(batch_data, keys):
    """
    Retrieve training input from batch data.

    This function checks whether the object returned as a batch from
    the training loader is an iterable or a mapping. If it is an
    iterable it will simply unpack the input- and target-data in the
    order ``x, y``. If ``batch_data`` is a mapping and keys is not
    ``None`` it will use the two arguments in keys to retrieve elements from
    ``batch_data``. If ``keys`` is ``None``, the first to keys will
    be used to retrieve inputs and targets, respectively.

    Args:
        batch_data: The object that is obtained when iterating o

    Returns:
        Tuple ``x, y`` of input data ``x`` and corresponding output data
        ``y``.
    """
    if isinstance(batch_data, Mapping):

        if keys is not None:
            try:
                x_key, y_key = keys
            except ValueError:
                raise DatasetError(
                    f"Could not unpack provided keys f{keys} into "
                    "variables 'x_key, y_key'"
                )

        else:
            try:
                x_key, y_key = batch_data.keys()
            except ValueError as v:
                raise DatasetError(
                    f"Could not unpack batch keys f{batch_data.keys()} into "
                    "variables 'x_key, y_key'"
                )

        try:
            x = batch_data[x_key]
            y = batch_data[y_key]
        except Exception as e:
            raise DatasetError(
                "The following error was encountered when trying to "
                f"retrieve the keys '{x_key}' and '{y_key} from a batch of  "
                f"training data.: {e}"
            )
    else:
        x, y = batch_data
    return x, y

    Retrieve training input from batch data.

    This function checks whether the object returned as a batch from
    the training loader is an iterable or a mapping. If it is an
    iterable it will simply unpack the input- and target-data in the
    order ``x, y``. If ``batch_data`` is a mapping and keys is not
    ``None`` it will use the two arguments in keys to retrieve elements from
    ``batch_data``. If ``keys`` is ``None``, the first to keys will
    be used to retrieve inputs and targets, respectively.

    Args:
        batch_data: The object that is obtained when iterating o

    Returns:
        Tuple ``x, y`` of input data ``x`` and corresponding output data
        ``y``.
    
Retrieve training input from batch data.
This function checks whether the object returned as a batch from
the training loader is an iterable or a mapping. If it is an
iterable it will simply unpack the input- and target-data in the
order ``x, y``.
Retrieve training input from batch data . This function checks whether the object returned as a batch from the training loader is an iterable or a mapping . If it is an iterable it will simply unpack the input - and target - data in the order ` ` x y ` ` .
def _get_x_y(batch_data, keys):
    if isinstance(batch_data, Mapping):
        if keys is not None:
            try:
                x_key, y_key = keys
            except ValueError:
                raise DatasetError(
                    f"Could not unpack provided keys f{keys} into "
                    "variables 'x_key, y_key'"
                )
        else:
            try:
                x_key, y_key = batch_data.keys()
            except ValueError as v:
                raise DatasetError(
                    f"Could not unpack batch keys f{batch_data.keys()} into "
                    "variables 'x_key, y_key'"
                )
        try:
            x = batch_data[x_key]
            y = batch_data[y_key]
        except Exception as e:
            raise DatasetError(
                "The following error was encountered when trying to "
                f"retrieve the keys '{x_key}' and '{y_key} from a batch of  "
                f"training data.: {e}"
            )
    else:
        x, y = batch_data
    return x, y
def _get_x_y ( batch_data , keys ) : if isinstance ( batch_data , Mapping ) : if keys is not None : try : x_key , y_key = keys except ValueError : raise DatasetError ( f"Could not unpack provided keys f{keys} into " "variables 'x_key, y_key'" ) else : try : x_key , y_key = batch_data . keys ( ) except ValueError as v : raise DatasetError ( f"Could not unpack batch keys f{batch_data.keys()} into " "variables 'x_key, y_key'" ) try : x = batch_data [ x_key ] y = batch_data [ y_key ] except Exception as e : raise DatasetError ( "The following error was encountered when trying to " f"retrieve the keys '{x_key}' and '{y_key} from a batch of  " f"training data.: {e}" ) else : x , y = batch_data return x , y
Retrieve training input from batch data.
Retrieve training input from batch data .
"""
    Retrieve training input from batch data.

    This function checks whether the object returned as a batch from
    the training loader is an iterable or a mapping. If it is an
    iterable it will simply unpack the input- and target-data in the
    order ``x, y``. If ``batch_data`` is a mapping and keys is not
    ``None`` it will use the two arguments in keys to retrieve elements from
    ``batch_data``. If ``keys`` is ``None``, the first to keys will
    be used to retrieve inputs and targets, respectively.

    Args:
        batch_data: The object that is obtained when iterating o

    Returns:
        Tuple ``x, y`` of input data ``x`` and corresponding output data
        ``y``.
    """
Tuple ``x, y`` of input data ``x`` and corresponding output data
``y``.
Tuple ` ` x y ` ` of input data ` ` x ` ` and corresponding output data ` ` y ` ` .
batch_data
The object that is obtained when iterating o
The object that is obtained when iterating o
keys