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 src/algobattle/util.py
26 27 28 29 30 | |
algobattle.util.BaseModel
¶
Bases: BaseModel
Base class for all pydantic models.
Source code in src/algobattle/util.py
33 34 35 36 | |
algobattle.util.Encodable
¶
Bases: EncodableBase, ABC
Represents data that docker containers can interact with.
Source code in src/algobattle/util.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
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 src/algobattle/util.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
algobattle.util.EncodableModel
¶
Bases: EncodableModelBase, ABC
Problem data that can easily be encoded into and decoded from json files.
Source code in src/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 src/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 src/algobattle/util.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
__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 src/algobattle/util.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
algobattle.util.EncodingError
¶
Bases: AlgobattleBaseException
Indicates that the given data could not be encoded or decoded properly.
Source code in src/algobattle/util.py
164 165 | |
algobattle.util.ValidationError
¶
Bases: AlgobattleBaseException
Indicates that the decoded problem instance or solution is invalid.
Source code in src/algobattle/util.py
168 169 | |
algobattle.util.BuildError
¶
Bases: AlgobattleBaseException
Indicates that the build process could not be completed successfully.
Source code in src/algobattle/util.py
172 173 | |
algobattle.util.ExecutionError
¶
Bases: AlgobattleBaseException
Indicates that the program could not be executed successfully.
Source code in src/algobattle/util.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
__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 src/algobattle/util.py
179 180 181 182 183 184 185 186 187 188 189 190 | |
algobattle.util.ExecutionTimeout
¶
Bases: ExecutionError
Indicates that the program ran into the timeout.
Source code in src/algobattle/util.py
193 194 | |
algobattle.util.DockerError
¶
Bases: AlgobattleBaseException
Indicates that an issue with the docker daemon occured.
Source code in src/algobattle/util.py
197 198 | |
algobattle.util.ExceptionInfo
¶
Bases: BaseModel
Details about an exception that was raised.
Source code in src/algobattle/util.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
from_exception(error)
classmethod
¶
Constructs an instance from a raised exception.
Source code in src/algobattle/util.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |