def rm_env(env_name): """Alias for remove_env """ if env_exists(env_name): logger.info("Removing environment: {0}". format(env_name)) remove_env(env_name)
def test_model(model_name, source_name, env_name, batch_size, vep=False): """kipoi test ... Args: model_name (str) source_name: source name """ if env_exists(env_name): logger.info("Environment {0} exists. Removing it.".format(env_name)) remove_env(env_name) # TODO - if the model is a Keras model, print the Keras config file # and note which config file got used # create the model test environment cmd = "kipoi" args = ["env", "create", "--source", source_name, "--env", env_name, model_name] if vep: # Add --vep to environment installation args.insert(-1, "--vep") returncode = _call_command(cmd, args, use_stdout=True) assert returncode == 0 # run the tests in the environment cmd = get_kipoi_bin(env_name) args = ["test", "--batch_size", str(batch_size), "--source", source_name, model_name] # New, modified path for conda. Source activate namely does the following: # - CONDA_DEFAULT_ENV=${env_name} # - CONDA_PREFIX=${env_path} # - PATH=$conda_bin:$PATH new_env = os.environ.copy() new_env['PATH'] = os.path.dirname(cmd) + os.pathsep + new_env['PATH'] returncode, logs = _call_command(cmd, args, use_stdout=True, return_logs_with_stdout=True, env=new_env ) assert returncode == 0 # detect WARNING in the output log warn = 0 for line in logs: warn_start = escape_codes[default_log_colors['WARNING']] + \ 'WARNING' + escape_codes['reset'] if line.startswith(warn_start): logger.error("Warning present: {0}".format(line)) warn += 1 if warn > 0: raise ValueError("{0} warnings were observed for model {1}". format(warn, model_name))
def rm_env(env_name): """Alias for remove_env """ from kipoi.conda.env_db import get_model_env_db if env_exists(env_name): logger.info("Removing environment: {0}".format(env_name)) remove_env(env_name) # remove from db db = get_model_env_db() db_entries = [e for e in db.get_all() if e.create_args.env == env_name] [db.remove(e) for e in db_entries] db.save()
def test_model(model_name, source_name, env_name, batch_size): """kipoi test ... Args: model_name (str) source_name: source name """ if env_exists(env_name): logger.info("Environment {0} exists. Removing it.".format(env_name)) remove_env(env_name) # TODO - if the model is a Keras model, print the Keras config file # and note which config file got used # create the model test environment cmd = "kipoi" args = ["env", "create", "--source", source_name, "--env", env_name, model_name] returncode = _call_command(cmd, args, use_stdout=True) assert returncode == 0 # run the tests in the environment cmd = get_kipoi_bin(env_name) args = ["test", "--batch_size", str(batch_size), "--source", source_name, model_name] returncode, logs = _call_command(cmd, args, use_stdout=True, return_logs_with_stdout=True) assert returncode == 0 # detect WARNING in the output log warn = 0 for line in logs: warn_start = escape_codes[default_log_colors['WARNING']] + \ 'WARNING' + escape_codes['reset'] if line.startswith(warn_start): logger.error("Warning present: {0}".format(line)) warn += 1 if warn > 0: raise ValueError("{0} warnings were observed for model {1}". format(warn, model_name))
def test_model(model_name, caplog): """kipoi test ... """ caplog.set_level(logging.INFO) source_name = "kipoi" assert source_name == "kipoi" env_name = conda_env_name(model_name, model_name, source_name) env_name = "test-" + env_name # prepend "test-" # if environment already exists, remove it if env_exists(env_name): print("Removing the environment: {0}".format(env_name)) remove_env(env_name) # create the model test environment args = ["kipoi", "env", "create", "--source", source_name, "--env", env_name, model_name] returncode = subprocess.call(args=args) assert returncode == 0 if model_name == "basenji": batch_size = str(2) else: batch_size = str(4) # run the tests in the environment args = [get_kipoi_bin(env_name), "test", "--batch_size", batch_size, "--source", source_name, model_name] returncode = subprocess.call(args=args) assert returncode == 0 for record in caplog.records: # there shoudn't be any warning assert record.levelname not in ['WARN', 'WARNING', 'ERROR', 'CRITICAL']
def create_model_env(model_name, source_name, env_name, vep=False): """kipoi test ... Args: model_name (str) source_name: source name """ if env_exists(env_name): logger.info("Environment {0} exists. Removing it.".format(env_name)) remove_env(env_name) # TODO - if the model is a Keras model, print the Keras config file # and note which config file got used # create the model test environment cmd = "kipoi" args = [ "env", "create", "--source", source_name, "--env", env_name, model_name ] if vep: # Add --vep to environment installation args.insert(-1, "--vep") returncode = _call_command(cmd, args, use_stdout=True) assert returncode == 0