-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
qiskit_ibm_transpiler/utils.py
Outdated
rand_lin = lambda seed: LinearFunction( # noqa:E731 | ||
random_invertible_binary_matrix(n_qubits, seed=seed) | ||
) | ||
|
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
qiskit_ibm_transpiler/utils.py
Outdated
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)) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
This reverts commit 69b8c83.
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