This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GymHandler(Handler): | |
# ... | |
def setup(self) -> None: | |
self._task_id = self.context.task_manager.enqueue_task(self.task) | |
# ... | |
class GymTask(Task): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GymTask(Task): | |
# ... | |
def execute(self, *args: Any, **kwargs: Any) -> None: | |
if not self._proxy_env.is_rl_agent_trained and not self.is_rl_agent_training: | |
self._start_training() | |
if self._proxy_env.is_rl_agent_trained and self.is_rl_agent_training: | |
self._stop_training() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Action = Any | |
Observation = Any | |
Reward = float | |
Done = bool | |
Info = dict | |
Feedback = Tuple[Observation, Reward, Done, Info] | |
NB_STEPS = 500 | |
class ProxyEnv(gym.Env): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GymTask(Task): | |
# ... | |
def _fit(self, proxy_env: ProxyEnv, nb_steps: int) -> None: | |
"""Fit the RL agent.""" | |
self._rl_agent.fit(proxy_env, nb_steps) | |
# ... | |
class MyRLAgent(RLAgent): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PriceBandit: | |
def __init__(self, price: float, beta_a: float = 1.0, beta_b: float = 1.0): | |
self.price = price | |
# default params imply a uniform random prior | |
self.beta_a = beta_a | |
self.beta_b = beta_b | |
def sample(self) -> int: | |
return round(np.random.beta(self.beta_a, self.beta_b)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.7.0 <0.9.0; | |
contract Chat { | |
struct Message { | |
uint id; | |
address from; | |
string text; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.7.0 <0.9.0; | |
contract Chat { | |
struct Message { | |
uint id; | |
address from; | |
string message; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.7.0 <0.9.0; | |
contract Chat { | |
// ... | |
// We can use an autoincremental id for each new message. | |
uint lastMessageId; | |
function sendMessage(string _text) public { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.7.0 <0.9.0; | |
contract Chat { | |
// the list of old messages in the chat | |
mapping(uint => Message) public messagesList; | |
function listMessages() public constant returns (uint[]){ | |
// if the chat is empty | |
if(lastMessageId == 0) { |