-
Notifications
You must be signed in to change notification settings - Fork 319
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
Feat/channelization further work #641
Feat/channelization further work #641
Conversation
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.
Review of channel.py
Apart from these modest changes:
- PEP8! Half the file has too long lines
- Some comments are now obsolete
qcodes/instrument/channel.py
Outdated
@@ -167,9 +140,10 @@ class ChannelList(Metadatable): | |||
|
|||
""" | |||
|
|||
def __init__(self, parent, name, chan_type: type, chan_list=None, | |||
def __init__(self, parent: Instrument, name, chan_type: type, chan_list=None, |
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.
Either we use type annotations or we don't (and I guess we are moving towards using them), but we should not mix. Also, the __init__
function raises errors if chan_type
and multichan_paramclass
are not something which is more specific than type
.
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.
Why not, it's gradual typing after all ;) That aside it's easy to add them but the main benefit comes from annotating the chan_type
because the linter has trouble figuring out that we are passing a Class and not an instance of a Class but sure it's easy to add the rest.
I am not sure that there is a better way of annotating that this is a Class not an instance of the Class. type(multichan_paramclass) is not what you are looking for at least.
qcodes/instrument/channel.py
Outdated
oneindexed=self._oneindexed) | ||
elif self._oneindexed: | ||
if i < 1: | ||
raise IndexError("1 indexed channel lists only support positive indexes") |
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.
Same as above.
qcodes/instrument/channel.py
Outdated
@@ -206,9 +181,18 @@ def __getitem__(self, i): | |||
i (int/slice): Either a single channel index or a slice of channels to get | |||
""" | |||
if isinstance(i, slice): | |||
if self._oneindexed: | |||
if i.start < 1 or i.stop < 1: | |||
raise IndexError("1 indexed channel lists only support positive indexes") |
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.
Merriam-Webster allows for both forms, but I prefer "indices" over "indexes".
qcodes/instrument/channel.py
Outdated
@@ -279,7 +264,7 @@ def index(self, obj): | |||
Args: | |||
obj(chan_type): The object to find in the channel list. | |||
""" | |||
return self._channels.index(obj) | |||
return self._channels.index(obj) + self._oneindexed |
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.
Maybe it's just me, but I would find self._channels.index(obj) + int(self._oneindexed)
to be more obvious.
qcodes/instrument/channel.py
Outdated
@@ -296,6 +281,11 @@ def insert(self, index, obj): | |||
raise TypeError("All items in a channel list must be of the same type." | |||
" Adding {} to a list of {}.".format(type(obj).__name__, | |||
self._chan_type.__name__)) | |||
if self._oneindexed: | |||
if index < 1: | |||
raise IndexError("1 based channel lists only support positive indexes") |
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.
Same as above.
self.name = str(name) | ||
self.parameters = {} | ||
self.functions = {} | ||
self.submodules = {} |
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.
Why does the InstrumentBase
have submodules? Does it need them? And if so, should it not be in the docstring and there be a add_submodule
method?
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 guess we still need the submodules mentioned in the docstring.
qcodes/instrument/base.py
Outdated
|
||
print(self.name + ':') | ||
print('{0:<{1}}'.format('\tparameter ', par_field_len) + 'value') | ||
print('-'*80) |
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.
80 should probably be max_chars
.
qcodes/instrument/base.py
Outdated
submodule.print_readable_snapshot(update, max_chars) | ||
|
||
# | ||
# shortcuts to parameters & setters & getters # |
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.
One space too many 😺
qcodes/instrument/base.py
Outdated
|
||
print(self.name + ':') | ||
print('{0:<{1}}'.format('\tparameter ', par_field_len) + 'value') | ||
print('-'*80) |
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.
This 80 character long line should probably be max_chars
long.
Should check how this works with the QCodes Monitor |
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.
Re the changes: Soooo pretty 😃
Re monitor: Agreed.
Just quickly, apologies for not responding earlier, is it worth having a
discussion of whether allowing 1-indexing is a good idea? It created a
syntax that is counter to what a python user would expect.
…On Tue., 20 Jun. 2017, 8:55 am William H.P. Nielsen, < ***@***.***> wrote:
***@***.**** approved this pull request.
Soooo pretty 😃
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#641 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAmyvA7u4uvf2Wrfshf2uQcPKyRI7Jhbks5sF2zZgaJpZM4N8PKx>
.
|
Im not sure, I don't particularly like it either but I fear that users will be very unhappy with a situation where chan[0] maps to channel 1 on an instrument |
Perhaps there can be a logical separation between channel names and
indexing though. While naming ports by their names as (like `vna.Port1..4`)
makes sense since this is explicitly instrument specific, while indexing
them using list notation, this creates a situation where similar
instruments could behave in two different ways.
For example, the Harvard dac naturally indexes from zero, while the QDac
does not. Code written for one over the other now does not port over
cleanly! There is now no longer a possibility to read code without knowing
whether certain instruments index by 1 or 0.
Indexing by 0 is sufficiently universal in coding that even if a user is
not a coder, they will encounter such syntax everywhere so I don't think it
is an unreasonable ask for users here.
|
Hmm... It's bit hard to be strongly in favour of either. I don't see porting of code from one driver to the other ever happening easily, so I am not very concerned about that aspect of things. Instruments are in my experience always in a world of their own, and two boxes never quite behave the same way. Having 1-indexed python lists are not nice, that is for sure. They are not too uncommon in the scientific world, though, with both Matlab/Octave and Mathematica indexing from 1, but I agree that python should be kept with one convention. My main concern (and Jens' too, I suspect) is that users will immediately complain and/or make their own patching of the driver too be 1-indexed. And just before doing so, they will accidentally fry a sample by setting DAC channel 23 to 10 Volts using |
Would a dict instead of a list solve this? In this case, there doesn't have
to be a separation between name and index, keys could even be numbers
…On Tue, Jun 20, 2017, 6:30 PM William H.P. Nielsen ***@***.***> wrote:
Hmm... It's bit hard to be strongly in favour of either.
I don't see porting of code from one driver to the other ever happening
easily, so I am not very concerned about that aspect of things. Instruments
are in my experience always in a world of their own, and two boxes never
quite behave the same way.
Having 1-indexed python lists are not nice, that is for sure. They are not
too uncommon in the scientific world, though, with both Matlab/Octave and
Mathematica indexing from 1, but I agree that python should be kept with
one convention.
My main concern (and Jens' too, I suspect) is that users will immediately
complain and/or make their own patching of the driver too be 1-indexed. And
just before doing so, they will accidentally fry a sample by setting DAC
channel 23 to 10 Volts using dac.channels[22]. Is there a good way to
avoid that?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#641 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AGgLHQjOGoB_sUtw4VMtoRrmPfha46rYks5sF4MTgaJpZM4N8PKx>
.
|
@nulinspiratie there is already a method to address channels by name (i.e. The fact is that adding 1-indexing creates the opposite problem for python users. Someone coming in could very easily set |
@spauka Ah right, but why not override slicing in
which outputs: |
Agreed with @spauka and @WilliamHPNielsen to go for the simplest solution now and only support regular python lists/tuples if the need arises we can come up with a more clever solution |
With regards to the monitor, Channel parameters are supported as well as regular parameters. Namely you cannot pass a MultiChannelParameter to the monitor but that is no different from a regular MultiParameter. Each channel is rendered as a new instrument which is suboptimal but probably ok for now |
|
That way you can access the names on the channellist via names as soon as they are locked
many instruments have hardware channels that are indexed and start at 1
354b3cd
to
cc56d6a
Compare
rebased and pushed submodules up to instrumentbase I think this is ready to merge |
Make it possible to get channels by name even when not locked
I changed it around a bit to make it possible to index channels by name without locking the channels, I think this is ready to be merged |
If we mention |
@WilliamHPNielsen done |
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.
Beautiful!
Author: Jens Hedegaard Nielsen <[email protected]> Feat/channelization further work (#641)
* fix: refactor Instrument to avoid removing methods from channels * Include channels in print_readable_snaphoot * Fix: make locked channels a named tuple That way you can access the names on the channellist via names as soon as they are locked * Fix: channels add support for indexing from 1 many instruments have hardware channels that are indexed and start at 1 * Fix linting errors in channel * fix typo * Move print readable snapshot to instrument class where it belongs * Fix: more channel annotation * Improve error message * pprint limit line lenght of header to max char * pep8 line lenght * Fix: channel remove support for oneindexed channels * improve type annotation * Optional -> Union * add channels to api docs * fix: make submodules nested * add submodule attributes to base * Replace namedtuple by dict Make it possible to get channels by name even when not locked * Add submodule to docstring
* fix: refactor Instrument to avoid removing methods from channels * Include channels in print_readable_snaphoot * Fix: make locked channels a named tuple That way you can access the names on the channellist via names as soon as they are locked * Fix: channels add support for indexing from 1 many instruments have hardware channels that are indexed and start at 1 * Fix linting errors in channel * fix typo * Move print readable snapshot to instrument class where it belongs * Fix: more channel annotation * Improve error message * pprint limit line lenght of header to max char * pep8 line lenght * Fix: channel remove support for oneindexed channels * improve type annotation * Optional -> Union * add channels to api docs * fix: make submodules nested * add submodule attributes to base * Replace namedtuple by dict Make it possible to get channels by name even when not locked * Add submodule to docstring
A few additional changes on top of the channelization
inst.channels.channelname
Add support for allowing channels to be one indexed@spauka @WilliamHPNielsen