Skip to content

Commit

Permalink
Merge pull request #284 from fitbenchmarking/215_ralfit
Browse files Browse the repository at this point in the history
215 Adding RALfit
  • Loading branch information
AndrewLister-STFC committed Nov 5, 2019
2 parents c36f0de + 77c5cf1 commit 3685404
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,29 @@ stages:
if: type = cron

before_install:
# Adding RALfit packages
- sudo apt-get update
- sudo apt-get install gfortran
- sudo apt-get install lcov
- sudo apt-get install libblas-dev
- sudo apt-get install liblapack-dev
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O
miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b
- conda update --yes conda
- conda install --yes python=$TRAVIS_PYTHON_VERSION numpy scipy matplotlib
h5py yaml ipython

install:
# Builds RALfit
- ./build_ralfit.sh
- pip install -r requirements.txt
- python setup.py install
- python setup.py externals
- python -m easy_install --upgrade pyOpenSSL
- export LD_LIBRARY_PATH=$HOME/build/fitbenchmarking/fitbenchmarking/RALFit/libRALFit/build/src:$LD_LIBRARY_PATH


jobs:
include:
Expand Down
15 changes: 15 additions & 0 deletions build_ralfit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

SCRIPTPATH=$PWD

git clone https://github.com/ralna/RALFit

cd $SCRIPTPATH/RALFit/libRALFit/
mkdir build
cd build
cmake ..
make
python setup.py build_ext
python setup.py install

cd $SCRIPTPATH
13 changes: 12 additions & 1 deletion docs/source/users/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ on setting up python see :ref:`setting-up-python`.
:target: https://www.python.org/downloads/release/python-2715/

.. _setting-up-python:

******************
Setting up Python
******************
Expand Down Expand Up @@ -193,3 +193,14 @@ manually, first install gdebi: ``sudo apt-get install gdebi`` then
install mantid using: ``sudo gdebi pkgname.deb`` while you are in the
folder from where you downloaded mantid and replace pckgname with the
name of the downloaded file.


.. _setting-up-ralfit:

*****************
Installing RAlfit
*****************

The fitbenchmarking setup does not currently support installing RALfit
through it. RALfit can be downloaded and installed from
`here https://github.com/ralna/RALFit>`__.
15 changes: 11 additions & 4 deletions docs/source/users/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Scipy:
- ``"dogbox"``
- ``"lm"``
- and ``"trf"``


Information about these can be found on the
`Scipy documentation
Expand All @@ -128,9 +128,16 @@ DFO-GN:
- ``"dfogn"``
Information about this can be found on the
`DFO-GN documentation
<http://people.maths.ox.ac.uk/robertsl/dfogn/>`__


<http://people.maths.ox.ac.uk/robertsl/dfogn/>`__


RALfit:
- ``"ralfit"``
Information about this can be found on the
`RALfit documentation
<https://github.com/ralna/RALFit>`__


``comparison_mode``
-------------------
The comparison mode is used when displaying results to select the value
Expand Down
5 changes: 5 additions & 0 deletions fitbenchmarking/fitbenchmark_one_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
from fitbenchmarking.fitting.controllers.mantid_controller import MantidController
except ImportError:
MantidController = None
try:
from fitbenchmarking.fitting.controllers.ralfit_controller import RALFitController
except ImportError:
RALFitController = None
try:
from fitbenchmarking.fitting.controllers.sasview_controller import SasviewController
except ImportError:
Expand Down Expand Up @@ -47,6 +51,7 @@ def fitbm_one_prob(user_input, problem):

controllers = {'dfogn': DFOGNController,
'mantid': MantidController,
'ralfit': RALFitController,
'sasview': SasviewController,
'scipy': ScipyController}

Expand Down
5 changes: 3 additions & 2 deletions fitbenchmarking/fitbenchmarking_default_options.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"Trust Region"],
"scipy" : ["lm", "trf", "dogbox"],
"sasview" : ["amoeba", "lm", "newton", "de", "pt", "mp"],
"dfogn" : ["dfogn"]
"dfogn" : ["dfogn"],
"ralfit" : ["ralfit"]
},

"comparison_mode" : "both"
"comparison_mode" : "both"
}
69 changes: 69 additions & 0 deletions fitbenchmarking/fitting/controllers/ralfit_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
Implements a controller for RALFit
https://github.com/ralna/RALFit
"""

import ral_nlls
from scipy.optimize._numdiff import approx_derivative

from fitbenchmarking.fitting.controllers.base_controller import Controller


class RALFitController(Controller):
"""
Controller for the RALFit fitting software.
"""

def __init__(self, problem, use_errors):
"""
Initialises variable used for temporary storage.
"""
super(RALFitController, self).__init__(problem, use_errors)

self._x = None
self._inform = None

def setup(self):
"""
Setup for RALFit
"""
pass

def _eval_f_arg_swap(self, params, x):
return self.problem.eval_f(x=x,
params=params,
function_id=self.function_id)

def _prediction_error(self, params, x, y):
return self._eval_f_arg_swap(params, x) - y

def _jac(self, params, x, y):
return approx_derivative(self._eval_f_arg_swap,
params,
args=tuple([x]))

def fit(self):
"""
Run problem with RALFit.
"""
self.success = False
try:
(self._x, self._inform) = ral_nlls.solve(self.initial_params,
self._prediction_error,
self._jac,
params=(self.data_x,
self.data_y))
self.success = True
except:
self.success = False

def cleanup(self):
"""
Convert the result to a numpy array and populate the variables results
will be read from.
"""
if self.success:
self.results = self.problem.eval_f(x=self.data_x,
params=self._x,
function_id=self.function_id)
self.final_params = self._x
13 changes: 13 additions & 0 deletions fitbenchmarking/fitting/tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
DFOGNController
from fitbenchmarking.fitting.controllers.mantid_controller import \
MantidController
from fitbenchmarking.fitting.controllers.ralfit_controller import \
RALFitController
from fitbenchmarking.fitting.controllers.sasview_controller import \
SasviewController
from fitbenchmarking.fitting.controllers.scipy_controller import \
Expand Down Expand Up @@ -35,6 +37,7 @@ class DummyController(Controller):
"""
Minimal instantiatable subclass of Controller class for testing
"""

def setup(self):
self.setup_result = 53

Expand All @@ -49,6 +52,7 @@ class BaseControllerTests(unittest.TestCase):
"""
Tests for base software controller class methods.
"""

def setUp(self):
self.problem = FittingProblem(misra1a_file())

Expand Down Expand Up @@ -99,6 +103,7 @@ class ControllerTests(unittest.TestCase):
"""
Tests for each controller class
"""

def setUp(self):
self.problem = FittingProblem(misra1a_file())

Expand Down Expand Up @@ -134,6 +139,14 @@ def test_dfogn(self):
controller.minimizer = 'dfogn'
self.shared_testing(controller)

def test_ralfit(self):
"""
RALFitController: Tests for output shape
"""
controller = RALFitController(self.problem, True)
controller.minimizer = 'ralfit'
self.shared_testing(controller)

def shared_testing(self, controller):
"""
Utility function to run controller and check output is in generic form
Expand Down

0 comments on commit 3685404

Please sign in to comment.