Giter Club home page Giter Club logo

Comments (12)

alexcjohnson avatar alexcjohnson commented on August 16, 2024

Three options come to mind:

  1. already possible: call del self.parameters['snazzy'] before self.add_parameter('snazzy', ...)
  2. we could add a keyword to add_parameter that enables overwriting
  3. to avoid even creating such parameters in the first place... this is a little hacky, but you could call super().__init__ after the new params with a pattern like:
def __init__(self, ...):
    # first add the overridden parameters
    self.add_parameter('override1', ...)
    self.add_parameter('override2', ...)
    ...

    # tell add_parameter() to not raise on overrides, just return without adding
    self.ignore_override_errors = True
    super().__init__(...)
    # turn off this behavior afterward
    self.ignore_override_errors = False

we could even get fancy and make this a context manager so you can't forget to clean up:

with self.ignore_override_errors:
    super().__init__(...)

from qcodes.

AdriaanRol avatar AdriaanRol commented on August 16, 2024

@alexcjohnson
I like "the with self.ignore_override_errors" option, however I would make it a private function.

from qcodes.

giulioungaretti avatar giulioungaretti commented on August 16, 2024

@AdriaanRol can you provide some examples where you would want to do this ?

from qcodes.

MerlinSmiles avatar MerlinSmiles commented on August 16, 2024

@giulioungaretti you could have a base awesomeness instrument, and have special drivers for models or versions that have a slightly different commandset or extended functionality or something like that.

from qcodes.

giulioungaretti avatar giulioungaretti commented on August 16, 2024

@MerlinSmiles fair point !

from qcodes.

giulioungaretti avatar giulioungaretti commented on August 16, 2024

So the proposed solution is to have an explicit overwrite_parameter function.
@AdriaanRol and @MerlinSmiles what you think ?

from qcodes.

MerlinSmiles avatar MerlinSmiles commented on August 16, 2024

@giulioungaretti would it break anything to be able to overwrite existing ones by default?
One might of course break something by doing so...

from qcodes.

AdriaanRol avatar AdriaanRol commented on August 16, 2024

I would propose as an argument in add_parameter, not a special function.
The current trick @alexcjohnson proposed based on del self.parameters['parameter_name'] does the trick but it is hard to gaurantee that all traces get removed if we at a later stage decide to change the functionality.

from qcodes.

giulioungaretti avatar giulioungaretti commented on August 16, 2024

I think it make more sense be explicit and avoid confusion. In this way you
will be warned both if you overwrite when adding and vice versa.
On Wed, 1 Jun 2016 at 14:19, MerlinSmiles [email protected] wrote:

@giulioungaretti https://github.com/giulioungaretti would it break
anything to be able to overwrite existing ones bu default?
One might of course break something by doing so...


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
qdev-dk-archive#32 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ACkcNzOExni8ynUAWYIXnkegF_9aCBIrks5qHXi_gaJpZM4HZLTb
.

from qcodes.

giulioungaretti avatar giulioungaretti commented on August 16, 2024

@AdriaanRol not sure what you mean with traces.
It's in general harder to reason about parameters (especially if they have default values, as it would be in this case) when refactoring.

from qcodes.

giulioungaretti avatar giulioungaretti commented on August 16, 2024

@AdriaanRol how about implementing as you proposed an add_praemter(...., overwrite=False) ?

from qcodes.

jenshnielsen avatar jenshnielsen commented on August 16, 2024

This is now possible via #3125

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.