Beispiel #1
0
def GetRestartByJobId(sim, job_id):

    restart = simrestart.SimRestart()
    restart.load(sim)

    rids = GetRestartIds(restart)

    for rid in rids:
        restart = simrestart.SimRestart()
        restart.load(sim, rid)

        if job_id == restart.GetJobId():
            return restart

        restart.done()
Beispiel #2
0
def command_cleanup():
    if len(simenv.OptionsManager.args):
        simulations = simenv.OptionsManager.args
    else:
        simulations = simlib.GetSimulations()

    for simulationName in simulations:
        display("Cleaning up simulation %s" % simulationName)

        restart = simrestart.SimRestart()
        ret = restart.load(simulationName)

        if simenv.OptionsManager.HasOption('restart-id'):
            rid = simenv.OptionsManager.GetOption('restart-id')
        else:
            rid = restartlib.GetActiveRestartId(restart)
        if rid<0:
            info("Simulation is not active; doing nothing")
            continue
        
        ret = restart.load(simulationName, rid)
        if ret == -1:
            fatal("unable to load simulation %s for cleanup" % simulationName)
                
        info("Cleaning up simulation %s, restart id %s" % (simulationName, rid))
        restart.finish()
        restart.done()
Beispiel #3
0
def command_create():
    if simenv.CACTUS_PATH == None:
        fatal("cannot proceed with unknown CACTUS_PATH")
    
    simulationName = simlib.ParseSimulationCommandLine()
    
    if simulationName == None:
        if len(simenv.OptionsManager.args) == 0:
            fatal("no simulation name specified")
            
        simulationName = simenv.OptionsManager.args.pop(0)
        display("Simulation name: %s" % simulationName)

    if not simenv.OptionsManager.HasOption('testsuite'):
        parfile = simlib.GetParFile()
        if parfile == None:
            fatal("no parameter file specified")
    
        display("Parameter file: %s" % parfile)
    else:
        parfile = simlib.GetParFile()
        if parfile != None:
            fatal("parameter file specified together with --testsuite option")

        parfile = "" # Properties system writes 'None' as an empty
                     # string to file, so we have to use something
                     # else

    restart = simrestart.SimRestart()
    restart.create(simulationName, parfile)
    restart.done()
Beispiel #4
0
def CheckActive(simulationName):

    # TODO: why do we load the restart?
    restart = simrestart.SimRestart()
    restart.load(simulationName)
    active_id = GetActiveRestartId(restart)
    restart.done()
    return active_id >= 0
Beispiel #5
0
def GetRestartByRestartId(sim, restart_id):
    restart = simrestart.SimRestart()
    ret = restart.load(sim, restart_id)

    if ret < 0:
        fatal("Could not load simulation %s with restart id %s" %
              (sim, restart_id))

    return restart
Beispiel #6
0
def CleanupRestarts():

    #dprint("CleanupRestarts...");

    if simenv.LocalMachine == None:
        return

    for sim in simlib.GetSimulations():

        # lets peek in to see if the simulation has an active restart
        if not HasActiveRestart(sim):
            continue

        restart = simrestart.SimRestart()
        ret = restart.load(sim)

        # get rate stamp.
        current_time = time.time()

        # TODO: this logic need to be moved into simrestart.finish
        # make sure the simulation is at least 1 minute old.
        sim_create_time = restart.GetMarkTime("simulation")

        if sim_create_time != None and (current_time - sim_create_time) < 60:
            restart.SimulationLog.Write(
                "Skipping simulation %s, simulation create time %s is not 60 seconds from current mark %s"
                % (sim, sim_create_time, current_time))
            restart.done()
            continue

        mark_time = restart.GetMarkTime()

        # only attempt a cleanup every wo minutes apart.
        if mark_time != None and (current_time - mark_time) < 30:
            restart.SimulationLog.Write(
                "Skipping simulation %s, mark time %s is not 30 seconds from current mark %s"
                % (sim, mark_time, current_time))
            restart.done()
            continue

        # less than zero, not greater than zero.
        if ret < 0:
            continue

        active_id = GetActiveRestartId(restart)

        if active_id != -1:
            ret = restart.load(sim, active_id)

            if ret > 0:
                restart.finish()
                restart.done()
Beispiel #7
0
def StopAllActiveRestarts(sim):

    restart = simrestart.SimRestart()
    restart.load(sim)

    rids = GetRestartIds(restart)

    for rid in rids:
        restart = simrestart.SimRestart()
        restart.load(sim, rid)

        job_id = restart.GetJobId()

        if job_id == -1:
            restart.done()
            continue

        status = GetJobStatus(job_id)

        if status != 'U':
            restart.stop()

        restart.done()
Beispiel #8
0
def command_submit():
    simulationName = simlib.ParseSimulationCommandLine()
    
    if simulationName == None:
        
        if len(simenv.OptionsManager.args) == 0:
            fatal("No simulation name specified")
            
        simulationName = simenv.OptionsManager.args.pop(0)
        display("Simulation name: %s" % simulationName)

    restart = simrestart.SimRestart()
    restart.userSubmit(simulationName)
    restart.done()
Beispiel #9
0
def GetMaxRestartID(simulationName):

    restart = simrestart.SimRestart()
    restart.load(simulationName)

    rids = GetRestartIds(restart)

    if len(rids) == 0:
        max_restart_id = -1
    else:
        max_restart_id = rids[len(rids) - 1]

    restart.done()

    return max_restart_id
Beispiel #10
0
def GetActiveJobId(simulationName):

    restart = simrestart.SimRestart()
    restart.load(simulationName)

    active_id = GetActiveRestartId(restart)

    if active_id == -1:
        return None

    restart.load(simulationName, active_id)
    job_id = restart.GetJobId()

    restart.done()

    return job_id
Beispiel #11
0
def command_archive():
    simulationName = simenv.OptionsManager.args.pop(0)
    
    display("Simulation name: %s" % simulationName)
    
    if simenv.OptionsManager.HasOption('restart-id'):
        restart_id = simenv.OptionsManager.GetOption('restart-id')
        restart = restartlib.GetRestartByRestartId(simulationName, restart_id)
    else:
        restart = simrestart.SimRestart()
        ret = restart.load(simulationName)
    
        if ret < 0:
            fatal("unable to load simulation %s for archiving" % simulationName)
    
    restart.archive()
    restart.done()
Beispiel #12
0
def command_run_debug():
    simulationName = simlib.ParseSimulationCommandLine()
    
    if simulationName == None:
        simulationName = simenv.OptionsManager.args.pop(0)
    
    display("Simulation name: %s" % simulationName)
    
    restart = simrestart.SimRestart()
    
    ret = restart.load(simulationName)
    
    if ret == -1:
        fatal("unable to load simulation %s for execution" % simulationName)
                
    restart.userRun(simulationName, debug=True)
    restart.done()
Beispiel #13
0
def command_purge():
    if len(simenv.OptionsManager.args) == 0:
        fatal("Error: no simulation name specified\nUsage: %s purge <simulationname> <simulationname> ..." % sys.argv[0])
        
    for simulationName in simenv.OptionsManager.args:
        simulationName = simenv.OptionsManager.args.pop(0)
    
        display("Simulation name: %s" % simulationName)
        
        restart = simrestart.SimRestart()
        
        ret = restart.load(simulationName)
        
        if ret == -1:
            fatal("unable to load simulation %s for purging" % simulationName)

        restart.trash()
        
        restart.done()
Beispiel #14
0
def GetMaxJobId(simulationName):
    # TODO: rename this function, because it return the job ID of the
    # penultimate (not the ultimate) restart

    restart = simrestart.SimRestart()
    restart.load(simulationName)

    # Subtract one, so that the current restart ID is ignored
    max_id = GetMaxRestartID(simulationName) - 1

    if max_id < 0:
        return None

    restart.load(simulationName, max_id)
    job_id = restart.GetJobId()

    restart.done()

    return job_id
Beispiel #15
0
def command_run():
    simulationName = simlib.ParseSimulationCommandLine()
    
    if simulationName == None:
        simulationName = simenv.OptionsManager.args.pop(0)
    
    display("Simulation name: %s" % simulationName)
    
    restart = simrestart.SimRestart()
    ret = restart.load(simulationName)
    
    if ret == -1:
        fatal("unable to load simulation %s for execution" % simulationName)
    
    if simenv.OptionsManager.HasOption('restart-id'):
        restart_id = simenv.OptionsManager.GetOption('restart-id')
        restart.submitRun(simulationName, restart_id)
    else:
        restart.userRun(simulationName)
        restart.done()
Beispiel #16
0
def command_show_output():
    simulationName = simenv.OptionsManager.args.pop(0)
    
    display("Simulation name: %s" % simulationName)
    
    restart_id = -1

    if simenv.OptionsManager.HasOption('restart-id'):
        restart_id = simenv.OptionsManager.GetOption('restart-id')
    else:
        restart_id = restartlib.GetMaxRestartID(simulationName)
        
    restart = simrestart.SimRestart()
    ret = restart.load(simulationName, restart_id)
    
    if ret == -1:
        fatal("unable to load simulation %s for output" % simulationName)
        
    restart.show_output()
    
    restart.done()
Beispiel #17
0
def command_get_output_dir():

    simulationName = None

    if simulationName == None:
        simulationName = simenv.OptionsManager.args.pop(0)

    restart = simrestart.SimRestart()

    restart_id = -1

    if simenv.OptionsManager.HasOption('restart-id'):
        restart_id = simenv.OptionsManager.GetOption('restart-id')
    else:
        restart_id = restartlib.GetMaxRestartID(simulationName)

    restart.load(simulationName, restart_id)

    display(restart.RestartDir)
    
    restart.done()
Beispiel #18
0
def command_interactive():
    restart = simrestart.SimRestart()
    restart.interactive()
Beispiel #19
0
def list_simulations():

    simlib.RequireMachine()

    if len(simenv.OptionsManager.args):
        simulations = simenv.OptionsManager.args
    else:
        simulations = simlib.GetSimulations()

    if len(simulations) == 0:
        display("There are no simulations")
        return

    simulations.sort()

    if simenv.VERBOSE:
        display("Simulations:")

    if simenv.OptionsManager.GetOption('name-only'):
        for sim in simulations:
            print sim
        return

    for sim in simulations:
        restart = simrestart.SimRestart()
        restart.load(sim)

        restartIds = restartlib.GetRestartIds(restart)
        activeId = restartlib.GetActiveRestartId(restart, warnOnly=True)
        if activeId == -2:
            display("   %-21s   [ERROR, restart %04d]" % (sim, int(activeId)))
            continue

        active = activeId >= 0
        if not active and len(restartIds) > 0:
            # Use the last restart if there is no active restart
            activeId = restartIds[len(restartIds) - 1]

        if activeId >= 0:
            ret = restart.load(sim, activeId)
            if ret < 0:
                # Something is wrong with the active restart
                display("   %-21s   [ERROR, restart %04d]" %
                        (sim, int(activeId)))
                continue
        job_id = -1
        if activeId >= 0:
            job_id = restart.GetJobId()

        # TODO: The number of presubmitted restarts should also be
        # output.

        if active:
            state_map = dict()
            state_map['H'] = 'ACTIVE (PRESUBMITTED)'
            state_map['Q'] = 'ACTIVE (QUEUED)'
            state_map['R'] = 'ACTIVE (RUNNING)'
            state_map['U'] = 'ACTIVE (FINISHED)'
            state_map['E'] = 'ERROR'
            job_status = restartlib.GetJobStatus(job_id)
            state = state_map[job_status]
            if not state:
                error("Illegal job status '%s'" % job_status)
        else:
            state = 'INACTIVE'

        if not simenv.OptionsManager.GetOption('long'):
            display("   %-21s   [%-9s, restart %04d, job id %s]" %
                    (sim, state, int(activeId), job_id))
        else:
            display("   %-21s= %s" % (sim, state))

            # Active Restart Id
            display("        %-16s= %04d" % ("restart id", int(activeId)))

            # Job
            display("        %-16s= %s" % ("job id", job_id))

            # Disk usage
            fd = simenv.popen("du -sk %s | cut -f1" % restart.SimulationDir)
            size_in_k = int(fd.read().strip())
            fd.close()
            display("        %-16s= %.1f GByte" %
                    ("Disk usage", size_in_k * 1024 / 1.0e+9))

            # Properties
            #PrintManyLeadingSpace(restart.Properties.toString(), 8)

        if restart:
            restart.done()