Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions src/box_2d/lunar_lander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tensor, Self::Error> {
self.destroy();
Expand Down Expand Up @@ -1165,7 +1166,7 @@ impl Gym for LunarLanderV3 {
})
}

fn observation_space(&self) -> Box<dyn Space> {
fn observation_space(&self) -> Box<dyn Space<Error = Self::SpaceError>> {
let low = vec![
-2.5,
-2.5,
Expand Down Expand Up @@ -1193,9 +1194,9 @@ impl Gym for LunarLanderV3 {
Box::new(spaces::BoxSpace::new(low_tensor, high_tensor))
}

fn action_space(&self) -> Box<dyn Space> {
fn action_space(&self) -> Box<dyn Space<Error = Self::SpaceError>> {
// 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))
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/classic_control/cartpole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Tensor, Self::Error> {
self.steps_beyond_terminated = None;
Expand Down Expand Up @@ -346,11 +347,11 @@ impl Gym for CartPoleV1 {
}
}

fn observation_space(&self) -> Box<dyn Space> {
fn observation_space(&self) -> Box<dyn Space<Error = Self::SpaceError>> {
Box::new(self.observation_space.clone())
}

fn action_space(&self) -> Box<dyn Space> {
fn action_space(&self) -> Box<dyn Space<Error = Self::SpaceError>> {
Box::new(self.action_space.clone())
}
}
Expand Down Expand Up @@ -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: _,
Expand Down
9 changes: 5 additions & 4 deletions src/classic_control/mountain_car.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Tensor, Self::Error> {
// Initialize position uniformly between -0.6 and -0.4
Expand Down Expand Up @@ -328,11 +329,11 @@ impl Gym for MountainCarV0 {
})
}

fn observation_space(&self) -> Box<dyn Space> {
fn observation_space(&self) -> Box<dyn Space<Error = Self::SpaceError>> {
Box::new(self.observation_space.clone())
}

fn action_space(&self) -> Box<dyn Space> {
fn action_space(&self) -> Box<dyn Space<Error = Self::SpaceError>> {
Box::new(self.action_space.clone())
}
}
Expand Down Expand Up @@ -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: _,
Expand Down