Comments (5)
Like the following feature:
'
@vsc.constraint
def basic_c(self):
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
self.GroupList[idx]<= self.mThreadNum
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
self.GroupList[idx]<= self.mThreadNum
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
with vsc.if_then(self.GroupList[idx] > 1):
self.GroupListScore[idx] == 1
with vsc.else_then():
self.GroupListScore[idx] == 0
self.GroupListScore.sum < self.getSum(self.GroupListScore)
self.GroupList.sum == self.mThreadNum
def getSum(self, aList):
return sum(aList)
'
from pyvsc.
Can you provide a full example that includes the definition of data fields?
Currently, PyVSC invokes functions when the constraint is built. So, getSum would be invoked once to obtain the size of the GroupListScore. Obviously, this behavior might not be what is desired.
from pyvsc.
For example, The following code doesn't run well for line 94:
Line 94 doesn't have caculation functions.
My question is how to meet similar requirement?
from pyvsc.
Hi @hanfeng0114,
Thank you for the full example. I created a small testcase based on the example. The error I receive from running this testcase is shown below:
File "/project/fun/pyvsc/pyvsc-20230821/src/vsc/rand_obj.py", line 208, in build_field_model
fo.c(self)
File "/project/fun/pyvsc/pyvsc-20230821/ve/unit/test_scalar_array.py", line 348, in basic_c
self.GroupList.sum == self.mThreadNum * self.mSharePercent/100
File "/project/fun/pyvsc/pyvsc-20230821/src/vsc/types.py", line 84, in __eq__
return self.bin_expr(BinExprType.Eq, rhs)
File "/project/fun/pyvsc/pyvsc-20230821/src/vsc/types.py", line 72, in bin_expr
to_expr(rhs)
File "/project/fun/pyvsc/pyvsc-20230821/src/vsc/types.py", line 338, in to_expr
raise Exception("Element \"" + str(t) + "\" isn't recognized, and doesn't provide to_expr (type=%s)" % str(type(t)))
Exception: Element "6.4" isn't recognized, and doesn't provide to_expr (type=<class 'float'>)
The core issue is that the right-hand side of the equation produces a floating-point result and PyVSC doesn't currently handle this. I receive proper results if I explicitly convert the right-hand side to an integer:
self.GroupList.sum == int(self.mThreadNum * self.mSharePercent/100)
I recommend using explicit conversion for now. In the future, I will either improve the error messaging or provide direct support for using floating-point expressions in integer constraint expressions.
from pyvsc.
The 0.8.4 release contains changes to automatically convert floating-point number used in constraints to integers. I believe this is the best way to address this issue.
Thank you for the issue report!
from pyvsc.
Related Issues (20)
- 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
- Unexpected behavior with unique rand_list_t HOT 4
- Cannot constrain attribute inside a rand_attr inside a rand_list HOT 12
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.