Ticket #7230 (closed: fixed)

Opened 7 years ago

Last modified 5 years ago

Simple api returns don't ignore optional properties

Reported by: Martyn Gigg Owned by: Martyn Gigg
Priority: major Milestone: Release 2.6
Component: Python Keywords:
Cc: Blocked By:
Blocking: Tester: Russell Taylor

Description

The simple API wrappers in the new API are not checking whether a workspace is optional when trying to return it. The old API used to accept the output properties even if they didn’t get produced. Example

from mantid.api import *
from mantid.kernel import *

class OptionalWorkspace(PythonAlgorithm):
    def PyInit(self):
        self.declareProperty(MatrixWorkspaceProperty("RequiredWorkspace", "", Direction.Output))
        self.declareProperty(MatrixWorkspaceProperty("OptionalWorkspace", "", Direction.Output, PropertyMode.Optional))
 
    def PyExec(self):
        ws = WorkspaceFactory.create("Workspace2D", NVectors=1, YLength=1,XLength=1)
        ws.dataY(0)[0] = 5
        self.setProperty("RequiredWorkspace", ws)

        optionalstr = self.getPropertyValue("OptionalWorkspace")
        if optionalstr != "":
          ws = WorkspaceFactory.create("Workspace2D", NVectors=1, YLength=1,XLength=1)
          ws.dataY(0)[0] = 10
          self.setProperty("OptionalWorkspace", ws)
          
        self.getLogger().notice("done!")
result = OptionalWorkspace(RequiredWorkspace="required", OptionalWorkspace="optional")

This should just return the required one as the even though the optional was specified the algorithm didn't create it but it was marked optional so that should be considered okay.

Change History

comment:1 Changed 7 years ago by Martyn Gigg

  • Status changed from new to accepted

comment:2 Changed 7 years ago by Martyn Gigg

Fix Python bug with optional workspace properties.

It now allows an optional output workspace to be specified within the input arguments but still not exist after the algorithm has been executed. Refs #7230

Changeset: 37e5a48a5c16501c7f679f3aed20f3ddc13dbd1b

comment:3 Changed 7 years ago by Martyn Gigg

  • Status changed from accepted to verify
  • Resolution set to fixed

comment:4 Changed 7 years ago by Martyn Gigg

Branch: bugfix/7230_simpleapi_optional_workspace_retvals

Tester: The above test algorithm should allow you to check that the optional output can indeed be ignored.

comment:5 Changed 7 years ago by Russell Taylor

  • Status changed from verify to verifying
  • Tester set to Russell Taylor

comment:6 Changed 7 years ago by Russell Taylor

  • Status changed from verifying to closed

My scripts work now...

comment:7 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 8076

Note: See TracTickets for help on using tickets.