From 7e0d6ffc633231d24d935b200ccc18126c9353a5 Mon Sep 17 00:00:00 2001 From: Erick Date: Fri, 24 Nov 2023 14:16:18 -0500 Subject: [PATCH 01/30] Adds Catalyst specification files. --- MANIFEST.in | 4 +- .../core/src/lightning.kokkos.toml | 79 +++++++++++++++++++ .../core/src/lightning.qubit.toml | 79 +++++++++++++++++++ 3 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 pennylane_lightning/core/src/lightning.kokkos.toml create mode 100644 pennylane_lightning/core/src/lightning.qubit.toml diff --git a/MANIFEST.in b/MANIFEST.in index 8f5a65d821..5ba9aefda4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,4 @@ include requirements.txt -include CHANGELOG.rst \ No newline at end of file +include CHANGELOG.rst +include lightning.qubit.toml +include lightning.kokkos.toml diff --git a/pennylane_lightning/core/src/lightning.kokkos.toml b/pennylane_lightning/core/src/lightning.kokkos.toml new file mode 100644 index 0000000000..1ddc4ac7dd --- /dev/null +++ b/pennylane_lightning/core/src/lightning.kokkos.toml @@ -0,0 +1,79 @@ +schema = 1 + +[device] +name = "lightning.kokkos" +version = "v0.31.0" +precision = ['float32', 'float64'] + +[operations] +observables = [ + "NamedObs", + "HermitianObs", + "TensorObs", + "HamiltonianObs", +] + +[[operations.gates]] +full = [ + "Identity", + "PauliX", + "PauliY", + "PauliZ", + "Hadamard", + "S", + "T", + "PhaseShift", + "RX", + "RY", + "RZ", + "Rot", + "CNOT", + "CY", + "CZ", + "SWAP", + "IsingXX", + "IsingXY", + "IsingYY", + "IsingZZ", + "ControlledPhaseShift", + "CRX", + "CRY", + "CRZ", + "CRot", + "Toffoli", + "CSWAP", + "MultiRZ", +] +# QubitUnitary should never be here. +# Gates in "matrix" are decomposed to QubitUnitary. +# Having a QubitUnitary here would mean an infinite loop. +matrix = [ + "OrbitalRotation", + "SingleExcitation", + "SingleExcitationMinus", + "SingleExcitationPlus", + "MultiControlledX", + "DoubleExcitation", + "DoubleExcitationMinus", + "DoubleExcitationPlus", + # TODO: + # Why is qml.ops.Controlled not in qml namespace? + # TODO: + # other gates supported via applying matrices +] + +[measurements] +exactshots = [ + "Expval", + "Var", +] +finiteshots = [ + "Probs", + "Sample", + "Measure", # mid-circuit measurement +] + +[compilation] +qjit_compatible = true +control_flow = true +dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo diff --git a/pennylane_lightning/core/src/lightning.qubit.toml b/pennylane_lightning/core/src/lightning.qubit.toml new file mode 100644 index 0000000000..30e0621155 --- /dev/null +++ b/pennylane_lightning/core/src/lightning.qubit.toml @@ -0,0 +1,79 @@ +schema = 1 + +[device] +name = "lightning.qubit" +version = "v0.31.0" +precision = ['float32', 'float64'] + +[operations] +observables = [ + "NamedObs", + "HermitianObs", + "TensorObs", + "HamiltonianObs", +] + +[[operations.gates]] +full = [ + "Identity", + "PauliX", + "PauliY", + "PauliZ", + "Hadamard", + "S", + "T", + "PhaseShift", + "RX", + "RY", + "RZ", + "Rot", + "CNOT", + "CY", + "CZ", + "SWAP", + "IsingXX", + "IsingXY", + "IsingYY", + "IsingZZ", + "ControlledPhaseShift", + "CRX", + "CRY", + "CRZ", + "CRot", + "CSWAP", + "Toffoli", + "MultiRZ", +] +# QubitUnitary should never be here. +# Gates in "matrix" are decomposed to QubitUnitary. +# Having a QubitUnitary here would mean an infinite loop. +matrix = [ + "OrbitalRotation", + "MultiControlledX", + "SingleExcitation", + "SingleExcitationMinus", + "SingleExcitationPlus", + "DoubleExcitation", + "DoubleExcitationMinus", + "DoubleExcitationPlus", + # TODO: + # Why is qml.ops.Controlled not in qml namespace? + # TODO: + # other gates supported via applying matrices +] + +[measurements] +exactshots = [ + "Expval", + "Var", +] +finiteshots = [ + "Probs", + "Sample", + "Measure", # mid-circuit measurement +] + +[compilation] +qjit_compatible = true +control_flow = true +dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo From c096a19837d88bb7d703bc5c42f803bda694aa95 Mon Sep 17 00:00:00 2001 From: Erick Date: Fri, 24 Nov 2023 16:24:18 -0500 Subject: [PATCH 02/30] Adds path config files. --- pennylane_lightning/core/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pennylane_lightning/core/__init__.py b/pennylane_lightning/core/__init__.py index d3a37803e8..db693d2e0c 100644 --- a/pennylane_lightning/core/__init__.py +++ b/pennylane_lightning/core/__init__.py @@ -14,3 +14,8 @@ """PennyLane lightning module.""" from ._version import __version__ + +from pathlib import Path + +lightning_qubit_config_file = Path(__file__).parents[0] / "src" / "lightning.qubit.toml" +lightning_kokkos_config_file = Path(__file__).parents[0] / "src" / "lightning.kokkos.toml" From c5ec709fa233b7fdf498d07598043249146827ef Mon Sep 17 00:00:00 2001 From: Erick Date: Fri, 24 Nov 2023 16:35:12 -0500 Subject: [PATCH 03/30] Add file as a field to the device class. --- pennylane_lightning/core/__init__.py | 4 +++- pennylane_lightning/lightning_kokkos/lightning_kokkos.py | 2 ++ pennylane_lightning/lightning_qubit/lightning_qubit.py | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pennylane_lightning/core/__init__.py b/pennylane_lightning/core/__init__.py index db693d2e0c..de47ff4e93 100644 --- a/pennylane_lightning/core/__init__.py +++ b/pennylane_lightning/core/__init__.py @@ -13,9 +13,11 @@ # limitations under the License. """PennyLane lightning module.""" +from pathlib import Path from ._version import __version__ -from pathlib import Path lightning_qubit_config_file = Path(__file__).parents[0] / "src" / "lightning.qubit.toml" lightning_kokkos_config_file = Path(__file__).parents[0] / "src" / "lightning.kokkos.toml" + +__all__ = ["__version__", "lightning_qubit_config_file", "lightning_kokkos_config_file"] diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py index 56cda8f92c..974ea86e8b 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py @@ -20,6 +20,7 @@ from warnings import warn import numpy as np +from pennylane_lightning.core import lightning_kokkos_config_file as config_file from pennylane_lightning.core.lightning_base import ( LightningBase, LightningBaseFallBack, @@ -185,6 +186,7 @@ class LightningKokkos(LightningBase): operations = allowed_operations observables = allowed_observables _backend_info = backend_info + config = config_file def __init__( self, diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.py b/pennylane_lightning/lightning_qubit/lightning_qubit.py index 9a4d4f5b35..ab959eb3fd 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.py +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.py @@ -20,6 +20,7 @@ from warnings import warn import numpy as np +from pennylane_lightning.core import lightning_qubit_config_file as config_file from pennylane_lightning.core.lightning_base import ( LightningBase, LightningBaseFallBack, @@ -186,6 +187,7 @@ class LightningQubit(LightningBase): operations = allowed_operations observables = allowed_observables _backend_info = backend_info + config = config_file def __init__( self, From d00308ce532b5d81095c42ea5f1768c0ba416508 Mon Sep 17 00:00:00 2001 From: Erick Date: Fri, 24 Nov 2023 16:40:19 -0500 Subject: [PATCH 04/30] Changelog. --- .github/CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 9341ead3f4..6b5177b10d 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -23,6 +23,9 @@ ### Improvements +* Add configuration files to improve compatibility with Catalyst + [(#557)](https://github.com/PennyLaneAI/pennylane-lightning/pull/566) + * Refactor shot-noise related methods of MeasurementsBase class in the C++ layer and eigenvalues are not limited to `1` and `-1`. Add `getObs()` method to Observables class. Refactor `applyInPlaceShots` to allow users to get eigenvalues of Observables object. Deprecated `_preprocess_state` method in `MeasurementsBase` class for safer use of the `LightningQubitRaw` backend. [(#570)](https://github.com/PennyLaneAI/pennylane-lightning/pull/570) @@ -64,7 +67,7 @@ This release contains contributions from (in alphabetical order): -Isaac De Vlugt, Vincent Michaud-Rioux, Lee James O'Riordan, Shuli Shu +Isaac De Vlugt, Vincent Michaud-Rioux, Lee James O'Riordan, Erick Ochoa Lopez, Shuli Shu --- From 8bdd9dd8558ad2daa64a285152d19f89334c4c97 Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 28 Nov 2023 09:16:47 -0500 Subject: [PATCH 05/30] Just use parent --- pennylane_lightning/core/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pennylane_lightning/core/__init__.py b/pennylane_lightning/core/__init__.py index de47ff4e93..25495c3674 100644 --- a/pennylane_lightning/core/__init__.py +++ b/pennylane_lightning/core/__init__.py @@ -17,7 +17,7 @@ from ._version import __version__ -lightning_qubit_config_file = Path(__file__).parents[0] / "src" / "lightning.qubit.toml" -lightning_kokkos_config_file = Path(__file__).parents[0] / "src" / "lightning.kokkos.toml" +lightning_qubit_config_file = Path(__file__).parent / "src" / "lightning.qubit.toml" +lightning_kokkos_config_file = Path(__file__).parent / "src" / "lightning.kokkos.toml" __all__ = ["__version__", "lightning_qubit_config_file", "lightning_kokkos_config_file"] From d48f229825149ef0ec15f94a0d6b425af7510e6d Mon Sep 17 00:00:00 2001 From: erick-xanadu <110487834+erick-xanadu@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:39:26 -0500 Subject: [PATCH 06/30] Apply suggestions from code review Co-authored-by: Amintor Dusko <87949283+AmintorDusko@users.noreply.github.com> Co-authored-by: Vincent Michaud-Rioux --- .github/CHANGELOG.md | 2 +- pennylane_lightning/core/src/lightning.kokkos.toml | 12 ++++++------ pennylane_lightning/core/src/lightning.qubit.toml | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 6b5177b10d..3f7960dbe7 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -23,7 +23,7 @@ ### Improvements -* Add configuration files to improve compatibility with Catalyst +* Add configuration files to improve compatibility with Catalyst. [(#557)](https://github.com/PennyLaneAI/pennylane-lightning/pull/566) * Refactor shot-noise related methods of MeasurementsBase class in the C++ layer and eigenvalues are not limited to `1` and `-1`. Add `getObs()` method to Observables class. Refactor `applyInPlaceShots` to allow users to get eigenvalues of Observables object. Deprecated `_preprocess_state` method in `MeasurementsBase` class for safer use of the `LightningQubitRaw` backend. diff --git a/pennylane_lightning/core/src/lightning.kokkos.toml b/pennylane_lightning/core/src/lightning.kokkos.toml index 1ddc4ac7dd..ba647a4768 100644 --- a/pennylane_lightning/core/src/lightning.kokkos.toml +++ b/pennylane_lightning/core/src/lightning.kokkos.toml @@ -43,19 +43,19 @@ full = [ "Toffoli", "CSWAP", "MultiRZ", + "SingleExcitation", + "SingleExcitationMinus", + "SingleExcitationPlus", + "DoubleExcitation", + "DoubleExcitationMinus", + "DoubleExcitationPlus", ] # QubitUnitary should never be here. # Gates in "matrix" are decomposed to QubitUnitary. # Having a QubitUnitary here would mean an infinite loop. matrix = [ "OrbitalRotation", - "SingleExcitation", - "SingleExcitationMinus", - "SingleExcitationPlus", "MultiControlledX", - "DoubleExcitation", - "DoubleExcitationMinus", - "DoubleExcitationPlus", # TODO: # Why is qml.ops.Controlled not in qml namespace? # TODO: diff --git a/pennylane_lightning/core/src/lightning.qubit.toml b/pennylane_lightning/core/src/lightning.qubit.toml index 30e0621155..47e101506c 100644 --- a/pennylane_lightning/core/src/lightning.qubit.toml +++ b/pennylane_lightning/core/src/lightning.qubit.toml @@ -43,6 +43,12 @@ full = [ "CSWAP", "Toffoli", "MultiRZ", + "SingleExcitation", + "SingleExcitationMinus", + "SingleExcitationPlus", + "DoubleExcitation", + "DoubleExcitationMinus", + "DoubleExcitationPlus", ] # QubitUnitary should never be here. # Gates in "matrix" are decomposed to QubitUnitary. @@ -50,12 +56,6 @@ full = [ matrix = [ "OrbitalRotation", "MultiControlledX", - "SingleExcitation", - "SingleExcitationMinus", - "SingleExcitationPlus", - "DoubleExcitation", - "DoubleExcitationMinus", - "DoubleExcitationPlus", # TODO: # Why is qml.ops.Controlled not in qml namespace? # TODO: From 6758a77fdfedaeaa430931f2fb62c1512bf20e92 Mon Sep 17 00:00:00 2001 From: Erick Date: Mon, 4 Dec 2023 09:55:05 -0500 Subject: [PATCH 07/30] Rename files. --- .../core/src/{lightning.kokkos.toml => lightning_kokkos.toml} | 0 .../core/src/{lightning.qubit.toml => lightning_qubit.toml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename pennylane_lightning/core/src/{lightning.kokkos.toml => lightning_kokkos.toml} (100%) rename pennylane_lightning/core/src/{lightning.qubit.toml => lightning_qubit.toml} (100%) diff --git a/pennylane_lightning/core/src/lightning.kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml similarity index 100% rename from pennylane_lightning/core/src/lightning.kokkos.toml rename to pennylane_lightning/core/src/lightning_kokkos.toml diff --git a/pennylane_lightning/core/src/lightning.qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml similarity index 100% rename from pennylane_lightning/core/src/lightning.qubit.toml rename to pennylane_lightning/core/src/lightning_qubit.toml From 7eb9afcdfe5c6a7b64d51f8938b86bb7c6d93862 Mon Sep 17 00:00:00 2001 From: Erick Date: Mon, 4 Dec 2023 09:55:17 -0500 Subject: [PATCH 08/30] Remove version. --- pennylane_lightning/core/src/lightning_kokkos.toml | 1 - pennylane_lightning/core/src/lightning_qubit.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index ba647a4768..863d427a56 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -2,7 +2,6 @@ schema = 1 [device] name = "lightning.kokkos" -version = "v0.31.0" precision = ['float32', 'float64'] [operations] diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 47e101506c..1438289278 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -2,7 +2,6 @@ schema = 1 [device] name = "lightning.qubit" -version = "v0.31.0" precision = ['float32', 'float64'] [operations] From e960fc4c9ada427c0683dc97438f5b6083578aed Mon Sep 17 00:00:00 2001 From: Erick Date: Mon, 4 Dec 2023 09:55:26 -0500 Subject: [PATCH 09/30] Add lightning_gpu.toml --- .../core/src/lightning_gpu.toml | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 pennylane_lightning/core/src/lightning_gpu.toml diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml new file mode 100644 index 0000000000..811f35e755 --- /dev/null +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -0,0 +1,74 @@ +schema = 1 + +[device] +name = "lightning.qubit" +precision = ['float32', 'float64'] + +[operations] +observables = [ + "NamedObs", + "HermitianObs", + "TensorObs", + "HamiltonianObs", +] + +[[operations.gates]] +full = [ + "Identity", + "PauliX", + "PauliY", + "PauliZ", + "Hadamard", + "S", + "T", + "PhaseShift", + "RX", + "RY", + "RZ", + "Rot", + "CNOT", + "CY", + "CZ", + "SWAP", + "IsingXX", + "IsingXY", + "IsingYY", + "IsingZZ", + "ControlledPhaseShift", + "CRX", + "CRY", + "CRZ", + "CRot", + "CSWAP", + "Toffoli", + "MultiRZ", + "SingleExcitation", + "SingleExcitationMinus", + "SingleExcitationPlus", + "DoubleExcitation", + "DoubleExcitationMinus", + "DoubleExcitationPlus", +] +# QubitUnitary should never be here. +# Gates in "matrix" are decomposed to QubitUnitary. +# Having a QubitUnitary here would mean an infinite loop. +matrix = [ + "OrbitalRotation", + "MultiControlledX", +] + +[measurements] +exactshots = [ + "Expval", + "Var", +] +finiteshots = [ + "Probs", + "Sample", + "Measure", +] + +[compilation] +qjit_compatible = false +control_flow = true +dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo From f0db1e01200167c6af42545c10ec2bd9016b379c Mon Sep 17 00:00:00 2001 From: Erick Date: Mon, 4 Dec 2023 11:18:32 -0500 Subject: [PATCH 10/30] Lightning gpu. --- MANIFEST.in | 5 +++-- pennylane_lightning/core/__init__.py | 7 ++++--- pennylane_lightning/lightning_gpu/lightning_gpu.py | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 5ba9aefda4..93fc5eda9e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ include requirements.txt include CHANGELOG.rst -include lightning.qubit.toml -include lightning.kokkos.toml +include lightning_qubit.toml +include lightning_kokkos.toml +include lightning_gpu.toml diff --git a/pennylane_lightning/core/__init__.py b/pennylane_lightning/core/__init__.py index 25495c3674..7155c76345 100644 --- a/pennylane_lightning/core/__init__.py +++ b/pennylane_lightning/core/__init__.py @@ -17,7 +17,8 @@ from ._version import __version__ -lightning_qubit_config_file = Path(__file__).parent / "src" / "lightning.qubit.toml" -lightning_kokkos_config_file = Path(__file__).parent / "src" / "lightning.kokkos.toml" +lightning_qubit_config_file = Path(__file__).parent / "src" / "lightning_qubit.toml" +lightning_kokkos_config_file = Path(__file__).parent / "src" / "lightning_kokkos.toml" +lightning_gpu_config_file = Path(__file__).parent / "src" / "lightning_gpu.toml" -__all__ = ["__version__", "lightning_qubit_config_file", "lightning_kokkos_config_file"] +__all__ = ["__version__", "lightning_qubit_config_file", "lightning_kokkos_config_file", "lightning_gpu_config_file"] diff --git a/pennylane_lightning/lightning_gpu/lightning_gpu.py b/pennylane_lightning/lightning_gpu/lightning_gpu.py index e7e76bcfbd..040aec99c6 100644 --- a/pennylane_lightning/lightning_gpu/lightning_gpu.py +++ b/pennylane_lightning/lightning_gpu/lightning_gpu.py @@ -20,6 +20,7 @@ from warnings import warn import numpy as np +from pennylane_lightning.core import lightning_gpu_config_file as config_file from pennylane_lightning.core.lightning_base import ( LightningBase, LightningBaseFallBack, @@ -230,6 +231,7 @@ class LightningGPU(LightningBase): # pylint: disable=too-many-instance-attribut operations = allowed_operations observables = allowed_observables _backend_info = backend_info + config = config_file def __init__( self, From c8ed49dc16c2902a79d467efbf4d651722d15416 Mon Sep 17 00:00:00 2001 From: Erick Date: Mon, 4 Dec 2023 11:35:39 -0500 Subject: [PATCH 11/30] Move logic to devices --- pennylane_lightning/core/__init__.py | 8 -------- pennylane_lightning/lightning_gpu/lightning_gpu.py | 4 ++-- pennylane_lightning/lightning_kokkos/lightning_kokkos.py | 4 ++-- pennylane_lightning/lightning_qubit/lightning_qubit.py | 4 ++-- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/pennylane_lightning/core/__init__.py b/pennylane_lightning/core/__init__.py index 7155c76345..d3a37803e8 100644 --- a/pennylane_lightning/core/__init__.py +++ b/pennylane_lightning/core/__init__.py @@ -13,12 +13,4 @@ # limitations under the License. """PennyLane lightning module.""" -from pathlib import Path from ._version import __version__ - - -lightning_qubit_config_file = Path(__file__).parent / "src" / "lightning_qubit.toml" -lightning_kokkos_config_file = Path(__file__).parent / "src" / "lightning_kokkos.toml" -lightning_gpu_config_file = Path(__file__).parent / "src" / "lightning_gpu.toml" - -__all__ = ["__version__", "lightning_qubit_config_file", "lightning_kokkos_config_file", "lightning_gpu_config_file"] diff --git a/pennylane_lightning/lightning_gpu/lightning_gpu.py b/pennylane_lightning/lightning_gpu/lightning_gpu.py index 040aec99c6..827e7a26db 100644 --- a/pennylane_lightning/lightning_gpu/lightning_gpu.py +++ b/pennylane_lightning/lightning_gpu/lightning_gpu.py @@ -18,9 +18,9 @@ """ from warnings import warn +from pathlib import Path import numpy as np -from pennylane_lightning.core import lightning_gpu_config_file as config_file from pennylane_lightning.core.lightning_base import ( LightningBase, LightningBaseFallBack, @@ -231,7 +231,7 @@ class LightningGPU(LightningBase): # pylint: disable=too-many-instance-attribut operations = allowed_operations observables = allowed_observables _backend_info = backend_info - config = config_file + config = Path(__file__).parents[1] / "core" / "src" / "lightning_gpu.toml" def __init__( self, diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py index 974ea86e8b..d9c2fee5f5 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py @@ -18,9 +18,9 @@ """ from warnings import warn +from pathlib import Path import numpy as np -from pennylane_lightning.core import lightning_kokkos_config_file as config_file from pennylane_lightning.core.lightning_base import ( LightningBase, LightningBaseFallBack, @@ -186,7 +186,7 @@ class LightningKokkos(LightningBase): operations = allowed_operations observables = allowed_observables _backend_info = backend_info - config = config_file + config = Path(__file__).parents[1] / "core" / "src" / "lightning_kokkos.toml" def __init__( self, diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.py b/pennylane_lightning/lightning_qubit/lightning_qubit.py index ab959eb3fd..2bc530954d 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.py +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.py @@ -18,9 +18,9 @@ """ from warnings import warn +from pathlib import Path import numpy as np -from pennylane_lightning.core import lightning_qubit_config_file as config_file from pennylane_lightning.core.lightning_base import ( LightningBase, LightningBaseFallBack, @@ -187,7 +187,7 @@ class LightningQubit(LightningBase): operations = allowed_operations observables = allowed_observables _backend_info = backend_info - config = config_file + config = Path(__file__).parents[1] / "core" / "src" / "lightning_qubit.toml" def __init__( self, From 462deca78f178fae65b610b4d2fa60e9981f458f Mon Sep 17 00:00:00 2001 From: erick-xanadu <110487834+erick-xanadu@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:43:39 -0500 Subject: [PATCH 12/30] Update .github/CHANGELOG.md Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com> --- .github/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 3f7960dbe7..91f02877c3 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -24,7 +24,7 @@ ### Improvements * Add configuration files to improve compatibility with Catalyst. - [(#557)](https://github.com/PennyLaneAI/pennylane-lightning/pull/566) + [(#566)](https://github.com/PennyLaneAI/pennylane-lightning/pull/566) * Refactor shot-noise related methods of MeasurementsBase class in the C++ layer and eigenvalues are not limited to `1` and `-1`. Add `getObs()` method to Observables class. Refactor `applyInPlaceShots` to allow users to get eigenvalues of Observables object. Deprecated `_preprocess_state` method in `MeasurementsBase` class for safer use of the `LightningQubitRaw` backend. [(#570)](https://github.com/PennyLaneAI/pennylane-lightning/pull/570) From 0ab84d2eb8fdef9e4458c5ef34930287a2661109 Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 5 Dec 2023 17:36:39 -0500 Subject: [PATCH 13/30] All gates in supported gates are now in the toml file. --- .../core/src/lightning_gpu.toml | 113 +++++++++++------ .../core/src/lightning_kokkos.toml | 119 ++++++++++++------ .../core/src/lightning_qubit.toml | 119 ++++++++++++------ 3 files changed, 232 insertions(+), 119 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml index 811f35e755..c44bda3c14 100644 --- a/pennylane_lightning/core/src/lightning_gpu.toml +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -12,49 +12,88 @@ observables = [ "HamiltonianObs", ] +# These are gates which are defined in Quantum Instruction Set. [[operations.gates]] -full = [ - "Identity", - "PauliX", - "PauliY", - "PauliZ", - "Hadamard", - "S", - "T", - "PhaseShift", - "RX", - "RY", - "RZ", - "Rot", - "CNOT", - "CY", - "CZ", - "SWAP", - "IsingXX", - "IsingXY", - "IsingYY", - "IsingZZ", - "ControlledPhaseShift", - "CRX", - "CRY", - "CRZ", - "CRot", - "CSWAP", - "Toffoli", - "MultiRZ", - "SingleExcitation", - "SingleExcitationMinus", - "SingleExcitationPlus", - "DoubleExcitation", - "DoubleExcitationMinus", - "DoubleExcitationPlus", +native = [ + "QubitUnitary", + "PauliX", + "PauliY", + "PauliZ", + "MultiRZ", + "Hadamard", + "S", + "T", + "CNOT", + "SWAP", + "CSWAP", + "Toffoli", + "CY", + "CZ", + "PhaseShift", + "ControlledPhaseShift", + "RX", + "RY", + "RZ", + "Rot", + "CRX", + "CRY", + "CRZ", + "CRot", + "IsingXX", + "IsingYY", + "IsingZZ", + "IsingXY", + # Adjoint'ed gates + # which just need the inverse flag set + # are considered natively supported gates. + "Adjoint(S)", + "Adjoint(T)", +] +# decomp gates are those which are neither supported natively +# and are not executed via the applyMatrix operation. Technically +# they could also be decomposed via applyMatrix. +decomp = [ + "SX", + "ISWAP", + "PSWAP", + "SISWAP", + "SQISW", + "CPhase", + # Adjoint'ed gates + # which are not in native set must either be decomposed + # or applied via matrix. + "Adjoint(SX)", + "Adjoint(ISWAP)", + "Adjoint(SISWAP)", ] # QubitUnitary should never be here. # Gates in "matrix" are decomposed to QubitUnitary. # Having a QubitUnitary here would mean an infinite loop. + +# These are gates that appear on the list of supported gates +# but are not in the list of Quantum Gate Set Instructions in +# the Catalyst repository. +# TODO: Move some of these to native once we add support for them +# in Catalyst runtime. matrix = [ - "OrbitalRotation", - "MultiControlledX", + "Identity", + "BasisState", + "QubitStateVector", + "StatePrep", + "ControlledQubitUnitary", + "MultiControlledX", + "DiagonalQubitUnitary", + "SingleExcitation", + "SingleExcitationPlus", + "SingleExcitationMinus", + "DoubleExcitation", + "DoubleExcitationPlus", + "DoubleExcitationMinus", + "QubitCarry", + "QubitSum", + "OrbitalRotation", + "QFT", + "ECR", ] [measurements] diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index 863d427a56..04c4058629 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -12,53 +12,90 @@ observables = [ "HamiltonianObs", ] +# These are gates which are defined in Quantum Instruction Set. [[operations.gates]] -full = [ - "Identity", - "PauliX", - "PauliY", - "PauliZ", - "Hadamard", - "S", - "T", - "PhaseShift", - "RX", - "RY", - "RZ", - "Rot", - "CNOT", - "CY", - "CZ", - "SWAP", - "IsingXX", - "IsingXY", - "IsingYY", - "IsingZZ", - "ControlledPhaseShift", - "CRX", - "CRY", - "CRZ", - "CRot", - "Toffoli", - "CSWAP", - "MultiRZ", - "SingleExcitation", - "SingleExcitationMinus", - "SingleExcitationPlus", - "DoubleExcitation", - "DoubleExcitationMinus", - "DoubleExcitationPlus", +native = [ + "QubitUnitary", + "PauliX", + "PauliY", + "PauliZ", + "MultiRZ", + "Hadamard", + "S", + "T", + "CNOT", + "SWAP", + "CSWAP", + "Toffoli", + "CY", + "CZ", + "PhaseShift", + "ControlledPhaseShift", + "RX", + "RY", + "RZ", + "Rot", + "CRX", + "CRY", + "CRZ", + "CRot", + "IsingXX", + "IsingYY", + "IsingZZ", + "IsingXY", + # Adjoint'ed gates + # which just need the inverse flag set + # are considered natively supported gates. + "Adjoint(S)", + "Adjoint(T)", +] +# decomp gates are those which are neither supported natively +# and are not executed via the applyMatrix operation. Technically +# they could also be decomposed via applyMatrix. +decomp = [ + "SX", + "ISWAP", + "PSWAP", + "SISWAP", + "SQISW", + "CPhase", + # Adjoint'ed gates + # which are not in native set must either be decomposed + # or applied via matrix. + "Adjoint(SX)", + "Adjoint(ISWAP)", + "Adjoint(SISWAP)", ] # QubitUnitary should never be here. # Gates in "matrix" are decomposed to QubitUnitary. # Having a QubitUnitary here would mean an infinite loop. + +# These are gates that appear on the list of supported gates +# but are not in the list of Quantum Gate Set Instructions in +# the Catalyst repository. +# One disadvantage of matrix gates is that they will be lowered to +# QubitUnitary and QubitUnitary is not differentiable. +# TODO: Move some of these to native once we add support for them +# in Catalyst runtime. matrix = [ - "OrbitalRotation", - "MultiControlledX", - # TODO: - # Why is qml.ops.Controlled not in qml namespace? - # TODO: - # other gates supported via applying matrices + "Identity", + "BasisState", + "QubitStateVector", + "StatePrep", + "ControlledQubitUnitary", + "MultiControlledX", + "DiagonalQubitUnitary", + "SingleExcitation", + "SingleExcitationPlus", + "SingleExcitationMinus", + "DoubleExcitation", + "DoubleExcitationPlus", + "DoubleExcitationMinus", + "QubitCarry", + "QubitSum", + "OrbitalRotation", + "QFT", + "ECR", ] [measurements] diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 1438289278..82ba1aa9a1 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -12,53 +12,90 @@ observables = [ "HamiltonianObs", ] +# These are gates which are defined in Quantum Instruction Set. [[operations.gates]] -full = [ - "Identity", - "PauliX", - "PauliY", - "PauliZ", - "Hadamard", - "S", - "T", - "PhaseShift", - "RX", - "RY", - "RZ", - "Rot", - "CNOT", - "CY", - "CZ", - "SWAP", - "IsingXX", - "IsingXY", - "IsingYY", - "IsingZZ", - "ControlledPhaseShift", - "CRX", - "CRY", - "CRZ", - "CRot", - "CSWAP", - "Toffoli", - "MultiRZ", - "SingleExcitation", - "SingleExcitationMinus", - "SingleExcitationPlus", - "DoubleExcitation", - "DoubleExcitationMinus", - "DoubleExcitationPlus", +native = [ + "QubitUnitary", + "PauliX", + "PauliY", + "PauliZ", + "MultiRZ", + "Hadamard", + "S", + "T", + "CNOT", + "SWAP", + "CSWAP", + "Toffoli", + "CY", + "CZ", + "PhaseShift", + "ControlledPhaseShift", + "RX", + "RY", + "RZ", + "Rot", + "CRX", + "CRY", + "CRZ", + "CRot", + "IsingXX", + "IsingYY", + "IsingZZ", + "IsingXY", + # Adjoint'ed gates + # which just need the inverse flag set + # are considered natively supported gates. + "Adjoint(S)", + "Adjoint(T)", +] +# decomp gates are those which are neither supported natively +# and are not executed via the applyMatrix operation. Technically +# they could also be decomposed via applyMatrix. +decomp = [ + "SX", + "ISWAP", + "PSWAP", + "SISWAP", + "SQISW", + "CPhase", + # Adjoint'ed gates + # which are not in native set must either be decomposed + # or applied via matrix. + "Adjoint(SX)", + "Adjoint(ISWAP)", + "Adjoint(SISWAP)", ] # QubitUnitary should never be here. # Gates in "matrix" are decomposed to QubitUnitary. # Having a QubitUnitary here would mean an infinite loop. + +# These are gates that appear on the list of supported gates +# but are not in the list of Quantum Gate Set Instructions in +# the Catalyst repository. +# One disadvantage of matrix gates is that they will be lowered to +# QubitUnitary and QubitUnitary is not differentiable. +# TODO: Move some of these to native once we add support for them +# in Catalyst runtime. matrix = [ - "OrbitalRotation", - "MultiControlledX", - # TODO: - # Why is qml.ops.Controlled not in qml namespace? - # TODO: - # other gates supported via applying matrices + "Identity", + "BasisState", + "QubitStateVector", + "StatePrep", + "ControlledQubitUnitary", + "MultiControlledX", + "DiagonalQubitUnitary", + "SingleExcitation", + "SingleExcitationPlus", + "SingleExcitationMinus", + "DoubleExcitation", + "DoubleExcitationPlus", + "DoubleExcitationMinus", + "QubitCarry", + "QubitSum", + "OrbitalRotation", + "QFT", + "ECR", ] [measurements] From ce85bd8edcb215f3543713a7bb7016f4f2fd070a Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 5 Dec 2023 17:42:55 -0500 Subject: [PATCH 14/30] Accounting for overlap. --- pennylane_lightning/core/src/lightning_gpu.toml | 6 +++++- pennylane_lightning/core/src/lightning_kokkos.toml | 6 +++++- pennylane_lightning/core/src/lightning_qubit.toml | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml index c44bda3c14..b8af29ac57 100644 --- a/pennylane_lightning/core/src/lightning_gpu.toml +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -100,11 +100,15 @@ matrix = [ exactshots = [ "Expval", "Var", + "Probs", + "State", ] finiteshots = [ + "Exp", + "Var", "Probs", "Sample", - "Measure", + "Counts", ] [compilation] diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index 04c4058629..593eb5d418 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -102,11 +102,15 @@ matrix = [ exactshots = [ "Expval", "Var", + "Probs", + "State", ] finiteshots = [ + "Exp", + "Var", "Probs", "Sample", - "Measure", # mid-circuit measurement + "Counts", ] [compilation] diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 82ba1aa9a1..c842b6a62a 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -102,11 +102,15 @@ matrix = [ exactshots = [ "Expval", "Var", + "Probs", + "State", ] finiteshots = [ + "Exp", + "Var", "Probs", "Sample", - "Measure", # mid-circuit measurement + "Counts", ] [compilation] From 265cc3adac55dfae8919f4a1b95b34e777c10a5f Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 5 Dec 2023 17:50:09 -0500 Subject: [PATCH 15/30] Adds options to lightning_qubit. --- pennylane_lightning/core/src/lightning_qubit.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index c842b6a62a..0540c0be64 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -116,4 +116,10 @@ finiteshots = [ [compilation] qjit_compatible = true control_flow = true +mid_circuit_measurement = true dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo + +[options] +mcmc = "_mcmc" +num_burnin = "_num_burnin" +kernel_name = "_kernel_name" From 54f8ebd2ab86dbf176117fc2d46c0a4f0ea114ec Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 5 Dec 2023 17:53:28 -0500 Subject: [PATCH 16/30] Add mid circuit measurement to lightning kokkos. --- pennylane_lightning/core/src/lightning_kokkos.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index 593eb5d418..0f7f6d624e 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -116,4 +116,5 @@ finiteshots = [ [compilation] qjit_compatible = true control_flow = true +mid_circuit_measurement = true dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo From eb20725f7979c3eafabae152296b73f57a8abe5d Mon Sep 17 00:00:00 2001 From: erick-xanadu <110487834+erick-xanadu@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:56:43 -0500 Subject: [PATCH 17/30] Update MANIFEST.in Co-authored-by: Vincent Michaud-Rioux --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 93fc5eda9e..ba9ba9519f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ include requirements.txt include CHANGELOG.rst include lightning_qubit.toml -include lightning_kokkos.toml include lightning_gpu.toml +include lightning_kokkos.toml From eb61f7d548679fc5d48e8f77ed89abe8a6ed59f9 Mon Sep 17 00:00:00 2001 From: erick-xanadu <110487834+erick-xanadu@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:21:41 -0500 Subject: [PATCH 18/30] Apply suggestions from code review Co-authored-by: Ali Asadi --- pennylane_lightning/core/src/lightning_gpu.toml | 2 +- pennylane_lightning/core/src/lightning_kokkos.toml | 2 +- pennylane_lightning/core/src/lightning_qubit.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml index b8af29ac57..248773cf7f 100644 --- a/pennylane_lightning/core/src/lightning_gpu.toml +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -104,7 +104,7 @@ exactshots = [ "State", ] finiteshots = [ - "Exp", + "Expval", "Var", "Probs", "Sample", diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index 0f7f6d624e..b5e8833367 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -106,7 +106,7 @@ exactshots = [ "State", ] finiteshots = [ - "Exp", + "Expval", "Var", "Probs", "Sample", diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 0540c0be64..16fc0221ac 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -106,7 +106,7 @@ exactshots = [ "State", ] finiteshots = [ - "Exp", + "Expval", "Var", "Probs", "Sample", From cc7fd90fde9af762466e2aca6f942cbc9307628b Mon Sep 17 00:00:00 2001 From: Erick Date: Wed, 6 Dec 2023 13:20:44 -0500 Subject: [PATCH 19/30] Move all matrix gates to decomp --- .../core/src/lightning_gpu.toml | 25 +++++++++--------- .../core/src/lightning_kokkos.toml | 26 +++++++++---------- .../core/src/lightning_qubit.toml | 26 +++++++++---------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml index 248773cf7f..d32b74a3c7 100644 --- a/pennylane_lightning/core/src/lightning_gpu.toml +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -65,17 +65,6 @@ decomp = [ "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", -] -# QubitUnitary should never be here. -# Gates in "matrix" are decomposed to QubitUnitary. -# Having a QubitUnitary here would mean an infinite loop. - -# These are gates that appear on the list of supported gates -# but are not in the list of Quantum Gate Set Instructions in -# the Catalyst repository. -# TODO: Move some of these to native once we add support for them -# in Catalyst runtime. -matrix = [ "Identity", "BasisState", "QubitStateVector", @@ -95,6 +84,17 @@ matrix = [ "QFT", "ECR", ] +# QubitUnitary should never be here. +# Gates in "matrix" are decomposed to QubitUnitary. +# Having a QubitUnitary here would mean an infinite loop. + +# These are gates that appear on the list of supported gates +# but are not in the list of Quantum Gate Set Instructions in +# the Catalyst repository. +# TODO: Move some of these to native once we add support for them +# in Catalyst runtime. +matrix = [ +] [measurements] exactshots = [ @@ -113,5 +113,6 @@ finiteshots = [ [compilation] qjit_compatible = false -control_flow = true +mid_circuit_measurement = false +control_flow = false dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index b5e8833367..81ac8c8f94 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -65,19 +65,6 @@ decomp = [ "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", -] -# QubitUnitary should never be here. -# Gates in "matrix" are decomposed to QubitUnitary. -# Having a QubitUnitary here would mean an infinite loop. - -# These are gates that appear on the list of supported gates -# but are not in the list of Quantum Gate Set Instructions in -# the Catalyst repository. -# One disadvantage of matrix gates is that they will be lowered to -# QubitUnitary and QubitUnitary is not differentiable. -# TODO: Move some of these to native once we add support for them -# in Catalyst runtime. -matrix = [ "Identity", "BasisState", "QubitStateVector", @@ -97,6 +84,19 @@ matrix = [ "QFT", "ECR", ] +# QubitUnitary should never be here. +# Gates in "matrix" are decomposed to QubitUnitary. +# Having a QubitUnitary here would mean an infinite loop. + +# These are gates that appear on the list of supported gates +# but are not in the list of Quantum Gate Set Instructions in +# the Catalyst repository. +# One disadvantage of matrix gates is that they will be lowered to +# QubitUnitary and QubitUnitary is not differentiable. +# TODO: Move some of these to native once we add support for them +# in Catalyst runtime. +matrix = [ +] [measurements] exactshots = [ diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 16fc0221ac..169ad2e673 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -65,19 +65,6 @@ decomp = [ "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", -] -# QubitUnitary should never be here. -# Gates in "matrix" are decomposed to QubitUnitary. -# Having a QubitUnitary here would mean an infinite loop. - -# These are gates that appear on the list of supported gates -# but are not in the list of Quantum Gate Set Instructions in -# the Catalyst repository. -# One disadvantage of matrix gates is that they will be lowered to -# QubitUnitary and QubitUnitary is not differentiable. -# TODO: Move some of these to native once we add support for them -# in Catalyst runtime. -matrix = [ "Identity", "BasisState", "QubitStateVector", @@ -97,6 +84,19 @@ matrix = [ "QFT", "ECR", ] +# QubitUnitary should never be here. +# Gates in "matrix" are decomposed to QubitUnitary. +# Having a QubitUnitary here would mean an infinite loop. + +# These are gates that appear on the list of supported gates +# but are not in the list of Quantum Gate Set Instructions in +# the Catalyst repository. +# One disadvantage of matrix gates is that they will be lowered to +# QubitUnitary and QubitUnitary is not differentiable. +# TODO: Move some of these to native once we add support for them +# in Catalyst runtime. +matrix = [ +] [measurements] exactshots = [ From e48a38f1f9f10965641fea0398234628d0cf1b7c Mon Sep 17 00:00:00 2001 From: Erick Date: Wed, 6 Dec 2023 13:22:35 -0500 Subject: [PATCH 20/30] Keep multicontrolledX as matrix gate as that is the current behaviour in Catalyst. --- pennylane_lightning/core/src/lightning_gpu.toml | 2 +- pennylane_lightning/core/src/lightning_kokkos.toml | 2 +- pennylane_lightning/core/src/lightning_qubit.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml index d32b74a3c7..c30c99426e 100644 --- a/pennylane_lightning/core/src/lightning_gpu.toml +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -70,7 +70,6 @@ decomp = [ "QubitStateVector", "StatePrep", "ControlledQubitUnitary", - "MultiControlledX", "DiagonalQubitUnitary", "SingleExcitation", "SingleExcitationPlus", @@ -94,6 +93,7 @@ decomp = [ # TODO: Move some of these to native once we add support for them # in Catalyst runtime. matrix = [ + "MultiControlledX", ] [measurements] diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index 81ac8c8f94..355a189152 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -70,7 +70,6 @@ decomp = [ "QubitStateVector", "StatePrep", "ControlledQubitUnitary", - "MultiControlledX", "DiagonalQubitUnitary", "SingleExcitation", "SingleExcitationPlus", @@ -96,6 +95,7 @@ decomp = [ # TODO: Move some of these to native once we add support for them # in Catalyst runtime. matrix = [ + "MultiControlledX", ] [measurements] diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 169ad2e673..782d4ce897 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -70,7 +70,6 @@ decomp = [ "QubitStateVector", "StatePrep", "ControlledQubitUnitary", - "MultiControlledX", "DiagonalQubitUnitary", "SingleExcitation", "SingleExcitationPlus", @@ -96,6 +95,7 @@ decomp = [ # TODO: Move some of these to native once we add support for them # in Catalyst runtime. matrix = [ + "MultiControlledX", ] [measurements] From 06cd61298108069f8e1ee2c32756fa734da2c65e Mon Sep 17 00:00:00 2001 From: Erick Date: Wed, 6 Dec 2023 18:42:02 -0500 Subject: [PATCH 21/30] Add toml files with new fields. --- .../core/src/lightning_gpu.toml | 17 +++++++------- .../core/src/lightning_kokkos.toml | 22 ++++++++----------- .../core/src/lightning_qubit.toml | 13 +++++------ 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml index c30c99426e..9e055d87c3 100644 --- a/pennylane_lightning/core/src/lightning_gpu.toml +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -39,15 +39,11 @@ native = [ "CRY", "CRZ", "CRot", + "Identity", "IsingXX", "IsingYY", "IsingZZ", "IsingXY", - # Adjoint'ed gates - # which just need the inverse flag set - # are considered natively supported gates. - "Adjoint(S)", - "Adjoint(T)", ] # decomp gates are those which are neither supported natively # and are not executed via the applyMatrix operation. Technically @@ -65,7 +61,6 @@ decomp = [ "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", - "Identity", "BasisState", "QubitStateVector", "StatePrep", @@ -82,6 +77,8 @@ decomp = [ "OrbitalRotation", "QFT", "ECR", + "Adjoint(S)", + "Adjoint(T)", ] # QubitUnitary should never be here. # Gates in "matrix" are decomposed to QubitUnitary. @@ -90,6 +87,8 @@ decomp = [ # These are gates that appear on the list of supported gates # but are not in the list of Quantum Gate Set Instructions in # the Catalyst repository. +# One disadvantage of matrix gates is that they will be lowered to +# QubitUnitary and QubitUnitary is not differentiable. # TODO: Move some of these to native once we add support for them # in Catalyst runtime. matrix = [ @@ -113,6 +112,8 @@ finiteshots = [ [compilation] qjit_compatible = false +runtime_code_generation = false +adjoint = false +quantum_control = false mid_circuit_measurement = false -control_flow = false -dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo +dynamic_qubit_management = false diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index 355a189152..a93ac7c3f7 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -43,11 +43,7 @@ native = [ "IsingYY", "IsingZZ", "IsingXY", - # Adjoint'ed gates - # which just need the inverse flag set - # are considered natively supported gates. - "Adjoint(S)", - "Adjoint(T)", + "Identity", ] # decomp gates are those which are neither supported natively # and are not executed via the applyMatrix operation. Technically @@ -59,13 +55,6 @@ decomp = [ "SISWAP", "SQISW", "CPhase", - # Adjoint'ed gates - # which are not in native set must either be decomposed - # or applied via matrix. - "Adjoint(SX)", - "Adjoint(ISWAP)", - "Adjoint(SISWAP)", - "Identity", "BasisState", "QubitStateVector", "StatePrep", @@ -82,6 +71,11 @@ decomp = [ "OrbitalRotation", "QFT", "ECR", + "Adjoint(SX)", + "Adjoint(ISWAP)", + "Adjoint(SISWAP)", + "Adjoint(S)", + "Adjoint(T)", ] # QubitUnitary should never be here. # Gates in "matrix" are decomposed to QubitUnitary. @@ -115,6 +109,8 @@ finiteshots = [ [compilation] qjit_compatible = true -control_flow = true +runtime_code_generation = false +adjoint = true +quantum_control = false mid_circuit_measurement = true dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 782d4ce897..7395152033 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -39,15 +39,11 @@ native = [ "CRY", "CRZ", "CRot", + "Identity", "IsingXX", "IsingYY", "IsingZZ", "IsingXY", - # Adjoint'ed gates - # which just need the inverse flag set - # are considered natively supported gates. - "Adjoint(S)", - "Adjoint(T)", ] # decomp gates are those which are neither supported natively # and are not executed via the applyMatrix operation. Technically @@ -65,7 +61,6 @@ decomp = [ "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", - "Identity", "BasisState", "QubitStateVector", "StatePrep", @@ -82,6 +77,8 @@ decomp = [ "OrbitalRotation", "QFT", "ECR", + "Adjoint(S)", + "Adjoint(T)", ] # QubitUnitary should never be here. # Gates in "matrix" are decomposed to QubitUnitary. @@ -115,7 +112,9 @@ finiteshots = [ [compilation] qjit_compatible = true -control_flow = true +runtime_code_generation = false +adjoint = true +quantum_control = false mid_circuit_measurement = true dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo From 1537fdc3324ce86ae1bfd1e03778e6a7a2d086ec Mon Sep 17 00:00:00 2001 From: Erick Date: Fri, 8 Dec 2023 19:54:31 -0500 Subject: [PATCH 22/30] New toml --- .../core/src/lightning_gpu.toml | 112 +++++++++--------- .../core/src/lightning_kokkos.toml | 110 +++++++++-------- .../core/src/lightning_qubit.toml | 108 +++++++++-------- 3 files changed, 177 insertions(+), 153 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml index 9e055d87c3..51ab8d5eab 100644 --- a/pennylane_lightning/core/src/lightning_gpu.toml +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -1,96 +1,102 @@ schema = 1 [device] -name = "lightning.qubit" +name = "lightning.gpu" precision = ['float32', 'float64'] [operations] observables = [ - "NamedObs", - "HermitianObs", - "TensorObs", - "HamiltonianObs", + "PauliX", + "PauliY", + "PauliZ", + "Hadamard", + "SparseHamiltonian", + "Hamiltonian", + "Hermitian", + "Identity", + "Sum", + "Prod", + "SProd", ] -# These are gates which are defined in Quantum Instruction Set. +# These are gates that do not need decomposition. +# Also gates which are natively supported by the device. [[operations.gates]] native = [ - "QubitUnitary", + "Identity", "PauliX", "PauliY", "PauliZ", - "MultiRZ", "Hadamard", "S", "T", - "CNOT", - "SWAP", - "CSWAP", - "Toffoli", - "CY", - "CZ", "PhaseShift", - "ControlledPhaseShift", "RX", "RY", "RZ", "Rot", + "CNOT", + "CY", + "CZ", + "SWAP", + "CSWAP", + "Toffoli", + "IsingXX", + "IsingXY", + "IsingYY", + "IsingZZ", + "ControlledPhaseShift", "CRX", "CRY", "CRZ", "CRot", - "Identity", - "IsingXX", - "IsingYY", - "IsingZZ", - "IsingXY", -] -# decomp gates are those which are neither supported natively -# and are not executed via the applyMatrix operation. Technically -# they could also be decomposed via applyMatrix. -decomp = [ - "SX", - "ISWAP", - "PSWAP", - "SISWAP", - "SQISW", - "CPhase", - # Adjoint'ed gates - # which are not in native set must either be decomposed - # or applied via matrix. + "SingleExcitation", + "SingleExcitationPlus", + "SingleExcitationMinus", + "DoubleExcitation", + "DoubleExcitationPlus", + "DoubleExcitationMinus", + "MultiRZ", + + # QubitUnitary is technically + # "applyMatrix", but it doesn't + # belong in matrix gates. + "QubitUnitary", + + # All adjoint operations in lightning_kokkos + # are applied via the inverse flag. + "Adjoint(S)", + "Adjoint(T)", "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", +] + +# Gates listed in qml.device.ops +# which the authors of this file would like to be decomposed +# according to rules outlined in the decomposition strategy for each +# operation. +decomp = [ "BasisState", + "ECR", "QubitStateVector", "StatePrep", "ControlledQubitUnitary", "DiagonalQubitUnitary", - "SingleExcitation", - "SingleExcitationPlus", - "SingleExcitationMinus", - "DoubleExcitation", - "DoubleExcitationPlus", - "DoubleExcitationMinus", + "SX", + "ISWAP", + "PSWAP", + "SISWAP", + "SQISW", + "CPhase", "QubitCarry", "QubitSum", "OrbitalRotation", "QFT", - "ECR", - "Adjoint(S)", - "Adjoint(T)", ] -# QubitUnitary should never be here. -# Gates in "matrix" are decomposed to QubitUnitary. -# Having a QubitUnitary here would mean an infinite loop. -# These are gates that appear on the list of supported gates -# but are not in the list of Quantum Gate Set Instructions in -# the Catalyst repository. -# One disadvantage of matrix gates is that they will be lowered to -# QubitUnitary and QubitUnitary is not differentiable. -# TODO: Move some of these to native once we add support for them -# in Catalyst runtime. +# Gates listed in qml.device.ops +# which the authors of this file would like to be decomposed into QubitUnitary. matrix = [ "MultiControlledX", ] diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index a93ac7c3f7..973203dde1 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -6,88 +6,98 @@ precision = ['float32', 'float64'] [operations] observables = [ - "NamedObs", - "HermitianObs", - "TensorObs", - "HamiltonianObs", + "PauliX", + "PauliY", + "PauliZ", + "Hadamard", + "Hermitian", + "Identity", + "SparseHamiltonian", + "Hamiltonian", + "Sum", + "SProd", + "Prod", + "Exp", ] -# These are gates which are defined in Quantum Instruction Set. +# These are gates that do not need decomposition. +# Also gates which are natively supported by the device. [[operations.gates]] native = [ - "QubitUnitary", + "Identity", "PauliX", "PauliY", "PauliZ", - "MultiRZ", "Hadamard", "S", "T", - "CNOT", - "SWAP", - "CSWAP", - "Toffoli", - "CY", - "CZ", "PhaseShift", - "ControlledPhaseShift", "RX", "RY", "RZ", "Rot", + "CNOT", + "CY", + "CZ", + "SWAP", + "CSWAP", + "Toffoli", + "IsingXX", + "IsingXY", + "IsingYY", + "IsingZZ", + "ControlledPhaseShift", "CRX", "CRY", "CRZ", "CRot", - "IsingXX", - "IsingYY", - "IsingZZ", - "IsingXY", - "Identity", + "SingleExcitation", + "SingleExcitationPlus", + "SingleExcitationMinus", + "DoubleExcitation", + "DoubleExcitationPlus", + "DoubleExcitationMinus", + "MultiRZ", + + # QubitUnitary is technically + # "applyMatrix", but it doesn't + # belong in matrix gates. + "QubitUnitary", + + # All adjoint operations in lightning_kokkos + # are applied via the inverse flag. + "Adjoint(S)", + "Adjoint(T)", + "Adjoint(SX)", + "Adjoint(ISWAP)", + "Adjoint(SISWAP)", ] -# decomp gates are those which are neither supported natively -# and are not executed via the applyMatrix operation. Technically -# they could also be decomposed via applyMatrix. + +# Gates listed in qml.device.ops +# which the authors of this file would like to be decomposed +# according to rules outlined in the decomposition strategy for each +# operation. decomp = [ + "BasisState", + "ECR", + "QubitStateVector", + "StatePrep", + "ControlledQubitUnitary", + "DiagonalQubitUnitary", "SX", "ISWAP", "PSWAP", "SISWAP", "SQISW", "CPhase", - "BasisState", - "QubitStateVector", - "StatePrep", - "ControlledQubitUnitary", - "DiagonalQubitUnitary", - "SingleExcitation", - "SingleExcitationPlus", - "SingleExcitationMinus", - "DoubleExcitation", - "DoubleExcitationPlus", - "DoubleExcitationMinus", "QubitCarry", "QubitSum", "OrbitalRotation", "QFT", - "ECR", - "Adjoint(SX)", - "Adjoint(ISWAP)", - "Adjoint(SISWAP)", - "Adjoint(S)", - "Adjoint(T)", ] -# QubitUnitary should never be here. -# Gates in "matrix" are decomposed to QubitUnitary. -# Having a QubitUnitary here would mean an infinite loop. -# These are gates that appear on the list of supported gates -# but are not in the list of Quantum Gate Set Instructions in -# the Catalyst repository. -# One disadvantage of matrix gates is that they will be lowered to -# QubitUnitary and QubitUnitary is not differentiable. -# TODO: Move some of these to native once we add support for them -# in Catalyst runtime. +# Gates listed in qml.device.ops +# which the authors of this file would like to be decomposed into QubitUnitary. matrix = [ "MultiControlledX", ] @@ -113,4 +123,4 @@ runtime_code_generation = false adjoint = true quantum_control = false mid_circuit_measurement = true -dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo +dynamic_qubit_management = false diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 7395152033..8fb422cbf8 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -6,91 +6,99 @@ precision = ['float32', 'float64'] [operations] observables = [ - "NamedObs", - "HermitianObs", - "TensorObs", - "HamiltonianObs", + "PauliX", + "PauliY", + "PauliZ", + "Hadamard", + "Hermitian", + "Identity", + "Projector", + "SparseHamiltonian", + "Hamiltonian", + "Sum", + "SProd", + "Prod", + "Exp", ] -# These are gates which are defined in Quantum Instruction Set. +# These are gates that do not need decomposition. +# Also gates which are natively supported by the device. [[operations.gates]] native = [ - "QubitUnitary", + "Identity", "PauliX", "PauliY", "PauliZ", - "MultiRZ", "Hadamard", "S", "T", - "CNOT", - "SWAP", - "CSWAP", - "Toffoli", - "CY", - "CZ", "PhaseShift", - "ControlledPhaseShift", "RX", "RY", "RZ", "Rot", + "CNOT", + "CY", + "CZ", + "SWAP", + "CSWAP", + "Toffoli", + "IsingXX", + "IsingXY", + "IsingYY", + "IsingZZ", + "ControlledPhaseShift", "CRX", "CRY", "CRZ", "CRot", - "Identity", - "IsingXX", - "IsingYY", - "IsingZZ", - "IsingXY", + "SingleExcitation", + "SingleExcitationPlus", + "SingleExcitationMinus", + "DoubleExcitation", + "DoubleExcitationPlus", + "DoubleExcitationMinus", + "MultiRZ", + # QubitUnitary is technically + # "applyMatrix", but it doesn't + # belong in matrix gates. + "QubitUnitary", ] -# decomp gates are those which are neither supported natively -# and are not executed via the applyMatrix operation. Technically -# they could also be decomposed via applyMatrix. + +# Gates listed in qml.device.ops +# which the authors of this file would like to be decomposed +# according to rules outlined in the decomposition strategy for each +# operation. decomp = [ - "SX", - "ISWAP", - "PSWAP", - "SISWAP", - "SQISW", - "CPhase", - # Adjoint'ed gates - # which are not in native set must either be decomposed - # or applied via matrix. + # All adjoint operations in lightning_qubit + # are applied via applyMatrix. + "Adjoint(S)", + "Adjoint(T)", "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", + + # The rest. "BasisState", + "ECR", "QubitStateVector", "StatePrep", "ControlledQubitUnitary", "DiagonalQubitUnitary", - "SingleExcitation", - "SingleExcitationPlus", - "SingleExcitationMinus", - "DoubleExcitation", - "DoubleExcitationPlus", - "DoubleExcitationMinus", + "SX", + "ISWAP", + "PSWAP", + "SISWAP", + "SQISW", + "CPhase", "QubitCarry", "QubitSum", "OrbitalRotation", "QFT", - "ECR", - "Adjoint(S)", - "Adjoint(T)", ] -# QubitUnitary should never be here. -# Gates in "matrix" are decomposed to QubitUnitary. -# Having a QubitUnitary here would mean an infinite loop. -# These are gates that appear on the list of supported gates -# but are not in the list of Quantum Gate Set Instructions in -# the Catalyst repository. -# One disadvantage of matrix gates is that they will be lowered to -# QubitUnitary and QubitUnitary is not differentiable. -# TODO: Move some of these to native once we add support for them -# in Catalyst runtime. +# Gates listed in qml.device.ops +# which the authors of this file would like to be decomposed into QubitUnitary. matrix = [ "MultiControlledX", ] From 224eb0b9e552545d437f01e14435e0a54ff08cbd Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 12 Dec 2023 10:10:10 -0500 Subject: [PATCH 23/30] Update toml files. --- .../core/src/lightning_gpu.toml | 48 ++++++++++--------- .../core/src/lightning_kokkos.toml | 41 ++++++++-------- .../core/src/lightning_qubit.toml | 44 +++++++++-------- 3 files changed, 69 insertions(+), 64 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml index 51ab8d5eab..6a7728c3ce 100644 --- a/pennylane_lightning/core/src/lightning_gpu.toml +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -2,26 +2,27 @@ schema = 1 [device] name = "lightning.gpu" -precision = ['float32', 'float64'] -[operations] +[operators] +# Observables supported by the device observables = [ "PauliX", "PauliY", "PauliZ", "Hadamard", - "SparseHamiltonian", - "Hamiltonian", "Hermitian", "Identity", + "SparseHamiltonian", + "Hamiltonian", "Sum", - "Prod", "SProd", + "Prod", + "Exp", ] -# These are gates that do not need decomposition. -# Also gates which are natively supported by the device. -[[operations.gates]] +# The union of all gate types listed in this section must match what +# the device considers "supported" through PennyLane's device API. +[[operators.gates]] native = [ "Identity", "PauliX", @@ -57,14 +58,7 @@ native = [ "DoubleExcitationPlus", "DoubleExcitationMinus", "MultiRZ", - - # QubitUnitary is technically - # "applyMatrix", but it doesn't - # belong in matrix gates. "QubitUnitary", - - # All adjoint operations in lightning_kokkos - # are applied via the inverse flag. "Adjoint(S)", "Adjoint(T)", "Adjoint(SX)", @@ -72,10 +66,11 @@ native = [ "Adjoint(SISWAP)", ] -# Gates listed in qml.device.ops -# which the authors of this file would like to be decomposed -# according to rules outlined in the decomposition strategy for each -# operation. +# Operators that should be decomposed according to the algorithm used +# by PennyLane's device API. +# Optional, since gates not listed in this list will typically be decomposed by +# default, but can be useful to express a deviation from this device's regular +# strategy in PennyLane. decomp = [ "BasisState", "ECR", @@ -95,13 +90,12 @@ decomp = [ "QFT", ] -# Gates listed in qml.device.ops -# which the authors of this file would like to be decomposed into QubitUnitary. +# Gates which should be translated to QubitUnitary matrix = [ "MultiControlledX", ] -[measurements] +[measurement_processes] exactshots = [ "Expval", "Var", @@ -117,9 +111,17 @@ finiteshots = [ ] [compilation] +# If the device is compatible with qjit qjit_compatible = false +# If the device requires run time generation of the quantum circuit. runtime_code_generation = false -adjoint = false +# If the device supports adjoint +quantum_adjoint = false +# If the device supports quantum control instructions natively quantum_control = false +# If the device supports mid circuit measurements natively mid_circuit_measurement = false + +# This field is currently unchecked but it is reserved for the purpose of +# determining if the device supports dynamic qubit allocation/deallocation. dynamic_qubit_management = false diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index 973203dde1..f5b6ff918d 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -2,9 +2,9 @@ schema = 1 [device] name = "lightning.kokkos" -precision = ['float32', 'float64'] -[operations] +[operators] +# Observables supported by the device observables = [ "PauliX", "PauliY", @@ -20,9 +20,9 @@ observables = [ "Exp", ] -# These are gates that do not need decomposition. -# Also gates which are natively supported by the device. -[[operations.gates]] +# The union of all gate types listed in this section must match what +# the device considers "supported" through PennyLane's device API. +[[operators.gates]] native = [ "Identity", "PauliX", @@ -58,14 +58,7 @@ native = [ "DoubleExcitationPlus", "DoubleExcitationMinus", "MultiRZ", - - # QubitUnitary is technically - # "applyMatrix", but it doesn't - # belong in matrix gates. "QubitUnitary", - - # All adjoint operations in lightning_kokkos - # are applied via the inverse flag. "Adjoint(S)", "Adjoint(T)", "Adjoint(SX)", @@ -73,10 +66,11 @@ native = [ "Adjoint(SISWAP)", ] -# Gates listed in qml.device.ops -# which the authors of this file would like to be decomposed -# according to rules outlined in the decomposition strategy for each -# operation. +# Operators that should be decomposed according to the algorithm used +# by PennyLane's device API. +# Optional, since gates not listed in this list will typically be decomposed by +# default, but can be useful to express a deviation from this device's regular +# strategy in PennyLane. decomp = [ "BasisState", "ECR", @@ -96,13 +90,12 @@ decomp = [ "QFT", ] -# Gates listed in qml.device.ops -# which the authors of this file would like to be decomposed into QubitUnitary. +# Gates which should be translated to QubitUnitary matrix = [ "MultiControlledX", ] -[measurements] +[measurement_processes] exactshots = [ "Expval", "Var", @@ -118,9 +111,17 @@ finiteshots = [ ] [compilation] +# If the device is compatible with qjit qjit_compatible = true +# If the device requires run time generation of the quantum circuit. runtime_code_generation = false -adjoint = true +# If the device supports adjoint +quantum_adjoint = true +# If the device supports quantum control instructions natively quantum_control = false +# If the device supports mid circuit measurements natively mid_circuit_measurement = true + +# This field is currently unchecked but it is reserved for the purpose of +# determining if the device supports dynamic qubit allocation/deallocation. dynamic_qubit_management = false diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 8fb422cbf8..bdd6809144 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -2,9 +2,9 @@ schema = 1 [device] name = "lightning.qubit" -precision = ['float32', 'float64'] -[operations] +[operators] +# Observables supported by the device observables = [ "PauliX", "PauliY", @@ -21,10 +21,11 @@ observables = [ "Exp", ] -# These are gates that do not need decomposition. -# Also gates which are natively supported by the device. -[[operations.gates]] +# The union of all gate types listed in this section must match what +# the device considers "supported" through PennyLane's device API. +[[operators.gates]] native = [ + # Operators that shouldn't be decomposed. "Identity", "PauliX", "PauliY", @@ -59,26 +60,20 @@ native = [ "DoubleExcitationPlus", "DoubleExcitationMinus", "MultiRZ", - # QubitUnitary is technically - # "applyMatrix", but it doesn't - # belong in matrix gates. "QubitUnitary", ] -# Gates listed in qml.device.ops -# which the authors of this file would like to be decomposed -# according to rules outlined in the decomposition strategy for each -# operation. +# Operators that should be decomposed according to the algorithm used +# by PennyLane's device API. +# Optional, since gates not listed in this list will typically be decomposed by +# default, but can be useful to express a deviation from this device's regular +# strategy in PennyLane. decomp = [ - # All adjoint operations in lightning_qubit - # are applied via applyMatrix. "Adjoint(S)", "Adjoint(T)", "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", - - # The rest. "BasisState", "ECR", "QubitStateVector", @@ -97,13 +92,12 @@ decomp = [ "QFT", ] -# Gates listed in qml.device.ops -# which the authors of this file would like to be decomposed into QubitUnitary. +# Gates which should be translated to QubitUnitary matrix = [ "MultiControlledX", ] -[measurements] +[measurement_processes] exactshots = [ "Expval", "Var", @@ -119,12 +113,20 @@ finiteshots = [ ] [compilation] +# If the device is compatible with qjit qjit_compatible = true +# If the device requires run time generation of the quantum circuit. runtime_code_generation = false -adjoint = true +# If the device supports adjoint +quantum_adjoint = true +# If the device supports quantum control instructions natively quantum_control = false +# If the device supports mid circuit measurements natively mid_circuit_measurement = true -dynamic_qubit_management = false # true after merging `StateVectorLQubitDynamic` to the monorepo + +# This field is currently unchecked but it is reserved for the purpose of +# determining if the device supports dynamic qubit allocation/deallocation. +dynamic_qubit_management = false [options] mcmc = "_mcmc" From 8c40df2092be950f79ba27685a7fc0ca922c2843 Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 12 Dec 2023 11:12:56 -0500 Subject: [PATCH 24/30] Update dev 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 7382faa86b..42f8909ba2 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.34.0-dev17" +__version__ = "0.34.0-dev18" From 7fea7745eb92110e401bfca58595e10da166591f Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 12 Dec 2023 13:59:47 -0500 Subject: [PATCH 25/30] Update toml according to maintainers preference. --- .../core/src/lightning_gpu.toml | 18 +++++++++--------- .../core/src/lightning_kokkos.toml | 18 +++++++++--------- .../core/src/lightning_qubit.toml | 16 ++++++++-------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/core/src/lightning_gpu.toml index 6a7728c3ce..e4d12360ce 100644 --- a/pennylane_lightning/core/src/lightning_gpu.toml +++ b/pennylane_lightning/core/src/lightning_gpu.toml @@ -64,6 +64,7 @@ native = [ "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", + "ControlledQubitUnitary", ] # Operators that should be decomposed according to the algorithm used @@ -73,25 +74,24 @@ native = [ # strategy in PennyLane. decomp = [ "BasisState", - "ECR", + "QFT", "QubitStateVector", "StatePrep", - "ControlledQubitUnitary", - "DiagonalQubitUnitary", +] + +# Gates which should be translated to QubitUnitary +matrix = [ + "ECR", "SX", "ISWAP", "PSWAP", "SISWAP", "SQISW", "CPhase", + "OrbitalRotation", "QubitCarry", "QubitSum", - "OrbitalRotation", - "QFT", -] - -# Gates which should be translated to QubitUnitary -matrix = [ + "DiagonalQubitUnitary", "MultiControlledX", ] diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/core/src/lightning_kokkos.toml index f5b6ff918d..89da77622b 100644 --- a/pennylane_lightning/core/src/lightning_kokkos.toml +++ b/pennylane_lightning/core/src/lightning_kokkos.toml @@ -64,6 +64,7 @@ native = [ "Adjoint(SX)", "Adjoint(ISWAP)", "Adjoint(SISWAP)", + "ControlledQubitUnitary", ] # Operators that should be decomposed according to the algorithm used @@ -73,25 +74,24 @@ native = [ # strategy in PennyLane. decomp = [ "BasisState", - "ECR", "QubitStateVector", "StatePrep", - "ControlledQubitUnitary", - "DiagonalQubitUnitary", + "QFT", +] + +# Gates which should be translated to QubitUnitary +matrix = [ + "ECR", "SX", "ISWAP", "PSWAP", "SISWAP", "SQISW", "CPhase", + "OrbitalRotation", "QubitCarry", "QubitSum", - "OrbitalRotation", - "QFT", -] - -# Gates which should be translated to QubitUnitary -matrix = [ + "DiagonalQubitUnitary", "MultiControlledX", ] diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index bdd6809144..80bd628ff5 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -75,25 +75,25 @@ decomp = [ "Adjoint(ISWAP)", "Adjoint(SISWAP)", "BasisState", - "ECR", "QubitStateVector", "StatePrep", "ControlledQubitUnitary", - "DiagonalQubitUnitary", + "QFT", +] + +# Gates which should be translated to QubitUnitary +matrix = [ + "ECR", "SX", "ISWAP", "PSWAP", "SISWAP", "SQISW", "CPhase", + "OrbitalRotation", "QubitCarry", "QubitSum", - "OrbitalRotation", - "QFT", -] - -# Gates which should be translated to QubitUnitary -matrix = [ + "DiagonalQubitUnitary", "MultiControlledX", ] From d50bcb9adfb765d667d44f7c668200b7d83b89a0 Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 12 Dec 2023 14:15:02 -0500 Subject: [PATCH 26/30] Move adjoint to native gates. --- pennylane_lightning/core/src/lightning_qubit.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/core/src/lightning_qubit.toml index 80bd628ff5..b0c6190dbd 100644 --- a/pennylane_lightning/core/src/lightning_qubit.toml +++ b/pennylane_lightning/core/src/lightning_qubit.toml @@ -61,6 +61,11 @@ native = [ "DoubleExcitationMinus", "MultiRZ", "QubitUnitary", + "Adjoint(S)", + "Adjoint(T)", + "Adjoint(SX)", + "Adjoint(ISWAP)", + "Adjoint(SISWAP)", ] # Operators that should be decomposed according to the algorithm used @@ -69,11 +74,6 @@ native = [ # default, but can be useful to express a deviation from this device's regular # strategy in PennyLane. decomp = [ - "Adjoint(S)", - "Adjoint(T)", - "Adjoint(SX)", - "Adjoint(ISWAP)", - "Adjoint(SISWAP)", "BasisState", "QubitStateVector", "StatePrep", From 4df3f8486bc76867eead81866965e92842e28735 Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 12 Dec 2023 14:31:23 -0500 Subject: [PATCH 27/30] Move files. --- pennylane_lightning/lightning_gpu/lightning_gpu.py | 2 +- .../{core/src => lightning_gpu}/lightning_gpu.toml | 0 pennylane_lightning/lightning_kokkos/lightning_kokkos.py | 2 +- .../{core/src => lightning_kokkos}/lightning_kokkos.toml | 0 pennylane_lightning/lightning_qubit/lightning_qubit.py | 2 +- .../{core/src => lightning_qubit}/lightning_qubit.toml | 0 6 files changed, 3 insertions(+), 3 deletions(-) rename pennylane_lightning/{core/src => lightning_gpu}/lightning_gpu.toml (100%) rename pennylane_lightning/{core/src => lightning_kokkos}/lightning_kokkos.toml (100%) rename pennylane_lightning/{core/src => lightning_qubit}/lightning_qubit.toml (100%) diff --git a/pennylane_lightning/lightning_gpu/lightning_gpu.py b/pennylane_lightning/lightning_gpu/lightning_gpu.py index 827e7a26db..f424d1e14e 100644 --- a/pennylane_lightning/lightning_gpu/lightning_gpu.py +++ b/pennylane_lightning/lightning_gpu/lightning_gpu.py @@ -231,7 +231,7 @@ class LightningGPU(LightningBase): # pylint: disable=too-many-instance-attribut operations = allowed_operations observables = allowed_observables _backend_info = backend_info - config = Path(__file__).parents[1] / "core" / "src" / "lightning_gpu.toml" + config = Path(__file__).parent / "lightning_gpu.toml" def __init__( self, diff --git a/pennylane_lightning/core/src/lightning_gpu.toml b/pennylane_lightning/lightning_gpu/lightning_gpu.toml similarity index 100% rename from pennylane_lightning/core/src/lightning_gpu.toml rename to pennylane_lightning/lightning_gpu/lightning_gpu.toml diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py index d9c2fee5f5..ea1c877ab4 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py @@ -186,7 +186,7 @@ class LightningKokkos(LightningBase): operations = allowed_operations observables = allowed_observables _backend_info = backend_info - config = Path(__file__).parents[1] / "core" / "src" / "lightning_kokkos.toml" + config = Path(__file__).parent / "lightning_kokkos.toml" def __init__( self, diff --git a/pennylane_lightning/core/src/lightning_kokkos.toml b/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml similarity index 100% rename from pennylane_lightning/core/src/lightning_kokkos.toml rename to pennylane_lightning/lightning_kokkos/lightning_kokkos.toml diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.py b/pennylane_lightning/lightning_qubit/lightning_qubit.py index 38ae69804d..2eb96e46c7 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.py +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.py @@ -208,7 +208,7 @@ class LightningQubit(LightningBase): operations = allowed_operations observables = allowed_observables _backend_info = backend_info - config = Path(__file__).parents[1] / "core" / "src" / "lightning_qubit.toml" + config = Path(__file__).parent / "lightning_qubit.toml" def __init__( # pylint: disable=too-many-arguments self, diff --git a/pennylane_lightning/core/src/lightning_qubit.toml b/pennylane_lightning/lightning_qubit/lightning_qubit.toml similarity index 100% rename from pennylane_lightning/core/src/lightning_qubit.toml rename to pennylane_lightning/lightning_qubit/lightning_qubit.toml From 3d9fcf5fe4d75b79945752a2955877da6803be55 Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 12 Dec 2023 15:19:32 -0500 Subject: [PATCH 28/30] Remove adjoint gates from toml. --- pennylane_lightning/lightning_gpu/lightning_gpu.toml | 5 ----- pennylane_lightning/lightning_kokkos/lightning_kokkos.toml | 5 ----- pennylane_lightning/lightning_qubit/lightning_qubit.toml | 5 ----- 3 files changed, 15 deletions(-) diff --git a/pennylane_lightning/lightning_gpu/lightning_gpu.toml b/pennylane_lightning/lightning_gpu/lightning_gpu.toml index e4d12360ce..e473be68ee 100644 --- a/pennylane_lightning/lightning_gpu/lightning_gpu.toml +++ b/pennylane_lightning/lightning_gpu/lightning_gpu.toml @@ -59,11 +59,6 @@ native = [ "DoubleExcitationMinus", "MultiRZ", "QubitUnitary", - "Adjoint(S)", - "Adjoint(T)", - "Adjoint(SX)", - "Adjoint(ISWAP)", - "Adjoint(SISWAP)", "ControlledQubitUnitary", ] diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml b/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml index 89da77622b..c3cff4682d 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml @@ -59,11 +59,6 @@ native = [ "DoubleExcitationMinus", "MultiRZ", "QubitUnitary", - "Adjoint(S)", - "Adjoint(T)", - "Adjoint(SX)", - "Adjoint(ISWAP)", - "Adjoint(SISWAP)", "ControlledQubitUnitary", ] diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.toml b/pennylane_lightning/lightning_qubit/lightning_qubit.toml index b0c6190dbd..ca4b0a0c76 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.toml +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.toml @@ -61,11 +61,6 @@ native = [ "DoubleExcitationMinus", "MultiRZ", "QubitUnitary", - "Adjoint(S)", - "Adjoint(T)", - "Adjoint(SX)", - "Adjoint(ISWAP)", - "Adjoint(SISWAP)", ] # Operators that should be decomposed according to the algorithm used From 159f6a8f7e434076fbeb28e7f9357ba4b83ffa1a Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 12 Dec 2023 15:50:30 -0500 Subject: [PATCH 29/30] Move ControlledQubitUnitary and MultiControlledX to decomp. --- pennylane_lightning/lightning_gpu/lightning_gpu.toml | 4 ++-- pennylane_lightning/lightning_kokkos/lightning_kokkos.toml | 4 ++-- pennylane_lightning/lightning_qubit/lightning_qubit.toml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pennylane_lightning/lightning_gpu/lightning_gpu.toml b/pennylane_lightning/lightning_gpu/lightning_gpu.toml index e473be68ee..5418270293 100644 --- a/pennylane_lightning/lightning_gpu/lightning_gpu.toml +++ b/pennylane_lightning/lightning_gpu/lightning_gpu.toml @@ -59,7 +59,6 @@ native = [ "DoubleExcitationMinus", "MultiRZ", "QubitUnitary", - "ControlledQubitUnitary", ] # Operators that should be decomposed according to the algorithm used @@ -72,6 +71,8 @@ decomp = [ "QFT", "QubitStateVector", "StatePrep", + "MultiControlledX", + "ControlledQubitUnitary", ] # Gates which should be translated to QubitUnitary @@ -87,7 +88,6 @@ matrix = [ "QubitCarry", "QubitSum", "DiagonalQubitUnitary", - "MultiControlledX", ] [measurement_processes] diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml b/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml index c3cff4682d..dead1575bc 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml @@ -59,7 +59,6 @@ native = [ "DoubleExcitationMinus", "MultiRZ", "QubitUnitary", - "ControlledQubitUnitary", ] # Operators that should be decomposed according to the algorithm used @@ -72,6 +71,8 @@ decomp = [ "QubitStateVector", "StatePrep", "QFT", + "ControlledQubitUnitary", + "MultiControlledX", ] # Gates which should be translated to QubitUnitary @@ -87,7 +88,6 @@ matrix = [ "QubitCarry", "QubitSum", "DiagonalQubitUnitary", - "MultiControlledX", ] [measurement_processes] diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.toml b/pennylane_lightning/lightning_qubit/lightning_qubit.toml index ca4b0a0c76..714044146c 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.toml +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.toml @@ -72,8 +72,9 @@ decomp = [ "BasisState", "QubitStateVector", "StatePrep", - "ControlledQubitUnitary", "QFT", + "ControlledQubitUnitary", + "MultiControlledX", ] # Gates which should be translated to QubitUnitary @@ -89,7 +90,6 @@ matrix = [ "QubitCarry", "QubitSum", "DiagonalQubitUnitary", - "MultiControlledX", ] [measurement_processes] From c2af0b1e2eacea96e8cfba334ed758532e5010e2 Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 12 Dec 2023 16:28:14 -0500 Subject: [PATCH 30/30] Move ControlledQubitUnitary to matrix gate set. --- pennylane_lightning/lightning_gpu/lightning_gpu.toml | 2 +- pennylane_lightning/lightning_kokkos/lightning_kokkos.toml | 2 +- pennylane_lightning/lightning_qubit/lightning_qubit.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pennylane_lightning/lightning_gpu/lightning_gpu.toml b/pennylane_lightning/lightning_gpu/lightning_gpu.toml index 5418270293..7e2944755d 100644 --- a/pennylane_lightning/lightning_gpu/lightning_gpu.toml +++ b/pennylane_lightning/lightning_gpu/lightning_gpu.toml @@ -72,11 +72,11 @@ decomp = [ "QubitStateVector", "StatePrep", "MultiControlledX", - "ControlledQubitUnitary", ] # Gates which should be translated to QubitUnitary matrix = [ + "ControlledQubitUnitary", "ECR", "SX", "ISWAP", diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml b/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml index dead1575bc..fd1b20de7a 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.toml @@ -71,12 +71,12 @@ decomp = [ "QubitStateVector", "StatePrep", "QFT", - "ControlledQubitUnitary", "MultiControlledX", ] # Gates which should be translated to QubitUnitary matrix = [ + "ControlledQubitUnitary", "ECR", "SX", "ISWAP", diff --git a/pennylane_lightning/lightning_qubit/lightning_qubit.toml b/pennylane_lightning/lightning_qubit/lightning_qubit.toml index 714044146c..bd5d3994d3 100644 --- a/pennylane_lightning/lightning_qubit/lightning_qubit.toml +++ b/pennylane_lightning/lightning_qubit/lightning_qubit.toml @@ -73,12 +73,12 @@ decomp = [ "QubitStateVector", "StatePrep", "QFT", - "ControlledQubitUnitary", "MultiControlledX", ] # Gates which should be translated to QubitUnitary matrix = [ + "ControlledQubitUnitary", "ECR", "SX", "ISWAP",