argmin-rs / argmin

Numerical optimization in pure Rust
http://argmin-rs.org
Apache License 2.0
942 stars 74 forks source link

Example (lbfgs) cannot be compiled after upgrade to version 0.10 #485

Closed humphreylee closed 3 months ago

humphreylee commented 3 months ago

The example lbfgs used to compile successfully prior to version 0.10. However, after upgraded to version 0.10, the compilation (cargo run) failed with many errors. I have tried to troubleshoot, but with no success. Appreciate your help.

   Compiling lbfgs_ndarray v0.1.0 (C:\Users\User1\lbfgs_ndarray)
error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminSub<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminSub<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminSub<T, U>`:
             <i8 as argmin_math::ArgminSub<i8, i8>>
             <i16 as argmin_math::ArgminSub<i16, i16>>
             <i32 as argmin_math::ArgminSub<i32, i32>>
             <i64 as argmin_math::ArgminSub<i64, i64>>
             <u8 as argmin_math::ArgminSub<u8, u8>>
             <u16 as argmin_math::ArgminSub<u16, u16>>
             <u32 as argmin_math::ArgminSub<u32, u32>>
             <u64 as argmin_math::ArgminSub<u64, u64>>
           and 12 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminSub<f64, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminSub<f64, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminSub<T, U>`:
             <i8 as argmin_math::ArgminSub<i8, i8>>
             <i16 as argmin_math::ArgminSub<i16, i16>>
             <i32 as argmin_math::ArgminSub<i32, i32>>
             <i64 as argmin_math::ArgminSub<i64, i64>>
             <u8 as argmin_math::ArgminSub<u8, u8>>
             <u16 as argmin_math::ArgminSub<u16, u16>>
             <u32 as argmin_math::ArgminSub<u32, u32>>
             <u64 as argmin_math::ArgminSub<u64, u64>>
           and 12 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminAdd<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminAdd<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminAdd<T, U>`:
             <i8 as argmin_math::ArgminAdd<i8, i8>>
             <i16 as argmin_math::ArgminAdd<i16, i16>>
             <i32 as argmin_math::ArgminAdd<i32, i32>>
             <i64 as argmin_math::ArgminAdd<i64, i64>>
             <u8 as argmin_math::ArgminAdd<u8, u8>>
             <u16 as argmin_math::ArgminAdd<u16, u16>>
             <u32 as argmin_math::ArgminAdd<u32, u32>>
             <u64 as argmin_math::ArgminAdd<u64, u64>>
           and 12 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminAdd<f64, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminAdd<f64, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminAdd<T, U>`:
             <i8 as argmin_math::ArgminAdd<i8, i8>>
             <i16 as argmin_math::ArgminAdd<i16, i16>>
             <i32 as argmin_math::ArgminAdd<i32, i32>>
             <i64 as argmin_math::ArgminAdd<i64, i64>>
             <u8 as argmin_math::ArgminAdd<u8, u8>>
             <u16 as argmin_math::ArgminAdd<u16, u16>>
             <u32 as argmin_math::ArgminAdd<u32, u32>>
             <u64 as argmin_math::ArgminAdd<u64, u64>>
           and 12 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminDot<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminDot<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminDot<T, U>`:
             <i8 as argmin_math::ArgminDot<i8, i8>>
             <i16 as argmin_math::ArgminDot<i16, i16>>
             <i32 as argmin_math::ArgminDot<i32, i32>>
             <i64 as argmin_math::ArgminDot<i64, i64>>
             <u8 as argmin_math::ArgminDot<u8, u8>>
             <u16 as argmin_math::ArgminDot<u16, u16>>
             <u32 as argmin_math::ArgminDot<u32, u32>>
             <u64 as argmin_math::ArgminDot<u64, u64>>
           and 12 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminMul<f64, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminMul<f64, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminMul<T, U>`:
             <i8 as argmin_math::ArgminMul<i8, i8>>
             <i16 as argmin_math::ArgminMul<i16, i16>>
             <i32 as argmin_math::ArgminMul<i32, i32>>
             <i64 as argmin_math::ArgminMul<i64, i64>>
             <u8 as argmin_math::ArgminMul<u8, u8>>
             <u16 as argmin_math::ArgminMul<u16, u16>>
             <u32 as argmin_math::ArgminMul<u32, u32>>
             <u64 as argmin_math::ArgminMul<u64, u64>>
           and 12 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminMul<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminMul<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminMul<T, U>`:
             <i8 as argmin_math::ArgminMul<i8, i8>>
             <i16 as argmin_math::ArgminMul<i16, i16>>
             <i32 as argmin_math::ArgminMul<i32, i32>>
             <i64 as argmin_math::ArgminMul<i64, i64>>
             <u8 as argmin_math::ArgminMul<u8, u8>>
             <u16 as argmin_math::ArgminMul<u16, u16>>
             <u32 as argmin_math::ArgminMul<u32, u32>>
             <u64 as argmin_math::ArgminMul<u64, u64>>
           and 12 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminL1Norm<f64>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminL1Norm<f64>` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminL1Norm<U>`:
             <i8 as argmin_math::ArgminL1Norm<i8>>
             <i16 as argmin_math::ArgminL1Norm<i16>>
             <i32 as argmin_math::ArgminL1Norm<i32>>
             <i64 as argmin_math::ArgminL1Norm<i64>>
             <u8 as argmin_math::ArgminL1Norm<u8>>
             <u16 as argmin_math::ArgminL1Norm<u16>>
             <u32 as argmin_math::ArgminL1Norm<u32>>
             <u64 as argmin_math::ArgminL1Norm<u64>>
           and 12 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminSignum` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminSignum` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the trait `Solver<O, IterState<P, G, (), (), (), F>>` is implemented for `LBFGS<L, P, G, F>`
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminZeroLike` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminZeroLike` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminZeroLike`:
             i8
             i16
             i32
             i64
             u8
             u16
             u32
             u64
           and 12 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminMinMax` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminMinMax` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminMinMax`:
             i8
             i16
             i32
             i64
             u8
             u16
             u32
             u64
           and 2 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>: argmin_math::ArgminL2Norm<f64>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminL2Norm<f64>` is not implemented for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `argmin_math::ArgminL2Norm<U>`:
             <i8 as argmin_math::ArgminL2Norm<i8>>
             <i16 as argmin_math::ArgminL2Norm<i16>>
             <i32 as argmin_math::ArgminL2Norm<i32>>
             <i64 as argmin_math::ArgminL2Norm<i64>>
             <u8 as argmin_math::ArgminL2Norm<u8>>
             <u16 as argmin_math::ArgminL2Norm<u16>>
             <u32 as argmin_math::ArgminL2Norm<u32>>
             <u64 as argmin_math::ArgminL2Norm<u64>>
           and 4 others
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0277]: the trait bound `f64: argmin_math::ArgminMul<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not satisfied
  --> src\main.rs:50:35
   |
50 |     let res = Executor::new(cost, solver)
   |               -------------       ^^^^^^ the trait `argmin_math::ArgminMul<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>` is not implemented for `f64`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the trait `argmin_math::ArgminMul<f64, f64>` is implemented for `f64`
   = note: required for `ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>` to implement `argmin_math::ArgminScaledAdd<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>`
   = note: required for `MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>` to implement `Solver<quasinewton::lbfgs::LineSearchProblem<Rosenbrock, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: 1 redundant requirement hidden
   = note: required for `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ..., ..., ...>` to implement `Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-17789123032868209773.txt'
note: required by a bound in `Executor::<O, S, I>::new`
  --> C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\core\executor.rs:39:8
   |
39 |     S: Solver<O, I>,
   |        ^^^^^^^^^^^^ required by this bound in `Executor::<O, S, I>::new`
...
63 |     pub fn new(problem: O, solver: S) -> Self {
   |            --- required by a bound in this associated function

error[E0599]: the method `configure` exists for struct `Executor<Rosenbrock, LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, ...>, ...>, ..., ..., ...>, ...>`, but its trait bounds were not satisfied
  --> src\main.rs:51:10
   |
50 |       let res = Executor::new(cost, solver)
   |  _______________-
51 | |         .configure(|state| state.param(init_param).max_iters(100))
   | |         -^^^^^^^^^ method cannot be called due to unsatisfied trait bounds
   | |_________|
   |
   |
  ::: C:\Users\User1\.cargo\registry\src\index.crates.io-6f17d22bba15001f\argmin-0.10.0\src\solver\quasinewton\lbfgs.rs:78:1
   |
78 |   pub struct LBFGS<L, P, G, F> {
   |   ---------------------------- doesn't satisfy `_: Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`
   |
   = note: the full type name has been written to 'C:\Users\User1\lbfgs_ndarray\target\debug\deps\example_lbfgs-f2fa77f4743f9654.long-type-109050685087764189.txt'
   = note: the following trait bounds were not satisfied:
           `LBFGS<MoreThuenteLineSearch<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, f64>: Solver<Rosenbrock, IterState<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, (), (), (), f64>>`

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `example-lbfgs` (bin "example-lbfgs") due to 14 previous errors

I have changed the Cargo.toml a bit, as below.

[package]
name = "lbfgs_ndarray"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
publish = false

[dependencies]
argmin = { version = "*"}
argmin-math = { version = "*", features = ["ndarray_latest-serde"]}
argmin-observer-slog = { version = "*"}
argmin_testfunctions = { version = "*"}
ndarray = "*"
finitediff = { version = "*", features = ["ndarray"] }
ndarray-linalg = { version = "*", features = ["netlib"] }

The code as downloaded from lbfgs example

// Copyright 2018-2024 argmin developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use argmin::{
    core::{observers::ObserverMode, CostFunction, Error, Executor, Gradient},
    solver::{linesearch::MoreThuenteLineSearch, quasinewton::LBFGS},
};
use argmin_observer_slog::SlogLogger;
use argmin_testfunctions::{rosenbrock, rosenbrock_derivative};
use ndarray::{array, Array1};

struct Rosenbrock {}

impl CostFunction for Rosenbrock {
    type Param = Array1<f64>;
    type Output = f64;

    fn cost(&self, p: &Self::Param) -> Result<Self::Output, Error> {
        Ok(rosenbrock(&p.to_vec()))
    }
}
impl Gradient for Rosenbrock {
    type Param = Array1<f64>;
    type Gradient = Array1<f64>;

    fn gradient(&self, p: &Self::Param) -> Result<Self::Gradient, Error> {
        Ok(Array1::from(rosenbrock_derivative(&p.to_vec()).to_vec()))
    }
}

fn run() -> Result<(), Error> {
    // Define cost function
    let cost = Rosenbrock {};

    // Define initial parameter vector
    let init_param: Array1<f64> = array![-1.2, 1.0];
    // let init_param: Array1<f64> = array![-1.2, 1.0, -10.0, 2.0, 3.0, 2.0, 4.0, 9.0];

    // set up a line search
    let linesearch = MoreThuenteLineSearch::new().with_c(1e-4, 0.9)?;

    // Set up solver
    let solver = LBFGS::new(linesearch, 7);

    // Run solver
    let res = Executor::new(cost, solver)
        .configure(|state| state.param(init_param).max_iters(100))
        .add_observer(SlogLogger::term(), ObserverMode::Always)
        .run()?;

    // Print result
    println!("{res}");
    Ok(())
}

fn main() {
    if let Err(ref e) = run() {
        println!("{e}");
        std::process::exit(1);
    }
}
stefan-k commented 3 months ago

As written in the blog post, you need to remove '-serde' from the argmin-math feature you are using.

humphreylee commented 3 months ago

Yes, that's fixed the problem. Thanks.