def test_ecl_defaults_methods(self): try: import ert.ecl.ecl_local as ecl_local self.assertEqual(EclDefault.ecl_cmd(), ecl_local.ecl_cmd) self.assertEqual(EclDefault.ecl_version(), ecl_local.ecl_version) self.assertEqual(EclDefault.lsf_resource_request(), ecl_local.lsf_resource_request) self.assertEqual(EclDefault.driver_type(), ecl_local.driver_type) self.assertEqual(EclDefault.driver_options(), ecl_local.driver_options) except ImportError: self.fail("Unable to import ecl_local.py")
def test_ecl_defaults_methods(self): if (has_ecl_local()): try: import ert.ecl.ecl_local as ecl_local if hasattr(ecl_local, 'ecl_cmd'): self.assertEqual(EclDefault.ecl_cmd(), ecl_local.ecl_cmd) else: with self.assertRaises(NotImplementedError): EclDefault.ecl_cmd() if hasattr(ecl_local, 'ecl_version'): self.assertEqual(EclDefault.ecl_version(), ecl_local.ecl_version) else: with self.assertRaises(NotImplementedError): EclDefault.ecl_version() if hasattr(ecl_local, 'lsf_resource_request'): self.assertEqual(EclDefault.lsf_resource_request(), ecl_local.lsf_resource_request) else: with self.assertRaises(NotImplementedError): EclDefault.lsf_resource_request() if hasattr(ecl_local, 'driver_type'): self.assertEqual(EclDefault.driver_type(), ecl_local.driver_type) else: with self.assertRaises(NotImplementedError): EclDefault.driver_type() if hasattr(ecl_local, 'driver_options'): self.assertEqual(EclDefault.driver_options(), ecl_local.driver_options) else: with self.assertRaises(NotImplementedError): EclDefault.driver_options() except ImportError: self.fail("Unable to import ecl_local.py") else: with self.assertRaises(NotImplementedError): EclDefault.ecl_cmd() EclDefault.ecl_version() EclDefault.lsf_resource_request() EclDefault.driver_type() EclDefault.driver_options()
def run(self, ecl_cmd=None, ecl_version=None, driver=None, driver_type=None, driver_options=None, blocking=False): """ Will start an ECLIPSE simulation of the current case. The method has a long and nasty argument list, but all arguments have sensible defaults, and you probably do not need to enter any at all. The arguments are as follows: ecl_cmd: The command used to run ECLIPSE. This will typically be a script of some kind. The command will be called with three commandline arguments: version datafile num_cpu ecl_version: The eclipse version you want to use, this should be a string of the type "2010.2". driver: This should be an instance of Driver() from ert.job_queue.driver. If driver is None the method will create a new driver instance. driver_type: If the driver is none the method will create a new driver instance, it will create a driver of this type (i.e. LOCAL, LSF or RSH). driver_options: When creating a new driver, these options will be used. blocking: If blocking is True the method will not return before the simulation is complete, otherwise the method will return immediately. If blocking is False the ECLIPSE simulation will continue even if the python script exits. Observe that there are some dependencies between the arguments: * If both driver and driver_type are present the existing driver instance will be used, and the driver_type argument will be ignored. * The driver_options argument will only be used when creating a new driver instance, and will not be used to modify an existing driver instance. This method will immediately start/submit an ECLIPSE simulation of the current case. If you have many simulations you might want use an EclQueue() and the submit() method instead, in particular if you are running locally. """ import ert.job_queue.driver as queue_driver num_cpu = EclUtil.get_num_cpu(self.datafile) argv = [ecl_version, self.datafile, num_cpu] if ecl_cmd is None: ecl_cmd = EclDefault.ecl_cmd() if driver_type is None: driver_type = EclDefault.driver_type() if ecl_version is None: ecl_version = EclDefault.ecl_version() if driver is None: if driver_options is None: driver_options = EclDefault.driver_options()[driver_type] driver = queue_driver.Driver(driver_type, max_running=0, options=driver_options) job = driver.submit(self.base, ecl_cmd, self.path, argv, blocking=blocking) return job
def run( self , ecl_cmd = None, ecl_version = None, driver = None , driver_type = None, driver_options = None, blocking = False ): """ Will start an ECLIPSE simulation of the current case. The method has a long and nasty argument list, but all arguments have sensible defaults, and you probably do not need to enter any at all. The arguments are as follows: ecl_cmd: The command used to run ECLIPSE. This will typically be a script of some kind. The command will be called with three commandline arguments: version datafile num_cpu ecl_version: The eclipse version you want to use, this should be a string of the type "2010.2". driver: This should be an instance of Driver() from ert.job_queue.driver. If driver is None the method will create a new driver instance. driver_type: If the driver is none the method will create a new driver instance, it will create a driver of this type (i.e. LOCAL, LSF or RSH). driver_options: When creating a new driver, these options will be used. blocking: If blocking is True the method will not return before the simulation is complete, otherwise the method will return immediately. If blocking is False the ECLIPSE simulation will continue even if the python script exits. Observe that there are some dependencies between the arguments: * If both driver and driver_type are present the existing driver instance will be used, and the driver_type argument will be ignored. * The driver_options argument will only be used when creating a new driver instance, and will not be used to modify an existing driver instance. This method will immediately start/submit an ECLIPSE simulation of the current case. If you have many simulations you might want use an EclQueue() and the submit() method instead, in particular if you are running locally. """ import ert.job_queue.driver as queue_driver num_cpu = EclUtil.get_num_cpu( self.datafile ) argv = [ecl_version , self.datafile , num_cpu] if ecl_cmd is None: ecl_cmd = EclDefault.ecl_cmd() if driver_type is None: driver_type = EclDefault.driver_type() if ecl_version is None: ecl_version = EclDefault.ecl_version() if driver is None: if driver_options is None: driver_options = EclDefault.driver_options()[ driver_type ] driver = queue_driver.Driver( driver_type , max_running = 0 , options = driver_options ) job = driver.submit( self.base , ecl_cmd , self.path , argv , blocking = blocking) return job
def __init__(self, driver=None, driver_type=None, driver_options=None, ecl_version=None, ecl_cmd=None, max_running=0, size=0): """ Create a new queue instance to manage ECLIPSE simulations. The constructor will create a new EclQueue instance which can be used to manage ECLIPSE simulations. All the ECLIPSE simulations managed by this queue instance will be 'of the same type', i.e. they will run the same ECLIPSE version using the same command to run ECLIPSE. The queue starts running (i.e. managing jobs) as soon as it is created. Subsequently the user must add jobs to run using the submit() method, or alternatively the submit() method of an EclCase instance. The queue will run in a separate thread, and there is nothing preventing your script from finishing (i.e. exit) even though the queue thread is still running; in that case the jobs which are still waiting in the queue will not be started[1]. To protect against this premature exit you must use on of the methods: - queue.block_waiting() - queue.block() - while queue.running: ..... All simulations which have been started by the queue instance will continue running even if the queue itself goes out of scope and the script exits. There are many arguments to the constructor, all of them are optional with sensible default values. There are essentially three groups of arguments: Driver related arguments ------------------------ driver: This should be an instance of Driver (or one of the descendants LSFDriver, LocalDriver, or ...) from the ert.job_queue.driver module. If the driver is None the queue will instanstiate a driver itself. driver_type: If the driver is None the queue needs to instantiate a private driver. It will then instantiate a driver of the type given by driver_type. driver_options: If the queue needs to instantiate a private driver it will pass the options given by the driver_options argument to the driver constructor. There is some dependance between the driver related arguments; if a @driver argument is passed the @driver_type and @driver_options arguments are not considered. ECLIPSE related arguments ------------------------- ecl_version: The ECLIPSE version used when simulating. This should be a string of the type "2009.1". ecl_cmd: The path to the executable used to invoke ECLIPSE. The executable will be invoked with commandline arguments: version data_file num_cpu And this executable is responsible for then starting the real ECLIPSE binary. Other arguments --------------- max_running: The maximum number of jobs the queue can run concurrently. The default value max_running=0 means that the queue can start an unlimited number of jobs; in the case of e.g. LSF the default value can be sensible, otherwise you should probably set a value. size: This is the total number of simulations we want to run with the queue; this is further documented in the ert.job_queue.queue.JobQueue class. Use example ----------- import ert.ecl.ecl as ecl import ert.job_queue.driver as driver queue = ecl.EclQueue( driver_type = driver.LOCAL , max_running = 4 , size = 100) data_file_fmt = "/path/to/ECLIPSE/sim%d/ECL.DATA" for i in range(100): queue.submit( data_file_fmt % i ) queue.block() [1]: It should be possible with a fork based solution to let the queue stay alive and continue managing jobs even after the main thread has exited - not yet :-( """ if ecl_cmd is None: ecl_cmd = EclDefault.ecl_cmd() if driver_type is None: driver_type = EclDefault.driver_type() if ecl_version is None: ecl_version = EclDefault.ecl_version() self.ecl_version = ecl_version self.ecl_cmd = ecl_cmd if driver is None: if driver_options is None: driver_options = EclDefault.driver_options()[driver_type] driver = Driver(driver_type, max_running=max_running, options=driver_options) super(EclQueue, self).__init__(driver, size=size)