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

[Low] Bias with dynamic constraints #89

Closed ShreyanJabade closed 3 years ago

ShreyanJabade commented 3 years ago

Hello, The same condition given inside a dynamic constraint leads to high bias as compared to a inside a normal constraint. I request you to look into this aspect. Thank you

@vsc.randobj
class my_cls(object):

    def __init__(self):
        self.a = vsc.rand_uint8_t()
        self.b = vsc.rand_uint8_t()

    @vsc.constraint
    def a_c(self):
        self.a <= 100

        # Not skew
        self.b in vsc.rangelist(vsc.rng(1, 10))

    @vsc.dynamic_constraint
    def a_small(self):
        self.a in vsc.rangelist(vsc.rng(1,10))

    @vsc.dynamic_constraint
    def a_large(self):
        self.a in vsc.rangelist(vsc.rng(90,100))

my_i = my_cls()

non_dynamic = []
small=[]
large = []
both = []
for i in range(1000):
    my_i.randomize()
    non_dynamic.append(my_i.b)

    with my_i.randomize_with() as it:
        it.a_small()
    small.append(my_i.a)

    with my_i.randomize_with() as it:
        it.a_large()
    large.append(my_i.a)

    with my_i.randomize_with() as it:
        it.a_small() | it.a_large()
    both.append(my_i.a)

plt.hist(small)
plt.title('Small')
plt.show()

plt.hist(non_dynamic)
plt.title('Non dynamic')
plt.show()

plt.hist(large)
plt.title('Large')
plt.show()

plt.hist(both)
plt.title('Small or large')
plt.show()

Output is:

image

image

image

image

mballance commented 3 years ago

Hi @ShreyanJabade, I've corrected the case of referencing a single dynamic constraint in 0.4.6. Getting solution distribution to be even with disjunctions (eg a.small() | a.large()) is a much larger project. I've filed an enhancement (#94) to track this work.