laboroai / border

A reinforcement learning library in Rust
Apache License 2.0
40 stars 8 forks source link

Fails to build #38

Open Boscop opened 3 years ago

Boscop commented 3 years ago

Thanks for working on this crate, it seems to be the only deep RL crate available. Unfortunately I'm getting errors when trying to build it:

D:\3rdparty\border> cargo run --example random_cartpole
   Compiling border v0.0.3 (D:\3rdparty\border)
error[E0308]: mismatched types
  --> src\env\py_gym_env\act_c.rs:65:65
   |
65 |                     let act = PyArrayDyn::<f32>::from_array(py, &act);
   |                                                                 ^^^^ expected struct `ndarray::ArrayBase`, found struct `ArrayBase`
   |
   = note: expected reference `&ndarray::ArrayBase<_, ndarray::dimension::dim::Dim<ndarray::dimension::dynindeximpl::IxDynImpl>>`
              found reference `&ArrayBase<OwnedRepr<f32>, Dim<IxDynImpl>>`
   = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
  --> src\env\py_gym_env\act_c.rs:72:70
   |
72 |                         .map(|act| PyArrayDyn::<f32>::from_array(py, &act))
   |                                                                      ^^^^ expected struct `ndarray::ArrayBase`, found struct `ArrayBase`
   |
   = note: expected reference `&ndarray::ArrayBase<_, ndarray::dimension::dim::Dim<ndarray::dimension::dynindeximpl::IxDynImpl>>`
              found reference `&ArrayBase<ViewRepr<&f32>, Dim<IxDynImpl>>`
   = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
  --> src\env\py_gym_env\act_c.rs:91:57
   |
91 |             let act = PyArrayDyn::<f32>::from_array(py, &act);
   |                                                         ^^^^ expected struct `ndarray::ArrayBase`, found struct `ArrayBase`
   |
   = note: expected reference `&ndarray::ArrayBase<_, ndarray::dimension::dim::Dim<ndarray::dimension::dynindeximpl::IxDynImpl>>`
              found reference `&ArrayBase<OwnedRepr<f32>, Dim<IxDynImpl>>`
   = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
  --> src\env\py_gym_env\act_c.rs:98:62
   |
98 |                 .map(|act| PyArrayDyn::<f32>::from_array(py, &act))
   |                                                              ^^^^ expected struct `ndarray::ArrayBase`, found struct `ArrayBase`
   |
   = note: expected reference `&ndarray::ArrayBase<_, ndarray::dimension::dim::Dim<ndarray::dimension::dynindeximpl::IxDynImpl>>`
              found reference `&ArrayBase<ViewRepr<&f32>, Dim<IxDynImpl>>`
   = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src\env\py_gym_env\framestack.rs:110:9
    |
104 |     fn get_ndarray(o: &PyAny) -> ArrayD<T2> {
    |                                  ---------- expected `ArrayBase<OwnedRepr<T2>, Dim<IxDynImpl>>` because of return type
...
110 |         o
    |         ^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected struct `ArrayBase<OwnedRepr<T2>, Dim<IxDynImpl>>`
               found struct `ndarray::ArrayBase<ndarray::data_repr::OwnedRepr<T2>, ndarray::dimension::dim::Dim<ndarray::dimension::dynindeximpl::IxDynImpl>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
  --> src\env\py_gym_env\obs.rs:43:33
   |
43 |                 obs.insert_axis(Axis(0))
   |                                 ^^^^^^^ expected struct `ndarray::dimension::axis::Axis`, found struct `Axis`
   |
   = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
  --> src\env\py_gym_env\obs.rs:32:5
   |
26 |   pub fn pyobj_to_arrayd<S, T1, T2>(obs: PyObject) -> ArrayD<T2>
   |                                                       ---------- expected `ArrayBase<OwnedRepr<T2>, Dim<IxDynImpl>>` because of return type
...
32 | /     pyo3::Python::with_gil(|py| {
33 | |         let obs: &PyArrayDyn<T1> = obs.extract(py).unwrap();
34 | |         let obs = obs.to_owned_array();
35 | |         // let obs = obs.mapv(|elem| elem as f32);
...  |
48 | |         obs
49 | |     })
   | |______^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
   |
   = note: expected struct `ArrayBase<OwnedRepr<T2>, Dim<IxDynImpl>>`
              found struct `ndarray::ArrayBase<ndarray::data_repr::OwnedRepr<T2>, ndarray::dimension::dim::Dim<ndarray::dimension::dynindeximpl::IxDynImpl>>`
   = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: `if` and `else` have incompatible types
   --> src\env\py_gym_env\obs.rs:200:29
    |
190 | /                         if o.get_type().name().unwrap() == "NoneType" {
191 | |                             ArrayD::zeros(IxDyn(S::shape()))
    | |                             -------------------------------- expected because of this
192 | |                         }
193 | |                         // Processes the partial observation in the vectorized environment.
...   |
200 | |                             obs
    | |                             ^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
201 | |                         }
    | |_________________________- `if` and `else` have incompatible types
    |
    = note: expected type `ArrayBase<OwnedRepr<_>, Dim<IxDynImpl>>`
             found struct `ndarray::ArrayBase<ndarray::data_repr::OwnedRepr<T2>, ndarray::dimension::dim::Dim<ndarray::dimension::dynindeximpl::IxDynImpl>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0308`.
error: could not compile `border`

To learn more, run the command again with --verbose.

D:\3rdparty\border> rustc -V
rustc 1.55.0-nightly (240ff4c4a 2021-07-09)
taku-y commented 3 years ago

@Boscop I'm sorry for bothering you. The error messages seems says that two different versions of crate ndarray are being used. I fixed this bug and pushed the code in issue35 branch. If you have time, please try to use it.

I will release the next version of this library 0.0.4, including this fix and some changes of the interface of API.

Boscop commented 3 years ago

Thanks for the quick reply :)

I checked out that branch and reran the example, but now I'm getting a python-related error:

$ cargo run --example random_cartpole
    Finished dev [unoptimized + debuginfo] target(s) in 0.20s
     Running `target\debug\examples\random_cartpole.exe`
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'D:\\3rdparty\\border\\target\\debug\\examples\\random_cartpole.exe'
  sys.base_prefix = 'C:\\Users\\me\\scoop\\apps\\python\\current'
  sys.base_exec_prefix = 'C:\\Users\\me\\scoop\\apps\\python\\current'
  sys.executable = 'D:\\3rdparty\\border\\target\\debug\\examples\\random_cartpole.exe'
  sys.prefix = 'C:\\Users\\me\\scoop\\apps\\python\\current'
  sys.exec_prefix = 'C:\\Users\\me\\scoop\\apps\\python\\current'
  sys.path = [
    'C:\\Users\\me\\scoop\\apps\\python\\current\\python38.zip',
    '.\\DLLs',
    '.\\lib',
    'D:\\3rdparty\\border\\target\\debug\\examples',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00005738 (most recent call first):
<no Python frame>
error: process didn't exit successfully: `target\debug\examples\random_cartpole.exe` (exit code: 1)

Any idea how to make it work? :)

taku-y commented 3 years ago

@Boscop I'm sorry for late reply. I don't have windows machine, but these tests did not show any errors on Windows. I think this thread may help you solve the issue.