Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #277 from pgdr/expose-lsf-resources-and-server
Browse files Browse the repository at this point in the history
Expose LSF_RESOURCES and LSF_SERVER in keys
  • Loading branch information
joakim-hove authored Apr 11, 2018
2 parents ef82706 + cebff63 commit 6f5043e
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 79 deletions.
12 changes: 12 additions & 0 deletions lib/enkf/config_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ const char * config_keys_get_queue_option_key() {
return QUEUE_OPTION_KEY;
}

const char * config_keys_get_lsf_resources_key() {
return LSF_RESOURCES_KEY;
}

const char * config_keys_get_lsf_server_key() {
return LSF_SERVER_KEY;
}

const char * config_keys_get_lsf_queue_key() {
return LSF_QUEUE_KEY;
}

const char * config_keys_get_install_job_key() {
return INSTALL_JOB_KEY;
}
Expand Down
36 changes: 18 additions & 18 deletions lib/enkf/queue_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ queue_config_type * queue_config_alloc_local_copy( queue_config_type * queue_con
queue_config_copy->driver_type = NULL_DRIVER;
else
queue_config_copy->driver_type = LOCAL_DRIVER;

queue_config_copy->max_submit = queue_config->max_submit;

return queue_config_copy;
Expand All @@ -130,12 +130,11 @@ queue_config_type * queue_config_alloc_local_copy( queue_config_type * queue_con
*/
job_queue_type * queue_config_alloc_job_queue(const queue_config_type * queue_config) {
job_queue_type * job_queue = job_queue_alloc(DEFAULT_MAX_SUBMIT, "OK", "status.json", "ERROR");
const char * driver_name = queue_config_get_queue_name(queue_config);
if (driver_name != NULL)
{
queue_driver_type * driver = queue_config_get_queue_driver(queue_config, driver_name);
job_queue_set_driver(job_queue, driver);
}
const char * driver_name = queue_config_get_queue_system(queue_config);
if (driver_name != NULL) {
queue_driver_type * driver = queue_config_get_queue_driver(queue_config, driver_name);
job_queue_set_driver(job_queue, driver);
}

job_queue_set_max_submit(job_queue, queue_config->max_submit);

Expand All @@ -148,7 +147,7 @@ void queue_config_free(queue_config_type * queue_config) {
free(queue_config);
}

const char * queue_config_get_queue_name(const queue_config_type * queue_config) {
const char * queue_config_get_queue_system(const queue_config_type * queue_config) {
switch(queue_config->driver_type) {
case LSF_DRIVER:
return LSF_DRIVER_NAME;
Expand Down Expand Up @@ -181,16 +180,13 @@ bool queue_config_has_job_script( const queue_config_type * queue_config ) {
return false;
}


bool queue_config_set_job_script(queue_config_type * queue_config, const char * job_script) {
if (util_is_executable(job_script)) {
char * job_script_full_path = util_alloc_realpath(job_script);
queue_config->job_script = util_realloc_string_copy(queue_config->job_script, job_script_full_path);
free(job_script_full_path);
return true;
}
else
if (!util_is_executable(job_script))
return false;
char * job_script_full_path = util_alloc_realpath(job_script);
queue_config->job_script = util_realloc_string_copy(queue_config->job_script, job_script_full_path);
free(job_script_full_path);
return true;
}


Expand Down Expand Up @@ -225,7 +221,11 @@ queue_driver_type * queue_config_get_queue_driver(const queue_config_type * queu


void queue_config_create_queue_drivers(queue_config_type * queue_config) {
queue_config_add_queue_driver(queue_config, LSF_DRIVER_NAME, queue_driver_alloc_LSF(NULL, NULL, NULL));
queue_config_add_queue_driver(queue_config,
LSF_DRIVER_NAME,
queue_driver_alloc_LSF(NULL,
NULL,
NULL));
queue_config_add_queue_driver(queue_config, TORQUE_DRIVER_NAME, queue_driver_alloc_TORQUE());
queue_config_add_queue_driver(queue_config, RSH_DRIVER_NAME, queue_driver_alloc_RSH(NULL, NULL));
queue_config_add_queue_driver(queue_config, LOCAL_DRIVER_NAME, queue_driver_alloc_local());
Expand Down Expand Up @@ -297,7 +297,7 @@ job_driver_type queue_config_get_driver_type(const queue_config_type * queue_con
}

void queue_config_add_queue_config_items(config_parser_type * parser, bool site_mode) {

}


Expand Down
5 changes: 3 additions & 2 deletions lib/enkf/site_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ void site_config_set_lsf_server(site_config_type * site_config, const char * lsf
queue_driver_set_option(lsf_driver, LSF_SERVER, lsf_server);
}

// TODO LSF resources requirement or lsf_request?
void site_config_set_lsf_request(site_config_type * site_config, const char * lsf_request) {
queue_driver_type * lsf_driver = site_config_get_queue_driver(site_config, LSF_DRIVER_NAME);
queue_driver_set_option(lsf_driver, LSF_RESOURCE, lsf_request);
Expand All @@ -477,8 +478,8 @@ const char * site_config_get_lsf_request(const site_config_type * site_config) {
/*****************************************************************/


const char * site_config_get_queue_name(const site_config_type * site_config) {
return queue_config_get_queue_name(site_config->queue_config); //based on driver_type
const char * site_config_get_queue_system(const site_config_type * site_config) {
return queue_config_get_queue_system(site_config->queue_config); //based on driver_type
}


Expand Down
2 changes: 1 addition & 1 deletion lib/enkf/tests/enkf_queue_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void test_parse() {
}

test_assert_true(queue_config_has_job_script(queue_config));
test_assert_string_equal(queue_config_get_queue_name(queue_config), LSF_DRIVER_NAME);
test_assert_string_equal(queue_config_get_queue_system(queue_config), LSF_DRIVER_NAME);

//test for licence path
job_queue_type * job_queue = queue_config_alloc_job_queue(queue_config);
Expand Down
4 changes: 2 additions & 2 deletions lib/include/ert/enkf/config_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ extern "C" {
#define LOCAL_CONFIG_KEY "LOCAL_CONFIG"
#define LOG_FILE_KEY "LOG_FILE"
#define LOG_LEVEL_KEY "LOG_LEVEL"
#define LSF_QUEUE_KEY "LSF_QUEUE"
#define LSF_RESOURCES_KEY "LSF_RESOURCES"
#define LSF_QUEUE_KEY "LSF_QUEUE" // The queue name, e.g. "mr"
#define LSF_RESOURCES_KEY "LSF_RESOURCE" // LSF resource requirements
#define LSF_SERVER_KEY "LSF_SERVER"
#define TORQUE_QUEUE_KEY "TORQUE_QUEUE"
#define MAX_RESAMPLE_KEY "MAX_RESAMPLE"
Expand Down
21 changes: 15 additions & 6 deletions lib/include/ert/enkf/queue_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,26 @@ typedef struct queue_config_struct queue_config_type;

int queue_config_get_max_submit(queue_config_type * queue_config);
bool queue_config_has_job_script( const queue_config_type * queue_config );
const char * queue_config_get_job_script(const queue_config_type * queue_config);
bool queue_config_set_job_script(queue_config_type * queue_config, const char * job_script);
const char * queue_config_get_job_script(const queue_config_type * queue_config);

job_driver_type queue_config_get_driver_type(const queue_config_type * queue_config);

queue_driver_type * queue_config_get_queue_driver(const queue_config_type * queue_config, const char * driver_name);
bool queue_config_has_queue_driver(const queue_config_type * queue_config, const char * driver_name);
queue_driver_type * queue_config_get_queue_driver(const queue_config_type * queue_config,
const char * driver_name);
bool queue_config_has_queue_driver(const queue_config_type * queue_config,
const char * driver_name);
void queue_config_create_queue_drivers(queue_config_type * queue_config);
const char * queue_config_get_queue_name(const queue_config_type * queue_config);
const char * queue_config_get_job_script(const queue_config_type * queue_config);

/**
* Queue system is typically one of LSF, LOCAL, TORQUE, RHS, ... Given a
* queue system, you can obtain the _driver_ (e.g. lsf_driver).
*
* Should not be confused with queue_name, which is typically just a
* parameter we can send to the LSF cluster to get a certain queue,
* e.g. "mr".
*/
const char * queue_config_get_queue_system(const queue_config_type * queue_config);

void queue_config_add_config_items(config_parser_type * parser, bool site_mode);

Expand All @@ -67,4 +77,3 @@ UTIL_IS_INSTANCE_HEADER(queue_config);
}
#endif
#endif

10 changes: 6 additions & 4 deletions lib/job_queue/queue_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,14 @@ void queue_driver_init_option_list(queue_driver_type * driver, stringlist_type *
}


queue_driver_type * queue_driver_alloc_LSF(const char * queue_name, const char * resource_request, const char * remote_lsf_server) {
queue_driver_type * queue_driver_alloc_LSF(const char * queue_name,
const char * lsf_resource,
const char * lsf_server) {
queue_driver_type * driver = queue_driver_alloc(LSF_DRIVER);

queue_driver_set_option(driver, LSF_QUEUE, queue_name);
queue_driver_set_option(driver, LSF_RESOURCE, resource_request);
queue_driver_set_option(driver, LSF_SERVER, remote_lsf_server);
queue_driver_set_option(driver, LSF_QUEUE, queue_name);
queue_driver_set_option(driver, LSF_RESOURCE, lsf_resource);
queue_driver_set_option(driver, LSF_SERVER, lsf_server);

return driver;
}
Expand Down
7 changes: 7 additions & 0 deletions python/res/enkf/config_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class ConfigKeys:
_simulation_job_key = ResPrototype("char* config_keys_get_simulation_job_key()", bind=False)
_log_file_key = ResPrototype("char* config_keys_get_log_file_key()", bind=False)
_log_level_key = ResPrototype("char* config_keys_get_log_level_key()", bind=False)
_lsf_resources_key = ResPrototype("char* config_keys_get_lsf_resources_key()", bind=False)
_lsf_server_key = ResPrototype("char* config_keys_get_lsf_server_key()", bind=False)
_lsf_queue_key = ResPrototype("char* config_keys_get_lsf_queue_key()", bind=False)
_update_log_path = ResPrototype("char* config_keys_get_update_log_path_key()", bind=False)
_store_seed = ResPrototype("char* config_keys_get_store_seed_key()", bind=False)
_load_seed = ResPrototype("char* config_keys_get_load_seed_key()", bind=False)
Expand Down Expand Up @@ -85,6 +88,10 @@ class ConfigKeys:
SIMULATION_JOB = _simulation_job_key()
LOG_FILE = _log_file_key()
LOG_LEVEL = _log_level_key()
LSF_RESOURCE_KEY = _lsf_resources_key()
LSF_QUEUE_NAME_KEY = _lsf_queue_key()
LSF_SERVER_KEY = _lsf_server_key()
LSF_KEY = 'LSF'
UPDATE_LOG_PATH = _update_log_path()
STORE_SEED = _store_seed()
LOAD_SEED = _load_seed()
Expand Down
37 changes: 33 additions & 4 deletions python/res/enkf/queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ecl.util.util import StringList, Hash

from res import ResPrototype
from res.enkf import ConfigKeys
from res.job_queue import JobQueue, ExtJoblist, Driver

class QueueConfig(BaseCClass):
Expand All @@ -32,7 +33,7 @@ class QueueConfig(BaseCClass):
_has_job_script = ResPrototype("bool queue_config_has_job_script( queue_config )")
_get_job_script = ResPrototype("char* queue_config_get_job_script(queue_config)")
_max_submit = ResPrototype("int queue_config_get_max_submit(queue_config)")
_queue_name = ResPrototype("char* queue_config_get_queue_name(queue_config)")
_queue_system = ResPrototype("char* queue_config_get_queue_system(queue_config)")
_queue_driver = ResPrototype("driver_ref queue_config_get_queue_driver(queue_config, char*)")

def __init__(self, user_config_file=None):
Expand All @@ -57,12 +58,40 @@ def max_submit(self):

@property
def queue_name(self):
return self._queue_name()
return self.driver.get_option(ConfigKeys.LSF_QUEUE_NAME_KEY)

@property
def driver(self):
return self._queue_driver(self.queue_name).setParent(self)
def queue_system(self):
"""The queue system in use, e.g. LSF or LOCAL"""
return self._queue_system()

@property
def job_script(self):
return self._get_job_script()

@property
def driver(self):
return self._queue_driver(self.queue_system).setParent(self)

def _assert_lsf(self, key='driver'):
sys = self.queue_system
if sys != ConfigKeys.LSF_KEY:
fmt = 'Cannot fetch LSF {key}, current queue is {system}'
raise ValueError(fmt.format(key=key,
system=self.queue_system))

@property
def _lsf_driver(self):
self._assert_lsf()
driver = self._queue_driver(ConfigKeys.LSF_KEY)
return driver.setParent(self)

@property
def lsf_resource(self):
self._assert_lsf(key=ConfigKeys.LSF_RESOURCE_KEY)
return self._lsf_driver.get_option(ConfigKeys.LSF_RESOURCE_KEY)

@property
def lsf_server(self):
self._assert_lsf(key=ConfigKeys.LSF_SERVER_KEY)
return self._lsf_driver.get_option(ConfigKeys.LSF_SERVER_KEY)
29 changes: 27 additions & 2 deletions python/tests/res/enkf/test_programmatic_res_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,22 @@ def setUp(self):
"DRIVER_NAME" : "LSF",
"OPTION" : "MAX_RUNNING",
"VALUE" : 100
}
},
{
"DRIVER_NAME" : "LSF",
"OPTION" : "LSF_RESOURCE",
"VALUE" : "select[x86_64Linux] same[type:model]",
},
{
"DRIVER_NAME" : "LSF",
"OPTION" : "LSF_SERVER",
"VALUE" : "simulacrum",
},
{
"DRIVER_NAME" : "LSF",
"OPTION" : "LSF_QUEUE",
"VALUE" : "mr",
},
]
},

Expand Down Expand Up @@ -392,9 +407,16 @@ def assert_equal_site_config(self, loaded_site_config, prog_site_config):
self.assertEqual(loaded_site_config.queue_config.max_submit,
prog_site_config.queue_config.max_submit)

self.assertEqual(loaded_site_config.queue_config.lsf_resource,
prog_site_config.queue_config.lsf_resource)

self.assertEqual(loaded_site_config.queue_config.lsf_server,
prog_site_config.queue_config.lsf_server)

self.assertEqual(loaded_site_config.umask,
prog_site_config.umask)


self.assertEqual(loaded_site_config.queue_config.driver.get_option("MAX_RUNNING"),
prog_site_config.queue_config.driver.get_option("MAX_RUNNING"))

Expand Down Expand Up @@ -494,6 +516,10 @@ def assert_equal_plot_config(self, loaded_plot_config, prog_plot_config):
self.assertEqual(loaded_plot_config.getPath(),
prog_plot_config.getPath())

def assert_equal_simulation_config(self, loaded_simulation_config, prog_simulation_config):
self.assertEqual(loaded_simulation_config.getPath(),
prog_simulation_config.getPath())

def test_new_config(self):
case_directory = self.createTestPath("local/simulation_model")
config_file = "simulation_model/sim_kw.ert"
Expand All @@ -518,7 +544,6 @@ def test_large_config(self):
work_area.copy_directory(case_directory)

loaded_res_config = ResConfig(user_config_file=config_file)

prog_res_config = ResConfig(config=self.large_config)

self.assert_equal_model_config(loaded_res_config.model_config,
Expand Down
Loading

0 comments on commit 6f5043e

Please sign in to comment.