Giter Club home page Giter Club logo

Comments (4)

MerlinSmiles avatar MerlinSmiles commented on July 17, 2024

@alexcjohnson, Related to drivers that work with multiple instrument models, there will also be drivers that share many features but ommit / extend on a base set of features, how would one go about this?
Subclassing a base driver and add features?

from qcodes.

alexcjohnson avatar alexcjohnson commented on July 17, 2024

drivers that share many features but omit / extend on a base set of features

Yes, subclassing should serve this purpose well.

class AcmeModel1(AcmeBase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs):
        self.add_parameter('only_in_model1', ...)
        del self.parameters['not_in_model1']
        # and same for functions

from qcodes.

AdriaanRol avatar AdriaanRol commented on July 17, 2024

I guess subclassing is indeed the obvious answer but does this mean they get a separate file? I guess it does not improve readability to have a separate file for an instrument driver that is a subclass and only contains 2 functions and 1 extra parameter. Altough I guess at the end it is more about findability of the drivers themselves.

Maybe this is a crazy idea but perhaps we cannot find the best possible solution at this point in time because we are not actually experiencing the problem yet. Maybe we should just stick to the most simple solution for now, being flat (or company named folders) with no fancy redirecting imports and revisit this issue once we hit ~30+ drivers or so. I guess then we have all the edge cases needed to find the most suitable approach.

from qcodes.

alexcjohnson avatar alexcjohnson commented on July 17, 2024

perhaps we cannot find the best possible solution at this point in time because we are not actually experiencing the problem yet

🌟 💯 🌟

Lets keep the company subdirectories, because changing that would be painful later. But beyond that,
the direct reference method works, will always work, and does everything we need including the requirement to only import the drivers we really need. Its only downsides are long, unwieldy import statements and it could do more to help the user find the driver they want.

Thinking further about this, We're probably all going to be totally fine with this as long as qcodes is installed in development mode; there won't be too many drivers, and all the users will know where the code is and how to look around in it for drivers. The problems are likely to come when it stabilizes and new people install it as a regular package: lots of times people don't even know where on disk these packages are, and anyway we'd rather they not hunt around in there but have nice ways to discover drivers from within Python.

So we have some time... but one way to do this without forcing us into any particular structure now (including things like one class per file, directory names matching file / class names) would be to make a driver "registry" - perhaps in the __init__.py for each subdirectory so we still avoid actually loading everything, each driver registers itself re: what instrument models it handles (under all the company aliases it might have), what instrument type it drives, a short description... then we can go crazy with a search system but also there could be several responses to statements like

awg = qcodes.instruments.AWG5014(address='...'):

  • success
    Connected to AWG5014 in 0.03 sec
  • partial match
    KeyError: no driver found for 'AWG5014' - perhaps you meant 'AWG5014C'?
  • multiple match
MultiValueError: 'AWG5014' matches 2 drivers:
  qcodes.instrument_drivers.tektronix.AWG5014C.Tektronix_AWG5014C
  qcodes.instrument_drivers.tektronix.AWG5014X.Tektronix_AWG5014X

Obviously there are a lot of things we could do with that, but the point is, there IS a solution that doesn't force any additional constraints on us right now, so we can keep the structure as it is currently, ie well organized for us as coders, and shelve further discussion for now.

from qcodes.

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.