def test_dead_lock_pipesystem(self): in_1 = Inlet(convert=False, name="in_1") sca = Scaler(scalar=1 / 255)(in_1) rot = Rotator([90, -90], remove_padding=False, keep_original=True)(sca) out_1 = Outlet(name="out_1")(rot) in_2 = Inlet(convert=True, name="in_2") cat = Categorizer(sparse=True)(in_2) dup = Duplicator()(cat) con = Concatenator()(dup) out_2 = Outlet(name="out_2")(con) dup.add_requirement( Requirement(rot, attribute="n_rotations", argument="n_result")) rot.add_requirement( Requirement(con, attribute="ignore_index", argument="remove_padding")) with pytest.raises(AttributeError): ps = PipeSystem(inlets=[in_1, in_2], outlets=[out_1, out_2], name="ps", verbose=True)
def basic_pipesystem(): in_1 = Inlet(convert=False, name="in_1") out_1 = Outlet(name="out_1")(in_1) in_2 = Inlet(convert=True, name="in_2") out_2 = Outlet(name="out_2")(in_2) return PipeSystem(inlets=[in_1, in_2], outlets=[out_1, out_2], name="ps")
def tests_to_from_config_req(self, complex_pipe_system_req, images, labels): before = complex_pipe_system_req.flow(images, labels) after = PipeSystem.from_config( complex_pipe_system_req.to_config()).flow(images, labels) assert (before[0] == after[0]).all() and (before[1] == after[1]).all().all()
def test_give_wrong_pipe_element(self): in_1 = Inlet(convert=False, name="in_1") out_1 = Outlet(name="out_1")(in_1) in_2 = Inlet(convert=True, name="in_2") out_2 = PipeElement(name="out_2")(in_2) with pytest.raises(TypeError): ps = PipeSystem(inlets=[in_1, in_2], outlets=[out_1, out_2], name="ps")
def complex_pipesystem(): in_1 = Inlet(convert=False, name="in_1") sca = Scaler(scalar=1 / 255)(in_1) rot = Rotator([90, -90], remove_padding=False, keep_original=True)(sca) out_1 = Outlet(name="out_1")(rot) in_2 = Inlet(convert=True, name="in_2") cat = Categorizer(sparse=True)(in_2) dup = Duplicator()(cat) con = Concatenator()(dup, dup, dup) out_2 = Outlet(name="out_2")(con) return PipeSystem(inlets=[in_1, in_2], outlets=[out_1, out_2], name="ps")
def make_simple_pipesystem(): in_1 = Inlet(convert=False, name="in_1") # sca = Scaler(scalar=1 / 255)(in_1) out_1 = Outlet(name="out_1")(in_1) in_2 = Inlet(convert=True, name="in_2") # cat = Categorizer(sparse=True)(in_2) out_2 = Outlet(name="out_2")(in_2) return PipeSystem(inlets=[in_1, in_2], outlets=[out_1, out_2], name="ps", verbose=True)
def test_correct_outlets(self, complex_pipesystem): in_1 = Inlet(convert=False, name="in_1") sca = Scaler(scalar=1 / 255)(in_1) rot = Rotator([90, -90], remove_padding=False, keep_original=True)(sca) out_1 = Outlet(name="out_1")(rot) in_2 = Inlet(convert=True, name="in_2") cat = Categorizer(sparse=True)(in_2) dup = Duplicator()(cat) con = Concatenator()(dup, dup, dup) out_2 = Outlet(name="out_2")(con) ps = PipeSystem(inlets=[in_1, in_2], outlets=[out_1, out_2], name="ps") assert ps.outlets[0] == out_1 and ps.outlets[1] == out_2
def test_mismatch_inlet_outlet(self, complex_pipesystem): in_1 = Inlet(convert=False, name="in_1") out_1 = Outlet(name="out_1")(in_1) in_2 = Inlet(convert=True, name="in_2") out_2 = Outlet(name="out_2")(in_2) in_3 = Inlet(name="in_3") out_3 = Outlet(name="out_3")(in_3) ps = PipeSystem(inlets=[in_1, in_2, in_3], outlets=[out_1, out_2, out_3], name="ps") with pytest.raises(AttributeError): new_ps = ps * complex_pipesystem
def pipe_system_and_elements(): in_1 = Inlet(convert=False, name="in_1") sca = Scaler(scalar=1 / 255)(in_1) rot = Rotator([90, -90], remove_padding=False, keep_original=True)(sca) out_1 = Outlet(name="out_1")(rot) in_2 = Inlet(convert=True, name="in_2") cat = Categorizer(sparse=True)(in_2) dup = Duplicator()(cat) con = Concatenator()(dup, dup, dup) out_2 = Outlet(name="out_2")(con) all_elements = [in_1, sca, rot, out_1, in_2, cat, dup, con, out_2] return ( PipeSystem(inlets=[in_1, in_2], outlets=[out_1, out_2], name="ps"), all_elements, )
def complex_pipe_system_req(): in_1 = Inlet(convert=False, name="in_1") sca = Scaler(scalar=1 / 255)(in_1) rot = Rotator([90, -90], remove_padding=False, keep_original=True)(sca) out_1 = Outlet(name="out_1")(rot) in_2 = Inlet(convert=True, name="in_2") cat = Categorizer(sparse=True)(in_2) dup = Duplicator()(cat) con = Concatenator()(dup) out_2 = Outlet(name="out_2")(con) dup.add_requirement( Requirement(rot, attribute="n_rotations", argument="n_result")) return PipeSystem(inlets=[in_1, in_2], outlets=[out_1, out_2], name="ps", verbose=True)
def test_order(self): in_1 = Inlet(convert=False, name="in_1") sca = Scaler(scalar=1 / 255)(in_1) rot = Rotator([90, -90], remove_padding=False, keep_original=True)(sca) out_1 = Outlet(name="out_1")(rot) in_2 = Inlet(convert=True, name="in_2") cat = Categorizer(sparse=True)(in_2) dup = Duplicator()(cat) con = Concatenator()(dup) out_2 = Outlet(name="out_2")(con) dup.add_requirement( Requirement(rot, attribute="n_rotations", argument="n_result")) ps = PipeSystem(inlets=[in_1, in_2], outlets=[out_1, out_2], name="ps", verbose=True) assert ps.execution_sequence.index(dup) > ps.execution_sequence.index( rot)
def complex_pipesystem_json(): return PipeSystem.from_json(json_file_name=PS_COMPLEX_PATH)
def basic_pipesystem_json(): return PipeSystem.from_json(json_file_name=PS_SIMPLE_PATH)
def dupe_pipe_invalid(): in_1 = Inlet(convert=True, name="in_2") x = Duplicator(n_result=3)(in_1) x = Concatenator(axis=1)(x, x) out_1 = Outlet(name="out_2")(x) return PipeSystem(inlets=[in_1], outlets=[out_1])