diff --git a/Cargo.lock b/Cargo.lock index ec2bda5..cf16bb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -924,12 +924,11 @@ dependencies = [ [[package]] name = "modurl" version = "0.1.0" -source = "git+https://github.com/ModuRL/ModuRL#902ec0673bc695f3ba6f17e10ba8f38139d84563" +source = "git+https://github.com/ModuRL/ModuRL?branch=implement-determinism#f23058ff76908602e78ec1d84239960df7d81f14" dependencies = [ "bon", "candle-core", "candle-nn", - "rand", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9a634f4..de93f02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2024" [dependencies] candle-core = { git = "https://github.com/huggingface/candle", rev = "d205fb4" } -modurl = { git = "https://github.com/ModuRL/ModuRL" } +modurl = { git = "https://github.com/ModuRL/ModuRL", branch = "implement-determinism" } tracing = { version = "0.1.37", optional = true } log = { version = "0.4.28", optional = true } box2d-rs = "0.0.4" diff --git a/src/box_2d/lunar_lander.rs b/src/box_2d/lunar_lander.rs index 526eed4..960e878 100644 --- a/src/box_2d/lunar_lander.rs +++ b/src/box_2d/lunar_lander.rs @@ -722,6 +722,7 @@ impl Default for LunarLanderV3 { impl Gym for LunarLanderV3 { type Error = candle_core::Error; + type SpaceError = candle_core::Error; fn reset(&mut self) -> Result { self.destroy(); @@ -1165,7 +1166,7 @@ impl Gym for LunarLanderV3 { }) } - fn observation_space(&self) -> Box { + fn observation_space(&self) -> Box> { let low = vec![ -2.5, -2.5, @@ -1193,9 +1194,9 @@ impl Gym for LunarLanderV3 { Box::new(spaces::BoxSpace::new(low_tensor, high_tensor)) } - fn action_space(&self) -> Box { + fn action_space(&self) -> Box> { // Discrete action space: 0=nop, 1=left engine, 2=main engine, 3=right engine - Box::new(spaces::Discrete::new(4, 0)) + Box::new(spaces::Discrete::new(4)) } } diff --git a/src/classic_control/cartpole.rs b/src/classic_control/cartpole.rs index e48603e..c182dfe 100644 --- a/src/classic_control/cartpole.rs +++ b/src/classic_control/cartpole.rs @@ -65,7 +65,7 @@ impl CartPoleV1 { let high = Tensor::from_vec(high, vec![4], device).expect("Failed to create tensor."); let low = Tensor::from_vec(low, vec![4], device).expect("Failed to create tensor."); - let action_space = spaces::Discrete::new(2, 0); + let action_space = spaces::Discrete::new(2); let observation_space = spaces::BoxSpace::new(low, high); Self { @@ -233,6 +233,7 @@ impl Default for CartPoleV1 { impl Gym for CartPoleV1 { type Error = candle_core::Error; + type SpaceError = candle_core::Error; fn reset(&mut self) -> Result { self.steps_beyond_terminated = None; @@ -346,11 +347,11 @@ impl Gym for CartPoleV1 { } } - fn observation_space(&self) -> Box { + fn observation_space(&self) -> Box> { Box::new(self.observation_space.clone()) } - fn action_space(&self) -> Box { + fn action_space(&self) -> Box> { Box::new(self.action_space.clone()) } } @@ -457,7 +458,7 @@ mod tests { let _state = env.reset().expect("Failed to reset environment."); let action_space = env.action_space(); for _ in 0..200 { - let action = action_space.sample(&Device::Cpu); + let action = action_space.sample(&Device::Cpu).unwrap(); let StepInfo { state: _, reward: _, diff --git a/src/classic_control/mountain_car.rs b/src/classic_control/mountain_car.rs index ee92cd1..d8410aa 100644 --- a/src/classic_control/mountain_car.rs +++ b/src/classic_control/mountain_car.rs @@ -44,7 +44,7 @@ impl MountainCarV0 { let low = Tensor::from_vec(low, vec![2], device).expect("Failed to create tensor."); let high = Tensor::from_vec(high, vec![2], device).expect("Failed to create tensor."); - let action_space = spaces::Discrete::new(3, 0); + let action_space = spaces::Discrete::new(3); let observation_space = spaces::BoxSpace::new(low, high); Self { @@ -274,6 +274,7 @@ impl Default for MountainCarV0 { impl Gym for MountainCarV0 { type Error = candle_core::Error; + type SpaceError = candle_core::Error; fn reset(&mut self) -> Result { // Initialize position uniformly between -0.6 and -0.4 @@ -328,11 +329,11 @@ impl Gym for MountainCarV0 { }) } - fn observation_space(&self) -> Box { + fn observation_space(&self) -> Box> { Box::new(self.observation_space.clone()) } - fn action_space(&self) -> Box { + fn action_space(&self) -> Box> { Box::new(self.action_space.clone()) } } @@ -423,7 +424,7 @@ mod tests { env.reset().unwrap(); let action_space = env.action_space(); for _ in 0..200 { - let action = action_space.sample(&Device::Cpu); + let action = action_space.sample(&Device::Cpu).unwrap(); let StepInfo { state: _, reward: _,