Exemple #1
0
def main(argv):

    app = QApplication(argv) #Early so that QT is initialized before other imports
    app.setWindowIcon(resourceIcon("application/window_icon_cutout"))

    if len(argv) == 1:
        sys.stderr.write("Missing configuration file")
        sys.exit(1)

    config_file = argv[1]
    strict = True
        
    if not os.path.exists(config_file):
        print("Can not run without a configuration file.")
        sys.exit(1)

    if os.path.isdir(config_file):
        print("The specified configuration file is a directory!")
        sys.exit(1)


    splash = ErtSplash()
    splash.version = "Version %s" % Version.getVersion()
    splash.timestamp = Version.getBuildTime()

    splash.show()
    splash.repaint()

    now = time.time()


    ert = EnKFMain(config_file, strict=strict, verbose=False)
    ert_gui.configureErtNotifier(ert, config_file)

    window = PlotWindow(ert, None)

    sleep_time = 2 - (time.time() - now)

    if sleep_time > 0:
        time.sleep(sleep_time)

    window.show()
    splash.finish(window)
    window.activateWindow()
    window.raise_()
    finished_code = app.exec_()

    ert.free()

    sys.exit(finished_code)
Exemple #2
0
def main(argv):

    app = QApplication(
        argv)  #Early so that QT is initialized before other imports
    app.setWindowIcon(util.resourceIcon("application/window_icon_cutout"))

    if len(argv) == 1:
        sys.stderr.write("Missing configuration file")
        sys.exit(1)

    config_file = argv[1]
    strict = True

    if not os.path.exists(config_file):
        print("Can not run without a configuration file.")
        sys.exit(1)

    if os.path.isdir(config_file):
        print("The specified configuration file is a directory!")
        sys.exit(1)

    splash = ErtSplash()
    splash.version = "Version %s" % Version.getVersion()
    splash.timestamp = Version.getBuildTime()

    splash.show()
    splash.repaint()

    now = time.time()

    ert = EnKFMain(config_file, strict=strict, verbose=False)
    ErtConnector.setErt(ert)

    window = PlotWindow(ert, None)

    sleep_time = 2 - (time.time() - now)

    if sleep_time > 0:
        time.sleep(sleep_time)

    window.show()
    splash.finish(window)
    window.activateWindow()
    window.raise_()
    finished_code = app.exec_()

    ert.free()

    sys.exit(finished_code)
Exemple #3
0
    def __init__(self, config, host="localhost", port=0, log_requests=False, verbose_queue=False):
        SimpleXMLRPCServer.__init__(self, (host, port), allow_none=True, logRequests=log_requests)
        self._host = host
        self._verbose_queue = verbose_queue
        # https: server.socket = ssl.wrap_socket(srv.socket, ...)

        if isinstance(config, EnKFMain):
            self._config = config
            self._config_file = config.getUserConfigFile()
        else:
            if os.path.exists(config):
                self._config = EnKFMain(config)
                self._config_file = config
            else:
                raise IOError("The ert config file: %s does not exist" % config)

        self._session = Session()

        self.register_function(self.ertVersion)
        self.register_function(self.getTimeMap)
        self.register_function(self.isRunning)
        self.register_function(self.isInitializationCaseAvailable)
        self.register_function(self.startSimulationBatch)
        self.register_function(self.addSimulation)
        self.register_function(self.isRealizationFinished)
        self.register_function(self.didRealizationSucceed)
        self.register_function(self.didRealizationFail)
        self.register_function(self.getGenDataResult)
        self.register_function(self.getCustomKWResult)
        self.register_function(self.isCustomKWKey)
        self.register_function(self.isGenDataKey)
        self.register_function(self.prototypeStorage)
        self.register_function(self.storeGlobalData)
        self.register_function(self.storeSimulationData)
Exemple #4
0
 def do_load_config(self, config_file):
     if os.path.exists(config_file) and os.path.isfile(config_file):
         self.shellContext().setErt(EnKFMain(config_file))
         ert_gui.configureErtNotifier(self.shellContext().ert(),
                                      config_file)
     else:
         self.lastCommandFailed("Config file '%s' not found!\n" %
                                config_file)
Exemple #5
0
class ErtServer(object):
    DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
    site_config = None

    def __init__(self, config_file, logger):
        installAbortSignals()

        self.queue_lock = threading.Lock()
        self.ert_handle = None
        self.logger = logger
        if os.path.exists(config_file):
            self.open(config_file)
        else:
            raise IOError("The config file:%s does not exist" % config_file)

        self.initCmdTable()
        self.run_context = None
        self.init_fs = None
        self.run_fs = None
        self.run_count = 0

    def SUCCESS(self, res):
        self.logger.debug("Success: returning: %s", res)
        return SUCCESS(res)

    def ERROR(self, res):
        self.logger.debug("ERROR: returning: %s", res)
        return ERROR(res)

    def initCmdTable(self):
        self.cmd_table = {
            "STATUS": self.handleSTATUS,
            "INIT_SIMULATIONS": self.handleINIT_SIMULATIONS,
            "ADD_SIMULATION": self.handleADD_SIMULATION,
            "GET_RESULT": self.handleGET_RESULT,
            "TIME_STEP": self.handleTIMESTEP
        }

    def open(self, config_file):
        self.config_file = config_file
        self.ert_handle = EnKFMain(config_file)
        self.logger.info("Have connect ert handle to:%s", config_file)

    def close(self):
        # More cleanup first ...
        self.logger.info("Shutting down ert handle")
        self.ert_handle = None

    def isConnected(self):
        if self.ert_handle:
            return True
        else:
            return False

    def __del__(self):
        if self.isConnected():
            self.close()

    def evalCmd(self, cmd_expr):
        cmd = cmd_expr[0]
        func = self.cmd_table.get(cmd)
        self.logger.info("Received command: %s" % cmd)

        if func:
            return func(cmd_expr[1:])
        else:
            raise KeyError("The command:%s was not recognized" % cmd)

    def handleSTATUS(self, args):
        if self.isConnected():
            if self.run_context is None:
                return self.SUCCESS(["READY"])
            else:
                if self.run_context.isRunning():
                    if len(args) == 0:
                        return self.SUCCESS([
                            "RUNNING",
                            self.run_context.getNumRunning(),
                            self.run_context.getNumComplete()
                        ])
                    else:
                        iens = args[0]
                        if self.run_context.realisationComplete(iens):
                            return self.SUCCESS(["COMPLETE"])
                        else:
                            return self.SUCCESS(["RUNNING"])
                else:
                    return self.SUCCESS(["COMPLETE"])
        else:
            return self.SUCCESS(["CLOSED"])

    def initSimulations(self, args):
        run_size = args[0]
        init_case = str(args[1])
        run_case = str(args[2])

        fs_manager = self.ert_handle.getEnkfFsManager()
        self.run_fs = fs_manager.getFileSystem(run_case)
        self.init_fs = fs_manager.getFileSystem(init_case)
        fs_manager.switchFileSystem(self.run_fs)

        self.run_context = RunContext(self.ert_handle, run_size, self.run_fs,
                                      self.run_count)
        self.run_count += 1
        return self.handleSTATUS([])

    def restartSimulations(self, args):
        return self.initSimulations(args)

    def handleINIT_SIMULATIONS(self, args):
        if len(args) == 3:
            result = []
            with self.queue_lock:
                if self.run_context is None:
                    self.initSimulations(args)
                else:
                    if not self.run_context.isRunning():
                        self.restartSimulations(args)

                result = ["OK"]

            return self.SUCCESS(result)
        else:
            raise IndexError(
                "The INIT_SIMULATIONS command expects three arguments: [ensemble_size , init_case, run_case]"
            )

    def handleGET_RESULT(self, args):
        iens = args[0]
        kw = str(args[2])

        try:
            year, month, day = args[1]
            time_map = self.run_fs.getTimeMap()
            report_step = time_map.lookupTime(
                datetime.date(year, month, day),
                tolerance_seconds_before=24 * 3600,
                tolerance_seconds_after=24 * 3600)
        except TypeError:
            report_step = args[1]

        ensembleConfig = self.ert_handle.ensembleConfig()
        if kw in ensembleConfig:
            state = self.ert_handle.getRealisation(iens)
            node = state[kw]
            gen_data = node.asGenData()

            fs = self.ert_handle.getEnkfFsManager().getCurrentFileSystem()
            node_id = NodeId(report_step, iens, EnkfStateType.FORECAST)
            if node.tryLoad(fs, node_id):
                data = gen_data.getData()
                return self.SUCCESS(["OK"] + data.asList())
            else:
                raise Exception("Loading iens:%d  report:%d   kw:%s   failed" %
                                (iens, report_step, kw))
        else:
            raise KeyError("The keyword:%s is not recognized" % kw)

    # ["ADD_SIMULATION" , 0 , 1 , 1 [ ["KW1" , ...] , ["KW2" , ....]]]
    def handleADD_SIMULATION(self, args):
        geo_id = args[0]
        pert_id = args[1]
        iens = args[2]
        self.logger.debug("ADD_SIMULATION  geo_id:%d  pert_id:%d  iens:%d" %
                          (geo_id, pert_id, iens))
        kw_list = args[3]
        state = self.ert_handle.getRealisation(iens)
        state.addSubstKeyword("GEO_ID", "%d" % geo_id)

        elco_kw = [l[0] for l in kw_list]
        ens_config = self.ert_handle.ensembleConfig()

        for kw in ens_config.getKeylistFromVarType(EnkfVarType.PARAMETER):
            if not kw in elco_kw:
                node = state[kw]
                init_id = NodeId(0, geo_id, EnkfStateType.ANALYZED)
                run_id = NodeId(0, iens, EnkfStateType.ANALYZED)
                node.load(self.init_fs, init_id)
                node.save(self.run_fs, run_id)

        for kw_arg in kw_list:
            kw = str(kw_arg[0])
            data = kw_arg[1:]
            self.logger.debug("ADD_SIMULATION %s : %s" % (kw, data))

            node = state[kw]
            gen_kw = node.asGenKw()
            gen_kw.setValues(data)

            run_id = NodeId(0, iens, EnkfStateType.ANALYZED)
            node.save(self.run_fs, run_id)

        self.run_fs.fsync()
        state_map = self.run_fs.getStateMap()
        state_map[iens] = RealizationStateEnum.STATE_INITIALIZED

        self.run_context.startSimulation(iens)
        return self.handleSTATUS([])

    def handleTIMESTEP(self, args):
        enkf_fs_manager = self.ert_handle.getEnkfFsManager()
        enkf_fs = enkf_fs_manager.getCurrentFileSystem()
        time_map = enkf_fs.getTimeMap()
        time_steps = [
            ts.datetime().strftime(ErtServer.DATE_FORMAT) for ts in time_map
        ]

        return self.SUCCESS(time_steps)
Exemple #6
0
def main(argv):
    app = QApplication(argv) #Early so that QT is initialized before other imports
    app.setWindowIcon(util.resourceIcon("application/window_icon_cutout"))

    splash = QSplashScreen(resourceImage("newsplash"), Qt.WindowStaysOnTopHint)
    splash.show()
    splash.showMessage("Starting up...", Qt.AlignLeft, Qt.white)
    app.processEvents()

    help_center = HelpCenter("ERT")
    help_center.setHelpLinkPrefix(os.getenv("ERT_SHARE_PATH") + "/gui/help/")
    help_center.setHelpMessageLink("welcome_to_ert")

    splash.showMessage("Bootstrapping...", Qt.AlignLeft, Qt.white)
    app.processEvents()

    strict = True
    site_config = os.getenv("ERT_SITE_CONFIG")
    if len(argv) == 1:
        print("-----------------------------------------------------------------")
        print("-- You must supply the name of configuration file as the first --")
        print("-- commandline argument:                                       --")
        print("--                                                             --")
        print("-- bash%  gert <config_file>                                   --")
        print("--                                                             --")
        print("-- If the configuration file does not exist, gert will create  --")
        print("-- create a new configuration file.                            --")
        print("-----------------------------------------------------------------")
    else:
        enkf_config = argv[1]
        if not os.path.exists(enkf_config):
            print("Trying to start new config")
            new_configuration_dialog = NewConfigurationDialog(enkf_config)
            success = new_configuration_dialog.exec_()
            if not success:
                print("Can not run without a configuration file.")
                sys.exit(1)
            else:
                enkf_config = new_configuration_dialog.getConfigurationPath()
                first_case_name = new_configuration_dialog.getCaseName()
                dbase_type = new_configuration_dialog.getDBaseType()
                num_realizations = new_configuration_dialog.getNumberOfRealizations()
                storage_path = new_configuration_dialog.getStoragePath()

                EnKFMain.createNewConfig(enkf_config, storage_path, first_case_name, dbase_type, num_realizations)
                strict = False

        ert = Ert(EnKFMain(enkf_config, site_config=site_config, strict=strict))
        ErtConnector.setErt(ert.ert())


        splash.showMessage("Creating GUI...", Qt.AlignLeft, Qt.white)
        app.processEvents()


        window = GertMainWindow()
        window.setWidget(SimulationPanel())

        help_tool = HelpTool("ERT", window)

        window.addDock("Configuration Summary", SummaryPanel(), area=Qt.BottomDockWidgetArea)
        window.addTool(IdeTool(os.path.basename(enkf_config), ert.reloadERT, help_tool))
        window.addTool(PlotTool())
        window.addTool(ExportTool())
        window.addTool(WorkflowsTool())
        window.addTool(ManageCasesTool())
        window.addTool(help_tool)


        splash.showMessage("Communicating with ERT...", Qt.AlignLeft, Qt.white)
        app.processEvents()

        window.show()
        splash.finish(window)

        sys.exit(app.exec_())
Exemple #7
0
#!/usr/bin/env python
import sys
import time
from ert.enkf import EnKFMain

# This will instantiate the EnkFMain object and create a handle to
# "everything" ert related for this instance.
ert = EnKFMain(sys.argv[1])
site_config = ert.siteConfig()

jobs = site_config.get_installed_jobs()
for job in jobs:
    print job.name()
    print "   config    : %s" % job.get_config_file()
    print "   executable: %s" % job.get_executable()
    print
Exemple #8
0
class ErtServer(object):
    site_config = None

    def __init__(self , config_file = None):
        self.ert_handle = None
        if config_file:
            if os.path.exists(config_file):
                self.open( config_file )
            else:
                raise IOError("The config file:%s does not exist" % config_file)
        self.initCmdTable()
        self.run_context = None



    def initCmdTable(self):
        self.cmd_table = {"STATUS" : self.handleSTATUS ,
                          "INIT_SIMULATIONS" : self.handleINIT_SIMULATIONS ,
                          "ADD_SIMULATION" : self.handleADD_SIMULATION ,
                          "SET_VARIABLE" : self.handleSET_VARIABLE ,
                          "GET_RESULT" : self.handleGET_RESULT }


    def open(self , config_file):
        self.config_file = config_file
        self.ert_handle = EnKFMain( config_file , ErtServer.site_config )
        


    def close(self):
        # More cleanup first ...
        self.ert_handle = None


    def isConnected(self):
        if self.ert_handle:
            return True
        else:
            return False


    def __del__(self):
        if self.isConnected():
            self.close()



    def evalCmd(self , cmd_expr):
        cmd = cmd_expr[0]
        func = self.cmd_table.get(cmd)

        if func:
            return func(cmd_expr[1:])
        else:
            raise ErtCmdError("The command:%s was not recognized" % cmd)


    def handleSTATUS(self , args):
        if self.isConnected():
            if self.run_context is None:
                return ["READY"]
            else:
                return ["RUNNING" , self.run_context.getNumRunning() , self.run_context.getNumComplete()]
        else:
            return ["CLOSED"]


    def handleINIT_SIMULATIONS(self , args):
        if len(args) == 2:
            if self.run_context is None:
                run_size = args[0]
                init_case = args[1]
                self.run_context = RunContext(self.ert_handle , run_size , init_case)
                return self.handleSTATUS([])
            else:
                raise ErtCmdError("The ert server has already started simulations")
        else:
            raise ErtCmdError("The INIT_SIMULATIONS command expects two arguments: [ensemble_size , init_case]")

    
    def handleGET_RESULT(self , args):
        iens = args[0]
        report_step = args[1]
        kw = str(args[2])
        ensembleConfig = self.ert_handle.ensembleConfig()
        if ensembleConfig.hasKey( kw ):
            state = self.ert_handle[iens]
            node = state[kw]
            gen_data = node.asGenData()
            
            fs = self.ert_handle.getEnkfFsManager().getCurrentFileSystem()
            node_id = NodeId(report_step , iens , EnkfStateType.FORECAST )
            if node.tryLoad( fs , node_id ):
                data = gen_data.getData()
                return json.dumps( ["OK"] + data.asList() )
            else:
                raise ErtCmdError("Loading iens:%d  report:%d   kw:%s   failed" % (iens , report_step , kw))
        else:
            raise ErtCmdError("The keyword:%s is not recognized" % kw)




    def handleSET_VARIABLE(self , args):
        geo_id = args[0]
        pert_id = args[1]
        iens = args[2]
        kw = str(args[3])
        ensembleConfig = self.ert_handle.ensembleConfig()
        if ensembleConfig.hasKey(kw):
            state = self.ert_handle[iens]
            node = state[kw]
            gen_kw = node.asGenKw()
            gen_kw.setValues(args[4:])
            
            fs = self.ert_handle.getEnkfFsManager().getCurrentFileSystem()
            node_id = NodeId(0 , iens , EnkfStateType.ANALYZED )
            node.save( fs , node_id )
        else:
            raise ErtCmdError("The keyword:%s is not recognized" % kw)
            


    def handleADD_SIMULATION(self , args):
        iens = args[0]
        self.run_context.startSimulation( iens )
Exemple #9
0
class ErtServer(object):
    DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
    site_config = None

    def __init__(self , config_file , logger):
        installAbortSignals()

        self.queue_lock = threading.Lock()
        self.ert_handle = None
        self.logger = logger
        if os.path.exists(config_file):
            self.open( config_file )
        else:
            raise IOError("The config file:%s does not exist" % config_file)

        self.initCmdTable()
        self.run_context = None
        self.init_fs = None
        self.run_fs = None
        self.run_count = 0


    def SUCCESS(self , res):
        self.logger.debug("Success: returning: %s" , res)
        return SUCCESS(res)


    def ERROR(self , res):
        self.logger.debug("ERROR: returning: %s" , res)
        return ERROR(res)


    def initCmdTable(self):
        self.cmd_table = {"STATUS" : self.handleSTATUS ,
                          "INIT_SIMULATIONS" : self.handleINIT_SIMULATIONS ,
                          "ADD_SIMULATION" : self.handleADD_SIMULATION ,
                          "GET_RESULT" : self.handleGET_RESULT ,
                          "TIME_STEP": self.handleTIMESTEP }


    def open(self , config_file):
        self.config_file = config_file
        self.ert_handle = EnKFMain( config_file )
        self.logger.info("Have connect ert handle to:%s" , config_file)


    def close(self):
        # More cleanup first ...
        self.logger.info("Shutting down ert handle")
        self.ert_handle = None


    def isConnected(self):
        if self.ert_handle:
            return True
        else:
            return False


    def __del__(self):
        if self.isConnected():
            self.close()



    def evalCmd(self , cmd_expr):
        cmd = cmd_expr[0]
        func = self.cmd_table.get(cmd)
        self.logger.info("Received command: %s" % cmd)
        
        if func:
            return func(cmd_expr[1:])
        else:
            raise KeyError("The command:%s was not recognized" % cmd)



    # The STATUS action can either report results for the complete
    # simulation set, or it can report the status of one particular
    # realisation. If the function is called with zero arguments it
    # will return the global status, if called with one argument it
    # will return the status for that realisation.
        
    def handleSTATUS(self , args):
        if self.isConnected():
            if self.run_context is None:
                return self.SUCCESS(["READY"])
            else:
                if len(args) == 0:
                    if self.run_context.isRunning():
                        return self.SUCCESS(["RUNNING" , self.run_context.getNumRunning() , self.run_context.getNumSuccess() , self.run_context.getNumFailed()])
                    else:
                        return self.SUCCESS(["COMPLETE" , self.run_context.getNumRunning() , self.run_context.getNumSuccess() , self.run_context.getNumFailed()])
                else:
                    iens = args[0]

                    if self.run_context.realisationRunning(iens):
                        return self.SUCCESS(["RUNNING"])
                    elif self.run_context.realisationFailed(iens):
                        return self.SUCCESS(["FAILED"])
                    elif self.run_context.realisationSuccess(iens):
                        return self.SUCCESS(["SUCCESS"])

        else:
            return self.SUCCESS(["CLOSED"])

    
    def initSimulations(self , args):
        run_size = args[0]
        init_case = str(args[1])
        run_case = str(args[2])
        
        fs_manager = self.ert_handle.getEnkfFsManager()
        self.run_fs = fs_manager.getFileSystem( run_case )
        self.init_fs = fs_manager.getFileSystem( init_case )
        fs_manager.switchFileSystem( self.run_fs )

        self.run_context = RunContext(self.ert_handle , run_size , self.run_fs  , self.run_count)
        self.run_count += 1
        return self.handleSTATUS([])


    def restartSimulations(self , args):
        return self.initSimulations(args)


    def handleINIT_SIMULATIONS(self , args):
        if len(args) == 3:
            result = []
            with self.queue_lock:
                if self.run_context is None:
                    self.initSimulations( args )
                else:
                    if not self.run_context.isRunning():
                        self.restartSimulations( args )
                
                result = ["OK"]
                
            return self.SUCCESS(result)
        else:
            raise IndexError("The INIT_SIMULATIONS command expects three arguments: [ensemble_size , init_case, run_case]")


    
    def handleGET_RESULT(self , args):
        iens = args[0]
        kw = str(args[2])

        try:
            year,month,day = args[1]
            time_map = self.run_fs.getTimeMap( )
            report_step = time_map.lookupTime( datetime.date( year , month , day) , tolerance_seconds_before = 24*3600 , tolerance_seconds_after = 24*3600)
        except TypeError:
            report_step = args[1]

        ensembleConfig = self.ert_handle.ensembleConfig()
        if kw in ensembleConfig:
            state = self.ert_handle.getRealisation( iens )
            node = state[kw]
            gen_data = node.asGenData()
            
            fs = self.ert_handle.getEnkfFsManager().getCurrentFileSystem()
            node_id = NodeId(report_step , iens , EnkfStateType.FORECAST )
            if node.tryLoad( fs , node_id ):
                data = gen_data.getData()
                return self.SUCCESS( ["OK"] + data.asList() )
            else:
                raise Exception("Loading iens:%d  report:%d   kw:%s   failed" % (iens , report_step , kw))
        else:
            raise KeyError("The keyword:%s is not recognized" % kw)





    # ["ADD_SIMULATION" , 0 , 1 , 1 [ ["KW1" , ...] , ["KW2" , ....]]]
    def handleADD_SIMULATION(self , args):
        geo_id = args[0]
        pert_id = args[1]
        iens = args[2]
        self.logger.debug("ADD_SIMULATION  geo_id:%d  pert_id:%d  iens:%d" % (geo_id , pert_id , iens))
        kw_list = args[3]
        state = self.ert_handle.getRealisation( iens )
        state.addSubstKeyword( "GEO_ID" , "%d" % geo_id )
        
        elco_kw = [ l[0] for l in kw_list ]
        ens_config = self.ert_handle.ensembleConfig()

        for kw in ens_config.getKeylistFromVarType( EnkfVarType.PARAMETER ):
            if not kw in elco_kw:
                node = state[kw]
                init_id = NodeId(0 , geo_id , EnkfStateType.ANALYZED )
                run_id = NodeId(0 , iens , EnkfStateType.ANALYZED )
                node.load( self.init_fs , init_id )
                node.save( self.run_fs , run_id )
            
        for kw_arg in kw_list:
            kw = str(kw_arg[0])
            data = kw_arg[1:]
            self.logger.debug("ADD_SIMULATION %s : %s" % (kw , data))
        
            node = state[kw]
            gen_kw = node.asGenKw()
            gen_kw.setValues(data)
        
            run_id = NodeId(0 , iens , EnkfStateType.ANALYZED )
            node.save( self.run_fs , run_id )
            
        self.run_fs.fsync()
        state_map = self.run_fs.getStateMap()
        state_map[iens] = RealizationStateEnum.STATE_INITIALIZED
        
        self.run_context.startSimulation( iens )
        return self.handleSTATUS([])

    def handleTIMESTEP(self, args):
        enkf_fs_manager = self.ert_handle.getEnkfFsManager()
        enkf_fs = enkf_fs_manager.getCurrentFileSystem()
        time_map = enkf_fs.getTimeMap()
        time_steps = [ ts.datetime().strftime(ErtServer.DATE_FORMAT) for ts in time_map ]

        return self.SUCCESS(time_steps)
Exemple #10
0
class ErtServer(object):
    site_config = None

    def __init__(self, config_file, logger):
        installAbortSignals()

        self.queue_lock = threading.Lock()
        self.ert_handle = None
        self.logger = logger
        if os.path.exists(config_file):
            self.open(config_file)
        else:
            raise IOError("The config file:%s does not exist" % config_file)

        self.initCmdTable()
        self.run_context = None
        self.init_fs = None
        self.run_fs = None
        self.run_count = 0

    def SUCCESS(self, res):
        self.logger.debug("Success: returning: %s", res)
        return SUCCESS(res)

    def ERROR(self, res):
        self.logger.debug("ERROR: returning: %s", res)
        return ERROR(res)

    def initCmdTable(self):
        self.cmd_table = {
            "STATUS": self.handleSTATUS,
            "INIT_SIMULATIONS": self.handleINIT_SIMULATIONS,
            "ADD_SIMULATION": self.handleADD_SIMULATION,
            "GET_RESULT": self.handleGET_RESULT,
        }

    def open(self, config_file):
        self.config_file = config_file
        self.ert_handle = EnKFMain(config_file, ErtServer.site_config)
        self.logger.info("Have connect ert handle to:%s", config_file)

    def close(self):
        # More cleanup first ...
        self.logger.info("Shutting down ert handle")
        self.ert_handle = None

    def isConnected(self):
        if self.ert_handle:
            return True
        else:
            return False

    def __del__(self):
        if self.isConnected():
            self.close()

    def evalCmd(self, cmd_expr):
        cmd = cmd_expr[0]
        func = self.cmd_table.get(cmd)
        self.logger.info("Received command: %s" % cmd)

        if func:
            return func(cmd_expr[1:])
        else:
            raise KeyError("The command:%s was not recognized" % cmd)

    def handleSTATUS(self, args):
        if self.isConnected():
            if self.run_context is None:
                return self.SUCCESS(["READY"])
            else:
                if self.run_context.isRunning():
                    if len(args) == 0:
                        return self.SUCCESS(
                            ["RUNNING", self.run_context.getNumRunning(), self.run_context.getNumComplete()]
                        )
                    else:
                        iens = args[0]
                        if self.run_context.realisationComplete(iens):
                            return self.SUCCESS(["COMPLETE"])
                        else:
                            return self.SUCCESS(["RUNNING"])
                else:
                    return self.SUCCESS(["COMPLETE"])
        else:
            return self.SUCCESS(["CLOSED"])

    def initSimulations(self, args):
        run_size = args[0]
        init_case = str(args[1])
        run_case = str(args[2])

        fs_manager = self.ert_handle.getEnkfFsManager()
        self.run_fs = fs_manager.getFileSystem(run_case)
        self.init_fs = fs_manager.getFileSystem(init_case)
        fs_manager.switchFileSystem(self.run_fs)

        self.run_context = RunContext(self.ert_handle, run_size, self.run_fs, self.run_count)
        self.run_count += 1
        return self.handleSTATUS([])

    def restartSimulations(self, args):
        return self.initSimulations(args)

    def handleINIT_SIMULATIONS(self, args):
        if len(args) == 3:
            result = []
            with self.queue_lock:
                if self.run_context is None:
                    self.initSimulations(args)
                else:
                    if not self.run_context.isRunning():
                        self.restartSimulations(args)

                result = ["OK"]

            return self.SUCCESS(result)
        else:
            raise IndexError(
                "The INIT_SIMULATIONS command expects three arguments: [ensemble_size , init_case, run_case]"
            )

    def handleGET_RESULT(self, args):
        iens = args[0]
        report_step = args[1]
        kw = str(args[2])

        ensembleConfig = self.ert_handle.ensembleConfig()
        if ensembleConfig.hasKey(kw):
            state = self.ert_handle.getRealisation(iens)
            node = state[kw]
            gen_data = node.asGenData()

            fs = self.ert_handle.getEnkfFsManager().getCurrentFileSystem()
            node_id = NodeId(report_step, iens, EnkfStateType.FORECAST)
            if node.tryLoad(fs, node_id):
                data = gen_data.getData()
                return self.SUCCESS(["OK"] + data.asList())
            else:
                raise Exception("Loading iens:%d  report:%d   kw:%s   failed" % (iens, report_step, kw))
        else:
            raise KeyError("The keyword:%s is not recognized" % kw)

    # ["ADD_SIMULATION" , 0 , 1 , 1 [ ["KW1" , ...] , ["KW2" , ....]]]
    def handleADD_SIMULATION(self, args):
        geo_id = args[0]
        pert_id = args[1]
        iens = args[2]
        kw_list = args[3]
        state = self.ert_handle.getRealisation(iens)
        state.addSubstKeyword("GEO_ID", "%s" % geo_id)

        elco_kw = [l[0] for l in kw_list]
        ens_config = self.ert_handle.ensembleConfig()

        for kw in ens_config.getKeylistFromVarType(EnkfVarType.PARAMETER):
            if not kw in elco_kw:
                node = state[kw]
                init_id = NodeId(0, geo_id, EnkfStateType.ANALYZED)
                run_id = NodeId(0, iens, EnkfStateType.ANALYZED)
                node.load(self.init_fs, init_id)
                node.save(self.run_fs, run_id)

        for kw_arg in kw_list:
            kw = str(kw_arg[0])
            data = kw_arg[1:]

            node = state[kw]
            gen_kw = node.asGenKw()
            gen_kw.setValues(data)

            run_id = NodeId(0, iens, EnkfStateType.ANALYZED)
            node.save(self.run_fs, run_id)

        state_map = self.run_fs.getStateMap()
        state_map[iens] = RealizationStateEnum.STATE_INITIALIZED

        self.run_context.startSimulation(iens)
        return self.handleSTATUS([])
Exemple #11
0
def main():
    QApplication.setGraphicsSystem("raster")
    app = QApplication(sys.argv)  # Early so that QT is initialized before other imports

    splash = QSplashScreen(resourceImage("newsplash"), Qt.WindowStaysOnTopHint)
    splash.show()
    splash.showMessage("Starting up...", Qt.AlignLeft, Qt.white)
    app.processEvents()

    HelpDock.setHelpLinkPrefix(os.getenv("ERT_SHARE_PATH") + "/gui/help/")

    splash.showMessage("Bootstrapping...", Qt.AlignLeft, Qt.white)
    app.processEvents()

    strict = True
    site_config = os.getenv("ERT_SITE_CONFIG")
    if len(sys.argv) == 1:
        print("-----------------------------------------------------------------")
        print("-- You must supply the name of configuration file as the first --")
        print("-- commandline argument:                                       --")
        print("--                                                             --")
        print("-- bash%  gert <config_file>                                   --")
        print("--                                                             --")
        print("-- If the configuration file does not exist, gert will create  --")
        print("-- create a new configuration file.                            --")
        print("-----------------------------------------------------------------")
    else:
        enkf_config = sys.argv[1]
        if not os.path.exists(enkf_config):
            print("Trying to start new config")
            new_configuration_dialog = NewConfigurationDialog(enkf_config)
            success = new_configuration_dialog.exec_()
            if not success:
                print("Can not run without a configuration file.")
                sys.exit(1)
            else:
                enkf_config = new_configuration_dialog.getConfigurationPath()
                firste_case_name = new_configuration_dialog.getCaseName()
                dbase_type = new_configuration_dialog.getDBaseType()
                num_realizations = new_configuration_dialog.getNumberOfRealizations()
                storage_path = new_configuration_dialog.getStoragePath()

                EnKFMain.createNewConfig(enkf_config, storage_path, firste_case_name, dbase_type, num_realizations)
                strict = False

        ert = EnKFMain(enkf_config, site_config=site_config, strict=strict)
        ErtConnector.setErt(ert)

        window = GertMainWindow()
        window.setSaveFunction(ert.saveConfig())

        splash.showMessage("Creating GUI...", Qt.AlignLeft, Qt.white)
        app.processEvents()

        simulation_panel = SimulationPanel()
        window.addTab(simulation_panel.getName(), simulation_panel)
        configuration_panel = ConfigurationPanel()
        window.addTab(configuration_panel.getName(), configuration_panel)

        splash.showMessage("Communicating with ERT...", Qt.AlignLeft, Qt.white)
        app.processEvents()

        window.show()
        splash.finish(window)

        HelpDock.setHelpMessageLink("welcome_to_ert")

        sys.exit(app.exec_())
Exemple #12
0
#!/usr/bin/env python
import sys
import time
from ert.enkf import EnKFMain, RunArg, NodeId
from ert.enkf.data import EnkfNode
from ert.job_queue import JobQueueManager

ert = EnKFMain(sys.argv[1])
fs_manager = ert.getEnkfFsManager()
fs = fs_manager.getCurrentFileSystem()

# Initialize the realisations.
for iens in range(ert.getEnsembleSize()):
    realisation = ert.getRealisation(iens)
    realisation.initialize(fs)

# Fetch out the job_queue from the SiteConfig object. In addition we
# create a JobQueueManager objects which wraps the queue. The purpose
# of this manager object is to let the queue run nonblocking in the
# background.
site_config = ert.siteConfig()
queue_manager = JobQueueManager(site_config.getJobQueue())
queue_manager.startQueue(ert.getEnsembleSize(), verbose=False)

# Create list of RunArg instances which hold metadata for one running
# realisation, create the directory where the simulation should run
# and submit the simulation.
path_fmt = "/tmp/run%d"
arg_list = [
    RunArg.createEnsembleExperimentRunArg(fs, iens, path_fmt % iens)
    for iens in range(ert.getEnsembleSize())
Exemple #13
0
#!/usr/bin/env python
import sys
import time 
from ert.enkf import EnKFMain


# This will instantiate the EnkFMain object and create a handle to
# "everything" ert related for this instance.
ert = EnKFMain( sys.argv[1] )
site_config = ert.siteConfig( )

jobs = site_config.get_installed_jobs( )
for job in jobs:
    print job.name()
    print "   config    : %s" % job.get_config_file()
    print "   executable: %s" % job.get_executable( ) 
    print
Exemple #14
0
 def open(self , config_file):
     self.config_file = config_file
     self.ert_handle = EnKFMain( config_file , ErtServer.site_config )
Exemple #15
0
 def open(self, config_file):
     self.config_file = config_file
     self.ert_handle = EnKFMain(config_file)
     self.logger.info("Have connect ert handle to:%s", config_file)
Exemple #16
0
#!/usr/bin/env python
import sys
import time 
from ert.enkf import EnKFMain
from ert.enkf.enums import ErtImplType


# This will instantiate the EnkFMain object and create a handle to
# "everything" ert related for this instance.
ert = EnKFMain( sys.argv[1] )


# Ask the EnKFMain instance how many realisations it has. Observe that
# the answer to this question is just the value of the
# NUM_REALISATIONS setting in the configuration file.
print("This instance has %d realisations" % ert.getEnsembleSize())


# Get the ensemble configuration object, and ask for all GEN_KW keys:
ens_config = ert.ensembleConfig( )
for key in ens_config.getKeylistFromImplType(ErtImplType.GEN_KW):
    config_node = ens_config[key]

    # "Downcast" to GEN_KW configuration.
    gen_kw_config = config_node.getModelConfig( )
    print("%s : %s" % (key , gen_kw_config.getKeyWords( )))

Exemple #17
0
def main(argv):

    app = QApplication(argv) #Early so that QT is initialized before other imports
    app.setWindowIcon(util.resourceIcon("application/window_icon_cutout"))

    if len(argv) == 1:
        config_file = QFileDialog.getOpenFileName(None, "Open Configuration File")

        config_file = str(config_file)

        if len(config_file) == 0:
            print("-----------------------------------------------------------------")
            print("-- You must supply the name of configuration file as the first --")
            print("-- commandline argument:                                       --")
            print("--                                                             --")
            print("-- bash%  gert <config_file>                                   --")
            print("--                                                             --")
            print("-- If the configuration file does not exist, gert will create  --")
            print("-- create a new configuration file.                            --")
            print("-----------------------------------------------------------------")

            sys.exit(1)
    else:
        config_file = argv[1]

    help_center = HelpCenter("ERT")
    help_center.setHelpLinkPrefix(os.getenv("ERT_SHARE_PATH") + "/gui/help/")
    help_center.setHelpMessageLink("welcome_to_ert")

    strict = True
        
    verbose = False
    verbose_var = os.getenv("ERT_VERBOSE", "False")
    lower_verbose_var = verbose_var.lower() 
    if lower_verbose_var == "true": 
        verbose = True


    if not os.path.exists(config_file):
        print("Trying to start new config")
        new_configuration_dialog = NewConfigurationDialog(config_file)
        success = new_configuration_dialog.exec_()
        if not success:
            print("Can not run without a configuration file.")
            sys.exit(1)
        else:
            config_file = new_configuration_dialog.getConfigurationPath()
            first_case_name = new_configuration_dialog.getCaseName()
            dbase_type = new_configuration_dialog.getDBaseType()
            num_realizations = new_configuration_dialog.getNumberOfRealizations()
            storage_path = new_configuration_dialog.getStoragePath()

            EnKFMain.createNewConfig(config_file, storage_path, first_case_name, dbase_type, num_realizations)
            strict = False


    if os.path.isdir(config_file):
        print("The specified configuration file is a directory!")
        sys.exit(1)


    splash = ErtSplash()
    splash.version = "Version %s" % Version.getVersion()
    splash.timestamp = Version.getBuildTime()

    splash.show()
    splash.repaint()

    now = time.time()


    ert = Ert(EnKFMain(config_file, strict=strict, verbose=verbose))
    ErtConnector.setErt(ert.ert())

    window = GertMainWindow()
    window.setWidget(SimulationPanel())

    plugin_handler = PluginHandler(ert.ert(), ert.ert().getWorkflowList().getPluginJobs(), window)

    help_tool = HelpTool("ERT", window)

    window.addDock("Configuration Summary", SummaryPanel(), area=Qt.BottomDockWidgetArea)
    window.addTool(IdeTool(os.path.basename(config_file), ert.reloadERT, help_tool))
    window.addTool(PlotTool(ert.ert()))
    window.addTool(ExportTool())
    window.addTool(WorkflowsTool())
    window.addTool(ManageCasesTool())
    window.addTool(PluginsTool(plugin_handler))
    window.addTool(LoadResultsTool())
    window.addTool(help_tool)

    sleep_time = 2 - (time.time() - now)

    if sleep_time > 0:
        time.sleep(sleep_time)

    window.show()
    splash.finish(window)
    window.activateWindow()
    window.raise_()
    finished_code = app.exec_()

    ert.ert().free()

    sys.exit(finished_code)
Exemple #18
0
#!/usr/bin/env python
import sys
import time 
from ert.enkf import EnKFMain, RunArg, NodeId
from ert.enkf.data import EnkfNode
from ert.job_queue import JobQueueManager

ert = EnKFMain( sys.argv[1] )
fs_manager = ert.getEnkfFsManager( )
fs = fs_manager.getCurrentFileSystem( )


# Initialize the realisations. 
for iens in range( ert.getEnsembleSize()):
    realisation = ert.getRealisation( iens )
    realisation.initialize( fs )


# Fetch out the job_queue from the SiteConfig object. In addition we
# create a JobQueueManager objects which wraps the queue. The purpose
# of this manager object is to let the queue run nonblocking in the
# background.
site_config = ert.siteConfig( )
queue_manager = JobQueueManager( site_config.getJobQueue( ) )
queue_manager.startQueue( ert.getEnsembleSize( ) , verbose = False )


# Create list of RunArg instances which hold metadata for one running
# realisation, create the directory where the simulation should run
# and submit the simulation.
path_fmt = "/tmp/run%d"
Exemple #19
0
 def open(self , config_file):
     self.config_file = config_file
     self.ert_handle = EnKFMain( config_file )
     self.logger.info("Have connect ert handle to:%s" , config_file)
Exemple #20
0
def main(argv):
    app = QApplication(argv) #Early so that QT is initialized before other imports
    app.setWindowIcon(util.resourceIcon("application/window_icon_cutout"))

    splash = ErtSplash()
    splash.version = "Version %s" % Version.getVersion()
    splash.timestamp = Version.getBuildTime()

    splash.show()
    splash.repaint()
    
    now = time.time()

    help_center = HelpCenter("ERT")
    help_center.setHelpLinkPrefix(os.getenv("ERT_SHARE_PATH") + "/gui/help/")
    help_center.setHelpMessageLink("welcome_to_ert")

    strict = True
    site_config = os.getenv("ERT_SITE_CONFIG")
    if len(argv) == 1:
        print("-----------------------------------------------------------------")
        print("-- You must supply the name of configuration file as the first --")
        print("-- commandline argument:                                       --")
        print("--                                                             --")
        print("-- bash%  gert <config_file>                                   --")
        print("--                                                             --")
        print("-- If the configuration file does not exist, gert will create  --")
        print("-- create a new configuration file.                            --")
        print("-----------------------------------------------------------------")
    else:
        enkf_config = argv[1]
        if not os.path.exists(enkf_config):
            print("Trying to start new config")
            new_configuration_dialog = NewConfigurationDialog(enkf_config)
            success = new_configuration_dialog.exec_()
            if not success:
                print("Can not run without a configuration file.")
                sys.exit(1)
            else:
                enkf_config = new_configuration_dialog.getConfigurationPath()
                first_case_name = new_configuration_dialog.getCaseName()
                dbase_type = new_configuration_dialog.getDBaseType()
                num_realizations = new_configuration_dialog.getNumberOfRealizations()
                storage_path = new_configuration_dialog.getStoragePath()

                EnKFMain.createNewConfig(enkf_config, storage_path, first_case_name, dbase_type, num_realizations)
                strict = False

        ert = Ert(EnKFMain(enkf_config, site_config=site_config, strict=strict))
        ErtConnector.setErt(ert.ert())

        window = GertMainWindow()
        window.setWidget(SimulationPanel())

        help_tool = HelpTool("ERT", window)

        window.addDock("Configuration Summary", SummaryPanel(), area=Qt.BottomDockWidgetArea)
        window.addTool(IdeTool(os.path.basename(enkf_config), ert.reloadERT, help_tool))
        window.addTool(PlotTool())
        window.addTool(ExportTool())
        window.addTool(WorkflowsTool(ert.reloadERT))
        window.addTool(ManageCasesTool())
        window.addTool(LoadResultsTool())
        window.addTool(help_tool)

        sleep_time = 2 - (time.time() - now)

        if sleep_time > 0:
            time.sleep(sleep_time)

        window.show()
        splash.finish(window)
        window.activateWindow()
        window.raise_()
        finished_code = app.exec_()

        ert.ert().free()

        sys.exit(finished_code)