diff --git a/.dep-versions b/.dep-versions index 8a7fa0067f..c22c3c5e17 100644 --- a/.dep-versions +++ b/.dep-versions @@ -15,4 +15,4 @@ pennylane=0.39.0.dev26 # 'runtime/Makefile' and at all GitHub workflows, using the exact # commit hash corresponding to the merged PR that implements the # desired feature. -lightning=0.38.0 +lightning=0.39.0-dev38 diff --git a/.github/workflows/build-wheel-linux-x86_64.yaml b/.github/workflows/build-wheel-linux-x86_64.yaml index 109886598f..899fc53686 100644 --- a/.github/workflows/build-wheel-linux-x86_64.yaml +++ b/.github/workflows/build-wheel-linux-x86_64.yaml @@ -342,7 +342,7 @@ jobs: -DPYTHON_EXECUTABLE=$(which python${{ matrix.python_version }}) \ -Dpybind11_DIR=$(python${{ matrix.python_version }} -c "import pybind11; print(pybind11.get_cmake_dir())") \ -DENABLE_LAPACK=OFF \ - -DLIGHTNING_GIT_TAG=latest_release \ + -DLIGHTNING_GIT_TAG=6f3e0d5d371ff9823a3177dd2c66052668883d42 \ -DENABLE_WARNINGS=OFF \ -DENABLE_OPENQASM=ON \ -DENABLE_OPENMP=OFF \ diff --git a/.github/workflows/build-wheel-macos-arm64.yaml b/.github/workflows/build-wheel-macos-arm64.yaml index 2fd6220c61..64bc758a31 100644 --- a/.github/workflows/build-wheel-macos-arm64.yaml +++ b/.github/workflows/build-wheel-macos-arm64.yaml @@ -301,7 +301,7 @@ jobs: -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$GITHUB_WORKSPACE/runtime-build/lib \ -DPYTHON_EXECUTABLE=$(which python${{ matrix.python_version }}) \ -Dpybind11_DIR=$(python${{ matrix.python_version }} -c "import pybind11; print(pybind11.get_cmake_dir())") \ - -DLIGHTNING_GIT_TAG=latest_release \ + -DLIGHTNING_GIT_TAG=6f3e0d5d371ff9823a3177dd2c66052668883d42\ -DENABLE_LAPACK=OFF \ -DENABLE_WARNINGS=OFF \ -DENABLE_OPENQASM=ON \ diff --git a/.github/workflows/build-wheel-macos-x86_64.yaml b/.github/workflows/build-wheel-macos-x86_64.yaml index f03f324617..b499f7c888 100644 --- a/.github/workflows/build-wheel-macos-x86_64.yaml +++ b/.github/workflows/build-wheel-macos-x86_64.yaml @@ -292,7 +292,7 @@ jobs: -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$GITHUB_WORKSPACE/runtime-build/lib \ -DPYTHON_EXECUTABLE=$(which python${{ matrix.python_version }}) \ -Dpybind11_DIR=$(python${{ matrix.python_version }} -c "import pybind11; print(pybind11.get_cmake_dir())") \ - -DLIGHTNING_GIT_TAG=latest_release \ + -DLIGHTNING_GIT_TAG=6f3e0d5d371ff9823a3177dd2c66052668883d42 \ -DENABLE_LAPACK=OFF \ -DENABLE_WARNINGS=OFF \ -DENABLE_OPENQASM=ON \ diff --git a/.github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh b/.github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh index aa7692215a..2408967e97 100644 --- a/.github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh +++ b/.github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh @@ -45,7 +45,7 @@ cmake -S runtime -B runtime-build -G Ninja \ -DPYTHON_INCLUDE_DIR=/opt/_internal/cpython-${PYTHON_VERSION}.${PYTHON_SUBVERSION}/include/python${PYTHON_VERSION} \ -DPYTHON_LIBRARY=/opt/_internal/cpython-${PYTHON_VERSION}.${PYTHON_SUBVERSION}/lib \ -Dpybind11_DIR=/opt/_internal/cpython-${PYTHON_VERSION}.${PYTHON_SUBVERSION}/lib/python${PYTHON_VERSION}/site-packages/pybind11/share/cmake/pybind11 \ - -DLIGHTNING_GIT_TAG=latest_release \ + -DLIGHTNING_GIT_TAG=6f3e0d5d371ff9823a3177dd2c66052668883d42 \ -DENABLE_LAPACK=OFF \ -DENABLE_WARNINGS=OFF \ -DENABLE_OPENQASM=ON \ diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 3c4935f6ae..929ccc4516 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -202,6 +202,9 @@ * Cached primitive lowerings is used instead of a custom cache structure. [(#1159)](https://github.com/PennyLaneAI/catalyst/pull/1159) +* Samples on lightning.qubit/kokkos can now be seeded with `qjit(seed=...)`. + [(#1164)](https://github.com/PennyLaneAI/catalyst/pull/1164) +

Breaking changes

* Remove `static_size` field from `AbstractQreg` class. diff --git a/doc/requirements.txt b/doc/requirements.txt index 84ebcabd5e..d047476483 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -30,6 +30,6 @@ lxml_html_clean # Pre-install PL development wheels --extra-index-url https://test.pypi.org/simple/ -pennylane-lightning-kokkos==0.38.0 -pennylane-lightning==0.38.0 +pennylane-lightning-kokkos==0.39.0-dev38 +pennylane-lightning==0.39.0-dev38 pennylane==0.39.0.dev26 diff --git a/frontend/test/pytest/test_measurement_transforms.py b/frontend/test/pytest/test_measurement_transforms.py index c589b8a629..c79e42a4ca 100644 --- a/frontend/test/pytest/test_measurement_transforms.py +++ b/frontend/test/pytest/test_measurement_transforms.py @@ -167,7 +167,7 @@ def basic_circuit(theta: float): assert "counts" in mlir theta = 1.9 - expval_res, var_res, counts_res, probs_res = qml.qjit(transformed_circuit)(theta) + expval_res, var_res, counts_res, probs_res = qml.qjit(transformed_circuit, seed=37)(theta) expval_expected = np.sin(theta) * np.sin(theta / 2) var_expected = 1 - np.sin(2 * theta) ** 2 @@ -221,7 +221,7 @@ def basic_circuit(theta: float): theta = 1.9 - expval_res, var_res, sample_res, probs_res = qml.qjit(transformed_circuit)(theta) + expval_res, var_res, sample_res, probs_res = qml.qjit(transformed_circuit, seed=37)(theta) expval_expected = np.sin(theta) * np.sin(theta / 2) var_expected = 1 - np.sin(2 * theta) ** 2 @@ -389,7 +389,7 @@ def circuit(theta: float): theta = 2.5 counts_expected = circuit(theta) - res = qml.qjit(measurements_from_counts(circuit, dev.wires))(theta) + res = qml.qjit(measurements_from_counts(circuit, dev.wires), seed=37)(theta) # counts comparison by converting catalyst format to PL style eigvals dict basis_states, counts = res @@ -441,7 +441,7 @@ def circuit(theta: float): return measurement() theta = 2.5 - res = qml.qjit(measurements_from_samples(circuit, dev.wires))(theta) + res = qml.qjit(measurements_from_samples(circuit, dev.wires), seed=37)(theta) if len(measurement().wires) == 1: samples_expected = qml.qjit(circuit)(theta) diff --git a/frontend/test/pytest/test_seeded_qjit.py b/frontend/test/pytest/test_seeded_qjit.py index f9ae311e45..185cc16357 100644 --- a/frontend/test/pytest/test_seeded_qjit.py +++ b/frontend/test/pytest/test_seeded_qjit.py @@ -99,5 +99,53 @@ def cfun0(): assert np.allclose(results0, results2) +@pytest.mark.parametrize( + "seed", + [ + 42, + 37, + 1337, + 2**32 - 1, + 0, + ], +) +@pytest.mark.parametrize("shots", [10]) +def test_seeded_sample(seed, shots, backend): + """Test that different calls to qjits with the same seed produce the same sample results""" + + if backend not in ["lightning.qubit", "lightning.kokkos"]: + pytest.skip("Sample seeding is only supported on lightning.qubit and lightning.kokkos") + + dev = qml.device(backend, wires=2, shots=shots) + + @qjit(seed=seed) + def workflow(): + @qml.qnode(dev) + def circuit(): + qml.Hadamard(wires=[0]) + qml.RX(12.34, wires=[1]) + return qml.sample() + + return circuit(), circuit(), circuit(), circuit() + + @qjit(seed=seed) + def workflow1(): + @qml.qnode(dev) + def circuit(): + qml.Hadamard(wires=[0]) + qml.RX(12.34, wires=[1]) + return qml.sample() + + return circuit(), circuit(), circuit(), circuit() + + # Calls to qjits with the same seed should return the same samples + for _ in range(5): + results0 = workflow() + results1 = workflow() + results2 = workflow1() + assert np.allclose(results0, results1) + assert np.allclose(results0, results2) + + if __name__ == "__main__": pytest.main(["-x", __file__]) diff --git a/runtime/Makefile b/runtime/Makefile index b36347933d..a3a85672b4 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -14,7 +14,7 @@ ENABLE_LIGHTNING?=ON ENABLE_LIGHTNING_KOKKOS?=ON ENABLE_OPENQASM?=ON ENABLE_ASAN?=OFF -LIGHTNING_GIT_TAG_VALUE?=latest_release +LIGHTNING_GIT_TAG_VALUE?=6f3e0d5d371ff9823a3177dd2c66052668883d42 ENABLE_LAPACK?=OFF BUILD_TARGETS := rt_capi rtd_dummy diff --git a/runtime/lib/backend/lightning/lightning_dynamic/LightningSimulator.cpp b/runtime/lib/backend/lightning/lightning_dynamic/LightningSimulator.cpp index a864f136a3..592bca4ad5 100644 --- a/runtime/lib/backend/lightning/lightning_dynamic/LightningSimulator.cpp +++ b/runtime/lib/backend/lightning/lightning_dynamic/LightningSimulator.cpp @@ -314,6 +314,9 @@ std::vector LightningSimulator::GenerateSamples(size_t shots) // the number of qubits. // // Return Value Optimization (RVO) + if (this->gen) { + return m.generate_samples(shots, (*(this->gen))()); + } return m.generate_samples(shots); } diff --git a/runtime/tests/Test_SVDynamicCPU_Allocation.cpp b/runtime/tests/Test_SVDynamicCPU_Allocation.cpp index 06dc606eec..2d3270700d 100644 --- a/runtime/tests/Test_SVDynamicCPU_Allocation.cpp +++ b/runtime/tests/Test_SVDynamicCPU_Allocation.cpp @@ -24,7 +24,7 @@ #include "LinearAlgebra.hpp" #include "StateVectorLQubitDynamic.hpp" #include "Util.hpp" -#include "cpu_kernels/GateImplementationsPI.hpp" +#include "cpu_kernels/GateImplementationsLM.hpp" #include #include "TestHelpers.hpp" diff --git a/runtime/tests/Test_SVDynamicCPU_Core.cpp b/runtime/tests/Test_SVDynamicCPU_Core.cpp index 1aa0d9b13b..e024224572 100644 --- a/runtime/tests/Test_SVDynamicCPU_Core.cpp +++ b/runtime/tests/Test_SVDynamicCPU_Core.cpp @@ -24,7 +24,7 @@ #include "LinearAlgebra.hpp" #include "StateVectorLQubitDynamic.hpp" #include "Util.hpp" -#include "cpu_kernels/GateImplementationsPI.hpp" +#include "cpu_kernels/GateImplementationsLM.hpp" #include #include "TestHelpers.hpp" @@ -129,7 +129,7 @@ TEMPLATE_TEST_CASE("StateVectorLQubitDynamic::applyMatrix with a pointer", const auto m = Pennylane::Util::randomUnitary(re, num_wires); sv1.applyMatrix(m, wires); - Gates::GateImplementationsPI::applyMultiQubitOp(sv2.getData(), num_qubits, + Gates::GateImplementationsLM::applyMultiQubitOp(sv2.getData(), num_qubits, m.data(), wires, false); CHECK(sv1.getDataVector() == approx(sv2.getDataVector()).margin(PrecisionT{1e-5})); }