fvutils / pyvsc

Python packages providing a library for Verification Stimulus and Coverage
https://fvutils.github.io/pyvsc
Apache License 2.0
113 stars 26 forks source link

Support to add "range" feature for values in weighted distribution constraint #36

Closed ShraddhaDevaiya closed 4 years ago

ShraddhaDevaiya commented 4 years ago

Hi @mballance, I was trying to use range in weighted distribution with Enum type values, because if we have many values in Enum class, then it seems little impractical to add every values between certain range in weighted distribution constraint. So, I was trying following code :

import vsc
from enum import Enum,auto

class my_e(Enum):
    A = 0
    B = auto()
    C = auto()
    D = auto()

@vsc.randobj 
class my_c(object):
    def __init__(self): 
        self.a = vsc.rand_enum_t(my_e)
        #self.a = vsc.rand_list_t(vsc.bit_t(7),15)
        #self.a = vsc.rand_uint8_t() 

    @vsc.constraint 
    def dist_a(self):
        #with vsc.foreach(self.a, idx=True) as i:
        vsc.dist(self.a, [ vsc.weight(vsc.rng(my_e.A, my_e.C),10) vsc.weight(my_e.D, 20)]) 

my = my_c()

# Randomize
for i in range(10):
    my.randomize()
    print("MY ITEM : ",i+1)
    print(my.a)

But for this rightnow we are getting syntax error. So, can you please take a look into this?

Thanks & Regards, Shraddha Devaiya.

mballance commented 4 years ago

Good catch, @ShraddhaDevaiya. I supported range specification as tuples, but not the vsc.rng format. Release 0.1.7 contains support for specifying weight ranges using vsc.rng.

Best Regards, Matthew

ShraddhaDevaiya commented 4 years ago

Hi @mballance , still it is giving me an error with this code. Can you please show me an example?

Thanks & Regards, Shraddha Devaiya.

mballance commented 4 years ago

Of course. Here's a link to the test I created from your example: https://github.com/fvutils/pyvsc/blob/71623e49f294364eacdd4639e5b84480f256e9a7/ve/unit/test_constraint_dist.py#L301-L326

I'll reopen this for now until we're able to confirm that it's been resolved.

Best Regards, Matthew

ShraddhaDevaiya commented 4 years ago

Hi, @mballance , Sorry for the delay. One thing I have observed in this code. With randomization , it is only giving my_e.C and my_e.D. I have run this 15 times, but it is just giving these two values. Just wanted to confirm, is this the same behavior at your end ? means my_e.B and my_e.A are not coming, but it is included in range.

mballance commented 4 years ago

Hi @ShraddhaDevaiya, Ah... I can see the issue. I believe the issue is now resolved in 0.1.8, and all values will be produced (subject to weighting, of course). Please confirm that you see the same.

Thanks and Regards, Matthew

ShraddhaDevaiya commented 4 years ago

Yeah now it is working !

Thanks & Regards, Shraddha Devaiya.