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

feat: add gate class docs to the subroutines in circuits #800

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AbeCoull
Copy link
Contributor

Issue #, if available:

Description of changes:

Testing done:

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (788b198) 100.00% compared to head (274763e) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #800   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          129       129           
  Lines         8519      8520    +1     
  Branches      1905      1905           
=========================================
+ Hits          8519      8520    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

function_docstring = (
"\n\n".join([cls_docstring, func.__doc__]) if len(cls_docstring) > 0 else func.__doc__
)
setattr(function_attr, "__doc__", function_docstring)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you whether setting __doc__ in this way allows the docstring to appear in IDEs such as VS Code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have VSCode setup so I am unsure at the moment.

@AbeCoull AbeCoull marked this pull request as ready for review December 22, 2023 16:02
@AbeCoull AbeCoull requested a review from a team as a code owner December 22, 2023 16:02
@@ -84,13 +84,15 @@ class Circuit:
_ALL_QUBITS = "ALL" # Flag to indicate all qubits in _qubit_observable_mapping

@classmethod
def register_subroutine(cls, func: SubroutineCallable) -> None:
def register_subroutine(cls, func: SubroutineCallable, cls_docstring: str) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this should be str | None and default to None? For backward compatibility reasons it seems like it needs a default value.

setattr(function_attr, "__doc__", func.__doc__)
# docstrings don't like a single newline for some reason.
function_docstring = (
"\n\n".join([cls_docstring, func.__doc__]) if len(cls_docstring) > 0 else func.__doc__
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"\n\n".join([cls_docstring, func.__doc__]) if len(cls_docstring) > 0 else func.__doc__
"\n\n".join([cls_docstring, func.__doc__]) if cls_docstring else func.__doc__

@@ -1522,13 +1528,15 @@ def __call__(self, arg: Any | None = None, **kwargs) -> Circuit:
return self.make_bound_circuit(param_values)


def subroutine(register: bool = False) -> Callable:
def subroutine(register: bool = False, cls_docstring: str = "") -> Callable:
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be str | None and default to None? Just to avoid a potential usage mistake, seems like None and "" should behave the same way here.

@@ -90,7 +90,7 @@ def fixed_qubit_count() -> int:
return 1

@staticmethod
@circuit.subroutine(register=True)
@circuit.subroutine(register=True, cls_docstring=__doc__)
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to only add this to the h gate, or do you also want to add this to the rest of the gates?

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.

2 participants