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

Make it possible to set parameters as attribues and document these using a parser #3188

Conversation

jenshnielsen
Copy link
Collaborator

@jenshnielsen jenshnielsen commented Jul 8, 2021

This is an alternative suggestion to #3098. Since #32 was solved by #3125 I consider that out of scope for both these prs.

This enables parameters to be expressed as attributes on the instrument directly without having to call add_parameter. This has the advantage that the code exactly matches what one would expect a parameter to be namely an attribute on the instrument.

Sphinx automatically documents attributes if they have a docstring enabling this to fix #1151 However the documentation for instance attributes is less than ideal by default. This therefor also includes a very early proof of concept sphinx extension that instantiates parameter attributes when calling getattr on an instrument. It does this by parsing the code and extracting any argument that contains self (since the instrument class cannot be instantiated) and then instantiating the parameter without these.

The attributes are documented via their __repr__ which has been overwritten here to prove the concept.
This parser would need significant further work. One could either do

Compared to the old way of add_parameter this has a few disadvantages.

  • One must explicitly pass self as instrument to the parameter.
  • Name is repeated both as the attribute name and as the name passed to the parameter.

I do however feel that the added clarity of the code more that out ways these issues.

Note that some tests fail due to the change in repr.
If we go down this route we should probably do the same for qcodes functions and submodules eventually.

and port two drivers to match the new parameter registration
@jenshnielsen jenshnielsen force-pushed the make_parameter_attrs_on_instr_with_docs branch from 41427ab to e0cc71d Compare July 22, 2021 15:36
@jenshnielsen
Copy link
Collaborator Author

replaced by #3224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract doc strings from dynanically added paramters
2 participants