Comments (7)
Hi @ShraddhaDevaiya,
Okay, this is a bit of an interesting example because it mixes plain-python control-flow constructs with constraint constructs. While this does work in some cases, I would generally recommend against it.
The first 'foreach' in the constraint block will be simplified down to:
with vsc.foreach(self.a_list, idx=True) as i:
self.a_list[i] in vsc.rangelist(10,11,12,13)
This is because 'c' is not a PyVSC variable. Depending on the application, this might be desired.
In the second case, because we're forming a constraint between two arrays, it is necessary to use the PyVSC constraint if/else. I've updated your example as follows and can confirm that elements of a_list are in [10..13] and elements of temp_list are '1'.
@vsc.randobj
class my_s(object):
def __init__(self):
self.a_list = vsc.rand_list_t(vsc.uint8_t(),7)
self.temp_list = vsc.rand_list_t(vsc.uint8_t(),7)
self.c = 0
@vsc.constraint
def ab_c(self):
with vsc.foreach(self.a_list, idx=True) as i:
if self.c:
self.a_list[i] in vsc.rangelist(5,6,7,8)
else:
self.a_list[i] in vsc.rangelist(10,11,12,13)
with vsc.foreach(self.temp_list, idx=True) as i:
with vsc.if_then(self.a_list[i].inside(vsc.rangelist(6,7))):
self.temp_list[i] == 0
with vsc.else_then:
self.temp_list[i] == 1
my = my_s()
my.randomize()
I'll leave this open for now, since I'd like to see if the solve-failure message could better indicate what is happening here.
Best Regards,
Matthew
from pyvsc.
Hi @mballance,
Yeah it is working this way. Thanks for helping!
Regards,
Shraddha Devaiya.
from pyvsc.
Hi @mballance,
I am trying to use this if_then construct with some other case combining this scenario but, when I am writing else_if for comparison of Enum type, then it is giving me an error.
Following is the code for it:
class my_e(Enum):
A = 0
B = 1
C = 2
D = 3
@vsc.randobj
class my_s(object):
def __init__(self):
self.name = my_e.A
self.a = vsc.rand_uint8_t(0)
self.b = vsc.rand_list_t(vsc.enum_t(my_e), 4)
@vsc.constraint
def ab_c(self):
with vsc.foreach(self.b, idx = True) as i:
with vsc.if_then(self.b[i] == my_e.A):
self.a == 0
with vsc.else_if(self.b[i] == my_e.B):
self.a == 1
my = my_s()
# Randomize
for i in range(5):
my.randomize()
print("ITERATION : ",i+1)
print(my.a, list(my.b))
And it is giving an error like following:
Traceback (most recent call last):
File "3usecase.py", line 31, in <module>
my.randomize()
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/rand_obj.py", line 107, in randomize
Randomizer.do_randomize([model])
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/randomizer.py", line 831, in do_randomize
constraint_l.extend(ArrayConstraintBuilder.build(
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/array_constraint_builder.py", line 45, in build
m.accept(builder)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/field_composite_model.py", line 143, in accept
v.visit_composite_field(self)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/model_visitor.py", line 65, in visit_composite_field
c.accept(self)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/constraint_block_model.py", line 42, in accept
v.visit_constraint_block(self)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/constraint_copy_builder.py", line 85, in visit_constraint_block
super().visit_constraint_block(c)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/model_visitor.py", line 101, in visit_constraint_block
self.visit_constraint_scope(c)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/constraint_override_visitor.py", line 26, in visit_constraint_scope
cc.accept(self)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/constraint_foreach_model.py", line 47, in accept
v.visit_constraint_foreach(self)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/array_constraint_builder.py", line 72, in visit_constraint_foreach
c.accept(self)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/constraint_if_else_model.py", line 62, in accept
visitor.visit_constraint_if_else(self)
File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/constraint_copy_builder.py", line 142, in visit_constraint_if_else
for cs in c.false_c.constraint_l:
AttributeError: 'ConstraintIfElseModel' object has no attribute 'constraint_l'
if we comment else_if block then it is working. So, can you please help me?
Thanks & Regards,
Shraddha Devaiya.
from pyvsc.
Hi @mballance,
Did you get a chance to look into this?
Thanks & Regards,
Shraddha Devaiya.
from pyvsc.
Hi @ShraddhaDevaiya ,
Apologies, I have not had a chance yet. I'll do my best to investigate over the weekend.
Best Regards,
Matthew
from pyvsc.
Hi @ShraddhaDevaiya,
I've corrected the issue -- which was specific to using else-if inside a foreach constraint. The testcase now runs and the fix is available both on GitHub and in the precompiled PyPi package.
I'll leave this issue open until you can confirm.
Best Regards,
Matthew
from pyvsc.
Hi @mballance ,
It is working now, Thanks for helping !
Regards,
Shraddha Devaiya.
from pyvsc.
Related Issues (20)
- 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
- Is there an example of pyvsc integrated with cocotb and SV RTL with a simulator? HOT 2
- Solve order of randsz_list_t size constraints within foreach incorrect [v0.8.8] HOT 5
- randsz_list_t: Placing the sum constraint before the size constraints can result in incorrect sums [v0.8.8]
- solve before is solve_order, but document marks it as not supported HOT 1
- Can't see vsc after installing pyvsc
- PyVSC to give exhaustive list of stimulus
- Set values on randobj and check if it satisfies the constraints HOT 2
- solve_order()'s after argument, when list is used, ends up in before_l list HOT 1
- Is there a way to construct a logarithm constraint? HOT 2
- Key Error in adding constraints in the for loop
- Key error of ordinary for loop and TypeError of list indices in vsc.foreach HOT 1
- constraint for one hot encoding. 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.