Repository: PennyLaneAI/pennylane
Pull request #6912 (2025-01-31 18:41:55)

Add FTQC bare module
### 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`.

- [ ] 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:** Adds an experimental `ftqc` module to PennyLane.

**Description of the Change:** Added new bare module `ftqc`. Added updates to `tach.toml` to ensure use of `ftqc` module does not propagate outside the module, or a user example:
e.g. adding `from pennylane.ftqc import *` to `operation.py` yields:
```bash
❌ pennylane/operation.py[L242]: Cannot import 'pennylane.ftqc.*'. Module '<root>' cannot depend on 'pennylane.ftqc'.
```

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**


github-actions[bot]: Hello. You may have forgotten to update the changelog!
Please edit [`doc/releases/changelog-dev.md`](/PennyLaneAI/pennylane/blob/master/doc/releases/changelog-dev.md) with:
* A one-to-two sentence description of the change. You may include a small working example for new features.
* A link back to this PR.
* Your name (or GitHub username) in the contributors section.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/6912?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) Report
Attention: Patch coverage is `0%` with `4 lines` in your changes missing coverage. Please review.
> Project coverage is 99.39%. Comparing base [(`5f813c2`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/5f813c2ceaaa1141c6f2d1f5111257791401f1b2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) to head [(`4a06e84`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/4a06e84035d132fe803d8f86113b9faa8806638c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).
> Report is 3 commits behind head on master.

| [Files with missing lines](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/6912?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) | Patch % | Lines |
|---|---|---|
| [pennylane/ftqc/\_\_init\_\_.py](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/6912?src=pr&el=tree&filepath=pennylane%2Fftqc%2F__init__.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI#diff-cGVubnlsYW5lL2Z0cWMvX19pbml0X18ucHk=) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/6912?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #6912      +/-   ##
==========================================
- Coverage   99.59%   99.39%   -0.21%     
==========================================
  Files         479      480       +1     
  Lines       45316    45467     +151     
==========================================
+ Hits        45134    45192      +58     
- Misses        182      275      +93     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/6912?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).


Patch:
diff --git a/.github/workflows/module-validation.yml b/.github/workflows/module-validation.yml
index 66af8bc21..e9f8c3189 100644
--- a/.github/workflows/module-validation.yml
+++ b/.github/workflows/module-validation.yml
@@ -31,10 +31,11 @@ jobs:
           python-version: "3.10"
 
       - name: Install dependencies
-        run: pip install tach==0.13.1
+        run: pip install tach==0.24.0
 
       - name: Run tach
         run: |
           tach report pennylane/labs
+          tach report pennylane/ftqc
           tach check
 
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index ddd2890a1..29a8ecccd 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -32,7 +32,7 @@ repos:
         ]
       files: ^(pennylane/|tests/)
 -   repo: https://github.com/gauge-sh/tach-pre-commit
-    rev: v0.13.1
+    rev: v0.24.0
     hooks:
     -   id: tach
 - repo: local
diff --git a/pennylane/__init__.py b/pennylane/__init__.py
index 6e8a8fe90..3f0399342 100644
--- a/pennylane/__init__.py
+++ b/pennylane/__init__.py
@@ -175,6 +175,10 @@ class PennyLaneDeprecationWarning(UserWarning):
     """Warning raised when a PennyLane feature is being deprecated."""
 
 
+class ExperimentalWarning(UserWarning):
+    """Warning raised to indicate experimental/non-stable feature or support."""
+
+
 def __getattr__(name):
 
     if name == "plugin_devices":
diff --git a/pennylane/ftqc/__init__.py b/pennylane/ftqc/__init__.py
new file mode 100644
index 000000000..5f8b65e45
--- /dev/null
+++ b/pennylane/ftqc/__init__.py
@@ -0,0 +1,37 @@
+# Copyright 2025 Xanadu Quantum Technologies Inc.
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+r"""
+.. currentmodule:: pennylane
+
+This module contains experimental features for supporting fault-tolerant workloads in PennyLane
+
+.. currentmodule:: pennylane.ftqc
+
+Modules
+~~~~~~~
+
+.. autosummary::
+    :toctree: api
+
+"""
+from warnings import warn
+from pennylane import ExperimentalWarning
+
+warn(
+    ExperimentalWarning(
+        "This module is currently experimental and will not maintain API stability between releases."
+    )
+)
+
+__all__ = []
diff --git a/tach.toml b/tach.toml
index 42866f205..dac414bdf 100644
--- a/tach.toml
+++ b/tach.toml
@@ -1,6 +1,7 @@
+interfaces = []
 exclude = [
-    ".*__pycache__",
-    ".*egg-info",
+    "**/*__pycache__",
+    "**/*egg-info",
     "docs",
     "tests",
 ]
@@ -8,9 +9,20 @@ source_roots = [
     ".",
     "pennylane",
 ]
+root_module = "allow"
+
+[[modules]]
+path = "<root>"
+depends_on = []
+
+[[modules]]
+path = "pennylane.ftqc"
+depends_on = [
+    "<root>",
+]
 
 [[modules]]
 path = "pennylane.labs"
 depends_on = [
-    { path = "<root>" },
+    "<root>",
 ]


Test patch:
diff --git a/tests/ftqc/test_import.py b/tests/ftqc/test_import.py
new file mode 100644
index 000000000..24569ef71
--- /dev/null
+++ b/tests/ftqc/test_import.py
@@ -0,0 +1,32 @@
+# Copyright 2018-2025 Xanadu Quantum Technologies Inc.
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Unit tests for the ftqc module import"""
+
+import pytest
+
+import pennylane as qml
+
+
+def test_import_warning():
+    """Test importing the module raises an experimental module warning."""
+
+    with pytest.warns(
+        qml.ExperimentalWarning,
+        match=r"This module is currently experimental",
+    ) as record:
+        # pylint: disable=import-outside-toplevel, unused-import
+        import pennylane.ftqc
+
+    assert len(record) == 1
+    assert "This module is currently experimental" in record[0].message.args[0]