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
The integration of SasView #199
Conversation
…nchmarking The file `example_runScripts_SasView.py` has been updated so that it will prompt a message if Bumps, sasmodels or sascalc is/are not installed. The folder `sas/sascalc` is added as sascalc is not an independent package to be installed via `pip` yet. This folder should be removed once there is an installation method for sascalc.
A script to test the modules in `parse_sasview_data.py` has been added. A set of mock problem files has also been added.
…o check if sasmodels is installed
This is a unit test file for `sasview/prepare_data.py`
This will be remove once bumps and sasmodels can be installed by `python setup.py install`.
lxml is required by sasmodels
@AtomAnu thanks for this PR and it detailed description. You write "As a consequence, it was neccessary to copy the folder sas from the SasView repository and place it inside FitBenchmarking (fitbenchmarking/sas) in order to run SasView headless inside FitBenchmarking.". A questions:
Obviously the above is not ideal, but with the sasview team actively working on separating out sascal it seems like the best workaround |
Thinking about it again. As an alternative to copy and paste have you considered code which
See https://stackoverflow.com/questions/2472552/python-way-to-clone-a-git-repository for suggestions for how a github repo can be cloned |
Dear Anders,
The intention was for the purpose of testing. The problem_sets variable
should be set to [“NIST/low_difficulty”].
Kind regards,
Atom
…On Fri, Aug 23, 2019 at 8:08 AM Anders Markvardsen ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In example_scripts/example_runScripts.py
<#199 (comment)>
:
> @@ -77,7 +78,7 @@
# problem_sets = ["Neutron_data", "NIST/average_difficulty"]
# problem_sets = ["CUTEst", "Muon_data", "Neutron_data", "NIST/average_difficulty", "NIST/high_difficulty", "NIST/low_difficulty"]
-problem_sets = ["NIST/low_difficulty"]
+problem_sets = ["Muon_data"]
@AtomAnu <https://github.com/AtomAnu> did you mean to change problem set
up Muon_data in this script? I.e. with problem_sets = Muon_data this script
with not run without mantid
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#199?email_source=notifications&email_token=AMN6IMHOT4NINSWMBS57NALQF6EHPA5CNFSM4IOIDXA2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCCPJMTA#pullrequestreview-278828620>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMN6IMH4FIDICPCPYETLQC3QF6EHPANCNFSM4IOIDXAQ>
.
|
return results_problem, best_fit | ||
|
||
def fit(problem, data, function, minimizer, init_func_def): | ||
""" |
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.
code comment please
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 meant def comment please
t_start, t_end = None, None | ||
model = function[0] | ||
|
||
if hasattr(model, '__call__'): |
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.
A few code comments here may help
|
||
final_param_values = result.x | ||
|
||
fin_func_def = get_fin_function_def(final_param_values, problem, init_func_def) |
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.
what does 'fin' in fin_func_def stand for
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.
The word fin stands for final in this case.
|
||
from utils.logging_setup import logger | ||
|
||
def prepare_data(problem, use_errors): |
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.
prepare data for what?
popt = list(popt) | ||
params = init_function_def.split("|")[1] | ||
params = re.sub(r"[-+]?\d+\.\d+", lambda m, rep=iter(popt): | ||
params = re.sub(r"[-+]?\d+[.]\d+", lambda m, rep=iter(popt): |
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.
looks subtle - code comment please and e.g. line 61 also
|
||
problem_type = extract_problem_type(problem) | ||
|
||
if not 'name=' in str(problem.equation): |
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.
please add comment to specify what use case this is. And for else below also
function_defs = [[fit_function, params]] | ||
|
||
return function_defs | ||
|
||
def get_fit_function_without_kwargs(fit_function, functions_string): | ||
""" |
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.
please add short def description
def get_fit_function_without_kwargs(fit_function, functions_string): | ||
""" | ||
|
||
:param fit_function: |
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 parameter info please
@@ -179,6 +204,7 @@ def get_fitbenchmark_ties(param_set, ties): | |||
else: | |||
tie = param_set[start + 1:comma] | |||
ties_per_function.append(tie.replace("=", "': ")) | |||
# ties_per_function.append(tie) |
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.
dead comment?
@@ -59,7 +59,7 @@ def __init__(self, fname): | |||
#String containing the function name(s) and the starting parameter values for each function | |||
self._equation = entries['function'] | |||
|
|||
self._starting_values = None | |||
# self._starting_values = (entries['function'].split(',', 1))[1] |
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.
dead comment?
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.
Functional testing all passes.
many thanks for this work - a monster PR!
Please address suggestions for changes in comments
These fixes were done as discussed in the Pull Request
…ng/fitbenchmarking into integratingSasView
… that can specify multiple software
All definitions works with Scipy and Mantid. All work for SasView except for FitBenchmark type problems. For example by setting problem_sets = ["Neutron"] in example_runscript_sasview gives the error
|
Remove SasView_example.py (not obvious what purpose it has)
@AtomAnu thanks for the changes and again for your work over the summer. I have created work for follow up work that this PR has highlighted during testing. |
Description of Work
This is the integration of SasView. There are five main additions for this integration.
An additional example script,
example_runScripts_SasView.py
has been added to use SasView as the software to fit the user-selected problem(s). At the start of the example script, there are three condition statements with each statement verifying if one of the three required SasView packages is installed. Bumps, sasmodels and sascalc are the three required packages. As explained in the FitBenchmarking README.md file, Bumps and sasmodels can be installed usingpip
while sascalc is not an independent package.Additionally, the package sasmodels contains a script
data.py
which contains a module calledload_data
. This module requires sascalc in order to function. In this module's code, the line of code which imports sascalc is written below.from sas.sascalc.dataloader.loader import Loader
Furthermore, sascalc now exists under the directory
src/sas
which resides in the SasView repository (https://github.com/SasView/sasview)As a consequence, it was neccessary to copy the folder
sas
from the SasView repository and place it inside FitBenchmarking (fitbenchmarking/sas
) in order to run SasView headless inside FitBenchmarking.A parsing script,
parse_sasview_data.py
has been added to parse SasView problem definition files and their corresponding data files. This script can later be integrated withparse_fitbenchmark_data.py
.in
parse_sasview_data.py
, the eval_f and get_function modules work in the same manner as that ofparse_nist_data.py
andparse_fitbenchmark_data.py
. However, the module eval_f forparse_sasview_data.py
accepts the parameters list in two formats. The first format is a string which contains the parameter names and values. The second format is to accept the parameter values as multiple parameters to the module.In
parse_fitbenchmark_data.py
, a new module,get_bumps_function
, is created to format Mantid functions into the functions that are acceptable by Bumps. Functions/models that are acceptable by Bumps should not contain any arguments (*arg) or keyword arguments (**kwargs).A data preparation script,
sasview/prepare_data.py
, has been created to prepare the data in the correct format. There are three main tasks done in this script. The first task is to set the data errors (data_e) if they are not given in the data file. The second task is to set the X data range if specified. If the X data range is not specified, the range would be set from the minimum X value to the maximum X value. The final task is to create a data object of typesasmodels.data.Data1D
so that it can be passed onto Bumps.A function definition preparation script,
sasview/func_def.py
, has been created to prepare the models/functions and their starting parameter values for Bumps fitting. The script also prepares the initial and the final function definition strings for each fit.Finally, a script,
sasview/main.py
, has been added to perform fitting using Bumps. All the fitting occur in the modulefit
. One can observe that this module is quite lengthy. This is because the method of configuring the function/model is different for SasView models and other functions from Scipy and Mantid. Nevertheless, this module could be shorten up in the future.This script also calculates the chi-squared value and the run time of each fit. Then, a result object is created for the graph and table creating modules. A single result object contains the fitted Y values, the fit status, the chi-squared value, the fit runtime, the minimiser name, the initial function definition string and the final function definition string.
Note that the unit tests for these scripts have not been completed.
Testing Instructions
example_runScripts.py
with problems of type NIST, FitBenchmark and SasViewexample_runScripts_mantid.py
with problems of type NIST, FitBenchmark and SasViewexample_runScripts_SasView.py
with problems of type NIST, FitBenchmark and SasView