bl1231 / bilbomd-worker

Processes BilboMD jobs and run CHARMM, FoXS, and MultiFoXS
1 stars 0 forks source link

Docker crashes when `rg_min` and `rg_max` only differ by `1` #170

Closed dsclassen closed 10 months ago

dsclassen commented 10 months ago

This is an odd one, and I might not be entirely correct, btu at the moment I think there is a bug in the code that determines how many dynamics_rg##.inp files to make based on the range of rg_max - rg_min.

Here is the logger output from a couple of failed runs:

workerHandler:  {
  type: 'BilboMD',
  title: 'schoccrdtest',
  uuid: 'e8de7abf-f1dc-4d4b-b3de-3399c3105ed3',
  jobid: '65b3010e3eba996889dcd347'
}
Start BilboMD job: schoccrdtest
Write File: /bilbomd/uploads/e8de7abf-f1dc-4d4b-b3de-3399c3105ed3/minimize.inp
CHARMM success: minimize.inp exit code: 0
Write File: /bilbomd/uploads/e8de7abf-f1dc-4d4b-b3de-3399c3105ed3/heat.inp
CHARMM success: heat.inp exit code: 0
Write File: /bilbomd/uploads/e8de7abf-f1dc-4d4b-b3de-3399c3105ed3/dynamics_rg35.inp
Write File: /bilbomd/uploads/e8de7abf-f1dc-4d4b-b3de-3399c3105ed3/dynamics_rg35.inp
Write File: /bilbomd/uploads/e8de7abf-f1dc-4d4b-b3de-3399c3105ed3/dynamics_rg35.inp
Write File: /bilbomd/uploads/e8de7abf-f1dc-4d4b-b3de-3399c3105ed3/dynamics_rg35.inp
CHARMM error: dynamics_rg35.inp exit code: 2
/app/build/bilbomd.functions.js:296
                reject(new Error(charmmOutput));
                       ^

Error
    at ChildProcess.<anonymous> (/app/build/bilbomd.functions.js:296:24)
    at ChildProcess.emit (node:events:517:28)
    at maybeClose (node:internal/child_process:1098:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:517:28)
    at Pipe.<anonymous> (node:net:350:12)

Node.js v18.19.0
 *  Terminal will be reused by tasks, press any key to close it. 

and

...
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
Write File: /bilbomd/uploads/3a91db75-e0e7-442a-bcdd-8a2384fe024e/dynamics_rg35.inp
CHARMM error: dynamics_rg35.inp exit code: 2
/app/build/bilbomd.functions.js:296
                reject(new Error(charmmOutput));
                       ^

Error
    at ChildProcess.<anonymous> (/app/build/bilbomd.functions.js:296:24)
    at ChildProcess.emit (node:events:517:28)
    at maybeClose (node:internal/child_process:1098:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:517:28)
    at Pipe.<anonymous> (node:net:350:12)

Node.js v18.19.0
 *  Terminal will be reused by tasks, press any key to close it. 
dsclassen commented 10 months ago

If rg_min=35 and rg_max=36, your step calculation:

const step = Math.round((params.rg_max - params.rg_min) / 5)

would result in a step value of 0 because (36 - 35) / 5 = 0.2, and Math.round(0.2) is 0. This would lead to an infinite loop because rg would be initialized to 35 and then you attempt to increment it by 0 in each iteration (rg += step), which means rg would never reach rg_max to exit the loop.

To prevent this, you should ensure that step is at least 1 to make progress in the loop and avoid an infinite loop. You could modify the step calculation like this:

const step = Math.max(Math.round((params.rg_max - params.rg_min) / 5), 1);

This way, you ensure that step is at least 1, allowing the loop to progress and eventually terminate. This adjustment is crucial for handling cases where the difference between rg_max and rg_min is too small to be divided into five segments, or in general, to ensure that your loop increments properly.