diff --git a/.github/workflows/module-validation.yml b/.github/workflows/module-validation.yml
new file mode 100644
index 00000000000..0db4f16faeb
--- /dev/null
+++ b/.github/workflows/module-validation.yml
@@ -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
+
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f8b9dde6e0e..ee6af757860 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -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
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index efbcf60b525..1804494a8ae 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -35,6 +35,9 @@
Improvements ðŸ›
+* 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)
diff --git a/pennylane/labs/README.md b/pennylane/labs/README.md
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/pennylane/labs/__init__.py b/pennylane/labs/__init__.py
index 000ba111704..c2c712317c0 100644
--- a/pennylane/labs/__init__.py
+++ b/pennylane/labs/__init__.py
@@ -13,3 +13,6 @@
# limitations under the License.
""":code:`pennylane/labs/` module contains experimental features enabling
advanced quantum computing research."""
+
+
+__all__ = []
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 2ddcf901667..65652b401ad 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -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
diff --git a/requirements.txt b/requirements.txt
index b5ab79f1a7d..5d7095cc5c3 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -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
diff --git a/tach.toml b/tach.toml
new file mode 100644
index 00000000000..42866f205c7
--- /dev/null
+++ b/tach.toml
@@ -0,0 +1,16 @@
+exclude = [
+ ".*__pycache__",
+ ".*egg-info",
+ "docs",
+ "tests",
+]
+source_roots = [
+ ".",
+ "pennylane",
+]
+
+[[modules]]
+path = "pennylane.labs"
+depends_on = [
+ { path = "" },
+]