Skip to content

Commit a795dbc

Browse files
jzaia18mudit2812
andauthored
Update specs tests to match new qml.specs output types (#2255)
**Context:** [This PR](PennyLaneAI/pennylane#8713) in PennyLane changes how `qml.specs` returns its results. This will break some integration tests within Catalyst. **Description of the Change:** Updates tests within `frontend/test/pytest/test_specs.py` to account for the new `qml.specs` output format. **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** PennyLaneAI/pennylane#8713 [sc-104965] --------- Co-authored-by: Mudit Pandey <[email protected]>
1 parent af3e13b commit a795dbc

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

.dep-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ enzyme=v0.0.203
1010

1111
# For a custom PL version, update the package version here and at
1212
# 'doc/requirements.txt'
13-
pennylane=0.44.0-dev48
13+
pennylane=0.44.0-dev50
1414

1515
# For a custom LQ/LK version, update the package version here and at
1616
# 'doc/requirements.txt'

doc/releases/changelog-dev.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@
366366

367367
<h3>Internal changes ⚙️</h3>
368368

369+
* Integration tests for `qml.specs` have been updated to match the new output format introduced
370+
in PennyLane.
371+
[(#2255)](https://github.com/PennyLaneAI/catalyst/pull/2255)
372+
369373
* Resource tracking now writes out at device destruction time instead of qubit deallocation
370374
time. The written resources will be the total amount of resources collected throughout the
371375
lifetime of the execution. For executions that split work between multiple functions,

doc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ lxml_html_clean
3333
--extra-index-url https://test.pypi.org/simple/
3434
pennylane-lightning-kokkos==0.44.0-dev16
3535
pennylane-lightning==0.44.0-dev16
36-
pennylane==0.44.0-dev48
36+
pennylane==0.44.0-dev50

frontend/test/pytest/test_specs.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""Test for qml.specs() Catalyst integration"""
14+
"""Tests for qml.specs() Catalyst integration"""
15+
1516
import pennylane as qml
1617
import pytest
1718
from jax import numpy as jnp
@@ -21,22 +22,22 @@
2122
# pylint:disable = protected-access,attribute-defined-outside-init
2223

2324

25+
# TODO: Remove this method once feature parity has been reached, and instead use `==` directly
2426
def check_specs_same(specs1, specs2):
2527
"""Check that two specs dictionaries are the same."""
2628
assert specs1["device_name"] == specs2["device_name"]
27-
assert specs1["resources"].num_wires == specs2["resources"].num_wires
28-
assert specs1["resources"].num_gates == specs2["resources"].num_gates
29-
assert specs1["resources"].depth == specs2["resources"].depth
29+
assert specs1["num_device_wires"] == specs2["num_device_wires"]
30+
assert specs1["shots"] == specs2["shots"]
3031

31-
assert len(specs1["resources"].gate_types) == len(specs2["resources"].gate_types)
32-
for gate, count in specs1["resources"].gate_types.items():
33-
assert gate in specs2["resources"].gate_types
34-
assert count == specs2["resources"].gate_types[gate]
32+
assert specs1["resources"].gate_types == specs2["resources"].gate_types
33+
assert specs1["resources"].gate_sizes == specs2["resources"].gate_sizes
3534

36-
assert len(specs1["resources"].gate_sizes) == len(specs2["resources"].gate_sizes)
37-
for gate, count in specs1["resources"].gate_sizes.items():
38-
assert gate in specs2["resources"].gate_sizes
39-
assert count == specs2["resources"].gate_sizes[gate]
35+
# Measurements are not yet supported in Catalyst device-level specs
36+
# assert specs1["resources"].measurements == specs2["resources"].measurements
37+
38+
assert specs1["resources"].num_allocs == specs2["resources"].num_allocs
39+
assert specs1["resources"].depth == specs2["resources"].depth
40+
assert specs1["resources"].num_gates == specs2["resources"].num_gates
4041

4142

4243
@pytest.mark.parametrize("level", ["device"])
@@ -85,14 +86,9 @@ def circuit():
8586

8687
assert cat_specs["device_name"] == "lightning.qubit"
8788

88-
# Catalyst level specs should report the number of controls for multi-controlled gates
89-
assert "2C(S)" in cat_specs["resources"].gate_types
90-
cat_specs["resources"].gate_types["C(S)"] += cat_specs["resources"].gate_types["2C(S)"]
91-
del cat_specs["resources"].gate_types["2C(S)"]
92-
9389
# Catalyst will handle Adjoint(PauliY) == PauliY
9490
assert "CY" in cat_specs["resources"].gate_types
95-
cat_specs["resources"].gate_types["C(Adjoint(PauliY))"] += cat_specs["resources"].gate_types[
91+
cat_specs["resources"].gate_types["C(Adjoint(PauliY))"] = cat_specs["resources"].gate_types[
9692
"CY"
9793
]
9894
del cat_specs["resources"].gate_types["CY"]

0 commit comments

Comments
 (0)