def create_test_case_invalid_step_choosen(): a_callback = TapeCallbackFunction() b_callback = TapeCallbackFunction() return NeuraxleTestCase(pipeline=Pipeline([ ChooseOneOrManyStepsOf([ ('a', TransformCallbackStep(a_callback, transform_function=lambda di: di * 2)), ('b', TransformCallbackStep(b_callback, transform_function=lambda di: di * 2)) ]), ]), callbacks=[a_callback, b_callback], expected_callbacks_data=[DATA_INPUTS, DATA_INPUTS], hyperparams={ 'ChooseOneOrManyStepsOf__c__enabled': True, 'ChooseOneOrManyStepsOf__b__enabled': False }, hyperparams_space={ 'ChooseOneOrManyStepsOf__a__enabled': Boolean(), 'ChooseOneOrManyStepsOf__b__enabled': Boolean() }, expected_processed_outputs=np.array( [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]))
def create_pipeline(tmpdir, pickle_checkpoint_step, tape, hyperparameters=None, different=False, save_pipeline=True): if different: pipeline = ResumablePipeline(steps=[ ('a', DifferentCallbackStep(tape.callback, ["1"], hyperparams=hyperparameters)), ('pickle_checkpoint', pickle_checkpoint_step), ('c', TransformCallbackStep(tape.callback, ["2"])), ('d', TransformCallbackStep(tape.callback, ["3"])) ], cache_folder=tmpdir) else: pipeline = ResumablePipeline(steps=[ ('a', TransformCallbackStep(tape.callback, ["1"], hyperparams=hyperparameters)), ('pickle_checkpoint', pickle_checkpoint_step), ('c', TransformCallbackStep(tape.callback, ["2"])), ('d', TransformCallbackStep(tape.callback, ["3"])) ], cache_folder=tmpdir) return pipeline
def test_transform_should_transform_all_steps_for_each_data_inputs_expected_outputs(): tape = TapeCallbackFunction() p = Pipeline([ ForEachDataInput(Pipeline([ TransformCallbackStep(tape.callback, ["1"]), TransformCallbackStep(tape.callback, ["2"]), ])) ]) data_inputs = [[0, 1], [1, 2]] outputs = p.transform(data_inputs) assert tape.get_name_tape() == ["1", "2", "1", "2"]
def test_pipeline_nested_mutate_inverse_transform_without_identities(): """ This test was required for a strange bug at the border of the pipelines that happened when the identities were not used. """ expected_tape = [ "1", "2", "3", "4", "5", "6", "7", "7", "6", "5", "4", "3", "2", "1" ] tape = TapeCallbackFunction() p = Pipeline([ TransformCallbackStep(tape.callback, ["1"]), TransformCallbackStep(tape.callback, ["2"]), Pipeline([ TransformCallbackStep(tape.callback, ["3"]), TransformCallbackStep(tape.callback, ["4"]), TransformCallbackStep(tape.callback, ["5"]), ]), TransformCallbackStep(tape.callback, ["6"]), TransformCallbackStep(tape.callback, ["7"]), ]) p, _ = p.fit_transform(np.ones((1, 1))) # will add range(1, 8) to tape. print("[mutating, inversing, and calling each inverse_transform]") reversed(p).transform(np.ones( (1, 1) )) # will add reversed(range(1, 8)) to tape, calling inverse_transforms. print(expected_tape) print(tape.get_name_tape()) assert expected_tape == tape.get_name_tape()
def test_pipeline_nested_mutate_inverse_transform(): expected_tape = [ "1", "2", "3", "4", "5", "6", "7", "7", "6", "5", "4", "3", "2", "1" ] tape = TapeCallbackFunction() p = Pipeline([ Identity(), TransformCallbackStep(tape.callback, ["1"]), TransformCallbackStep(tape.callback, ["2"]), Pipeline([ Identity(), TransformCallbackStep(tape.callback, ["3"]), TransformCallbackStep(tape.callback, ["4"]), TransformCallbackStep(tape.callback, ["5"]), Identity() ]), TransformCallbackStep(tape.callback, ["6"]), TransformCallbackStep(tape.callback, ["7"]), Identity() ]) p, _ = p.fit_transform(np.ones((1, 1))) # will add range(1, 8) to tape. print("[mutating]") p = p.mutate(new_method="inverse_transform", method_to_assign_to="transform") p.transform(np.ones((1, 1))) # will add reversed(range(1, 8)) to tape. print(expected_tape) print(tape.get_name_tape()) assert expected_tape == tape.get_name_tape()
def test_pipeline_simple_mutate_inverse_transform(): expected_tape = ["1", "2", "3", "4", "4", "3", "2", "1"] tape = TapeCallbackFunction() p = Pipeline([ Identity(), TransformCallbackStep(tape.callback, ["1"]), TransformCallbackStep(tape.callback, ["2"]), TransformCallbackStep(tape.callback, ["3"]), TransformCallbackStep(tape.callback, ["4"]), Identity() ]) p, _ = p.fit_transform(np.ones((1, 1))) print("[mutating]") p = p.mutate(new_method="inverse_transform", method_to_assign_to="transform") p.transform(np.ones((1, 1))) assert expected_tape == tape.get_name_tape()
def transform(self, data_inputs): TransformCallbackStep.transform(self, data_inputs) return list(np.array(data_inputs) * 2)