types

Data types and protocols for the coding experiments library.

This module defines the core data structures, type aliases, and protocols used throughout the library for representing messages, transmission events, logs, and experimental configurations.

class codinglab.types.Symbol

Generic type variable representing any symbol type.

alias of TypeVar(‘Symbol’)

class codinglab.types.SourceChar

Type variable for source alphabet symbols (input to encoder).

alias of TypeVar(‘SourceChar’)

class codinglab.types.ChannelChar

Type variable for channel alphabet symbols (output from encoder).

alias of TypeVar(‘ChannelChar’)

class codinglab.types.Message(id, data)[source]

Bases: Generic[Symbol]

A message containing a sequence of symbols.

This class represents a message as an immutable sequence of symbols with a unique identifier for tracking purposes.

Parameters:
id: int

Unique identifier for the message.

data: Sequence[Symbol]

Sequence of symbols comprising the message.

__init__(id, data)
Parameters:
Return type:

None

class codinglab.types.TransmissionEvent(*values)[source]

Bases: str, Enum

Events that occur during message transmission.

These events are logged throughout the transmission pipeline for monitoring, debugging, and analysis purposes.

SOURCE_GENERATED = 'source_generated'

Event when a source message is generated.

ENCODED = 'encoded'

Event when a message is encoded.

TRANSMITTED = 'transmitted'

Event when a message is transmitted through a channel.

RECEIVED = 'received'

Event when a message is received from a channel.

DECODED = 'decoded'

Event when a message is decoded.

VALIDATED = 'validated'

Event when a message is validated.

ERROR = 'error'

Event when an error occurs during transmission.

class codinglab.types.TransmissionLog(timestamp, event, message, data)[source]

Bases: Generic[Symbol]

Log entry for a transmission event.

Contains detailed information about a specific event in the transmission pipeline, including timing, message data, and additional context.

Parameters:
__init__(timestamp, event, message, data)
Parameters:
Return type:

None

timestamp: float

Time of the event in seconds since epoch.

event: TransmissionEvent

Type of transmission event.

message: Message[Symbol]

The message associated with the event.

data: Dict[str, Any]

Additional event-specific data as key-value pairs.

class codinglab.types.TransmissionLogger(*args, **kwargs)[source]

Bases: Protocol

Protocol for logging transmission events.

Implementations of this protocol are responsible for handling log entries generated during message transmission, which can be used for monitoring, debugging, or analytics.

__init__(*args, **kwargs)
log(log_entry)[source]

Log a transmission event.

Parameters:

log_entry (TransmissionLog) – The transmission log entry to record

Return type:

None