Ticket #5157 (closed: fixed)

Opened 8 years ago

Last modified 5 years ago

Expose DataProcessorAlgorithm to Python

Reported by: Martyn Gigg Owned by: Martyn Gigg
Priority: blocker Milestone: Release 3.2
Component: Framework Keywords: CORE
Cc: Blocked By: #5051
Blocking: Tester: Anders Markvardsen

Description

When DataProcessorAlgorithm is completed it needs to be exposed to Python in a similar manner to the plain Python algorithms. Workflow algorithms can then inherit from this & get things such as history recording of sub-algorithms etc.

Change History

comment:1 Changed 8 years ago by Nick Draper

  • Milestone changed from Release 2.1 to Release 2.2

Moved at end of release 2.1

comment:2 Changed 8 years ago by Nick Draper

  • Status changed from new to assigned
  • Owner set to Martyn Gigg

comment:3 Changed 8 years ago by Nick Draper

  • Milestone changed from Release 2.2 to Release 2.3

Moved at the end of release 2.2

comment:4 Changed 8 years ago by Nick Draper

  • Milestone changed from Release 2.3 to Release 2.4

Moved to milestone 2.4

comment:5 Changed 8 years ago by Martyn Gigg

  • Milestone changed from Release 2.4 to Release 2.5

comment:6 Changed 7 years ago by Nick Draper

  • Milestone changed from Release 2.5 to Release 2.6

Moved to r2.6 at the end of r2.5

comment:7 Changed 7 years ago by Martyn Gigg

  • Milestone changed from Release 2.6 to Release 2.7

Batch move to 2.7

comment:8 Changed 7 years ago by Nick Draper

  • Status changed from assigned to new

comment:9 Changed 7 years ago by Nick Draper

  • Milestone changed from Release 2.7 to Backlog

comment:10 Changed 7 years ago by Nick Draper

  • Component changed from Mantid to Framework

comment:11 Changed 7 years ago by Martyn Gigg

  • Milestone changed from Backlog to Release 3.0

comment:12 Changed 7 years ago by Nick Draper

  • Milestone changed from Release 3.0 to Backlog

Moved out to backlog as not enough time in R3.0

comment:13 Changed 7 years ago by Martyn Gigg

  • Priority changed from major to blocker

comment:14 Changed 7 years ago by Martyn Gigg

  • Milestone changed from Backlog to Release 3.2

comment:15 Changed 7 years ago by Nick Draper

  • Status changed from new to assigned

Bulk move of tickets out of triage (new) to assigned at the introduction of the triage state

comment:16 Changed 7 years ago by Martyn Gigg

  • Status changed from assigned to inprogress

Add pass-through methods for DataProcessor

MSVC won't compile when they have been redefined as public on the adapter class when used in conjunction with the boost.python class_ exporter. Refs #5157

Changeset: dbf9091bc6cd6d0a798c0863790137c899991273

comment:17 Changed 7 years ago by Martyn Gigg

Remove Python FrameworkManager::createAlgorithm method.

It was different to the C++ one and it wasn't transparent as to what happened when an algorithm was created. The code for creating an algorithm for a simpleapi function is now back in the simpleapi module so it is easier to determine what is actually happening. Refs #5157

Changeset: b288ecbb288efbb596a39efca7e887bb17854918

comment:18 Changed 7 years ago by Martyn Gigg

Remove unused callstack methods

Refs #5157

Changeset: 46315420d66e75224519fe83ae834cfd04f171e0

comment:19 Changed 7 years ago by Martyn Gigg

Update FrameworkManager.createAlgorithm references

They now use the more standard AlgorithmManager. Refs #5157

Changeset: e523f3eefa384f29da3b111c87bbce710d931452

comment:20 Changed 7 years ago by Martyn Gigg

Update RunPythonScript to wrap script code in small algorithm.

This ensures that all calls to make child algorithms go through Algorithm.createChildAlgorithm Refs #5157

Changeset: c271b4cad31637aaeffe79e876cbac90456a8170

comment:21 Changed 7 years ago by Martyn Gigg

The Python-level declareProperty methods are now static

They also accept a boost::python::object as the first argument so that they can match against multiple types of base class. Refs #5157

Changeset: 082dc3cb982fbe9846256392b978fb03206ee4b4

comment:22 Changed 7 years ago by Martyn Gigg

Fix check for DataProcessor as base class.

Refs #5157

Changeset: 5db11d64488c504ebac1e97ffc1d94304ddb1981

comment:23 Changed 7 years ago by Martyn Gigg

Use DataProcessorAlgorithm as base for algorithms requiring history

Refs #5157

Changeset: 7268e6dc7c92fc18cf351b95d881865c121c75f9

comment:24 Changed 7 years ago by Martyn Gigg

Switch systemtest usage of FrameworkManager to AlgorithmManager.

Refs #5157

Changeset: 4adc4a3b164aa22002db8ce9d16de1c9b00f01d5

comment:25 Changed 7 years ago by Martyn Gigg

Fix a few createAlgorithm references.

Refs #5157

Changeset: 97bbccda11727df0ad17703003e21d65bf15d543

comment:26 Changed 7 years ago by Martyn Gigg

Export exists method on python AlgorithmFactory.

Refs #5157

Changeset: a12527781534e8214a3f64d1b32891c646f8002a

comment:27 Changed 7 years ago by Martyn Gigg

Use AlgorithmFactory::exists for checking algorithm availability

...in SNSPowderReduction. This avoids the far more expensive check of grabbing all registered algorithms and checking that list and cuts down the required work at start up. Refs #5157

Changeset: 0349d8b13248c803000a222788c2d42a2006c76e

comment:28 Changed 7 years ago by Martyn Gigg

Change SNSPowderReduction to be a DataProcessorAlgorithm.

This then preserves the history of the child algorithms so that it can generate its script. Refs #5157

Changeset: d31067533e2010f0f00d964d7e7e9b0e64307c60

comment:29 Changed 7 years ago by Martyn Gigg

A bit more commenting around creating the child algorithms in Python

Refs #5157

Changeset: a44f55f6d448cb36c7f87bdf57a2d5f940e7221d

comment:30 Changed 7 years ago by Martyn Gigg

Merge remote-tracking branch 'origin/master' into feature/5157_dataprocessor_in_python

Conflicts:

Code/Mantid/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py

Refs #5157

Changeset: 775773201bd8c5b5d1aa40275837246e2fa34f70

comment:31 Changed 7 years ago by Martyn Gigg

  • Keywords CORE added

comment:32 Changed 7 years ago by Martyn Gigg

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

Branch: feature/5157_dataprocessor_in_python

Tester: This affects the python algorithm portion of the Python layer so has been marked CORE as it involved refactoring some of the old code.

The summary of the changes are:

  • The DataProcessorAlgorithm class is now available to be inherited from in Python
  • History is now only recorded for child algorithms run through the simpleapi functions if their parent is a python alg and specifcally inherits from DataProcessorAlgorithm
  • SNSPowderReduction now inherits from DataProcessorAlgorithm in order to get the history recording so that it can generate a script of itself.

The following algorithm is a very basic DataProcessorAlgorithm. Check that running this and looking at the workspace history of the output workspace shows the Load command. The history will also show the top-level algorithm and does look a little confusing but this is outside the remit of this ticket and will be addressed in #8913.

After that has been verified, switch the base class to be a plain PythonAlgorithm and check that now the only history record is that of the top-level MyReduction algorithm

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

class MyReduction(DataProcessorAlgorithm):

    def PyInit(self):
        self.declareProperty(FileProperty("Filename", "", FileAction.Load), "Input filename")
        self.declareProperty(WorkspaceProperty("OutputWorkspace", "", Direction.Output))

    def PyExec(self):
        from mantid.simpleapi import Load, DeleteWorkspace
        _ws = Load(Filename=self.getPropertyValue("Filename"))
        self.setProperty("OutputWorkspace", _ws)
        DeleteWorkspace(_ws)

# end class

AlgorithmFactory.subscribe(MyReduction)
########################################

comment:33 Changed 7 years ago by Martyn Gigg

Kill OS X compiler warning.

Refs #5157

Changeset: 5c5758704ee20b06506e20549f9114379b12d35a

comment:34 Changed 7 years ago by Anders Markvardsen

  • Status changed from verify to verifying
  • Tester set to Anders Markvardsen

comment:35 Changed 7 years ago by Anders Markvardsen

History with DataProcessorAlgorithm:

###################################################################### #Python Script Generated by GeneratePythonScript Algorithm ###################################################################### Load(Filename=r'isis/inst$/NDXHRPD/Instrument/data/cycle_13_5/HRP58607.nxs',OutputWorkspace='_ws') MyReduction(Filename=r'isis/inst$/NDXHRPD/Instrument/data/cycle_13_5/HRP58607.nxs',OutputWorkspace='HRPD')

History with PythonAlgorithm:

###################################################################### #Python Script Generated by GeneratePythonScript Algorithm ###################################################################### MyReduction(Filename=r'isis/inst$/NDXHRPD/Instrument/data/cycle_13_5/HRP58607.nxs',OutputWorkspace='HRPD')

comment:36 Changed 7 years ago by Anders Markvardsen

  • Status changed from verifying to closed

Merge remote-tracking branch 'origin/feature/5157_dataprocessor_in_python'

Full changeset: 7b659c2c8e14224822762851e8f15a584c5c7026

comment:37 Changed 7 years ago by Martyn Gigg

Merge remote-tracking branch 'origin/feature/5157_dataprocessor_in_python'

Full changeset: 01479bf46dc259175ab53c3b3d703e5e13de6f39

comment:38 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 6003

Note: See TracTickets for help on using tickets.