-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Extension/dynamic module #1353
Conversation
qcodes/instrument/channel.py
Outdated
self._parent, channel_list=self, **kwargs) | ||
|
||
for channel in new_channels: | ||
# NB: There is a bug in `extend`. TODO: Make a PR! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the bug about? Are you planning to make a PR with a test and a fix? That'd be great to do before landing this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will make a PR for that as well. Yes, there is a bug I discovered in the ChannelList
class, but I have not come round to fixing this and making a PR. There is something wrong with the extend
method in the ChannelList
class, but I forgot what, exactly :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this a good starting point. But in general my feeling is that the kwarg part of the interface is not explicit enough, and i'm looking forward to more fool-proofing measures (with tests :) ), see comments.
) | ||
|
||
def write_raw(self, cmd: str): | ||
return self._backend.send(cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write functions don't return, right?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is true. I will fix this.
|
||
def _create(self)->None: | ||
"""Create the channel on the instrument""" | ||
self.parent.write(f":INST:CHN:ADD {self._channel}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't self.root_instrument.write
be used instead of parent
? note that the docstring of _create
in the class suggests that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this should be root_instrument
. Good catch!
qcodes/instrument/channel.py
Outdated
raise NotImplementedError("Please subclass") | ||
|
||
@classmethod | ||
def get_new_instance_kwargs(cls, parent: Instrument, **kwargs)->dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I look at the usage of this method, I struggle to understand something. Do you mean that through this method a channel class obtains also the values of kwargs that it needs for its __init__
? From the test below, I deduct that it is expected the channel will need to basically refer to the parent instrument to get some important info (like the list of existing channels, so that the new channel can get a unique id that does not clash with the existing channels). What if for some instruments it's not the case? I'd propose to have parent
as an optional kwarg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can make parent
an optional keyword argument. Some instruments indeed do not need the parent instrument, while other do.
self.add_submodule("channels", channels) | ||
|
||
|
||
def test_sanity(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the test! but an example notebook with at least (for now) bare intentions of this infra, would be appreciated. This will also help to (if necessary) improve the design, strip down excessive code, and perhaps even add something. (yes, yes, i know that everything is expressed in the description of the linked issue, but still :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly think that adding a driver which uses this infrastructure will be illuminating, perhaps even more so than a notebook as it will show the complexities involved with a real instrument. I will make the PNA driver use the infrastructure which I think will be helpful.
Co-Authored-By: sohailc <[email protected]>
2) Make the parent argument of get_new_instance_kwargs optional 3) create should first assert that the channel does not exist 4) delete should first assert that the channel exists 5) delete should first check that self is in channels list 6) In the test channel class, use parent.root_instrument 7) In the test channel class, write does not return 8) In the test channel class, check for the specific error message in raise assertions. 9) In the test channel class, use fixtures 10) Make a new_instance method 11) More clear doc string in _get_new)instance_kwargs
…ion/dynamic_module
with pytest.raises(RuntimeError): | ||
# Once we remove the channel we should no longer be able to talk to the instrument | ||
new_channel.remove() | ||
with pytest.raises(RuntimeError) as e2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use pytest.raises(Exception, match="Object does not exist (anymore) on the instrument")
instead of working with e2
explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I did not know that! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, Mikhail, we should message the kwarg message
instead of match
…the channel_list argument.
…ion/dynamic_module
… into extension/dynamic_module # Conflicts: # qcodes/instrument/channel.py # qcodes/tests/test_autoloadable_channels.py
…R. Temporarily housed here to verify effectiveness
…into extension/dynamic_module
Codecov Report
@@ Coverage Diff @@
## master #1353 +/- ##
==========================================
+ Coverage 73.22% 73.29% +0.06%
==========================================
Files 79 79
Lines 9188 9256 +68
==========================================
+ Hits 6728 6784 +56
- Misses 2460 2472 +12 |
@astafan8 Can you approve this PR if you have no further objections? The tests and CI seem to be passing. |
@sohailc If you say that the PR is ready, please remove WIP from the title, and update the description :) I'm reviewing now... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good! It's almost ready modulo some typos and clarifications (see my comments).
…ion/dynamic_module
Give more useful hints when `_get_new_instance_kwargs` raises an exception.
…uld state that the newly created instance is returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good! I think this is ready to go. What do you think, @QCoDeS/core ?
Merge: 4dd73ba 4a4825d Author: sohail chatoor <[email protected]> Merge pull request #1353 from sohailc/extension/dynamic_module
Fixes #1342
This PR is still work in progress, but I would like to have comments early in the process.