Closed ShreyanJabade closed 3 years ago
Related to #81, there are no more unwanted solutions due to overflow. I checked the distribution and it is similar to this issue. So have added this comment here.
import vsc
import matplotlib.pyplot as plt
@vsc.randobj
class Test:
def __init__(self):
self.a = vsc.rand_uint8_t()
self.b = vsc.rand_uint8_t()
@vsc.constraint
def test_c(self):
self.a*self.b == 60
inst = Test()
a_vals = []
for i in range(1000):
inst.randomize()
a_vals.append(inst.b)
plt.hist(a_vals)
plt.show()
Output is:
Hi @ShreyanJabade, I've corrected the original issue in #83 in the 0.4.5 release. The second issue is significantly different.
PyVSC uses a SMT solver to create valid solutions. SMT solvers are not designed to produce solutions with a random distribution, so PyVSC introduces randomness by randomly selecting a set of variables to constrain to a randomly-selected value. This approach has limitations when the solution space of a variable is very small and the domain is also non-trivial to establish. To the best of my understanding, that is what is happening in the second case.
With respect to the second case, do the constraints in use on your project heavily involve multiplication? Is the solution space also very sparse like that shown above?
Hello, The nested constraints distribution is working perfectly now. Thank you for your consideration. The constraints in the project can involve multiplication to some extent, but not exclusively. Also, it is difficult to gauge the sparsity in general, since the constraint writer can have any set of constraints.
Hello, Specifying constraints on variables in members of list (eg. self.c1[0].a[0].value) leads to very high bias. Specifically, the highest value satisfying constraint is returned almost always. The same constraint given without list works normally as demonstrated in the output below. I request you to look into this aspect. Thank you
Output is: