Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snopt7 now working with 7.7 and 7.6 APIs #7

Merged
merged 11 commits into from
Jan 31, 2019
Merged

Conversation

darioizzo
Copy link
Member

@darioizzo darioizzo commented Jan 30, 2019

Tested. Here is the log of a working session. Both Snopt 7.7.1 and Snopt 7.2.4 were used (fortran). Note that the c library version is, instead, 2.2 and 2.0 respectively.

┌─[dario@valentina]─[~]
└──╼ ipython
imPython 3.7.2 (default, Jan 10 2019, 23:51:51) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pygmo_plugins_nonfree as pnf                                                                                                                                                                        

In [2]: import pygmo as pg                                                                                                                                                                                         

In [3]: uda = pnf.snopt7(library = r'/usr/local/lib/libsnopt76_c.so', screen_output=True, minor_version=6)                                                                                                         

In [4]: algo = pg.algorithm(uda)                                                                                                                                                                                   

In [5]: prob = pg.problem(pg.ackley(10))                                                                                                                                                                           

In [6]: pop = pg.population(prob, 10)                                                                                                                                                                              

In [7]: pop = algo.evolve(pop)                                                                                                                                                                                     
 ==============================
   SNOPT  C interface  2.0.0   
 ==============================
 S N O P T  7.2-4    (Jun 2006)
 ==============================
 
 SNMEMA EXIT 100 -- finished successfully
 SNMEMA INFO 104 -- memory requirements estimated
 

 Nonlinear constraints       0     Linear constraints       1
 Nonlinear variables        10     Linear variables         0
 Jacobian  variables         0     Objective variables     10
 Total constraints           1     Total variables         10
 

 
 The user has defined       0   out of      10   first  derivatives
 

 Major Minors     Step   nObj Feasible  Optimal      Objective    nS
     0     10               1           5.9E-01  1.6817613E+01    10   r
     1      1  1.5E-01      2           5.0E-01  1.6130361E+01    10 n r
     2      1  1.4E-01      3           3.2E-01  1.5813800E+01    10 s
     3      1  1.0E+00      4           7.8E-02  1.5704890E+01    10
     4      1  1.0E+00      5           6.4E-03  1.5698342E+01    10
     5      1  3.3E-01      6           2.2E-03  1.5698329E+01    10
     6      1  1.0E+00      7           2.4E-03  1.5698328E+01    10
     7      1  1.0E+00      8           7.5E-04  1.5698324E+01    10
     8      1  1.0E+00      9           2.2E-04  1.5698324E+01    10
     9      1  1.0E+00     10           2.7E-05  1.5698324E+01    10

 Major Minors     Step   nObj Feasible  Optimal      Objective    nS
    10      1  1.0E+00     11           1.5E-05  1.5698324E+01    10
    11      1  1.0E+00     12           5.7E-06  1.5698324E+01    10       c
    11      2  1.0E+00     12           2.7E-05  1.5698324E+01    10       c
    12      1  4.5E-01     13           5.9E-06  1.5698324E+01    10       c
    13      1  1.0E+00     14          (8.0E-07) 1.5698324E+01    10       c
 
 SNOPTA EXIT   0 -- finished successfully
 SNOPTA INFO   1 -- optimality conditions satisfied

 Problem name                 Ackley F
 No. of iterations                  24   Objective value      1.5698323763E+01
 No. of major iterations            13   Linear objective     0.0000000000E+00
 Penalty parameter           0.000E+00   Nonlinear objective  1.5698323763E+01
 No. of calls to funobj            211   No. of calls to funcon            211
 Calls with modes 1,2 (known g)     14   Calls with modes 1,2 (known g)     14
 Calls for forward differencing    120   Calls for forward differencing    120
 Calls for central differencing     60   Calls for central differencing     60
 No. of superbasics                 10   No. of basic nonlinears             0
 No. of degenerate steps             0   Percentage                       0.00
 Max x                       5 1.6E+01   Max pi                      1 1.0E+00
 Max Primal infeas           0 0.0E+00   Max Dual infeas             5 1.6E-06

 Solution not printed

In [8]: uda = pnf.snopt7(library = r'/usr/local/lib/libsnopt77_c.so', screen_output=True, minor_version=7)                                                                                                         

In [9]: algo = pg.algorithm(uda)                                                                                                                                                                                   

In [10]: pop = pg.population(prob, 10)                                                                                                                                                                             

In [11]: pop = algo.evolve(pop)                                                                                                                                                                                    
 ==============================
    SNOPT  C interface  2.2.0   
 ==============================
 S N O P T  7.7.1    (Nov 2018)
 ==============================
 
 SNMEMA EXIT 100 -- finished successfully
 SNMEMA INFO 104 -- memory requirements estimated

 Trial version of SNOPT -- for evaluation or academic purposes only
 

 Nonlinear constraints       0     Linear constraints       1
 Nonlinear variables        10     Linear variables         0
 Jacobian  variables         0     Objective variables     10
 Total constraints           1     Total variables         10
 

 
 The user has defined       0   out of      10   first  derivatives
 

 Major Minors     Step   nObj Feasible  Optimal      Objective     nS
     0     10               1           5.6E-01  1.9313431E+01     10   r
     1      1  1.0E+00      2           7.5E-01  1.8485845E+01     10   r
     2      1  1.9E-01      3           5.7E-01  1.8046349E+01     10 s
     3      1  1.0E+00      4           5.2E-01  1.7804930E+01     10
     4      1  1.0E+00      5           5.1E-01  1.7799763E+01     10
     5      1  1.0E+00      6           3.6E-02  1.7783339E+01     10
     6      1  1.0E+00      7           1.0E-02  1.7783045E+01     10
     7      1  1.0E+00      8           1.2E-03  1.7783021E+01     10
     8      1  1.0E+00      9           9.8E-04  1.7783021E+01     10
     9      1  1.0E+00     10           2.2E-05  1.7783020E+01     10
     9      1              10           8.9E-05  1.7783020E+01     10       c

 Major Minors     Step   nObj Feasible  Optimal      Objective     nS
    10      1  1.0E+00     11           6.4E-05  1.7783020E+01     10       c
    11      1  1.0E+00     12          (4.3E-07) 1.7783020E+01     10       c
 
 SNOPTA EXIT   0 -- finished successfully
 SNOPTA INFO   1 -- optimality conditions satisfied

 Problem name                 Ackley F
 No. of iterations                  22   Objective            1.7783020464E+01
 No. of major iterations            11   Linear    obj. term  0.0000000000E+00
                                         Nonlinear obj. term  1.7783020464E+01
 User function calls (total)       185   Calls with modes 1,2 (known g)     12
 Calls for forward differencing    130   Calls for central differencing     30
 No. of superbasics                 10   No. of basic nonlinears             0
 No. of degenerate steps             0   Percentage                       0.00
 Max x                       6 2.7E+01   Max pi                      1 1.0E+00
 Max Primal infeas           0 0.0E+00   Max Dual infeas            10 4.3E-07

 Solution not printed
 
 Time for MPS input                             0.00 seconds
 Time for solving problem                       0.00 seconds
 Time for solution output                       0.01 seconds
 Time for constraint functions                  0.00 seconds
 Time for objective function                    0.00 seconds

snopt7(bool screen_output = false, std::string snopt7_c_library = "/usr/local/lib/libsnopt7_c.so",
unsigned minor_version = 6u)
: m_snopt7_c_library(snopt7_c_library), m_minor_version(minor_version), m_integer_opts(),
m_numeric_opts(), m_screen_output(screen_output), m_verbosity(0), m_log(){};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a check on the minor_version parameter would be good here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to check. Its unsigned. any number > 0 is valid. from 1 to 6 the old API will be triggered, 7 to inf will trigger the other API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that this should work for snopt 7.1 7.2 7.3 7.4 7.5 7.6 with the old API, for snopt 7.7+ with the new API.

If in the future they introduce a further change then we will have to catch it and have a further branching.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's more like a boolean flag right now? Because phrased like that it seems like it is open to supporting newer api versions in the future, but clearly if the snopt guys put out a new API tomorrow and a user passes in minor_version 8, it will still crash.

Not sure what is the best course of action to be honest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps an enum would be better? With an enum, you could have

enum class snopt_api: unsigned {
   ver1,   // Support up to SNOPT 7.4
   ver2,   // Support from 7.4  to 7.8
   latest  // Anything above 7.8
};

Then you could add ver3 between latest and ver2 whenever the API changes again. Not sure, just spitballing here.

I think the minor_version thing is a bit confusing because of its name, it seems like the user needs to fill in the correct snopt minor version but that's not actually the case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right ok I think I see the point better now. This seems like a good place where one would use a warning system, if we had one in pagmo :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue I have with enums is that they do not play nicely at the interface with python. Also, since we do not have all the libraries of all versions, nor a description of the API changes is easy to find, would not guarantee that this works with all the versions.

Its very confusing, I agree.

I did try to put in the docs warnings on these things. Also about possible crashes if the library version is wrong .... not sure how to make this properly but my guess is that its not possible since snopt7 is developed quite "old fashioned" and does not offer much support for a proper integration.

template <typename Archive>
void serialize(Archive &ar)
{
ar(cereal::base_class<not_population_based>(this), m_snopt7_c_library, m_integer_opts, m_numeric_opts,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the minor version member is missing from serialization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch .... also adding it to the screen stream ... will do

@codecov-io
Copy link

codecov-io commented Jan 30, 2019

Codecov Report

Merging #7 into master will decrease coverage by 0.25%.
The diff coverage is 91.17%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #7      +/-   ##
=========================================
- Coverage   96.55%   96.3%   -0.26%     
=========================================
  Files           4       4              
  Lines         872     866       -6     
=========================================
- Hits          842     834       -8     
- Misses         30      32       +2
Impacted Files Coverage Δ
include/pagmo_plugins_nonfree/worhp.hpp 93.44% <66.66%> (-0.45%) ⬇️
include/pagmo_plugins_nonfree/snopt7.hpp 97.86% <93.54%> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c605b39...59b3c74. Read the comment docs.

@darioizzo darioizzo merged commit 3668dc0 into esa:master Jan 31, 2019
@darioizzo darioizzo deleted the snopt77 branch January 31, 2019 13:06
@darioizzo darioizzo mentioned this pull request Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants