Utility¶
This module contains various objects needed in the rest of the algobattle package. In particular, the exception classes
and the Encodable base classes.
            algobattle.util.Role
¶
    
              Bases: StrEnum
Indicates whether the role of a program is to generate or to solve instances.
Source code in algobattle/util.py
                21 22 23 24 25  |  | 
            algobattle.util.BaseModel
¶
    
              Bases: BaseModel
Base class for all pydantic models.
Source code in algobattle/util.py
                28 29 30 31  |  | 
            algobattle.util.Encodable
¶
    
              Bases: EncodableBase, ABC
Represents data that docker containers can interact with.
Source code in algobattle/util.py
                70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90  |  | 
            decode(source, max_size, role)
  
      abstractmethod
      classmethod
  
¶
    Decodes the data found at the given path into a python object.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                source
             | 
            
                  Path
             | 
            
               Path to data that can be used to construct an instance of this class. May either point to a folder
or a single file. The expected type of path should be consistent with the result of :meth:  | 
            required | 
                max_size
             | 
            
                  int
             | 
            
               Maximum size the current battle allows.  | 
            required | 
                role
             | 
            
                  Role
             | 
            
               Role of the program that generated this data.  | 
            required | 
Raises:
| Type | Description | 
|---|---|
                  EncodingError
             | 
            
               If the data cannot be decoded into an instance.  | 
          
Returns:
| Type | Description | 
|---|---|
                  Self
             | 
            
               The decoded object.  | 
          
Source code in algobattle/util.py
              73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90  |  | 
            algobattle.util.EncodableModel
¶
    
              Bases: EncodableModelBase, ABC
Problem data that can easily be encoded into and decoded from json files.
Source code in algobattle/util.py
                122 123 124 125 126 127 128  |  | 
            decode(source, max_size, role)
  
      classmethod
  
¶
    Uses pydantic to create a python object from a .json file.
Source code in algobattle/util.py
              125 126 127 128  |  | 
            algobattle.util.AlgobattleBaseException
¶
    
              Bases: Exception
Base exception class for errors used by the algobattle package.
Source code in algobattle/util.py
                139 140 141 142 143 144 145 146 147 148 149 150 151  |  | 
            __init__(message, *, detail=None)
¶
    Base exception class for errors used by the algobattle package.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                message
             | 
            
                  LiteralString
             | 
            
               Simple error message that can always be displayed.  | 
            required | 
                detail
             | 
            
                  str | list[str] | list[dict[str, Any]] | None
             | 
            
               More detailed error message that may include sensitive information.  | 
            
                  None
             | 
          
Source code in algobattle/util.py
              142 143 144 145 146 147 148 149 150 151  |  | 
            algobattle.util.EncodingError
¶
    
              Bases: AlgobattleBaseException
Indicates that the given data could not be encoded or decoded properly.
Source code in algobattle/util.py
                154 155  |  | 
            algobattle.util.ValidationError
¶
    
              Bases: AlgobattleBaseException
Indicates that the decoded problem instance or solution is invalid.
Source code in algobattle/util.py
                158 159  |  | 
            algobattle.util.BuildError
¶
    
              Bases: AlgobattleBaseException
Indicates that the build process could not be completed successfully.
Source code in algobattle/util.py
                162 163  |  | 
            algobattle.util.ExecutionError
¶
    
              Bases: AlgobattleBaseException
Indicates that the program could not be executed successfully.
Source code in algobattle/util.py
                166 167 168 169 170 171 172 173 174 175 176 177 178  |  | 
            __init__(message, *, detail=None, runtime)
¶
    Indicates that the program could not be executed successfully.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                message
             | 
            
                  LiteralString
             | 
            
               Simple error message that can always be displayed.  | 
            required | 
                runtime
             | 
            
                  float
             | 
            
               Runtime of the program in seconds until the error occured.  | 
            required | 
                detail
             | 
            
                  str | None
             | 
            
               More detailed error message that may include sensitive information.  | 
            
                  None
             | 
          
Source code in algobattle/util.py
              169 170 171 172 173 174 175 176 177 178  |  | 
            algobattle.util.ExecutionTimeout
¶
    
              Bases: ExecutionError
Indicates that the program ran into the timeout.
Source code in algobattle/util.py
                181 182  |  | 
            algobattle.util.DockerError
¶
    
              Bases: AlgobattleBaseException
Indicates that an issue with the docker daemon occured.
Source code in algobattle/util.py
                185 186  |  | 
            algobattle.util.ExceptionInfo
¶
    
              Bases: BaseModel
Details about an exception that was raised.
Source code in algobattle/util.py
                193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220  |  | 
            from_exception(error)
  
      classmethod
  
¶
    Constructs an instance from a raised exception.
Source code in algobattle/util.py
              200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220  |  |