Skip to content

Commit 09107e1

Browse files
authored
Avoid decomposing unsupported Ops into QubitUnitary when not specified in the device TOML file (#1348)
**Context:** Avoid decomposing unsupported gates and templates into `QubitUnitary` when not specified in the device TOML file of Lightning simulators from Catalyst. re: PennyLaneAI/catalyst#2426 **Description of the Change:** - Skip the initialization of `_to_matrix_ops` when `QubitUnitary` is not in the list of supported ops in Lightning **Benefits:** - Enable decomposing to a custom target gateset without `QubitUnitary` when using Lightning simulators with `qml.qjit`. **Possible Drawbacks:** **Related GitHub Issues:** [sc-111263]
1 parent b41f32f commit 09107e1

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

.github/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
<h3>Improvements 🛠</h3>
1212

13+
- Avoid decomposing unsupported gates and templates into `QubitUnitary` when not specified in the device TOML file of Lightning simulators from Catalyst.
14+
[(#1348)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1348)
15+
1316
- Added sitemap configuration and SEO improvements to documentation, including noindex meta tags for C++ API reference pages.
1417
[(#1331)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1331)
1518

pennylane_lightning/core/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.45.0-dev20"
19+
__version__ = "0.45.0-dev21"

pennylane_lightning/lightning_gpu/lightning_gpu.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,20 @@ class LightningGPU(LightningBase):
159159
_CPP_BINARY_AVAILABLE = LGPU_CPP_BINARY_AVAILABLE
160160
_backend_info = backend_info if LGPU_CPP_BINARY_AVAILABLE else None
161161

162-
# TODO: This is to communicate to Catalyst in qjit-compiled workflows that these operations
163-
# should be converted to QubitUnitary instead of their original decompositions. Remove
164-
# this when customizable multiple decomposition pathways are implemented
165-
_to_matrix_ops = _to_matrix_ops
166-
167162
# This configuration file declares capabilities of the device
168163
config_filepath = Path(__file__).parent / "lightning_gpu.toml"
169164

165+
# TODO: This is to communicate to Catalyst in qjit-compiled workflows that these operations
166+
# should be converted to QubitUnitary instead of their original decompositions. Remove
167+
# this when the legacy decomposition system in Catalyst is integrated with the
168+
# graph-based decomposition system, which will allow for customizable multi-pathway.
169+
_to_matrix_ops = (
170+
_to_matrix_ops
171+
if "QubitUnitary"
172+
in qml.devices.capabilities.load_toml_file(config_filepath)["operators"]["gates"]
173+
else None
174+
)
175+
170176
def __init__( # pylint: disable=too-many-arguments
171177
self,
172178
wires: Union[int, List] = None,

pennylane_lightning/lightning_kokkos/lightning_kokkos.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,14 @@ class LightningKokkos(LightningBase):
136136

137137
# TODO: This is to communicate to Catalyst in qjit-compiled workflows that these operations
138138
# should be converted to QubitUnitary instead of their original decompositions. Remove
139-
# this when customizable multiple decomposition pathways are implemented
140-
_to_matrix_ops = _to_matrix_ops
139+
# this when the legacy decomposition system in Catalyst is integrated with the
140+
# graph-based decomposition system, which will allow for customizable multi-pathway.
141+
_to_matrix_ops = (
142+
_to_matrix_ops
143+
if "QubitUnitary"
144+
in qml.devices.capabilities.load_toml_file(config_filepath)["operators"]["gates"]
145+
else None
146+
)
141147

142148
def __init__( # pylint: disable=too-many-arguments
143149
self,

pennylane_lightning/lightning_qubit/lightning_qubit.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,14 @@ class LightningQubit(LightningBase):
155155

156156
# TODO: This is to communicate to Catalyst in qjit-compiled workflows that these operations
157157
# should be converted to QubitUnitary instead of their original decompositions. Remove
158-
# this when customizable multiple decomposition pathways are implemented
159-
_to_matrix_ops = _to_matrix_ops
158+
# this when the legacy decomposition system in Catalyst is integrated with the
159+
# graph-based decomposition system, which will allow for customizable multi-pathway.
160+
_to_matrix_ops = (
161+
_to_matrix_ops
162+
if "QubitUnitary"
163+
in qml.devices.capabilities.load_toml_file(config_filepath)["operators"]["gates"]
164+
else None
165+
)
160166

161167
def __init__( # pylint: disable=too-many-arguments
162168
self,

tests/test_device.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,14 @@ def test_supported_macos_platform_qubit():
245245

246246
assert dev_name == "LightningSimulator"
247247
assert "liblightning_qubit_catalyst.dylib" in shared_lib_name
248+
249+
250+
@pytest.mark.skipif(
251+
(device_name == "lightning.tensor"),
252+
reason="Lightning-Tensor is not integrated with Catalyst and doesn't support to_matrix_ops.",
253+
)
254+
def test_device_to_matrix_ops():
255+
"""Test that the device's to_matrix_ops capability is correctly set based on the config file."""
256+
dev = qml.device(device_name)
257+
to_mat_ops = dev._to_matrix_ops
258+
assert to_mat_ops is not None and isinstance(to_mat_ops, dict)

0 commit comments

Comments
 (0)