DeepGraphLearning / torchdrug

A powerful and flexible machine learning platform for drug discovery
https://torchdrug.ai/
Apache License 2.0
1.42k stars 199 forks source link

Help needed using a molecular dataset #139

Open bananenpampe opened 1 year ago

bananenpampe commented 1 year ago

Hello together,

I have created a molecular dataset using:

dataset_train.load_smiles(Strain,targets={"property":Ytrain_full})

Now, when I want to create an Engine from a defined task:

task = tasks.PropertyPrediction(model, task=dataset_train.tasks,
criterion="bce", metric=("auprc", "auroc"),num_class=3)
optimizer = torch.optim.Adam(task.parameters(), lr=1e-3)
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, batch_size=1024)

I receive the following error:

'MoleculeDataset' object has no attribute 'config_dict'

How can I set the config dict using a user defined dataset?

Oxer11 commented 1 year ago

Hi!

Every class inherited from core.Configurable should has an attribute 'config_dict', e.g., data.MoleculeDataset. Could you show the code of our defined dataset? It will help us find the reason of the error.

taidbui commented 1 year ago

Got the same issue with MoleculeDataset

mol_dataset = torchdrug_data.dataset.MoleculeDataset()

mol_dataset.load_csv('data_dippr_liquid_heat_capacity_smiles.csv', smiles_field='SMILES')
model = models.RGCN(input_dim=mol_dataset.node_feature_dim,
                    num_relation=mol_dataset.num_bond_type,
                    hidden_dims=[10, 10, 10, 10])

task = tasks.GCPNGeneration(model, mol_dataset.atom_types, max_edge_unroll=12, max_node=38, criterion='nll')

optimizer = optim.Adam(task.parameters(), lr = 1e-3)

solver = core.Engine(task, mol_dataset, None, None, optimizer)
AttributeError: 'MoleculeDataset' object has no attribute 'config_dict'
BobvanSchendel commented 1 year ago

Has there been progress on this or a fix using a different class? I have the same issue as the others and want to know what I can do to circumvent this issue while using custom molecule datasets.

bananenpampe commented 1 year ago

Hello,

for me this fix worked, I assume ther is something wrong eith this wrapper:


from torchdrug.core import Registry as R

@R.register("datasets.Solvation")
class mymoldataset(data.MoleculeDataset):
    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)
BobvanSchendel commented 1 year ago

That fixes it for me, thanks!

bananenpampe commented 1 year ago

nice!