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 of constraint failure #47

Closed ishitapvips closed 3 years ago

ishitapvips commented 3 years ago

Hi,

I was trying to run the below example

  import vsc

@vsc.randobj
class ex:
    def __init__(self):
        self.a = 0
        self.rs1 = vsc.rand_uint8_t()
        self.rd = vsc.rand_uint8_t()

@vsc.randobj
class riscv_lr_sc_instr_stream:
    def __init__(self):
        self.lr_instr = ex()
        self.sc_instr = ex()
        self.num_amo = vsc.rand_uint8_t()
        self.num_mixed_instr = vsc.rand_uint8_t()
        self.isa = "RV32A"
        self.reserved_regs = vsc.rand_list_t(vsc.uint8_t(), 4) #[1, 2, 3, 4]
        self.reserved_rd = vsc.rand_list_t(vsc.uint8_t(), 4) # [1, 2, 3, 4]
        self.rs1_reg = vsc.rand_list_t(vsc.uint8_t(), 1)

    @vsc.constraint
    def legal_c(self):
        self.num_amo == 1
        self.num_mixed_instr in (vsc.rangelist(vsc.rng(0, 15)))

    @vsc.constraint
    def lr_con(self):
        self.lr_instr.rs1 == self.rs1_reg[0]
        self.lr_instr.rd.not_inside(vsc.rangelist(self.reserved_rd))
        self.lr_instr.rd.not_inside(vsc.rangelist(self.reserved_regs))
        self.lr_instr.rd != self.rs1_reg[0]

    @vsc.constraint
    def sc_con(self):
        self.sc_instr.rs1 == self.rs1_reg[0]
        self.sc_instr.rd.not_inside(vsc.rangelist(self.reserved_rd))
        self.sc_instr.rd.not_inside(vsc.rangelist(self.reserved_regs))
        self.sc_instr.rd != self.rs1_reg[0]

    def post_randomize(self):
        print("RS1_REG = ",self.rs1_reg)

pri_obj = ex()
pri_obj.randomize()
obj = riscv_lr_sc_instr_stream()
obj.randomize()

For this, I getting the following error,

Problem Constraints:
Constraint 1:
(rd(0) != [0][0]);
(rd != rs1_reg[0]);
Constraint 2:
(rd(0) != [0][0]);
(rd != rs1_reg[0]);

Traceback (most recent call last):
  File "../example_lr_sc.py", line 47, in <module>
    obj.randomize()
  File "/home/ishita/.local/lib/python3.6/site-packages/vsc/rand_obj.py", line 112, in randomize
    raise e
  File "/home/ishita/.local/lib/python3.6/site-packages/vsc/rand_obj.py", line 109, in randomize
    Randomizer.do_randomize([model])
  File "/home/ishita/.local/lib/python3.6/site-packages/vsc/model/randomizer.py", line 565, in do_randomize
    r.randomize(ri, bounds_v.bound_m)
  File "/home/ishita/.local/lib/python3.6/site-packages/vsc/model/randomizer.py", line 204, in randomize
    self.create_diagnostics(active_randsets))
vsc.model.solve_failure.SolveFailure: solve failure

Can you help me with this? Regards, Ishita

mballance commented 3 years ago

Hi @ishitapvips , There are two issues here. One is that the solve-failure message is confusing. I'll look more deeply into that. That said, you can resolve the issue by making lr_instr and sc_instr 'rand'. If I understand the constraints correctly, this is the intent. You should change the beginning of the constructor as follows:

Existing code:

@vsc.randobj
class riscv_lr_sc_instr_stream:
    def __init__(self):
        self.lr_instr = ex()
        self.sc_instr = ex()

New code:

@vsc.randobj
class riscv_lr_sc_instr_stream:
    def __init__(self):
        self.lr_instr = vsc.rand_attr(ex())
        self.sc_instr = vsc.rand_attr(ex())

I've made this change locally, and the constraints solve properly.

Best Regards, Matthew

mballance commented 3 years ago

Appreciate the confirmation, @ishitapvips!