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

numpy/scipy cause syntax errors in python model builder (Trac #1218) #1247

Closed
pkienzle opened this issue Mar 30, 2019 · 9 comments
Closed

numpy/scipy cause syntax errors in python model builder (Trac #1218) #1247

pkienzle opened this issue Mar 30, 2019 · 9 comments
Assignees
Labels
Defect Bug or undesirable behaviour Major Big change in the code or important change in behaviour

Comments

@pkienzle
Copy link
Contributor

pkienzle commented Mar 30, 2019

If the code in your simple python model contains numpy, np or scipy then it will cause a syntax error when you try to run the model. This is because the model builder does not include \n when it inserts the numpy import line.

Better would be to place the imports at the top of the template for all models instead of including it dynamically in the function definition. The model reload problems should be fixed, so this should now work. This will make the code simpler, and we are relying on this fix already for the trig and exponential functions.

Instead of from math import *, we should use from sasmodels.special import * at the top of the template. This will define the same set of functions that are available to C models, including functions such as sas_erf, etc, constants such as M_PI and the gaussian quadrature weights for 20, 76 and 150 point quadrature. It also defines the np symbol in case any thing else is needed.

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

{
    "status": "assigned",
    "changetime": "2018-12-12T03:01:22",
    "_ts": "2018-12-12 03:01:22.193668+00:00",
    "description": "If the code in your simple python model contains numpy, np or scipy then it will cause a syntax error when you try to run the model. This is because the model builder does not include `\\n` when it inserts the numpy import line.\n\nBetter would be to place the imports at the top of the template for all models instead of including it dynamically in the function definition. The model reload problems should be fixed, so this should now work.  This will make the code simpler, and we are relying on this fix already for the trig and exponential functions.\n\nInstead of `from math import *`, we should use `from sasmodels.special import *` at the top of the template.  This will define the same set of functions that are available to C models, including functions such as sas_erf, etc, constants such as M_PI and the gaussian quadrature weights for 20, 76 and 150 point quadrature.  It also defines the `np` symbol in case any thing else is needed.",
    "reporter": "pkienzle",
    "cc": "",
    "resolution": "",
    "workpackage": "SasView Bug Fixing",
    "time": "2018-11-16T23:39:31",
    "component": "SasView",
    "summary": "numpy/scipy cause syntax errors in python model builder",
    "priority": "major",
    "keywords": "",
    "milestone": "SasView 4.3.0",
    "owner": "piotr",
    "type": "defect"
}
@pkienzle pkienzle added this to the SasView 4.3.0 milestone Mar 30, 2019
@pkienzle pkienzle added Defect Bug or undesirable behaviour Incomplete Migration Major Big change in the code or important change in behaviour labels Mar 30, 2019
@butlerpd
Copy link
Member

Trac update at 2018/11/17 00:10:30:

  • butler commented:

should be trivial enough to fix so would be nice to do.

  • butler changed milestone from "SasView 4.3.0" to "SasView 4.2.1"

@butlerpd
Copy link
Member

Trac update at 2018/11/27 14:39:18:

  • butler changed owner from "" to "piotr"
  • butler changed status from "new" to "assigned"

@rozyczko
Copy link
Member

Trac update at 2018/11/28 08:59:01: piotr commented:

It appears I already had "\n" added to relevant lines in the Qt version.
The ''sasmodels'' import may be superior but it is hiding information from the user - what are we actually importing? At least with the ''math'' module the user knows exactly what the namespace is.

@rozyczko
Copy link
Member

Trac update at 2018/11/28 09:21:24:

  • piotr changed _comment0 from "Added the newline characters." to "1543397096302126"
  • piotr commented:

Added the newline characters. Pull request #348

@pkienzle
Copy link
Contributor Author

Trac update at 2018/11/28 15:06:07: pkienzle commented:

The namespace is documented in the sasmodels manual.

I suggest renaming the ticket: "Make the opencl special function library available to python models".

Maybe add that the template builder should be moved to sascalc rather than living in the GUI tree, or maybe make that a new ticket.

@sasview-bot
Copy link

Trac update at 2018/12/12 02:54:56: GitHub [email protected] commented:

In changeset 33d3a74:

#!CommitTicketReference repository="sasview" revision="33d3a74a667474b22585012089a8913dabfa7454"
Merge pull request #348 from SasView/ticket-1218

Added newlines to import statements in the plugin model template.

Addresses #1247
need to edit 1218 now

@butlerpd
Copy link
Member

Trac update at 2018/12/12 03:01:03: butler commented:

Could this not be fixed by just adding a comment line before the import statement explaining what is being imported? The user writing a plugin doesn't see any of this anyway so should not matter?

Replying to [comment:3 piotr]:

It appears I already had "\n" added to relevant lines in the Qt version.
The ''sasmodels'' import may be superior but it is hiding information from the user - what are we actually importing? At least with the ''math'' module the user knows exactly what the namespace is.

@butlerpd
Copy link
Member

Trac update at 2018/12/12 03:01:22: butler changed milestone from "SasView 4.2.1" to "SasView 4.3.0"

@rozyczko
Copy link
Member

rozyczko commented Apr 5, 2019

Addressed in ESS_GUI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Defect Bug or undesirable behaviour Major Big change in the code or important change in behaviour
Projects
None yet
Development

No branches or pull requests

4 participants