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

Enabling Ruff as code linter #139

Merged
merged 6 commits into from
Dec 9, 2024
Merged

Enabling Ruff as code linter #139

merged 6 commits into from
Dec 9, 2024

Conversation

jesus-talavera-ibm
Copy link
Contributor

@jesus-talavera-ibm jesus-talavera-ibm commented Dec 4, 2024

Summary

This PR enables ruff https://github.com/astral-sh/ruff as a code linter for the project

Details and comments

After enabling ruff, this PR includes all the relevant fixes to make the ruff checker to pass

Based on: #48

Copy link
Collaborator

@victor-villar victor-villar left a comment

Choose a reason for hiding this comment

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

Thanks!
I think we can get rid of some of the ruff issues. Some solutions in the review.

@@ -383,7 +381,7 @@ def __init__(
local_mode: bool = False,
**kwargs,
) -> None:
if local_mode == True:
if local_mode == True: # noqa:E712
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we do the recommended fix: if local_mode ?

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 guess that here we want to check also that local_mode is a boolean, just in case local_mode is another type (a string with value "false", for example) and Python can process it as a truthy value.
Maybe adding something like:

 if isinstance(local_mode, bool) and local_mode:

could work

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, we could do it but in the parent class we only check if local_mode: and we are specifying in the arguments that it should be a boolean, so I won't check if it is a boolean. You can leave the # noqa if you prefer.

Comment on lines 64 to 67
rand_lin = lambda seed: LinearFunction( # noqa:E731
random_invertible_binary_matrix(n_qubits, seed=seed)
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's fix this function. Tome it looks like we can simply do:

def create_random_linear_function(n_qubits: int, seed: int = 123) -> LinearFunction:
    return LinearFunction(random_invertible_binary_matrix(n_qubits, seed=seed))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

Comment on lines 71 to 77
def random_clifford_from_linear_function(n_qubits: int, seed: int = 123):
"""Generate a random clifford from a random linear function of n_qubits qubits."""

random_linear = lambda seed: LinearFunction(
random_linear = lambda seed: LinearFunction( # noqa:E731
random_invertible_binary_matrix(n_qubits, seed=seed)
)
random_clifford = Clifford(random_linear(seed))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly, we can do here:

def random_clifford_from_linear_function(n_qubits: int, seed: int = 123):
    """Generate a random clifford from a random linear function of n_qubits qubits."""

    random_linear = LinearFunction(
        random_invertible_binary_matrix(n_qubits, seed=seed)
    )
    return Clifford(random_linear)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

victor-villar
victor-villar previously approved these changes Dec 9, 2024
This reverts commit 69b8c83.
@jesus-talavera-ibm jesus-talavera-ibm merged commit 23b1ee0 into main Dec 9, 2024
2 of 4 checks passed
@jesus-talavera-ibm jesus-talavera-ibm deleted the jt-adding-ruff branch December 9, 2024 14:51
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