def test_that_can_find_can_reduction_with_wav_range(self): test_director = TestDirector() state = test_director.construct() tagged_workspace_names = {None: "test_ws", OutputParts.COUNT: "test_ws_count", OutputParts.NORM: "test_ws_norm"} SANSFunctionsTest._prepare_workspaces(number_of_workspaces=4, tagged_workspace_names=tagged_workspace_names, state=state, reduction_mode=ReductionMode.LAB, wav_range="1-2") workspace, workspace_count, workspace_norm = get_reduced_can_workspace_from_ads( state, output_parts=True, wav_range="1-2", reduction_mode=ReductionMode.LAB) self.assertIsNotNone(workspace) self.assertIsNotNone(workspace_count) self.assertIsNotNone(workspace_norm) self.assertEqual(workspace.name(), AnalysisDataService.retrieve("test_ws").name()) self.assertEqual(workspace_count.name(), AnalysisDataService.retrieve("test_ws_count").name()) self.assertEqual(workspace_norm.name(), AnalysisDataService.retrieve("test_ws_norm").name()) # Both should not find anything workspace, workspace_count, workspace_norm = get_reduced_can_workspace_from_ads( state, output_parts=True, wav_range=None, reduction_mode=ReductionMode.LAB) self.assertIsNone(workspace) workspace, workspace_count, workspace_norm = get_reduced_can_workspace_from_ads( state, output_parts=True, wav_range="2-3", reduction_mode=ReductionMode.LAB) self.assertIsNone(workspace) # Clean up SANSFunctionsTest._remove_workspaces()
def test_that_can_find_can_reduction_if_it_exists(self): # Arrange test_director = TestDirector() state = test_director.construct() tagged_workspace_names = { None: "test_ws", OutputParts.Count: "test_ws_count", OutputParts.Norm: "test_ws_norm" } SANSFunctionsTest._prepare_workspaces( number_of_workspaces=4, tagged_workspace_names=tagged_workspace_names, state=state, reduction_mode=ISISReductionMode.LAB) # Act workspace, workspace_count, workspace_norm = get_reduced_can_workspace_from_ads( state, output_parts=True, reduction_mode=ISISReductionMode.LAB) # noqa # Assert self.assertTrue(workspace is not None) self.assertTrue( workspace.name() == AnalysisDataService.retrieve("test_ws").name()) self.assertTrue(workspace_count is not None) self.assertTrue(workspace_count.name() == AnalysisDataService.retrieve( "test_ws_count").name()) self.assertTrue(workspace_norm is not None) self.assertTrue(workspace_norm.name() == AnalysisDataService.retrieve( "test_ws_norm").name()) # Clean up SANSFunctionsTest._remove_workspaces()
def test_that_can_find_can_reduction_if_it_exists(self): # Arrange test_director = TestDirector() state = test_director.construct() tagged_workspace_names = {None: "test_ws", OutputParts.Count: "test_ws_count", OutputParts.Norm: "test_ws_norm"} SANSFunctionsTest._prepare_workspaces(number_of_workspaces=4, tagged_workspace_names=tagged_workspace_names, state=state, reduction_mode=ISISReductionMode.LAB) # Act workspace, workspace_count, workspace_norm = get_reduced_can_workspace_from_ads(state, output_parts=True, reduction_mode=ISISReductionMode.LAB) # noqa # Assert self.assertTrue(workspace is not None) self.assertTrue(workspace.name() == AnalysisDataService.retrieve("test_ws").name()) self.assertTrue(workspace_count is not None) self.assertTrue(workspace_count.name() == AnalysisDataService.retrieve("test_ws_count").name()) self.assertTrue(workspace_norm is not None) self.assertTrue(workspace_norm.name() == AnalysisDataService.retrieve("test_ws_norm").name()) # Clean up SANSFunctionsTest._remove_workspaces()
def test_that_returns_none_if_it_does_not_exist(self): # Arrange test_director = TestDirector() state = test_director.construct() SANSFunctionsTest._prepare_workspaces(number_of_workspaces=4, tagged_workspace_names=None, state=state, reduction_mode=ISISReductionMode.LAB) # Act workspace, workspace_count, workspace_norm = \ get_reduced_can_workspace_from_ads(state, output_parts=False, reduction_mode=ISISReductionMode.LAB) # Assert self.assertTrue(workspace is None) self.assertTrue(workspace_count is None) self.assertTrue(workspace_norm is None) # Clean up SANSFunctionsTest._remove_workspaces()
def test_that_returns_none_if_it_does_not_exist(self): # Arrange test_director = TestDirector() state = test_director.construct() SANSFunctionsTest._prepare_workspaces(number_of_workspaces=4, tagged_workspace_names=None, state=state, reduction_mode=ISISReductionMode.LAB) # Act workspace, workspace_count, workspace_norm = \ get_reduced_can_workspace_from_ads(state, output_parts=False, reduction_mode=ISISReductionMode.LAB) # Assert self.assertTrue(workspace is None) self.assertTrue(workspace_count is None) self.assertTrue(workspace_norm is None) # Clean up SANSFunctionsTest._remove_workspaces()
def _get_existing_cans(reduction_setting_bundle, state): output_parts = reduction_setting_bundle.output_parts reduction_mode = reduction_setting_bundle.reduction_mode data_type = reduction_setting_bundle.data_type existing_slices = [] for wav_slice in state.wavelength.wavelength_interval.selected_ranges: wav_string = wav_range_to_str(wav_slice) reduced_can_workspace, reduced_can_workspace_count, reduced_can_workspace_norm = \ get_reduced_can_workspace_from_ads(state, output_parts, reduction_mode, wav_string) output_calculated_transmission_workspace, output_unfitted_transmission_workspace = \ get_transmission_workspaces_from_ads(state, reduction_mode, wav_string) # Set the results on the output bundle existing_slices.append( ReducedSlice( wav_range=wav_string, output_bundle=OutputBundle( state=state, data_type=data_type, reduction_mode=reduction_mode, output_workspace=reduced_can_workspace), parts_bundle=OutputPartsBundle( state=state, data_type=data_type, reduction_mode=reduction_mode, output_workspace_count=reduced_can_workspace_count, output_workspace_norm=reduced_can_workspace_norm), transmission_bundle=OutputTransmissionBundle( state=reduction_setting_bundle.state, data_type=data_type, calculated_transmission_workspace= output_calculated_transmission_workspace, unfitted_transmission_workspace= output_unfitted_transmission_workspace))) return existing_slices
def run_optimized_for_can(reduction_alg, reduction_setting_bundle): """ Check if the state can reduction already exists, and if so, use it else reduce it and add it to the ADS. @param reduction_alg: a handle to the SANSReductionCore algorithm @param reduction_setting_bundle: a ReductionSettingBundle tuple. @return: a reduced workspace, a partial output workspace for the counts, a partial workspace for the normalization. """ state = reduction_setting_bundle.state output_parts = reduction_setting_bundle.output_parts reduction_mode = reduction_setting_bundle.reduction_mode data_type = reduction_setting_bundle.data_type reduced_can_workspace, reduced_can_workspace_count, reduced_can_workspace_norm = \ get_reduced_can_workspace_from_ads(state, output_parts, reduction_mode) output_calculated_transmission_workspace, output_unfitted_transmission_workspace = \ get_transmission_workspaces_from_ads(state, reduction_mode) # Set the results on the output bundle output_bundle = OutputBundle(state=state, data_type=data_type, reduction_mode=reduction_mode, output_workspace=reduced_can_workspace) output_parts_bundle = OutputPartsBundle(state=state, data_type=data_type, reduction_mode=reduction_mode, output_workspace_count=reduced_can_workspace_count, output_workspace_norm=reduced_can_workspace_norm) output_transmission_bundle = OutputTransmissionBundle(state=reduction_setting_bundle.state, data_type=data_type, calculated_transmission_workspace=output_calculated_transmission_workspace, unfitted_transmission_workspace=output_unfitted_transmission_workspace ) # The logic table for the recalculation of the partial outputs is: # | output_parts | reduced_can_workspace_count is None | reduced_can_workspace_norm is None | Recalculate | # ---------------------------------------------------------------------------------------------------------- # | False | True | True | False | # | False | True | False | False | # | False | False | True | False | # | False | False | False | False | # | True | True | True | False | # | True | True | False | True | # | True | False | True | True | # | True | False | False | False | is_invalid_partial_workspaces = ((output_parts_bundle.output_workspace_count is None and output_parts_bundle.output_workspace_norm is not None) or (output_parts_bundle.output_workspace_count is not None and output_parts_bundle.output_workspace_norm is None)) is_invalid_transmission_workspaces = (output_transmission_bundle.calculated_transmission_workspace is None or output_transmission_bundle.unfitted_transmission_workspace is None) \ and state.adjustment.show_transmission partial_output_require_reload = output_parts and is_invalid_partial_workspaces must_reload = output_bundle.output_workspace is None or partial_output_require_reload or is_invalid_transmission_workspaces if 'boost.mpi' in sys.modules: # In MPI runs the result is only present on rank 0 (result of Q1D2 integration), # so the reload flag must be broadcasted from rank 0. must_reload = mpisetup.boost.mpi.broadcast(mpisetup.boost.mpi.world, must_reload, 0) if must_reload: # if output_bundle.output_workspace is None or partial_output_require_reload: output_bundle, output_parts_bundle, output_transmission_bundle = run_core_reduction(reduction_alg, reduction_setting_bundle) # Now we need to tag the workspaces and add it to the ADS if output_bundle.output_workspace is not None: write_hash_into_reduced_can_workspace(state=output_bundle.state, workspace=output_bundle.output_workspace, partial_type=None, reduction_mode=reduction_mode) if output_transmission_bundle.calculated_transmission_workspace is not None and \ output_transmission_bundle.unfitted_transmission_workspace is not None: write_hash_into_reduced_can_workspace(state=output_transmission_bundle.state, workspace=output_transmission_bundle.calculated_transmission_workspace, partial_type=TransmissionType.Calculated, reduction_mode=reduction_mode) write_hash_into_reduced_can_workspace(state=output_transmission_bundle.state, workspace=output_transmission_bundle.unfitted_transmission_workspace, partial_type=TransmissionType.Unfitted, reduction_mode=reduction_mode) if (output_parts_bundle.output_workspace_count is not None and output_parts_bundle.output_workspace_norm is not None): write_hash_into_reduced_can_workspace(state=output_parts_bundle.state, workspace=output_parts_bundle.output_workspace_count, partial_type=OutputParts.Count, reduction_mode=reduction_mode) write_hash_into_reduced_can_workspace(state=output_parts_bundle.state, workspace=output_parts_bundle.output_workspace_norm, partial_type=OutputParts.Norm, reduction_mode=reduction_mode) return output_bundle, output_parts_bundle, output_transmission_bundle
def run_optimized_for_can(reduction_alg, reduction_setting_bundle, event_slice_optimisation=False): """ Check if the state can reduction already exists, and if so, use it else reduce it and add it to the ADS. :param reduction_alg: a handle to the SANSReductionCore algorithm :param reduction_setting_bundle: a ReductionSettingBundle tuple. :param event_slice_optimisation: An optional bool. If true then run run_core_event_slice_reduction, else run_core_reduction. :return: a reduced workspace, a partial output workspace for the counts, a partial workspace for the normalization. """ state = reduction_setting_bundle.state output_parts = reduction_setting_bundle.output_parts reduction_mode = reduction_setting_bundle.reduction_mode data_type = reduction_setting_bundle.data_type reduced_can_workspace, reduced_can_workspace_count, reduced_can_workspace_norm = \ get_reduced_can_workspace_from_ads(state, output_parts, reduction_mode) output_calculated_transmission_workspace, output_unfitted_transmission_workspace = \ get_transmission_workspaces_from_ads(state, reduction_mode) # Set the results on the output bundle output_bundle = OutputBundle(state=state, data_type=data_type, reduction_mode=reduction_mode, output_workspace=reduced_can_workspace) output_parts_bundle = OutputPartsBundle( state=state, data_type=data_type, reduction_mode=reduction_mode, output_workspace_count=reduced_can_workspace_count, output_workspace_norm=reduced_can_workspace_norm) output_transmission_bundle = OutputTransmissionBundle( state=reduction_setting_bundle.state, data_type=data_type, calculated_transmission_workspace= output_calculated_transmission_workspace, unfitted_transmission_workspace=output_unfitted_transmission_workspace) # The logic table for the recalculation of the partial outputs is: # | output_parts | reduced_can_workspace_count is None | reduced_can_workspace_norm is None | Recalculate | # ---------------------------------------------------------------------------------------------------------- # | False | True | True | False | # | False | True | False | False | # | False | False | True | False | # | False | False | False | False | # | True | True | True | False | # | True | True | False | True | # | True | False | True | True | # | True | False | False | False | is_invalid_partial_workspaces = ( (output_parts_bundle.output_workspace_count is None and output_parts_bundle.output_workspace_norm is not None) or (output_parts_bundle.output_workspace_count is not None and output_parts_bundle.output_workspace_norm is None)) is_invalid_transmission_workspaces = ( output_transmission_bundle.calculated_transmission_workspace is None or output_transmission_bundle.unfitted_transmission_workspace is None) partial_output_require_reload = output_parts and is_invalid_partial_workspaces must_reload = output_bundle.output_workspace is None or partial_output_require_reload or is_invalid_transmission_workspaces if 'boost.mpi' in sys.modules: # In MPI runs the result is only present on rank 0 (result of Q1D2 integration), # so the reload flag must be broadcasted from rank 0. must_reload = mpisetup.boost.mpi.broadcast(mpisetup.boost.mpi.world, must_reload, 0) if must_reload: # if output_bundle.output_workspace is None or partial_output_require_reload: if not event_slice_optimisation: output_bundle, output_parts_bundle, \ output_transmission_bundle = run_core_reduction(reduction_alg, reduction_setting_bundle) else: output_bundle, output_parts_bundle, \ output_transmission_bundle = run_core_event_slice_reduction(reduction_alg, reduction_setting_bundle) # Now we need to tag the workspaces and add it to the ADS if output_bundle.output_workspace is not None: write_hash_into_reduced_can_workspace( state=output_bundle.state, workspace=output_bundle.output_workspace, partial_type=None, reduction_mode=reduction_mode) if output_transmission_bundle.calculated_transmission_workspace is not None and \ output_transmission_bundle.unfitted_transmission_workspace is not None: write_hash_into_reduced_can_workspace( state=output_transmission_bundle.state, workspace=output_transmission_bundle. calculated_transmission_workspace, partial_type=TransmissionType.CALCULATED, reduction_mode=reduction_mode) write_hash_into_reduced_can_workspace( state=output_transmission_bundle.state, workspace=output_transmission_bundle. unfitted_transmission_workspace, partial_type=TransmissionType.UNFITTED, reduction_mode=reduction_mode) if (output_parts_bundle.output_workspace_count is not None and output_parts_bundle.output_workspace_norm is not None): write_hash_into_reduced_can_workspace( state=output_parts_bundle.state, workspace=output_parts_bundle.output_workspace_count, partial_type=OutputParts.COUNT, reduction_mode=reduction_mode) write_hash_into_reduced_can_workspace( state=output_parts_bundle.state, workspace=output_parts_bundle.output_workspace_norm, partial_type=OutputParts.NORM, reduction_mode=reduction_mode) return output_bundle, output_parts_bundle, output_transmission_bundle
def run_optimized_for_can(reduction_alg, reduction_setting_bundle): """ Check if the state can reduction already exists, and if so, use it else reduce it and add it to the ADS. @param reduction_alg: a handle to the SANSReductionCore algorithm @param reduction_setting_bundle: a ReductionSettingBundle tuple. @return: a reduced workspace, a partial output workspace for the counts, a partial workspace for the normalization. """ state = reduction_setting_bundle.state output_parts = reduction_setting_bundle.output_parts reduction_mode = reduction_setting_bundle.reduction_mode data_type = reduction_setting_bundle.data_type reduced_can_workspace, reduced_can_workspace_count, reduced_can_workspace_norm = \ get_reduced_can_workspace_from_ads(state, output_parts, reduction_mode) # Set the results on the output bundle output_bundle = OutputBundle(state=state, data_type=data_type, reduction_mode=reduction_mode, output_workspace=reduced_can_workspace) output_parts_bundle = OutputPartsBundle(state=state, data_type=data_type, reduction_mode=reduction_mode, output_workspace_count=reduced_can_workspace_count, output_workspace_norm=reduced_can_workspace_norm) # The logic table for the recalculation of the partial outputs is: # | output_parts | reduced_can_workspace_count is None | reduced_can_workspace_norm is None | Recalculate | # ---------------------------------------------------------------------------------------------------------- # | False | True | True | False | # | False | True | False | False | # | False | False | True | False | # | False | False | False | False | # | True | True | True | False | # | True | True | False | True | # | True | False | True | True | # | True | False | False | False | is_invalid_partial_workspaces = ((output_parts_bundle.output_workspace_count is None and output_parts_bundle.output_workspace_norm is not None) or (output_parts_bundle.output_workspace_count is not None and output_parts_bundle.output_workspace_norm is None)) partial_output_require_reload = output_parts and is_invalid_partial_workspaces if output_bundle.output_workspace is None or partial_output_require_reload: output_bundle, output_parts_bundle = run_core_reduction(reduction_alg, reduction_setting_bundle) # Now we need to tag the workspaces and add it to the ADS if output_bundle.output_workspace is not None: write_hash_into_reduced_can_workspace(state=output_bundle.state, workspace=output_bundle.output_workspace, partial_type=None, reduction_mode=reduction_mode) if (output_parts_bundle.output_workspace_count is not None and output_parts_bundle.output_workspace_norm is not None): write_hash_into_reduced_can_workspace(state=output_parts_bundle.state, workspace=output_parts_bundle.output_workspace_count, partial_type=OutputParts.Count, reduction_mode=reduction_mode) write_hash_into_reduced_can_workspace(state=output_parts_bundle.state, workspace=output_parts_bundle.output_workspace_norm, partial_type=OutputParts.Norm, reduction_mode=reduction_mode) return output_bundle, output_parts_bundle