jxx123 / simglucose

A Type-1 Diabetes simulator implemented in Python for Reinforcement Learning purpose
MIT License
232 stars 109 forks source link

Scenario with no meal in gym env #45

Open maxime-louis opened 2 years ago

maxime-louis commented 2 years ago

Hey,

Thank you for this awesome library.

I'm trying to run a gym env without any meal (ideally I would like a controller which can also suggest carb but from what I understood it's not supported).

I did the following:

start_time = datetime.now()
no_meal_scenario = CustomScenario(start_time=start_time, scenario=[])

register(
    id='env-v0',
    entry_point='simglucose.envs:T1DSimEnv',
    kwargs={'patient_name': 'adult#001',
           'custom_scenario': no_meal_scenario}
)

env = gym.make('env-v0')

min_insulin = env.action_space.low
max_insulin = env.action_space.high

observation = env.reset()
for t in range(100):
    env.render(mode='human')
    print(observation)
    action = np.random.uniform(min_insulin, max_insulin)

    print(action)
    observation, reward, done, info = env.step(action)
    if done:
        print("Episode finished after {} timesteps".format(t + 1))
        break

But I still het carbohydrates inputs sometimes: image

What is the correct way to do that ? Thank you !

jingyi-y commented 2 years ago

Same question here. It seems that custom scenario is not correctly handled in OpenAI Gym.

jxx123 commented 2 years ago

Yes, I did not expose the meal as an action here. I treat the random meal as a challenge for the control algorithm. You might want to implement the meal action yourself for now.

I will consider adding meal as an input in the future.