Skip to content

Commit

Permalink
Add default.tensor to setup.py (#719)
Browse files Browse the repository at this point in the history
* Update setup for default.tensor

* Added test

* Auto update version from '0.37.0-dev3' to '0.37.0-dev4'

* Update changelog

* Update setup.py

* Update per review

* Updated docstrings

* Auto update version from '0.37.0-dev4' to '0.37.0-dev5'

* [skip ci] Skip CI

* Auto update version from '0.37.0-dev5' to '0.37.0-dev6'

---------

Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai>
  • Loading branch information
mudit2812 and ringo-but-quantum committed May 10, 2024
1 parent 279f7e8 commit 3187d24
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 @@ -26,7 +29,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-dev5"
__version__ = "0.37.0-dev6"
4 changes: 2 additions & 2 deletions pennylane_lightning/lightning_tensor/backends/quimb/_mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@


def stopping_condition(op: qml.operation.Operator) -> bool:
"""A function that determines if an operation is supported by ``lightning.tensor`` for this interface."""
"""A function that determines if an operation is supported by ``default.tensor`` for this interface."""
return op.name in _operations # pragma: no cover


def accepted_observables(obs: qml.operation.Operator) -> bool:
"""A function that determines if an observable is supported by ``lightning.tensor`` for this interface."""
"""A function that determines if an observable is supported by ``default.tensor`` for this interface."""
return obs.name in _observables # pragma: no cover


Expand Down
18 changes: 9 additions & 9 deletions pennylane_lightning/lightning_tensor/lightning_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@


def accepted_backends(backend: str) -> bool:
"""A function that determines whether or not a backend is supported by ``lightning.tensor``."""
"""A function that determines whether or not a backend is supported by ``default.tensor``."""
return backend in _backends


def accepted_methods(method: str) -> bool:
"""A function that determines whether or not a method is supported by ``lightning.tensor``."""
"""A function that determines whether or not a method is supported by ``default.tensor``."""
return method in _methods


Expand Down 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."
)
12 changes: 10 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def build_extension(self, ext: CMakeExtension):
packages_list = ["pennylane_lightning." + backend]

if backend == "lightning_qubit":
packages_list += ["pennylane_lightning.core"]
packages_list += ["pennylane_lightning.core", "pennylane_lightning.lightning_tensor"]
else:
requirements += ["pennylane_lightning==" + version]

Expand All @@ -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":
pennylane_plugins.append(
"default.tensor = pennylane_lightning.lightning_tensor:LightningTensor"
)

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

Expand Down Expand Up @@ -222,7 +226,11 @@ def build_extension(self, ext: CMakeExtension):
"pennylane_lightning.core": [
os.path.join("src", "*"),
os.path.join("src", "**", "*"),
]
],
"pennylane_lightning.lightning_tensor": [
os.path.join("backends", "*"),
os.path.join("backends", "**", "*"),
],
},
}
)
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)

0 comments on commit 3187d24

Please sign in to comment.