Ticket #6015 (closed: fixed)

Opened 8 years ago

Last modified 5 years ago

Binary operations in python don't return the desired workspace type

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

Description

I'm not sure if this is always the case or not, but the following scriptlets will at the last line give back a workspace of type IMDWorkspace rather than MatrixWorkspace:

ws2d = Load('LOQ48127')
column = Integration(ws2d)
column = ws2d / column
ws2d = Load('LOQ48127')
singlespec = SumSpectra(ws2d)
singlespec += ws2d

The expected fix was to make the following change around line 81 of _workspaceops.py:

    # Do the operation
    _performBinaryOp(self,rhs, op, output_name, inplace, reverse)
    resultws = AnalysisDataService[output_name]

However, this leads to a hang/crash of the VanillaPythonInterfaceTest unit test suite (apparently for some problem relating to the algorithm history propagation), so some investigation is required.

Change History

comment:1 Changed 8 years ago by Russell Taylor

Here's a stack trace of the point the VanillaPythonInterfaceTest.py crashes on my mac build. The point at which it crashes is in this function:

  inline bool operator<(const AlgorithmHistory &other) const
  {
    return (execCount() < other.execCount()) ;
  }

I suspect that 'other' has been deleted by the point this function is being called.

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libMantidAPI.dylib            	0x000000010b42d97f Mantid::API::AlgorithmHistory::operator<(Mantid::API::AlgorithmHistory const&) const + 63 (AlgorithmHistory.h:79)
1   libMantidAPI.dylib            	0x000000010b42a415 std::less<Mantid::API::AlgorithmHistory>::operator()(Mantid::API::AlgorithmHistory const&, Mantid::API::AlgorithmHistory const&) const + 39 (stl_function.h:227)
2   libMantidAPI.dylib            	0x000000010b42affd std::_Rb_tree<Mantid::API::AlgorithmHistory, Mantid::API::AlgorithmHistory, std::_Identity<Mantid::API::AlgorithmHistory>, std::less<Mantid::API::AlgorithmHistory>, std::allocator<Mantid::API::AlgorithmHistory> >::_M_insert_unique(Mantid::API::AlgorithmHistory const&) + 203 (stl_tree.h:982)
3   libMantidAPI.dylib            	0x000000010b42b43b std::_Rb_tree<Mantid::API::AlgorithmHistory, Mantid::API::AlgorithmHistory, std::_Identity<Mantid::API::AlgorithmHistory>, std::less<Mantid::API::AlgorithmHistory>, std::allocator<Mantid::API::AlgorithmHistory> >::_M_insert_unique(std::_Rb_tree_iterator<Mantid::API::AlgorithmHistory>, Mantid::API::AlgorithmHistory const&) + 365 (stl_tree.h:1010)
4   libMantidAPI.dylib            	0x000000010b42b954 void std::_Rb_tree<Mantid::API::AlgorithmHistory, Mantid::API::AlgorithmHistory, std::_Identity<Mantid::API::AlgorithmHistory>, std::less<Mantid::API::AlgorithmHistory>, std::allocator<Mantid::API::AlgorithmHistory> >::_M_insert_unique<std::_Rb_tree_const_iterator<Mantid::API::AlgorithmHistory> >(std::_Rb_tree_const_iterator<Mantid::API::AlgorithmHistory>, std::_Rb_tree_const_iterator<Mantid::API::AlgorithmHistory>) + 110 (stl_tree.h:1237)
5   libMantidAPI.dylib            	0x000000010b42bc0e void std::set<Mantid::API::AlgorithmHistory, std::less<Mantid::API::AlgorithmHistory>, std::allocator<Mantid::API::AlgorithmHistory> >::insert<std::_Rb_tree_const_iterator<Mantid::API::AlgorithmHistory> >(std::_Rb_tree_const_iterator<Mantid::API::AlgorithmHistory>, std::_Rb_tree_const_iterator<Mantid::API::AlgorithmHistory>) + 46 (stl_set.h:345)
6   libMantidAPI.dylib            	0x000000010b426c31 Mantid::API::WorkspaceHistory::addHistory(Mantid::API::WorkspaceHistory const&) + 117 (WorkspaceHistory.cpp:62)
7   libMantidAPI.dylib            	0x000000010b271edb Mantid::API::Algorithm::fillHistory(Mantid::Kernel::DateAndTime, double, unsigned long) + 1217 (Algorithm.cpp:892)
8   libMantidAPI.dylib            	0x000000010b269e33 Mantid::API::Algorithm::execute() + 6171 (Algorithm.cpp:551)
9   _api.so                       	0x000000010e44ae5f (anonymous namespace)::executeWhileReleasingGIL(Mantid::API::IAlgorithm&) + 59 (IAlgorithm.cpp:206)
10  _api.so                       	0x000000010e45e292 _object* boost::python::detail::invoke<boost::python::to_python_value<bool const&>, bool (*)(Mantid::API::IAlgorithm&), boost::python::arg_from_python<Mantid::API::IAlgorithm&> >(boost::python::detail::invoke_tag_<false, false>, boost::python::to_python_value<bool const&> const&, bool (*&)(Mantid::API::IAlgorithm&), boost::python::arg_from_python<Mantid::API::IAlgorithm&>&) + 52 (invoke.hpp:75)

comment:2 Changed 8 years ago by Martyn Gigg

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

This will need to be fixed or else the result workspace is essentially useless.

comment:3 Changed 8 years ago by Martyn Gigg

Ensure Python binary ops return the correct ptr type. Refs #6015

Changeset: 90a7818bd34e144c320cc5cec2e55f08d96c57f4

comment:4 Changed 8 years ago by Martyn Gigg

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

comment:5 Changed 8 years ago by Vickie Lynch

  • Status changed from verify to verifying
  • Tester set to Vickie Lynch

comment:6 Changed 8 years ago by Vickie Lynch

  • Status changed from verifying to verify
  • Tester Vickie Lynch deleted

comment:7 Changed 8 years ago by Nick Draper

  • Status changed from verify to verifying
  • Tester set to Nick Draper

comment:8 Changed 8 years ago by Nick Draper

  • Status changed from verifying to closed

tested with the following script

ws2d = Load('LOQ48127')
column = Integration(ws2d)
column = ws2d / column
print column
column
print type(column)
<class 'mantid.api._api.MatrixWorkspace'>
ws2d = Load('LOQ48127')
singlespec = SumSpectra(ws2d)
singlespec += ws2d
print type(singlespec)
<class 'mantid.api._api.MatrixWorkspace'>
print type(ws2d)
<class 'mantid.api._api.MatrixWorkspace'>
ws2d = Load('LOQ48127')
column = Integration(ws2d)
column = ws2d / column
print column
column
print type(column)
<class 'mantid.api._api.MatrixWorkspace'>
ws2d = Load('LOQ48127')
singlespec = SumSpectra(ws2d)
singlespec += ws2d
print type(singlespec)
<class 'mantid.api._api.MatrixWorkspace'>
print type(ws2d)
<class 'mantid.api._api.MatrixWorkspace'>

comment:9 Changed 8 years ago by Martyn Gigg

Ensure Python binary ops return the correct ptr type. Refs #6015

Changeset: 90a7818bd34e144c320cc5cec2e55f08d96c57f4

comment:10 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 6861

Note: See TracTickets for help on using tickets.