def test_state_to_csv_from_csv_no_reward(): original_state = CompilerEnvState(benchmark="foo", walltime=100, commandline="-a -b -c") state_from_csv = CompilerEnvState.from_csv(original_state.to_csv()) assert state_from_csv.benchmark == "foo" assert state_from_csv.walltime == 100 assert state_from_csv.reward is None assert state_from_csv.commandline == "-a -b -c"
def test_state_to_csv_from_csv(env: LlvmEnv): env.reset(benchmark="cBench-v0/crc32") env.episode_reward = 10 state = env.state assert state.reward == 10 state_from_csv = CompilerEnvState.from_csv(env.state.to_csv()) assert state_from_csv.reward == 10 assert state == state_from_csv
def test_validate_states_lambda_callback(): state = CompilerEnvState( benchmark="cBench-v0/crc32", walltime=1, commandline="opt input.bc -o output.bc", ) results = list( validate_states(make_env=lambda: gym.make("llvm-v0"), states=[state], datasets=["cBench-v0"])) assert len(results) == 1 assert results[0].success
def test_validate_state_no_reward(): state = CompilerEnvState( benchmark="cBench-v0/dijkstra", walltime=1, commandline="opt input.bc -o output.bc", ) env = gym.make("llvm-v0") try: result = validate_state(env, state) finally: env.close() assert result.success assert not result.failed assert not result.reward_validated assert str(result) == "✅ cBench-v0/dijkstra"
def test_validate_state_with_reward(): state = CompilerEnvState( benchmark="cBench-v0/crc32", walltime=1, reward=0, commandline="opt input.bc -o output.bc", ) env = gym.make("llvm-v0", reward_space="IrInstructionCount") try: env.require_dataset("cBench-v0") result = validate_state(env, state) finally: env.close() assert result.success assert not result.failed assert result.reward_validated assert not result.reward_validation_failed assert str(result) == "✅ cBench-v0/crc32 0.0000"
def test_validate_state_invalid_reward(): state = CompilerEnvState( benchmark="cBench-v0/dijkstra", walltime=1, reward=1, commandline="opt input.bc -o output.bc", ) env = gym.make("llvm-v0", reward_space="IrInstructionCount") try: result = validate_state(env, state) finally: env.close() assert not result.success assert result.failed assert result.reward_validated assert result.reward_validation_failed assert ( str(result) == "❌ cBench-v0/dijkstra Expected reward 1.0000 but received reward 0.0000" )
def test_state_from_csv_invalid_format(): with pytest.raises(ValueError) as ctx: CompilerEnvState.from_csv("abcdef") assert str(ctx.value).startswith("Failed to parse input: `abcdef`: ")
def test_state_from_csv_empty(): with pytest.raises(ValueError) as ctx: CompilerEnvState.from_csv("") assert str(ctx.value) == "Failed to parse input: ``"