Comments (7)
Ah, good point about model
, we should just make that a required parameter.
server_name
is a little trickier - because of the way RemoteInstrument
s are instantiated and the weird behavior of __new__
. See the note at the start of #70, you ask to construct TestInstrument2
but you get an instance of RemoteInstrument
if the server is not None
- it's required that every instrument constructor accept server_name
as a kwarg. The easiest way to do this is to pass **kwargs
on from the final instrument to its super().__init__
, which is often useful anyway for taking advantage of superclass options.
I'll play around with it and see if I can find a clean way to not require that... but for now consider server_name
a known issue.
from qcodes.
Ah, and now I remember why I did model
this way too: Because the model
also has its own process, with queues and such, it's not picklable and so it must be provided to the MockInstrument
server on instantiation and shared by all MockInstrument
s on that server. And THAT means that it needs to be available in the arguments of the final subclass constructor, as a kwarg, otherwise we can't find it during creation of the RemoteInstrument
...
This is all a consequence of the fact that we need to know what server to make and how to make it before we even start to instantiate the object. So server_name
(what server to make) and model
(how to start the server) can't go through the normal inheritance machinery. I can think of ways to sort of solve this, but it would be complicated and not very robust, so I think I'd prefer to just better document what we have now. Is that OK?
from qcodes.
Why wouldn't it work to change the MockInstrument
init from
def __init__(self, name, delay=0, model=None, keep_history=True,
read_response=None, **kwargs):
to
def __init__(self, name, delay=0, model=None, keep_history=True,
read_response=None, server_name=None, **kwargs):
?
If that is not sufficient we should definitely document this, and perhaps add a check, e.g.
def __init__(self, name, delay=0, model=None, keep_history=True,
read_response=None, **kwargs):
if not 'server_name' in kwargs:
raise Exception('some error message')
from qcodes.
server_name
doesn't need to be in the kwargs, but it needs to be allowed in the kwargs at every level of subclassing.
from qcodes.
We can document this, but I am sure users will keep having trouble with this. See for example the code below. How about adding a check to the Instrument
class, e.g.
def __new__(cls, *args, server_name='', **kwargs):
if len(args)>1:
raise Exception('name can be passed as arg, the rest should be in kwargs')
...
I do not like this solution, but it will at least generate a proper error message.
Based on the code of MockMeter it is very hard to understand why the second instantiation of MockMeter would fail.
import numpy as np
from qcodes import Instrument, MockInstrument
from toymodel import AModel
model = AModel()
class MockMeter(MockInstrument):
def __init__(self, name, model=None, **kwargs):
super().__init__(name, model=model, **kwargs)
self.add_parameter('amplitude',
label='Current (nA)',
get_cmd='ampl?',
get_parser=float)
mine=MockMeter('mock1', model=model) # good
mine2=MockMeter('mock2', model) # fail
from qcodes.
(documenting my thinking as mentioned in #85 for when I get a chance to dig into this)
@peendebak I don't like this situation either... it's more complicated than that in fact, it would be totally fine for instruments to accept more positional arguments, but server_name
and any shared_kwargs
must be allowed as kwargs and if provided they must be provided as kwargs.
Originally I thought this was a quirk of __new__
, because it gets called with the arguments of the subclass constructor even though it's defined in the base class... and we could avoid __new__
by making a helper function (which also avoids the unexpected behavior that you ask to construct one class and you get a different one) but this still doesn't help with the strange requirements around model
(and anything else that needs to be a shared_kwarg
) and makes the syntax for defining instruments cumbersome.
What I think we can and should do is let __new__
inspect the signature of __init__
to see:
- if it meets the requirements (must allow
server_name
and anyshared_kwargs
as kwargs), and provide a proper error message if not - if we can find things we expected to see as kwargs hiding in the args, and move them to kwargs so the rest of the machinery will work
from qcodes.
Mock Model has been ⚡️ so closing this.
from qcodes.
Related Issues (20)
- Loading a parameter called "current_time" produces an array that just contains the completed timestamp HOT 2
- xarray dataset dependency is incorrect when adding an independent parameter to the measurement
- Make it possible to use ConnectionPlus as a context manager
- Non-gridded data export to netcdf HOT 3
- Captured_run_id is incorrect if run has been inserted HOT 1
- Pyvisa sim instruments are not cleanup on close. HOT 1
- Lakeshore 336 Driver with USB interface not connecting HOT 9
- Random error in test_logger HOT 3
- Agilent E8257D Instrument Driver Bug in on() and off() Methods HOT 5
- Code coverage jumps by 10 lines
- Warning when calling data_set.cache.load_data HOT 1
- Acccessing a faulty property of an instrument throws obscure error.
- print_readable_snapshot() of instrument modules without parameters broken.
- Random failure in do_nd test HOT 2
- Cannot exit ipython with running qcodes.Monitor() HOT 4
- Add redirects to new documentation? HOT 2
- Error when running `Infiniium.py` driver file HOT 4
- Parameter.__getitem__ behavior HOT 5
- Ignored exception on ci in windows related to monitor and socket. HOT 1
- Alazar example (and driver) is broken HOT 2
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 qcodes.