@@ -1988,6 +1988,126 @@ def test_wf_nostate_cachelocations_forcererun(plugin, tmpdir):
1988
1988
assert wf2 .output_dir .exists ()
1989
1989
1990
1990
1991
+ @pytest .mark .parametrize ("plugin" , Plugins )
1992
+ def test_wf_nostate_cachelocations_wftaskrerun (plugin , tmpdir ):
1993
+ """
1994
+ Two identical wfs with provided cache_dir;
1995
+ the second wf has cache_locations and rerun=True,
1996
+ so the workflow is rerun, but it doesn't propagate to nodes,
1997
+ so none of the node has to be recalculated
1998
+ """
1999
+ cache_dir1 = tmpdir .mkdir ("test_wf_cache3" )
2000
+ cache_dir2 = tmpdir .mkdir ("test_wf_cache4" )
2001
+
2002
+ wf1 = Workflow (name = "wf" , input_spec = ["x" , "y" ], cache_dir = cache_dir1 )
2003
+ wf1 .add (multiply (name = "mult" , x = wf1 .lzin .x , y = wf1 .lzin .y ))
2004
+ wf1 .add (add2_wait (name = "add2" , x = wf1 .mult .lzout .out ))
2005
+ wf1 .set_output ([("out" , wf1 .add2 .lzout .out )])
2006
+ wf1 .inputs .x = 2
2007
+ wf1 .inputs .y = 3
2008
+ wf1 .plugin = plugin
2009
+
2010
+ t0 = time .time ()
2011
+ with Submitter (plugin = plugin ) as sub :
2012
+ sub (wf1 )
2013
+ t1 = time .time () - t0
2014
+
2015
+ results1 = wf1 .result ()
2016
+ assert 8 == results1 .output .out
2017
+
2018
+ wf2 = Workflow (
2019
+ name = "wf" ,
2020
+ input_spec = ["x" , "y" ],
2021
+ cache_dir = cache_dir2 ,
2022
+ cache_locations = cache_dir1 ,
2023
+ rerun = True ,
2024
+ )
2025
+ wf2 .add (multiply (name = "mult" , x = wf2 .lzin .x , y = wf2 .lzin .y ))
2026
+ wf2 .add (add2_wait (name = "add2" , x = wf2 .mult .lzout .out ))
2027
+ wf2 .set_output ([("out" , wf2 .add2 .lzout .out )])
2028
+ wf2 .inputs .x = 2
2029
+ wf2 .inputs .y = 3
2030
+ wf2 .plugin = plugin
2031
+
2032
+ t0 = time .time ()
2033
+ with Submitter (plugin = plugin ) as sub :
2034
+ sub (wf2 )
2035
+ t2 = time .time () - t0
2036
+
2037
+ results2 = wf2 .result ()
2038
+ assert 8 == results2 .output .out
2039
+
2040
+ # checking if the second wf runs again
2041
+ assert wf1 .output_dir .exists ()
2042
+ assert wf2 .output_dir .exists ()
2043
+
2044
+ # even if the second wf is recomputed the nodes are not, so it's fast
2045
+ assert len (list (Path (cache_dir1 ).glob ("F*" ))) == 2
2046
+ assert len (list (Path (cache_dir2 ).glob ("F*" ))) == 0
2047
+ assert t1 > 3
2048
+ assert t2 < 1
2049
+
2050
+
2051
+ @pytest .mark .parametrize ("plugin" , Plugins )
2052
+ def test_wf_nostate_cachelocations_taskrerun (plugin , tmpdir ):
2053
+ """
2054
+ Two identical wfs with provided cache_dir;
2055
+ the second wf has cache_locations and rerun=True
2056
+ and one of the task also has rerun=True;
2057
+ so the workflow is rerun, and one of the node also has to be rerun,
2058
+ """
2059
+ cache_dir1 = tmpdir .mkdir ("test_wf_cache3" )
2060
+ cache_dir2 = tmpdir .mkdir ("test_wf_cache4" )
2061
+
2062
+ wf1 = Workflow (name = "wf" , input_spec = ["x" , "y" ], cache_dir = cache_dir1 )
2063
+ wf1 .add (multiply (name = "mult" , x = wf1 .lzin .x , y = wf1 .lzin .y ))
2064
+ wf1 .add (add2_wait (name = "add2" , x = wf1 .mult .lzout .out ))
2065
+ wf1 .set_output ([("out" , wf1 .add2 .lzout .out )])
2066
+ wf1 .inputs .x = 2
2067
+ wf1 .inputs .y = 3
2068
+ wf1 .plugin = plugin
2069
+
2070
+ t0 = time .time ()
2071
+ with Submitter (plugin = plugin ) as sub :
2072
+ sub (wf1 )
2073
+ t1 = time .time () - t0
2074
+
2075
+ results1 = wf1 .result ()
2076
+ assert 8 == results1 .output .out
2077
+
2078
+ wf2 = Workflow (
2079
+ name = "wf" ,
2080
+ input_spec = ["x" , "y" ],
2081
+ cache_dir = cache_dir2 ,
2082
+ cache_locations = cache_dir1 ,
2083
+ rerun = True ,
2084
+ )
2085
+ wf2 .add (multiply (name = "mult" , x = wf2 .lzin .x , y = wf2 .lzin .y ))
2086
+ wf2 .add (add2_wait (name = "add2" , x = wf2 .mult .lzout .out , rerun = True ))
2087
+ wf2 .set_output ([("out" , wf2 .add2 .lzout .out )])
2088
+ wf2 .inputs .x = 2
2089
+ wf2 .inputs .y = 3
2090
+ wf2 .plugin = plugin
2091
+
2092
+ t0 = time .time ()
2093
+ with Submitter (plugin = plugin ) as sub :
2094
+ sub (wf2 )
2095
+ t2 = time .time () - t0
2096
+
2097
+ results2 = wf2 .result ()
2098
+ assert 8 == results2 .output .out
2099
+
2100
+ # checking if the second wf runs again
2101
+ assert wf1 .output_dir .exists ()
2102
+ assert wf2 .output_dir .exists ()
2103
+
2104
+ # the second task also has to be recomputed this time
2105
+ assert len (list (Path (cache_dir1 ).glob ("F*" ))) == 2
2106
+ assert len (list (Path (cache_dir2 ).glob ("F*" ))) == 1
2107
+ assert t1 > 3
2108
+ assert t2 > 3
2109
+
2110
+
1991
2111
@pytest .mark .parametrize ("plugin" , Plugins )
1992
2112
def test_wf_nostate_nodecachelocations (plugin , tmpdir ):
1993
2113
"""
@@ -2408,7 +2528,7 @@ def test_wf_nostate_cachelocations_recompute(plugin, tmpdir):
2408
2528
2409
2529
# checking execution time (second task shouldn't be recompute, t2 should be small)
2410
2530
assert t1 > 3
2411
- assert t2 < 0.5
2531
+ assert t2 < 1
2412
2532
2413
2533
2414
2534
@pytest .mark .parametrize ("plugin" , Plugins )
0 commit comments