pyvsc icon indicating copy to clipboard operation
pyvsc copied to clipboard

randsz_list_t: Placing the sum constraint before the size constraints can result in incorrect sums [v0.8.8]

Open alwilson opened this issue 2 years ago • 0 comments

Calling the sum constraint after the size constraints seems to work well, which I think is due to the size being solved in a RandSet before the sum RandSet. Calling the sum constraint before appears to use the previous or initialized (maximum?) size of the randsz_list_t.

This runs til the sum isn't correct:

import vsc

@vsc.randobj
class my_cls(object):

    def __init__(self):
        self.l = vsc.randsz_list_t(vsc.uint8_t())

    @vsc.constraint
    def l_c(self):
        self.l.sum == 10
        self.l.size > 0
        self.l.size <= 5

my_i : vsc.RandObjInt = my_cls()
for _ in range(100):
    my_i.randomize(debug=False)
    print(f'{len(my_i.l)=} {my_i.l}')
    if sum(my_i.l) != 10:
        break

Output:

len(my_i.l)=5 [0, 8, 1, 0, 1]
len(my_i.l)=5 [0, 0, 0, 0, 10]
len(my_i.l)=2 [8, 0]

alwilson avatar Feb 05 '24 00:02 alwilson