Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions frontend/test/pytest/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# 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.
"""Test for qml.specs() Catalyst integration"""
"""Tests for qml.specs() Catalyst integration"""

import pennylane as qml
import pytest
from jax import numpy as jnp
Expand All @@ -21,22 +22,22 @@
# pylint:disable = protected-access,attribute-defined-outside-init


# TODO: Remove this method once feature pairty has been reached, and instead use `==` directly
def check_specs_same(specs1, specs2):
"""Check that two specs dictionaries are the same."""
assert specs1["device_name"] == specs2["device_name"]
assert specs1["resources"].num_wires == specs2["resources"].num_wires
assert specs1["resources"].num_gates == specs2["resources"].num_gates
assert specs1["resources"].depth == specs2["resources"].depth
assert specs1["num_device_wires"] == specs2["num_device_wires"]
assert specs1["shots"] == specs2["shots"]

assert len(specs1["resources"].gate_types) == len(specs2["resources"].gate_types)
for gate, count in specs1["resources"].gate_types.items():
assert gate in specs2["resources"].gate_types
assert count == specs2["resources"].gate_types[gate]
assert specs1["resources"].gate_types == specs2["resources"].gate_types
assert specs1["resources"].gate_sizes == specs2["resources"].gate_sizes

assert len(specs1["resources"].gate_sizes) == len(specs2["resources"].gate_sizes)
for gate, count in specs1["resources"].gate_sizes.items():
assert gate in specs2["resources"].gate_sizes
assert count == specs2["resources"].gate_sizes[gate]
# Measurements are not yet supported in Catalyst device-level specs
# assert specs1["resources"].measurements == specs2["resources"].measurements

assert specs1["resources"].num_allocs == specs2["resources"].num_allocs
assert specs1["resources"].depth == specs2["resources"].depth
assert specs1["resources"].num_gates == specs2["resources"].num_gates


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

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

# Catalyst level specs should report the number of controls for multi-controlled gates
assert "2C(S)" in cat_specs["resources"].gate_types
cat_specs["resources"].gate_types["C(S)"] += cat_specs["resources"].gate_types["2C(S)"]
del cat_specs["resources"].gate_types["2C(S)"]

# Catalyst will handle Adjoint(PauliY) == PauliY
assert "CY" in cat_specs["resources"].gate_types
cat_specs["resources"].gate_types["C(Adjoint(PauliY))"] += cat_specs["resources"].gate_types[
cat_specs["resources"].gate_types["C(Adjoint(PauliY))"] = cat_specs["resources"].gate_types[
"CY"
]
del cat_specs["resources"].gate_types["CY"]
Expand Down
Loading