Repository: DataBiosphere/toil

Issue:
Memory Limit value Zero
https://github.com/DataBiosphere/toil/blob/f159848b4e0c06dc27cccd6c3389dd6efbbad750/src/toil/batchSystems/lsf.py#L252

```
Traceback (most recent call last):
  File "/nfs/production/panda/ensembl/thiagogenez/usr/linuxbrew/Cellar/cactus/HEAD-71f6430/libexec/lib/python3.9/site-packages/toil/batchSystems/abstractGridEngineBatchSystem.py", line 222, in run
    while self._runStep():
  File "/nfs/production/panda/ensembl/thiagogenez/usr/linuxbrew/Cellar/cactus/HEAD-71f6430/libexec/lib/python3.9/site-packages/toil/batchSystems/abstractGridEngineBatchSystem.py", line 211, in _runStep
    activity |= self.createJobs(newJob)
  File "/nfs/production/panda/ensembl/thiagogenez/usr/linuxbrew/Cellar/cactus/HEAD-71f6430/libexec/lib/python3.9/site-packages/toil/batchSystems/abstractGridEngineBatchSystem.py", line 115, in createJobs
    batchJobID = self.boss.with_retries(self.submitJob, subLine)
  File "/nfs/production/panda/ensembl/thiagogenez/usr/linuxbrew/Cellar/cactus/HEAD-71f6430/libexec/lib/python3.9/site-packages/toil/batchSystems/abstractGridEngineBatchSystem.py", line 448, in with_retries
    raise err
  File "/nfs/production/panda/ensembl/thiagogenez/usr/linuxbrew/Cellar/cactus/HEAD-71f6430/libexec/lib/python3.9/site-packages/toil/batchSystems/abstractGridEngineBatchSystem.py", line 439, in with_retries
    return operation(*args, **kwargs)
  File "/nfs/production/panda/ensembl/thiagogenez/usr/linuxbrew/Cellar/cactus/HEAD-71f6430/libexec/lib/python3.9/site-packages/toil/batchSystems/lsf.py", line 90, in submitJob
    stdout = call_command(subLine, env=combinedEnv)
  File "/nfs/production/panda/ensembl/thiagogenez/usr/linuxbrew/Cellar/cactus/HEAD-71f6430/libexec/lib/python3.9/site-packages/toil/lib/misc.py", line 226, in call_command
    raise CalledProcessErrorStderr(proc.returncode, cmd, output=stdout, stderr=stderr)
toil.lib.misc.CalledProcessErrorStderr: Command '['bsub', '-cwd', '.', '-J', 'toil_job_0', '-R', 'select[mem > 0] rusage[mem=0]', '-M', '0', '-n', '1', '-o', '/scratch/toil_workflow_bca7db08-c60c-4d2c-ab39-4c4943bce9a0_job_0_batch_lsf_%J_std_output.log', '-e', '/scratch/toil_workflow_bca7db08-c60c-4d2c-ab39-4c4943bce9a0_job_0_batch_lsf_%J_std_error.log', '_toil_worker RunSelfBlast file:/hps/nobackup2/production/ensembl/thiagogenez/mohab/cactus/jobStore kind-RunSelfBlast/instance-52384sl0 --context gASVtAAAAAAAAACMJXRvaWwuYmF0Y2hTeXN0ZW1zLmFic3RyYWN0QmF0Y2hTeXN0ZW2UjBRXb3JrZXJDbGVhbnVwQ29udGV4dJSTlCmBlH2UKIwRd29ya2VyQ2xlYW51cEluZm+UaACMEVdvcmtlckNsZWFudXBJbmZvlJOUTowkYmNhN2RiMDgtYzYwYy00ZDJjLWFiMzktNGM0OTQzYmNlOWEwlIwGYWx3YXlzlIeUgZSMBWFyZW5hlE51Yi4=']' exit status 255: MEMLIMIT value <0> is not valid. Limit must be a positive integer. You can use the following units for the limit: KB (or K), MB (or M), GB (or G), TB (or T), PB (or P), EB (or E), ZB (or Z). Job not submitted.

```
Problem:
```
>>> mem = 104857600
>>> mem
104857600
>>> mem = float(mem) // 1024**3
>>> mem
0.0
```

Suggestion for fix would be:
```
            bsubMem = []
            if mem:
                if per_core_reservation():
                    mem = float(mem)/1024**3/math.ceil(cpu)
                    mem_resource = parse_memory_resource(mem)
                    mem_limit = parse_memory_limit(mem)
                else:
                    mem = float(mem) // 1024**3
                    logger.info("INFO Transformation: {}".format(mem))
                    mem_resource = parse_memory_resource(mem)
                    mem_limit = parse_memory_limit(mem)

                if mem > 0:
                  bsubMem = ['-R', 'select[mem > {m}] '
                           'rusage[mem={m}]'.format(m=mem_resource),
                           '-M', str(mem_limit)]
```

Will do a pull request for this issue.

┆Issue is synchronized with this [Jira Task](https://ucsc-cgl.atlassian.net/browse/TOIL-761)
┆Issue Number: TOIL-761



Discussion:
@thiagogenez Sorry, this one is my fault!
@mr-c  No worries. Glad to help!  
May I leave this issue with you? (I will not pull a request then.)
If you have a tested fix, it would be better coming from you! I'm guessing
the double division operator is to blame here.

>

Okay - Will do a bit of more tests and pull a request. 

Resolving patch:
diff --git a/src/toil/batchSystems/lsf.py b/src/toil/batchSystems/lsf.py
--- a/src/toil/batchSystems/lsf.py
+++ b/src/toil/batchSystems/lsf.py
@@ -249,7 +249,7 @@ def prepareBsub(self, cpu, mem, jobID):
                     mem_resource = parse_memory_resource(mem)
                     mem_limit = parse_memory_limit(mem)
                 else:
-                    mem = float(mem) // 1024**3
+                    mem = float(mem) / 1024**3
                     mem_resource = parse_memory_resource(mem)
                     mem_limit = parse_memory_limit(mem)
 


Test patch: