feat: Look up any instrument by name, and ensure name is unique#323
feat: Look up any instrument by name, and ensure name is unique#323alexcjohnson merged 6 commits intomasterfrom
Conversation
To make sure I understand this correctly: Secondly, this would also mean that Instrument names should only be unique per instrument server (as one instrument would usualy contain both itself, and its remote copy with the same name) I will do a detailed reading of the changes in the near future, but I would like to understand it a bit better before I start doing that ;) |
| # method this is not an issue, as the class is reimported in the | ||
| # new process, but with fork it can be a problem ironically. | ||
| from qcodes.instrument.base import Instrument | ||
| Instrument._all_instruments = {} |
There was a problem hiding this comment.
Holiday comment 🍸
this is a no go in my book.
It's hinting that there is a design issue somewhere. Either in the class design or in the server/proxy design.
It's a fine workaround, but shall not go into master IMHO.
There was a problem hiding this comment.
Do you have an alternative to propose (other than "yes, I'm working on a new architecture")? This just exists to smooth out a difference between the inheritance models of the two multiprocessing methods, so presumably will go away entirely with the new architecture, but what do we do until then?
There was a problem hiding this comment.
nops, hence the holiday remark in the first line.
There was a problem hiding this comment.
but idk, it seems like adding one more hack makes people happy so whatevs.
There was a problem hiding this comment.
also not really sure it is about inheritance, but rather namespaces.
Correct - in the main process you can find all locally-defined instruments and the
Except that the main process has references to all instruments, either as defined locally or pointing to a server (the |
|
@alexcjohnson |
Yes, absolutely correct. Perhaps not to be recommended, but there's nothing stopping you. |
qcodes/instrument/base.py
Outdated
| # remove from all_instruments too, but don't depend on the | ||
| # name to do it, in case name has changed or been deleted | ||
| all_ins = Instrument._all_instruments | ||
| for name in list(all_ins.keys()): |
There was a problem hiding this comment.
@alexcjohnson
Why not
for name, inst in all_ins.items():
the difference is not enormous, but this feels faster (I have no data to support this)
I think it makes the code more clear
There was a problem hiding this comment.
Partially... it could be changed to
for name, inst in list(all_ins.items()):
if inst is wr:but the list() is necessary because I'm going to mutate the contents of the dict - otherwise you get RuntimeError: dictionary changed size during iteration
There was a problem hiding this comment.
Ah, awesome. I learned something today
|
It looks good, |
qcodes/instrument/base.py
Outdated
|
|
||
| # remove from all_instruments too, but don't depend on the | ||
| # name to do it, in case name has changed or been deleted | ||
| all_ins = Instrument._all_instruments |
There was a problem hiding this comment.
change it here to
ins = cls._all_instruments
then, (for consistency with line 293)?
judging by your earlier comment
There was a problem hiding this comment.
good point, thanks!
Plus a couple of comments
And un-proxy find_instrument in RemoteInstrument
|
@damazter tested and ready when you are. |
| for arg in self.args3: | ||
| self.assertIn(arg, e.exception.args) | ||
|
|
||
| mv.close() |
There was a problem hiding this comment.
what's this? Why added in this commit ?
There was a problem hiding this comment.
Oh sorry, should have been in a previous commit. Because we can't have two instruments with the same name now, it's important to close instruments you're done with.
|
this should not go into v0.1, adds one more layer of things to maintain that are linked to the old architecture. |
|
@giulioungaretti More importantly, the alazar driver #66 is contingent on having this interface working. This PR is the last hurdle towards merging the ats driver as far as I know. I think that the alazar comes before the v0.1 milestone. |
|
@damazter you are kind of right, but this forces the new architecture to have one more requirement that may or may not be what one wants. Maybe this is a horrible idea with the new architecture, if it's added now I will have to support it, maintain it and cry. Or maybe not. But I feel like it's too dangerous. |
|
@giulioungaretti I can understand your reluctance... but we are going to need some way to let instruments talk to each other. Seems to me this solves a lot of issues with a clean interface and low footprint (very much unlike the clumsy It will be important to build the new architecture in such a way that these connections can be supported, so we may as well support them from the outset, if not by this exact API then something else that we define and implement very very soon. |
|
@giulioungaretti We are all waiting for the Alazar - without it there will be no v0.1 users! |
|
@majacassidy @alexcjohnson . Then go for it, I will just suffer if it was not the right choice. |
|
@alexcjohnson This is stupid behaviour of the user in this case, but the crash it causes is nasty and obscure. what do you think? |
|
@damazter good point. Two thoughts:
|
|
@alexcjohnson What I like about the second option is that it also prevents the user from finding a weird instrument because of some naming issue. I think it would be a good idea to add this to this pr, such that developers are alerted to this potential mistake. |
|
let's hope this won't create subtle problems with the future 🕶 (more state to take care of, but Alazar comes first! ) |
qcodes/instrument/remote.py
Outdated
| """ | ||
| return self._instrument_class.instances() | ||
|
|
||
| def find_instrument(self, name): |
There was a problem hiding this comment.
What is the reason for overwriting the baseclass method?
Oh smart, nevermind. Never thought about remote instrument not being an instrument :d
|
@alexcjohnson |
Changes proposed in this pull request:
Instrument.find_instrument(name)or, sinceInstrumentis a parent of all other instruments, within an instrument driver you can doself.find_instrument(name).@damazter what do you think?
TODO: