ICAMS / python-ace

Other
66 stars 15 forks source link

Error when using trf/lm/dogbox optimizer #69

Open gooaah opened 1 month ago

gooaah commented 1 month ago

Hello developers, I am trying optimizers in python-ace, and I met a problem when using trf/lm/dogbox optimizer. Here is the error information when I set optimizer as 'lm' for the example of Cu-I:

2024/07/11 11:21:42 I - Loss function specification: LossFunctionSpecification(kappa=0, L1=1e-08, L2=1e-08, DeltaRad=(1e-08, 1e-08, 1e-08), w_orth=0)
2024/07/11 11:21:42 I - Batch size: 100
Traceback (most recent call last):
  File "/home/hao/.local/bin/pacemaker", line 401, in <module>
    main(sys.argv[1:])
  File "/home/hao/.local/bin/pacemaker", line 248, in main
    general_fit.fit()
  File "/home/hao/.local/lib/python3.10/site-packages/pyace/generalfit.py", line 481, in fit
    self.target_bbasisconfig = self.ladder_fitting(self.initial_bbasisconfig, self.target_bbasisconfig)
  File "/home/hao/.local/lib/python3.10/site-packages/pyace/generalfit.py", line 509, in ladder_fitting
    current_bbasisconfig = self.cycle_fitting(current_bbasisconfig)
  File "/home/hao/.local/lib/python3.10/site-packages/pyace/generalfit.py", line 564, in cycle_fitting
    current_bbasisconfig = self.fit_backend.fit(
  File "/home/hao/.local/lib/python3.10/site-packages/pyace/fitadapter.py", line 129, in fit
    raise e
  File "/home/hao/.local/lib/python3.10/site-packages/pyace/fitadapter.py", line 96, in fit
    fit_res = self.run_tensorpot_fit(bbasisconfig, dataframe, loss_spec, fit_config,
  File "/home/hao/.local/lib/python3.10/site-packages/pyace/fitadapter.py", line 236, in run_tensorpot_fit
    self.fitter.fit(dataframe, test_df=test_dataframe, niter=fit_config[FIT_NITER_KW],
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/fit.py", line 99, in fit
    res_opt = least_squares(ls_opt_func.func, coefs, jac=ls_opt_func.jac,
  File "/home/hao/.local/lib/python3.10/site-packages/scipy/optimize/_lsq/least_squares.py", line 832, in least_squares
    f0 = fun_wrapped(x0)
  File "/home/hao/.local/lib/python3.10/site-packages/scipy/optimize/_lsq/least_squares.py", line 830, in fun_wrapped
    return np.atleast_1d(fun(x, *args, **kwargs))
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/fit.py", line 487, in func
    self.update(x, batches)
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/fit.py", line 481, in update
    resid_value, jacob_value = self.run_fit(x, batches)
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/fit.py", line 436, in run_fit
    loss, jac, e, f = self.tensorpot_fit.tensorpot.external_vector_fit(x, b)
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/tensorpot.py", line 391, in external_vector_fit
    loss, grad_loss, e, f, self.reg_components = self._evaluate_vector_loss(*input2evaloss(data))
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/tensorpot.py", line 193, in _evaluate_vector_loss
    loss, grad_loss, e, f = self.compute_vector_grad()
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/tensorpot.py", line 325, in compute_vector_grad
    e = self.forward_pass(pos)
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/tensorpot.py", line 247, in forward_pass
    e_atomic = self.potential.compute_atomic_energy(r_ij,
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/potentials/ace.py", line 496, in compute_atomic_energy
    e_atom = self.eval_atomic_energy(r_ij)
  File "/home/hao/.local/lib/python3.10/site-packages/tensorpotential/potentials/ace.py", line 420, in eval_atomic_energy
    a_munlm_r = tf.tensor_scatter_nd_update(a_munlm_r, update_index, a_nlm_r)
  File "/home/hao/.local/lib/python3.10/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/hao/.local/lib/python3.10/site-packages/tensorflow/python/framework/ops.py", line 5983, in raise_from_not_ok_status
    raise core._status_to_exception(e) from None  # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: {{function_node __wrapped__TensorScatterUpdate_device_/job:localhost/replica:0/task:0/device:CPU:0}} Indices and updates specified for empty output shape [Op:TensorScatterUpdate] name: 

Could you tell me the hint to solve the problem?

Best, Hao

yury-lysogorskiy commented 1 month ago

Actually, we do not support any other optimizers except BFGS and L-BFGS. However, does you setup works if you use BFGS as optimizer?