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
25 26 27 28 29 |
|
algobattle.util.BaseModel
¶
Bases: BaseModel
Base class for all pydantic models.
Source code in algobattle/util.py
32 33 34 35 |
|
algobattle.util.Encodable
¶
Bases: EncodableBase
, ABC
Represents data that docker containers can interact with.
Source code in algobattle/util.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
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
127 128 129 130 131 132 133 |
|
decode(source, max_size, role)
classmethod
¶
Uses pydantic to create a python object from a .json
file.
Source code in algobattle/util.py
130 131 132 133 |
|
algobattle.util.AlgobattleBaseException
¶
Bases: Exception
Base exception class for errors used by the algobattle package.
Source code in algobattle/util.py
144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
__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
147 148 149 150 151 152 153 154 155 156 |
|
algobattle.util.EncodingError
¶
Bases: AlgobattleBaseException
Indicates that the given data could not be encoded or decoded properly.
Source code in algobattle/util.py
159 160 |
|
algobattle.util.ValidationError
¶
Bases: AlgobattleBaseException
Indicates that the decoded problem instance or solution is invalid.
Source code in algobattle/util.py
163 164 |
|
algobattle.util.BuildError
¶
Bases: AlgobattleBaseException
Indicates that the build process could not be completed successfully.
Source code in algobattle/util.py
167 168 |
|
algobattle.util.ExecutionError
¶
Bases: AlgobattleBaseException
Indicates that the program could not be executed successfully.
Source code in algobattle/util.py
171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
__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
174 175 176 177 178 179 180 181 182 183 |
|
algobattle.util.ExecutionTimeout
¶
Bases: ExecutionError
Indicates that the program ran into the timeout.
Source code in algobattle/util.py
186 187 |
|
algobattle.util.DockerError
¶
Bases: AlgobattleBaseException
Indicates that an issue with the docker daemon occured.
Source code in algobattle/util.py
190 191 |
|
algobattle.util.ExceptionInfo
¶
Bases: BaseModel
Details about an exception that was raised.
Source code in algobattle/util.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
from_exception(error)
classmethod
¶
Constructs an instance from a raised exception.
Source code in algobattle/util.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|