-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access parent class variable in child class constraint #38
Comments
Hi @aneels3, Best Regards, |
Hi @mballance |
Hi @mballance Regards, |
Hi @aneels3, Thanks, |
Hi @mballance import vsc
@vsc.randobj
class parent:
def __init__(self):
self.num = vsc.rand_int8_t()
self.values = {} # This should be of vsc type
self.name = {
0 : {"name":"start", "value":10},
1 : {"name":"end", "value":20}
}
def pre_randomize(self):
if num > 10:
self.values = self.name
@vsc.randobj
class child(parent):
def __init__(self):
super().__init__()
self.data = vsc.rand_uint32_t()
self.max_num_t = vsc.rand_uint32_t()
@vsc.constraint
def data_c(self):
self.data < self.num
with vsc.foreach(self.values, idx=True) as i:
self.max_num_t = self.values[i].value
def pre_randomize(self):
super().pre_randomize()
child_ins = child()
child_ins.randomize()
print("Max number ", child_ins.max_num_t) |
Hi @mballance |
Hi @mballance As @aneels3 mentioned previously we don't have support for dict type in pyvsc. Can we expect that support? Thanks, |
Hi @pvipsyash and @aneels3, Thanks and Best Regards, |
Hi @mballance import vsc
@vsc.randobj
class parent:
def __init__(self):
self.num = vsc.rand_int8_t()
self.values = [{}] # This should be of vsc type, for eg. list of dict
self.name = {
0 : {"name":"start", "value":10},
1 : {"name":"end", "value":20}
}
def pre_randomize(self):
if num > 10:
self.values = self.name
@vsc.randobj
class child(parent):
def __init__(self):
super().__init__()
self.data = vsc.rand_uint32_t()
self.max_num_t = vsc.rand_uint32_t()
self.name_t = "" # This should be pyvsc str data type
@vsc.constraint
def data_c(self):
self.data < self.num
with vsc.foreach(self.values, idx=True) as i:
self.max_num_t == self.values[i].["value"]
# Or
self.name_t == self.values[i].["name"]
def pre_randomize(self):
super().pre_randomize()
child_ins = child()
child_ins.randomize()
print("Max number ", child_ins.max_num_t) Thanks and Regards, |
Hi @aneels3, Best Regards, |
Hi @mballance So in this use-case, the data page is a queue of the associative array. To accomplish this using pyvsc I will require a list of dict instead of dict of dict. (Correction) Regards, |
Hi @aneels3, Thanks and Best Regards, |
Hi @mballance, I think I might have made this a little complicated for you. I want to store the I hope this makes sense to you. Thanks and Regards, |
Hi @aneels3, pyvsc/ve/unit/test_ext_array.py Lines 11 to 80 in 3f58e3a
I'm using a class, region_c, to represent the properties of a memory region. This aligns with the SystemVerilog description. Note that this class is a pyvsc random object, and uses pyvsc fields. I followed the SystemVerilog approach of holding the different types of memory regions within a cfg class. This is an optional element of the example. You can certainly continue to store these at the package level. The instruction-generation class sets the data_page array within the instruction-generation class to the appropriate array from the configuration. Note that I did need to correct two things in the library to support this, so you will need to update your pyvsc library. Does this approach look like it would work? Thanks and Regards, |
Hi @mballance |
I was trying to access the parent class variable in child class constraints as in the test example below.
Output log
I found that the constraint of child class being called after the creation of the child class object. Is this expected?
Ideally, the constraint should be checked only after we call the randomize() method.
The text was updated successfully, but these errors were encountered: