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

Repeated Capabilites documentation improvements #1686

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

ni-jfitzger
Copy link
Collaborator

@ni-jfitzger ni-jfitzger commented Jan 21, 2022

  • This contribution adheres to CONTRIBUTING.md.
  • I've updated CHANGELOG.md if applicable.
  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

There are several issues open against the way we document usage of repeated capabilities in our rep_caps.rst pages.

Summary of Issues

  • We present implementation details that the user doesn't care about
    • These may be useful to contributors, but to everyone else they're just distracting.
  • We list all of the possible types that can be passed to the indexing operator but don't make it clear what the recommended or "pythonic" types are.
    • This information is worth keeping, but we need to provide better guidance.
  • We use channel_enabled in all of our examples, though it may not actually support the repeated capability in the example code and not all apis have a channel_enabled property.

This PR addresses these by doing the following:

  • Explicitly recommend what types to pass to the indexing operator.
  • Present examples which demonstrate accessing the repeated capability with some of our recommended types.
    • Do not present examples using other types.
  • Specify fields in metadata used to build real examples specific to each rep cap
    • New helper functions were added to return the snippet and explanation for each example

List issues fixed by this Pull Request below, if any.

What testing has been done?

Local code generation with documentation inspection.

There are several issues open against the way we document usage of
repeated capabilites in our rep_caps.rst pages.

Summary of Issues
* We present implementation details that the user doesn't care about
  - These may be useful to contributors, but to everyone else they're just distracting.
* We list all of the possible types that can be passed to the indexing operator but don't make it clear what the recommend or "python" types are.
  - This information is worth keeping, but we need to provide better guidance.
* We use channel_enabled in all of our examples, though it may not actually support the repeated capability in the example code.

The approach to fixing this is as follows:
* Turn documentation related to implementation details into comments only viewable in the raw source
* Explicilty recommend what types to pass to the indexing operator.
* Present examples which demonstrate accessing the repeated capability with our recommended types.
  - Do not present examples using other types.
* Add a note that channel_enabled may not actually supported the repeated capability and to check individual property and method documentation.
passes a string of :python:`'${prefix}0, ${prefix}1, ${prefix}2'` to the set attribute function.
session.${name}[0:2].channel_enabled = True

sets :py:attr:`channel_enabled` to :python:`True` for ${name} 0, 1, 2.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I add anything to the recommend types above, I should add an example usage, here.

@nimi-bot
Copy link

Can one of the admins verify this patch?

@ni-jfitzger
Copy link
Collaborator Author

I haven't committed the results of tox -e codegen.
I can do that when there's agreement on the contents of rep_caps.rst.mako.

@marcoskirsch
Copy link
Member

I haven't committed the results of tox -e codegen.
I can do that when there's agreement on the contents of rep_caps.rst.mako.

No, please commit them before the PR is ready for review so we can see the effects and merge without having to track anything.

@ni-jfitzger
Copy link
Collaborator Author

committed the results of tox-e codegen as requested.

docs/nidcpower/rep_caps.rst Show resolved Hide resolved
docs/nidcpower/rep_caps.rst Outdated Show resolved Hide resolved
docs/nidcpower/rep_caps.rst Outdated Show resolved Hide resolved
docs/nidcpower/rep_caps.rst Outdated Show resolved Hide resolved
build/templates/rep_caps.rst.mako Outdated Show resolved Hide resolved
build/templates/rep_caps.rst.mako Outdated Show resolved Hide resolved

Some repeated capabilities use a prefix before the number and this is optional
The recommended way of accessing repeated capabilities is with an integer :python:`[0]` or range :python:`[0:2]`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

range :python:[0:2]

I don't think this will work since this is not the correct syntax for Python range. But ['0:2'] will work because of the custom logic we have for handling range-based strings.

Having said that, I don't think any of the ways I've enumerated above can be recommended over others. int is obviously the go-to for single instances. Basic sequence types and slice are good to use because they're part of the language, Range-based strings provides syntactic sugar for defining ranges. e.g. ['0:2'] rather than [range(0,2)].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see @marcoskirsch doesn't like us to recommend the range-based strings. Since I saw we had logic specifically for handling it, I thought it was important. But it sounds like it was ill-conceived. I don't mind not documenting it.

Once we land on recommended ways, we should go over the examples to ensure only recommended types are used.

build/templates/rep_caps.rst.mako Outdated Show resolved Hide resolved
build/templates/rep_caps.rst.mako Outdated Show resolved Hide resolved
build/templates/rep_caps.rst.mako Outdated Show resolved Hide resolved

Some repeated capabilities use a prefix before the number and this is optional
The recommended way of accessing multiple repeated capabilites at once is with a tuple (:python:`[0, 1]` or :python:`['Dev1', 'Dev2']`) or slice :python:`[0:2]`.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not currently providing slice usage examples. Let me know if you want me to add them.

Copy link
Member

@marcoskirsch marcoskirsch Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be nice.
I wonder if we should change wording to say that it should be an iterable rather than provide examples of iterables. Or at least it should be :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we already mention supported values above:

Use the indexing operator [] to indicate which repeated capability instance you are trying to access. The parameter can be a single element or an iterable that implements sequence semantics, like list, tuple, range and slice.

I guess it wouldn't hurt, to keep this part more generic, though, especially given our examples below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still undocumented: rep cap chaining.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

different issue/pr?

docs/nidcpower/rep_caps.rst Outdated Show resolved Hide resolved
Use the indexing operator :python:`[]` to indicate which repeated capability instance you are trying to access.
The parameter can be a single element or an iterable that implements sequence semantics, like list, tuple, range and slice.

The recommended way of accessing a single repeated capability is with an integer :python:`[0]` for capabilities that support it and a string :python:`['Dev1']`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all the repeated capabilities we have in nimi-python, at least at the moment, work with integers with the exception of instruments.

I wonder if we should remove this sentence, and instead where we list the repeated capabilites we tell you that the index should be an integer or an iterable of integers (or strings).

We can deduce which one it would be programmatically by looking at the metadata, specifically the rep cap prefix.


passes a string of :python:`'0, 1, 2'` to the set attribute function.
session.channels[0, 2].output_function = nidcpower.OutputFunction.DC_CURRENT

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is where we could add an example using an iterable, below line 42?

session.channles[range(3)].output_function = nidcpower.OutputFunction.DC_CURRENT


passes a string of :python:`'0, 1, 2'` to the set attribute function.
print(session.instruments['Dev1', 'Dev2', '3rdDevice'].serial_number)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found 3rdDevice confusing. Do we even allow aliases that begin with a number?

Consider using values closer to the defaults customers would encounter:

['PXI1Slot3', 'PXI1Slot4', 'PXI1Slot5']

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do allow aliases that begin with a number, yes. They don't have to have letters, at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found 3rdDevice confusing.

I just didn't want users to think it had to start with "Dev". I have the same concern with the examples you gave.
Maybe my blurb about the basic element should specify "device alias string" for instruments?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, just use something that matches defaults. This will be informative enough and not confused anyone.

Maybe my blurb about the basic element should specify "device alias string" for instruments?

I question how familiar customers are with term "device alias". It's certainly not in our APIs. Let's avoid,

#. pattern_opcode_events_
#. conditional_jump_triggers_
#. sites_
#. rio_events_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this... are the RIO triggers and events usable from Python at all in an application?

Copy link
Collaborator Author

@ni-jfitzger ni-jfitzger Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are. We test it:

def test_rio_events_rep_cap(self, single_instrument_session):

def test_rio_triggers_rep_cap(self, single_instrument_session):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They work. But are they actually useful in an application? Given that there is no LVFPGA support in Python.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, maybe not.
I can create an issue to remove them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They work. But are they actually useful in an application? Given that there is no LVFPGA support in Python.

I think there is support.
https://github.com/ni/nifpga-python

src/niscope/metadata/config_addon.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants