Object has no attribute '__code__'
Closed this issue · 5 comments
Hi there, I noticed that sample_space
does not seem to work with class instances, because they do not have a __code__
attribute:
import exmol
class A:
pass
exmol.sample_space('C', A(), batched=True)
AttributeError: 'A' object has no attribute '__code__'
Is there any way around this other than forcing the call to a separate function?
Not exactly sure how your class is supposed to work, but here are a few examples:
Make class on each call:
import exmol
class A:
def __call__(self, seqs):
# do something with seqs
return ys
obj = A()
exmol.sample_space('C', obj, batched=True)
Make new object each time
def wrapper(seqs):
my_a = A()
return my_a(seqs)
exmol.sample_space('C', wrapper, batched=True)
Sorry for the late reply Andrew.
The second example works, but the first one - providing a class object directly to sample_space
- would still fail with the same AttributeError
described above. It's not a major issue since one can always wrap the call into another function. I was just wondering if this could be addressed somehow.
Ah, I think I understand now what's going on. Have a PR on #118 that should fix this. It was also broken for function partials
Perfect, thanks a lot!