Simulation
ExperimentConfig requires a seed and names the independent dimensions as
n_replicates and horizon. Common reward coupling is the default paired
design; independent policy reward streams are available explicitly.
Results contain read-only arrays and recursively immutable configuration,
metadata, and provenance. Use SimulationResult.equals instead of dataclass
== for value comparison. JSON and NPZ save methods are atomic, normalize a
missing suffix, and return the actual destination path.
Contextual runs record a digest by default. Set record_contexts=True to keep
the complete context tensor when downstream auditing requires it.
Reproducible experiment orchestration.
- class BackendCompatibilityReport[source]
Bases:
objectComplete explanation of whether an experiment can run natively.
- class Experiment[source]
Bases:
objectRun named policies against a reproducible simulated environment.
- __init__(*, environment, policies, config, metadata=None)[source]
- Parameters:
environment (ClassicEnvironment | ContextualEnvironment)
policies (Mapping[str, Policy | ContextualPolicy])
config (ExperimentConfig)
metadata (Mapping[str, None | bool | int | float | str | tuple[None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue], ...] | Mapping[str, None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue]]] | None)
- Return type:
None
- class ExperimentConfig[source]
Bases:
objectConfiguration for independent replicated bandit experiments.
Validated immutable simulation results and derived metrics.
- class SimulationResult[source]
Bases:
objectRead-only observations, ground truth, configuration, and provenance.
- config: Mapping[str, None | bool | int | float | str | tuple[None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue], ...] | Mapping[str, None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue]]]
- provenance: RunProvenance
- metadata: Mapping[str, None | bool | int | float | str | tuple[None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue], ...] | Mapping[str, None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue]]]
- classmethod from_dict(payload)[source]
Construct a result through the versioned persistence schema.
- Parameters:
- Return type:
- classmethod load_npz(path)[source]
Load and validate a compressed result archive.
- Parameters:
- Return type:
- __init__(rewards, actions, expected_rewards, arm_means, optimal_mask, recommendations, policy_ids, replicate_seeds, config, provenance, metadata=<factory>, contexts=None, context_digest=None, schema_version=3, library_version='')
- Parameters:
config (Mapping[str, None | bool | int | float | str | tuple[None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue], ...] | Mapping[str, None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue]]])
provenance (RunProvenance)
metadata (Mapping[str, None | bool | int | float | str | tuple[None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue], ...] | Mapping[str, None | bool | int | float | str | tuple[JSONValue, ...] | Mapping[str, JSONValue]]])
context_digest (str | None)
schema_version (int)
library_version (str)
- Return type:
None
Metrics computed from simulation results.
- average_reward_by_step(result)[source]
Mean realized reward per step and policy.
- Parameters:
result (SimulationResult)
- Return type:
- best_arm_identification_rate_by_step(result)[source]
Fraction of replicates recommending any optimal arm.
- Parameters:
result (SimulationResult)
- Return type:
- cumulative_regret_by_step(result)[source]
Cumulative expected regret averaged across replicates.
- Parameters:
result (SimulationResult)
- Return type:
- cumulative_reward_by_step(result)[source]
Cumulative mean realized reward per step and policy.
- Parameters:
result (SimulationResult)
- Return type:
- expected_regret_by_step(result)[source]
Expected regret per replicate, step, and policy.
- Parameters:
result (SimulationResult)
- Return type:
- optimal_action_rate_by_step(result)[source]
Share of replicates selecting an optimal action at each step.
- Parameters:
result (SimulationResult)
- Return type:
- simple_regret_by_step(result)[source]
Mean recommendation regret per step and policy.
- Parameters:
result (SimulationResult)
- Return type: