Benchmarks (puxle.benchmark)¶
Benchmark infrastructure for evaluating puzzle-solving algorithms against known-optimal solutions.
BenchmarkSample¶
Benchmark (Base)¶
- class puxle.benchmark.benchmark.Benchmark[source]¶
Bases:
ABC,Generic[StateT,SolveConfigT]Abstract base class for a benchmark dataset.
Subclasses must implement:
build_puzzle()— create thePuzzleinstance.load_dataset()— load or generate the raw dataset.sample_ids()— enumerate available sample IDs.get_sample()— retrieve aBenchmarkSampleby ID.
The base class provides lazy caching for
puzzleanddatasetand a genericverify_solution()that checks both validity (is the final state solved?) and optimality (is the cost ≤ optimal?).- abstractmethod build_puzzle()[source]¶
Instantiate the puzzle that defines this benchmark.
- Return type:
- abstractmethod load_dataset()[source]¶
Return the raw dataset object backing the benchmark.
- Return type:
- abstractmethod get_sample(sample_id)[source]¶
Fetch the state, solve configuration and optimal action sequence for a sample.
- Return type:
BenchmarkSample[TypeVar(StateT, bound=PuzzleState),TypeVar(SolveConfigT, bound=PuzzleState)]- Parameters:
sample_id (Hashable)
- verify_solution(sample, states=None, action_sequence=None)[source]¶
Verify that a solution is valid and optimal for the given sample.
If action_sequence or states are provided, they are treated as the candidate solution. Otherwise, verifies sample.optimal_action_sequence.
- Returns:
if valid (solved) and length matches optimal (<= optimal cost). - False: if invalid (not solved) or suboptimal (> optimal cost). - None: if valid (solved) but sample has no optimal info to compare against.
- Return type:
True
- Parameters:
DeepCubeA Utilities¶
- class puxle.benchmark._deepcubea.DeepCubeAUnpickler[source]¶
Bases:
UnpicklerUnpickler that recreates missing DeepCubeA environment classes on the fly.
- find_class(module, name)[source]¶
Return an object from a specified module.
If necessary, the module will be imported. Subclasses may override this method (e.g. to restrict unpickling of arbitrary classes and functions).
This method is called whenever a class or a function object is needed. Both arguments passed are str objects.
- puxle.benchmark._deepcubea.load_deepcubea(handle)[source]¶
Helper that loads a DeepCubeA pickle with the compatible unpickler.
RubiksCube Benchmarks¶
SlidePuzzle Benchmarks¶
LightsOut Benchmarks¶
- class puxle.benchmark.lightsout_deepcubea.LightsOutDeepCubeABenchmark[source]¶
Bases:
BenchmarkBenchmark that exposes the DeepCubeA LightsOut dataset.
- get_sample(sample_id)[source]¶
Fetch the state, solve configuration and optimal action sequence for a sample.
- Return type:
BenchmarkSample- Parameters:
sample_id (Hashable)