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

Reparameterizing an inline C model fails #605

Open
tsole0 opened this issue Jul 15, 2024 · 1 comment
Open

Reparameterizing an inline C model fails #605

tsole0 opened this issue Jul 15, 2024 · 1 comment
Labels

Comments

@tsole0
Copy link
Contributor

tsole0 commented Jul 15, 2024

**Partner issue of SasView/sasview#2958
** To see how to replicate issue in the SasView GUI, see above issue

Describe the bug
Reparameterizing a python model with inline C code will fail with an error in the format:

11:29:37 - root - ERROR - C:\Users\userDir\AppData\Local\miniconda3\envs\sasview_dev\Lib\site-packages\tinycc\tcc.exe -shared -rdynamic -Wall C:\Users\userDir\AppData\Local\Temp\1\sas64_reparameterizedModel_EF781090_2i9v5xc5.c -o C:\Users\userDir\.sasview\compiled_models\sas64_reparameterizedModel_EF781090.so
C:/Users/userDir/.sasview/plugin_models/oldModel.py:35: error: 'reparameterizedVariable' undeclared

on the developer version of SasView, where reparameterizedModel is the reparameterized file, oldModel is the model being reparameterized, and reparameterizedVariable is the name of a reparameterized variable accessed in inline C code within oldModel.

This bug occurs if any inline C code is included in the model, even if a separate C file is defined using source = [] in the main python file. However, models that have defined C code entirely in a separate file are unaffected.

Note: currently, this bug only affects lamellar.py in the 1.0.7 sasmodels version, but will also affect any user-created models with inline C unless resolved

To Reproduce
Steps to reproduce the behavior:

  1. Create a new user model.
  2. Copy in the following code:
from numpy import inf

from sasmodels.core import reparameterize
from sasmodels.special import *

parameters = [
    # name, units, default, [min, max], type, description
	['new', '', 0, [-inf, inf], '', ''],
]

translation = """
    sld = new
"""

model_info = reparameterize('lamellar', parameters, translation, __file__)
  1. The new model should return an error if a model check is run on it

Expected behavior
The model should have no issues being loaded or used with the new redefinitions.

sasmodels version:

  • Version: 1.0.7

Suggested Solution:
Either deprecate using inline C code (only one model currently uses it and it is easily replaceable), or fix the reparameterization code in sasmodels.core to support inline C code.

@pkienzle
Copy link
Contributor

pkienzle commented Sep 3, 2024

generate._gen_fn needs to be called on the original parameter table, not the new parameter table defined by core.reparameterize. Replacing call_table with base_table in the following should work.

if isinstance(model_info.form_volume, str):
pars = call_table.form_volume_parameters
source.append(_gen_fn(model_info, 'form_volume', pars))
if isinstance(model_info.shell_volume, str):
pars = call_table.form_volume_parameters
source.append(_gen_fn(model_info, 'shell_volume', pars))
if isinstance(model_info.Iq, str):
pars = [q] + call_table.iq_parameters
source.append(_gen_fn(model_info, 'Iq', pars))
if isinstance(model_info.Iqxy, str):
pars = [qx, qy] + call_table.iq_parameters + call_table.orientation_parameters
source.append(_gen_fn(model_info, 'Iqxy', pars))
if isinstance(model_info.Iqac, str):
pars = [qab, qc] + call_table.iq_parameters
source.append(_gen_fn(model_info, 'Iqac', pars))
if isinstance(model_info.Iqabc, str):
pars = [qa, qb, qc] + call_table.iq_parameters
source.append(_gen_fn(model_info, 'Iqabc', pars))

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

No branches or pull requests

2 participants