Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PotentialNet edge dimension error #158

Open
and-tos opened this issue Nov 11, 2021 · 4 comments
Open

PotentialNet edge dimension error #158

and-tos opened this issue Nov 11, 2021 · 4 comments

Comments

@and-tos
Copy link

and-tos commented Nov 11, 2021

Hi,
I want to train a model using PotentialNet. The code fails due to an error with the edge dimensions:

Traceback (most recent call last):
  File "contextlib.py", line 130, in __exit__
python-BaseException
    self.gen.throw(type, value, traceback)
  File "dgl/heterograph.py", line 5614, in local_scope
    yield
  File "dgllife/model/model_zoo/potentialnet.py", line 238, in forward
    eids = graph.edata['e'][:,i].nonzero(as_tuple=False).view(-1).type(graph.idtype)
IndexError: index 8 is out of bounds for dimension 1 with size 8

There seems to be a mismatch with the constructed graphs.
According to a comment in the code:
n_etypes=n_etypes, # num_distance_bins + 5 covalent types
n_etypes should have length 9, but it is 8.

>>>distance_bins
[1.5, 2.5, 3.5, 4.5]
>>>d_one_hot.shape
(1384, 3)
>>>complex_knn_graph.edata['e'].shape
torch.Size([2068, 8])

I'd really appreciate your help!

@and-tos and-tos changed the title PotentialNet PotentialNet edge dimension error Nov 11, 2021
@mufeili
Copy link
Contributor

mufeili commented Nov 12, 2021

How did you modify the code? Can you provide a minimal script to reproduce the error?

@and-tos
Copy link
Author

and-tos commented Nov 12, 2021

I did not make any changes to the code, but want to use it to run on a private dataset. For this I defined the following configuration:

PotentialNet_inhouse = {
    'dataset': 'PDBBind',
    'task': 'Ki_inhouse', 
    'subset': '',
    'load_binding_pocket': True,
    'random_seed': 123,
    'frac_train': 0.6,
    'frac_val': 0.2,
    'frac_test': 0.2,
    'batch_size': 200,
    'shuffle': False,
    'max_num_neighbors': 5,
    'distance_bins': [1.5, 2.5, 3.5, 4.5],
    'f_in': 44,
    'f_bond': 48,  # has to be larger than f_in
    'f_gather': 48,
    'f_spatial': 48,  # better to be the same as f_gather
    'n_rows_fc': [48, 24],
    'n_bond_conv_steps': 2,
    'n_spatial_conv_steps': 1,
    'dropouts': [0.25, 0.25, 0.25],
    'lr': 0.01,
    'num_epochs': 100,
    'wd': 1e-05,
    'metrics': ['r2', 'mae'],
    'split': 'temporal'
}

Apologies, I cannot provide an actual example right now, but would appreciate any hint on what to look for.

@and-tos
Copy link
Author

and-tos commented Nov 12, 2021

The code works if I set:
distance_bins': [1.5, 2.5, 3.5]
I suggest that

def int_2_one_hot(a):
    """Convert integer encodings on a vector to a matrix of one-hot encoding"""
    n = len(a)
    b = np.zeros((n, a.max()+1))
    b[np.arange(n), a] = 1
    return b

changes to

def int_2_one_hot(a, distance_bins):
    """Convert integer encodings on a vector to a matrix of one-hot encoding"""
    n = len(a)
    b = np.zeros((n, len(distance_bins))
    b[np.arange(n), a] = 1
    return b

@mufeili
Copy link
Contributor

mufeili commented Feb 8, 2022

Sorry for the late reply. #170 should fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants