Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default.tensor to setup.py #719

Merged
merged 12 commits into from
May 10, 2024
5 changes: 4 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* Add support for `qml.expval` and `qml.var` in the `lightning.tensor` device for the `quimb` interface and the MPS method.
[(#686)](https://github.com/PennyLaneAI/pennylane-lightning/pull/686)

* Changed the name of `lightning.tensor` to `default.tensor` with the `quimb` backend.
[(#719)](https://github.com/PennyLaneAI/pennylane-lightning/pull/719)

### Documentation

### Bug fixes
Expand All @@ -23,7 +26,7 @@

This release contains contributions from (in alphabetical order):

Amintor Dusko, Pietropaolo Frisoni, Vincent Michaud-Rioux
Amintor Dusko, Pietropaolo Frisoni, Vincent Michaud-Rioux, Mudit Pandey

---

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.37.0-dev3"
__version__ = "0.37.0-dev4"
14 changes: 7 additions & 7 deletions pennylane_lightning/lightning_tensor/lightning_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(
raise ValueError(f"Unsupported method: {method}")

if shots is not None:
raise ValueError("LightningTensor does not support finite shots.")
raise ValueError("default.tensor does not support finite shots.")

super().__init__(wires=wires, shots=shots)

Expand Down Expand Up @@ -143,13 +143,13 @@ def __init__(
for arg in kwargs:
if arg not in self._device_options:
raise TypeError(
f"Unexpected argument: {arg} during initialization of the LightningTensor device."
f"Unexpected argument: {arg} during initialization of the default.tensor device."
)

@property
def name(self):
"""The name of the device."""
return "lightning.tensor"
return "default.tensor"

@property
def num_wires(self):
Expand Down Expand Up @@ -266,7 +266,7 @@ def compute_derivatives(
Tuple: The Jacobian for each trainable parameter.
"""
raise NotImplementedError(
"The computation of derivatives has yet to be implemented for the lightning.tensor device."
"The computation of derivatives has yet to be implemented for the default.tensor device."
)

def execute_and_compute_derivatives(
Expand All @@ -284,7 +284,7 @@ def execute_and_compute_derivatives(
tuple: A numeric result of the computation and the gradient.
"""
raise NotImplementedError(
"The computation of derivatives has yet to be implemented for the lightning.tensor device."
"The computation of derivatives has yet to be implemented for the default.tensor device."
)

# pylint: disable=unused-argument
Expand Down Expand Up @@ -323,7 +323,7 @@ def compute_vjp(
tensor-like: A numeric result of computing the vector-Jacobian product.
"""
raise NotImplementedError(
"The computation of vector-Jacobian product has yet to be implemented for the lightning.tensor device."
"The computation of vector-Jacobian product has yet to be implemented for the default.tensor device."
)

def execute_and_compute_vjp(
Expand All @@ -344,5 +344,5 @@ def execute_and_compute_vjp(
Tuple, Tuple: the result of executing the scripts and the numeric result of computing the vector-Jacobian product
"""
raise NotImplementedError(
"The computation of vector-Jacobian product has yet to be implemented for the lightning.tensor device."
"The computation of vector-Jacobian product has yet to be implemented for the default.tensor device."
)
4 changes: 4 additions & 0 deletions setup.py
mudit2812 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def build_extension(self, ext: CMakeExtension):
suffix = suffix[0].upper() + suffix[1:]

pennylane_plugins = [device_name + " = pennylane_lightning." + backend + ":Lightning" + suffix]
if suffix == "Qubit":
mudit2812 marked this conversation as resolved.
Show resolved Hide resolved
pennylane_plugins.append(
"default.tensor = pennylane_lightning.lightning_tensor:LightningTensor"
)

pkg_suffix = "" if suffix == "Qubit" else "_" + suffix

Expand Down
20 changes: 13 additions & 7 deletions tests/lightning_tensor/test_lightning_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_device_name_and_init(num_wires, c_dtype):
"""Test the class initialization and returned properties."""
wires = Wires(range(num_wires)) if num_wires else None
dev = LightningTensor(wires=wires, c_dtype=c_dtype)
assert dev.name == "lightning.tensor"
assert dev.name == "default.tensor"
assert dev.c_dtype == c_dtype
assert dev.wires == wires
if num_wires is None:
Expand All @@ -46,6 +46,12 @@ def test_device_name_and_init(num_wires, c_dtype):
assert dev.num_wires == num_wires


def test_device_available_as_plugin():
"""Test that the device can be instantiated using ``qml.device``."""
dev = qml.device("default.tensor", wires=2)
assert isinstance(dev, LightningTensor)


@pytest.mark.parametrize("backend", ["fake_backend"])
def test_invalid_backend(backend):
"""Test an invalid backend."""
Expand All @@ -64,14 +70,14 @@ def test_invalid_keyword_arg():
"""Test an invalid keyword argument."""
with pytest.raises(
TypeError,
match=f"Unexpected argument: fake_arg during initialization of the LightningTensor device.",
match=f"Unexpected argument: fake_arg during initialization of the default.tensor device.",
):
LightningTensor(fake_arg=None)


def test_invalid_shots():
"""Test that an error is raised if finite number of shots are requestd."""
with pytest.raises(ValueError, match="LightningTensor does not support finite shots."):
with pytest.raises(ValueError, match="default.tensor does not support finite shots."):
LightningTensor(shots=5)


Expand All @@ -86,7 +92,7 @@ def test_compute_derivatives():
dev = LightningTensor()
with pytest.raises(
NotImplementedError,
match="The computation of derivatives has yet to be implemented for the lightning.tensor device.",
match="The computation of derivatives has yet to be implemented for the default.tensor device.",
):
dev.compute_derivatives(circuits=None)

Expand All @@ -96,7 +102,7 @@ def test_execute_and_compute_derivatives():
dev = LightningTensor()
with pytest.raises(
NotImplementedError,
match="The computation of derivatives has yet to be implemented for the lightning.tensor device.",
match="The computation of derivatives has yet to be implemented for the default.tensor device.",
):
dev.execute_and_compute_derivatives(circuits=None)

Expand All @@ -112,7 +118,7 @@ def test_compute_vjp():
dev = LightningTensor()
with pytest.raises(
NotImplementedError,
match="The computation of vector-Jacobian product has yet to be implemented for the lightning.tensor device.",
match="The computation of vector-Jacobian product has yet to be implemented for the default.tensor device.",
):
dev.compute_vjp(circuits=None, cotangents=None)

Expand All @@ -122,6 +128,6 @@ def test_execute_and_compute_vjp():
dev = LightningTensor()
with pytest.raises(
NotImplementedError,
match="The computation of vector-Jacobian product has yet to be implemented for the lightning.tensor device.",
match="The computation of vector-Jacobian product has yet to be implemented for the default.tensor device.",
):
dev.execute_and_compute_vjp(circuits=None, cotangents=None)
Loading