forcebalance icon indicating copy to clipboard operation
forcebalance copied to clipboard

(not urgent) single parameter optimization with workers fails

Open pavankum opened this issue 3 years ago • 1 comments

Hi, nothing urgent about this but I noticed that single parameter optimization runs with workers fail with this error even before sending work to the worker jobs

Traceback (most recent call last):
  File "/dfs6/pub/pbehara/bin/conda/fb_env/bin/ForceBalance.py", line 45, in Run_ForceBalance
    optimizer.Run()
  File "/dfs6/pub/pbehara/bin/conda/fb_env/lib/python3.9/site-packages/forcebalance/optimizer.py", line 319, in Run
    xk = self.OptTab[self.jobtype]()
  File "/dfs6/pub/pbehara/bin/conda/fb_env/lib/python3.9/site-packages/forcebalance/optimizer.py", line 943, in NewtonRaphson
    return self.MainOptimizer(b_BFGS=0)
  File "/dfs6/pub/pbehara/bin/conda/fb_env/lib/python3.9/site-packages/forcebalance/optimizer.py", line 493, in MainOptimizer
    data        = self.Objective.Full(xk,Ord,verbose=True)
  File "/dfs6/pub/pbehara/bin/conda/fb_env/lib/python3.9/site-packages/forcebalance/objective.py", line 313, in Full
    Objective = self.Target_Terms(vals, Order, verbose, customdir)
  File "/dfs6/pub/pbehara/bin/conda/fb_env/lib/python3.9/site-packages/forcebalance/objective.py", line 216, in Target_Terms
    Tgt.stage(mvals, AGrad = Order >= 1, AHess = Order >= 2, customdir=customdir)
  File "/dfs6/pub/pbehara/bin/conda/fb_env/lib/python3.9/site-packages/forcebalance/target.py", line 637, in stage
    self.submit_jobs(mvals, AGrad, AHess)
  File "/dfs6/pub/pbehara/bin/conda/fb_env/lib/python3.9/site-packages/forcebalance/target.py", line 789, in submit_jobs
    self.serialize_ff(mvals, outside="forcefield-remote")
  File "/dfs6/pub/pbehara/bin/conda/fb_env/lib/python3.9/site-packages/forcebalance/target.py", line 745, in serialize_ff
    if len(mvalsf) > 0 and np.max(np.abs(mvals - mvalsf)) != 0.0:
TypeError: len() of unsized object

the same input works fine when run directly without any worker jobs. Also, it works if I optimize two parameters instead of one. Attached a minimal example for testing. I tested this with 1.8.1, 1.9.0 and the latest release and it fails in all. forcebalance.zip

pavankum avatar Sep 28 '21 00:09 pavankum

Just ran into this; the issue is that if there is only one value in the mvals.txt file, np.loadtxt will create an "array" that holds only a scalar, and has no shape or len. The fix is to change the line to np.loadtxt("mvals.txt", ndmin=1).

trevorgokey avatar Jan 09 '22 01:01 trevorgokey