Skip to content

Commit

Permalink
Add preliminary support for qml.labs module sandboxing (#6369)
Browse files Browse the repository at this point in the history
### Before submitting

Please complete the following checklist when submitting a PR:

- [x] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      test directory!

- [x] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [x] Ensure that the test suite passes, by running `make test`.

- [x] Add a new entry to the `doc/releases/changelog-dev.md` file,
summarizing the
      change, and including a link back to the PR.

- [x] The PennyLane source code conforms to
      [PEP8 standards](https://www.python.org/dev/peps/pep-0008/).
We check all of our code against [Pylint](https://www.pylint.org/).
      To lint modified files, simply `pip install pylint`, and then
      run `pylint pennylane/path/to/file.py`.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:** This PR adds `tach` as a development dependency to ensure
`qml.labs` additions do not migrate into mainline PennyLane.

**Description of the Change:** Configs are added to restrict this
library wide, with pre-commit hook support added to prevent additions
going upstream.

**Benefits:** Prevents `qml.labs` additions entering into the main
PennyLane library.

**Possible Drawbacks:** Currently requires explicit use of pre-commit
hooks. CI settings and partitioning to follow.

**Related GitHub Issues:**

---------

Co-authored-by: Rashid N H M <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
  • Loading branch information
3 people authored Oct 10, 2024
1 parent 06129a0 commit dbb64fb
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/module-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Validate module imports

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

tach:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5

with:
python-version: "3.10"

- name: Install dependencies
run: pip install tach==0.13.1

- name: Run tach
run: |
tach report pennylane/labs
tach check
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ repos:
"--filter-files",
]
files: ^(pennylane/|tests/)
- repo: https://github.com/gauge-sh/tach-pre-commit
rev: v0.13.1
hooks:
- id: tach
- repo: local
hooks:
- id: pylint
Expand Down
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

<h3>Improvements 🛠</h3>

* Module-level sandboxing added to `qml.labs` via pre-commit hooks.
[(#6369)](https://github.com/PennyLaneAI/pennylane/pull/6369)

* `qml.matrix` now works with empty objects (such as empty tapes, `QNode`s and quantum functions that do
not call operations, single operators with empty decompositions).
[(#6347)](https://github.com/PennyLaneAI/pennylane/pull/6347)
Expand Down
Empty file added pennylane/labs/README.md
Empty file.
3 changes: 3 additions & 0 deletions pennylane/labs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
# limitations under the License.
""":code:`pennylane/labs/` module contains experimental features enabling
advanced quantum computing research."""


__all__ = []
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ tomli~=2.0.0 # Drop once minimum Python version is 3.11
isort==5.13.2
pylint==2.7.4
rich>=13.7.1
tach==0.13.1
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ opt_einsum~=3.3
requests~=2.31.0
typing_extensions~=4.5.0
tomli~=2.0.0 # Drop once minimum Python version is 3.11
tach~=0.13.1
16 changes: 16 additions & 0 deletions tach.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exclude = [
".*__pycache__",
".*egg-info",
"docs",
"tests",
]
source_roots = [
".",
"pennylane",
]

[[modules]]
path = "pennylane.labs"
depends_on = [
{ path = "<root>" },
]

0 comments on commit dbb64fb

Please sign in to comment.