Hi All, I have 2 files “utils.py” and “trainer.py”. The trainer.py has a class “Trainer” with a function “tnr” defined under the class as shown in the image below. I want to access the highlighted variables “edge_logits” and “nodes_logits” in the last line of the trainer.py and use them in the “reconstruction_scores” function in the utils.py file but I have tried all possible options but getting error. As can be seen, I have already imported utils in the trainer.py file and so when I import trainer in the utils.py, it will throw a error as a result of circular imports. Any ideas to help access the “nodes_logits” and “edges_logits” from the trainer.py and use them in the “reconstruction_scores” function in the utils.py are welcomed. Below are the images of the trainer.py and utils.py.
You should be able to import
MolecularMetrics and use it in
edges_logits, nodes_logits = self.G(z)
PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier.
Hi @ptrblck. Thanks for the reply but I want to do the opposite of what you are thinking. I want to import from the trainer.py and use
nodes_logits in the
utils.py as highlighted under the
reconstruction_scores function in the utils image. How do I go about it without incurring circular import errors.
I have already tried importing Trainer class in the
from trainer import Trainer and using
Trainer.tnr.edges_logits in the reconstruction_scores function, but I get circular import error since I have also imported
utils.py in the
ImportError: cannot import name 'Trainer' from 'trainer'
You won’t be able to access
Trainer.tnr as they are not attributes but local variables.
return these tensors and call the
Trainer class from
To avoid circular imports, check e.g this post.