def test_get_observation_space_and_history_not_a_version():
    '''
    Test the get_observation_space_and_history function with invalid version.
    '''
    shape = (5, 5)
    max_history = 10
    with pytest.raises(RuntimeError):
        utils.get_obs_version(shape, max_history, version=-1)
def test_get_observation_space_and_history_v4():
    '''Test the get_observation_space_and_history function version 4.'''
    shape = (5, 5)
    max_history = 10
    space, hist = utils.get_obs_version(shape, max_history, version=4)
    assert isinstance(space, gym.spaces.Box)
    assert isinstance(hist, utils_common.History)
    assert hist.max_history == max_history
    assert {'gradients'} == hist.keys()
    assert space.shape == (max_history, )
    assert np.all(space.low == -1e6)
    assert np.all(space.high == 1e6)
    assert space.dtype == np.float32
    def __init__(self,
                 data_set='iris',
                 batch_size=None,
                 version=1,
                 max_batches=400,
                 max_history=5,
                 observation_version=0,
                 action_version=0,
                 reward_version=0):
        super().__init__()
        self.model = get_problem(data_set=load_data(data_set, batch_size))
        model_size = (self.model.size, )
        self.history = History(5,
                               losses=(),
                               gradients=model_size,
                               weights=model_size)
        result = utils_env.get_obs_version(model_size, max_history, version)
        obs_space, self.adjusted_history = result
        if action_version == 0:
            action_low = -4.
            action_high = 4.
        elif action_version == 1:
            action_low = -1e8
            action_high = 1e8
        else:
            raise RuntimeError()

        self.observation_space = Dict({
            MultiOptimize.AGENT_FMT.format(i): obs_space
            for i in range(self.model.size)
        })
        self.action_space = Dict({
            MultiOptimize.AGENT_FMT.format(i): Box(low=action_low,
                                                   high=action_high,
                                                   dtype=np.float32,
                                                   shape=(1, ))
            for i in range(self.model.size)
        })
        self.seed()
        self.max_history = max_history
        self.max_batches = max_batches
        self.version = VersionType(version, observation_version,
                                   action_version, reward_version)
    def __init__(self, problem='func', max_batches=400, max_history=5):
        super().__init__()
        self.model = get_problem(problem)
        self.history = History(5,
                               losses=(),
                               gradients=(self.model.size, ),
                               weights=(self.model.size, ))
        result = utils_env.get_obs_version((self.model.size, ), max_history, 3)
        obs_space, self.adjusted_history = result
        act_space = utils_env.get_action_space_optlrs(2)

        self.observation_space = Dict({
            MultiOptLRs.AGENT_FMT.format(i): obs_space
            for i in range(self.model.size)
        })
        self.action_space = Dict({
            MultiOptLRs.AGENT_FMT.format(i): act_space
            for i in range(self.model.size)
        })
        self.seed()
        self.max_history = max_history
        self.max_batches = max_batches
        self.version = VersionType(3, 3, 0, 6)