Skip to content

Commit

Permalink
add hpc executor method: check_if_models_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed Feb 11, 2025
1 parent e1a0c54 commit 97e8ef8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils/operandi_utils/hpc/nhr_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def remove_workflow_job_dir(self, workflow_job_id: str):
self.logger.info(f"Command err: {err}")
self.logger.info(f"Command return code: {return_code}")

def check_if_model_exists(self, ocrd_processor: str, model: str) -> bool:
model_path = f"{self.project_root_dir}/ocrd_models/ocrd-resources/{ocrd_processor}/{model}"
command = f"bash -lc 'ls -la {model_path}'"
self.logger.info(f"About to execute a force command: {command}")
output, err, return_code = self.execute_blocking(command)
self.logger.info(f"Command output: {output}")
self.logger.info(f"Command err: {err}")
self.logger.info(f"Command return code: {return_code}")
return not bool(return_code)

def trigger_slurm_job(
self, workflow_job_id: str, nextflow_script_path: Path, input_file_grp: str,
workspace_id: str, mets_basename: str, nf_process_forks: int, ws_pages_amount: int, use_mets_server: bool,
Expand Down
18 changes: 18 additions & 0 deletions tests/tests_utils/test_3_hpc/test_1_nhr_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,21 @@ def test_hpc_connector_executor_cd_dir(hpc_nhr_command_executor):
# The test dir name will be part of the returned error message
assert f'{test_dir_name}' in err[0]
assert output == []


def test_hpc_connector_executor_check_if_models_exists(hpc_nhr_command_executor):
non_existing_models = {
"ocrd-calamari-recognize": "non-existing-model",
"non-existing-processor": "qurator-gt4histocr-1.0",
}
existing_models = {
"ocrd-calamari-recognize": "qurator-gt4histocr-1.0",
"ocrd-cis-ocropy-recognize": "LatinHist.pyrnn.gz",
"ocrd-kraken-recognize": "typewriter.mlmodel",
"ocrd-tesserocr-recognize": "Fraktur.traineddata"
}

for key, value in existing_models.items():
assert hpc_nhr_command_executor.check_if_model_exists(ocrd_processor=key, model=value)
for key, value in non_existing_models.items():
assert not hpc_nhr_command_executor.check_if_model_exists(ocrd_processor=key, model=value)

0 comments on commit 97e8ef8

Please sign in to comment.