def __init__(self, theta_threshold_radians: float, x_threshold: float, reward_aggregator: RewardAggregatorInterface): super().__init__() self.theta_threshold_radians = theta_threshold_radians self.x_threshold = x_threshold # init pubsub for event to reward routing self.pubsub = Pubsub(self.context.event_service) # KPIs calculation self.kpi_calculator = CartPoleKpiCalculator() # init reward and register it with pubsub self.reward_aggregator = Factory(RewardAggregatorInterface).instantiate(reward_aggregator) self.pubsub.register_subscriber(self.reward_aggregator) # setup environment self.cart_position = None self.cart_velocity = None self.pole_angle = None self.pole_velocity = None self.env_rng: Optional[np.random.RandomState] = None self.seed(None) self._setup_env() # initialize rendering self.renderer = CartPoleRenderer(pole_length=self.length, x_threshold=self.x_threshold)
def test_wrong_arguments(): pubsub = Pubsub(EventService()) topic = pubsub.create_event_topic(DummyInterface) with pytest.raises(TypeError): # noinspection PyArgumentList topic.event2(wrong_name=1)
def __init__(self, max_pieces_in_inventory: int, raw_piece_size: Tuple[int, int], static_demand: List[Tuple[int, int]], reward_aggregator: RewardAggregatorInterface): super().__init__() self.max_pieces_in_inventory = max_pieces_in_inventory self.raw_piece_size = tuple(raw_piece_size) self.static_demand = static_demand # init current demand self.current_demand = None self.demand_idx = 0 # initialize rendering self.renderer = Cutting2DRenderer() # init pubsub for event to reward routing self.pubsub = Pubsub(self.context.event_service) # KPIs calculation self.kpi_calculator = Cutting2dKpiCalculator() # setup environment self._setup_env() # init reward and register it with pubsub self.reward_aggregator = reward_aggregator self.pubsub.register_subscriber(self.reward_aggregator)
def __init__(self, observation_space): super().__init__(observation_space) self.reward_aggregator = CustomDummyRewardAggregator() self.maze_state = self.observation_space.sample() self.pubsub: Pubsub = Pubsub(self.context.event_service) self.pubsub.register_subscriber(self.reward_aggregator) self.base_event_publisher = self.pubsub.create_event_topic(BaseEnvEvents) self.renderer = DummyRenderer()
def __init__(self, observation_space): super().__init__(observation_space) self.reward_aggregator = CustomDummyRewardAggregator() self.pubsub: Pubsub = Pubsub(self.context.event_service) self.pubsub.register_subscriber(self.reward_aggregator) self.base_event_publisher = self.pubsub.create_event_topic( BaseEnvEvents) self.kpi_calculator = CustomDummyKPICalculator()
def __init__(self, max_pieces_in_inventory: int, raw_piece_size: (int, int), static_demand: (int, int)): super().__init__() ... # init pubsub for event to reward routing self.pubsub = Pubsub(self.context.event_service) # KPIs calculation self.kpi_calculator = Cutting2dKpiCalculator()
def __init__(self, observation_space: gym.spaces.space.Space): super().__init__() self.pubsub = Pubsub(self.context.event_service) self.dummy_core_events = self.pubsub.create_event_topic(DummyEnvEvents) self.reward_aggregator = RewardAggregator() self.pubsub.register_subscriber(self.reward_aggregator) self.observation_space = observation_space # initialize rendering self.renderer = DummyMatplotlibRenderer()
def __init__(self, max_pieces_in_inventory: int, raw_piece_size: (int, int), static_demand: (int, int)): super().__init__() self.max_pieces_in_inventory = max_pieces_in_inventory self.raw_piece_size = tuple(raw_piece_size) self.current_demand = static_demand # initialize rendering self.renderer = Cutting2DRenderer() # init pubsub for event to reward routing self.pubsub = Pubsub(self.context.event_service) # KPIs calculation self.kpi_calculator = Cutting2dKpiCalculator() # setup environment self._setup_env()
def test_pubsub_topic(): pubsub = Pubsub(EventService()) subscriber = DummySubscriber() publisher = pubsub.create_event_topic(DummyInterface) pubsub.register_subscriber(subscriber) publisher.event1() publisher.event2(param1=1, param2=2) assert len(subscriber.events) == 2 record = subscriber.events[0] assert record.interface_method == DummyInterface.event1 assert record.attributes == dict() record = subscriber.events[1] assert record.interface_method == DummyInterface.event2 assert record.attributes == dict(param1=1, param2=2)