Closed qzcx closed 3 years ago
Thanks for pointing this out, @qzcx! I haven't done much with Jupyter notebooks, but the error does make sense in the context of something that doesn't "really" have source information. Let me look into this a bit, but certainly worth fixing for completeness.
Thanks.
I hit the issue above using visual studio code with the Jupyter extension.
I also tried to repro the issue in google colab (google's free cloud jupyter notebook tool), but had issues installing pyvsc. So I'd recommend trying it in a local server instance.
I was also able to repro the issue just using the normal python terminal which is a bit painful to plug in, but is at least another data point.
>python
>>> import vsc
>>> @vsc.randobj
... class BranchInstr:
... def __init__(self):
... self.type = vsc.rand_bit_t(1)
... self.disp = vsc.rand_bit_t(22)
...
>>> @vsc.covergroup
... class BranchInstr_cg:
... def __init__(self):
... self.with_sample(item = BranchInstr())
... self.type = vsc.coverpoint(self.item.type)
... self.disp_cp = vsc.coverpoint(self.item.disp, bins = {"type0_disp" : vsc.bin_array([16], [0, 4095]),"type1_disp" : vsc.bin_array([32], [8192, 16383]) })
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "python36_venv/lib/python3.6/site-packages/vsc/coverage.py", line 272, in covergroup
file = inspect.getsourcefile(T)
File "python/3.6.8/lib/python3.6/inspect.py", line 684, in getsourcefile
filename = getfile(object)
File "3.6.8/lib/python3.6/inspect.py", line 654, in getfile
raise TypeError('{!r} is a built-in class'.format(object))
TypeError: <module '__main__' (built-in)> is a built-in class
Hi @qzcx I can see you are using Python 3.6.8. Try installing Python version 3.7+ (If possible) Just a guess, it might work.
Regards, Anil
Hi Jon (@qzcx), I've corrected this in the 0.6.0 release.
I like to work in jupyter notebooks when working on examples, creating graphs or examining data. A skill I picked up in multiple machine learning classes.
While trying msmftc's example in #107, I noticed that covergroups classes fail to create. Giving the following error:
It seems to be an issue with trying to get a source file, but likely it is confused since a jupyter notebook is more of an extention of an ipython terminal instead of running a python file directly. Overall, this is only a minor issue since randobj and constraints seem to work fine in jupyter notebooks and I can just graph a histogram of the results instead of generating coverage.
Here is the code from #107 which I used: