Closed junechanh closed 3 years ago
Hello @junechanh, I've been looking into dist and soft constraints, and believe I have improvements to the 'B' case. You are correct that, previously, dist constraints and soft constraints were given roughly the same priority. This allowed soft constraints to skew the distribution from dist constraints. I've improved that in the 0.3.7 release of PyVSC. Case 'D' is a bit more problematic. The PyVSC implementation of dist constraints selects the target range based solely on the weights -- in other words, it assumes that all ranges are reachable. In case 'D', the target value 20 will be selected according to its very high weight. When that value cannot be selected, one of the reachable values will be selected using unweighted-random selection. This does match SystemVerilog semantics (whether or not it's desirable in this case):
Absent any other constraints, the probability that the expression matches any value in the list is proportional
to its specified weight. If there are constraints on some expressions that cause the distribution weights on
these expressions to be not satisfiable, implementations are only required to satisfy the constraints. An
exception to this rule is a weight of zero, which is treated as a constraint.
I'll leave this open for now until you're able to confirm the improvements in 0.3.7.
Best Regards, Matthew
Thanks for the support on this Matthew. I wasn't aware of the behavior for case D in SystemVerilog; I appreciate the education. I can confirm that the scenario in case B is fixed with the latest. I'll close this issue now.
I've been playing around with dist constraints to see how they react in various scenarios, and I found some cases wherein they yield unexpected/unintuitive behavior. My code is similar to that of issue #61 :
The cases I wanted to highlight are cases B and D:
Case B: I am getting a distribution of mostly '1' and '2', ~45% and ~52%, respectively. I might have expected ~97% and ~1% if the dist constraint takes precedence, or an even distribution if the soft constraint takes precedence.
Case D: I am getting a distribution of mostly '0' and '2', ~50% and ~48%, respectively. I might have expected ~1% each if weights of the invalid/unused portions of the dist domain are ignored, or near-even if they are redistributed to the valid portions of the domain.