12
12
from datetime import datetime
13
13
import gymnasium
14
14
15
-
16
15
PATIENT_PARA_FILE = pkg_resources .resource_filename (
17
- "simglucose" , "params/vpatient_params.csv"
18
- )
16
+ "simglucose" , "params/vpatient_params.csv" )
19
17
20
18
21
19
class T1DSimEnv (gym .Env ):
@@ -28,9 +26,11 @@ class T1DSimEnv(gym.Env):
28
26
SENSOR_HARDWARE = "Dexcom"
29
27
INSULIN_PUMP_HARDWARE = "Insulet"
30
28
31
- def __init__ (
32
- self , patient_name = None , custom_scenario = None , reward_fun = None , seed = None
33
- ):
29
+ def __init__ (self ,
30
+ patient_name = None ,
31
+ custom_scenario = None ,
32
+ reward_fun = None ,
33
+ seed = None ):
34
34
"""
35
35
patient_name must be 'adolescent#001' to 'adolescent#010',
36
36
or 'adult#001' to 'adult#010', or 'child#001' to 'child#010'
@@ -79,20 +79,19 @@ def _create_env(self):
79
79
80
80
if isinstance (self .patient_name , list ):
81
81
patient_name = self .np_random .choice (self .patient_name )
82
- patient = T1DPatient .withName (patient_name , random_init_bg = True , seed = seed4 )
82
+ patient = T1DPatient .withName (patient_name ,
83
+ random_init_bg = True ,
84
+ seed = seed4 )
83
85
else :
84
- patient = T1DPatient .withName (
85
- self . patient_name , random_init_bg = True , seed = seed4
86
- )
86
+ patient = T1DPatient .withName (self . patient_name ,
87
+ random_init_bg = True ,
88
+ seed = seed4 )
87
89
88
90
if isinstance (self .custom_scenario , list ):
89
91
scenario = self .np_random .choice (self .custom_scenario )
90
92
else :
91
- scenario = (
92
- RandomScenario (start_time = start_time , seed = seed3 )
93
- if self .custom_scenario is None
94
- else self .custom_scenario
95
- )
93
+ scenario = (RandomScenario (start_time = start_time , seed = seed3 ) if
94
+ self .custom_scenario is None else self .custom_scenario )
96
95
97
96
sensor = CGMSensor .withName (self .SENSOR_HARDWARE , seed = seed2 )
98
97
pump = InsulinPump .withName (self .INSULIN_PUMP_HARDWARE )
@@ -109,19 +108,19 @@ def _close(self):
109
108
@property
110
109
def action_space (self ):
111
110
ub = self .env .pump ._params ["max_basal" ]
112
- return spaces .Box (low = 0 , high = ub , shape = (1 ,))
111
+ return spaces .Box (low = 0 , high = ub , shape = (1 , ))
113
112
114
113
@property
115
114
def observation_space (self ):
116
- return spaces .Box (low = 0 , high = 1000 , shape = (1 ,))
115
+ return spaces .Box (low = 0 , high = 1000 , shape = (1 , ))
117
116
118
117
@property
119
118
def max_basal (self ):
120
119
return self .env .pump ._params ["max_basal" ]
121
120
122
121
123
122
class T1DSimGymnaisumEnv (gymnasium .Env ):
124
- metadata = {"render_modes" : ["human" ]}
123
+ metadata = {"render_modes" : ["human" ], "render_fps" : 60 }
125
124
MAX_BG = 1000
126
125
127
126
def __init__ (
@@ -140,12 +139,14 @@ def __init__(
140
139
reward_fun = reward_fun ,
141
140
seed = seed ,
142
141
)
143
- self .observation_space = gymnasium .spaces .Box (
144
- low = 0 , high = self .MAX_BG , shape = (1 ,), dtype = np .float32
145
- )
146
- self .action_space = gymnasium .spaces .Box (
147
- low = 0 , high = self .env .max_basal , shape = (1 ,), dtype = np .float32
148
- )
142
+ self .observation_space = gymnasium .spaces .Box (low = 0 ,
143
+ high = self .MAX_BG ,
144
+ shape = (1 , ),
145
+ dtype = np .float32 )
146
+ self .action_space = gymnasium .spaces .Box (low = 0 ,
147
+ high = self .env .max_basal ,
148
+ shape = (1 , ),
149
+ dtype = np .float32 )
149
150
150
151
def step (self , action ):
151
152
obs , reward , done , info = self .env .step (action )
@@ -159,7 +160,8 @@ def step(self, action):
159
160
# )
160
161
# Once the max_episode_steps is set, the truncated value will be overridden.
161
162
truncated = False
162
- return np .array ([obs .CGM ], dtype = np .float32 ), reward , done , truncated , info
163
+ return np .array ([obs .CGM ],
164
+ dtype = np .float32 ), reward , done , truncated , info
163
165
164
166
def reset (self , seed = None , options = None ):
165
167
super ().reset (seed = seed )
0 commit comments