Skip to content
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

Merged
merged 33 commits into from Nov 12, 2018

Conversation

sohailc
Copy link
Member

@sohailc sohailc commented Oct 30, 2018

Fixes #1342

This PR is still work in progress, but I would like to have comments early in the process.

@astafan8 astafan8 changed the title Extension/dynamic module [WIP] Extension/dynamic module Oct 30, 2018
self._parent, channel_list=self, **kwargs)

for channel in new_channels:
# NB: There is a bug in `extend`. TODO: Make a PR!
Copy link
Contributor

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.

Copy link
Member Author

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 :-)

Copy link
Contributor

@astafan8 astafan8 left a 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)
Copy link
Contributor

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?)

Copy link
Member Author

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}")
Copy link
Contributor

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.

Copy link
Member Author

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 Show resolved Hide resolved
raise NotImplementedError("Please subclass")

@classmethod
def get_new_instance_kwargs(cls, parent: Instrument, **kwargs)->dict:
Copy link
Contributor

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.

Copy link
Member Author

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.

qcodes/instrument/channel.py Show resolved Hide resolved
self.add_submodule("channels", channels)


def test_sanity():
Copy link
Contributor

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 :) )

Copy link
Member Author

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.

qcodes/instrument/channel.py Show resolved Hide resolved
qcodes/instrument/channel.py Show resolved Hide resolved
qcodes/tests/test_autoloadable_channels.py Show resolved Hide resolved
qcodes/tests/test_autoloadable_channels.py Show resolved Hide resolved
astafan8 and others added 4 commits October 30, 2018 06:40
Co-Authored-By: sohailc <schatoor@gmail.com>
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
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:
Copy link
Contributor

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.

Copy link
Member Author

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!

Copy link
Member Author

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

@codecov
Copy link

codecov bot commented Nov 1, 2018

Codecov Report

Merging #1353 into master will increase coverage by 0.06%.
The diff coverage is 82.6%.

@@            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

@sohailc
Copy link
Member Author

sohailc commented Nov 1, 2018

@astafan8 Can you approve this PR if you have no further objections? The tests and CI seem to be passing.
@Dominik-Vogel Can you have a look at this PR as well?

@astafan8
Copy link
Contributor

astafan8 commented Nov 7, 2018

@sohailc If you say that the PR is ready, please remove WIP from the title, and update the description :)

I'm reviewing now...

Copy link
Contributor

@astafan8 astafan8 left a 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).

qcodes/instrument/channel.py Outdated Show resolved Hide resolved
qcodes/instrument/channel.py Outdated Show resolved Hide resolved
qcodes/instrument/channel.py Outdated Show resolved Hide resolved
qcodes/instrument/channel.py Outdated Show resolved Hide resolved
qcodes/instrument/channel.py Outdated Show resolved Hide resolved
qcodes/tests/test_autoloadable_channels.py Outdated Show resolved Hide resolved
qcodes/tests/test_autoloadable_channels.py Show resolved Hide resolved
qcodes/tests/test_autoloadable_channels.py Outdated Show resolved Hide resolved
qcodes/tests/test_autoloadable_channels.py Outdated Show resolved Hide resolved
qcodes/tests/test_autoloadable_channels.py Show resolved Hide resolved
Copy link
Contributor

@astafan8 astafan8 left a 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 ?

@sohailc sohailc merged commit 9c7b9a0 into microsoft:master Nov 12, 2018
giulioungaretti pushed a commit that referenced this pull request Nov 12, 2018
Merge: 4dd73ba 4a4825d
Author: sohail chatoor <schatoor@gmail.com>

    Merge pull request #1353 from sohailc/extension/dynamic_module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants