From 3edae2f2dfcf3e04858db46703a16996f6595f36 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:14:59 -0400 Subject: [PATCH 01/17] Update lq config and toml --- .../lightning_kokkos/lightning_kokkos.toml | 1 + pennylane_lightning/lightning_qubit/lightning_qubit.py | 10 ++++++---- .../lightning_qubit/lightning_qubit.toml | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml b/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml index b8261d6808..e4cf01a526 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml @@ -18,6 +18,7 @@ observables = [ "SProd", "Prod", "Exp", + "LinearCombination", ] # The union of all gate types listed in this section must match what diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.py b/pennylane_lightning/lightning_qubit/lightning_qubit.py index e507f37642..5a1aaa3f9f 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.py +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.py @@ -358,7 +358,9 @@ class LightningQubit(Device): _CPP_BINARY_AVAILABLE = LQ_CPP_BINARY_AVAILABLE _new_API = True _backend_info = backend_info if LQ_CPP_BINARY_AVAILABLE else None - _config = Path(__file__).parent / "lightning_qubit.toml" + + # This `config` is used in Catalyst-Frontend + config = Path(__file__).parent / "lightning_qubit.toml" # TODO: Move supported ops/obs to TOML file operations = _operations @@ -465,7 +467,7 @@ def preprocess(self, execution_config: ExecutionConfig = DefaultExecutionConfig) * Currently does not intrinsically support parameter broadcasting """ - config = self._setup_execution_config(execution_config) + exec_config = self._setup_execution_config(execution_config) program = TransformProgram() program.add_transform(validate_measurements, name=self.name) @@ -475,9 +477,9 @@ def preprocess(self, execution_config: ExecutionConfig = DefaultExecutionConfig) program.add_transform(decompose, stopping_condition=stopping_condition, name=self.name) program.add_transform(qml.transforms.broadcast_expand) - if config.gradient_method == "adjoint": + if exec_config.gradient_method == "adjoint": _add_adjoint_transforms(program) - return program, config + return program, exec_config # pylint: disable=unused-argument def execute( diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.toml b/pennylane_lightning/lightning_qubit/lightning_qubit.toml index e5517c6e17..38d1c6ea49 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.toml +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.toml @@ -19,6 +19,7 @@ observables = [ "SProd", "Prod", "Exp", + "LinearCombination", ] # The union of all gate types listed in this section must match what @@ -92,6 +93,8 @@ matrix = [ "QubitSum", "DiagonalQubitUnitary", "BlockEncode", + "MidMeasureMP", + "Conditional", ] [measurement_processes] From fd85444d74bd58a823126c212f814e5596fedd9e Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:14:41 -0400 Subject: [PATCH 02/17] Fix the issue with _num_burnin default value --- pennylane_lightning/lightning_qubit/lightning_qubit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.py b/pennylane_lightning/lightning_qubit/lightning_qubit.py index 5a1aaa3f9f..76358564b5 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.py +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.py @@ -415,7 +415,7 @@ def __init__( # pylint: disable=too-many-arguments self._num_burnin = num_burnin else: self._kernel_name = None - self._num_burnin = None + self._num_burnin = 0 @property def name(self): From 8d7657dcffa1aa45dad1f9d367b09c887e78b501 Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Thu, 28 Mar 2024 20:24:38 +0000 Subject: [PATCH 03/17] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 58da0aa862..19067082da 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev20" +__version__ = "0.36.0-dev21" From cda3c5cc0fa8f5ce8404f2debe592db38f902caa Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:25:45 -0400 Subject: [PATCH 04/17] trigger ci From 6f681cf5ccbec389e79a201a942134d870f12078 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:54:08 -0400 Subject: [PATCH 05/17] Update lq toml --- pennylane_lightning/lightning_qubit/lightning_qubit.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.toml b/pennylane_lightning/lightning_qubit/lightning_qubit.toml index 38d1c6ea49..3d659337d5 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.toml +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.toml @@ -93,8 +93,6 @@ matrix = [ "QubitSum", "DiagonalQubitUnitary", "BlockEncode", - "MidMeasureMP", - "Conditional", ] [measurement_processes] From fac3326bcc7c71aa94585215995e8fc67fc563f8 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:52:24 -0400 Subject: [PATCH 06/17] Update pytests --- tests/new_api/test_device.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/new_api/test_device.py b/tests/new_api/test_device.py index a7fe0ac7d3..1bc3b6e634 100644 --- a/tests/new_api/test_device.py +++ b/tests/new_api/test_device.py @@ -184,7 +184,7 @@ def process_and_execute(device, tape): "batch_obs": False, "mcmc": False, "kernel_name": None, - "num_burnin": None, + "num_burnin": 0, } @pytest.mark.parametrize( @@ -222,7 +222,7 @@ def process_and_execute(device, tape): "batch_obs": False, "mcmc": True, "kernel_name": None, - "num_burnin": None, + "num_burnin": 0, }, ), ), From d3bdb139d2c74a1b92f2ffeb65615a05832c6abf Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Thu, 11 Apr 2024 21:14:20 +0000 Subject: [PATCH 07/17] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index bdedc820ba..3180e9d655 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev25" +__version__ = "0.36.0-dev26" From 2807452cc08628b77fb01407dc7023400aa667a4 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:20:21 -0400 Subject: [PATCH 08/17] trigger ci From a110f84a72f3341e35b7a65ed3ce13ec87970f3e Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:26:08 -0400 Subject: [PATCH 09/17] Revert changes to config.h --- pennylane_lightning/core/src/utils/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/src/utils/config.h b/pennylane_lightning/core/src/utils/config.h index 384357892b..a1f67a4efb 100644 --- a/pennylane_lightning/core/src/utils/config.h +++ b/pennylane_lightning/core/src/utils/config.h @@ -20,5 +20,5 @@ #ifndef CONFIG_H #define CONFIG_H -#define SCIPY_LIBS_PATH "/home/ali/miniforge3/envs/cat/lib/python3.11/site-packages/scipy.libs" +#define SCIPY_LIBS_PATH "" #endif From 9b29e6c5d7c2672e8ebd9a4d4a80697f18f0cf26 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:31:07 -0400 Subject: [PATCH 10/17] Tidy up --- pennylane_lightning/core/src/utils/config.h | 1 - .../lightning_qubit/lightning_qubit.py | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pennylane_lightning/core/src/utils/config.h b/pennylane_lightning/core/src/utils/config.h index a1f67a4efb..d9c12fd532 100644 --- a/pennylane_lightning/core/src/utils/config.h +++ b/pennylane_lightning/core/src/utils/config.h @@ -17,7 +17,6 @@ * Config file for the path to scipy.libs at compile time. */ - #ifndef CONFIG_H #define CONFIG_H #define SCIPY_LIBS_PATH "" diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.py b/pennylane_lightning/lightning_qubit/lightning_qubit.py index d054b71873..8aa30713fe 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.py +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.py @@ -34,7 +34,7 @@ validate_observables, ) from pennylane.measurements import MidMeasureMP -from pennylane.operation import Tensor +from pennylane.operation import DecompositionUndefinedError, Operator, Tensor from pennylane.ops import Prod, SProd, Sum from pennylane.tape import QuantumScript, QuantumTape from pennylane.transforms.core import TransformProgram @@ -290,23 +290,23 @@ def simulate_and_vjp( # The set of supported observables. -def stopping_condition(op: qml.operation.Operator) -> bool: +def stopping_condition(op: Operator) -> bool: """A function that determines whether or not an operation is supported by ``lightning.qubit``.""" return op.name in _operations -def stopping_condition_shots(op: qml.operation.Operator) -> bool: +def stopping_condition_shots(op: Operator) -> bool: """A function that determines whether or not an operation is supported by ``lightning.qubit`` with finite shots.""" - return op.name in _operations or isinstance(op, (MidMeasureMP, qml.Conditional)) + return op.name in _operations or isinstance(op, (MidMeasureMP, qml.ops.op_math.Conditional)) -def accepted_observables(obs: qml.operation.Operator) -> bool: +def accepted_observables(obs: Operator) -> bool: """A function that determines whether or not an observable is supported by ``lightning.qubit``.""" return obs.name in _observables -def adjoint_observables(obs: qml.operation.Operator) -> bool: +def adjoint_observables(obs: Operator) -> bool: """A function that determines whether or not an observable is supported by ``lightning.qubit`` when using the adjoint differentiation method.""" if isinstance(obs, qml.Projector): @@ -340,7 +340,7 @@ def _supports_adjoint(circuit): try: prog((circuit,)) - except (qml.operation.DecompositionUndefinedError, qml.DeviceError, AttributeError): + except (DecompositionUndefinedError, qml.DeviceError, AttributeError): return False return True From 8e552c3795935dfe98c590e9cc0ed8a3c685aea9 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:47:40 -0400 Subject: [PATCH 11/17] Update changelog --- .github/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index d76910abdf..6976bf20db 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -83,6 +83,9 @@ * `lightning.qubit` correctly decomposed state preparation operations with adjoint differentiation. [(#661)](https://github.com/PennyLaneAI/pennylane-lightning/pull/661) +* Update the `LightningQubit` new device API to work with Catalyst. + [(#665)](https://github.com/PennyLaneAI/pennylane-lightning/pull/665) + ### Contributors This release contains contributions from (in alphabetical order): From c195c8854d63f2740e19f6e69a967c96bd4e44c3 Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Tue, 16 Apr 2024 20:48:16 +0000 Subject: [PATCH 12/17] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 3da22800fb..547a79e452 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev28" +__version__ = "0.36.0-dev29" From 2528990352dd357035e4491938067004add1f991 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:48:33 -0400 Subject: [PATCH 13/17] trigger ci From 7ab0a5c868859b6c1d81509182b91d7faf6d84f2 Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Wed, 17 Apr 2024 12:14:24 +0000 Subject: [PATCH 14/17] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 547a79e452..7fbbc4aee8 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev29" +__version__ = "0.36.0-dev30" From feef0e8c7ae9694f6af1fca5ffc5b8aa5e40d621 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Wed, 17 Apr 2024 08:14:43 -0400 Subject: [PATCH 15/17] trigger ci From 9e832f7be70a2294582cf372df88567cd8308ff7 Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:07:57 -0400 Subject: [PATCH 16/17] Update tests --- tests/new_api/test_device.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/new_api/test_device.py b/tests/new_api/test_device.py index d0a9ac1c84..601bcf7816 100644 --- a/tests/new_api/test_device.py +++ b/tests/new_api/test_device.py @@ -33,6 +33,7 @@ decompose, no_sampling, stopping_condition, + stopping_condition_shots, validate_adjoint_trainable_params, validate_device_wires, validate_measurements, @@ -107,6 +108,7 @@ def test_add_adjoint_transforms(self): expected_program.add_transform( decompose, stopping_condition=adjoint_ops, + stopping_condition_shots=stopping_condition_shots, name=name, skip_initial_state_prep=False, ) @@ -260,7 +262,10 @@ def test_preprocess(self, adjoint): qml.devices.preprocess.mid_circuit_measurements, device=device ) expected_program.add_transform( - decompose, stopping_condition=stopping_condition, name=device.name + decompose, + stopping_condition=stopping_condition, + stopping_condition_shots=stopping_condition_shots, + name=device.name, ) expected_program.add_transform(qml.transforms.broadcast_expand) @@ -270,6 +275,7 @@ def test_preprocess(self, adjoint): expected_program.add_transform( decompose, stopping_condition=adjoint_ops, + stopping_condition_shots=stopping_condition_shots, name=name, skip_initial_state_prep=False, ) From 9fddd8b88e5dd6169ec211e0f07637be670b607b Mon Sep 17 00:00:00 2001 From: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:16:34 -0400 Subject: [PATCH 17/17] trigger ci