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

[py][nfc] imports clean up. #2590

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

boschmitt
Copy link
Collaborator

@boschmitt boschmitt commented Feb 5, 2025

Description

Cleans up imports throughout the python runtime. I trie following the principles in PEP8.

The changes include:

  • Grouping imports two blocks: external and internal, w.r.t cudaq.
  • Not using relative paths when the module is in a parent dir (..)
  • Not using wildcard imports
  • Remove unused ones

@boschmitt boschmitt changed the title [py][nfc] imports clean up. [py][nfc] imports clean up. Feb 5, 2025
@boschmitt boschmitt force-pushed the nfc_python_cleanup branch 2 times, most recently from e997d80 to 77ba55a Compare February 5, 2025 22:39
Copy link

github-actions bot commented Feb 5, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Feb 5, 2025
Copy link

github-actions bot commented Feb 6, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Feb 6, 2025
Copy link

@iqbalbhatti49 iqbalbhatti49 left a comment

Choose a reason for hiding this comment

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

Good cleanup of imports! Well done following PEP8 principles.

Cleans up imports throughout the python runtime. I trie following
the principles in PEP8 (https://peps.python.org/pep-0008/#imports).

The changes include:
  * Grouping imports two blocks: external and internal, w.r.t cudaq.
  * Not using relative paths when the module is in a parent dir (`..`)
  * Not using wildcard imports
  * Removing unused ones

Signed-off-by: boschmitt <[email protected]>
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Feb 11, 2025
@@ -6,20 +6,36 @@
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
import ast
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think we are inconsistent with a blank line after the copyright banner and fist import.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, we don't seem to have any guideline regarding these things.

from typing import get_origin
import sys
import traceback
import numpy as np
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: Are the external imports sorted alphabetically?

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 was going for that but it's really an arbitrary decision. The only exception being from __future__ which is required to be the first.

from .schedule import Schedule
from .expressions import Operator
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime
from cudaq.mlir._mlir_libs._quakeDialects import cudaq_runtime
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: Is there relative ordering for the . imports and named internal imports?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should have. The idea was to have project imports followed by relative imports. Also, I did change things in a way that relative imports are only for modules within the same directory (so moving the whole directory wouldn't require changing the imports)

Copy link
Collaborator

@khalatepradnya khalatepradnya left a comment

Choose a reason for hiding this comment

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

Minor comments. LGTM.
Thanks, Bruno! 👍🏽

@khalatepradnya
Copy link
Collaborator

@boschmitt : In case you used a tool / script for this, can you share. Perhaps we can add that as part of CI ?

@schweitzpgi schweitzpgi added the maintenance Work items to update and improve the code base label Feb 14, 2025
@boschmitt
Copy link
Collaborator Author

@boschmitt : In case you used a tool / script for this, can you share. Perhaps we can add that as part of CI ?

I did it by hand while studying the code, so it is really a best-effort sort of thing and is not really free of inconsistencies.

Thanks for the review (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Work items to update and improve the code base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants