|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | | -"""Test for qml.specs() Catalyst integration""" |
| 14 | +"""Tests for qml.specs() Catalyst integration""" |
| 15 | + |
15 | 16 | import pennylane as qml |
16 | 17 | import pytest |
17 | 18 | from jax import numpy as jnp |
|
21 | 22 | # pylint:disable = protected-access,attribute-defined-outside-init |
22 | 23 |
|
23 | 24 |
|
| 25 | +# TODO: Remove this method once feature parity has been reached, and instead use `==` directly |
24 | 26 | def check_specs_same(specs1, specs2): |
25 | 27 | """Check that two specs dictionaries are the same.""" |
26 | 28 | 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"] |
30 | 31 |
|
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 |
35 | 34 |
|
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 |
40 | 41 |
|
41 | 42 |
|
42 | 43 | @pytest.mark.parametrize("level", ["device"]) |
@@ -85,14 +86,9 @@ def circuit(): |
85 | 86 |
|
86 | 87 | assert cat_specs["device_name"] == "lightning.qubit" |
87 | 88 |
|
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 | | - |
93 | 89 | # Catalyst will handle Adjoint(PauliY) == PauliY |
94 | 90 | 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[ |
96 | 92 | "CY" |
97 | 93 | ] |
98 | 94 | del cat_specs["resources"].gate_types["CY"] |
|
0 commit comments