mir-group / flare_pp

A many-body extension of the FLARE code.
MIT License
35 stars 6 forks source link

TypeError at `gp_model.add_training_structure(train_struc)` #31

Closed MengnanCui closed 2 years ago

MengnanCui commented 2 years ago

Thanks so much for your nice work, I tried to repeat the codes shown on Google Colab. Everything works very well, until this step:

# Train the model.
print("Training the GP...") 
batch_size = 10  # monitor the MAE after adding this many frames
n_strucs = np.zeros(batch_size)
mb_maes = np.zeros(batch_size)
for m in range(training_size): # 100
  train_struc = training_strucs[m]

  # Add training structure and sparse environments.
  gp_model.add_training_structure(train_struc)
  gp_model.add_all_environments(train_struc)

  if (m + 1) % batch_size == 0: # 10 per iteration
    # Update the sparse GP training coefficients.
    gp_model.update_matrices_QR()

    # Predict on the validation set.
    pred_forces = np.zeros((validation_size, noa, 3))
    for n, test_struc in enumerate(validation_strucs):
      gp_model.predict_SOR(test_struc)
      pred_vals = test_struc.mean_efs[1:-6].reshape(noa, 3)
      pred_forces[n] = pred_vals

    # Calculate and store the MAE.
    batch_no = int((m + 1) / batch_size)
    mae = np.mean(np.abs(validation_forces - pred_forces))
    n_strucs[batch_no - 1] = batch_size * batch_no
    mb_maes[batch_no - 1] = mae
    print("Batch %i MAE: %.2f kcal/mol/A" % (batch_no, made))

Here is the error message.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-c4db7c1083ef> in <module>
      8 
      9   # Add training structure and sparse environments.
---> 10   gp_model.add_training_structure(train_struc)
     11   gp_model.add_all_environments(train_struc)
     12 

TypeError: add_training_structure(): incompatible function arguments. The following argument types are supported:
    1. (self: flare_pp._C_flare.SparseGP, arg0: flare_pp._C_flare.Structure, arg1: List[int]) -> None

Invoked with: <flare_pp._C_flare.SparseGP object at 0x7ff6d426b130>, <flare_pp._C_flare.Structure object at 0x7ff6e16b7d70>

I actually didn't change any content, do you have ideas about the error? PS: pip install flare_pp didn't work on my laptop, so I download your code from GitHub, then install manually. Fortunately, no error report while installation, and flare_pp also can be imported very well. Thank you!

YuuuXie commented 2 years ago

Hi @mnTusi

Thanks for your interest in our code! I think this issue is because of our recent update of code interface, that is not synced to the colab tutorial. We will address it soon.

MengnanCui commented 2 years ago

Dear YuXie, Good to Know, thanks so much for your reply! Mengnan

YuuuXie commented 2 years ago

close via #33