Skip to content
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

Usage of Model API #23

Closed
yashp0103 opened this issue Jul 30, 2020 · 1 comment
Closed

Usage of Model API #23

yashp0103 opened this issue Jul 30, 2020 · 1 comment

Comments

@yashp0103
Copy link

Hi @mballance

We have done some experiments on different APIs from pyvsc. Some Model APIs are provided, and we have tried one from them that is, set_constraint_enabled(en). We are expecting the output same as constraint_mode(). Don't know the actual use of Model APIs.
Can you provide some examples related to that? So that we can know how to use and where to use.

API

Code:
Code

Output:
Output

Thanks & Regards,
Yash Patel

@yashp0103 yashp0103 changed the title Use of Model API Usage of Model API Jul 30, 2020
@mballance
Copy link
Member

Hi @pvipsyash,
The Model APIs are used to programmatically build up data and constraint models. They're currently used to implement the user-level API (eg @constraint, @randobj, etc). They can also be used standalone -- see an example here:

def test_smoke(self):
obj = FieldCompositeModel("obj")
a = obj.add_field(FieldScalarModel("a", 8, False, True))
b = obj.add_field(FieldScalarModel("a", 8, False, True))
obj.add_constraint(ConstraintBlockModel("c", [
ConstraintExprModel(
ExprBinModel(
a.expr(),
BinExprType.Lt,
b.expr()))
]))
rand = Randomizer()
rand.do_randomize([obj])
self.assertLess(a.val, b.val)

In this example, you could call 'set_constraint_enabled' on the ConstraintModel object.
Can you provide a bit more detail on your use model? Depending on what it is, the user-level API, model API, or some combination could be the best approach.

Best Regards,
Matthew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants