|
2 | 2 | import shutil, os
|
3 | 3 | import time
|
4 | 4 | import attr
|
| 5 | +from pathlib import Path |
5 | 6 |
|
6 | 7 | from .utils import (
|
7 | 8 | add2,
|
8 | 9 | add2_wait,
|
9 | 10 | multiply,
|
10 | 11 | power,
|
| 12 | + ten, |
11 | 13 | identity,
|
12 | 14 | list_output,
|
13 | 15 | fun_addvar3,
|
@@ -1986,6 +1988,63 @@ def test_wf_nostate_cachelocations_forcererun(plugin, tmpdir):
|
1986 | 1988 | assert wf2.output_dir.exists()
|
1987 | 1989 |
|
1988 | 1990 |
|
| 1991 | +@pytest.mark.parametrize("plugin", Plugins) |
| 1992 | +def test_wf_nostate_nodecachelocations(plugin, tmpdir): |
| 1993 | + """ |
| 1994 | + Two wfs with different input, but the second node has the same input; |
| 1995 | + the second wf has cache_locations and should recompute the wf, |
| 1996 | + but without recomputing the second node |
| 1997 | + """ |
| 1998 | + cache_dir1 = tmpdir.mkdir("test_wf_cache3") |
| 1999 | + cache_dir2 = tmpdir.mkdir("test_wf_cache4") |
| 2000 | + |
| 2001 | + wf1 = Workflow(name="wf", input_spec=["x"], cache_dir=cache_dir1) |
| 2002 | + wf1.add(ten(name="ten", x=wf1.lzin.x)) |
| 2003 | + wf1.add(add2_wait(name="add2", x=wf1.ten.lzout.out)) |
| 2004 | + wf1.set_output([("out", wf1.add2.lzout.out)]) |
| 2005 | + wf1.inputs.x = 3 |
| 2006 | + wf1.plugin = plugin |
| 2007 | + |
| 2008 | + t0 = time.time() |
| 2009 | + with Submitter(plugin=plugin) as sub: |
| 2010 | + sub(wf1) |
| 2011 | + t1 = time.time() - t0 |
| 2012 | + |
| 2013 | + results1 = wf1.result() |
| 2014 | + assert 12 == results1.output.out |
| 2015 | + |
| 2016 | + wf2 = Workflow( |
| 2017 | + name="wf", |
| 2018 | + input_spec=["x", "y"], |
| 2019 | + cache_dir=cache_dir2, |
| 2020 | + cache_locations=cache_dir1, |
| 2021 | + ) |
| 2022 | + wf2.add(ten(name="ten", x=wf2.lzin.x)) |
| 2023 | + wf2.add(add2_wait(name="add2", x=wf2.ten.lzout.out)) |
| 2024 | + wf2.set_output([("out", wf2.add2.lzout.out)]) |
| 2025 | + wf2.inputs.x = 2 |
| 2026 | + wf2.plugin = plugin |
| 2027 | + |
| 2028 | + t0 = time.time() |
| 2029 | + with Submitter(plugin=plugin) as sub: |
| 2030 | + sub(wf2) |
| 2031 | + t2 = time.time() - t0 |
| 2032 | + |
| 2033 | + results2 = wf2.result() |
| 2034 | + assert 12 == results2.output.out |
| 2035 | + |
| 2036 | + # checking execution time |
| 2037 | + assert t1 > 3 |
| 2038 | + assert t2 < 0.5 |
| 2039 | + |
| 2040 | + # checking if the second wf runs again, but runs only one task |
| 2041 | + assert wf1.output_dir.exists() |
| 2042 | + assert wf2.output_dir.exists() |
| 2043 | + |
| 2044 | + assert len(list(Path(cache_dir1).glob("F*"))) == 2 |
| 2045 | + assert len(list(Path(cache_dir2).glob("F*"))) == 1 |
| 2046 | + |
| 2047 | + |
1989 | 2048 | @pytest.mark.parametrize("plugin", Plugins)
|
1990 | 2049 | def test_wf_state_cachelocations(plugin, tmpdir):
|
1991 | 2050 | """
|
|
0 commit comments