Giter Site home page Giter Site logo

Comments (1)

alwilson avatar alwilson commented on July 26, 2024

Yeah, I think the @vsc_constraint decorator tries to override as many operators as possible to give you SV-like constraints, but just b/c you can put things in that function doesn't mean the decorator will handle it or execute as a normal function.

There aren't any examples in the docs for rand_list_t or randsz_list_t, but there is a sum property you can use to get the desired effect. Edit: My bad, there are examples. I was misreading the docs search bar results.
https://fvutils.github.io/pyvsc/reference.html#vsc.types.list_t

To give each element in rand_list_t a name like a,b,c,... I just assigned it in post_randomize. Maybe there's a clearer way to do it in the init, but I don't think the rand_list_t elements exist before calling randomize. The unit tests have more examples than the docs, so it can be a good to peruse.
https://github.com/fvutils/pyvsc/tree/master/ve/unit

Here's my take on your example. I left debug=True on the randomize since it can be helpful knowing what constraints were actually generated.

import vsc

@vsc.randobj
class bist_constraints:

    def __init__(self):
        self.vars = vsc.rand_list_t(vsc.rand_bit_t(1), 6)

    @vsc.constraint
    def abc(self):
        self.vars.sum < 2

    def post_randomize(self):
        self.a = self.vars[0]
        self.b = self.vars[1]
        self.c = self.vars[2]
        self.d = self.vars[3]
        self.e = self.vars[4]
        self.f = self.vars[5]

    def __repr__(self):
        return self.__str__()

    def __str__(self):
        return f'{[self.a,self.b,self.c,self.d,self.e,self.f]}'

if __name__ == "__main__":
    cfg=bist_constraints()
    cfg.randomize(debug=True)
    print(str(cfg))
    print(cfg.a)

from pyvsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.