<reponame>Z223I/deephyper<filename>deephyper/core/exceptions/nas/space.py
from deephyper.core.exceptions.nas import NASError


class WrongSequenceToSetOperations(NASError):
    """Raised when a sequence of actions is not of the same lenght as the number of variable nodes of the search_space."""

    def __init__(self, sequence_given, sequence_valid):
        self.sequence_given = sequence_given
        self.sequence_valid = sequence_valid

    def __str__(self):
        return f"Wrong sequence given: '{self.sequence_given}' of length {len(self.sequence_given)} when a valid sequence should be of length {len(self.sequence_valid)}"


class StructureHasACycle(NASError):
    """Raised when a search_space is containing a cycle."""

    def __init__(self, msg):
        self.msg = msg

    def __str__(self):
        return self.msg


class InputShapeOfWrongType(NASError):
    """Raised when an input shape of a search_space is of a wrong type.
    """

    def __init__(self, input_shape):
        self.input_shape = input_shape

    def __str__(self):
        f"input_shape must be either a 'tuple' or a 'list(tuple)' but it is of type '{type(self.input_shape)}'!"


class NodeAlreadyAdded(NASError):
    """Raised when a node has already been added in a search_space.
    """

    def __init__(self, node):
        self.node = node

    def __str__(self):
        return f"The node '{str(self.node)}' has already been added to the search_space."


class WrongOutputShape(NASError):
    """Raised when the output shape of the model generated by a search_space doesn't
    match the expected shape.
    """

    def __init__(self, tensor_shape, expected_shape):
        self.tensor_shape = tensor_shape
        self.expected_shape = expected_shape

    def __str__(self):
        return f"The output tensor of shape {self.tensor_shape} doesn't match the expected shape {self.expected_shape}!"

from deephyper.core.exceptions.nas import NASError


class WrongSequenceToSetOperations(NASError):
    """Raised when a sequence of actions is not of the same lenght as the number of variable nodes of the search_space."""

    def __init__(self, sequence_given, sequence_valid):
        self.sequence_given = sequence_given
        self.sequence_valid = sequence_valid

    def __str__(self):
        return f"Wrong sequence given: '{self.sequence_given}' of length {len(self.sequence_given)} when a valid sequence should be of length {len(self.sequence_valid)}"


class StructureHasACycle(NASError):
    """Raised when a search_space is containing a cycle."""

    def __init__(self, msg):
        self.msg = msg

    def __str__(self):
        return self.msg


class InputShapeOfWrongType(NASError):
    """Raised when an input shape of a search_space is of a wrong type.
    """

    def __init__(self, input_shape):
        self.input_shape = input_shape

    def __str__(self):
        f"input_shape must be either a 'tuple' or a 'list(tuple)' but it is of type '{type(self.input_shape)}'!"


class NodeAlreadyAdded(NASError):
    """Raised when a node has already been added in a search_space.
    """

    def __init__(self, node):
        self.node = node

    def __str__(self):
        return f"The node '{str(self.node)}' has already been added to the search_space."


class WrongOutputShape(NASError):
    """Raised when the output shape of the model generated by a search_space doesn't
    match the expected shape.
    """

    def __init__(self, tensor_shape, expected_shape):
        self.tensor_shape = tensor_shape
        self.expected_shape = expected_shape

    def __str__(self):
        return f"The output tensor of shape {self.tensor_shape} doesn't match the expected shape {self.expected_shape}!"
Raised when a sequence of actions is not of the same lenght as the number of variable nodes of the search_space. Raised when a search_space is containing a cycle. Raised when an input shape of a search_space is of a wrong type. Raised when a node has already been added in a search_space. Raised when the output shape of the model generated by a search_space doesn't     match the expected shape.