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

Error for constraint failure #37

Closed
ShraddhaDevaiya opened this issue Aug 31, 2020 · 3 comments
Closed

Error for constraint failure #37

ShraddhaDevaiya opened this issue Aug 31, 2020 · 3 comments

Comments

@ShraddhaDevaiya
Copy link

Hi @mballance ,
I was trying this code, but it is giving an error for constraint failure.

import vsc

@vsc.randobj
class my_s(object):
    def __init__(self):
        super().__init__()
        self.num_of_nested_loop = vsc.rand_bit_t(8)
        self.loop_init_val = vsc.rand_list_t(vsc.uint8_t())
    

    @vsc.constraint
    def ab_con(self):
        self.num_of_nested_loop.inside(vsc.rangelist(1,2))
        self.loop_init_val.size == self.num_of_nested_loop;


item = my_s()

for i in range(5):
    item.randomize()
    print("A = ",item.num_of_nested_loop,", B = ",item.loop_init_val)

and this is giving an error like following :

Failed constraints:
[1]: num_of_nested_loop in [2, 1];

[1]: num_of_nested_loop in [2, 1];

[2]: (size == num_of_nested_loop);

[2]: (0 == num_of_nested_loop);

Solve failure
Traceback (most recent call last):
  File "usecase.py", line 22, in <module>
    item.randomize()
  File "/home/shraddha/.local/lib/python3.6/site-packages/vsc/rand_obj.py", line 107, in randomize
    Randomizer.do_randomize([model])
  File "/home/shraddha/.local/lib/python3.6/site-packages/vsc/model/randomizer.py", line 855, in do_randomize
    r.randomize(ri, bounds_v.bound_m)
  File "/home/shraddha/.local/lib/python3.6/site-packages/vsc/model/randomizer.py", line 160, in randomize
    raise Exception("solve failure")
Exception: solve failure

I think for this we need solve before constraint . Can you please take a look into it?

@mballance
Copy link
Member

Hi @ShraddhaDevaiya,
You'll need to make two changes to make this work:

  • Change from using rand_list_t to using randsz_list_t

  • Add a constraint on the size of the list

    Randomizing a rand_list_t just randomizes the elements already in the list. In your case, there are no elements. Your example should work when written as follows:

import vsc

@vsc.randobj
class my_s(object):
    def __init__(self):
        super().__init__()
        self.num_of_nested_loop = vsc.rand_bit_t(8)
        self.loop_init_val = vsc.randsz_list_t(vsc.uint8_t())
    

    @vsc.constraint
    def ab_con(self):
        self.num_of_nested_loop.inside(vsc.rangelist(1,2))
        self.loop_init_val.size.inside(vsc.rangelist(1,2))
        self.loop_init_val.size == self.num_of_nested_loop;


item = my_s()

for i in range(5):
    item.randomize()
    print("A = ",item.num_of_nested_loop,", B = ",item.loop_init_val)

Best Regards,
Matthew

@ShraddhaDevaiya
Copy link
Author

Yeah it is working this way. Thanks for helping !

Regards,
Shraddha Devaiya.

@ShraddhaDevaiya
Copy link
Author

Hi @mballance ,
One more issue I am facing in this case is like, it is iterating or randomizing every time with fix numbers. Like following is the code :

import vsc

@vsc.randobj
class my_s(object):
    def __init__(self):
        super().__init__()
        self.num_of_nested_loop = vsc.rand_bit_t(8)
        self.loop_init_val = vsc.randsz_list_t(vsc.uint8_t())
    

    @vsc.constraint
    def ab_con(self):
        self.num_of_nested_loop.inside(vsc.rangelist(1,2))
        self.loop_init_val.size.inside(vsc.rangelist(1,2))
        self.loop_init_val.size == self.num_of_nested_loop


item = my_s()

for i in range(3):
    item.randomize()
    print("A = ",item.num_of_nested_loop,", B = ",item.loop_init_val)

So, for this we should get 3 prints , but every time it is giving an output like this for any value of range() :

A =  1 , B =  [100]
A =  2 , B =  [126, 210]
A =  1 , B =  [184]
A =  1 , B =  [204]
A =  2 , B =  [7, 189]
A =  1 , B =  [6]
A =  2 , B =  [33, 71]
A =  1 , B =  [219]
A =  2 , B =  [61, 59]
A =  1 , B =  [39]
A =  1 , B =  [129]
A =  1 , B =  [208]
A =  1 , B =  [164]

Can you please help in this ?

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