Skip to content

Improve developer experience - #230

Closed
EarlMilktea wants to merge 26 commits into
masterfrom
improve-dx
Closed

Improve developer experience#230
EarlMilktea wants to merge 26 commits into
masterfrom
improve-dx

Conversation

@EarlMilktea

@EarlMilkteaEarlMilktea commented Nov 1, 2024

Copy link
Copy Markdown
Contributor

Description of the change:

  • List all the CI configs. in noxfile.py
  • Setup pre-commit
  • Update ruff config.

@EarlMilkteaEarlMilktea self-assigned this Nov 1, 2024
@codecov

codecovBot commented Nov 1, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 86.36364% with 6 lines in your changes missing coverage. Please review.

Project coverage is 78.66%. Comparing base (7da2095) to head (a84830d).

Files with missing linesPatch %Lines
graphix/gflow.py50.00%3 Missing ⚠️
graphix/pattern.py75.00%2 Missing ⚠️
graphix/device_interface.py0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## master #230 +/- ##
==========================================
- Coverage 78.99% 78.66% -0.34% 
==========================================
Files 40 40 Lines 6113 5976 -137 ==========================================
- Hits 4829 4701 -128 + Misses 1284 1275 -9 

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

@EarlMilktea
EarlMilktea marked this pull request as ready for review November 1, 2024 11:55

@thierry-martinezthierry-martinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks. Some minor remarks.

Comment threadgraphix/gflow.py Outdated
Comment threadgraphix/gflow.py Outdated
Comment threadgraphix/sim/density_matrix.py
Co-authored-by: thierry-martinez <thierry.martinez@inria.fr>

@shinich1shinich1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks! could you add instruction to use pre-commit in CONTRIBUTING.md? brief description with pointing to a good online page is ok. anything else we need to elaborate in the contribution guide?

@EarlMilktea

Copy link
Copy Markdown
ContributorAuthor

CONTRIBUTING.md is already updated to use pre-commit instead of ruff (may need to add more though).

@EarlMilktea

Copy link
Copy Markdown
ContributorAuthor

@thierry-martinez

@thierry-martinezthierry-martinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is a regression in to_qasm3, and some minor remarks.

hooks:
- id: ruff
name: ruff-isort
args: [--fix, --select, I]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe the developer experience will improve without --fix:

  • When executed as a GitHub Action, messages for fixed errors are hidden, rendering the output unhelpful.
  • When executed locally, making changes to the unstaged area during a commit operation is counterintuitive. Developers are better off explicitly running ruff --fix to apply auto-fix changes when errors are reported.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

When executed as a GitHub Action, messages for fixed errors are hidden, rendering the output unhelpful.
When executed locally, making changes to the unstaged area during a commit operation is counterintuitive. Developers are better off explicitly running ruff --fix to apply auto-fix changes when errors are reported.

Agree, but if so I feel pre-commit may not be the best choice as its strength comes from env. isolation feature (it does not contaminate venv with CI deps.) while your comments suggest that we'd better invoke ruff manually by hand.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can have the best of both worlds: pre-commit is useful for running local checks automatically and ensuring consistency with CI, while manually running ruff --fix is helpful for applying trivial fixes quickly. Under the rules proposed in this PR, developers would still need to invoke ruff --fix to automatically address errors outside the I group.

I believe it’s best to start with the single hook below, which offers clearer error messages and fewer surprises, and then leave room for further improvements if we later agree on additional hooks.

 - id: ruff

- id: ruff
name: ruff-isort
args: [--fix, --select, I]
- id: ruff

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why separate I from the rest? If the sole reason is --fix, I believe we can safely merge the two rules by removing --fix.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

This mimics the default behavior of isort.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This thread is related to the above discussion: #230 (comment)

Comment threadCONTRIBUTING.md
pre-commit run -a
```

and you are ready to commit the changes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We could add the note: 'If ruff check reports that some errors can be automatically fixed, you can rerun it with the --fix option: ruff check --fix.'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This thread is related to the above discussion: #230 (comment)

Comment threadgraphix/device_interface.py
Comment threadgraphix/pattern.py Outdated
Comment on lines +1 to +41
files-typed: &files-typed "^(\
graphix/channels|\
graphix/clifford|\
graphix/command|\
graphix/fundamentals|\
graphix/instruction|\
graphix/linalg_validations|\
graphix/measurements|\
graphix/ops|\
graphix/pauli|\
graphix/pyzx|\
graphix/rng|\
graphix/states|\
graphix/utils|\
graphix/_db|\
noxfile|\
setup.py|\
tests/conftest|\
tests/test_clifford|\
tests/test_command|\
tests/test_db|\
tests/test_fundamentals|\
tests/test_kraus|\
tests/test_pauli|\
tests/test_pyzx|\
tests/test_rng\
.*/__init__|\
).py$"

deps-typecheck:
&deps-typecheck [
"nox",
"numpy",
"psutil",
"pydantic",
"pytest",
"pytest-mock",
"pyzx",
"types-networkx",
"types-psutil",
]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Defining files-typed and deps-typecheck at root triggers the following warnings:

[WARNING] Unexpected key(s) present at root: deps-typecheck, files-typed

I propose to inline them in the first occurrence of their use: 17bbdd9

Co-authored-by: thierry-martinez <thierry.martinez@inria.fr>
thierry-martinez added a commit to thierry-martinez/graphix that referenced this pull request Jan 6, 2025
In the discussion on TeamGraphix#230, there was a comment about improving the
device interface implementation (see
TeamGraphix#230 (comment)
).
In particular, I removed the `except Exception` path, being unable to
reproduce an example where this path is reached. If we want to handle
some errors (such as `TranspilerError`?), we should be more specific.
This was referenced Jan 6, 2025
@EarlMilktea

Copy link
Copy Markdown
ContributorAuthor

Let me close this PR as I no longer feel this PR will contribute to better DX.

@EarlMilktea
EarlMilktea deleted the improve-dx branch January 25, 2025 14:36
Sign up for freeto 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

@EarlMilktea@thierry-martinez@shinich1