SasView / sasview

Code for the SasView application.
BSD 3-Clause "New" or "Revised" License
51 stars 41 forks source link

Reparameterization of multiplicity models does not work correctly #2634

Open smk78 opened 1 year ago

smk78 commented 1 year ago

Creating this as a sasview issue on advice of @lucas-wilkins, but it may be a sasmodels issue instead/too.

Describe the bug User SteveP was trying to reparametrize the core_multi_shell model thus:

from numpy import inf
from sasmodels.core import reparameterize
#             ["name", "units", default, [lower, upper], "type","description"],
parameters = [["core_c_sld", "1e-6/Ang^2", 1.0, [-inf, inf], "sld",
               "Core Cytoplasm scattering length density"],
              ["core_c_radius", "Ang", 200., [0, inf], "volume",
               "Radius of the core"],

              # Buffer 
              ["sld_buffer", "1e-6/Ang^2", 6.4, [-inf, inf], "sld",
               "Solvent aka buffer scattering length density"],

              ["new_n", "", 2, [0, 10], "volume",
               "number of shells"],
              # Head group
              ["head_sld[new_n]", "1e-6/Ang^2", 1.7, [-inf, inf], "sld",
               "scattering length density of the head group"],
              ["head_thickness[new_n]", "Ang", 40., [0, inf], "volume",
               "Thickness of the head group k"],
              # Chain group
              ["chain_sld[new_n]", "1e-6/Ang^2", 1.7, [-inf, inf], "sld",
               "scattering length density of the head group"],
              ["chain_thickness[new_n]", "Ang", 40., [0, inf], "volume",
               "Thickness of the head group k"], 

             ]

translation = """ 
    sld_core=core_c_sld
    radius=core_c_radius

    sld_solvent=sld_buffer

    n=new_n
    # Shell 1      
    sld1=head_sld
    thickness1=head_thickness
    # Shell 2      
    sld2=chain_sld
    thickness2=chain_thickness

    """
model_info = reparameterize('core_multi_shell', parameters, translation, __file__)

The translation sort of works, but the parameters under multiplicity control are sort of duplicated in both their untranslated and translated forms.

To Reproduce Load the code block above as a plugin model and scroll through the parameter list.

Expected behavior The parameters should translate correctly.

SasView version (please complete the following information):

Operating system (please complete the following information):

smk78 commented 1 year ago

@butler commented in [Help]:

The multishell is an example of a "multiplicity" model. Basically it uses a non fittable parameter that controls flow in some way - in this case how many times the shell loop gets implemented (for the RPA it controls which of 10 cases to use). The problem is that the reparameterization code was written without thinking of that special model case and use of the reparameterization code for multiplicity models never tested as far as I know (or Paul Kienzle knows). My guess is that the code does NOT handle multiplicity at all?