Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ShraddhaDevaiya opened this issue Aug 19, 2020 · 6 comments

Comments

@ShraddhaDevaiya
Copy link

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
Copy link
Member

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
Copy link
Author

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

Thanks & Regards,
Shraddha Devaiya.

@mballance
Copy link
Member

Of course. Here's a link to the test I created from your example:

def test_dist_array_elems_range(self):
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)

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

Best Regards,
Matthew

@mballance mballance reopened this Aug 21, 2020
@ShraddhaDevaiya
Copy link
Author

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
Copy link
Member

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
Copy link
Author

Yeah now it is working !

Thanks & Regards,
Shraddha Devaiya.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants