Replies: 2 comments
-
I'm not sure if randsz_list_t can be nested recursively yet. I believe the TODO in list_t.init is relevant: Line 817 in 32f01e6 I reduced your example to a snippet so I could see what the debug shows for a randsz_list_t and then a nested one, and it doesn't generate any entries for that nested array other than the top-level size variable and an extra array_sz_c constraint. I don't see any unit tests that really do this either, so I'm not sure how well supported this is yet. @vsc.randobj
class Rand2d(object):
def __init__(self):
self.txn_arr = vsc.randsz_list_t(vsc.rand_int32_t())
self.txn_arr_nested = vsc.randsz_list_t(vsc.randsz_list_t(vsc.rand_int32_t()))
@vsc.constraint
def size_c(self):
self.txn_arr.size <= 5
self.txn_arr_nested.size <= 5
if __name__=="__main__":
obj=Rand2d()
obj.randomize(debug=True)
print(obj.txn_arr.size, obj.txn_arr)
print(obj.txn_arr_nested.size, obj.txn_arr_nested) Snippet from debug output: Final Model:
<anonymous> {
rand unsigned [32] txn_arr.size
txn_arr {
rand signed [32] txn_arr.txn_arr[0]
rand signed [32] txn_arr.txn_arr[1]
rand signed [32] txn_arr.txn_arr[2]
rand signed [32] txn_arr.txn_arr[3]
rand signed [32] txn_arr.txn_arr[4]
}
rand unsigned [32] txn_arr_nested.size
txn_arr_nested {
}
constraint size_c {
(txn_arr.size <= 5);
(txn_arr_nested.size <= 5);
}
}
constraint array_sz_c {
(txn_arr_nested.size <= 0);
} I did play around with nesting objects inside randsz_list_t though and using rand_attr to keep constraints in the top-level object. I was able to get something close to your original constraints. I'd be curious what @mballance thinks. Most of this was cobbled from unit tests and me looking into how distributions on arrays/lists are constructed. @vsc.randobj
class Wrap32(object):
def __init__(self):
self.num = vsc.rand_int32_t()
@vsc.randobj
class Array2D(object):
def __init__(self):
self.arr_size = vsc.rand_int32_t()
# TODO Why does this have to be wrapped up again?
self.arr = vsc.randsz_list_t(Wrap32())
for i in range(10):
self.arr.append(Wrap32())
@vsc.constraint
def size_c(self):
self.arr.size == self.arr_size
@vsc.randobj
class Rand2d(object):
def __init__(self):
self.num_total_txns=vsc.rand_int32_t()
self.num_channels=vsc.rand_int32_t()
self.txn_counts = vsc.randsz_list_t(vsc.rand_bit_t(4))
# TODO Is there better way to init a randsz_list_t like this?
self.txn_arr = vsc.randsz_list_t(vsc.rand_attr(Array2D()))
for i in range(4):
self.txn_arr.append(vsc.rand_attr(Array2D()))
@vsc.constraint
def size_c(self):
self.num_channels in vsc.rangelist(vsc.rng(1,5))
self.txn_counts.size == self.num_channels
self.txn_arr.size == self.num_channels
@vsc.constraint
def txn_counts_c(self):
self.num_total_txns == 10
with vsc.foreach(self.txn_counts) as it:
it>0
# TODO Why can't randsz_list_t have sum constrained to a non-constant?
self.txn_counts.sum == 10 # self.num_total_txns # It is OK if the sum is wrapped around for now.
@vsc.constraint
def txns_c(self):
with vsc.foreach(self.txn_arr, it=True, idx=True) as (idx,it):
# TODO Why can't arr.size be accessed directly?
it.arr_size == self.txn_counts[idx]
if __name__=="__main__":
obj=Rand2d()
obj.randomize(debug=False)
print(f'{obj.num_total_txns=}')
print(f'{obj.num_channels=}')
print(f'{str(obj.txn_counts)=}')
print(f'obj.txn_arr=')
for a in obj.txn_arr:
print('[', ', '.join([str(w32.num) for w32 in a.arr]), ']') Ouput showing 10 transactions across 4 channels: obj.num_total_txns=10
obj.num_channels=4
str(obj.txn_counts)='[4, 3, 1, 2]'
obj.txn_arr=
[ 1848195024, 1110448389, -566653803, 1289927244 ]
[ 282511111, -1296988485, 57745215 ]
[ 92529036 ]
[ -1456842762, -333868195 ] |
Beta Was this translation helpful? Give feedback.
-
Thanks! for your investigation Alex.
pyvsc looks promising and I am waiting for it to be usable in my projects.
I will stay tuned to see what improvements come down the pipe. Atm, SV
constraint random engine is the superior tool for my purposes with nested
arrays and also with nested objects. Those are a couple of must-have
features for making a jump to a python-based constraint random
implementation.
Thanks again for your time on this thread. Much appreciated.
… Message ID: ***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Thanks! for this Python module. I am looking forward to start using this in my work.
At this time I am playing around to gain some practice with this module. The toy problem I am trying to solve is this -
I need to send data pkts over some random number of channels. The number of data pkts sent on the channels is randomized but the total number of pkts across all channels is constrained to a maximum limit.
Is this some thing that can be implemented by the Pyvcs module? Can I get some guidance on how to go about solving such problems in Pyvcs?
I have tried an implementation in Pyvcs but I am not getting the desired effect (The SV implementation and result are at the bottom of my post).
My Pyvcs solutions is-
The error I get is from the child list randomization -
For reference, the SV implementaion looks like -
A sample output from the SV code in EDA playgorund, over 5 iterations looks like -
Many thanks!
Beta Was this translation helpful? Give feedback.
All reactions