@@ -42,7 +42,7 @@ impl GymEnv {
42
42
/// Creates a new session of the specified OpenAI Gym environment.
43
43
pub fn new ( name : & str ) -> Result < GymEnv > {
44
44
Python :: with_gil ( |py| {
45
- let gym = py. import ( "gymnasium" ) ?;
45
+ let gym = py. import_bound ( "gymnasium" ) ?;
46
46
let make = gym. getattr ( "make" ) ?;
47
47
let env = make. call1 ( ( name, ) ) ?;
48
48
let action_space = env. getattr ( "action_space" ) ?;
@@ -66,10 +66,10 @@ impl GymEnv {
66
66
/// Resets the environment, returning the observation tensor.
67
67
pub fn reset ( & self , seed : u64 ) -> Result < Tensor > {
68
68
let state: Vec < f32 > = Python :: with_gil ( |py| {
69
- let kwargs = PyDict :: new ( py) ;
69
+ let kwargs = PyDict :: new_bound ( py) ;
70
70
kwargs. set_item ( "seed" , seed) ?;
71
- let state = self . env . call_method ( py, "reset" , ( ) , Some ( kwargs) ) ?;
72
- state. as_ref ( py) . get_item ( 0 ) ?. extract ( )
71
+ let state = self . env . call_method_bound ( py, "reset" , ( ) , Some ( & kwargs) ) ?;
72
+ state. bind ( py) . get_item ( 0 ) ?. extract ( )
73
73
} )
74
74
. map_err ( w) ?;
75
75
Tensor :: new ( state, & Device :: Cpu )
@@ -81,8 +81,10 @@ impl GymEnv {
81
81
action : A ,
82
82
) -> Result < Step < A > > {
83
83
let ( state, reward, terminated, truncated) = Python :: with_gil ( |py| {
84
- let step = self . env . call_method ( py, "step" , ( action. clone ( ) , ) , None ) ?;
85
- let step = step. as_ref ( py) ;
84
+ let step = self
85
+ . env
86
+ . call_method_bound ( py, "step" , ( action. clone ( ) , ) , None ) ?;
87
+ let step = step. bind ( py) ;
86
88
let state: Vec < f32 > = step. get_item ( 0 ) ?. extract ( ) ?;
87
89
let reward: f64 = step. get_item ( 1 ) ?. extract ( ) ?;
88
90
let terminated: bool = step. get_item ( 2 ) ?. extract ( ) ?;
0 commit comments