Ticket #5565 (closed: wontfix)

Opened 8 years ago

Last modified 5 years ago

Bug with ConvertUnits Inplace

Reported by: Owen Arnold Owned by: Martyn Gigg
Priority: major Milestone: Release 2.2
Component: Mantid Keywords:
Cc: Blocked By:
Blocking: Tester: Stuart Campbell

Description (last modified by Martyn Gigg) (diff)

This is an issue raised by Tim Charlton. I've confirmed that this is an issue with the most recent builds.

This is Tim's original script:

RunNo=6224
w=Load(Filename='D:/data/cycle_12_1/POLREF0000%d.raw'%RunNo,OutputWorkspace='w%d'%RunNo,SpectrumMax='4')
ConvertUnits(InputWorkspace=w,OutputWorkspace=w,Target="Wavelength",AlignBins="1")
print w

Mon 2. Jul 12:03:53 2012: Script execution started.


RuntimeError: Variable invalidated, data has been deleted. at line 5 in

Change History

comment:1 Changed 8 years ago by Martyn Gigg

  • Description modified (diff)

comment:2 Changed 8 years ago by Martyn Gigg

  • Status changed from new to verify
  • Resolution set to wontfix

After thinking about it I've realised what is actually happening and it's not a bug but more a feature of the underlying memory management & python's variable passing behaviour.

What's happening is:

  • ConvertUnits asks for the input workspace named 'w' to be converted to the output workspace with the same name 'w';
  • The python variable is a weak pointer to the shared_ptr in the ADS so that it doesn't hold on to memory when the workspace is deleted.
  • The ConvertUnits call, while it looks like it is in place, is actually creating a new workspace, because of the AlignBins call, that is then stored in the ADS with the same name 'w'.
  • The python reference is then invalidated because the original shared_ptr no longer exists.

The w value for the OutputWorkspace argument is immutable as far as Python is concerned so there is no way of changing it inside the ConvertUnits call.

I think we'll have to mark this:

ConvertUnits(InputWorkspace=w,OutputWorkspace=w,Target="Wavelength",AlignBins="1")

as not possible under the new API but this will work and should be encouraged,

w = ConvertUnits(InputWorkspace=w,Target="Wavelength",AlignBins="1")

or this would work too

w = ConvertUnits(InputWorkspace=w,OutputWorkspace=w,Target="Wavelength",AlignBins="1")

comment:3 Changed 8 years ago by Stuart Campbell

  • Status changed from verify to verifying
  • Tester set to Stuart Campbell

comment:4 Changed 8 years ago by Stuart Campbell

  • Status changed from verifying to closed

Sounds good to me.

comment:5 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 6411

Note: See TracTickets for help on using tickets.