test_integration_2adjtltest.py 2.21 KB
Newer Older
1
import pytest
2
3
import os
from pycif.utils.yml import ordered_dump
4
from pycif.utils.classes.setup import Setup
Antoine Berchet's avatar
Antoine Berchet committed
5
6


Antoine Berchet's avatar
Antoine Berchet committed
7
@pytest.mark.test_in_ci
8
@pytest.mark.dummy
9
10
11
12
@pytest.mark.adjtltest
@pytest.mark.parametrize(
    "settings",
    [{"incrmode": "cst", "testspace": "control"},
Antoine Berchet's avatar
Antoine Berchet committed
13
14
15
     {"incrmode": "cst", "testspace": "chi"},
     {"incrmode": "rand", "testspace": "control"},
     {"incrmode": "rand", "testspace": "chi"}
16
     ])
17
def test_integration_adjtltest(dummy_config_inversion, settings):
Antoine Berchet's avatar
Antoine Berchet committed
18
19
20
    """
    Integration test that runs the dummy_forward model.
    """
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    (tmpdir, config, tag) = dummy_config_inversion

    # Changing mode
    config.update(
        {"mode": {
            "plugin": {"name": "adj-tl_test", "version": "std"},
            "increments": 0.2,
            "incrmode": "cst",
            "testspace": "control",
        }}
    )

    # Applying various configurations modes
    config["mode"]["incrmode"] = settings.get("incrmode", "cst")
    config["mode"]["testspace"] = settings.get("testspace", "control")

    # Altering temporal resolution
    params = config["datavect"]["components"]["fluxes"]["parameters"]
    CH4 = params["CH4"] if "CH4" in params else params["CH4_ref"]
    CH4["period"] = settings.get("tresol", "5D")
42

43
44
45
46
47
    # Dump yml config file
    dummy_config_file = os.path.join(tmpdir, "dummy_config.yml")
    with open(dummy_config_file, "w") as outfile:
        ordered_dump(outfile, config)
        
48
49
    # Run the dummy model
    adjtltest_results = Setup.run_simu({"def_file": dummy_config_file})
50

51
52
    # Test of the adjoint passes only if eps < 100
    assert adjtltest_results < 100
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    
    # Dump configuration into CIF examples
    tag += "_" + settings.get("incrmode", "cst") + "-incr_" \
          + settings.get("testspace", "control") + "-testspace_" \
          + ("fullperiod" if settings.get("tresol", "5D") else
             "subperiod")
    
    current_dir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
    example_dir = \
        os.path.abspath(os.path.join(current_dir, "../../examples/dummy/"))
    
    dummy_config_file = \
        os.path.join(example_dir, "config_adjtltest_{}.yml".format(tag))
    with open(dummy_config_file, "w") as outfile:
        ordered_dump(outfile, config)