-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
noxfile.py
134 lines (118 loc) · 4.2 KB
/
noxfile.py
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import nox
import os
import sys
import warnings
import platform
from pathlib import Path
nox.options.default_venv_backend = "virtualenv"
nox.options.reuse_existing_virtualenvs = True
if sys.platform != "win32":
nox.options.sessions = ["idaklu-requires", "unit"]
else:
nox.options.sessions = ["unit"]
def set_iree_state():
"""
Check if IREE is enabled and set the environment variable accordingly.
Returns
-------
str
"ON" if IREE is enabled, "OFF" otherwise.
"""
state = "ON" if os.getenv("PYBAMM_IDAKLU_EXPR_IREE", "OFF") == "ON" else "OFF"
if state == "ON":
if sys.platform == "win32":
warnings.warn(
(
"IREE is not enabled on Windows yet. "
"Setting PYBAMM_IDAKLU_EXPR_IREE=OFF."
),
stacklevel=2,
)
return "OFF"
if sys.platform == "darwin":
# iree-compiler is currently only available as a wheel on macOS 13 (or
# higher) and Python version 3.11
mac_ver = int(platform.mac_ver()[0].split(".")[0])
if (not sys.version_info[:2] == (3, 11)) or mac_ver < 13:
warnings.warn(
(
"IREE is only supported on MacOS 13 (or higher) and Python"
"version 3.11. Setting PYBAMM_IDAKLU_EXPR_IREE=OFF."
),
stacklevel=2,
)
return "OFF"
return state
homedir = Path(__file__)
PYBAMM_ENV = {
"LD_LIBRARY_PATH": f"{homedir}/.idaklu/lib",
"PYTHONIOENCODING": "utf-8",
"MPLBACKEND": "Agg",
# Expression evaluators (...EXPR_CASADI cannot be fully disabled at this time)
"PYBAMM_IDAKLU_EXPR_CASADI": os.getenv("PYBAMM_IDAKLU_EXPR_CASADI", "ON"),
"PYBAMM_IDAKLU_EXPR_IREE": set_iree_state(),
"IREE_INDEX_URL": os.getenv(
"IREE_INDEX_URL", "https://iree.dev/pip-release-links.html"
),
}
VENV_DIR = Path("./venv").resolve()
def set_environment_variables(env_dict, session):
"""
Sets environment variables for a nox Session object.
Parameters
-----------
session : nox.Session
The session to set the environment variables for.
env_dict : dict
A dictionary of environment variable names and values.
"""
for key, value in env_dict.items():
session.env[key] = value
@nox.session(name="idaklu-requires")
def run_pybamm_requires(session):
"""Download, compile, and install the build-time requirements for Linux and macOS. Supports --install-dir for custom installation paths and --force to force installation."""
set_environment_variables(PYBAMM_ENV, session=session)
if sys.platform != "win32":
session.run("python", "install_KLU_Sundials.py", *session.posargs)
if PYBAMM_ENV.get("PYBAMM_IDAKLU_EXPR_IREE") == "ON" and not os.path.exists(
"./iree"
):
session.run(
"git",
"clone",
"--depth=1",
"--recurse-submodules",
"--shallow-submodules",
"--branch=candidate-20240507.886",
"https://github.com/openxla/iree",
"iree/",
external=True,
)
with session.chdir("iree"):
session.run(
"git",
"submodule",
"update",
"--init",
"--recursive",
external=True,
)
else:
session.error("nox -s idaklu-requires is only available on Linux & macOS.")
@nox.session(name="unit")
def run_unit(session):
"""Run the unit tests."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("setuptools", silent=False)
session.install("casadi", silent=False)
session.install("-e", ".[dev]", silent=False)
if PYBAMM_ENV.get("PYBAMM_IDAKLU_EXPR_IREE") == "ON":
# See comments in 'dev' session
session.install(
"-e",
".[iree]",
"--find-links",
PYBAMM_ENV.get("IREE_INDEX_URL"),
silent=False,
)
session.run("pytest", "tests")