Comments (15)
Hi @aneels3,
The issue here appears to be that 'num' is not declared as a PyVSC variable. When num is used in a constraint, it's current value is captured. This is all because of how Python implements operator overloading. The constraint failure message (data < 0) reflects this.
I believe this should work if you declare num as a vsc.rand_uint32_t, etc.
Best Regards,
Matthew
from pyvsc.
Hi @aneels3,
After investigating this more, and looking at the related SystemVerilog description, I'd like to suggest an alternate approach. I've created a test illustrating the approach here:
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,
Matthew
from pyvsc.
Hi @mballance
Got it. I have completely missed that. Now It is working as expected.
Thanks!
from pyvsc.
Hi @mballance
I came across a similar problem where I have to use a dict variable of parent class in a child class constraint. As you have suggested above to declare the PyVSC variable in order to use it in a constraint. Do we have something like vsc.rand_list_t() for dictionary variables?
Regards,
Anil
from pyvsc.
Hi @aneels3,
We don't currently have a dict that can be used in constraints. Do you happen to have an example that you can share?
Thanks,
Matthew
from pyvsc.
Hi @mballance
please go through the test that I have written for this issue.
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)
from pyvsc.
Hi @mballance
Did you get a chance to look into this issue?
from pyvsc.
Hi @mballance
As @aneels3 mentioned previously we don't have support for dict type in pyvsc. Can we expect that support?
Thanks,
Yash
from pyvsc.
Hi @pvipsyash and @aneels3,
Apologies for the oversight!
@aneels3, the example above appears to be iterating over the elements of a dict and equating the variable to the values (not keys) in the map. Can you help me understand what you're trying to accomplish (ie what your usecase is)? I think there's an issue with the example, and understanding a bit more about what you're trying to do would help me.
Thanks and Best Regards,
Matthew
from pyvsc.
Hi @mballance
Sorry for the minor mistake in the test case that I had provided previously.
Please use the below test case.
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,
Anil
from pyvsc.
Hi @aneels3,
Okay, so it looks like you're looking for a non-rand 'dict-like' type that can be indexed with constraint-foreach index variables? If this is a pattern you're used to using in SystemVerilog, could you share (or point me to) an example?
I see a few potential issues -- especially, for example, if the intent is to have this data type act as a type of constraint. If it's a pretty-simple key/value map for which the primary requirement is that we be able to index it in a foreach, then it's likely easier.
Best Regards,
Matthew
from pyvsc.
Hi @mballance
Please refer to these links for the SV example.
https://github.com/google/riscv-dv/blob/3cdce00e63997201d0f00294365d920ff5e3ba7d/src/riscv_load_store_instr_lib.sv#L64
https://github.com/google/riscv-dv/blob/3cdce00e63997201d0f00294365d920ff5e3ba7d/src/riscv_directed_instr_lib.sv#L48
So in this use-case, the data page is a queue of the associative array.
which is being updated here
https://github.com/google/riscv-dv/blob/3cdce00e63997201d0f00294365d920ff5e3ba7d/src/riscv_directed_instr_lib.sv#L55
To accomplish this using pyvsc I will require a list of dict instead of dict of dict. (Correction)
Regards,
Anil
from pyvsc.
Hi @aneels3,
Thanks for sharing these references. I'm starting to get the picture of the current challenges of implementing this approach with pyvsc as it stands today.
I see that 'cfg' sets up some lists of configurations for memory regions. The instruction-stream class then selects one of those lists based on some instruction-stream configuration knobs.
Once difference I note between the SystemVerilog generator and the Python generator is that it appears the instruction-stream classes hold a handle to the config in the SystemVerilog version, while they reference a global object in the Python version. Is this difference desirable (ie it's preferable in Python to use the global object)?
It seems to me that if we could populate the data_page list -- either by changing the handle, or by updating the content of the list -- that this would work with PyVSC. Do you agree? Is there something I'm not understanding about the example?
Thanks and Best Regards,
Matthew
from pyvsc.
Hi @mballance,
Actually, The idea is to create the objects once in the config_gen module and importing the object in different modules throughout the generator in order to minimize multiple object creation of the same class. Even if I create a different handle for cfg
that would require a pyvsc list data type which can store the dictionary keys and values of mem_region
mem_region is a dict of dict in our case.
I think I might have made this a little complicated for you.
Let me try to explain it once again.
The self.data_page
is being appended with mem_region contents here
which is needed in the addr_c
constraint block here.
I want to store the mem_region
content to a pyvsc list and use it in the addr_c
constraint block based on string and int as key.
Such that self.max_load_store_offset
will constraint to corresponding values of size_in_bytes
I hope this makes sense to you.
Please let me know if you still have some doubts about this? or any workaround you can think of!
Thanks and Regards,
Anil
from pyvsc.
Hi @mballance
Thanks a lot for the WA. It worked perfectly as expected.
Closing it for now!
Regards,
Anil
from pyvsc.
Related Issues (20)
- Can't have a randsz_list_t of randobj HOT 1
- ModuleNotFoundError: No module named 'pyboolector' HOT 10
- I'm not able to install pyvsc package, it fails when handling the pyboolector module HOT 3
- Selecting a list element from a list of bit-vectors returns an int HOT 3
- Setting constraint_mode to False retains the previous range/bounds of the constraint HOT 1
- Cannot make constraint under if_then soft HOT 13
- Cannot use random value as list index in a constraint HOT 2
- PicklingError when trying to pickle a VSC randobj HOT 2
- What is the relation between pyvsc and portable stimulus (pss)? HOT 2
- how to print coverage model HOT 3
- pyvsc performance dominated by stack frame operations in inspect module HOT 1
- import error _boolector_add
- Enh: Support Default bin (How to write "default" in vsc.coverpoint ?)
- install error for latest version macos HOT 3
- support for function incur in constraint functions HOT 5
- constraint solver error HOT 1
- Installing pyvsc fails on pyboolector for python 3.11.5 on Linux (Arch) HOT 3
- Distributions have higher priority than soft constraints HOT 1
- I can't install pyvsc for pypy3.10! HOT 4
- not_inside constraint unexpectedly reducing output set significantly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyvsc.