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

Error using soft constraints with dist #61

Closed junechanh closed 3 years ago

junechanh commented 3 years ago

I'm getting an Exception with the following code snippet:

import vsc

@vsc.randobj
class my_item(object):
    def __init__(self):
        self.a = vsc.rand_bit_t(8)
        self.b = vsc.rand_bit_t(8)

    @vsc.constraint
    def valid_ab_c(self):
        self.a < self.b
        vsc.soft(self.a > 5) #A

    @vsc.constraint
    def dist_a(self):
        vsc.dist(self.a, [
            vsc.weight(0,  10),
            vsc.weight(1,  100),
            vsc.weight(2,  10),
            vsc.weight(4,  10),
            vsc.weight(8, 10)])

item = my_item()
for i in range(10):
    with item.randomize_with() as it:
        it.b > 10
        it.a == 1 #B
File "/Users/junenguyen/Projects/constraint_eval/pyvsc/src/vsc/model/randomizer.py", line 177, in randomize
    for f in rs.nontarget_field_s:
AttributeError: 'RandSet' object has no attribute 'nontarget_field_s'

I haven't dug too much into it, but 'nontarget_field_s' doesn't seem to exist in the codebase.

This error case seems to stem from the presence of both the dist constraint and an override of a soft constraint (line #A) via inline hard constraint (line #B).

mballance commented 3 years ago

Hi @junechanh, Very much appreciate the bug report and testcase. As it turns out, there were two issues that occurred when combining a dist constraint (which is implemented with soft constraints) with a soft constraint and causing both to fail with an inline constraint. I've corrected both issues and the test now runs correctly. I've made a new release (0.3.1), so you can either update PyVSC via PyPi or update the source code to get the fix. I'll leave the issue open until you're able to confirm the fix.

Best Regards, Matthew

junechanh commented 3 years ago

Thanks for such a fast turnaround @mballance -- I can confirm that the fix works.