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

unpin black, make code black-friendly #5119

Merged
merged 7 commits into from
Jan 31, 2024
Merged

unpin black, make code black-friendly #5119

merged 7 commits into from
Jan 31, 2024

Conversation

timmysilv
Copy link
Contributor

@timmysilv timmysilv commented Jan 29, 2024

Context:
See #5112. New version of black came out, and it auto-formatted a bunch of files. Most of these changes are backwards-compatible (with previous versions of black) but not all, so it was non-trivial

Description of the Change:
Did the following:

pip install -U black
make format
git add .
pip install black~=23.12
make format

At this point, all unstaged changes are non-backwards-compatible lines. So, I tweaked those lines, ran make format to make sure they were good with old black, then re-ran the above set of commands to ensure it's forwards-compatible too. I'll inline comment each actual change I made.

Benefits:

  • devs can use whatever version of black they choose, including the new one
  • less pinned packages == more pennylane spirit

Possible Drawbacks:
N/A

[sc-55823]

Copy link
Contributor Author

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

these are the only manual changes I had to make. for some reason they all just became outdated 😵‍💫 but this is the list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the versions disagreed on formatting empty functions with ..., but using pass should be the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same problem with ... vs pass

Comment on lines +102 to 107
coeff = np.sqrt(2 ** (1 - num_op_wires))
vector = np.array(
[
np.sqrt(2 ** (1 - num_op_wires))
* np.cos(-np.pi / 2 + np.pi * x / 2**num_op_wires)
coeff * np.cos(-np.pi / 2 + np.pi * x / 2**num_op_wires)
for x in range(2**num_op_wires)
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

factored out the coeff to make it work

Comment on lines 899 to 916
common_term = np.sqrt(
4 * eT2**2
+ 4 * p_reset**2 * pe**2
- 4 * p_reset**2 * pe
+ p_reset**2
+ np.eps
base = sum(
4 * eT2**2,
4 * p_reset**2 * pe**2,
-4 * p_reset**2 * pe,
p_reset**2,
np.eps,
)
common_term = np.sqrt(base)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

idk why but this worked

Copy link
Contributor Author

@timmysilv timmysilv Jan 29, 2024

Choose a reason for hiding this comment

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

put the for logic in each branch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

factored out the base in each test to make it happy

@timmysilv timmysilv requested a review from a team January 29, 2024 20:23
# pylint: disable=import-outside-toplevel,too-many-branches,not-callable,unexpected-keyword-arg
# pylint: disable=unused-argument,unnecessary-lambda-assignment,inconsistent-return-statements
# pylint: disable=invalid-unary-operand-type,isinstance-second-argument-not-valid-type
# pylint: disable=too-many-arguments,too-many-statements,function-redefined,too-many-function-args
Copy link
Contributor

Choose a reason for hiding this comment

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

😭

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 know... i just rearranged it, only added 2. but still

Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

Think I'm actually a fan of the new syntax for multi-line comprehensions.

@albi3ro albi3ro requested a review from a team January 29, 2024 21:29
Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (321ad70) 99.68% compared to head (3bd9444) 99.47%.
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5119      +/-   ##
==========================================
- Coverage   99.68%   99.47%   -0.22%     
==========================================
  Files         391      393       +2     
  Lines       35793    35713      -80     
==========================================
- Hits        35682    35524     -158     
- Misses        111      189      +78     

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

@timmysilv
Copy link
Contributor Author

the new changes from black have thrown codecov all out of sorts, will need a force-merge upon 2nd approval

Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

Thanks @timmysilv !

@albi3ro albi3ro merged commit f19d976 into master Jan 31, 2024
32 of 33 checks passed
@albi3ro albi3ro deleted the upgrade-black branch January 31, 2024 14:57
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.

3 participants