Types
Stores low-level types used through the library.
SortedSequence: TypeAlias
module-attribute
#
A sequence that is sorted. Only useful for typing
SortedIterable: TypeAlias
module-attribute
#
An iterable that is sorted. Only useful for typing
Item
module-attribute
#
The type associated with components, splits and choices
Config: TypeAlias
module-attribute
#
An object representing a configuration of a pipeline.
Space
module-attribute
#
Generic for objects that are aware of a space but not the specific kind
Seed: TypeAlias
module-attribute
#
Type alias for kinds of Seeded objects.
FidT: TypeAlias
module-attribute
#
Type alias for a fidelity bound.
class Requeue(generator)
#
Bases: Iterator[T]
A queue that can have items requeued.
import random
from amltk.types import Requeue
name_generator = iter(["Alice", "Bob", "Charlie"])
queue: Requeue[str] = Requeue(name_generator)
rng = random.Random(1)
def process_name(name: str) -> bool:
return rng.choice([True, False])
for name in queue:
print(f"Processing {name}")
processed = process_name(name)
if not processed:
print(f"Failed to process {name}, requeuing")
queue.requeue(name)
See Also
-
If you have a function which will generate items, you can use this to create a requeue from it.
-
Append an item to the end of the queue
-
Requeue an item to the start of the queue
Source code in src/amltk/types.py
def assert_never(value)
#
Utility function for asserting that a value is never reached.
def safe_issubclass(cls, classes)
#
Check if a class is a subclass of a given type.
This is a safe version of issubclass that relies on strings, which is useful for when the type is not importable.
| PARAMETER | DESCRIPTION |
|---|---|
cls |
The class to check
TYPE:
|
classes |
The type to check for. |
| RETURNS | DESCRIPTION |
|---|---|
bool
|
bool |
Source code in src/amltk/types.py
def safe_isinstance(obj, t)
#
Check if an object is of a given type.
This is a safe version of isinstance that relies on strings, which is useful for when the type is not importable.
| PARAMETER | DESCRIPTION |
|---|---|
obj |
The object to check
TYPE:
|
t |
The type to check for. |
| RETURNS | DESCRIPTION |
|---|---|
bool
|
bool |