Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#1052 closed defect (fixed)

Can't use a user-created plugin model in a plugin model

Reported by: smk78 Owned by: krzywon
Priority: critical Milestone: SasView 4.2.0
Component: SasView Keywords:
Cc: Work Package: SasView Bug Fixing

Description

Tested with Jenkins nightly and pulling from master and building, both on Win7.

I did have a quick look to see if this was already ticketed but couldn't see anything obvious, so apologies if I've missed an existing ticket.

You can create a plugin using Sum|Multi to, say, add two built-in functions together. If you then want to add a third function to those two the natural reaction of a normal user (eg, one of our team members) is to go back to Sum|Multi and create a new plugin selecting the previously created plugin as one of the two functions.

If you do this SasView creates a syntactically-correct and valid-looking .py, for example:

from sasmodels.core import load_model_info
from sasmodels.sasview_model import make_model_from_info

model_info = load_model_info('sarah2+sphere')
model_info.name = 'sarah5'
Model = make_model_from_info(model_info)

but the new plugin does not appear in the model chooser. If you go the Advanced Model Editor, select the new plugin and run Check Model you get something like this (where sarah2 was the first plugin created):

Running model 'sarah5.py'...

Error occurred:
Traceback (most recent call last):
  File "D:\!SasViewDevelopment\sasview\src\sas\sasgui\perspectives\calculator\pyconsole.py", line 53, in show_model_output
    result, errmsg = check_model(fname), None
  File "D:\!SasViewDevelopment\sasview\src\sas\sasgui\perspectives\calculator\pyconsole.py", line 32, in check_model
    Model = load_custom_model(path)
  File "D:\!SasViewDevelopment\sasmodels\sasmodels\sasview_model.py", line 114, in load_custom_model
    kernel_module = custom.load_custom_kernel_module(path)
  File "D:\!SasViewDevelopment\sasmodels\sasmodels\custom\__init__.py", line 45, in load_custom_kernel_module
    os.path.expanduser(path))
  File "D:\!SasViewDevelopment\sasmodels\sasmodels\custom\__init__.py", line 36, in load_module_from_path
    module = imp.load_source(fullname, os.path.expanduser(path))
  File "C:\Users\smk78\.sasview\plugin_models\sarah5.py", line 5, in <module>
    model_info = load_model_info('sphere+sarah2')
  File "D:\!SasViewDevelopment\sasmodels\sasmodels\core.py", line 162, in load_model_info
    addition_parts = [load_model_info(part) for part in addition_parts_names]
  File "D:\!SasViewDevelopment\sasmodels\sasmodels\core.py", line 182, in load_model_info
    kernel_module = generate.load_kernel_module(product_parts_names[0])
  File "D:\!SasViewDevelopment\sasmodels\sasmodels\generate.py", line 837, in load_kernel_module
    __import__('sasmodels.models.'+model_name)
!ImportError: No module named sarah2

The workaround is simply to edit the plugin directly and specify all three functions in one plugin, for example:

from sasmodels.core import load_model_info
from sasmodels.sasview_model import make_model_from_info

model_info = load_model_info('elliptical_cylinder+broad_peak+sphere')
model_info.name = 'sarah4'
Model = make_model_from_info(model_info)

but this is surely not we intended or would prefer?

Am marking this as a blocker for now so it gets some visibility/discussion, but fully expect it to be dropped a notch later.

Change History (5)

comment:1 Changed 7 years ago by butler

So is this because the generate infrastructure only looks in the built in model directory and not the plugin directory?

comment:2 Changed 7 years ago by butler

  • Owner set to krzywon
  • Priority changed from blocker to critical
  • Status changed from new to assigned

See if we can get PK hack in quickly.

comment:3 Changed 7 years ago by smk78

Have tested the fix in krzywon's sasmodels/sasview ticket-1052 branches. Works for me (on W10)! Recommend the PRs be merged.

comment:4 Changed 7 years ago by GitHub <noreply@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 5973257358efa6f1c17a25df619aabe38fe1543c/sasview:

Merge pull request #146 from SasView?/ticket-1052

Ticket 1052: Allow custom models to be used in sum|multi models

closes #1052

comment:5 Changed 7 years ago by GitHub <noreply@…>

In a0243f7d4897a26b23de5bca1382aa9a9b5bc06e/sasmodels:

Merge pull request #63 from SasView?/ticket-1052

Ticket 1052: Allow custom models to be used in sum|multi models

closes #1052

Note: See TracTickets for help on using tickets.