Esempio n. 1
0
def test_eager_observation_space(env: CompilerEnv):
    env.eager_observation_space = "Autophase"
    assert env.eager_observation_space == "Autophase"

    env.eager_observation_space = None
    assert env.eager_observation_space is None

    invalid = "invalid value"
    with pytest.raises(LookupError) as ctx:
        env.eager_observation_space = invalid
    assert str(ctx.value) == f"Observation space not found: {invalid}"
Esempio n. 2
0
def test_eager_features_observation(env: CompilerEnv, ):
    env.eager_observation_space = "features"
    observation = env.reset()
    assert isinstance(observation, np.ndarray)
    assert observation.shape == (3, )
    assert observation.dtype == np.int64
    assert observation.tolist() == [0, 0, 0]
Esempio n. 3
0
def test_eager_ir_observation(env: CompilerEnv):
    env.eager_observation_space = "ir"
    observation = env.reset()
    assert observation == "Hello, world!"

    observation, reward, done, info = env.step(0)
    assert observation == "Hello, world!"
    assert reward is None
    assert not done
def test_step(env: CompilerEnv, observation_space: str, reward_space: str):
    """Request every combination of observation and reward in a fresh environment."""
    env.eager_reward_space = None
    env.eager_observation_space = None
    env.reset(benchmark="cBench-v0/crc32")

    observation = env.observation[observation_space]
    assert observation is not None

    reward = env.reward[reward_space]
    assert reward is not None
def test_step(env: CompilerEnv, action_name: str):
    """Run each action on a single benchmark."""
    env.eager_reward_space = "IrInstructionCount"
    env.eager_observation_space = "Autophase"
    env.reset(benchmark="cBench-v0/crc32")
    observation, reward, done, info = env.step(
        env.action_space.from_string(action_name)
    )

    if done:
        assert observation is None
        assert reward is None
    else:
        assert isinstance(observation, np.ndarray)
        assert observation.shape == (56,)
        assert reward < 0
Esempio n. 6
0
def test_service_env_dies_reset(env: CompilerEnv):
    env.eager_observation_space = "Autophase"
    env.eager_reward_space = "IrInstructionCount"
    env.reset("cBench-v0/crc32")

    # Kill the service.
    env.service.close()

    # Check that the environment doesn't fall over.
    observation, reward, done, _ = env.step(0)
    assert done
    assert observation is None
    assert reward is None

    # Reset the environment and check that it works.
    env.reset(benchmark="cBench-v0/crc32")
    observation, reward, done, _ = env.step(0)
    assert not done
    assert observation is not None
    assert reward is not None
Esempio n. 7
0
def test_invalid_eager_observation_space(env: CompilerEnv, ):
    with pytest.raises(LookupError):
        env.eager_observation_space = 100