1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack.package import *
class PyPennylaneLightning(CMakePackage, PythonExtension):
"""The PennyLane-Lightning plugin provides a fast state-vector simulator written in C++."""
homepage = "https://docs.pennylane.ai/projects/lightning"
git = "https://github.com/PennyLaneAI/pennylane-lightning.git"
url = "https://github.com/PennyLaneAI/pennylane-lightning/archive/refs/tags/v0.30.0.tar.gz"
maintainers("mlxd", "AmintorDusko")
version("master", branch="master")
version("0.30.0", sha256="0f4032409d20d00991b5d14fe0b2b928baca4a13c5a1b16eab91f61f9273e58d")
version("0.29.0", sha256="da9912f0286d1a54051cc19cf8bdbdcd732795636274c95f376db72a88e52d85")
version(
"0.28.0",
sha256="f5849c2affb5fb57aca20feb40ca829d171b07db2304fde0a37c2332c5b09e18",
deprecated=True,
) # on Spack v0.19.0
variant("blas", default=True, description="Build with BLAS support")
variant(
"dispatcher",
default=True,
description="Build with AVX2/AVX512 gate automatic dispatching support",
)
variant("kokkos", default=True, description="Build with Kokkos support")
variant("openmp", default=True, description="Build with OpenMP support")
variant("native", default=False, description="Build natively for given hardware")
variant("verbose", default=False, description="Build with full verbosity")
variant("cpptests", default=False, description="Build CPP tests")
variant("cppbenchmarks", default=False, description="Build CPP benchmark examples")
extends("python")
# hard dependencies
depends_on("cmake@3.21:3.24,3.25.2:", type="build")
depends_on("ninja", type=("run", "build"))
# variant defined dependencies
depends_on("blas", when="+blas")
depends_on("kokkos@:3.7.01", when="+kokkos")
depends_on("kokkos-kernels@:3.7.01", when="+kokkos")
depends_on("llvm-openmp", when="+openmp %apple-clang")
depends_on("python@3.8:", type=("build", "run"))
depends_on("py-setuptools", type="build")
depends_on("py-numpy", type=("build", "run"))
depends_on("py-pybind11", type="link")
depends_on("py-pip", type="build")
depends_on("py-wheel", type="build")
# depends_on("py-pennylane@0.28:", type=("build", "run")) # circular dependency
class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
build_directory = "build"
def cmake_args(self):
"""
Here we specify all variant options that can be dynamicaly specified at build time
"""
args = [
self.define_from_variant("ENABLE_OPENMP", "openmp"),
self.define_from_variant("ENABLE_NATIVE", "native"),
self.define_from_variant("ENABLE_BLAS", "blas"),
self.define_from_variant("CMAKE_VERBOSE_MAKEFILE:BOOL", "verbose"),
self.define_from_variant("BUILD_TESTS", "cpptests"),
self.define_from_variant("BUILD_BENCHMARKS", "cppbenchmarks"),
self.define_from_variant("ENABLE_GATE_DISPATCHER", "dispatcher"),
]
if "+kokkos" in self.spec:
args += [
"-DENABLE_KOKKOS=ON",
f"-DKokkos_Core_DIR={self.spec['kokkos'].home}",
f"-DKokkos_Kernels_DIR={self.spec['kokkos-kernels'].home}",
]
else:
args += ["-DENABLE_KOKKOS=OFF"]
return args
def build(self, pkg, spec, prefix):
super().build(pkg, spec, prefix)
cm_args = ";".join(
[
s[2:]
for s in self.cmake_args()
if s[2:] not in ["BUILD_TESTS:BOOL=ON", "BUILD_BENCHMARKS:BOOL=ON"]
]
)
args = ["-i", f"--define={cm_args}"]
python("setup.py", "build_ext", *args)
def install(self, pkg, spec, prefix):
pip_args = std_pip_args + ["--prefix=" + prefix, "."]
pip(*pip_args)
super().install(pkg, spec, prefix)
@run_after("install")
@on_package_attributes(run_tests=True)
def test_lightning_build(self):
with working_dir(self.stage.source_path):
pl_runner = Executable(self.prefix.bin.pennylane_lightning_test_runner)
pl_runner()
|