Exemplo n.º 1
0
def check_case(case):
    check_lockedfiles(case)
    create_namelists(case) # Must be called before check_all_input_data
    logger.info("Checking that inputdata is available as part of case submission")
    check_all_input_data(case)

    expect(case.get_value("BUILD_COMPLETE"), "Build complete is "
           "not True please rebuild the model by calling case.build")
    logger.info("Check case OK")
Exemplo n.º 2
0
def check_case(case, caseroot):
    check_lockedfiles(caseroot)
    create_namelists(case) # Must be called before check_all_input_data
    check_all_input_data(case)
    # Now that we have baselines, do baseline operations
    if case.get_value("TEST"):
        case_cmpgen_namelists(case)

    expect(case.get_value("BUILD_COMPLETE"), "Build complete is "
           "not True please rebuild the model by calling case.build")
    logger.info("Check case OK")
Exemplo n.º 3
0
    def run_phase(self):
        caseroot = self._case.get_value("CASEROOT")
        clone1_path = "%s.ref1" % caseroot
        clone2_path = "%s.ref2" % caseroot
        #self._case.set_value("CHECK_TIMING", False)

        #
        # clone the main case to create ref1 and ref2 cases
        #
        for clone_path in [clone1_path, clone2_path]:
            if os.path.exists(clone_path):
                shutil.rmtree(clone_path)

        clone1, clone2 = [self._case.create_clone(clone_path, keepexe=True) for clone_path in [clone1_path, clone2_path]]
        orig_case = self._case
        orig_casevar = orig_case.get_value("CASE")
        #
        # determine run lengths needed below
        #
        stop_n = self._case.get_value("STOP_N")
        stop_option = self._case.get_value("STOP_OPTION")
        run_startdate = self._case.get_value("RUN_STARTDATE")

        stop_n1 = stop_n / 6
        rest_n1 = stop_n1
        start_1 = run_startdate

        stop_n2 = stop_n - stop_n1
        rest_n2 = stop_n2 / 2 + 1
        hist_n  = stop_n2

        start_1_year, start_1_month, start_1_day = [int(item) for item in start_1.split("-")]
        start_2_year = start_1_year + 2
        start_2 = "%04d-%02d-%02d" % (start_2_year, start_1_month, start_1_day)

        stop_n3 = stop_n2 - rest_n2
        rest_n3 = stop_n3 / 2 + 1

        stop_n4 = stop_n3 - rest_n3

        expect(stop_n4 >= 1 and stop_n1 >= 1, "Run length too short")

        #
        # (1) Test run:
        # do an initial ref1 case run
        # cloned the case and running there
        # (NOTE: short term archiving is on)
        #

        os.chdir(clone1_path)
        self._set_active_case(clone1)

        logger.info("ref1 startup: doing a %s %s startup run from %s and 00000 seconds" % (stop_n1, stop_option, start_1))
        logger.info("  writing restarts at %s %s" % (rest_n1, stop_option))
        logger.info("  short term archiving is on ")

        clone1.set_value("CONTINUE_RUN", False)
        clone1.set_value("RUN_STARTDATE", start_1)
        clone1.set_value("STOP_N", stop_n1)
        clone1.set_value("REST_OPTION", stop_option)
        clone1.set_value("REST_N", rest_n1)
        clone1.set_value("HIST_OPTION", "never")
        clone1.flush()

        # if the initial case is hybrid this will put the reference data in the correct location
        check_all_input_data(clone1)

        dout_sr1 = clone1.get_value("DOUT_S_ROOT")

        # force cam namelist to write out initial file at end of run
        if os.path.exists("user_nl_cam"):
            if "inithist" not in open("user_nl_cam", "r").read():
                with open("user_nl_cam", "a") as fd:
                    fd.write("inithist = 'ENDOFRUN'\n")

        self.run_indv(st_archive=True, suffix=None)

        #
        # (2) Test run:
        # do a hybrid ref2 case run
        # cloned the main case and running with ref1 restarts
        # (NOTE: short term archiving is on)
        #

        os.chdir(clone2_path)
        self._set_active_case(clone2)

        # Set startdate to start2, set ref date based on ref1 restart
        refdate_2 = run_cmd_no_fail(r'ls -1dt %s/rest/*-00000* | head -1 | sed "s/-00000.*//" | sed "s/^.*rest\///"' % dout_sr1)
        refsec_2 = "00000"

        logger.info("ref2 hybrid: doing a %s %s startup hybrid run" % (stop_n2, stop_option))
        logger.info("  starting from %s and using ref1 %s and %s seconds" % (start_2, refdate_2, refsec_2))
        logger.info("  writing restarts at %s %s" % (rest_n2, stop_option))
        logger.info("  short term archiving is on ")

        # setup ref2 case
        clone2.set_value("RUN_TYPE",      "hybrid")
        clone2.set_value("RUN_STARTDATE", start_2)
        clone2.set_value("RUN_REFCASE",   "%s.ref1" % orig_casevar)
        clone2.set_value("RUN_REFDATE",   refdate_2)
        clone2.set_value("RUN_REFTOD",    refsec_2)
        clone2.set_value("GET_REFCASE",   False)
        clone2.set_value("CONTINUE_RUN",  False)
        clone2.set_value("STOP_N",        stop_n2)
        clone2.set_value("REST_OPTION",   stop_option)
        clone2.set_value("REST_N",        rest_n2)
        clone2.set_value("HIST_OPTION",   stop_option)
        clone2.set_value("HIST_N",        hist_n)
        clone2.flush()

        rundir = clone2.get_value("RUNDIR")
        dout_sr2 = clone2.get_value("DOUT_S_ROOT")

        if not os.path.exists(rundir):
            os.makedirs(rundir)

        _helper(dout_sr1, refdate_2, refsec_2, rundir)

        # run ref2 case (all component history files will go to short term archiving)

        self.run_indv(suffix="hybrid", st_archive=True)

        #
        # (3a) Test run:
        # do a branch run from ref2 restart (short term archiving is off)
        #

        os.chdir(caseroot)
        self._set_active_case(orig_case)

        refdate_3 = run_cmd_no_fail(r'ls -1dt %s/rest/*-00000* | head -1 | sed "s/-00000.*//" | sed "s/^.*rest\///"' % dout_sr2)
        refsec_3 = "00000"

        logger.info("branch: doing a %s %s branch" % (stop_n3, stop_option))
        logger.info("  starting from ref2 %s and %s seconds restarts" % (refdate_3, refsec_3))
        logger.info("  writing restarts at %s %s" % (rest_n3, stop_option))
        logger.info("  short term archiving is off")

        self._case.set_value("RUN_TYPE"      , "branch")
        self._case.set_value("RUN_REFCASE"   , "%s.ref2" % self._case.get_value("CASE"))
        self._case.set_value("RUN_REFDATE"   , refdate_3)
        self._case.set_value("RUN_REFTOD"    , refsec_3)
        self._case.set_value("GET_REFCASE"   , False)
        self._case.set_value("CONTINUE_RUN"  , False)
        self._case.set_value("STOP_N"        , stop_n3)
        self._case.set_value("REST_OPTION"   , stop_option)
        self._case.set_value("REST_N"        , rest_n3)
        self._case.set_value("HIST_OPTION"   , stop_option)
        self._case.set_value("HIST_N"        , stop_n2)
        self._case.set_value("DOUT_S"        , False)
        self._case.flush()

        rundir = self._case.get_value("RUNDIR")
        if not os.path.exists(rundir):
            os.makedirs(rundir)

        _helper(dout_sr2, refdate_3, refsec_3, rundir)

        # the following lines creates the initial component history files for the restart test
        for item in glob.glob("%s/*/hist/*nc" % dout_sr2):
            newfile = "%s" % item.replace(".ref2", "")
            newfile = os.path.basename(newfile)
            os.symlink(item, os.path.join(rundir, newfile))

        self._component_compare_copy("hybrid")

        # run branch case (short term archiving is off)
        self.run_indv()

        #
        # (3b) Test run:
        # do a restart continue from (3a) (short term archiving off)
        #

        logger.info("branch restart: doing a %s %s continue restart test" % (stop_n4, stop_option))

        self._case.set_value("CONTINUE_RUN",  True)
        self._case.set_value("STOP_N",        stop_n4)
        self._case.set_value("REST_OPTION",   "never")
        self._case.set_value("DOUT_S",        False)
        self._case.set_value("HIST_OPTION",   stop_option)
        self._case.set_value("HIST_N",        hist_n)
        self._case.flush()

        # do the restart run (short term archiving is off)
        self.run_indv(suffix="rest")

        self._component_compare_test("base", "hybrid")
        self._component_compare_test("base", "rest")
Exemplo n.º 4
0
def case_build(caseroot, case, sharedlib_only=False, model_only=False):
###############################################################################

    t1 = time.time()

    expect(not (sharedlib_only and model_only),
           "Contradiction: both sharedlib_only and model_only")

    logger.info("sharedlib_only is %s" % sharedlib_only)
    logger.info("model_only is %s" % model_only)

    expect(os.path.isdir(caseroot), "'%s' is not a valid directory" % caseroot)
    os.chdir(caseroot)

    expect(os.path.exists("case.run"),
           "ERROR: must invoke case.setup script before calling build script ")

    cimeroot = case.get_value("CIMEROOT")

    comp_classes = case.get_values("COMP_CLASSES")

    if not sharedlib_only:
        check_all_input_data(case)

    run_cmd_no_fail("./Tools/check_lockedfiles --caseroot %s" % caseroot)

    # Retrieve relevant case data
    # This environment variable gets set for cesm Make and
    # needs to be unset before building again.
    if "MODEL" in os.environ.keys():
        del os.environ["MODEL"]
    build_threaded      = case.get_value("BUILD_THREADED")
    casetools           = case.get_value("CASETOOLS")
    exeroot             = case.get_value("EXEROOT")
    incroot             = case.get_value("INCROOT")
    libroot             = case.get_value("LIBROOT")
    sharedlibroot       = case.get_value("SHAREDLIBROOT")

    complist = []
    for comp_class in comp_classes:
        if comp_class == "DRV":
            comp_class = "CPL"
            ninst = 1
            config_dir = None
        else:
            ninst = case.get_value("NINST_%s"%comp_class)
            config_dir = os.path.dirname(case.get_value("CONFIG_%s_FILE"%comp_class))

        comp = case.get_value("COMP_%s"%comp_class)
        thrds =  case.get_value("NTHRDS_%s"%comp_class)
        complist.append((comp_class.lower(), comp, thrds, ninst, config_dir ))
        os.environ["COMP_%s"%comp_class] = comp
    machines_file       = case.get_value("MACHINES_SPEC_FILE")
    ocn_submodel        = case.get_value("OCN_SUBMODEL")
    profile_papi_enable = case.get_value("PROFILE_PAPI_ENABLE")
    compiler            = case.get_value("COMPILER")
    comp_interface      = case.get_value("COMP_INTERFACE")
    mpilib              = case.get_value("MPILIB")
    use_esmf_lib        = case.get_value("USE_ESMF_LIB")
    debug               = case.get_value("DEBUG")
    ninst_build         = case.get_value("NINST_BUILD")
    smp_value           = case.get_value("SMP_VALUE")
    clm_use_petsc       = case.get_value("CLM_USE_PETSC")
    cism_use_trilinos   = case.get_value("CISM_USE_TRILINOS")
    mpasli_use_albany   = case.get_value("MPASLI_USE_ALBANY")
    clm_config_opts     = case.get_value("CLM_CONFIG_OPTS")
    cam_config_opts     = case.get_value("CAM_CONFIG_OPTS")
    pio_config_opts     = case.get_value("PIO_CONFIG_OPTS")
    ninst_value         = case.get_value("NINST_VALUE")
    mach                = case.get_value("MACH")
    os_                 = case.get_value("OS")
    # Load some params into env
    os.environ["CIMEROOT"]             = cimeroot
    os.environ["CASETOOLS"]            = casetools
    os.environ["EXEROOT"]              = exeroot
    os.environ["INCROOT"]              = incroot
    os.environ["LIBROOT"]              = libroot
    os.environ["SHAREDLIBROOT"]        = sharedlibroot
    os.environ["CASEROOT"]             = caseroot
    os.environ["COMPILER"]             = compiler
    os.environ["COMP_INTERFACE"]       = comp_interface
    os.environ["NINST_VALUE"]          = str(ninst_value)
    os.environ["BUILD_THREADED"]       = stringify_bool(build_threaded)
    os.environ["MACH"]                 = mach
    os.environ["USE_ESMF_LIB"]         = stringify_bool(use_esmf_lib)
    os.environ["MPILIB"]               = mpilib
    os.environ["DEBUG"]                = stringify_bool(debug)
    os.environ["OS"]                   = os_
    os.environ["CLM_CONFIG_OPTS"]      = clm_config_opts     if clm_config_opts     is not None else ""
    os.environ["CAM_CONFIG_OPTS"]      = cam_config_opts     if cam_config_opts     is not None else ""
    os.environ["PIO_CONFIG_OPTS"]      = pio_config_opts     if pio_config_opts     is not None else ""
    os.environ["OCN_SUBMODEL"]         = ocn_submodel        if ocn_submodel        is not None else ""
    os.environ["PROFILE_PAPI_ENABLE"]  = stringify_bool(profile_papi_enable)
    os.environ["CLM_USE_PETSC"]        = stringify_bool(clm_use_petsc)
    os.environ["CISM_USE_TRILINOS"]    = stringify_bool(cism_use_trilinos)
    os.environ["MPASLI_USE_ALBANY"]    = stringify_bool(mpasli_use_albany)

    # This is a timestamp for the build , not the same as the testid,
    # and this case may not be a test anyway. For a production
    # experiment there may be many builds of the same case.
    lid               = run_cmd_no_fail("date +%y%m%d-%H%M%S")
    os.environ["LID"] = lid

    # Set the overall USE_PETSC variable to TRUE if any of the
    # *_USE_PETSC variables are TRUE.
    # For now, there is just the one CLM_USE_PETSC variable, but in
    # the future there may be others -- so USE_PETSC will be true if
    # ANY of those are true.

    use_petsc = clm_use_petsc
    case.set_value("USE_PETSC", use_petsc)
    os.environ["USE_PETSC"] = stringify_bool(use_petsc)

    # Set the overall USE_TRILINOS variable to TRUE if any of the
    # *_USE_TRILINOS variables are TRUE.
    # For now, there is just the one CISM_USE_TRILINOS variable, but in
    # the future there may be others -- so USE_TRILINOS will be true if
    # ANY of those are true.

    use_trilinos = False if cism_use_trilinos is None else cism_use_trilinos
    case.set_value("USE_TRILINOS", use_trilinos)
    os.environ["USE_TRILINOS"] = stringify_bool(use_trilinos)

    # Set the overall USE_ALBANY variable to TRUE if any of the
    # *_USE_ALBANY variables are TRUE.
    # For now, there is just the one MPASLI_USE_ALBANY variable, but in
    # the future there may be others -- so USE_ALBANY will be true if
    # ANY of those are true.

    use_albany = stringify_bool(mpasli_use_albany)
    case.set_value("USE_ALBANY", use_albany)
    os.environ["USE_ALBANY"] = use_albany

    # Load modules
    env_module = case.get_env("mach_specific")
    env_module.load_env_for_case(compiler=case.get_value("COMPILER"),
                                 debug=case.get_value("DEBUG"),
                                 mpilib=case.get_value("MPILIB"))


    # Need to flush case xml to disk before calling preview_namelists
    case.flush()

    if not sharedlib_only:
        preview_namelists(case)

    build_checks(case, build_threaded, comp_interface, use_esmf_lib, debug, compiler, mpilib,
                 sharedlibroot, complist, ninst_build, smp_value)

    t2 = time.time()
    logs = []

    if not model_only:
        logs = build_libraries(case, exeroot, caseroot, cimeroot, libroot, mpilib, lid,
                               machines_file)

    if not sharedlib_only:
        logs.extend(build_model(build_threaded, exeroot, clm_config_opts, incroot, complist,
                                lid, caseroot, cimeroot))

    if not sharedlib_only:
        post_build(case, logs)

    t3 = time.time()

    logger.info("Time spent not building: %f sec" % (t2 - t1))
    logger.info("Time spent building: %f sec" % (t3 - t2))

    return True