experiment

Experiment framework for the coding experiments library.

This module provides the infrastructure for running coding experiments, including experiment runners and result data structures. It enables systematic evaluation of different coding schemes and channel models.

class codinglab.experiment.ExperimentResult(stats, start_time, end_time, metadata=<factory>)[source]

Bases: object

Results from a coding experiment run.

This class encapsulates all data collected during an experiment, including statistics, timing information, and any additional metadata. It provides computed properties for common analysis and can be serialized for storage or further processing.

Parameters:
stats: TransmissionStats

Transmission statistics collected during the experiment.

start_time: float

Experiment start time in seconds since epoch.

end_time: float

Experiment end time in seconds since epoch.

metadata: Dict[str, Any]

Additional experiment metadata as key-value pairs.

property duration: float

Calculate the total duration of the experiment.

Returns:

Experiment duration in seconds

summary()[source]

Generate a human-readable summary of experiment results.

Return type:

str

Returns:

Formatted string with key experiment metrics

__init__(stats, start_time, end_time, metadata=<factory>)
Parameters:
Return type:

None

class codinglab.experiment.ExperimentRunner(sender, channel, receiver)[source]

Bases: object

Orchestrates and runs coding experiments.

This class coordinates the interaction between sender, channel, and receiver components to run complete transmission experiments. It manages the data flow, timing, and result collection.

Parameters:
__init__(sender, channel, receiver)[source]

Initialize the experiment runner with component instances.

Parameters:
  • sender (Sender[TypeVar(SourceChar), TypeVar(ChannelChar)]) – Sender instance for generating and encoding messages

  • channel (Channel[TypeVar(ChannelChar)]) – Channel instance for transmitting messages

  • receiver (TrackingReceiver[TypeVar(SourceChar), TypeVar(ChannelChar)]) – TrackingReceiver instance for collecting stats

Raises:

TypeError – If receiver is not a TrackingReceiver instance

Return type:

None

sender

Sender instance for generating and encoding messages.

channel

Channel instance for transmitting messages.

receiver

TrackingReceiver instance for receiving and decoding messages.

run(num_messages=100)[source]

Run a coding experiment with the configured components.

This method executes the complete transmission pipeline: 1. Generate and encode messages using the sender 2. Transmit messages through the channel 3. Receive, decode, and track messages using the receiver 4. Collect and return experiment results

Parameters:

num_messages (int) – Number of messages to transmit (default: 100)

Return type:

ExperimentResult

Returns:

ExperimentResult object containing all experiment data

Raises:

ValueError – If num_messages <= 0