Open butlerpd opened 5 years ago
Trac update at 2012/05/06 16:07:28
: butlerpd changed milestone from "" to "WishList"
Trac update at 2015/01/30 00:41:32
: butler changed workpackage from "" to "SasView Fitting Redesign"
Trac update at 2017/01/17 13:05:47
: ajj changed component from "SansView" to "SasView"
This ticket came up today during our training class at NIST. The biggest hurdle the students are facing is no longer writing the model structure, it is debugging the mathematics, especially in more complex systems. The suggestion in this ticket may not be the best way, but some form of debugging tool is needed when writing plugin models.
perhaps we could implement a logger function for the C code that can pass back to the console whatever it is passed? maybe not elegant.... but?
I mostly use sascomp from the command line for debugging models.
It turns out you can run it from >tool >python shell/editor
as well:
import sasmodels.compare
def sascomp(s): sasmodels.compare.main(*s.split())
sascomp("sphere radius=500,600") # compares two radii of sphere on the same plot
sascomp("sphere,cylinder length=4/3*radius -highq") # compare sphere to same volume cylinder
cd ~/.sasview/plugin_model
sascomp("newmodel.py") # runs a model in the plugin directory
sascomp("-h") # Show the many options available to sascomp
Unfortunately you can't use --edit
for the interactive model viewer that lets you drag parameters with a slider since sasview no longer provides wx
.
The other thing I use is sasmodels/explore/realspace.py
. Using points uniformly selected from the shape I can compute a monte carlo approximation to the model and compare it against the analytic form implemented in sasview. This option isn't available inside the sasview gui.
To clarify a bit there are (so far) 2 critical issues identified here (none of which are about validation of the model - i.e. is it giving the correct answer compared to some known "standard").
printf
does not seem to print to the console and there is no simple way to access all the C variables in python for printing out.... and complicated models are likely to be in C. This is a huge issue it turns out. If there were an easy way to allow printf
to print to the console log that would fix this problem.There may be other issues I'm forgetting but these are the ones I noticed both in preparing the demo and working with the model writing group.
You can put printf
statements into the C code so long as you don't run it on the gpu. Easy enough to do with sascomp from the terminal but this requires a python development environment.
You could set up the sasview application to run python scripts. This would be useful for people who want to do batch processing on files but don't have a python development environment set up. Add the -m
option similar to the python interpreter and you could test your model using sasview -m sasmodels.compare model.py
. The printf
output should then show up in the terminal.
You could probably run the model within the sasview gui and capture the output to the log window but it'll take a bit of fiddling. Maybe it is as simple as redirecting sys.stdout to a string before running the model. Or maybe you will have to run it as a separate process and capture the process output.
The ability to launch a "debug my model" process or window might be good ask user for a single Q value, or list of Q values, then print out everything that comes back from compilation and run output - the main results, plus perhaps, optionally, the whole long list that the model returns. This would be a half way house to what "show plot" might do. May be very helpful when we try to make more complex sum & product combination models, where sasview needs some work still. My original request on this ticket was to just run one iteration of a "fit" rather than run to convergence, as that might also help in a debug situation. (Personally, because of all the difficulties, I always make new models in the main code of my developer build not the plugin directory, print( ) or printf() in the models appears in the console window, so maybe I'm not the best to comment on this as I never use the gui model editor.)
Richard Heenan points out that it can be very useful when fits go awry to be able to single step through each iteration, with a rewind option.
Migrated from http://trac.sasview.org/ticket/31