GithubHelp home page GithubHelp logo

felixlen / trlib Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 9.0 407 KB

Trust Region Subproblem Solver Library

License: MIT License

CMake 7.72% Python 0.39% C 74.99% MATLAB 4.41% Julia 2.58% M 0.15% Cython 9.75%

trlib's People

Contributors

chrhansk avatar felixlen avatar jgillis avatar jonaszehn avatar traversaro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

trlib's Issues

python interface, pass matrix to Minv results in error

According to the documentation, trlib_solve accepts an argument invM which may be a dense matrix. But passing a numpy array results in an error.

Minimal working example:

import numpy as np
from trlib import trlib_solve

H = np.diag(np.arange(3)+1)
Minv = np.diag(1/np.sqrt(np.arange(3)+1))
g = np.array([-0.1, 0.2, 0.1])

trlib_solve(H, g, 1)                     # works
trlib_solve(H, g, 1, invM=Minv)  # produces error

The exact error read:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-c02cfcb4fd2d> in <module>()
----> 1 trlib_solve(H, g, 1, invM=Minv)

trlib.pyx in trlib.trlib_solve (/home/name/Documents/phd/models/lib/trlib/build/bindings/python/_trlib3.c:8832
)()

TypeError: 'numpy.ndarray' object is not callable

What am I doing wrong here? If I have to supply a function, how would I create one that preconditions based on the values of H, without recalculating the H.

Trust-Region code does not handle a hard case

It seems like the code has issues with a hard case problem. Here some code:

julia> using trlib
julia> g = [1.0, 0.0, -1.0]; H = zeros(3, 3); H[2, 2] = -20.0;
julia> tr = trlib.trlib_data(H, g);
julia> trlib.trlib_solve(tr, 1.0)
2
julia> tr.lam
1.4142135623730951

However the value tr.lam does not result in H+lambda eye(3) being positive definite. Hence, the tuple (tr.sol, tr.lam) cannot be an optimal solution of the trust-region problem, right?
Primal and dual feasibility as well as complementarity do hold since

julia> norm(tr.sol)
0.9999999999999999
julia> (H+tr.lam*eye(3))*tr.sol+g
3-element Array{Float64,1}:
 0.0
 0.0
 0.0

I would very much be interested in an explanation of this effect. Thanks!

Issues if gradient and Hessian contain only zeros

I have experience some issues with trlib. If I run trlib with zero gradient and Hessian, the result is a NaN vector. Here some code:

julia> include("/home/johannes/trlib/bindings/julia/trlib.jl")
julia> using trlib
julia> H = zeros(3, 3); g = zeros(3); radius = 1.0; 
julia> TR = trlib.trlib_data(H, g);
julia> trlib.trlib_solve(TR, 1.0);
julia> TR.sol
3-element Array{Float64,1}:
 NaN
 NaN
 NaN

Python2 installation

I'm interested in trying out trlib, but I can't get it to work with python2. In CMakeLists.txt I set option(TRLIB_BUILD_PYTHON2 ON) and ran make, make doc, make test, and make install. Even running python in the cmake build directory, though, I cannot import trlib (it says module not found). I see that a ./bindings/python/trlib.pyx file was generated, but no py files. A simple pyximport also failed. Any ideas?

RuntimeWarning when using Python interface

I would like to solve the trust region problem in two dimensions for H = -Id and g = 0 with a trust radius of 1 using the python3 (version 3.10.4) interface of trlib using the following code:

import scipy.sparse
import numpy as np

import trlib

H = -1. * scipy.sparse.eye(2)

g = np.zeros((2,))

x, TR = trlib.trlib_solve(H, g, 1.0)

However, when I run the code I get the following messages:

<stdin>:1: RuntimeWarning: invalid value encountered in true_divide
<stdin>:1: RuntimeWarning: invalid value encountered in multiply
<stdin>:1: RuntimeWarning: trlib status -5

Is there a way to get trlib to solve the problem (I would expect to end up at some arbitrary point on the boundary)? I also tried with the C interface and got a message TRLIB_TTR_HARD_INIT_LAM back...

Objective offset

I would like to be able to add an objective offset to trlib. Essentially, this would no affect the solution process, but print a corrected value in the obj column during the iterations.

Thus far, the value is stored in fwork + 8, set to 0. initially and then updated.

Could we add an offset field to fwork, have users initialize it and use that during prints?

C linking errors

Hi,
I was trying to install trilb library but I didn't succeed. I am running C interface on Mac OS 10.12.6. I followed all steps in the documentation. It looks fine when I set up cmake with all default settings and run make:

Scanning dependencies of target trlib
[ 16%] Building C object src/CMakeFiles/trlib.dir/trlib_krylov.c.o
[ 33%] Building C object src/CMakeFiles/trlib.dir/trlib_tri_factor.c.o
[ 50%] Building C object src/CMakeFiles/trlib.dir/trlib_leftmost.c.o
[ 66%] Building C object src/CMakeFiles/trlib.dir/trlib_eigen_inverse.c.o
[ 83%] Building C object src/CMakeFiles/trlib.dir/trlib_quadratic_zero.c.o
[100%] Linking C shared library libtrlib.dylib
[100%] Built target trlib

When I compile the file using make test, it returns

Running tests...
Test project /Users/YulingYao/desktop/trlib-master/build
No tests were found!!!

OK, I guess this just doesn't matter.
It also looks fine when I execute make install and sudo make install.

[100%] Built target trlib
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /usr/local/include/trlib.h
-- Up-to-date: /usr/local/include/trlib/trlib_types.h
-- Up-to-date: /usr/local/include/trlib/trlib_krylov.h
-- Up-to-date: /usr/local/include/trlib/trlib_tri_factor.h
-- Up-to-date: /usr/local/include/trlib/trlib_leftmost.h
-- Up-to-date: /usr/local/include/trlib/trlib_quadratic_zero.h
-- Up-to-date: /usr/local/include/trlib/trlib_eigen_inverse.h
......
-- Installing: /usr/local/lib/libtrlib.dylib
......

It should work. However, I still end up with a linking error whenever I call the library in C
LDLIBS = -ltrlib ...

ld: library not found for -ltrlib
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I guess I just didn't install the whole package successfully. When I manually link the binary with library in Xcode, I also didn't find any trilb framework. (I suppose the library itself should be generated in the CMAKE_OSX_SYSROOT path according to the CMake file, but it wan't.)

I googled for a while and find nothing directly related. Could you provide any suggestion?

Thanks,
Yuling

Some tests fail on FreeBSD

The following tests FAILED:
	  2 - test_quadratic_zero_valgrind (Failed)
	  4 - test_eigen_inverse_valgrind (Failed)
	  6 - test_leftmost_valgrind (Failed)
	  8 - test_leftmost_irreducible_valgrind (Failed)
	 10 - test_factor_tri_simple_posdef_valgrind (Failed)
	 12 - test_factor_tri_simple_indef_valgrind (Failed)
	 14 - test_factor_tri_simple_indef_reg_valgrind (Failed)
	 16 - test_factor_tri_reducible_valgrind (Failed)
	 18 - test_factor_tri_expanding_valgrind (Failed)
	 20 - test_factor_tri_narrow_lam_valgrind (Failed)
	 22 - test_krylov_2d_simple_valgrind (Failed)
	 24 - test_krylov_3d_all_cases_valgrind (Failed)
	 26 - test_krylov_tri_simple_valgrind (Failed)
	 28 - test_krylov_tri_diagonal_lanczos_trigger_valgrind (Failed)
	 30 - test_krylov_tri_diagonal_with_zeros_valgrind (Failed)
	 32 - test_krylov_lanczos_rosenbrock_valgrind (Subprocess aborted)
	 34 - test_prepare_memory_valgrind (Failed)
	 36 - test_krylov_zero_hessian_valgrind (Failed)

But when I run individual test executables they succeed.

clang-12
FreeBSD 13

Build errors with later distributions

The build fails on later distributions (Debian Bullseye and Ubuntu Bionic):

Scanning dependencies of target trlib
[  1%] Building C object src/CMakeFiles/trlib.dir/trlib_krylov.c.o
[  2%] Building C object src/CMakeFiles/trlib.dir/trlib_tri_factor.c.o
[  2%] Building C object src/CMakeFiles/trlib.dir/trlib_leftmost.c.o
[  3%] Building C object src/CMakeFiles/trlib.dir/trlib_eigen_inverse.c.o
[  4%] Building C object src/CMakeFiles/trlib.dir/trlib_quadratic_zero.c.o
[  5%] Linking C shared library libtrlib.so
[  5%] Built target trlib
[  6%] Generating test_factor_tri_simple_indef_valgrind.c
Scanning dependencies of target test_factor_tri_simple_indef_valgrind
[  7%] Building C object tests/CMakeFiles/test_factor_tri_simple_indef_valgrind.dir/test_factor_tri_simple_indef_valgrind.c.o
[  8%] Building C object tests/CMakeFiles/test_factor_tri_simple_indef_valgrind.dir/trlib_test.c.o
[  8%] Linking C executable test_factor_tri_simple_indef_valgrind
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcheck.a(check.o): In function `check_get_clockid':
(.text+0xab3): undefined reference to `timer_create'
(.text+0xad5): undefined reference to `timer_delete'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcheck.a(check_run.o): In function `srunner_run':
(.text+0xa92): undefined reference to `timer_create'
(.text+0xae0): undefined reference to `timer_settime'
(.text+0xb0a): undefined reference to `timer_delete'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcheck.a(check_log.o): In function `subunit_lfun':
(.text+0x5f4): undefined reference to `subunit_test_start'
(.text+0x6bf): undefined reference to `subunit_test_fail'
(.text+0x6d4): undefined reference to `subunit_test_pass'
(.text+0x6ef): undefined reference to `subunit_test_error'
collect2: error: ld returned 1 exit status
tests/CMakeFiles/test_factor_tri_simple_indef_valgrind.dir/build.make:129: recipe for target 'tests/test_factor_tri_simple_indef_valgrind' failed

Specifically, there seems to some linker error regarding libcheck. Could you look into the problem and maybe also update the travis file to include a build matrix containing some more recent Ubuntu distros like Focal and Bionic? Those should be supported ?!

Add a release/tag

Hello @felixlen, thanks a lot for working on trlib !

I am interested in adding trlib as package in conda-forge to simplify its installation (and also because it is a dependency of https://github.com/chrhansk/sleqp that I am also interested in packaging). For doing that, it would be useful to add git tags to indicate the point of the history that refer to a precise version. For example, I see that you are keeping a version number in CMake (see 0998af9), would you be interested in adding a tag to indicate which git commit in history is the trlib version 0.4?

Thanks a lot in advance, and if you are not interested in adding tags to the repo, no problem!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.