-
Notifications
You must be signed in to change notification settings - Fork 49
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
Remove Fortran code #481
Remove Fortran code #481
Conversation
LevMar does not handle parameters limits/bounds as well as possible, ie it does not transform. Having the code in C/C++ now should make transition easier for the implementer. |
@dtnguyen2 all the tests are failing because of a residual statement that should be removed. Is the PR missing a commit or should the statement be removed? |
The code did not compile with certain compilers as the C++ methods were incorrectly called. I fixed that. There were more residual usages of the fortran flags that prevented the build from happening, and I removed those too. One potential issue with this PR is that it requires a new dependency, |
Unfortunately including |
I am also bumping the minimum version of matplotlib we test against to 2, as 1.5 was incompatible with numpy 1.12. At this point I am just trying to get the tests to pass, we'll need to figure out what to do with the dependencies and the tests. |
autograd is not needed (it was some left-over work which should have been rm from my work on autodiff). I tried to push the changes but was unable to do cause I guess Omar had messed with it: error: failed to push some refs to 'https://github.com/dtnguyen2/sherpa' |
|
(sherpa3) [dtn@devel12 sherpa]$ git fetch |
|
done (sherpa3) [dtn@devel12 sherpa]$ git reset --hard (gnome-ssh-askpass:15783): Gtk-WARNING **: cannot open display: (gnome-ssh-askpass:15792): Gtk-WARNING **: cannot open display: |
All right. I'll revert the changes I made, cancel all the tests on travis, and push again. Fingers crossed. |
@dtnguyen2 two tests are failing on Linux and four on macOS. They are all tests requiring xspec. |
|
||
class LevMar(OptMethod): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the docstring should be retained; at least the
"""Levenberg-Marquardt optimization method."""
part but ideally more.
… relaxing tol should fix it
Rebasing to clean history and fix conflicts. Was a5be52b |
a5be52b
to
1cdb0a0
Compare
I did a fit with this branch and got the following screen output, where the
EDITED Aha: this functionality was always there, it's just that the previous LevMar routine didn't return the covariance matrix, so the numbers were never displayed before. |
As reliable as the fit, but more reliable as sherpa's covar command. The
LevMar method has a built-in estimated covariance matrix. The following is
the excerpt from Numerical Recipes:
Once the acceptable minimum has been found, one wants to set lamda = 0
and compute the matrix
[C] = [alpha]^-1
which, as before, is the estimated covariance matrix of the standard errors
in the fitted parameters a (see next section).
Of course, XSpec gives you a warning about using the values etc...
…On Tue, Oct 2, 2018 at 1:38 PM Doug Burke ***@***.***> wrote:
I did a fit with this branch and got the following screen output, where
the +/- error term is new. I assume this is part of the change here. We
need to document this: what do we say about these error estimates (how are
they calculated and how reliable are they)?
In [25]: ui.fit()
Dataset = 1
Method = levmar
Statistic = chi2gehrels
Initial fit statistic = 675034
Final fit statistic = 6738.63 at function evaluation 9
Data points = 3827
Degrees of freedom = 3825
Probability [Q-value] = 5.63697e-165
Reduced statistic = 1.76173
Change in statistic = 668296
mdl.c0 244.128 +/- 0.996649
mdl.c1 -0.00677439 +/- 0.000155806
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#481 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ALsGUJWyGWcaLr5hvn_e4WO8glWg30BMks5ug6SEgaJpZM4Vq5tZ>
.
|
The main focus is on adding the error estimates in the FitResults.format output. Several other numerical values have been tweaked (change in numerical precision and dictionary ordering), none of which have any significant change to the results.
I've added two minor doc edits - one is to the FitResults class to point out the change from
output we see from fitting with LevMar. |
@@ -606,8 +891,10 @@ static PyMethodDef WrapperFcts[] = { | |||
FCTSPEC(difevo, py_difevo), | |||
FCTSPEC(nm_difevo, py_difevo_nm), | |||
FCTSPEC(lm_difevo, py_difevo_lm), | |||
FCTSPEC(cpp_lmder, py_lmder), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need cpp_lmder
crreated/exported as I can't see a place where it is being used?
One can also get the covar matrix via the extra_output, for example:
fit_results = get_fit_results()
covar = fit_results.extra_output['covar']
I can't seem to find it now, but as I remember it XSpec gives the user some
kind of warning about the covarerr from the resulting fit.
…On Tue, Oct 2, 2018 at 2:50 PM Doug Burke ***@***.***> wrote:
I've added two minor doc edits - one is to the FitResults class to point
out the change from covarerr to covar and the other is to the "quick
guide" in the Sphinx documentation to add the "new"
parameter +/- covarerr
output we see from fitting with LevMar.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#481 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ALsGUNCENfvx2ogK9ayxUpoNpNihwGtSks5ug7VkgaJpZM4Vq5tZ>
.
|
Not sure which version you are using but the following should be in the
said file:
static PyMethodDef WrapperFcts[] = {
FCTSPEC(difevo, py_difevo),
FCTSPEC(nm_difevo, py_difevo_nm),
FCTSPEC(lm_difevo, py_difevo_lm),
FCTSPEC(cpp_lmdif, py_lmdif),
FCTSPEC(neldermead, py_nm),
{ NULL, NULL, 0, NULL }
};
not:
static PyMethodDef WrapperFcts[] = {
FCTSPEC(difevo, py_difevo),
FCTSPEC(nm_difevo, py_difevo_nm),
FCTSPEC(lm_difevo, py_difevo_lm),
FCTSPEC(cpp_lmder, py_lmder),
FCTSPEC(cpp_lmdif, py_lmdif),
FCTSPEC(neldermead, py_nm),
FCTSPEC(minim, py_nm_minim),
{ NULL, NULL, 0, NULL }
};
The latter version is my new attempt at gettting rid of the Fortran code in
the stand alone version of sherpa, but some of the tests are failing on
some versions of macs and I haven't had a chance to look at the issues yet.
…On Tue, Oct 2, 2018 at 3:33 PM Doug Burke ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In sherpa/optmethods/src/_saoopt.cc
<#481 (comment)>:
> @@ -606,8 +891,10 @@ static PyMethodDef WrapperFcts[] = {
FCTSPEC(difevo, py_difevo),
FCTSPEC(nm_difevo, py_difevo_nm),
FCTSPEC(lm_difevo, py_difevo_lm),
+ FCTSPEC(cpp_lmder, py_lmder),
Do we need cpp_lmder crreated/exported as I can't see a place where it is
being used?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#481 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALsGUKbHGutmqYo0hblc9H-1AovwgvDsks5ug79vgaJpZM4Vq5tZ>
.
|
Dan, I'm reviewing this PR as requested by Omar, so I'm meant to be looking at your new version. |
Ok. As for the lmder: while I was adding the C++ version of lmdif I
decided to add in lmder (same as lmdif but uses analytical derivatives
instead of numerical ones which would save some computation time) since
there was some debate about whether XSpec supplying us with analytical
derivatives or not (in my opinion: no but others may think otherwise).
…On Tue, Oct 2, 2018 at 4:13 PM Doug Burke ***@***.***> wrote:
Dan, I'm reviewing this PR as requested by Omar, so I'm meant to be
looking at your new version.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#481 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ALsGULtUhmu_YTNt-pTxriJlPTFEUUypks5ug8jOgaJpZM4Vq5tZ>
.
|
Ta - so it sounds like |
0074622
to
03244c2
Compare
@olaurino I've had a look at the code and - modulo the fact that I've skipped over the C++ side of it completely - it looks fine to me (as of commit 03244c2 aka "increase tolerance for tests that failed with older xspec"). You can consider this an "official" sign off, assuming that the only remaining changes are "test wibbles" (or perhaps doc fixes). I think the fact that the best-fit results in the tests aren't changing here (at least within the tolerance) is as good a sign as my review. Let me know if there's something else ion this you wanted a comment on. |
I wouldn't mind an additional check on the README changes. I think I'll merge everything tomorrow morning and kick off the release process. |
I'm concerned about #503 and the excessive memory usage we are seeing. I
believe there code that causes there regressions in the ciao build are also
in 4.10.1
…On Thu, Oct 4, 2018, 17:31 Omar Laurino ***@***.***> wrote:
I wouldn't mind an additional check on the README changes. I think I'll
merge everything tomorrow morning and kick off the release process.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#481 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AANtfjRzWF2IJVWeqj9N4Wqbrb10FZF4ks5uhn45gaJpZM4Vq5tZ>
.
|
@@ -509,9 +504,6 @@ used, but the full path should be in your own copy of the file): | |||
have been issues seen using the CIAO binaries on certain OS X | |||
systems. | |||
|
|||
In all cases, the same version of `gfortran` should be used to build | |||
Sherpa and XSPEC, in order to avoid possible incompatibilities. | |||
|
|||
If there are problems building, or using, the module, then the other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this paragraph which talks about gfortran_xxx
settings. This seems at odds with our brave, new, Fortran-Free world. I think I added this paragraph, but I don't know of a situation where we've had to change these settings (which is not a solid proof that they are not needed, I admit).
I think we should leave this paragraph in for now, but when we get to the XSPEC 12.10.0 PRs we can look at whether this paragraph still has any use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll clarify that part. Gfortran is not needed to build the xspec extension. Only libgfortran is, and it needs to be the same (or same version) as the one used to build xspec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would help to include a setup.cfg.xspec with some of the options preset to a common scenario, with placeholders for the actual paths the user will have to change.
A couple of comments about the tolerance. When I changed the minpack code (lmdif) from Fortran to C++ I only had to change one test: If you look carefully at the LevMar.cc file, you will notice that I have valgrind the c++ code (outside of sherpa). One can compile the test from typing the following (documented in the code itself): // Whenever possible I generalized the test model functions from a fixed number of parameters to a general number of free parameters. For example, the Rosenbrock in the aforementioned paper were written for npar=2, in my test version npar can be any even number etc... I included the covariance matrix for the Levenberg-Marquardt algorithm, cause I will (someday) intend to do the same for the NelderMead algorithm since they are useful for Lev3 work (get_draws needs a covariance matrix and sherpa's covar command is iffy at best, never mind about covariance from int_unc). As I mentioned before, I have always wanted to transform the fitted parameters to handle parameter boundaries. In theory, I could do that from Fortran, but that is not going to be handy for my next job. I have thoroughly tested the C++ code, and I very confident that it will be fine |
If there are problems building, or using, the module, then the other | ||
options may need to be set - in particular the `gfortran_lib_dirs` and | ||
`gfortran_libraries` settings. | ||
|
||
It is important that the `gfortran`-related options above point to a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DougBurke does this seem OK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I am merging this. If we need to reword we can do it anyway.
PR sherpa#481 means that we no longer create _minim/_minpack modules in sherpa.optmethods, so they can be removed from the list of modules that need to be mocked when building the Sphinx documentation.
Release Note
Sherpa does not rely on any Fortran routines anymore, except those compiled in XSPEC. The existing Fortran code, which was used mainly in some of the optimization routines, has been replaced by equivalent C++ code. This means that
gfortran
is no longer required for building Sherpa, although a version oflibgfortran
compatible with the one used to link the XSPEC libraries would still be needed at runtime if the XSPEC extension is built.Notes