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

autogenerated plot in doc for rpa is not helpful (Trac #871) #145

Open
butlerpd opened this issue Mar 30, 2019 · 4 comments
Open

autogenerated plot in doc for rpa is not helpful (Trac #871) #145

butlerpd opened this issue Mar 30, 2019 · 4 comments

Comments

@butlerpd
Copy link
Member

butlerpd commented Mar 30, 2019

The autogeneration of an example plot in sasmodel documentation based on default parameters is quite useful normally, it can be problematic for multiplicity models where all the parameters of the multiplicity have the same value. In particular the rpa has scattering length of each component as a multiplicity parameter so all are set equal to the one default. Unfortunately that means that I(Q)=0 at all Q. It would be nice if we could get a sensible plot in such, admittedly rare, cases.

Migrated from http://trac.sasview.org/ticket/871

{
    "status": "new",
    "changetime": "2019-03-27T12:42:26",
    "_ts": "2019-03-27 12:42:26.918941+00:00",
    "description": "The autogeneration of an example plot in sasmodel documentation based on default parameters is quite useful normally, it can be problematic for multiplicity models where all the parameters of the multiplicity have the same value.  In particular the rpa has scattering length of each component as a multiplicity parameter so all are set equal to the one default.  Unfortunately that means that I(Q)=0 at all Q.  It would be nice if we could get a sensible plot in such, admittedly rare, cases.",
    "reporter": "butler",
    "cc": "",
    "resolution": "",
    "workpackage": "SasModels Infrastructure",
    "time": "2017-03-07T06:25:38",
    "component": "sasmodels",
    "summary": "autogenerated plot in doc for rpa is not helpful",
    "priority": "major",
    "keywords": "",
    "milestone": "SasView 4.3.0",
    "owner": "",
    "type": "defect"
}
@pkienzle
Copy link
Contributor

Trac update at 2017/03/07 13:43:55: pkienzle commented:

(1) Accept vector values for parameter defaults so you can provide an interesting default parameter set.

parameters = [
    ["case_num", "", 1, [CASES], "", "Component organization"],

    ["N[4]", "", [1000.0, 1000.0, 500., 750.], [1, inf], "", "Degree of polymerization"],
    ...
    ["K34", "", -0.0004, [-inf, inf], "", "C:D interaction parameter"],
]

The doc generator will need to know how to format parameter lists.

(2) Use the "demo" parameter set for the doc plot. We can remove demo parameters for all models that have reasonable defaults, which is to say most of them. Demo already supports vector parameters:

demo = {
    "N": [1000., 1000., 500., 750.],
    ...
}

The doc generator will need to include a nicely formatted list of parameter values that are not the default value as part of the figure caption.

(3) Give the user direct control over the sphinx layout of the parameter table. This would allow us to define the table using sasview 3.x parameter names while still having a compact table representation:

parameters = [
    ["case_num", "", 1, [CASES], "", "Component organization"],

    ["Na", "", 1000.0, [1, inf], "", "Degree of polymerization"],
    ["Nb", "", 1000.0, [1, inf], "", "Degree of polymerization"],
    ...
    ["Kcd", "", -0.0004, [-inf, inf], "", "C:D interaction parameter"],
]
parameter_table = """
============== ========================= ======= =============
Parameter      Description               Units   Default value
============== ========================= ======= =============
scale          Source intensity          None                1
background     Source background         |cm^-1|         0.001
case_num       Component organization    None                1
Na,...,Nd      Degree of polymerization  None             1000
Phia,...,Phid  Volume fraction           None             0.25
va,...,vd      specific volume           mL/mol            100
La,...,Ld      scattering length         fm                 10
ba,...,bd      segment length            |Ang|               5
Kab,...,Kcd    Component interaction     None          -0.0004
============== ========================= ======= =============
"""

(4) Allow the parameter table to be manipulated after construction. We should probably do this anyway since it is pretty trivial and provides a lot of flexibility. The result would look something like:

from sasmodels import modelinfo

parameters = [
    ["case_num", "", 1, [CASES], "", "Component organization"],

    ["N[4]", "", 1000.0, [1, inf], "", "Degree of polymerization"],
    ...
    ["K34", "", -0.0004, [-inf, inf], "", "C:D interaction parameter"],
]
parameters = modelinfo.make_parameter_table(parameters)
demo = {
    "N": [1000., 1000., 500., 750.],
    ...
}
for k, v in modelinfo.expand_pars(parameters, demo):
    for p in parameters.user_parameters:
        if p.id == k: 
            p.default = v

We could then rename the user parameters from N1,N2,... to Na, Nb,... using:

for p in parameters.user_parameters:
    p.id = p.id.replace('1','a').replace('2','b').replace('3','c').replace('4','d')

This approach will be somewhat brittle. Any changes to the internal data structures will require all affected models to be updated. The doc generator won't know how to handle an arbitrary manipulation of the internal data structures, so this would need to be in combination with option (3).

These options are not exclusive. That is, we may want to have independent control of the default values on vectors while using the demo values to generate the default plot while allowing the user to override the parameter table while allowing direct manipulation of the underlying !ParameterTable data structure.

@butlerpd
Copy link
Member Author

Trac update at 2017/10/27 15:18:48: butler changed milestone from "SasView 4.2.0" to "SasView 4.3.0"

@butlerpd
Copy link
Member Author

Trac update at 2019/03/02 00:19:56: butler changed workpackage from "SasModels Redesign" to "SasModels Infrastructure"

@smk78
Copy link
Contributor

smk78 commented Mar 30, 2019

Trac update at 2019/03/27 12:42:26: smk78 commented:

Also see attachments in SasView/sasview#1283

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants