def test_unique_clients(self): # Using ints as a computation won't actually be run client0 = 1 r0 = ReflectiveReward(0) rf0 = rewards.RewardFactory(client0) rf0.register_reward(1, r0) client1 = 2 r1 = ReflectiveReward(1) rf1 = rewards.RewardFactory(client1) rf1.register_reward(1, r1) self.assertEqual(client0, r0.client) self.assertEqual(client1, r1.client)
def __init__(self, config: configs.Solo8BaseConfig, use_gui: bool): """Create a solo8 env. Args: config (configs.Solo8BaseConfig): The SoloConfig. Defaults to None. use_gui (bool): Whether or not to show the pybullet GUI. Defaults to False. """ self.config = config self.client = bc.BulletClient( connection_mode=p.GUI if use_gui else p.DIRECT) self.client.setAdditionalSearchPath(pbd.getDataPath()) self.client.setGravity(*self.config.gravity) if self.config.dt: self.client.setPhysicsEngineParameter(fixedTimeStep=self.config.dt, numSubSteps=1) else: self.client.setRealTimeSimulation(1) self.client_configuration() self.plane = self.client.loadURDF('plane.urdf') self.load_bodies() self.obs_factory = obs.ObservationFactory(self.client) self.reward_factory = rewards.RewardFactory(self.client) self.termination_factory = terms.TerminationFactory() self.reset(init_call=True)
def test_register_and_compute(self, name, rewards_dict, expected_reward): client = bullet_client.BulletClient(connection_mode=p.DIRECT) rf = rewards.RewardFactory(client) for weight, reward in rewards_dict.items(): rf.register_reward(weight, ReflectiveReward(reward)) self.assertEqual(rf.get_reward(), expected_reward) client.disconnect()
def test_empty(self): rf = rewards.RewardFactory(None) self.assertListEqual(rf._rewards, []) with self.assertRaises(ValueError): rf.get_reward()