Skip to content

Bug: OSError: could not get source code #609

@rubenalv

Description

@rubenalv

I downloaded the pre_processed data and tried running the tutorial here https://github.com/DeepRank/deeprank2/blob/main/tutorials/training.ipynb

At the stage of

trainer.train(
    nepoch=epochs,
    batch_size=batch_size,
    earlystop_patience=earlystop_patience,
    earlystop_maxgap=earlystop_maxgap,
    min_epoch=min_epoch,
    validate=True,
    filename=os.path.join(output_path, f"gnn_{task}", "model.pth.tar"),
)

The output is:

INFO:deeprank2.trainer:Training set loaded
INFO:deeprank2.trainer:Validation set loaded
INFO:deeprank2.trainer:Epoch 0:
INFO:deeprank2.trainer:training loss 0.8269949356714884 | time 0.3814964294433594
INFO:deeprank2.trainer:validation loss 0.8072875671916537 | time 0.0742034912109375
INFO:deeprank2.trainer:Epoch 1:
INFO:deeprank2.trainer:training loss 0.7365012235111661 | time 0.36728739738464355
INFO:deeprank2.trainer:validation loss 0.6814224786228604 | time 0.07352352142333984
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/apps/software/Anaconda3/2022.05/envs/deeprank2/lib/python3.10/site-packages/deeprank2/trainer.py", line 649, in train
    checkpoint_model = self._save_model()
  File "/apps/software/Anaconda3/2022.05/envs/deeprank2/lib/python3.10/site-packages/deeprank2/trainer.py", line 949, in _save_model
    str_expr = inspect.getsource(key["transform"])
  File "/apps/software/Anaconda3/2022.05/envs/deeprank2/lib/python3.10/inspect.py", line 1139, in getsource
    lines, lnum = getsourcelines(object)
  File "/apps/software/Anaconda3/2022.05/envs/deeprank2/lib/python3.10/inspect.py", line 1121, in getsourcelines
    lines, lnum = findsource(object)
  File "/apps/software/Anaconda3/2022.05/envs/deeprank2/lib/python3.10/inspect.py", line 958, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

I have deeprank2 installed in a cluster, with permissions rwxr.x... and I run it with my user that belongs to the group (ie running it with permissions r.x). I tried running it with full rwx as well, but got the same error.

Also, I noticed that the file in https://github.com/DeepRank/deeprank2/blob/main/deeprank2/trainer.py is not identical to the file that gets installed. At least, in the save_model() function they differ:
In the file:

     if features_transform_to_save:
            for key in features_transform_to_save.values():
                if key["transform"] is None:
                    continue
                str_expr = inspect.getsource(key["transform"])
                match = re.search(r"[\"|\']transform[\"|\']:.*(lambda.*).*,.*[\"|\']standardize[\"|\'].*", str_expr).group(1)
                key["transform"] = match

But in github:

        if features_transform_to_save:
            for key in features_transform_to_save.values():
                if key["transform"] is None:
                    continue
                # Serialize the function
                serialized_func = dill.dumps(key["transform"])
                # Deserialize the function
                deserialized_func = dill.loads(serialized_func)  # noqa: S301
                str_expr = inspect.getsource(deserialized_func)
                match = re.search(r"[\"|\']transform[\"|\']:.*(lambda.*).*,.*[\"|\']standardize[\"|\'].*", str_expr).group(1)
                key["transform"] = match

Any hints as to the OS error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to documentation

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions