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

Adding pre-commit #628

Merged
merged 12 commits into from
Aug 5, 2022
Merged

Adding pre-commit #628

merged 12 commits into from
Aug 5, 2022

Conversation

scarrazza
Copy link
Member

Adding a basic pre-commit hook and applying black to all files.

@scarrazza
Copy link
Member Author

@stavros11 this is failing with a tsp+tensorflow issue, which looks familiar to me, do you remember if this is related to seeds?

@andrea-pasquale
Copy link
Contributor

Thanks for implementing this.
I have a few comments:

  • For now, are you happy with just adding black? Additionally we can include isort to fix the imports order.
  • Since this repository is public we can even add precommit to CI. With this we can either: (1) make CI fail if the user doesn't use the precommit hooks and/or (2) let the action automatically fix any issues with this (in this case we'll have an extra commit that follows the user commits).
  • I feel like we need to add somewhere in the docs that we are using pre-commit, under Developer guides probably.

@scarrazza
Copy link
Member Author

scarrazza commented Aug 4, 2022

@andrea-pasquale thanks for the comments.

For now, are you happy with just adding black? Additionally we can include isort to fix the imports order.

yes, but if you try here, you will see that qibo fails, due to circular import, so I think we can do that in another PR.

Since this repository is public we can even add precommit to CI. With this we can either: (1) make CI fail if the user doesn't use the precommit hooks and/or (2) let the action automatically fix any issues with this (in this case we'll have an extra commit that follows the user commits).

yes, I fully agree.

I feel like we need to add somewhere in the docs that we are using pre-commit, under Developer guides probably.

yes, absolutely.

@stavros11
Copy link
Member

Thanks for implementing this. I checked locally and it works for me.

  • Since this repository is public we can even add precommit to CI. With this we can either: (1) make CI fail if the user doesn't use the precommit hooks and/or (2) let the action automatically fix any issues with this (in this case we'll have an extra commit that follows the user commits).

I also agree with this. I think option (2) is more friendly for external developers, but we may get many additional commits if people push frequently (not sure if this is an issue).

  • I feel like we need to add somewhere in the docs that we are using pre-commit, under Developer guides probably.

I agree, we should add a related section in "How to contribute". We could also add the pre-commit libarary in setup.py as a requirement for the [tests] package, which is oriented towards developers.

@stavros11 this is failing with a tsp+tensorflow issue, which looks familiar to me, do you remember if this is related to seeds?

Yes, I was aware of this from other branches and I can get reproduce it locally. An easy fix is to set atol=1e-5 for this test, but before doing so I would like to understand better where this precision issue comes from and why it happens only with tensorflow, because it is a bit high to classify as numerical error. It should not be related to seeds as this test is not random since we removed the measurements and we are checking the state vector directly.

@andrea-pasquale
Copy link
Contributor

I've fixed the documentation and I've also added the pre-commit action.
@scarrazza I don't know if it will be enabled when we open another PR or if you as admin will need to install the Github action. I tried it to install the action but I think that I don't have the permissions.

@scarrazza
Copy link
Member Author

Thanks, I have granted permission, please try again now.

@andrea-pasquale
Copy link
Contributor

andrea-pasquale commented Aug 4, 2022

Now the action is there. I believe that it was failing because there were some conflicts.
If you want I can open a dummy PR and perform some checks.
EDIT: Do we actually want it to fail if there are conflicts or should we maybe remove this option?

@scarrazza
Copy link
Member Author

Sure, please go ahead, and indeed conflicts should not fail.

Copy link
Member

@stavros11 stavros11 left a comment

Choose a reason for hiding this comment

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

Thank you for all the updates and tests @andrea-pasquale. I think this can be merged.

@@ -45,6 +45,7 @@ The current code standards that are applied to any new changes:
- **Tests**: We use pytest to run our tests that must continue to pass when new changes are integrated in the code. Regression tests, which are run by the continuous integration workflow are stored in ``qibo/tests``. These tests contain several examples about how to use Qibo.
- **Coverage**: Test coverage should be maintained / be at least at the same level when new features are implemented.
- **Pylint**: Test code for anomalies, such as bad coding practices, missing documentation, unused variables.
- **Pre commit**: We use pre-commit to enforce automatation and to format the code.
Copy link
Member

Choose a reason for hiding this comment

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

Do you mean

Suggested change
- **Pre commit**: We use pre-commit to enforce automatation and to format the code.
- **Pre commit**: We use pre-commit to enforce automation and to format the code.

?

Perhaps we could also say that this is enforced automatically for all PRs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching this.
Yes that's what I meant :)
Now that we've enabled the pre-commit action I should probably update this line.

@scarrazza
Copy link
Member Author

@stavros11 please let me know when you are happy with the atol increase so we can merge this.

@scarrazza scarrazza marked this pull request as ready for review August 5, 2022 05:59
@codecov
Copy link

codecov bot commented Aug 5, 2022

Codecov Report

Merging #628 (40802bd) into master (1af0342) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #628   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           80        80           
  Lines        10342     10380   +38     
=========================================
+ Hits         10342     10380   +38     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/qibo/__init__.py 100.00% <ø> (ø)
src/qibo/backends/abstract.py 100.00% <ø> (ø)
src/qibo/gates/special.py 100.00% <ø> (ø)
src/qibo/hamiltonians/__init__.py 100.00% <ø> (ø)
src/qibo/models/__init__.py 100.00% <ø> (ø)
src/qibo/tests/test_dill.py 100.00% <ø> (ø)
src/qibo/tests/test_gates_special.py 100.00% <ø> (ø)
src/qibo/tests/test_models_circuit_qasm.py 100.00% <ø> (ø)
...rc/qibo/tests/test_models_distcircuit_execution.py 100.00% <ø> (ø)
src/qibo/tests/test_models_hep.py 100.00% <ø> (ø)
... and 106 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@scarrazza scarrazza merged commit 369e1cf into master Aug 5, 2022
@scarrazza scarrazza deleted the prehook branch August 17, 2022 07:21
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